Skip to content

Commit

Permalink
Support enabling Clusterclass operations via helm install (#1074)
Browse files Browse the repository at this point in the history
* feat: add clusterclass operations to dockerfile

Signed-off-by: Carlos Salas <carlos.salas@suse.com>

* feat: add chart value to enable clusterclass operations controller

Signed-off-by: Carlos Salas <carlos.salas@suse.com>

---------

Signed-off-by: Carlos Salas <carlos.salas@suse.com>
  • Loading branch information
salasberryfin authored Feb 6, 2025
1 parent 830b13d commit b8394d1
Show file tree
Hide file tree
Showing 10 changed files with 860 additions and 31 deletions.
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,35 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
sh -c "cd exp/day2 && ls && go build -trimpath -ldflags \"${ldflags} -extldflags '-static'\" -o manager ${package}"

FROM --platform=$BUILDPLATFORM ${builder_image} as clusterclass-operations-builder
WORKDIR /workspace

# Run this with docker build --build-arg goproxy=$(go env GOPROXY) to override the goproxy
ARG goproxy=https://proxy.golang.org
# Run this with docker build --build-arg package=./exp/etcdrestore
ENV GOPROXY=$goproxy

# Copy the sources
COPY ./ ./

# Build
ARG ldflags
ARG TARGETOS TARGETARCH

# Do not force rebuild of up-to-date packages (do not use -a) and use the compiler cache folder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
sh -c "cd exp/clusterclass && ls && go build -trimpath -ldflags \"${ldflags} -extldflags '-static'\" -o manager ${package}"

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
LABEL org.opencontainers.image.source=https://github.com/rancher/turtles
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=day2-operations-builder /workspace/exp/day2/manager turtles-day2-operations
COPY --from=clusterclass-operations-builder /workspace/exp/clusterclass/manager turtles-clusterclass-operations
# Use uid of nonroot user (65532) because kubernetes expects numeric user when applying pod security policies
USER 65532
ENTRYPOINT ["/manager"]
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ CONTROLLER_IMG ?= $(REGISTRY)/$(ORG)/$(CONTROLLER_IMAGE_NAME)
CONTROLLER_IMAGE_VERSION ?= $(shell git describe --abbrev=0 2>/dev/null)
IID_FILE ?= $(shell mktemp)

# clusterclass
CLUSTERCLASS_IMAGE_NAME ?= turtles-clusterclass-operations
CLUSTERCLASS_IMG ?= $(REGISTRY)/$(ORG)/$(CLUSTERCLASS_IMAGE_NAME)

# Release
# Exclude tags with the prefix 'test/'
RELEASE_TAG ?= $(shell git describe --abbrev=0 --exclude 'test/*' 2>/dev/null)
Expand Down Expand Up @@ -228,6 +224,7 @@ generate: vendor ## Run all generators
$(MAKE) generate-modules
$(MAKE) generate-manifests-api
$(MAKE) generate-exp-day2-manifests-api
$(MAKE) generate-exp-clusterclass-manifests-api
$(MAKE) generate-manifests-external
$(MAKE) generate-go-deepcopy
$(MAKE) vendor-clean
Expand Down Expand Up @@ -278,6 +275,7 @@ generate-go-deepcopy: ## Run deepcopy generation
object:headerFile=./hack/boilerplate.go.txt \
paths=./api/... \
paths=./exp/day2/api/...
paths=./exp/clusterclass/api/...

# Run go mod
.PHONY: vendor
Expand Down Expand Up @@ -329,7 +327,7 @@ updatecli-apply: $(UPDATECLI)
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))

.PHONY: test
test: $(SETUP_ENVTEST) manifests test-exp-day2 ## Run all generators and exp tests.
test: $(SETUP_ENVTEST) manifests test-exp-day2 test-exp-clusterclass ## Run all generators and exp tests.
go clean -testcache
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... $(TEST_ARGS)

Expand Down Expand Up @@ -559,7 +557,9 @@ release: clean-release $(RELEASE_DIR) ## Builds and push container images using
build-chart: $(HELM) $(KUSTOMIZE) $(RELEASE_DIR) $(CHART_RELEASE_DIR) $(CHART_PACKAGE_DIR) ## Builds the chart to publish with a release
$(KUSTOMIZE) build ./config/chart > $(CHART_DIR)/templates/rancher-turtles-components.yaml
$(KUSTOMIZE) build ./exp/day2/config/default > $(CHART_DIR)/templates/rancher-turtles-exp-day2-components.yaml
./scripts/process-exp-day2-manifests.sh $(CHART_DIR)/templates/rancher-turtles-exp-day2-components.yaml
$(KUSTOMIZE) build ./exp/clusterclass/config/default > $(CHART_DIR)/templates/rancher-turtles-exp-clusterclass-components.yaml
./scripts/process-manifests.sh day2-operations $(CHART_DIR)/templates/rancher-turtles-exp-day2-components.yaml
./scripts/process-manifests.sh clusterclass-operations $(CHART_DIR)/templates/rancher-turtles-exp-clusterclass-components.yaml
cp -rf $(CHART_DIR)/* $(CHART_RELEASE_DIR)

sed -i'' -e 's@image: .*@image: '"$(CONTROLLER_IMG)"'@' $(CHART_RELEASE_DIR)/values.yaml
Expand All @@ -570,6 +570,10 @@ build-chart: $(HELM) $(KUSTOMIZE) $(RELEASE_DIR) $(CHART_RELEASE_DIR) $(CHART_PA
sed -i'' -e '/day2-operations:/,/imageVersion:/ s@imageVersion: .*@imageVersion: '"$(RELEASE_TAG)"'@' $(CHART_RELEASE_DIR)/values.yaml
sed -i'' -e '/day2-operations:/,/imagePullPolicy:/ s@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' $(CHART_RELEASE_DIR)/values.yaml

sed -i'' -e '/clusterclass:/,/image:/ s@image: .*@image: '"$(CONTROLLER_IMG)"'@' $(CHART_RELEASE_DIR)/values.yaml
sed -i'' -e '/clusterclass:/,/imageVersion:/ s@imageVersion: .*@imageVersion: '"$(RELEASE_TAG)"'@' $(CHART_RELEASE_DIR)/values.yaml
sed -i'' -e '/clusterclass:/,/imagePullPolicy:/ s@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' $(CHART_RELEASE_DIR)/values.yaml

cd $(CHART_RELEASE_DIR) && $(HELM) dependency update
$(HELM) package $(CHART_RELEASE_DIR) --app-version=$(HELM_CHART_TAG) --version=$(HELM_CHART_TAG) --destination=$(CHART_PACKAGE_DIR)

Expand Down
4 changes: 3 additions & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ projects = {
"internal/",
],
"kustomize_dir": "config/default",
"label": "turtles-clusterclass-operations"
"label": "turtles-clusterclass-operations",
"command": ["/manager"],
"binary_name" : "turtles-clusterclass-operations"
}
}

Expand Down
Loading

0 comments on commit b8394d1

Please sign in to comment.