Skip to content

Commit a339f2e

Browse files
sbueringerk8s-ci-robot
authored andcommitted
fixup v1alpha3
1 parent 263bfbf commit a339f2e

File tree

86 files changed

+3193
-2477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3193
-2477
lines changed

Dockerfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
# Build the manager binary
16-
FROM golang:1.13.7 as builder
16+
FROM golang:1.13.8 as builder
1717
WORKDIR /workspace
1818

1919
# Run this with docker build --build_arg $(go env GOPROXY) to override the goproxy
@@ -30,11 +30,17 @@ RUN go mod download
3030
# Copy the sources
3131
COPY ./ ./
3232

33+
RUN wget --output-document /restart.sh --quiet https://raw.githubusercontent.com/windmilleng/rerun-process-wrapper/master/restart.sh && \
34+
wget --output-document /start.sh --quiet https://raw.githubusercontent.com/windmilleng/rerun-process-wrapper/master/start.sh && \
35+
chmod +x /start.sh && chmod +x /restart.sh
36+
3337
# Build
3438
ARG ARCH
39+
ARG LDFLAGS
3540
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
36-
go build -a -ldflags '-extldflags "-static"' \
41+
go build -a -ldflags "${LDFLAGS} -extldflags '-static'" \
3742
-o manager .
43+
ENTRYPOINT [ "/start.sh", "/workspace/manager" ]
3844

3945
# Copy the controller-manager into a thin image
4046
FROM gcr.io/distroless/static:latest

Makefile

Lines changed: 144 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ BIN_DIR := bin
3939
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
4040
CLUSTERCTL := $(BIN_DIR)/clusterctl
4141
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
42+
ENVSUBST := $(TOOLS_BIN_DIR)/envsubst
4243
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
4344
MOCKGEN := $(TOOLS_BIN_DIR)/mockgen
45+
CONVERSION_GEN := $(TOOLS_BIN_DIR)/conversion-gen
46+
RELEASE_NOTES_BIN := bin/release-notes
47+
RELEASE_NOTES := $(TOOLS_DIR)/$(RELEASE_NOTES_BIN)
4448

4549
# Define Docker related variables. Releases should modify and double check these vars.
4650
REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
@@ -58,9 +62,21 @@ CRD_ROOT ?= $(MANIFEST_ROOT)/crd/bases
5862
WEBHOOK_ROOT ?= $(MANIFEST_ROOT)/webhook
5963
RBAC_ROOT ?= $(MANIFEST_ROOT)/rbac
6064

65+
# Allow overriding the imagePullPolicy
66+
PULL_POLICY ?= Always
67+
68+
# Hosts running SELinux need :z added to volume mounts
69+
SELINUX_ENABLED := $(shell cat /sys/fs/selinux/enforce 2> /dev/null || echo 0)
70+
71+
ifeq ($(SELINUX_ENABLED),1)
72+
DOCKER_VOL_OPTS?=:z
73+
endif
74+
75+
# Set build time variables including version details
76+
LDFLAGS := $(shell source ./hack/version.sh; version::ldflags)
77+
6178
# Check if binaries exist
6279
HAS_YQ := $(shell command -v yq;)
63-
HAS_ENVSUBST := $(shell command -v envsubst;)
6480

6581
## --------------------------------------
6682
## Help
@@ -97,14 +113,10 @@ test-go: ## Run golang tests
97113
# See:
98114
# * https://github.com/mikefarah/yq/issues/291
99115
# * https://github.com/mikefarah/yq/issues/289
100-
test-generate-examples: $(KUSTOMIZE)
116+
test-generate-examples: $(KUSTOMIZE) $(ENVSUBST)
101117
ifndef HAS_YQ
102118
echo "installing yq"
103-
GO111MODULE=on go get -u github.com/mikefarah/yq@d05391e
104-
endif
105-
ifndef HAS_ENVSUBST
106-
echo "installing envsubst"
107-
go get github.com/a8m/envsubst/cmd/envsubst
119+
GO111MODULE=on go get github.com/mikefarah/yq/v2
108120
endif
109121
# Create a dummy file for test only
110122
mkdir -p tmp/dummy-make-auto-test
@@ -137,12 +149,21 @@ $(CLUSTERCTL): go.mod ## Build clusterctl binary.
137149
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
138150
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
139151

152+
$(ENVSUBST): $(TOOLS_DIR)/go.mod # Build envsubst from tools folder.
153+
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/envsubst github.com/a8m/envsubst/cmd/envsubst
154+
140155
$(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod # Build golangci-lint from tools folder.
141156
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
142157

143158
$(MOCKGEN): $(TOOLS_DIR)/go.mod # Build mockgen from tools folder.
144159
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/mockgen github.com/golang/mock/mockgen
145160

161+
$(CONVERSION_GEN): $(TOOLS_DIR)/go.mod
162+
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/conversion-gen k8s.io/code-generator/cmd/conversion-gen
163+
164+
$(RELEASE_NOTES) : $(TOOLS_DIR)/go.mod
165+
cd $(TOOLS_DIR) && go build -tags tools -o $(BIN_DIR)/release-notes sigs.k8s.io/cluster-api/hack/tools/release
166+
146167
## --------------------------------------
147168
## Linting
148169
## --------------------------------------
@@ -169,17 +190,22 @@ generate: ## Generate code
169190
$(MAKE) generate-manifests
170191

171192
.PHONY: generate-go
172-
generate-go: $(CONTROLLER_GEN) $(MOCKGEN) ## Runs Go related generate targets
173-
go generate ./...
193+
generate-go: $(CONTROLLER_GEN) $(CONVERSION_GEN) $(MOCKGEN) ## Runs Go related generate targets
174194
$(CONTROLLER_GEN) \
175195
paths=./api/... \
176-
object:headerFile=./hack/boilerplate.go.txt
196+
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt
197+
198+
$(CONVERSION_GEN) \
199+
--input-dirs=./api/v1alpha2 \
200+
--output-file-base=zz_generated.conversion \
201+
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt
202+
go generate ./...
177203

178204
.PHONY: generate-manifests
179205
generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
180206
$(CONTROLLER_GEN) \
181207
paths=./api/... \
182-
crd \
208+
crd:crdVersions=v1 \
183209
output:crd:dir=$(CRD_ROOT) \
184210
output:webhook:dir=$(WEBHOOK_ROOT) \
185211
webhook
@@ -190,15 +216,21 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
190216

191217
.PHONY: generate-examples
192218
generate-examples: clean-examples ## Generate examples configurations to run a cluster.
193-
./examples/generate.sh
219+
ifndef HAS_YQ
220+
echo "installing yq"
221+
GO111MODULE=on go get github.com/mikefarah/yq/v2
222+
endif
223+
./examples/generate.sh -f ${OPENSTACK_CONFIG_FILE} ${CLUSTER_NAME} ./examples/_out single-node
194224

195225
## --------------------------------------
196226
## Docker
197227
## --------------------------------------
198228

199229
.PHONY: docker-build
200230
docker-build: ## Build the docker image for controller-manager
201-
docker build --pull --build-arg ARCH=$(ARCH) . -t $(CONTROLLER_IMG)-$(ARCH):$(TAG)
231+
docker build --pull --build-arg ARCH=$(ARCH) --build-arg LDFLAGS="$(LDFLAGS)" . -t $(CONTROLLER_IMG)-$(ARCH):$(TAG)
232+
MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image
233+
$(MAKE) set-manifest-pull-policy
202234

203235
.PHONY: docker-push
204236
docker-push: ## Push the docker image
@@ -226,18 +258,20 @@ docker-push-manifest: ## Push the fat manifest docker image.
226258
## Minimum docker version 18.06.0 is required for creating and pushing manifest images.
227259
docker manifest create --amend $(CONTROLLER_IMG):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(CONTROLLER_IMG)\-&:$(TAG)~g")
228260
@for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${CONTROLLER_IMG}:${TAG} ${CONTROLLER_IMG}-$${arch}:${TAG}; done
229-
docker manifest push --purge $(CONTROLLER_IMG):$(TAG)
261+
docker manifest push --purge ${CONTROLLER_IMG}:${TAG}
262+
MANIFEST_IMG=$(CONTROLLER_IMG) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image
263+
$(MAKE) set-manifest-pull-policy
230264

231265
.PHONY: set-manifest-image
232266
set-manifest-image:
233267
$(info Updating kustomize image patch file for manager resource)
234-
sed -i'' -e 's@image: .*@image: '"${MANIFEST_IMG}:$(MANIFEST_TAG)"'@' ./config/default/manager_image_patch.yaml
268+
sed -i'' -e 's@image: .*@image: '"${MANIFEST_IMG}:$(MANIFEST_TAG)"'@' ./config/manager/manager_image_patch.yaml
235269

236270

237271
.PHONY: set-manifest-pull-policy
238272
set-manifest-pull-policy:
239273
$(info Updating kustomize pull policy file for manager resource)
240-
sed -i'' -e 's@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' ./config/default/manager_pull_policy.yaml
274+
sed -i'' -e 's@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' ./config/manager/manager_pull_policy.yaml
241275

242276
## --------------------------------------
243277
## Release
@@ -250,87 +284,105 @@ $(RELEASE_DIR):
250284
mkdir -p $(RELEASE_DIR)/
251285

252286
.PHONY: release
253-
release: clean-release ## Builds and push container images using the latest git tag for the commit.
287+
release: clean-release ## Builds and push container images using the latest git tag for the commit.
254288
@if [ -z "${RELEASE_TAG}" ]; then echo "RELEASE_TAG is not set"; exit 1; fi
255-
# Push the release image to the staging bucket first.
256-
REGISTRY=$(STAGING_REGISTRY) TAG=$(RELEASE_TAG) \
257-
$(MAKE) docker-build-all docker-push-all
289+
@if ! [ -z "$$(git status --porcelain)" ]; then echo "Your local git repository contains uncommitted changes, use git clean before proceeding."; exit 1; fi
290+
git checkout "${RELEASE_TAG}"
258291
# Set the manifest image to the production bucket.
292+
$(MAKE) set-manifest-image MANIFEST_IMG=$(PROD_REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG)
293+
$(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent
259294
$(MAKE) release-manifests
260295

261296
.PHONY: release-manifests
262297
release-manifests: $(RELEASE_DIR) ## Builds the manifests to publish with a release
263-
MANIFEST_IMG=$(PROD_REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG) \
264-
$(MAKE) set-manifest-image
265-
PULL_POLICY=IfNotPresent $(MAKE) set-manifest-pull-policy
266-
$(KUSTOMIZE) build config/default > $(RELEASE_DIR)/infrastructure-components.yaml
298+
kustomize build config > $(RELEASE_DIR)/infrastructure-components.yaml
299+
300+
.PHONY: release-binary
301+
release-binary: $(RELEASE_DIR)
302+
docker run \
303+
--rm \
304+
-e CGO_ENABLED=0 \
305+
-e GOOS=$(GOOS) \
306+
-e GOARCH=$(GOARCH) \
307+
-v "$$(pwd):/workspace$(DOCKER_VOL_OPTS)" \
308+
-w /workspace \
309+
golang:1.13.8 \
310+
go build -a -ldflags '$(LDFLAGS) -extldflags "-static"' \
311+
-o $(RELEASE_DIR)/$(notdir $(RELEASE_BINARY))-$(GOOS)-$(GOARCH) $(RELEASE_BINARY)
267312

268313
.PHONY: release-staging
269314
release-staging: ## Builds and push container images to the staging bucket.
270315
REGISTRY=$(STAGING_REGISTRY) $(MAKE) docker-build-all docker-push-all release-alias-tag
271316

272-
RELEASE_ALIAS_TAG=$(shell if [ "$(PULL_BASE_REF)" = "master" ]; then echo "latest"; else echo "$(PULL_BASE_REF)"; fi)
317+
RELEASE_ALIAS_TAG=$(PULL_BASE_REF)
273318

274319
.PHONY: release-alias-tag
275320
release-alias-tag: # Adds the tag to the last build tag.
276321
gcloud container images add-tag $(CONTROLLER_IMG):$(TAG) $(CONTROLLER_IMG):$(RELEASE_ALIAS_TAG)
277322

323+
.PHONY: release-notes
324+
release-notes: $(RELEASE_NOTES)
325+
$(RELEASE_NOTES) $(ARGS)
326+
278327
## --------------------------------------
279328
## Development
280329
## --------------------------------------
281330

331+
# This is used in the get-kubeconfig call below in the create-cluster target. It may be overridden by the
332+
# e2e-conformance.sh script, which is why we need it as a variable here.
333+
CLUSTER_NAME ?= test1
334+
335+
# NOTE: do not add 'generate-exmaples' as a prerequisite of this target. It will break e2e conformance testing.
282336
.PHONY: create-cluster
283-
create-cluster: $(CLUSTERCTL) ## Create a development Kubernetes cluster on OpenStack using examples
284-
$(CLUSTERCTL) \
285-
create cluster -v 4 \
286-
--bootstrap-flags="name=clusterapi" \
287-
--bootstrap-type kind \
288-
-m ./examples/_out/controlplane.yaml \
289-
-c ./examples/_out/cluster.yaml \
290-
-p ./examples/_out/provider-components.yaml \
291-
-a ./examples/addons.yaml
292-
293-
294-
.PHONY: create-cluster-management
295-
create-cluster-management: $(CLUSTERCTL) ## Create a development Kubernetes cluster on OpenStack in a KIND management cluster.
296-
kind create cluster --name=clusterapi
337+
create-cluster: $(CLUSTERCTL) $(ENVSUBST) ## Create a development Kubernetes cluster on OpenStack in a KIND management cluster.
338+
@if [ -z `kind get clusters | grep clusterapi` ]; then \
339+
kind create cluster --name=clusterapi; \
340+
fi
341+
@if [ ! -z "${LOAD_IMAGE}" ]; then \
342+
echo "loading ${LOAD_IMAGE} into kind cluster ..." && \
343+
kind --name="clusterapi" load docker-image "${LOAD_IMAGE}"; \
344+
fi
345+
# Install cert manager and wait for availability
346+
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v0.11.1/cert-manager.yaml
347+
kubectl wait --for=condition=Available --timeout=5m apiservice v1beta1.webhook.cert-manager.io
348+
349+
# Deploy CAPI
350+
kubectl apply -f https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.3.0-rc.3/cluster-api-components.yaml
351+
352+
# Deploy CAPO
353+
kustomize build config | $(ENVSUBST) | kubectl apply -f -
354+
355+
# Wait for CAPI pods
356+
kubectl wait --for=condition=Ready --timeout=5m -n capi-system pod -l cluster.x-k8s.io/provider=cluster-api
357+
kubectl wait --for=condition=Ready --timeout=5m -n capi-kubeadm-bootstrap-system pod -l cluster.x-k8s.io/provider=bootstrap-kubeadm
358+
kubectl wait --for=condition=Ready --timeout=5m -n capi-kubeadm-control-plane-system pod -l cluster.x-k8s.io/provider=control-plane-kubeadm
359+
360+
# Wait for CAPO pods
361+
kubectl wait --for=condition=Ready --timeout=5m -n capo-system pod -l cluster.x-k8s.io/provider=infrastructure-openstack
362+
363+
# FIXME:
364+
# Create Cluster.
365+
#sleep 10
366+
#kustomize build templates | $(ENVSUBST) | kubectl apply -f -
367+
297368
# Apply provider-components.
298-
kubectl \
299-
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
300-
create -f examples/_out/provider-components.yaml
369+
kubectl apply -f examples/_out/provider-components.yaml
301370
# Create Cluster.
302-
kubectl \
303-
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
304-
create -f examples/_out/cluster.yaml
371+
kubectl apply -f examples/_out/cluster.yaml
305372
# Create control plane machine.
306-
kubectl \
307-
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
308-
create -f examples/_out/controlplane.yaml
309-
# Get KubeConfig using clusterctl.
310-
$(CLUSTERCTL) \
311-
alpha phases get-kubeconfig -v=3 \
312-
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
313-
--namespace=default \
314-
--cluster-name=test1
315-
# Apply addons on the target cluster, waiting for the control-plane to become available.
316-
$(CLUSTERCTL) \
317-
alpha phases apply-addons -v=3 \
318-
--kubeconfig=./kubeconfig \
319-
-a examples/addons.yaml
373+
kubectl apply -f examples/_out/controlplane.yaml
374+
375+
# Wait for the kubeconfig to become available.
376+
timeout 300 bash -c "while ! kubectl -n $(CLUSTER_NAME) get secrets | grep $(CLUSTER_NAME)-kubeconfig; do sleep 1; done"
377+
# Get kubeconfig and store it locally.
378+
kubectl -n $(CLUSTER_NAME) get secrets $(CLUSTER_NAME)-kubeconfig -o json | jq -r .data.value | base64 --decode > ./kubeconfig
379+
timeout 300 bash -c "while ! kubectl --kubeconfig=./kubeconfig get nodes | grep master; do sleep 1; done"
380+
381+
# Deploy calico
382+
kubectl --kubeconfig=./kubeconfig apply -f https://docs.projectcalico.org/manifests/calico.yaml
383+
# FIXME:
320384
# Create a worker node with MachineDeployment.
321-
kubectl \
322-
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
323-
create -f examples/_out/machinedeployment.yaml
324-
325-
.PHONY: delete-cluster
326-
delete-cluster: $(CLUSTERCTL) ## Deletes the development Kubernetes Cluster "test1"
327-
$(CLUSTERCTL) \
328-
delete cluster -v 4 \
329-
--bootstrap-type kind \
330-
--bootstrap-flags="name=clusterapi" \
331-
--cluster test1 \
332-
--kubeconfig ./kubeconfig \
333-
-p ./examples/_out/provider-components.yaml \
385+
kubectl apply -f examples/_out/machinedeployment.yaml
334386

335387
.PHONY: kind-reset
336388
kind-reset: ## Destroys the "clusterapi" kind cluster.
@@ -359,11 +411,28 @@ clean-temporary: ## Remove all temporary files and folders
359411
clean-release: ## Remove the release folder
360412
rm -rf $(RELEASE_DIR)
361413

414+
# FIXME:
362415
.PHONY: clean-examples
363416
clean-examples: ## Remove all the temporary files generated in the examples folder
364417
rm -rf examples/_out/
365418
rm -f examples/provider-components/provider-components-*.yaml
366419

367-
.PHONY: verify-install
368-
verify-install: ## Checks that you've installed this repository correctly
369-
./hack/verify-install.sh
420+
.PHONY: verify
421+
verify: verify-boilerplate verify-modules verify-gen
422+
423+
.PHONY: verify-boilerplate
424+
verify-boilerplate:
425+
./hack/verify-boilerplate.sh
426+
427+
.PHONY: verify-modules
428+
verify-modules: modules
429+
@if !(git diff --quiet HEAD -- go.sum go.mod hack/tools/go.mod hack/tools/go.sum); then \
430+
git diff; \
431+
echo "go module files are out of date"; exit 1; \
432+
fi
433+
434+
verify-gen: generate
435+
@if !(git diff --quiet HEAD); then \
436+
git diff; \
437+
echo "generated files are out of date, run make generate"; exit 1; \
438+
fi

0 commit comments

Comments
 (0)