Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit fefd213

Browse files
authored
Merge pull request #57 from christopherhein/chore/move-controlplane
⚠️ Moving Control Plane Provider and Infra Provider
2 parents e4eb62c + 12ad851 commit fefd213

File tree

88 files changed

+1205
-369
lines changed

Some content is hidden

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

88 files changed

+1205
-369
lines changed

.dockerignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.github
33
.vscode
44
bin/
5-
**/*.yaml
5+
# **/*.yaml
66
hack/
77
docs/
88
logos/

Dockerfile

+44-10
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,62 @@
1-
# Build the manager binary
2-
FROM golang:1.15 as builder
1+
# syntax=docker/dockerfile:1.1-experimental
2+
3+
# Copyright 2021 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
316

17+
# Build the manager binary
18+
FROM golang:1.16.2 as builder
419
WORKDIR /workspace
20+
21+
# Run this with docker build --build_arg $(go env GOPROXY) to override the goproxy
22+
ARG goproxy=https://proxy.golang.org
23+
ENV GOPROXY=$goproxy
24+
525
# Copy the Go Modules manifests
626
COPY go.mod go.mod
727
COPY go.sum go.sum
8-
# cache deps before building and copying source so that we don't need to re-download as much
28+
# Cache deps before building and copying source so that we don't need to re-download as much
929
# and so that source changes don't invalidate our downloaded layer
10-
RUN go mod download
30+
RUN --mount=type=cache,target=/root/.local/share/golang \
31+
--mount=type=cache,target=/go/pkg/mod \
32+
go mod download
1133

12-
# Copy the go source
34+
# Copy the sources
1335
COPY main.go main.go
14-
COPY apis/ apis/
36+
COPY api/ api/
1537
COPY controllers/ controllers/
16-
COPY certificate/ certificate/
38+
COPY controlplane/ controlplane/
39+
40+
RUN wget --output-document /restart.sh --quiet https://raw.githubusercontent.com/windmilleng/rerun-process-wrapper/master/restart.sh && \
41+
wget --output-document /start.sh --quiet https://raw.githubusercontent.com/windmilleng/rerun-process-wrapper/master/start.sh && \
42+
chmod +x /start.sh && chmod +x /restart.sh
1743

1844
# Build
19-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
45+
ARG package=.
46+
ARG ARCH
47+
ARG LDFLAGS
48+
RUN --mount=type=cache,target=/root/.cache/go-build \
49+
--mount=type=cache,target=/go/pkg/mod \
50+
--mount=type=cache,target=/root/.local/share/golang \
51+
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -ldflags "${LDFLAGS} -extldflags '-static'" -o manager ${package}
52+
ENTRYPOINT [ "/start.sh", "/workspace/manager" ]
2053

2154
# Use distroless as minimal base image to package the manager binary
2255
# Refer to https://github.com/GoogleContainerTools/distroless for more details
2356
FROM gcr.io/distroless/static:nonroot
57+
# Copy the controller-manager into a thin image
2458
WORKDIR /
2559
COPY --from=builder /workspace/manager .
60+
COPY controlplane/nested/component-templates/ ./component-templates/
2661
USER 65532:65532
27-
28-
ENTRYPOINT ["/manager"]
62+
ENTRYPOINT ["/manager"]

Makefile

+107-29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018 The Kubernetes Authors.
1+
# Copyright 2021 The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,9 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# If you update this file, please follow
16-
# https://suva.sh/posts/well-documented-makefiles
17-
1815
# Ensure Make is run with bash shell as some syntax below is bash-specific
1916
SHELL:=/usr/bin/env bash
2017

@@ -61,9 +58,15 @@ REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
6158
endif
6259
STAGING_REGISTRY ?= gcr.io/k8s-staging-cluster-api-provider-nested
6360
PROD_REGISTRY ?= us.gcr.io/k8s-artifacts-prod/cluster-api-provider-nested
61+
62+
# Infrastructure
6463
IMAGE_NAME ?= cluster-api-nested-controller
6564
CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)
6665

66+
# Control Plane
67+
CONTROLPLANE_IMAGE_NAME ?= nested-controlplane-controller
68+
CONTROLPLANE_CONTROLLER_IMG ?= $(REGISTRY)/$(CONTROLPLANE_IMAGE_NAME)
69+
6770
TAG ?= dev
6871
ARCH ?= amd64
6972
ALL_ARCH = amd64 arm arm64 ppc64le s390x
@@ -93,13 +96,18 @@ test: ## Run tests.
9396
.PHONY: binaries
9497
binaries: managers
9598

96-
.PHONY: manager
97-
manager-core: ## Build manager binary
98-
go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/manager sigs.k8s.io/cluster-api-provider-nested
99-
10099
.PHONY: managers
101100
managers: ## Build all managers
102-
$(MAKE) manager-core
101+
$(MAKE) manager-nested-infrastructure
102+
$(MAKE) manager-nested-controlplane
103+
104+
.PHONY: manager-nested-infrastructure
105+
manager-nested-infrastructure:
106+
go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/manager sigs.k8s.io/cluster-api-provider-nested
107+
108+
.PHONY: manager-nested-controlplane
109+
manager-nested-controlplane: ## Build manager binary
110+
go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/nested-controlplane-manager sigs.k8s.io/cluster-api-provider-nested/controlplane/nested
103111

104112
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
105113
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
@@ -150,24 +158,52 @@ generate:
150158
.PHONY: generate-go
151159
generate-go: $(CONTROLLER_GEN) ## Runs Go related generate targets
152160
go generate ./...
161+
$(MAKE) generate-go-infrastructure
162+
$(MAKE) generate-go-controlplane
163+
164+
.PHONY: generate-go-infrastructure
165+
generate-go-infrastructure: $(CONTROLLER_GEN)
166+
$(CONTROLLER_GEN) \
167+
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \
168+
paths=./api/...
169+
170+
generate-go-controlplane: $(CONTROLLER_GEN)
153171
$(CONTROLLER_GEN) \
154172
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \
155-
paths=./apis/...
173+
paths=./controlplane/nested/api/...
156174

157175
.PHONY: generate-manifests
158176
generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
177+
$(MAKE) generate-manifests-infrastructure
178+
$(MAKE) generate-manifests-controlplane
179+
## Copy files in CI folders.
180+
mkdir -p ./config/ci/{rbac,manager}
181+
cp -f ./config/rbac/*.yaml ./config/ci/rbac/
182+
cp -f ./config/manager/manager*.yaml ./config/ci/manager/
183+
184+
.PHONY: generate-manifests-infrastructure
185+
generate-manifests-infrastructure:
159186
$(CONTROLLER_GEN) \
160-
paths=./apis/... \
187+
paths=./api/... \
161188
paths=./controllers/... \
162189
crd:crdVersions=v1 \
163190
rbac:roleName=manager-role \
164191
output:crd:dir=./config/crd/bases \
165192
output:webhook:dir=./config/webhook \
193+
output:rbac:dir=./config/rbac \
194+
webhook
195+
196+
.PHONY: generate-manifests-controlplane
197+
generate-manifests-controlplane:
198+
$(CONTROLLER_GEN) \
199+
paths=./controlplane/nested/api/... \
200+
paths=./controlplane/nested/controllers/... \
201+
crd:crdVersions=v1 \
202+
rbac:roleName=manager-role \
203+
output:crd:dir=./controlplane/nested/config/crd/bases \
204+
output:webhook:dir=./controlplane/nested/config/webhook \
205+
output:rbac:dir=./controlplane/nested/config/rbac \
166206
webhook
167-
## Copy files in CI folders.
168-
mkdir -p ./config/ci/{rbac,manager}
169-
cp -f ./config/rbac/*.yaml ./config/ci/rbac/
170-
cp -f ./config/manager/manager*.yaml ./config/ci/manager/
171207

172208
.PHONY: modules
173209
modules: ## Runs go mod to ensure modules are up to date.
@@ -184,32 +220,63 @@ docker-pull-prerequisites:
184220
docker pull docker.io/library/golang:1.15.3
185221
docker pull gcr.io/distroless/static:latest
186222

187-
.PHONY: docker-build
188-
docker-build: docker-pull-prerequisites ## Build the docker images for controller managers
223+
.PHONY: docker-infrastructure-build
224+
docker-infrastructure-build: docker-pull-prerequisites ## Build the docker images for controller managers
189225
DOCKER_BUILDKIT=1 docker build --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" . -t $(CONTROLLER_IMG)-$(ARCH):$(TAG)
190-
# $(MAKE) set-manifest-image MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="./config/manager/manager_image_patch.yaml"
191-
# $(MAKE) set-manifest-pull-policy TARGET_RESOURCE="./config/manager/manager_pull_policy.yaml"
226+
$(MAKE) set-manifest-image MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="./config/default/manager_image_patch.yaml"
227+
$(MAKE) set-manifest-pull-policy TARGET_RESOURCE="./config/default/manager_pull_policy.yaml"
192228

193-
.PHONY: docker-push
194-
docker-push: ## Push the docker images
229+
.PHONY: docker-controlplane-build
230+
docker-controlplane-build: docker-pull-prerequisites ## Build the docker images for controller managers
231+
DOCKER_BUILDKIT=1 docker build --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" --build-arg package=./controlplane/nested . -t $(CONTROLPLANE_CONTROLLER_IMG)-$(ARCH):$(TAG)
232+
$(MAKE) set-manifest-image MANIFEST_IMG=$(CONTROLPLANE_CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="./controlplane/nested/config/default/manager_image_patch.yaml"
233+
$(MAKE) set-manifest-pull-policy TARGET_RESOURCE="./controlplane/nested/config/default/manager_pull_policy.yaml"
234+
235+
236+
.PHONY: docker-infrastructure-push
237+
docker-infrastructure-push: ## Push the docker images
195238
docker push $(CONTROLLER_IMG)-$(ARCH):$(TAG)
196239

240+
.PHONY: docker-controlplane-push
241+
docker-controlplane-push: ## Push the docker images
242+
docker push $(CONTROLPLANE_CONTROLLER_IMG)-$(ARCH):$(TAG)
243+
197244
## --------------------------------------
198245
## Docker — All ARCH
199246
## --------------------------------------
200247

201248
.PHONY: docker-build-all ## Build all the architecture docker images
202-
docker-build-all: $(addprefix docker-build-,$(ALL_ARCH))
249+
docker-build-all: $(addprefix docker-infrastructure-build-,$(ALL_ARCH)) $(addprefix docker-controlplane-build-,$(ALL_ARCH))
250+
251+
.PHONY: docker-build
252+
docker-build:
253+
$(MAKE) docker-infrastructure-build
254+
$(MAKE) docker-controlplane-build
203255

204-
docker-build-%:
205-
$(MAKE) ARCH=$* docker-build
256+
.PHONY: docker-infrastructure-build
257+
docker-infrastructure-build-%:
258+
$(MAKE) ARCH=$* docker-infrastructure-build
259+
260+
.PHONY: docker-controlplane-build
261+
docker-controlplane-build-%:
262+
$(MAKE) ARCH=$* docker-controlplane-build
206263

207264
.PHONY: docker-push-all ## Push all the architecture docker images
208-
docker-push-all: $(addprefix docker-push-,$(ALL_ARCH))
265+
docker-push-all: $(addprefix docker-infrastructure-push-,$(ALL_ARCH)) $(addprefix docker-controlplane-push-,$(ALL_ARCH))
209266
$(MAKE) docker-push-core-manifest
210267

211-
docker-push-%:
212-
$(MAKE) ARCH=$* docker-push
268+
.PHONY: docker-push
269+
docker-push:
270+
$(MAKE) docker-infrastructure-push
271+
$(MAKE) docker-controlplane-push
272+
273+
.PHONY: docker-infrastructure-push
274+
docker-infrastructure-push-%:
275+
$(MAKE) ARCH=$* docker-infrastructure-push
276+
277+
.PHONY: docker-controlplane-push
278+
docker-controlplane-push-%:
279+
$(MAKE) ARCH=$* docker-controlplane-push
213280

214281
.PHONY: docker-push-core-manifest
215282
docker-push-core-manifest: ## Push the fat manifest docker image for the core image.
@@ -260,17 +327,28 @@ release: clean-release ## Builds and push container images using the latest git
260327
.PHONY: release-manifests
261328
release-manifests: $(RELEASE_DIR) $(KUSTOMIZE) ## Builds the manifests to publish with a release
262329
# Build infrastructure-components.
263-
$(KUSTOMIZE) build config > $(RELEASE_DIR)/infrastructure-components.yaml
330+
$(KUSTOMIZE) build config/default > $(RELEASE_DIR)/infrastructure-components.yaml
331+
# Build control-plane-components.
332+
$(KUSTOMIZE) build controlplane/nested/config/default > $(RELEASE_DIR)/control-plane-components.yaml
333+
334+
## Build cluster-api-provider-nested-components (aggregate of all of the above).
335+
cat $(RELEASE_DIR)/infrastructure-components.yaml > $(RELEASE_DIR)/cluster-api-provider-nested-components.yaml
336+
echo "---" >> $(RELEASE_DIR)/cluster-api-provider-nested-components.yaml
337+
cat $(RELEASE_DIR)/control-plane-components.yaml >> $(RELEASE_DIR)/cluster-api-provider-nested-components.yaml
338+
# Add metadata to the release artifacts
339+
cp metadata.yaml $(RELEASE_DIR)/metadata.yaml
340+
264341

265342
.PHONY: release-staging
266343
release-staging: ## Builds and push container images to the staging bucket.
267-
REGISTRY=$(STAGING_REGISTRY) $(MAKE) docker-build docker-push release-alias-tag
344+
REGISTRY=$(STAGING_REGISTRY) $(MAKE) docker-build-all docker-push-all release-alias-tag
268345

269346
RELEASE_ALIAS_TAG=$(PULL_BASE_REF)
270347

271348
.PHONY: release-alias-tag
272349
release-alias-tag: ## Adds the tag to the last build tag.
273350
gcloud container images add-tag $(CONTROLLER_IMG):$(TAG) $(CONTROLLER_IMG):$(RELEASE_ALIAS_TAG)
351+
gcloud container images add-tag $(CONTROLPLANE_CONTROLLER_IMG):$(TAG) $(CONTROLPLANE_CONTROLLER_IMG):$(RELEASE_ALIAS_TAG)
274352

275353
.PHONY: release-notes
276354
release-notes: $(RELEASE_NOTES) ## Generates a release notes template to be used with a release.

PROJECT

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
11
domain: cluster.x-k8s.io
22
layout:
33
- go.kubebuilder.io/v3
4-
multigroup: true
54
projectName: cluster-api-provider-nested
65
repo: sigs.k8s.io/cluster-api-provider-nested
76
resources:
8-
- group: controlplane
9-
kind: NestedControlPlane
10-
version: v1alpha4
11-
- api:
12-
crdVersion: v1
13-
group: controlplane
14-
kind: NestedEtcd
15-
version: v1alpha4
16-
- api:
17-
crdVersion: v1
18-
group: controlplane
19-
kind: NestedAPIServer
20-
version: v1alpha4
21-
- api:
22-
crdVersion: v1
23-
group: controlplane
24-
kind: NestedControllerManager
25-
version: v1alpha4
267
- api:
278
crdVersion: v1
289
namespaced: true
2910
controller: true
3011
domain: cluster.x-k8s.io
3112
group: infrastructure
3213
kind: NestedCluster
33-
path: sigs.k8s.io/cluster-api-provider-nested/apis/infrastructure/v1alpha4
14+
path: sigs.k8s.io/cluster-api-provider-nested/api/v1alpha4
3415
version: v1alpha4
3516
version: "3"

config/crd/kustomization.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
# It should be run by config/default
44
resources:
55
- bases/infrastructure.cluster.x-k8s.io_nestedclusters.yaml
6-
- bases/controlplane.cluster.x-k8s.io_nestedcontrolplanes.yaml
7-
- bases/controlplane.cluster.x-k8s.io_nestedetcds.yaml
8-
- bases/controlplane.cluster.x-k8s.io_nestedapiservers.yaml
9-
- bases/controlplane.cluster.x-k8s.io_nestedcontrollermanagers.yaml
106
#+kubebuilder:scaffold:crdkustomizeresource
117

128
patchesStrategicMerge:

config/default/kustomization.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace: capn-system
66
commonLabels:
77
# Label to denote name of the infra provider
88
# https://cluster-api.sigs.k8s.io/clusterctl/provider-contract.html#labels
9-
cluster.x-k8s.io/provider: "infrastructure-aws"
9+
cluster.x-k8s.io/provider: "infrastructure-nested"
1010

1111
bases:
1212
- ../crd
@@ -25,6 +25,8 @@ patchesStrategicMerge:
2525
# If you want your controller-manager to expose the /metrics
2626
# endpoint w/o any authn/z, please comment the following line.
2727
- manager_auth_proxy_patch.yaml
28+
- manager_image_patch.yaml
29+
- manager_pull_policy.yaml
2830

2931
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
3032
# crd/kustomization.yaml

config/default/manager_auth_proxy_patch.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ spec:
2121
name: https
2222
- name: manager
2323
args:
24-
- "--metrics-addr=127.0.0.1:8080"
25-
- "--enable-leader-election"
24+
- "--metrics-bind-address=127.0.0.1:8080"
25+
- "--leader-elect"
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
namespace: system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- image: gcr.io/cluster-api-nested-controller-amd64:dev
11+
name: manager

0 commit comments

Comments
 (0)