Skip to content

Commit

Permalink
add health checks to schema and compose
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Aug 27, 2024
1 parent e24d055 commit f55468d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 9 deletions.
16 changes: 9 additions & 7 deletions packages/zarf-registry/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion src/api/v1alpha1/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions src/pkg/packager/composer/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions src/pkg/packager/creator/normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions zarf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f55468d

Please sign in to comment.