-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Austin Abro <[email protected]>
- Loading branch information
1 parent
54ad03c
commit 3a047bc
Showing
1 changed file
with
140 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import ( | |
"strings" | ||
"testing" | ||
|
||
"github.com/defenseunicorns/pkg/helpers/v2" | ||
fluxv2 "github.com/fluxcd/helm-controller/api/v2" | ||
"github.com/stretchr/testify/require" | ||
"github.com/zarf-dev/zarf/src/api/v1alpha1" | ||
|
@@ -265,6 +266,7 @@ func TestCreate(t *testing.T) { | |
version string | ||
repo string | ||
skipFlux bool | ||
pkg v1alpha1.ZarfPackage | ||
expectedPackage string | ||
}{ | ||
{ | ||
|
@@ -274,23 +276,142 @@ func TestCreate(t *testing.T) { | |
repo: "https://repo1.dso.mil/big-bang/bigbang", | ||
skipFlux: false, | ||
expectedPackage: filepath.Join("testdata", "create", "default.yaml"), | ||
pkg: v1alpha1.ZarfPackage{ | ||
APIVersion: "zarf.dev/v1alpha1", | ||
Kind: v1alpha1.ZarfPackageConfig, | ||
Metadata: v1alpha1.ZarfMetadata{ | ||
Name: "bigbang", | ||
}, | ||
Components: []v1alpha1.ZarfComponent{ | ||
{ | ||
Name: "flux", | ||
Required: helpers.BoolPtr(true), | ||
Manifests: []v1alpha1.ZarfManifest{ | ||
{ | ||
Name: "flux-system", | ||
Namespace: "flux-system", | ||
Files: []string{"flux/bb-flux.yaml"}, | ||
}, | ||
}, | ||
Images: []string{ | ||
"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: helpers.BoolPtr(true), | ||
Manifests: []v1alpha1.ZarfManifest{ | ||
{ | ||
Name: "bigbang", | ||
Namespace: "bigbang", | ||
Files: []string{ | ||
"manifests/bb-gitrepository.yaml", | ||
"manifests/bb-zarf-credentials.yaml", | ||
"manifests/bb-helmrelease.yaml", | ||
}, | ||
}, | ||
}, | ||
Images: []string{ | ||
"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: []string{ | ||
"https://repo1.dso.mil/big-bang/[email protected]", | ||
"https://repo1.dso.mil/big-bang/product/packages/[email protected]", | ||
"https://repo1.dso.mil/big-bang/product/packages/[email protected]", | ||
"https://repo1.dso.mil/big-bang/product/packages/[email protected]", | ||
"https://repo1.dso.mil/big-bang/product/packages/[email protected]", | ||
"https://repo1.dso.mil/big-bang/product/packages/[email protected]", | ||
"https://repo1.dso.mil/big-bang/product/packages/[email protected]", | ||
"https://repo1.dso.mil/big-bang/product/packages/[email protected]", | ||
"https://repo1.dso.mil/big-bang/product/packages/[email protected]", | ||
"https://repo1.dso.mil/big-bang/product/packages/[email protected]", | ||
"https://repo1.dso.mil/big-bang/product/packages/[email protected]", | ||
"https://repo1.dso.mil/big-bang/product/packages/[email protected]", | ||
"https://repo1.dso.mil/big-bang/product/packages/[email protected]", | ||
"https://repo1.dso.mil/big-bang/product/packages/[email protected]", | ||
}, | ||
Actions: v1alpha1.ZarfComponentActions{ | ||
OnRemove: v1alpha1.ZarfComponentActionSet{ | ||
Before: []v1alpha1.ZarfComponentAction{ | ||
{ | ||
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: []v1alpha1.NamespacedObjectKindReference{ | ||
{APIVersion: "helm.toolkit.fluxcd.io/v2", Kind: "HelmRelease", Namespace: "bigbang", Name: "grafana"}, | ||
{APIVersion: "helm.toolkit.fluxcd.io/v2", Kind: "HelmRelease", Namespace: "bigbang", Name: "istio"}, | ||
{APIVersion: "helm.toolkit.fluxcd.io/v2", Kind: "HelmRelease", Namespace: "bigbang", Name: "istio-operator"}, | ||
{APIVersion: "helm.toolkit.fluxcd.io/v2", Kind: "HelmRelease", Namespace: "bigbang", Name: "kiali"}, | ||
{APIVersion: "helm.toolkit.fluxcd.io/v2", Kind: "HelmRelease", Namespace: "bigbang", Name: "kyverno"}, | ||
{APIVersion: "helm.toolkit.fluxcd.io/v2", Kind: "HelmRelease", Namespace: "bigbang", Name: "kyverno-policies"}, | ||
{APIVersion: "helm.toolkit.fluxcd.io/v2", Kind: "HelmRelease", Namespace: "bigbang", Name: "kyverno-reporter"}, | ||
{APIVersion: "helm.toolkit.fluxcd.io/v2", Kind: "HelmRelease", Namespace: "bigbang", Name: "loki"}, | ||
{APIVersion: "helm.toolkit.fluxcd.io/v2", Kind: "HelmRelease", Namespace: "bigbang", Name: "monitoring"}, | ||
{APIVersion: "helm.toolkit.fluxcd.io/v2", Kind: "HelmRelease", Namespace: "bigbang", Name: "neuvector"}, | ||
{APIVersion: "helm.toolkit.fluxcd.io/v2", Kind: "HelmRelease", Namespace: "bigbang", Name: "promtail"}, | ||
{APIVersion: "helm.toolkit.fluxcd.io/v2", Kind: "HelmRelease", Namespace: "bigbang", Name: "tempo"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "skip flux", | ||
airgap: true, | ||
version: "2.35.0", | ||
repo: "https://repo1.dso.mil/big-bang/bigbang", | ||
skipFlux: true, | ||
expectedPackage: filepath.Join("testdata", "create", "skip_flux.yaml"), | ||
}, | ||
{ | ||
name: "Not air gapped", | ||
airgap: false, | ||
version: "2.35.0", | ||
repo: "https://repo1.dso.mil/big-bang/bigbang", | ||
skipFlux: false, | ||
expectedPackage: filepath.Join("testdata", "create", "not_airgap.yaml"), | ||
}, | ||
// { | ||
// name: "skip flux", | ||
// airgap: true, | ||
// version: "2.35.0", | ||
// repo: "https://repo1.dso.mil/big-bang/bigbang", | ||
// skipFlux: true, | ||
// expectedPackage: filepath.Join("testdata", "create", "skip_flux.yaml"), | ||
// }, | ||
// { | ||
// name: "Not air gapped", | ||
// airgap: false, | ||
// version: "2.35.0", | ||
// repo: "https://repo1.dso.mil/big-bang/bigbang", | ||
// skipFlux: false, | ||
// expectedPackage: filepath.Join("testdata", "create", "not_airgap.yaml"), | ||
// }, | ||
} | ||
|
||
for _, tt := range tests { | ||
|
@@ -309,24 +430,19 @@ func TestCreate(t *testing.T) { | |
err := Create(context.Background(), bbOpts) | ||
require.NoError(t, err) | ||
|
||
expectedContent, err := os.ReadFile(tt.expectedPackage) | ||
require.NoError(t, err) | ||
var expectedPkg v1alpha1.ZarfPackage | ||
err = yaml.Unmarshal(expectedContent, &expectedPkg) | ||
require.NoError(t, err) | ||
actualContent, err := os.ReadFile(filepath.Join(tempDir, "zarf.yaml")) | ||
require.NoError(t, err) | ||
var actualPkg v1alpha1.ZarfPackage | ||
err = yaml.Unmarshal(actualContent, &actualPkg) | ||
require.NoError(t, err) | ||
for i, c := range actualPkg.Components { | ||
for i, c := range tt.pkg.Components { | ||
for j, m := range c.Manifests { | ||
for k, f := range m.Files { | ||
actualPkg.Components[i].Manifests[j].Files[k] = strings.TrimPrefix(f, fmt.Sprintf("%s/", tempDir)) | ||
tt.pkg.Components[i].Manifests[j].Files[k] = fmt.Sprintf("%s/%s", tempDir, f) | ||
} | ||
} | ||
} | ||
require.Equal(t, expectedPkg, actualPkg) | ||
require.Equal(t, tt.pkg, actualPkg) | ||
}) | ||
} | ||
} |