From f55468d1b23bf35fb5b8a71994e7de8978824d41 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 27 Aug 2024 18:08:09 +0000 Subject: [PATCH] add health checks to schema and compose Signed-off-by: Austin Abro --- packages/zarf-registry/zarf.yaml | 16 ++++++------ src/api/v1alpha1/component.go | 3 ++- src/pkg/packager/composer/list.go | 1 + src/pkg/packager/creator/normal.go | 9 +++++++ src/pkg/packager/deploy.go | 2 +- zarf.schema.json | 39 ++++++++++++++++++++++++++++++ 6 files changed, 61 insertions(+), 9 deletions(-) diff --git a/packages/zarf-registry/zarf.yaml b/packages/zarf-registry/zarf.yaml index 190eeba4c0..0c6d46ee0d 100644 --- a/packages/zarf-registry/zarf.yaml +++ b/packages/zarf-registry/zarf.yaml @@ -168,15 +168,17 @@ components: namespace: zarf valuesFiles: - registry-values.yaml + healthChecks: + - namespace: zarf + kind: Deployment + apiVersion: apps/v1 + name: zarf-docker-registry images: # This image (or images) must match that used for injection (see zarf-config.toml) - "###ZARF_PKG_TMPL_REGISTRY_IMAGE_DOMAIN######ZARF_PKG_TMPL_REGISTRY_IMAGE###:###ZARF_PKG_TMPL_REGISTRY_IMAGE_TAG###" + + - name: "check-registry" actions: onDeploy: - after: - - wait: - cluster: - kind: deployment - namespace: zarf - name: app=docker-registry - condition: Available + before: + - cmd: "kubectl rollout status deployment/zarf-docker-registry -n zarf" diff --git a/src/api/v1alpha1/component.go b/src/api/v1alpha1/component.go index fe372c7620..8defcfde67 100644 --- a/src/api/v1alpha1/component.go +++ b/src/api/v1alpha1/component.go @@ -81,8 +81,9 @@ func (c ZarfComponent) RequiresCluster() bool { hasManifests := len(c.Manifests) > 0 hasRepos := len(c.Repos) > 0 hasDataInjections := len(c.DataInjections) > 0 + hasHealthChecks := len(c.HealthChecks) > 0 - if hasImages || hasCharts || hasManifests || hasRepos || hasDataInjections { + if hasImages || hasCharts || hasManifests || hasRepos || hasDataInjections || hasHealthChecks { return true } diff --git a/src/pkg/packager/composer/list.go b/src/pkg/packager/composer/list.go index 291fdb71db..b021355739 100644 --- a/src/pkg/packager/composer/list.go +++ b/src/pkg/packager/composer/list.go @@ -337,6 +337,7 @@ func (ic *ImportChain) Compose(ctx context.Context) (composed *v1alpha1.ZarfComp overrideDeprecated(composed, node.ZarfComponent) overrideResources(composed, node.ZarfComponent) overrideActions(composed, node.ZarfComponent) + composed.HealthChecks = append(composed.HealthChecks, node.ZarfComponent.HealthChecks...) bigbang.Compose(composed, node.ZarfComponent, node.relativeToHead) diff --git a/src/pkg/packager/creator/normal.go b/src/pkg/packager/creator/normal.go index 847a22003e..891fc48ca0 100644 --- a/src/pkg/packager/creator/normal.go +++ b/src/pkg/packager/creator/normal.go @@ -77,6 +77,8 @@ func (pc *PackageCreator) LoadPackageDefinition(ctx context.Context, src *layout } warnings = append(warnings, composeWarnings...) + fmt.Println("pkg with health checks: ", pkg) + // After components are composed, template the active package. pkg, templateWarnings, err := FillActiveTemplate(pkg, pc.createOpts.SetVariables) if err != nil { @@ -237,6 +239,7 @@ func (pc *PackageCreator) Assemble(ctx context.Context, dst *layout.PackagePaths // - writes the Zarf package as a tarball to a local directory, // or an OCI registry based on the --output flag func (pc *PackageCreator) Output(ctx context.Context, dst *layout.PackagePaths, pkg *v1alpha1.ZarfPackage) (err error) { + fmt.Println("we are in output") // Process the component directories into compressed tarballs // NOTE: This is purposefully being done after the SBOM cataloging for _, component := range pkg.Components { @@ -256,6 +259,12 @@ func (pc *PackageCreator) Output(ctx context.Context, dst *layout.PackagePaths, return err } + for _, v := range pkg.Components { + for _, x := range v.HealthChecks { + fmt.Print("this is health check: ", x) + } + } + if err := utils.WriteYaml(dst.ZarfYAML, pkg, helpers.ReadUser); err != nil { return fmt.Errorf("unable to write zarf.yaml: %w", err) } diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 03b7b53e31..c70518d7b5 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -236,7 +236,7 @@ func (p *Packager) deployComponents(ctx context.Context) (deployedComponents []t } objs = append(objs, obj) } - err := pkgkubernetes.WaitForReady(ctx, nil, objs) + err := pkgkubernetes.WaitForReady(ctx, p.cluster.Watcher, objs) if err != nil { deployedComponents[idx].Status = types.ComponentStatusFailed return deployedComponents, err diff --git a/zarf.schema.json b/zarf.schema.json index b1fca50208..d5067e42ad 100644 --- a/zarf.schema.json +++ b/zarf.schema.json @@ -169,6 +169,38 @@ "^x-": {} } }, + "NamespacedObjectKindReference": { + "properties": { + "apiVersion": { + "type": "string", + "description": "API Version of the resource" + }, + "kind": { + "type": "string", + "description": "Kind of the resource" + }, + "namespace": { + "type": "string", + "description": "Namespace of the resource" + }, + "name": { + "type": "string", + "description": "Name of the resource" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "apiVersion", + "kind", + "namespace", + "name" + ], + "description": "NamespacedObjectKindReference is a reference to a specific resource in a namespace using its kind and API version.", + "patternProperties": { + "^x-": {} + } + }, "Shell": { "properties": { "windows": { @@ -512,6 +544,13 @@ "actions": { "$ref": "#/$defs/ZarfComponentActions", "description": "Custom commands to run at various stages of a package lifecycle." + }, + "healthChecks": { + "items": { + "$ref": "#/$defs/NamespacedObjectKindReference" + }, + "type": "array", + "description": "List of resources to health check after deployment" } }, "additionalProperties": false,