@@ -43,15 +43,15 @@ help: ## Display this help.
43
43
# #@ Development
44
44
45
45
.PHONY : manifests
46
- manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
46
+ manifests : $( CONTROLLER_GEN ) # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
47
47
$(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
48
48
49
49
.PHONY : apiresourceschemas
50
- apiresourceschemas : kustomize # # Convert CRDs from config/crds to APIResourceSchemas. Specify APIEXPORT_PREFIX as needed.
50
+ apiresourceschemas : $( KUSTOMIZE ) # # Convert CRDs from config/crds to APIResourceSchemas. Specify APIEXPORT_PREFIX as needed.
51
51
$(KUSTOMIZE ) build config/crd | kubectl kcp crd snapshot -f - --prefix $(APIEXPORT_PREFIX ) > config/kcp/$(APIEXPORT_PREFIX ) .apiresourceschemas.yaml
52
52
53
53
.PHONY : generate
54
- generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
54
+ generate : $( CONTROLLER_GEN ) # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
55
55
$(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
56
56
57
57
.PHONY : fmt
@@ -63,9 +63,65 @@ vet: ## Run go vet against code.
63
63
go vet ./...
64
64
65
65
.PHONY : test
66
- test : manifests generate fmt vet envtest # # Run tests.
66
+ test : manifests generate fmt vet $( ENVTEST ) # # Run tests.
67
67
KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test ./... -coverprofile cover.out
68
68
69
+ .PHONY : require-%
70
+ require-% :
71
+ @if ! command -v $* 1> /dev/null 2>&1 ; then echo " $* not found in \$ $PATH " ; exit 1; fi
72
+
73
+ ARTIFACT_DIR ?= .test
74
+
75
+ .PHONY : test-e2e
76
+ test-e2e : $(ARTIFACT_DIR ) /kind.kubeconfig kcp-synctarget ready-deployment
77
+ go test ./test/e2e/...
78
+
79
+ .PHONY : ready-deployment
80
+ ready-deployment : KUBECONFIG = $(ARTIFACT_DIR ) /kcp.kubeconfig
81
+ ready-deployment : kind-image install deploy
82
+ $(KCP_KUBECTL ) --namespace " controller-runtime-example-system" rollout status deployment/controller-runtime-example-controller-manager
83
+
84
+ .PHONY : kind-image
85
+ kind-image : docker-build
86
+ kind load docker-image $(IMG ) --name controller-runtime-example
87
+
88
+ $(ARTIFACT_DIR ) /kind.kubeconfig : $(ARTIFACT_DIR ) require-kind
89
+ @if ! kind get clusters --quiet | grep --quiet controller-runtime-example; then kind create cluster --name controller-runtime-example; fi
90
+ kind get kubeconfig --name controller-runtime-example > $(ARTIFACT_DIR ) /kind.kubeconfig
91
+
92
+ $(ARTIFACT_DIR ) :
93
+ mkdir -p $(ARTIFACT_DIR )
94
+
95
+ KCP_KUBECTL ?= PATH=$(LOCALBIN ) :$(PATH ) KUBECONFIG=$(ARTIFACT_DIR ) /kcp.kubeconfig kubectl
96
+ KIND_KUBECTL ?= kubectl --kubeconfig $(ARTIFACT_DIR ) /kind.kubeconfig
97
+
98
+ .PHONY : kcp-synctarget
99
+ kcp-synctarget : require-yq kcp-workspace $(ARTIFACT_DIR ) /syncer.yaml
100
+ $(KIND_KUBECTL ) apply -f $(ARTIFACT_DIR ) /syncer.yaml
101
+ $(eval DEPLOYMENT_NAME = $(shell yq 'select(.kind=="Deployment") | .metadata.name' --raw-output < $(ARTIFACT_DIR ) /syncer.yaml ) )
102
+ $(eval DEPLOYMENT_NAMESPACE = $(shell yq 'select(.kind=="Deployment") | .metadata.namespace' --raw-output < $(ARTIFACT_DIR ) /syncer.yaml ) )
103
+ $(KIND_KUBECTL ) --namespace $(DEPLOYMENT_NAMESPACE ) rollout status deployment/$(DEPLOYMENT_NAME )
104
+ @if [[ ! -s $( ARTIFACT_DIR) /syncer.log ]]; then ( $( KIND_KUBECTL) --namespace $( DEPLOYMENT_NAMESPACE) logs deployment/$( DEPLOYMENT_NAME) -f > $( ARTIFACT_DIR) /syncer.log 2>&1 & ); fi
105
+ $(KCP_KUBECTL ) wait --for=condition=Ready synctarget/controller-runtime
106
+
107
+ $(ARTIFACT_DIR ) /syncer.yaml :
108
+ $(KCP_KUBECTL ) kcp workload sync controller-runtime --resources services --syncer-image ghcr.io/kcp-dev/kcp/syncer:v$(KCP_VERSION ) --output-file $(ARTIFACT_DIR ) /syncer.yaml
109
+
110
+ .PHONY : kcp-workspace
111
+ kcp-workspace : $(KUBECTL_KCP ) require-kubectl
112
+ kcp-workspace : kcp-server
113
+ $(KCP_KUBECTL ) kcp workspace use ' ~'
114
+ @if ! $(KCP_KUBECTL ) kcp workspace use controller-runtime-example; then $(KCP_KUBECTL ) kcp workspace create controller-runtime-example --type universal --enter; fi
115
+
116
+ .PHONY : kcp-server
117
+ kcp-server : $(KCP ) $(ARTIFACT_DIR ) /kcp
118
+ @if [[ ! -s $( ARTIFACT_DIR) /kcp.log ]]; then ( $( KCP) start --root-directory $( ARTIFACT_DIR) /kcp --kubeconfig-path $( ARTIFACT_DIR) /kcp.kubeconfig > $( ARTIFACT_DIR) /kcp.log 2>&1 & ); fi
119
+ @while true ; do if [[ ! -s $( ARTIFACT_DIR) /kcp.kubeconfig ]]; then sleep 0.2; else break ; fi ; done
120
+ @while true ; do if ! kubectl --kubeconfig $( ARTIFACT_DIR) /kcp.kubeconfig get --raw /readyz > $( ARTIFACT_DIR) /kcp.probe.log 2>&1 ; then sleep 0.2; else break ; fi ; done
121
+
122
+ $(ARTIFACT_DIR ) /kcp :
123
+ mkdir -p $(ARTIFACT_DIR ) /kcp
124
+
69
125
# #@ Build
70
126
71
127
.PHONY : build
@@ -80,11 +136,11 @@ run: manifests generate fmt vet ## Run a controller from your host.
80
136
go run ./main.go --api-export-name $(NAME_PREFIX )$(APIEXPORT_NAME )
81
137
82
138
.PHONY : docker-build
83
- docker-build : build # # Build docker image with the manager.
139
+ docker-build : require-docker build # # Build docker image with the manager.
84
140
docker build -t ${IMG} .
85
141
86
142
.PHONY : docker-push
87
- docker-push : # # Push docker image with the manager.
143
+ docker-push : require-docker # # Push docker image with the manager.
88
144
docker push ${IMG}
89
145
90
146
# #@ Deployment
@@ -93,27 +149,29 @@ ifndef ignore-not-found
93
149
ignore-not-found = false
94
150
endif
95
151
152
+ KUBECONFIG ?= $(shell realpath ~/.kube/config )
153
+
96
154
.PHONY : install
97
- install : manifests kustomize # # Install APIResourceSchemas and APIExport into kcp (using $KUBECONFIG or ~/.kube/config).
98
- $(KUSTOMIZE ) build config/kcp | kubectl apply -f -
155
+ install : manifests $( KUSTOMIZE ) # # Install APIResourceSchemas and APIExport into kcp (using $KUBECONFIG or ~/.kube/config).
156
+ $(KUSTOMIZE ) build config/kcp | kubectl --kubeconfig $( KUBECONFIG ) apply -f -
99
157
100
158
.PHONY : uninstall
101
- uninstall : manifests kustomize # # Uninstall APIResourceSchemas and APIExport from kcp (using $KUBECONFIG or ~/.kube/config). Call with ignore-not-found=true to ignore resource not found errors during deletion.
102
- $(KUSTOMIZE ) build config/kcp | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
159
+ uninstall : manifests $( KUSTOMIZE ) # # Uninstall APIResourceSchemas and APIExport from kcp (using $KUBECONFIG or ~/.kube/config). Call with ignore-not-found=true to ignore resource not found errors during deletion.
160
+ $(KUSTOMIZE ) build config/kcp | kubectl --kubeconfig $( KUBECONFIG ) delete --ignore-not-found=$(ignore-not-found ) -f -
103
161
104
162
.PHONY : deploy-crd
105
- deploy-crd : manifests kustomize # # Deploy controller
163
+ deploy-crd : manifests $( KUSTOMIZE ) # # Deploy controller
106
164
cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
107
- $(KUSTOMIZE ) build config/default-crd | kubectl apply -f - || true
165
+ $(KUSTOMIZE ) build config/default-crd | kubectl --kubeconfig $( KUBECONFIG ) apply -f - || true
108
166
109
167
.PHONY : deploy
110
- deploy : manifests kustomize # # Deploy controller
168
+ deploy : manifests $( KUSTOMIZE ) # # Deploy controller
111
169
cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
112
- $(KUSTOMIZE ) build config/default | kubectl apply -f -
170
+ $(KUSTOMIZE ) build config/default | kubectl --kubeconfig $( KUBECONFIG ) apply -f -
113
171
114
172
.PHONY : undeploy
115
173
undeploy : # # Undeploy controller. Call with ignore-not-found=true to ignore resource not found errors during deletion.
116
- $(KUSTOMIZE ) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
174
+ $(KUSTOMIZE ) build config/default | kubectl --kubeconfig $( KUBECONFIG ) delete --ignore-not-found=$(ignore-not-found ) -f -
117
175
118
176
# #@ Build Dependencies
119
177
@@ -126,23 +184,29 @@ $(LOCALBIN):
126
184
KUSTOMIZE ?= $(LOCALBIN ) /kustomize
127
185
CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
128
186
ENVTEST ?= $(LOCALBIN ) /setup-envtest
187
+ KCP ?= $(LOCALBIN ) /kcp
188
+ KUBECTL_KCP ?= $(LOCALBIN ) /kubectl-kcp
129
189
130
190
# # Tool Versions
131
191
KUSTOMIZE_VERSION ?= v3.8.7
132
192
CONTROLLER_TOOLS_VERSION ?= v0.8.0
193
+ KCP_VERSION ?= 0.7.4
133
194
134
195
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
135
- .PHONY : kustomize
136
- kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
137
196
$(KUSTOMIZE ) : $(LOCALBIN )
138
197
curl -s $(KUSTOMIZE_INSTALL_SCRIPT ) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION ) ) $(LOCALBIN )
139
198
140
- .PHONY : controller-gen
141
- controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
142
199
$(CONTROLLER_GEN ) : $(LOCALBIN )
143
200
GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
144
201
145
- .PHONY : envtest
146
- envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
202
+ OS ?= $(shell go env GOOS )
203
+ ARCH ?= $(shell go env GOARCH )
204
+
205
+ $(KCP ) : $(LOCALBIN ) # # Download kcp locally if necessary.
206
+ wget -qO- https://github.com/kcp-dev/kcp/releases/download/v$(KCP_VERSION ) /kcp_$(KCP_VERSION ) _$(OS ) _$(ARCH ) .tar.gz | tar -xvzf - bin/kcp --directory $(LOCALBIN ) /../
207
+
208
+ $(KUBECTL_KCP ) : $(LOCALBIN ) # # Download kcp kubectl plugins locally if necessary.
209
+ wget -qO- https://github.com/kcp-dev/kcp/releases/download/v$(KCP_VERSION ) /kubectl-kcp-plugin_$(KCP_VERSION ) _$(OS ) _$(ARCH ) .tar.gz | tar -xvzf - bin --directory $(LOCALBIN ) /../
210
+
147
211
$(ENVTEST ) : $(LOCALBIN )
148
212
GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
0 commit comments