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

fix: support registry override for dev deploy (yolo) #3064

Merged
merged 3 commits into from
Oct 22, 2024
Merged
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
11 changes: 9 additions & 2 deletions src/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (

var extractPath string

var defaultRegistry = fmt.Sprintf("%s:%d", helpers.IPV4Localhost, types.ZarfInClusterContainerRegistryNodePort)

var devCmd = &cobra.Command{
Use: "dev",
Aliases: []string{"prepare", "prep"},
Expand Down Expand Up @@ -349,8 +351,7 @@ func init() {
// skip searching cosign artifacts in find images
devFindImagesCmd.Flags().BoolVar(&pkgConfig.FindImagesOpts.SkipCosign, "skip-cosign", false, lang.CmdDevFlagFindImagesSkipCosign)

defaultRegistry := fmt.Sprintf("%s:%d", helpers.IPV4Localhost, types.ZarfInClusterContainerRegistryNodePort)
devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.RegistryURL, "registry-url", defaultRegistry, lang.CmdDevFlagFindImagesRegistry)
devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.RegistryURL, "registry-url", defaultRegistry, lang.CmdDevFlagRegistry)

devLintCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdPackageCreateFlagSet)
devLintCmd.Flags().StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor)
Expand All @@ -364,6 +365,12 @@ func bindDevDeployFlags(v *viper.Viper) {
devDeployFlags.StringToStringVar(&pkgConfig.CreateOpts.RegistryOverrides, "registry-override", v.GetStringMapString(common.VPkgCreateRegistryOverride), lang.CmdPackageCreateFlagRegistryOverride)
devDeployFlags.StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor)

devDeployFlags.StringVar(&pkgConfig.DeployOpts.RegistryURL, "registry-url", defaultRegistry, lang.CmdDevFlagRegistry)
err := devDeployFlags.MarkHidden("registry-url")
if err != nil {
message.Debug("Unable to mark dev-deploy flag as hidden", "error", err)
}

devDeployFlags.StringToStringVar(&pkgConfig.PkgOpts.SetVariables, "deploy-set", v.GetStringMapString(common.VPkgDeploySet), lang.CmdPackageDeployFlagSet)

// Always require adopt-existing-resources flag (no viper)
Expand Down
2 changes: 1 addition & 1 deletion src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ $ zarf package pull oci://ghcr.io/defenseunicorns/packages/dos-games:1.0.0 -a sk
CmdDevFlagRepoChartPath = `If git repos hold helm charts, often found with gitops tools, specify the chart path, e.g. "/" or "/chart"`
CmdDevFlagGitAccount = "User or organization name for the git account that the repos are created under."
CmdDevFlagKubeVersion = "Override the default helm template KubeVersion when performing a package chart template"
CmdDevFlagFindImagesRegistry = "Override the ###ZARF_REGISTRY### value"
CmdDevFlagRegistry = "Override the ###ZARF_REGISTRY### value"
CmdDevFlagFindImagesWhy = "Prints the source manifest for the specified image"
CmdDevFlagFindImagesSkipCosign = "Skip searching for cosign artifacts related to discovered images"

Expand Down
19 changes: 19 additions & 0 deletions src/pkg/packager/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/zarf-dev/zarf/src/pkg/message"
"github.com/zarf-dev/zarf/src/pkg/packager/creator"
"github.com/zarf-dev/zarf/src/pkg/packager/filters"
"github.com/zarf-dev/zarf/src/types"
)

// DevDeploy creates + deploys a package in one shot
Expand Down Expand Up @@ -76,6 +77,24 @@ func (p *Packager) DevDeploy(ctx context.Context) error {

if !p.cfg.CreateOpts.NoYOLO {
p.cfg.Pkg.Metadata.YOLO = true

// Set default builtin values so they exist in case any helm charts rely on them
registryInfo := types.RegistryInfo{Address: p.cfg.DeployOpts.RegistryURL}
if err := registryInfo.FillInEmptyValues(); err != nil {
return err
}
gitServer := types.GitServerInfo{}
if err = gitServer.FillInEmptyValues(); err != nil {
return err
}
artifactServer := types.ArtifactServerInfo{}
artifactServer.FillInEmptyValues()

p.state = &types.ZarfState{
RegistryInfo: registryInfo,
GitServer: gitServer,
ArtifactServer: artifactServer,
}
} else {
p.hpaModified = false
// Reset registry HPA scale down whether an error occurs or not
Expand Down
10 changes: 9 additions & 1 deletion src/test/e2e/99_yolo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,17 @@ func TestDevDeploy(t *testing.T) {
return
}

// Generic test of dev deploy
stdOut, stdErr, err := e2e.Zarf(t, "dev", "deploy", "examples/dos-games")
require.NoError(t, err, stdOut, stdErr)

stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "dos-games", "--confirm")
stdOut, stdErr, err = e2e.Zarf(t, "tools", "kubectl", "delete", "namespace", "dos-games")
require.NoError(t, err, stdOut, stdErr)
Comment on lines +60 to +61
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might just be crazy but I don't think package remove works on something that was dev deployed, so I switched this to just delete the namespace instead...


// Special test of hidden registry-url flag
stdOut, stdErr, err = e2e.Zarf(t, "dev", "deploy", "src/test/packages/99-registry-url", "--registry-url", "ghcr.io")
require.NoError(t, err, stdOut, stdErr)

stdOut, stdErr, err = e2e.Zarf(t, "tools", "kubectl", "delete", "namespace", "registry-url")
require.NoError(t, err, stdOut, stdErr)
}
8 changes: 8 additions & 0 deletions src/test/packages/99-registry-url/registry-url.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
name: registry-url
spec:
containers:
- name: podinfo
image: "###ZARF_REGISTRY###/stefanprodan/podinfo:6.4.0"
16 changes: 16 additions & 0 deletions src/test/packages/99-registry-url/zarf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
kind: ZarfPackageConfig
metadata:
name: registry-url
description: Deploys a simple pod with the special ZARF_REGISTRY value

components:
- name: registry-url
required: true
manifests:
- name: registry-url
namespace: registry-url
noWait: true
files:
- registry-url.yaml
images:
- ghcr.io/stefanprodan/podinfo:6.4.0
2 changes: 2 additions & 0 deletions src/types/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ type ZarfDeployOptions struct {
Timeout time.Duration
// [Library Only] A map of component names to chart names containing Helm Chart values to override values on deploy
ValuesOverridesMap map[string]map[string]map[string]interface{}
// [Dev Deploy Only] Manual override for ###ZARF_REGISTRY###
RegistryURL string
mjnagel marked this conversation as resolved.
Show resolved Hide resolved
}

// ZarfMirrorOptions tracks the user-defined preferences during a package mirror.
Expand Down