From 7be99b9ce36dd86b3d2f8c18ac3d047b66854118 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 19 Sep 2024 13:26:26 +0000 Subject: [PATCH] add type meta Signed-off-by: Austin Abro --- examples/bb-generate/zarf.yaml | 260 +++++++++++++-------------- src/internal/bigbang/bigbang.go | 23 +-- src/internal/bigbang/bigbang_test.go | 12 +- src/internal/bigbang/flux.go | 15 +- 4 files changed, 158 insertions(+), 152 deletions(-) diff --git a/examples/bb-generate/zarf.yaml b/examples/bb-generate/zarf.yaml index fbb5b4ef32..30b75ed80d 100644 --- a/examples/bb-generate/zarf.yaml +++ b/examples/bb-generate/zarf.yaml @@ -3,137 +3,137 @@ kind: ZarfPackageConfig metadata: name: bigbang components: - - name: flux - required: true - manifests: - - name: flux-system - namespace: flux-system - files: - - flux/bb-flux.yaml - images: - - registry1.dso.mil/ironbank/fluxcd/source-controller:v1.3.0 - - registry1.dso.mil/ironbank/fluxcd/kustomize-controller:v1.3.0 - - registry1.dso.mil/ironbank/fluxcd/helm-controller:v1.0.1 - - registry1.dso.mil/ironbank/fluxcd/notification-controller:v1.3.0 +- name: flux + required: true + manifests: + - name: flux-system + namespace: flux-system + files: + - flux/bb-flux.yaml + images: + - registry1.dso.mil/ironbank/fluxcd/source-controller:v1.3.0 + - registry1.dso.mil/ironbank/fluxcd/kustomize-controller:v1.3.0 + - registry1.dso.mil/ironbank/fluxcd/helm-controller:v1.0.1 + - registry1.dso.mil/ironbank/fluxcd/notification-controller:v1.3.0 +- name: bigbang + required: true + manifests: - name: bigbang - required: true - manifests: - - name: bigbang - namespace: bigbang - files: - - manifests/bb-gitrepository.yaml - - manifests/bb-zarf-credentials.yaml - - values-files/ingress.yaml - - values-files/kyverno.yaml - - values-files/loki.yaml - - values-files/neuvector.yaml - - manifests/bb-helmrelease.yaml - images: - - registry1.dso.mil/ironbank/big-bang/grafana/grafana-plugins:11.1.4 - - registry1.dso.mil/ironbank/kiwigrid/k8s-sidecar:1.27.5 - - registry1.dso.mil/ironbank/big-bang/base:2.1.0 - - registry1.dso.mil/ironbank/opensource/istio/pilot:1.22.4 - - registry1.dso.mil/ironbank/opensource/istio/proxyv2:1.22.4 - - registry1.dso.mil/ironbank/opensource/istio/operator:1.22.4 - - registry1.dso.mil/ironbank/opensource/kiali/kiali:v1.89.0 - - registry1.dso.mil/ironbank/opensource/kiali/kiali-operator:v1.89.1 - - registry1.dso.mil/ironbank/opensource/kyverno:v1.12.5 - - registry1.dso.mil/ironbank/opensource/kyverno/kyvernopre:v1.12.5 - - registry1.dso.mil/ironbank/opensource/kubernetes/kubectl:v1.29.7 - - registry1.dso.mil/ironbank/redhat/ubi/ubi9-minimal:9.4 - - registry1.dso.mil/ironbank/opensource/kyverno/kyverno/reports-controller:v1.12.5 - - registry1.dso.mil/ironbank/opensource/kyverno/kyverno/background-controller:v1.12.5 - - registry1.dso.mil/ironbank/opensource/kyverno/kyverno/cleanup-controller:v1.12.5 - - registry1.dso.mil/ironbank/opensource/kyverno/kyvernocli:v1.12.5 - - registry1.dso.mil/ironbank/opensource/kyverno/policy-reporter:2.20.1 - - registry1.dso.mil/ironbank/opensource/grafana/loki:3.1.1 - - registry1.dso.mil/ironbank/opensource/kubernetes-sigs/metrics-server:v0.7.1 - - registry1.dso.mil/ironbank/opensource/prometheus/alertmanager:v0.27.0 - - registry1.dso.mil/ironbank/opensource/kubernetes/kubectl:v1.29.6 - - registry1.dso.mil/ironbank/opensource/kubernetes/kube-state-metrics:v2.12.0 - - registry1.dso.mil/ironbank/opensource/ingress-nginx/kube-webhook-certgen:v1.3.0 - - registry1.dso.mil/ironbank/opensource/prometheus/prometheus:v2.53.0 - - registry1.dso.mil/ironbank/opensource/prometheus-operator/prometheus-config-reloader:v0.75.0 - - registry1.dso.mil/ironbank/opensource/prometheus-operator/prometheus-operator:v0.75.0 - - registry1.dso.mil/ironbank/opensource/prometheus/node-exporter:v1.8.1 - - registry1.dso.mil/ironbank/opensource/thanos/thanos:v0.35.1 - - registry1.dso.mil/ironbank/neuvector/neuvector/controller:5.3.4 - - registry1.dso.mil/ironbank/neuvector/neuvector/enforcer:5.3.4 - - registry1.dso.mil/ironbank/neuvector/neuvector/manager:5.3.4 - - registry1.dso.mil/ironbank/neuvector/neuvector/scanner:5 - - registry1.dso.mil/ironbank/neuvector/neuvector/prometheus-exporter:5.3.2 - - registry1.dso.mil/ironbank/opensource/grafana/promtail:v3.0.0 - - registry1.dso.mil/ironbank/opensource/grafana/tempo:2.5.0 - - registry1.dso.mil/ironbank/opensource/grafana/tempo-query:2.5.0 - repos: - - https://repo1.dso.mil/big-bang/bigbang@2.35.0 - - https://repo1.dso.mil/big-bang/product/packages/grafana.git@8.4.6-bb.1 - - https://repo1.dso.mil/big-bang/product/packages/istio-controlplane.git@1.22.4-bb.1 - - https://repo1.dso.mil/big-bang/product/packages/istio-operator.git@1.22.4-bb.0 - - https://repo1.dso.mil/big-bang/product/packages/kiali.git@1.89.0-bb.0 - - https://repo1.dso.mil/big-bang/product/packages/kyverno-policies.git@3.2.5-bb.3 - - https://repo1.dso.mil/big-bang/product/packages/kyverno-reporter.git@2.24.1-bb.0 - - https://repo1.dso.mil/big-bang/product/packages/kyverno.git@3.2.6-bb.0 - - https://repo1.dso.mil/big-bang/product/packages/loki.git@6.10.0-bb.0 - - https://repo1.dso.mil/big-bang/product/packages/metrics-server.git@3.12.1-bb.4 - - https://repo1.dso.mil/big-bang/product/packages/monitoring.git@62.1.0-bb.0 - - https://repo1.dso.mil/big-bang/product/packages/neuvector.git@2.7.8-bb.1 - - https://repo1.dso.mil/big-bang/product/packages/promtail.git@6.16.2-bb.3 - - https://repo1.dso.mil/big-bang/product/packages/tempo.git@1.10.3-bb.0 - actions: - onRemove: - before: - - cmd: ./zarf tools kubectl patch helmrelease -n bigbang bigbang --type=merge -p '{"spec":{"suspend":true}}' - description: Suspend Big Bang HelmReleases to prevent reconciliation during removal. - healthChecks: - - apiVersion: v1 - kind: HelmRelease - namespace: bigbang - name: grafana - - apiVersion: v1 - kind: HelmRelease - namespace: bigbang - name: istio - - apiVersion: v1 - kind: HelmRelease - namespace: bigbang - name: istio-operator - - apiVersion: v1 - kind: HelmRelease - namespace: bigbang - name: kiali - - apiVersion: v1 - kind: HelmRelease - namespace: bigbang - name: kyverno - - apiVersion: v1 - kind: HelmRelease - namespace: bigbang - name: kyverno-policies - - apiVersion: v1 - kind: HelmRelease - namespace: bigbang - name: kyverno-reporter - - apiVersion: v1 - kind: HelmRelease - namespace: bigbang - name: loki - - apiVersion: v1 - kind: HelmRelease - namespace: bigbang - name: monitoring - - apiVersion: v1 - kind: HelmRelease - namespace: bigbang - name: neuvector - - apiVersion: v1 - kind: HelmRelease - namespace: bigbang - name: promtail - - apiVersion: v1 - kind: HelmRelease - namespace: bigbang - name: tempo + namespace: bigbang + files: + - manifests/bb-gitrepository.yaml + - manifests/bb-zarf-credentials.yaml + - values-files/ingress.yaml + - values-files/kyverno.yaml + - values-files/loki.yaml + - values-files/neuvector.yaml + - manifests/bb-helmrelease.yaml + images: + - registry1.dso.mil/ironbank/big-bang/grafana/grafana-plugins:11.1.4 + - registry1.dso.mil/ironbank/kiwigrid/k8s-sidecar:1.27.5 + - registry1.dso.mil/ironbank/big-bang/base:2.1.0 + - registry1.dso.mil/ironbank/opensource/istio/pilot:1.22.4 + - registry1.dso.mil/ironbank/opensource/istio/proxyv2:1.22.4 + - registry1.dso.mil/ironbank/opensource/istio/operator:1.22.4 + - registry1.dso.mil/ironbank/opensource/kiali/kiali:v1.89.0 + - registry1.dso.mil/ironbank/opensource/kiali/kiali-operator:v1.89.1 + - registry1.dso.mil/ironbank/opensource/kyverno:v1.12.5 + - registry1.dso.mil/ironbank/opensource/kyverno/kyvernopre:v1.12.5 + - registry1.dso.mil/ironbank/opensource/kubernetes/kubectl:v1.29.7 + - registry1.dso.mil/ironbank/redhat/ubi/ubi9-minimal:9.4 + - registry1.dso.mil/ironbank/opensource/kyverno/kyverno/reports-controller:v1.12.5 + - registry1.dso.mil/ironbank/opensource/kyverno/kyverno/background-controller:v1.12.5 + - registry1.dso.mil/ironbank/opensource/kyverno/kyverno/cleanup-controller:v1.12.5 + - registry1.dso.mil/ironbank/opensource/kyverno/kyvernocli:v1.12.5 + - registry1.dso.mil/ironbank/opensource/kyverno/policy-reporter:2.20.1 + - registry1.dso.mil/ironbank/opensource/grafana/loki:3.1.1 + - registry1.dso.mil/ironbank/opensource/kubernetes-sigs/metrics-server:v0.7.1 + - registry1.dso.mil/ironbank/opensource/prometheus/alertmanager:v0.27.0 + - registry1.dso.mil/ironbank/opensource/kubernetes/kubectl:v1.29.6 + - registry1.dso.mil/ironbank/opensource/kubernetes/kube-state-metrics:v2.12.0 + - registry1.dso.mil/ironbank/opensource/ingress-nginx/kube-webhook-certgen:v1.3.0 + - registry1.dso.mil/ironbank/opensource/prometheus/prometheus:v2.53.0 + - registry1.dso.mil/ironbank/opensource/prometheus-operator/prometheus-config-reloader:v0.75.0 + - registry1.dso.mil/ironbank/opensource/prometheus-operator/prometheus-operator:v0.75.0 + - registry1.dso.mil/ironbank/opensource/prometheus/node-exporter:v1.8.1 + - registry1.dso.mil/ironbank/opensource/thanos/thanos:v0.35.1 + - registry1.dso.mil/ironbank/neuvector/neuvector/controller:5.3.4 + - registry1.dso.mil/ironbank/neuvector/neuvector/enforcer:5.3.4 + - registry1.dso.mil/ironbank/neuvector/neuvector/manager:5.3.4 + - registry1.dso.mil/ironbank/neuvector/neuvector/scanner:5 + - registry1.dso.mil/ironbank/neuvector/neuvector/prometheus-exporter:5.3.2 + - registry1.dso.mil/ironbank/opensource/grafana/promtail:v3.0.0 + - registry1.dso.mil/ironbank/opensource/grafana/tempo:2.5.0 + - registry1.dso.mil/ironbank/opensource/grafana/tempo-query:2.5.0 + repos: + - https://repo1.dso.mil/big-bang/bigbang@2.35.0 + - https://repo1.dso.mil/big-bang/product/packages/grafana.git@8.4.6-bb.1 + - https://repo1.dso.mil/big-bang/product/packages/istio-controlplane.git@1.22.4-bb.1 + - https://repo1.dso.mil/big-bang/product/packages/istio-operator.git@1.22.4-bb.0 + - https://repo1.dso.mil/big-bang/product/packages/kiali.git@1.89.0-bb.0 + - https://repo1.dso.mil/big-bang/product/packages/kyverno-policies.git@3.2.5-bb.3 + - https://repo1.dso.mil/big-bang/product/packages/kyverno-reporter.git@2.24.1-bb.0 + - https://repo1.dso.mil/big-bang/product/packages/kyverno.git@3.2.6-bb.0 + - https://repo1.dso.mil/big-bang/product/packages/loki.git@6.10.0-bb.0 + - https://repo1.dso.mil/big-bang/product/packages/metrics-server.git@3.12.1-bb.4 + - https://repo1.dso.mil/big-bang/product/packages/monitoring.git@62.1.0-bb.0 + - https://repo1.dso.mil/big-bang/product/packages/neuvector.git@2.7.8-bb.1 + - https://repo1.dso.mil/big-bang/product/packages/promtail.git@6.16.2-bb.3 + - https://repo1.dso.mil/big-bang/product/packages/tempo.git@1.10.3-bb.0 + actions: + onRemove: + before: + - cmd: ./zarf tools kubectl patch helmrelease -n bigbang bigbang --type=merge -p '{"spec":{"suspend":true}}' + description: Suspend Big Bang HelmReleases to prevent reconciliation during removal. + healthChecks: + - apiVersion: v1 + kind: HelmRelease + namespace: bigbang + name: grafana + - apiVersion: v1 + kind: HelmRelease + namespace: bigbang + name: istio + - apiVersion: v1 + kind: HelmRelease + namespace: bigbang + name: istio-operator + - apiVersion: v1 + kind: HelmRelease + namespace: bigbang + name: kiali + - apiVersion: v1 + kind: HelmRelease + namespace: bigbang + name: kyverno + - apiVersion: v1 + kind: HelmRelease + namespace: bigbang + name: kyverno-policies + - apiVersion: v1 + kind: HelmRelease + namespace: bigbang + name: kyverno-reporter + - apiVersion: v1 + kind: HelmRelease + namespace: bigbang + name: loki + - apiVersion: v1 + kind: HelmRelease + namespace: bigbang + name: monitoring + - apiVersion: v1 + kind: HelmRelease + namespace: bigbang + name: neuvector + - apiVersion: v1 + kind: HelmRelease + namespace: bigbang + name: promtail + - apiVersion: v1 + kind: HelmRelease + namespace: bigbang + name: tempo # YAML keys starting with `x-` are custom keys that are ignored by the Zarf CLI # The `x-mdx` key is used to render the markdown content for https://docs.zarf.dev/ref/examples diff --git a/src/internal/bigbang/bigbang.go b/src/internal/bigbang/bigbang.go index 43adae6268..5a2a6c7e43 100644 --- a/src/internal/bigbang/bigbang.go +++ b/src/internal/bigbang/bigbang.go @@ -179,7 +179,7 @@ func Create(ctx context.Context, bbOpts Opts) error { // Sort so the dependencies are always the same between runs sort.Slice(hrDependencies, func(i, j int) bool { - return hrDependencies[i].Metadata.Name < hrDependencies[j].Metadata.Name + return hrDependencies[i].metadata.Name < hrDependencies[j].metadata.Name }) // Add wait actions for each of the helm releases in generally the order they should be deployed. @@ -188,15 +188,15 @@ func Create(ctx context.Context, bbOpts Opts) error { // The check it, we need to look for the existence of APIService instead of the HelmRelease, which // may not ever be created. See links below for more details. // https://repo1.dso.mil/big-bang/bigbang/-/blob/1.54.0/chart/templates/metrics-server/helmrelease.yaml - if hr.Metadata.Name == "metrics-server" { + if hr.metadata.Name == "metrics-server" { continue } healthCheck := v1alpha1.NamespacedObjectKindReference{ APIVersion: "v1", Kind: "HelmRelease", - Name: hr.Metadata.Name, - Namespace: hr.Metadata.Namespace, + Name: hr.metadata.Name, + Namespace: hr.metadata.Namespace, } bbComponent.HealthChecks = append(bbComponent.HealthChecks, healthCheck) @@ -211,8 +211,8 @@ func Create(ctx context.Context, bbOpts Opts) error { // Select the images needed to support the repos for this configuration of Big Bang. if bbOpts.Airgap { for _, hr := range hrDependencies { - namespacedName := getNamespacedNameFromMeta(hr.Metadata) - gitRepo := gitRepos[hr.NamespacedSource] + namespacedName := getNamespacedNameFromMeta(hr.metadata) + gitRepo := gitRepos[hr.namespacedSource] values := hrValues[namespacedName] images, err := findImagesForBBChartRepo(ctx, gitRepo, values) @@ -353,10 +353,11 @@ func findBBResources(t string) (map[string]string, []HelmReleaseDependency, map[ srcNamespacedName := getNamespacedNameFromStr(h.Spec.Chart.Spec.SourceRef.Namespace, h.Spec.Chart.Spec.SourceRef.Name) helmReleaseDeps = append(helmReleaseDeps, HelmReleaseDependency{ - Metadata: h.ObjectMeta, - NamespacedDependencies: deps, - NamespacedSource: srcNamespacedName, - ValuesFrom: h.Spec.ValuesFrom, + typeMeta: h.TypeMeta, + metadata: h.ObjectMeta, + namespacedDependencies: deps, + namespacedSource: srcNamespacedName, + valuesFrom: h.Spec.ValuesFrom, }) case fluxSrcCtrl.GitRepositoryKind: @@ -403,7 +404,7 @@ func findBBResources(t string) (map[string]string, []HelmReleaseDependency, map[ } for _, hr := range helmReleaseDeps { - namespacedName := getNamespacedNameFromMeta(hr.Metadata) + namespacedName := getNamespacedNameFromMeta(hr.metadata) values, err := composeValues(hr, secrets, configMaps) if err != nil { return nil, nil, nil, err diff --git a/src/internal/bigbang/bigbang_test.go b/src/internal/bigbang/bigbang_test.go index a47d634c9f..9d23d74a9e 100644 --- a/src/internal/bigbang/bigbang_test.go +++ b/src/internal/bigbang/bigbang_test.go @@ -67,13 +67,17 @@ func TestFindBBResources(t *testing.T) { }, expectedHelmReleaseDeps: []HelmReleaseDependency{ { - Metadata: metav1.ObjectMeta{ + typeMeta: metav1.TypeMeta{ + Kind: "HelmRelease", + APIVersion: "helm.toolkit.fluxcd.io/v2beta1", + }, + metadata: metav1.ObjectMeta{ Name: "my-helm-release", Namespace: "default", }, - NamespacedDependencies: []string{"istio.another-helm-release"}, - NamespacedSource: "default.my-git-repo", - ValuesFrom: []fluxv2.ValuesReference{ + namespacedDependencies: []string{"istio.another-helm-release"}, + namespacedSource: "default.my-git-repo", + valuesFrom: []fluxv2.ValuesReference{ { Kind: "ConfigMap", Name: "my-configmap", diff --git a/src/internal/bigbang/flux.go b/src/internal/bigbang/flux.go index 806d3c8add..6b762a53ec 100644 --- a/src/internal/bigbang/flux.go +++ b/src/internal/bigbang/flux.go @@ -20,10 +20,11 @@ import ( // HelmReleaseDependency is a struct that represents a Flux Helm Release from an HR DependsOn list. type HelmReleaseDependency struct { - Metadata metav1.ObjectMeta - NamespacedDependencies []string - NamespacedSource string - ValuesFrom []fluxHelmCtrl.ValuesReference + typeMeta metav1.TypeMeta + metadata metav1.ObjectMeta + namespacedDependencies []string + namespacedSource string + valuesFrom []fluxHelmCtrl.ValuesReference } // readFluxImages finds the images Flux needs to deploy @@ -70,9 +71,9 @@ func readFluxImages(fluxFilePath string) (images []string, err error) { func composeValues(hr HelmReleaseDependency, secrets map[string]corev1.Secret, configMaps map[string]corev1.ConfigMap) (valuesMap chartutil.Values, err error) { valuesMap = chartutil.Values{} - for _, v := range hr.ValuesFrom { + for _, v := range hr.valuesFrom { var valuesData string - namespacedName := getNamespacedNameFromStr(hr.Metadata.Namespace, v.Name) + namespacedName := getNamespacedNameFromStr(hr.metadata.Namespace, v.Name) switch v.Kind { case "ConfigMap": @@ -101,7 +102,7 @@ func composeValues(hr HelmReleaseDependency, secrets map[string]corev1.Secret, c values, err := chartutil.ReadValues([]byte(valuesData)) if err != nil { - return nil, fmt.Errorf("unable to read values from key '%s' in %s '%s': %w", v.GetValuesKey(), v.Kind, hr.Metadata.Name, err) + return nil, fmt.Errorf("unable to read values from key '%s' in %s '%s': %w", v.GetValuesKey(), v.Kind, hr.metadata.Name, err) } valuesMap = helpers.MergeMapRecursive(valuesMap, values)