Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add non versioned Zarf Package type #2926

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/api/v1beta1/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ type GitRepoSource struct {
URL string `json:"url"`
// The sub directory to the chart within a git repo.
Path string `json:"path,omitempty"`
// The Tag of the repo where the helm chart is stored.
Tag string `json:"tag,omitempty"`
}

// LocalRepoSource represents a Helm chart stored locally.
Expand Down
7 changes: 7 additions & 0 deletions src/api/v1beta1/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ func (pkg ZarfPackage) HasImages() bool {
return false
}

func (pkg ZarfPackage) IsAirGap() bool {
if pkg.Metadata.Airgap == nil {
return true
}
return *pkg.Metadata.Airgap
}

// IsSBOMAble checks if a package has contents that an SBOM can be created on (i.e. images, files, or data injections).
func (pkg ZarfPackage) IsSBOMAble() bool {
for _, c := range pkg.Components {
Expand Down
117 changes: 0 additions & 117 deletions src/api/v1beta1/translate.go

This file was deleted.

58 changes: 30 additions & 28 deletions src/extensions/bigbang/bigbang.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
fluxHelmCtrl "github.com/fluxcd/helm-controller/api/v2beta1"
fluxSrcCtrl "github.com/fluxcd/source-controller/api/v1beta2"
"github.com/zarf-dev/zarf/src/api/v1alpha1"
"github.com/zarf-dev/zarf/src/api/v1alpha1/extensions"
"github.com/zarf-dev/zarf/src/internal/packager/helm"
"github.com/zarf-dev/zarf/src/pkg/layout"
"github.com/zarf-dev/zarf/src/pkg/message"
"github.com/zarf-dev/zarf/src/pkg/utils"
"github.com/zarf-dev/zarf/src/pkg/variables"
"github.com/zarf-dev/zarf/src/types"
"helm.sh/helm/v3/pkg/chartutil"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -43,9 +43,9 @@ var tenMins = metav1.Duration{

// Run mutates a component that should deploy Big Bang to a set of manifests
// that contain the flux deployment of Big Bang
func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c v1alpha1.ZarfComponent) (v1alpha1.ZarfComponent, error) {
cfg := c.Extensions.BigBang
manifests := []v1alpha1.ZarfManifest{}
func Run(ctx context.Context, airgap bool, tmpPaths *layout.ComponentPaths, c types.ZarfComponent) (types.ZarfComponent, error) {
cfg := c.DeprecatedExtensions.BigBang
manifests := []types.ZarfManifest{}

validVersionResponse, err := isValidVersion(cfg.Version)

Expand Down Expand Up @@ -76,7 +76,7 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c v1al
// Add the flux manifests to the list of manifests to be pulled down by Zarf.
manifests = append(manifests, fluxManifest)

if !YOLO {
if airgap {
// Add the images to the list of images to be pulled down by Zarf.
c.Images = append(c.Images, images...)
}
Expand All @@ -86,13 +86,15 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c v1al

// Configure helm to pull down the Big Bang chart.
helmCfg := helm.New(
v1alpha1.ZarfChart{
Name: bb,
Namespace: bb,
URL: bbRepo,
Version: cfg.Version,
types.ZarfChart{
Name: bb,
Namespace: bb,
Git: types.GitRepoSource{
URL: bbRepo,
Tag: cfg.Version,
Path: "./chart",
},
ValuesFiles: cfg.ValuesFiles,
GitPath: "./chart",
},
path.Join(tmpPaths.Temp, bb),
path.Join(tmpPaths.Temp, bb, "values"),
Expand All @@ -113,7 +115,7 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c v1al
}

// Add the Big Bang repo to the list of repos to be pulled down by Zarf.
if !YOLO {
if airgap {
bbRepo := fmt.Sprintf("%s@%s", cfg.Repo, cfg.Version)
c.Repos = append(c.Repos, bbRepo)
}
Expand All @@ -122,7 +124,7 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c v1al
if err != nil {
return c, fmt.Errorf("unable to find Big Bang resources: %w", err)
}
if !YOLO {
if airgap {
for _, gitRepo := range gitRepos {
c.Repos = append(c.Repos, gitRepo)
}
Expand All @@ -139,21 +141,21 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c v1al
}

// ten minutes in seconds
maxTotalSeconds := 10 * 60
maxTotalSeconds := time.Duration(10 * 60 * time.Second)

defaultMaxTotalSeconds := c.Actions.OnDeploy.Defaults.MaxTotalSeconds
defaultMaxTotalSeconds := c.Actions.OnDeploy.Defaults.Timeout.Duration
if defaultMaxTotalSeconds > maxTotalSeconds {
maxTotalSeconds = defaultMaxTotalSeconds
}

// Add wait actions for each of the helm releases in generally the order they should be deployed.
for _, hrNamespacedName := range namespacedHelmReleaseNames {
hr := hrDependencies[hrNamespacedName]
action := v1alpha1.ZarfComponentAction{
Description: fmt.Sprintf("Big Bang Helm Release `%s` to be ready", hrNamespacedName),
MaxTotalSeconds: &maxTotalSeconds,
Wait: &v1alpha1.ZarfComponentActionWait{
Cluster: &v1alpha1.ZarfComponentActionWaitCluster{
action := types.ZarfComponentAction{
Description: fmt.Sprintf("Big Bang Helm Release `%s` to be ready", hrNamespacedName),
Timeout: &metav1.Duration{Duration: maxTotalSeconds},
Wait: &types.ZarfComponentActionWait{
Cluster: &types.ZarfComponentActionWaitCluster{
Kind: "HelmRelease",
Name: hr.Metadata.Name,
Namespace: hr.Metadata.Namespace,
Expand All @@ -168,7 +170,7 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c v1al
// https://repo1.dso.mil/big-bang/bigbang/-/blob/1.54.0/chart/templates/metrics-server/helmrelease.yaml
if hr.Metadata.Name == "metrics-server" {
action.Description = "K8s metric server to exist or be deployed by Big Bang"
action.Wait.Cluster = &v1alpha1.ZarfComponentActionWaitCluster{
action.Wait.Cluster = &types.ZarfComponentActionWaitCluster{
Kind: "APIService",
// https://github.com/kubernetes-sigs/metrics-server#compatibility-matrix
Name: "v1beta1.metrics.k8s.io",
Expand All @@ -195,27 +197,27 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c v1al

// Add onFailure actions with additional troubleshooting information.
for _, cmd := range failureGeneral {
c.Actions.OnDeploy.OnFailure = append(c.Actions.OnDeploy.OnFailure, v1alpha1.ZarfComponentAction{
c.Actions.OnDeploy.OnFailure = append(c.Actions.OnDeploy.OnFailure, types.ZarfComponentAction{
Cmd: fmt.Sprintf("./zarf tools kubectl %s", cmd),
})
}

for _, cmd := range failureDebug {
c.Actions.OnDeploy.OnFailure = append(c.Actions.OnDeploy.OnFailure, v1alpha1.ZarfComponentAction{
c.Actions.OnDeploy.OnFailure = append(c.Actions.OnDeploy.OnFailure, types.ZarfComponentAction{
Mute: &t,
Description: "Storing debug information to the log for troubleshooting.",
Cmd: fmt.Sprintf("./zarf tools kubectl %s", cmd),
})
}

// Add a pre-remove action to suspend the Big Bang HelmReleases to prevent reconciliation during removal.
c.Actions.OnRemove.Before = append(c.Actions.OnRemove.Before, v1alpha1.ZarfComponentAction{
c.Actions.OnRemove.Before = append(c.Actions.OnRemove.Before, types.ZarfComponentAction{
Description: "Suspend Big Bang HelmReleases to prevent reconciliation during removal.",
Cmd: `./zarf tools kubectl patch helmrelease -n bigbang bigbang --type=merge -p '{"spec":{"suspend":true}}'`,
})

// Select the images needed to support the repos for this configuration of Big Bang.
if !YOLO {
if airgap {
for _, hr := range hrDependencies {
namespacedName := getNamespacedNameFromMeta(hr.Metadata)
gitRepo := gitRepos[hr.NamespacedSource]
Expand All @@ -234,7 +236,7 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c v1al
}

// Create the flux wrapper around Big Bang for deployment.
manifest, err := addBigBangManifests(YOLO, tmpPaths.Temp, cfg)
manifest, err := addBigBangManifests(airgap, tmpPaths.Temp, cfg)
if err != nil {
return c, err
}
Expand Down Expand Up @@ -453,9 +455,9 @@ func findBBResources(t string) (gitRepos map[string]string, helmReleaseDeps map[
}

// addBigBangManifests creates the manifests component for deploying Big Bang.
func addBigBangManifests(YOLO bool, manifestDir string, cfg *extensions.BigBang) (v1alpha1.ZarfManifest, error) {
func addBigBangManifests(YOLO bool, manifestDir string, cfg *types.BigBang) (types.ZarfManifest, error) {
// Create a manifest component that we add to the zarf package for bigbang.
manifest := v1alpha1.ZarfManifest{
manifest := types.ZarfManifest{
Name: bb,
Namespace: bb,
}
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/bigbang/flux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"github.com/defenseunicorns/pkg/helpers/v2"
fluxHelmCtrl "github.com/fluxcd/helm-controller/api/v2beta1"
"github.com/zarf-dev/zarf/src/api/v1alpha1"
"github.com/zarf-dev/zarf/src/api/v1alpha1/extensions"
"github.com/zarf-dev/zarf/src/internal/packager/kustomize"
"github.com/zarf-dev/zarf/src/pkg/utils"
"github.com/zarf-dev/zarf/src/types"
"helm.sh/helm/v3/pkg/chartutil"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -43,7 +43,7 @@ func (h HelmReleaseDependency) Dependencies() []string {
}

// getFlux Creates a component to deploy Flux.
func getFlux(baseDir string, cfg *extensions.BigBang) (manifest v1alpha1.ZarfManifest, images []string, err error) {
func getFlux(baseDir string, cfg *types.BigBang) (manifest types.ZarfManifest, images []string, err error) {
localPath := path.Join(baseDir, "bb-ext-flux.yaml")
kustomizePath := path.Join(baseDir, "kustomization.yaml")

Expand Down
2 changes: 1 addition & 1 deletion src/internal/packager/helm/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
type Modifier func(*Helm)

// New returns a new Helm config struct.
func New(chart v1alpha1.ZarfChart, chartPath string, valuesPath string, mods ...Modifier) *Helm {
func New(chart types.ZarfChart, chartPath string, valuesPath string, mods ...Modifier) *Helm {
h := &Helm{
chart: chart,

Check failure on line 56 in src/internal/packager/helm/common.go

View workflow job for this annotation

GitHub Actions / validate-docs-and-schema

cannot use chart (variable of type "github.com/zarf-dev/zarf/src/types".ZarfChart) as "github.com/zarf-dev/zarf/src/api/v1alpha1".ZarfChart value in struct literal

Check failure on line 56 in src/internal/packager/helm/common.go

View workflow job for this annotation

GitHub Actions / validate-unit

cannot use chart (variable of type "github.com/zarf-dev/zarf/src/types".ZarfChart) as "github.com/zarf-dev/zarf/src/api/v1alpha1".ZarfChart value in struct literal

Check failure on line 56 in src/internal/packager/helm/common.go

View workflow job for this annotation

GitHub Actions / build-upgrade

cannot use chart (variable of type "github.com/zarf-dev/zarf/src/types".ZarfChart) as "github.com/zarf-dev/zarf/src/api/v1alpha1".ZarfChart value in struct literal

Check failure on line 56 in src/internal/packager/helm/common.go

View workflow job for this annotation

GitHub Actions / build-bigbang

cannot use chart (variable of type "github.com/zarf-dev/zarf/src/types".ZarfChart) as "github.com/zarf-dev/zarf/src/api/v1alpha1".ZarfChart value in struct literal

Check failure on line 56 in src/internal/packager/helm/common.go

View workflow job for this annotation

GitHub Actions / build-e2e

cannot use chart (variable of type "github.com/zarf-dev/zarf/src/types".ZarfChart) as "github.com/zarf-dev/zarf/src/api/v1alpha1".ZarfChart value in struct literal

Check failure on line 56 in src/internal/packager/helm/common.go

View workflow job for this annotation

GitHub Actions / validate-external

cannot use chart (variable of type "github.com/zarf-dev/zarf/src/types".ZarfChart) as "github.com/zarf-dev/zarf/src/api/v1alpha1".ZarfChart value in struct literal

Check failure on line 56 in src/internal/packager/helm/common.go

View workflow job for this annotation

GitHub Actions / codeql-scan (go)

cannot use chart (variable of type "github.com/zarf-dev/zarf/src/types".ZarfChart) as "github.com/zarf-dev/zarf/src/api/v1alpha1".ZarfChart value in struct literal
chartPath: chartPath,
valuesPath: valuesPath,
timeout: config.ZarfDefaultTimeout,
Expand Down
8 changes: 4 additions & 4 deletions src/pkg/packager/creator/normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,17 @@ func (pc *PackageCreator) Output(ctx context.Context, dst *layout.PackagePaths,
return nil
}

func (pc *PackageCreator) processExtensions(ctx context.Context, components []v1alpha1.ZarfComponent, layout *layout.PackagePaths, isYOLO bool) (processedComponents []v1alpha1.ZarfComponent, err error) {
func (pc *PackageCreator) processExtensions(ctx context.Context, pkg types.ZarfPackage, layout *layout.PackagePaths) (processedComponents []types.ZarfComponent, err error) {
// Create component paths and process extensions for each component.
for _, c := range components {
for _, c := range pkg.Components {
componentPaths, err := layout.Components.Create(c)
if err != nil {
return nil, err
}

// Big Bang
if c.Extensions.BigBang != nil {
if c, err = bigbang.Run(ctx, isYOLO, componentPaths, c); err != nil {
if c.DeprecatedExtensions.BigBang != nil {
if c, err = bigbang.Run(ctx, pkg.IsAirGap(), componentPaths, c); err != nil {
return nil, fmt.Errorf("unable to process bigbang extension: %w", err)
}
}
Expand Down
Loading
Loading