Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

kubebuilder 2 #93

Merged
merged 10 commits into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 11 additions & 12 deletions .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
- 'master'

jobs:

build-docker:
name: Ensure Docker image builds
runs-on: ubuntu-latest
Expand Down Expand Up @@ -138,25 +137,25 @@ jobs:
# - build-go
env:
GOPATH: /home/runner/go
ARGOCD_FAKE_IN_CLUSTER: "true"
ARGOCD_SSH_DATA_PATH: "/tmp/argo-e2e/app/config/ssh"
ARGOCD_TLS_DATA_PATH: "/tmp/argo-e2e/app/config/tls"
ARGOCD_E2E_SSH_KNOWN_HOSTS: "../fixture/certs/ssh_known_hosts"
ARGOCD_E2E_K3S: "true"
ARGOCD_IN_CI: "true"
ARGOCD_E2E_APISERVER_PORT: "8088"
ARGOCD_SERVER: "127.0.0.1:8088"
ARGOCD_FAKE_IN_CLUSTER: 'true'
ARGOCD_SSH_DATA_PATH: '/tmp/argo-e2e/app/config/ssh'
ARGOCD_TLS_DATA_PATH: '/tmp/argo-e2e/app/config/tls'
ARGOCD_E2E_SSH_KNOWN_HOSTS: '../fixture/certs/ssh_known_hosts'
ARGOCD_E2E_K3S: 'true'
ARGOCD_IN_CI: 'true'
ARGOCD_E2E_APISERVER_PORT: '8088'
ARGOCD_SERVER: '127.0.0.1:8088'
steps:
- name: Checkout latest Argo CD code
uses: actions/checkout@v2
with:
repository: argoproj/argo-cd
ref: v1.8.0
ref: v1.8.1
# Pin a specific commit to prevent Argo CD regressions from impacting us
- name: Setup Golang
uses: actions/setup-go@v1
with:
go-version: '1.14.2'
go-version: '1.14.12'
- name: Install K3S
env:
INSTALL_K3S_VERSION: ${{ matrix.k3s-version }}+k3s1
Expand Down Expand Up @@ -233,7 +232,7 @@ jobs:
kubectl apply -f manifests/crds/argoproj.io_applicationsets.yaml
make build
make start-e2e 2>&1 | tee /tmp/appset-e2e-server.log &
make test-e2e
make test-e2e
- name: Upload e2e-server logs
uses: actions/upload-artifact@v2
with:
Expand Down
20 changes: 15 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
# Build the binary
FROM golang:1.14.1 as builder
FROM golang:1.14.12 as builder

WORKDIR /workspace

# Copy the Go Modules manifests
COPY go.mod go.mod
mgoodness marked this conversation as resolved.
Show resolved Hide resolved
COPY go.sum go.sum
mgoodness marked this conversation as resolved.
Show resolved Hide resolved
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY . .
COPY main.go main.go
COPY api/ api/
COPY pkg/ pkg/
mgoodness marked this conversation as resolved.
Show resolved Hide resolved
jgwest marked this conversation as resolved.
Show resolved Hide resolved

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -a -o applicationset-controller main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-w -s" -a -o applicationset-controller main.go
mgoodness marked this conversation as resolved.
Show resolved Hide resolved

# Use distroless as minimal base image to package the manager binary
FROM debian:10-slim
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y git-all && \
rm -r /var/lib/apt/lists /var/cache/apt/archives

WORKDIR /
COPY --from=builder /workspace/applicationset-controller /usr/local/bin/
COPY --from=builder /workspace/applicationset-controller /usr/local/bin/
46 changes: 38 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,44 @@ VERSION?=$(shell cat VERSION)
IMAGE?=argoprojlabs/argocd-applicationset:v$(VERSION)
DOCKER_PUSH?=true

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

.PHONY: build
build:
build: manifests fmt vet
CGO_ENABLED=0 go build -ldflags="-w -s" -o ./dist/argocd-applicationset .

.PHONY: test
test:
test: generate fmt vet manifests
go test -race -count=1 -coverprofile=coverage.out `go list ./... | grep -v 'test/e2e'`

.PHONY: image
image:
image: test
docker build -t $(IMAGE) .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE) ; fi

.PHONY: deploy
deploy:
deploy: manifests
kustomize build manifests/namespace-install | kubectl apply -f -
kubectl patch deployment -n argocd argocd-applicationset-controller --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value": "$(IMAGE)"}]'

# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests:
controller-gen paths=./api/... crd:trivialVersions=true output:dir=./manifests/crds/
controller-gen object paths=./api/...
manifests: generate
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./..." output:crd:artifacts:config=./manifests/crds/

.PHONY: lint
lint:
golangci-lint --version
GOMAXPROCS=2 golangci-lint run --fix --verbose --timeout 300s


# Run go fmt against code
.PHONY: fmt
fmt:
Expand All @@ -50,3 +59,24 @@ start-e2e:
.PHONY: test-e2e
test-e2e:
NAMESPACE=argocd-e2e go test -race -count=1 -v -timeout 120s ./test/e2e/applicationset

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
2 changes: 1 addition & 1 deletion PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ resources:
- group: argoproj.io
kind: ApplicationSet
version: v1alpha1
version: "1"
version: "2"
32 changes: 26 additions & 6 deletions api/v1alpha1/applicationset_types.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
Expand All @@ -7,13 +23,12 @@ import (

// ApplicationSet is a set of Application resources
// +kubebuilder:object:root=true
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ApplicationSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec ApplicationSetSpec `json:"spec"`

Spec ApplicationSetSpec `json:"spec"`
Status ApplicationSetStatus `json:"status,omitempty"`
}

// ApplicationSetSpec represents a class of application set state.
Expand Down Expand Up @@ -48,7 +63,7 @@ type ListGenerator struct {
Elements []ListGeneratorElement `json:"elements"`
}

// ListGeneratorItem include cluster and url info
// ListGeneratorElement include cluster and url info
type ListGeneratorElement struct {
Cluster string `json:"cluster"`
Url string `json:"url"`
Expand Down Expand Up @@ -78,9 +93,14 @@ type GitFileGeneratorItem struct {
Path string `json:"path"`
}

// +kubebuilder:object:root=true
// ApplicationSetStatus defines the observed state of ApplicationSet
type ApplicationSetStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

// ApplicationSetList contains a list of ApplicationSet
// +kubebuilder:object:root=true
type ApplicationSetList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
16 changes: 16 additions & 0 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the argoproj.io v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=argoproj.io
Expand Down
52 changes: 52 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/argoproj/argo-cd v1.8.1
github.com/argoproj/gitops-engine v0.2.1
github.com/argoproj/pkg v0.2.0
github.com/go-logr/logr v0.3.0
github.com/jeremywohl/flatten v1.0.1
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.6.0
Expand Down
15 changes: 15 additions & 0 deletions hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/