diff --git a/.envrc b/.envrc index 52ccc1558..73847a166 100644 --- a/.envrc +++ b/.envrc @@ -7,8 +7,8 @@ export DEVBOX_NO_ENVRC_UPDATE=1 eval "$(devbox generate direnv --print-envrc --env-file .dev-envrc)" -dotenv_if_exists '.envrc.local' -dotenv_if_exists '.envrc.e2e' +source_env_if_exists '.envrc.local' +source_env_if_exists '.envrc.e2e' # check out https://www.jetpack.io/devbox/docs/ide_configuration/direnv/ # for more details diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 26e0c2b62..e3db1ebcc 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -234,14 +234,19 @@ jobs: name: Build Docker images run: devbox run -- make release-snapshot + - if: steps.list-changed.outputs.changed == 'true' + name: Export image tag + id: export-image-tag + run: echo test-image-tag="$(devbox run -- gojq -r .version dist/metadata.json)-$(devbox run -- go env GOARCH)" >> "$GITHUB_OUTPUT" + - if: steps.list-changed.outputs.changed == 'true' name: Sideload docker image run: | devbox run -- \ kind load docker-image \ --name "${KIND_CLUSTER_NAME}" \ - "ko.local/cluster-api-runtime-extensions-nutanix:$(devbox run -- gojq -r .version dist/metadata.json)-$(devbox run -- go env GOARCH)" \ - "ghcr.io/nutanix-cloud-native/caren-helm-reg:$(devbox run -- gojq -r .version dist/metadata.json)-$(devbox run -- go env GOARCH)" + "ko.local/cluster-api-runtime-extensions-nutanix:${{ steps.export-image-tag.outputs.test-image-tag }}" \ + "ghcr.io/nutanix-cloud-native/caren-helm-reg:${{ steps.export-image-tag.outputs.test-image-tag }}" - if: steps.list-changed.outputs.changed == 'true' name: Setup Cluster API and cert-manager @@ -253,7 +258,7 @@ jobs: devbox run -- \ ct install \ --config charts/ct-config.yaml \ - --helm-extra-set-args "--set-string image.repository=ko.local/cluster-api-runtime-extensions-nutanix --set-string image.tag=$(devbox run -- gojq -r .version dist/metadata.json)-$(devbox run -- go env GOARCH) --set-string helmRepositoryImage.tag=$(devbox run -- gojq -r .version dist/metadata.json)-$(devbox run -- go env GOARCH)" + --helm-extra-set-args "--set-string image.repository=ko.local/cluster-api-runtime-extensions-nutanix --set-string image.tag=${{ steps.export-image-tag.outputs.test-image-tag }} --set-string helmRepository.images.bundleInitializer.tag=${{ steps.export-image-tag.outputs.test-image-tag }}" env: KUBECONFIG: ${{ env.KIND_KUBECONFIG }} diff --git a/.goreleaser.yml b/.goreleaser.yml index 280792b0b..31560ecd8 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -44,7 +44,7 @@ before: $(helm template {{ .ProjectName }} ./charts/{{ .ProjectName }} \ --namespace caren-system \ --set-string image.tag=v{{ trimprefix .Version "v" }}{{ if .IsSnapshot }}-{{ .Runtime.Goarch }}{{ end }} \ - --set-string helmRepositoryImage.tag=v{{ trimprefix .Version "v" }}{{ if .IsSnapshot }}-{{ .Runtime.Goarch }} \ + --set-string helmRepository.images.bundleInitializer.tag=v{{ trimprefix .Version "v" }}{{ if .IsSnapshot }}-{{ .Runtime.Goarch }} \ --set-string image.repository=ko.local/{{ .ProjectName }}{{ end }} \ ) EOF' @@ -103,9 +103,9 @@ dockers: - image_templates: - 'ghcr.io/nutanix-cloud-native/caren-helm-reg:v{{ trimprefix .Version "v" }}-amd64' use: buildx - dockerfile: ./hack/addons/mindthegap-helm-registry/Dockerfile + dockerfile: ./hack/addons/helm-chart-bundler/Dockerfile extra_files: - - hack/addons/mindthegap-helm-registry/repos.yaml + - hack/addons/helm-chart-bundler/repos.yaml build_flag_templates: - "--platform=linux/amd64" - "--pull" @@ -119,9 +119,9 @@ dockers: - image_templates: - 'ghcr.io/nutanix-cloud-native/caren-helm-reg:v{{ trimprefix .Version "v" }}-arm64' use: buildx - dockerfile: ./hack/addons/mindthegap-helm-registry/Dockerfile + dockerfile: ./hack/addons/helm-chart-bundler/Dockerfile extra_files: - - hack/addons/mindthegap-helm-registry/repos.yaml + - hack/addons/helm-chart-bundler/repos.yaml build_flag_templates: - "--platform=linux/arm64" - "--pull" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 23b7f9139..8a233f758 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -55,7 +55,7 @@ repos: name: addons-repo-yaml entry: make template-helm-repository language: system - files: "hack/addons/mindthegap-helm-registry/repos.yaml" + files: "hack/addons/helm-chart-bundler/repos.yaml" pass_filenames: false - id: check-devbox-lock name: check-devbox-lock diff --git a/charts/cluster-api-runtime-extensions-nutanix/README.md b/charts/cluster-api-runtime-extensions-nutanix/README.md index 15670da7b..b985b0b6c 100644 --- a/charts/cluster-api-runtime-extensions-nutanix/README.md +++ b/charts/cluster-api-runtime-extensions-nutanix/README.md @@ -32,12 +32,16 @@ A Helm chart for cluster-api-runtime-extensions-nutanix | deployment.replicas | int | `1` | | | env | object | `{}` | | | helmAddonsConfigMap | string | `"default-helm-addons-config"` | | -| helmRepositoryImage.pullPolicy | string | `"IfNotPresent"` | | -| helmRepositoryImage.repository | string | `"ghcr.io/nutanix-cloud-native/caren-helm-reg"` | | -| helmRepositoryImage.tag | string | `""` | | -| helmRepositorySecurityContext.fsGroup | int | `65534` | | -| helmRepositorySecurityContext.runAsGroup | int | `65534` | | -| helmRepositorySecurityContext.runAsUser | int | `65534` | | +| helmRepository.enabled | bool | `true` | | +| helmRepository.images.bundleInitializer.pullPolicy | string | `"IfNotPresent"` | | +| helmRepository.images.bundleInitializer.repository | string | `"ghcr.io/nutanix-cloud-native/caren-helm-reg"` | | +| helmRepository.images.bundleInitializer.tag | string | `""` | | +| helmRepository.images.mindthegap.pullPolicy | string | `"IfNotPresent"` | | +| helmRepository.images.mindthegap.repository | string | `"ghcr.io/mesosphere/mindthegap"` | | +| helmRepository.images.mindthegap.tag | string | `"v1.16.0"` | | +| helmRepository.securityContext.fsGroup | int | `65532` | | +| helmRepository.securityContext.runAsGroup | int | `65532` | | +| helmRepository.securityContext.runAsUser | int | `65532` | | | hooks.ccm.aws.helmAddonStrategy.defaultValueTemplateConfigMap.create | bool | `true` | | | hooks.ccm.aws.helmAddonStrategy.defaultValueTemplateConfigMap.name | string | `"default-aws-ccm-helm-values-template"` | | | hooks.ccm.aws.k8sMinorVersionToCCMVersion."1.27" | string | `"v1.27.9"` | | @@ -99,7 +103,6 @@ A Helm chart for cluster-api-runtime-extensions-nutanix | resources.requests.cpu | string | `"100m"` | | | resources.requests.memory | string | `"128Mi"` | | | securityContext.runAsUser | int | `65532` | | -| selfHostedRegistry | bool | `true` | | | service.annotations | object | `{}` | | | service.port | int | `443` | | | service.type | string | `"ClusterIP"` | | diff --git a/charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml b/charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml index 6520f5e5e..dd1947a2a 100644 --- a/charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml +++ b/charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml @@ -10,48 +10,48 @@ data: aws-ccm: | ChartName: aws-cloud-controller-manager ChartVersion: 0.0.8 - RepositoryURL: {{ if .Values.selfHostedRegistry }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://kubernetes.github.io/cloud-provider-aws{{ end }} + RepositoryURL: '{{ if .Values.helmRepository.enabled }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://kubernetes.github.io/cloud-provider-aws{{ end }}' aws-ebs-csi: | ChartName: aws-ebs-csi-driver ChartVersion: 2.35.1 - RepositoryURL: {{ if .Values.selfHostedRegistry }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://kubernetes-sigs.github.io/aws-ebs-csi-driver{{ end }} + RepositoryURL: '{{ if .Values.helmRepository.enabled }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://kubernetes-sigs.github.io/aws-ebs-csi-driver{{ end }}' cilium: | ChartName: cilium ChartVersion: 1.16.2 - RepositoryURL: {{ if .Values.selfHostedRegistry }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://helm.cilium.io/{{ end }} + RepositoryURL: '{{ if .Values.helmRepository.enabled }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://helm.cilium.io/{{ end }}' cluster-autoscaler: | ChartName: cluster-autoscaler ChartVersion: 9.40.0 - RepositoryURL: {{ if .Values.selfHostedRegistry }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://kubernetes.github.io/autoscaler{{ end }} + RepositoryURL: '{{ if .Values.helmRepository.enabled }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://kubernetes.github.io/autoscaler{{ end }}' local-path-provisioner-csi: | ChartName: local-path-provisioner ChartVersion: 0.0.29 - RepositoryURL: {{ if .Values.selfHostedRegistry }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://charts.containeroo.ch{{ end }} + RepositoryURL: '{{ if .Values.helmRepository.enabled }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://charts.containeroo.ch{{ end }}' metallb: | ChartName: metallb ChartVersion: 0.14.8 - RepositoryURL: {{ if .Values.selfHostedRegistry }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://metallb.github.io/metallb{{ end }} + RepositoryURL: '{{ if .Values.helmRepository.enabled }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://metallb.github.io/metallb{{ end }}' nfd: | ChartName: node-feature-discovery ChartVersion: 0.16.4 - RepositoryURL: {{ if .Values.selfHostedRegistry }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://kubernetes-sigs.github.io/node-feature-discovery/charts{{ end }} + RepositoryURL: '{{ if .Values.helmRepository.enabled }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://kubernetes-sigs.github.io/node-feature-discovery/charts{{ end }}' nutanix-ccm: | ChartName: nutanix-cloud-provider ChartVersion: 0.4.1 - RepositoryURL: {{ if .Values.selfHostedRegistry }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://nutanix.github.io/helm/{{ end }} + RepositoryURL: '{{ if .Values.helmRepository.enabled }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://nutanix.github.io/helm/{{ end }}' nutanix-storage-csi: | ChartName: nutanix-csi-storage ChartVersion: 3.1.0 - RepositoryURL: {{ if .Values.selfHostedRegistry }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://nutanix.github.io/helm-releases/{{ end }} + RepositoryURL: '{{ if .Values.helmRepository.enabled }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://nutanix.github.io/helm-releases/{{ end }}' snapshot-controller: | ChartName: snapshot-controller ChartVersion: 3.0.6 - RepositoryURL: {{ if .Values.selfHostedRegistry }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://piraeus.io/helm-charts/{{ end }} + RepositoryURL: '{{ if .Values.helmRepository.enabled }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://piraeus.io/helm-charts/{{ end }}' tigera-operator: | ChartName: tigera-operator ChartVersion: v3.28.2 - RepositoryURL: {{ if .Values.selfHostedRegistry }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://docs.tigera.io/calico/charts{{ end }} + RepositoryURL: '{{ if .Values.helmRepository.enabled }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}https://docs.tigera.io/calico/charts{{ end }}' kind: ConfigMap metadata: creationTimestamp: null - name: {{ .Values.helmAddonsConfigMap }} + name: '{{ .Values.helmAddonsConfigMap }}' diff --git a/charts/cluster-api-runtime-extensions-nutanix/templates/helm-repository.yaml b/charts/cluster-api-runtime-extensions-nutanix/templates/helm-repository.yaml index c6c158014..1d89d0409 100644 --- a/charts/cluster-api-runtime-extensions-nutanix/templates/helm-repository.yaml +++ b/charts/cluster-api-runtime-extensions-nutanix/templates/helm-repository.yaml @@ -3,7 +3,7 @@ # This file contains the manifests to run a helmRepository deployment which contains helm charts for our addons. # The pod is built via goreleaser with configuration from hack/addons. # -{{ if .Values.selfHostedRegistry }} +{{ if .Values.helmRepository.enabled }} apiVersion: cert-manager.io/v1 kind: Issuer metadata: @@ -62,8 +62,8 @@ spec: spec: initContainers: - name: copy-charts - image: "{{ .Values.helmRepositoryImage.repository }}:{{ default $.Chart.AppVersion .Values.helmRepositoryImage.tag }}" - command: ["/bin/sh", "-c", "cp /charts/*.tar /helm-charts"] + image: "{{ .Values.helmRepository.images.bundleInitializer.repository }}:{{ default $.Chart.AppVersion .Values.helmRepository.images.bundleInitializer.tag }}" + command: ["/bin/cp", "-r", "/charts/", "/helm-charts/bundles/"] imagePullPolicy: "{{ .Values.image.pullPolicy }}" volumeMounts: - name: charts-volume @@ -74,13 +74,12 @@ spec: - name: serve protocol: TCP containerPort: 5000 - image: "{{ .Values.helmRepositoryImage.repository }}:{{ default $.Chart.AppVersion .Values.helmRepositoryImage.tag }}" + image: "{{ .Values.helmRepository.images.mindthegap.repository }}:{{ .Values.helmRepository.images.mindthegap.tag }}" imagePullPolicy: "{{ .Values.image.pullPolicy }}" - command: ["/usr/bin/mindthegap"] args: - serve - bundle - - --bundle=/helm-charts/helm-charts-*.tar + - --bundle=/helm-charts/bundles/helm-charts-*.tar - --listen-port=5000 - --listen-address=0.0.0.0 - --tls-private-key-file=/certs/tls.key @@ -101,7 +100,7 @@ spec: periodSeconds: 1 priorityClassName: {{ .Values.priorityClassName }} securityContext: - {{ with .Values.helmRepositorySecurityContext }} + {{ with .Values.helmRepository.securityContext }} {{- toYaml . | nindent 8}} {{- end }} volumes: diff --git a/charts/cluster-api-runtime-extensions-nutanix/values.schema.json b/charts/cluster-api-runtime-extensions-nutanix/values.schema.json index 4406bba58..605bf9320 100644 --- a/charts/cluster-api-runtime-extensions-nutanix/values.schema.json +++ b/charts/cluster-api-runtime-extensions-nutanix/values.schema.json @@ -38,30 +38,57 @@ "helmAddonsConfigMap": { "type": "string" }, - "helmRepositoryImage": { + "helmRepository": { "properties": { - "pullPolicy": { - "type": "string" - }, - "repository": { - "type": "string" - }, - "tag": { - "type": "string" - } - }, - "type": "object" - }, - "helmRepositorySecurityContext": { - "properties": { - "fsGroup": { - "type": "integer" + "enabled": { + "type": "boolean" }, - "runAsGroup": { - "type": "integer" + "images": { + "properties": { + "bundleInitializer": { + "properties": { + "pullPolicy": { + "type": "string" + }, + "repository": { + "type": "string" + }, + "tag": { + "type": "string" + } + }, + "type": "object" + }, + "mindthegap": { + "properties": { + "pullPolicy": { + "type": "string" + }, + "repository": { + "type": "string" + }, + "tag": { + "type": "string" + } + }, + "type": "object" + } + }, + "type": "object" }, - "runAsUser": { - "type": "integer" + "securityContext": { + "properties": { + "fsGroup": { + "type": "integer" + }, + "runAsGroup": { + "type": "integer" + }, + "runAsUser": { + "type": "integer" + } + }, + "type": "object" } }, "type": "object" @@ -575,9 +602,6 @@ }, "type": "object" }, - "selfHostedRegistry": { - "type": "boolean" - }, "service": { "properties": { "annotations": { diff --git a/charts/cluster-api-runtime-extensions-nutanix/values.yaml b/charts/cluster-api-runtime-extensions-nutanix/values.yaml index e09004f82..e68b4fd3d 100644 --- a/charts/cluster-api-runtime-extensions-nutanix/values.yaml +++ b/charts/cluster-api-runtime-extensions-nutanix/values.yaml @@ -110,8 +110,6 @@ hooks: helmAddonsConfigMap: default-helm-addons-config -selfHostedRegistry: true - deployDefaultClusterClasses: true # The ClusterClass and the Templates it references must be in the same namespace @@ -132,10 +130,21 @@ image: tag: "" pullPolicy: IfNotPresent -helmRepositoryImage: - repository: ghcr.io/nutanix-cloud-native/caren-helm-reg - tag: "" - pullPolicy: IfNotPresent +helmRepository: + enabled: true + images: + bundleInitializer: + repository: ghcr.io/nutanix-cloud-native/caren-helm-reg + tag: "" + pullPolicy: IfNotPresent + mindthegap: + repository: ghcr.io/mesosphere/mindthegap + tag: "v1.16.0" + pullPolicy: IfNotPresent + securityContext: + runAsUser: 65532 + runAsGroup: 65532 + fsGroup: 65532 # -- Optional secrets used for pulling the container image imagePullSecrets: [] @@ -160,12 +169,6 @@ resources: securityContext: runAsUser: 65532 -# The helm-repository containers are based on an Alpine image with a different nonroot user -helmRepositorySecurityContext: - runAsUser: 65534 - runAsGroup: 65534 - fsGroup: 65534 - service: annotations: {} type: ClusterIP diff --git a/hack/addons/add-warning-helm-configmap.sh b/hack/addons/add-warning-helm-configmap.sh index 484c229fc..9fea23b40 100755 --- a/hack/addons/add-warning-helm-configmap.sh +++ b/hack/addons/add-warning-helm-configmap.sh @@ -8,6 +8,8 @@ readonly SCRIPT_DIR # shellcheck source=hack/common.sh source "${SCRIPT_DIR}/../common.sh" ASSETS_DIR="$(mktemp -d -p "${TMPDIR:-/tmp}")" +trap 'rm -rf "${ASSETS_DIR}"' EXIT + mv "${GIT_REPO_ROOT}/charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml" "${ASSETS_DIR}/helm-config.yaml" # add warning not to edit file directly cat <"${GIT_REPO_ROOT}/charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml" @@ -19,5 +21,3 @@ $(cat "${GIT_REPO_ROOT}/hack/license-header.yaml.txt") #================================================================= $(cat "${ASSETS_DIR}/helm-config.yaml") EOF - -sed -i s/placeholder/"{{ .Values.helmAddonsConfigMap }}"/g "${GIT_REPO_ROOT}/charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml" diff --git a/hack/addons/generate-mindthegap-repofile.sh b/hack/addons/generate-mindthegap-repofile.sh index dc5406603..c863321bf 100755 --- a/hack/addons/generate-mindthegap-repofile.sh +++ b/hack/addons/generate-mindthegap-repofile.sh @@ -9,15 +9,14 @@ readonly SCRIPT_DIR source "${SCRIPT_DIR}/../common.sh" ASSETS_DIR="$(mktemp -d -p "${TMPDIR:-/tmp}")" +trap 'rm -rf "${ASSETS_DIR}"' EXIT cp "${GIT_REPO_ROOT}/charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml" "${ASSETS_DIR}" -# this sed line is needed because the go library is unable to parse yaml with a template string. -sed -i s/"{{ .Values.helmAddonsConfigMap }}"/placeholder/g "${ASSETS_DIR}/helm-config.yaml" go run "${GIT_REPO_ROOT}/hack/tools/mindthegap-helm-reg/main.go" --input-configmap-file="${ASSETS_DIR}/helm-config.yaml" --output-file="${ASSETS_DIR}/repos.yaml" # add warning not to edit file directly -cat <"${GIT_REPO_ROOT}/hack/addons/mindthegap-helm-registry/repos.yaml" +cat <"${GIT_REPO_ROOT}/hack/addons/helm-chart-bundler/repos.yaml" $(cat "${GIT_REPO_ROOT}/hack/license-header.yaml.txt") #================================================================= diff --git a/hack/addons/mindthegap-helm-registry/Dockerfile b/hack/addons/helm-chart-bundler/Dockerfile similarity index 59% rename from hack/addons/mindthegap-helm-registry/Dockerfile rename to hack/addons/helm-chart-bundler/Dockerfile index 4481e52c5..38c3ed2dd 100644 --- a/hack/addons/mindthegap-helm-registry/Dockerfile +++ b/hack/addons/helm-chart-bundler/Dockerfile @@ -1,19 +1,19 @@ -ARG MINDTHEGAP_VERSION=v1.14.4 +ARG MINDTHEGAP_VERSION=v1.16.0 + FROM --platform=${BUILDPLATFORM} ghcr.io/mesosphere/mindthegap:${MINDTHEGAP_VERSION} as bundle_builder -# this gets called by goreleaser so the copy source has to be the path relative to the repo root. -RUN --mount=source=./hack/addons/mindthegap-helm-registry/repos.yaml,target=/repos.yaml \ +# This gets called by goreleaser so the copy source has to be the path relative to the repo root. +RUN --mount=source=./hack/addons/helm-chart-bundler/repos.yaml,target=/repos.yaml \ ["/ko-app/mindthegap", "create", "bundle", "--helm-charts-file=/repos.yaml", "--output-file=/tmp/helm-charts.tar"] -FROM --platform=${TARGETPLATFORM} ghcr.io/mesosphere/mindthegap:${MINDTHEGAP_VERSION} as mindthegap +FROM --platform=${TARGETPLATFORM} busybox:1.37.0-musl as static-busybox -FROM --platform=${TARGETPLATFORM} alpine:3.20.3 -# Add mindthegap binary that matches TARGETPLATFORM -COPY --from=mindthegap /ko-app/mindthegap /usr/bin/mindthegap +FROM --platform=${TARGETPLATFORM} scratch # Add helm charts for the current version ARG VERSION COPY --from=bundle_builder /tmp/helm-charts.tar /charts/helm-charts-${VERSION}.tar # TODO remove me as soon as its not needed to hold multiple versions of helm charts COPY --from=ghcr.io/nutanix-cloud-native/caren-helm-reg:v0.14.6 /tmp/helm-charts.tar /charts/helm-charts-v0.14.6.tar COPY --from=ghcr.io/nutanix-cloud-native/caren-helm-reg:v0.14.9 /tmp/helm-charts.tar /charts/helm-charts-v0.14.9.tar -VOLUME /certs -ENTRYPOINT /usr/bin/mindthegap + +# Add statically compiled cp to the image used to copy bundles to the mounted PVC at runtime. +COPY --from=static-busybox /bin/cp /bin/cp diff --git a/hack/addons/mindthegap-helm-registry/repos.yaml b/hack/addons/helm-chart-bundler/repos.yaml similarity index 100% rename from hack/addons/mindthegap-helm-registry/repos.yaml rename to hack/addons/helm-chart-bundler/repos.yaml diff --git a/hack/tools/helm-cm/main.go b/hack/tools/helm-cm/main.go index b812c57e8..6a2e9515d 100644 --- a/hack/tools/helm-cm/main.go +++ b/hack/tools/helm-cm/main.go @@ -137,7 +137,7 @@ func createConfigMapFromDir(kustomizeDir string) (*corev1.ConfigMap, error) { finalCM := corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: "placeholder", + Name: "{{ .Values.helmAddonsConfigMap }}", }, TypeMeta: metav1.TypeMeta{ APIVersion: corev1.SchemeGroupVersion.String(), diff --git a/hack/tools/mindthegap-helm-reg/main.go b/hack/tools/mindthegap-helm-reg/main.go index 2e18775e2..53e6dd1dc 100644 --- a/hack/tools/mindthegap-helm-reg/main.go +++ b/hack/tools/mindthegap-helm-reg/main.go @@ -4,16 +4,14 @@ package main import ( "bytes" - "context" "flag" - "fmt" + "log" "os" "path" "gopkg.in/yaml.v2" corev1 "k8s.io/api/core/v1" yamlDecode "k8s.io/apimachinery/pkg/util/yaml" - ctrl "sigs.k8s.io/controller-runtime" ) type HelmChartFromConfigMap struct { @@ -31,8 +29,6 @@ type HelmChartsConfig struct { Repositories map[string]Repository `yaml:"repositories,omitempty"` } -var log = ctrl.LoggerFrom(context.Background()) - func main() { args := os.Args var ( @@ -46,27 +42,32 @@ func main() { "input configmap file to create the mindthegap repo file from") err := flagSet.Parse(args[1:]) if err != nil { - log.Error(err, "failed to parse args") + log.Fatalln("failed to parse args:", err) + } + if outputFile == "" { + log.Fatalln("output file is required") + } + if inputConfigMapFile == "" { + log.Fatalln("input configmap file is required") } fullPath := inputConfigMapFile if !path.IsAbs(fullPath) { wd, err := os.Getwd() if err != nil { - log.Error(err, "failed to get wd") - return + log.Fatalln("failed to get wd:", err) } fullPath = path.Join(wd, inputConfigMapFile) } f, err := os.Open(fullPath) if err != nil { - log.Error(err, "failed to open file") - return + log.Fatalln("failed to open file:", err) } defer f.Close() cm := &corev1.ConfigMap{} err = yamlDecode.NewYAMLOrJSONDecoder(f, 1024).Decode(cm) if err != nil { - log.Error(err, fmt.Sprintf("failed to unmarshal file %s", fullPath)) + f.Close() + log.Fatalf("failed to unmarshal file %s: %v\n", fullPath, err) } out := HelmChartsConfig{ map[string]Repository{}, @@ -75,8 +76,7 @@ func main() { var settings HelmChartFromConfigMap err = yaml.Unmarshal([]byte(info), &settings) if err != nil { - log.Error(err, "failed unmarshl settings") - return + log.Fatalln("failed to unmarshal settings:", err) } out.Repositories[settings.Name] = Repository{ RepoURL: settings.Repository, @@ -89,23 +89,23 @@ func main() { } b, err := yaml.Marshal(out) if err != nil { - log.Error(err, fmt.Sprintf("failed to marshal obj %v", out)) + log.Fatalf("failed to marshal obj %+v: %v", out, err) } fullOutputfilePath := outputFile if !path.IsAbs(outputFile) { wd, err := os.Getwd() if err != nil { - log.Error(err, "failed") + log.Fatalln("failed:", err) } fullOutputfilePath = path.Join(wd, outputFile) } f, err = os.OpenFile(fullOutputfilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o666) if err != nil { - log.Error(err, "failed to create file") + log.Fatalln("failed to create file:", err) } defer f.Close() _, err = bytes.NewBuffer(b).WriteTo(f) if err != nil { - log.Error(err, "failed to write to file") + log.Fatalln("failed to write to file:", err) } } diff --git a/make/addons.mk b/make/addons.mk index 33b12f97b..6bca48beb 100644 --- a/make/addons.mk +++ b/make/addons.mk @@ -83,7 +83,7 @@ generate-mindthegap-repofile: generate-helm-configmap ; $(info $(M) generating h .PHONY: template-helm-repository template-helm-repository: generate-mindthegap-repofile ## this is used by gorealeaser to set the helm value to this. - sed -i '/RepositoryURL:/s#\(RepositoryURL: *\)\(.*\)#\1{{ if .Values.selfHostedRegistry }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}\2{{ end }}#' "./charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml" + yq -i '.data |= (to_entries | map(.value |= (. | fromjson | .RepositoryURL |= "{{ if .Values.helmRepository.enabled }}oci://helm-repository.{{ .Release.Namespace }}.svc/charts{{ else }}" + . + "{{ end }}" | to_yaml)) | from_entries)' ./charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml .PHONY: list-images list-images: diff --git a/make/dev.mk b/make/dev.mk index 9fd2d8421..72a8b53fc 100644 --- a/make/dev.mk +++ b/make/dev.mk @@ -15,7 +15,7 @@ dev.run-on-kind: helm upgrade --install cluster-api-runtime-extensions-nutanix ./charts/cluster-api-runtime-extensions-nutanix \ --set-string image.repository=ko.local/cluster-api-runtime-extensions-nutanix \ --set-string image.tag=$(SNAPSHOT_VERSION) \ - --set-string helmRepositoryImage.tag=$(SNAPSHOT_VERSION) \ + --set-string helmRepository.images.bundleInitializer.tag=$(SNAPSHOT_VERSION) \ --wait --wait-for-jobs kubectl rollout restart deployment cluster-api-runtime-extensions-nutanix kubectl rollout restart deployment helm-repository