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: set variables on find images #2282

Merged
merged 87 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
f05eb5e
WIP, now signed
AustinAbro321 Jan 22, 2024
700255f
changing spinnners
AustinAbro321 Jan 22, 2024
1f963bf
revert yaml name change
AustinAbro321 Feb 2, 2024
e7223aa
make test cases more clear, fix helm test case
AustinAbro321 Feb 5, 2024
3b9143d
Merge branch 'main' into set-variables-on-find-images
AustinAbro321 Feb 5, 2024
c5bfbae
delete eks.yaml
AustinAbro321 Feb 5, 2024
32dc518
refactor: name
AustinAbro321 Feb 5, 2024
6c0324a
de-dup text
AustinAbro321 Feb 5, 2024
da4d3fc
simplying test
AustinAbro321 Feb 5, 2024
a0314ad
bettter test name
AustinAbro321 Feb 5, 2024
de984ab
refactor test
AustinAbro321 Feb 5, 2024
5975039
make docs and schema
AustinAbro321 Feb 5, 2024
fc882d8
lint + duplicated code
AustinAbro321 Feb 5, 2024
56a69f3
Apply suggestions from code review
AustinAbro321 Feb 5, 2024
e2efae0
fix suggestions
AustinAbro321 Feb 5, 2024
cf5febd
Merge branch 'main' into set-variables-on-find-images
AustinAbro321 Feb 5, 2024
8d8762d
better name
AustinAbro321 Feb 5, 2024
9ec7205
Merge branch 'set-variables-on-find-images' of github.com:defenseunic…
AustinAbro321 Feb 5, 2024
8bbadfd
simplify spinner logic
AustinAbro321 Feb 6, 2024
6430697
delete eks.yaml created from test
AustinAbro321 Feb 6, 2024
f328ae8
use only one renderer
AustinAbro321 Feb 6, 2024
1c78954
update flag sentence
AustinAbro321 Feb 6, 2024
6964c6b
rename folder
AustinAbro321 Feb 6, 2024
1839e69
Merge branch 'main' into set-variables-on-find-images
AustinAbro321 Feb 6, 2024
6f4ef70
fix early return
AustinAbro321 Feb 7, 2024
7020a79
Merge branch 'main' into set-variables-on-find-images
AustinAbro321 Feb 7, 2024
4de0674
hack fix for renderer with big bang
AustinAbro321 Feb 7, 2024
ebc9dbd
error message
AustinAbro321 Feb 8, 2024
a49d660
Merge branch 'main' into set-variables-on-find-images
AustinAbro321 Feb 8, 2024
f1f5dae
merge
AustinAbro321 Feb 8, 2024
3461de2
Merge branch 'main' into set-variables-on-find-images
Racer159 Feb 8, 2024
8aec367
Update src/cmd/dev.go
AustinAbro321 Feb 9, 2024
f86e7a2
adding flavor
AustinAbro321 Feb 9, 2024
5516ca5
Merge branch 'main' into set-variables-on-find-images
AustinAbro321 Feb 13, 2024
5c27622
make docs and schema
AustinAbro321 Feb 13, 2024
30448ff
removing setRegistry function
AustinAbro321 Feb 13, 2024
f11c615
switching test to be on already created packages
AustinAbro321 Feb 14, 2024
256341e
put test in right place
AustinAbro321 Feb 14, 2024
9fd22a7
refactor
AustinAbro321 Feb 14, 2024
77b3a10
removing unused test package
AustinAbro321 Feb 14, 2024
2d2c7cb
fix incorrect paths
AustinAbro321 Feb 14, 2024
4c3bfd9
using contants over magic string
AustinAbro321 Feb 15, 2024
4d6d498
rename + lint
AustinAbro321 Feb 15, 2024
3b0d7eb
switching to %w directive
AustinAbro321 Feb 15, 2024
5bb9664
removing unnecessary code
AustinAbro321 Feb 15, 2024
9d1ede5
adding create set / deploy set to test and adding back necessary code
AustinAbro321 Feb 15, 2024
4547ba9
capitals
AustinAbro321 Feb 15, 2024
bb506e2
fix tests
AustinAbro321 Feb 15, 2024
09ca7ca
Merge branch 'main' into set-variables-on-find-images
Racer159 Feb 20, 2024
28057e8
Merge branch 'main' into set-variables-on-find-images
AustinAbro321 Feb 26, 2024
395008a
change test and example
AustinAbro321 Feb 26, 2024
8092254
refactoring how state gets default values in
AustinAbro321 Feb 27, 2024
b1e7807
fixing test, editing code to use new functions
AustinAbro321 Feb 27, 2024
3ec5504
allowing more builtins to be there by default
AustinAbro321 Feb 27, 2024
1bee765
Merge branch 'main' into set-variables-on-find-images
AustinAbro321 Feb 27, 2024
202d351
format
AustinAbro321 Feb 27, 2024
28be0b8
comment
AustinAbro321 Feb 27, 2024
c8180a8
switching registry secret length back
AustinAbro321 Feb 27, 2024
0b5f8b0
Merge branch 'main' into set-variables-on-find-images
AustinAbro321 Feb 28, 2024
379b64f
Merge branch 'main' into set-variables-on-find-images
Racer159 Mar 4, 2024
74df520
Merge branch 'main' into set-variables-on-find-images
AustinAbro321 Mar 4, 2024
aa24dc9
removing registry from struct
AustinAbro321 Mar 4, 2024
416d454
Merge branch 'main' into set-variables-on-find-images
Racer159 Mar 4, 2024
9a623c9
using smaller redis image
AustinAbro321 Mar 4, 2024
bc11327
merge
AustinAbro321 Mar 4, 2024
735f6a5
Merge branch 'main' into set-variables-on-find-images
Noxsios Mar 5, 2024
9b874a6
clearing up error messaging
AustinAbro321 Mar 5, 2024
11c5c16
add err message
AustinAbro321 Mar 5, 2024
e8322a9
message
AustinAbro321 Mar 5, 2024
1aec808
refactor to pointer recievers to set default for types
AustinAbro321 Mar 5, 2024
9a93268
changing tests to point to test package over examples
AustinAbro321 Mar 5, 2024
cf326af
reverting chart
AustinAbro321 Mar 5, 2024
d4c032d
simplify deployment
AustinAbro321 Mar 5, 2024
36e2869
fix flake (hopefully)
AustinAbro321 Mar 5, 2024
40c7428
deleting redis templates to declutter
AustinAbro321 Mar 5, 2024
4f76006
changing values to pointers for consistency
AustinAbro321 Mar 5, 2024
63a35ce
cleaning up ci fix
AustinAbro321 Mar 5, 2024
d2423df
disabling traefik on ci cluster
AustinAbro321 Mar 6, 2024
468404a
merge
AustinAbro321 Mar 6, 2024
7384e44
update text description
AustinAbro321 Mar 6, 2024
fb83b66
make docs and schema
AustinAbro321 Mar 6, 2024
2397afa
fix tests
AustinAbro321 Mar 6, 2024
64a9f85
moving find images tests together
AustinAbro321 Mar 6, 2024
b251a62
reformatting tests
AustinAbro321 Mar 6, 2024
a15ae57
de-parralizeing
AustinAbro321 Mar 6, 2024
5d2065b
fix wordpress test
AustinAbro321 Mar 6, 2024
e4d4543
adding back parrallel fixing lint test
AustinAbro321 Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/k3d/action.yaml
Expand Up @@ -7,5 +7,5 @@ runs:
- run: "curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash"
shell: bash

- run: k3d cluster delete && k3d cluster create
- run: k3d cluster delete && k3d cluster create --k3s-arg="--disable=traefik@server:0"
shell: bash
11 changes: 7 additions & 4 deletions docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md
Expand Up @@ -16,10 +16,13 @@ zarf dev find-images [ PACKAGE ] [flags]
## Options

```
-h, --help help for find-images
--kube-version string Override the default helm template KubeVersion when performing a package chart template
-p, --repo-chart-path string If git repos hold helm charts, often found with gitops tools, specify the chart path, e.g. "/" or "/chart"
--set stringToString Specify package variables to set on the command line (KEY=value). Note, if using a config file, this will be set by [package.create.set]. (default [])
--create-set stringToString Specify package variables to set on the command line (KEY=value). Note, if using a config file, this will be set by [package.create.set]. (default [])
--deploy-set stringToString Specify deployment variables to set on the command line (KEY=value) (default [])
-f, --flavor string The flavor of components to include in the resulting package (i.e. have a matching or empty "only.flavor" key)
-h, --help help for find-images
--kube-version string Override the default helm template KubeVersion when performing a package chart template
--registry-url string Override the ###ZARF_REGISTRY### value (default "127.0.0.1:31999")
-p, --repo-chart-path string If git repos hold helm charts, often found with gitops tools, specify the chart path, e.g. "/" or "/chart"
```

## Options inherited from parent commands
Expand Down
15 changes: 14 additions & 1 deletion src/cmd/dev.go
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/defenseunicorns/zarf/src/pkg/transform"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/pkg/utils/helpers"
"github.com/defenseunicorns/zarf/src/types"
"github.com/mholt/archiver/v3"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -190,8 +191,11 @@ var devFindImagesCmd = &cobra.Command{

// Ensure uppercase keys from viper
v := common.GetViper()

pkgConfig.CreateOpts.SetVariables = helpers.TransformAndMergeMap(
v.GetStringMapString(common.VPkgCreateSet), pkgConfig.CreateOpts.SetVariables, strings.ToUpper)
pkgConfig.PkgOpts.SetVariables = helpers.TransformAndMergeMap(
v.GetStringMapString(common.VPkgDeploySet), pkgConfig.PkgOpts.SetVariables, strings.ToUpper)

// Configure the packager
pkgClient := packager.NewOrDie(&pkgConfig)
Expand Down Expand Up @@ -265,12 +269,21 @@ func init() {
devFindImagesCmd.Flags().StringVarP(&pkgConfig.FindImagesOpts.RepoHelmChartPath, "repo-chart-path", "p", "", lang.CmdDevFlagRepoChartPath)
// use the package create config for this and reset it here to avoid overwriting the config.CreateOptions.SetVariables
devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdDevFlagSet)

devFindImagesCmd.Flags().MarkDeprecated("set", "this field is replaced by create-set")
devFindImagesCmd.Flags().MarkHidden("set")
devFindImagesCmd.Flags().StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor)
devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "create-set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdDevFlagSet)
AustinAbro321 marked this conversation as resolved.
Show resolved Hide resolved
devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.PkgOpts.SetVariables, "deploy-set", v.GetStringMapString(common.VPkgDeploySet), lang.CmdPackageDeployFlagSet)
// allow for the override of the default helm KubeVersion
devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.KubeVersionOverride, "kube-version", "", lang.CmdDevFlagKubeVersion)

defaultRegistry := fmt.Sprintf("%s:%d", helpers.IPV4Localhost, types.ZarfInClusterContainerRegistryNodePort)
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)
devTransformGitLinksCmd.Flags().StringVar(&pkgConfig.InitOpts.GitServer.PushUsername, "git-account", config.ZarfGitPushUser, lang.CmdDevFlagGitAccount)
devTransformGitLinksCmd.Flags().StringVar(&pkgConfig.InitOpts.GitServer.PushUsername, "git-account", types.ZarfGitPushUser, lang.CmdDevFlagGitAccount)
}

func bindDevDeployFlags(v *viper.Viper) {
Expand Down
5 changes: 3 additions & 2 deletions src/cmd/initialize.go
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/pkg/utils/helpers"
"github.com/defenseunicorns/zarf/src/pkg/zoci"
"github.com/defenseunicorns/zarf/src/types"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -181,8 +182,8 @@ func init() {

// Init package variable defaults that are non-zero values
// NOTE: these are not in common.setDefaults so that zarf tools update-creds does not erroneously update values back to the default
v.SetDefault(common.VInitGitPushUser, config.ZarfGitPushUser)
v.SetDefault(common.VInitRegistryPushUser, config.ZarfRegistryPushUser)
v.SetDefault(common.VInitGitPushUser, types.ZarfGitPushUser)
v.SetDefault(common.VInitRegistryPushUser, types.ZarfRegistryPushUser)

// Init package set variable flags
initCmd.Flags().StringToStringVar(&pkgConfig.PkgOpts.SetVariables, "set", v.GetStringMapString(common.VPkgDeploySet), lang.CmdInitFlagSet)
Expand Down
5 changes: 3 additions & 2 deletions src/cmd/package.go
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/packager/sources"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/types"

"oras.land/oras-go/v2/registry"

Expand Down Expand Up @@ -395,8 +396,8 @@ func bindMirrorFlags(v *viper.Viper) {

// Init package variable defaults that are non-zero values
// NOTE: these are not in common.setDefaults so that zarf tools update-creds does not erroneously update values back to the default
v.SetDefault(common.VInitGitPushUser, config.ZarfGitPushUser)
v.SetDefault(common.VInitRegistryPushUser, config.ZarfRegistryPushUser)
v.SetDefault(common.VInitGitPushUser, types.ZarfGitPushUser)
v.SetDefault(common.VInitRegistryPushUser, types.ZarfRegistryPushUser)

// Always require confirm flag (no viper)
mirrorFlags.BoolVar(&config.CommonOptions.Confirm, "confirm", false, lang.CmdPackageDeployFlagConfirm)
Expand Down
14 changes: 1 addition & 13 deletions src/config/config.go
Expand Up @@ -26,9 +26,7 @@ const (
GithubProject = "defenseunicorns/zarf"

// ZarfMaxChartNameLength limits helm chart name size to account for K8s/helm limits and zarf prefix
ZarfMaxChartNameLength = 40
ZarfGeneratedPasswordLen = 24
ZarfGeneratedSecretLen = 48
ZarfMaxChartNameLength = 40

ZarfAgentHost = "agent-hook.zarf.svc"

Expand All @@ -53,16 +51,6 @@ const (
ZarfImagePullSecretName = "private-registry"
ZarfGitServerSecretName = "private-git-server"

ZarfRegistryPushUser = "zarf-push"
ZarfRegistryPullUser = "zarf-pull"
ZarfInClusterContainerRegistryNodePort = 31999

ZarfGitPushUser = "zarf-git-user"
ZarfGitReadUser = "zarf-git-read-user"

ZarfInClusterGitServiceURL = "http://zarf-gitea-http.zarf.svc.cluster.local:3000"
ZarfInClusterArtifactServiceURL = ZarfInClusterGitServiceURL + "/api/packages/" + ZarfGitPushUser

ZarfLoggingUser = "zarf-admin"
)

Expand Down
1 change: 1 addition & 0 deletions src/config/lang/english.go
Expand Up @@ -384,6 +384,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"
CmdDevFlagRegistry = "Override the ###ZARF_REGISTRY### value"

CmdDevLintShort = "Lints the given package for valid schema and recommended practices"
CmdDevLintLong = "Verifies the package schema, checks if any variables won't be evaluated, and checks for unpinned images/repos/files"
Expand Down
1 change: 1 addition & 0 deletions src/extensions/bigbang/bigbang.go
Expand Up @@ -94,6 +94,7 @@ func Run(YOLO bool, tmpPaths *layout.ComponentPaths, c types.ZarfComponent) (typ
},
path.Join(tmpPaths.Temp, bb),
path.Join(tmpPaths.Temp, bb, "values"),
helm.WithPackageConfig(&types.PackagerConfig{}),
)

// Download the chart from Git and save it to a temporary directory.
Expand Down
3 changes: 1 addition & 2 deletions src/internal/agent/hooks/argocd-repository.go
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"
"fmt"

"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/internal/agent/operations"
"github.com/defenseunicorns/zarf/src/internal/agent/state"
Expand Down Expand Up @@ -102,7 +101,7 @@ func mutateRepository(r *v1.AdmissionRequest) (result *operations.Result, err er
func populateArgoRepositoryPatchOperations(repoURL string, zarfGitPullPassword string) []operations.PatchOperation {
var patches []operations.PatchOperation
patches = append(patches, operations.ReplacePatchOperation("/data/url", base64.StdEncoding.EncodeToString([]byte(repoURL))))
patches = append(patches, operations.ReplacePatchOperation("/data/username", base64.StdEncoding.EncodeToString([]byte(config.ZarfGitReadUser))))
patches = append(patches, operations.ReplacePatchOperation("/data/username", base64.StdEncoding.EncodeToString([]byte(types.ZarfGitReadUser))))
patches = append(patches, operations.ReplacePatchOperation("/data/password", base64.StdEncoding.EncodeToString([]byte(zarfGitPullPassword))))

return patches
Expand Down
21 changes: 11 additions & 10 deletions src/internal/packager/helm/chart.go
Expand Up @@ -139,12 +139,12 @@ func (h *Helm) InstallOrUpgradeChart() (types.ConnectStrings, string, error) {
}

// TemplateChart generates a helm template from a given chart.
func (h *Helm) TemplateChart() (string, chartutil.Values, error) {
func (h *Helm) TemplateChart() (manifest string, chartValues chartutil.Values, err error) {
message.Debugf("helm.TemplateChart()")
spinner := message.NewProgressSpinner("Templating helm chart %s", h.chart.Name)
defer spinner.Stop()

err := h.createActionConfig(h.chart.Namespace, spinner)
err = h.createActionConfig(h.chart.Namespace, spinner)

// Setup K8s connection.
if err != nil {
Expand Down Expand Up @@ -183,13 +183,18 @@ func (h *Helm) TemplateChart() (string, chartutil.Values, error) {
return "", nil, fmt.Errorf("unable to load chart data: %w", err)
}

client.PostRenderer, err = h.newRenderer()
if err != nil {
return "", nil, fmt.Errorf("unable to create helm renderer: %w", err)
}

// Perform the loadedChart installation.
templatedChart, err := client.Run(loadedChart, chartValues)
if err != nil {
return "", nil, fmt.Errorf("error generating helm chart template: %w", err)
}

manifest := templatedChart.Manifest
manifest = templatedChart.Manifest

for _, hook := range templatedChart.Hooks {
manifest += fmt.Sprintf("\n---\n%s", hook.Manifest)
Expand Down Expand Up @@ -243,7 +248,7 @@ func (h *Helm) UpdateReleaseValues(updatedValues map[string]interface{}) error {
// Namespace must be specified.
client.Namespace = h.chart.Namespace

// Post-processing our manifests for reasons....
// Post-processing our manifests to apply vars and run zarf helm logic in cluster
client.PostRenderer = postRender

// Set reuse values to only override the values we are explicitly given
Expand Down Expand Up @@ -285,7 +290,7 @@ func (h *Helm) installChart(postRender *renderer) (*release.Release, error) {
// Namespace must be specified.
client.Namespace = h.chart.Namespace

// Post-processing our manifests for reasons....
// Post-processing our manifests to apply vars and run zarf helm logic in cluster
client.PostRenderer = postRender

loadedChart, chartValues, err := h.loadChartData()
Expand All @@ -298,10 +303,6 @@ func (h *Helm) installChart(postRender *renderer) (*release.Release, error) {
}

func (h *Helm) upgradeChart(lastRelease *release.Release, postRender *renderer) (*release.Release, error) {
// Print the postRender object piece by piece to not print the htpasswd
message.Debugf("helm.upgradeChart(%#v, %#v, %#v, %#v, %s)", postRender.actionConfig, postRender.connectStrings,
postRender.namespaces, postRender.Helm, fmt.Sprintf("values:template.Values{ registry: \"%s\" }", postRender.values.GetRegistry()))

// Migrate any deprecated APIs (if applicable)
err := h.migrateDeprecatedAPIs(lastRelease)
if err != nil {
Expand All @@ -322,7 +323,7 @@ func (h *Helm) upgradeChart(lastRelease *release.Release, postRender *renderer)
// Namespace must be specified.
client.Namespace = h.chart.Namespace

// Post-processing our manifests for reasons....
// Post-processing our manifests to apply vars and run zarf helm logic in cluster
client.PostRenderer = postRender

loadedChart, chartValues, err := h.loadChartData()
Expand Down
12 changes: 12 additions & 0 deletions src/internal/packager/helm/common.go
Expand Up @@ -148,7 +148,19 @@ func WithKubeVersion(kubeVersion string) Modifier {
}
}

// WithPackageConfig sets the packager config for the chart
func WithPackageConfig(cfg *types.PackagerConfig) Modifier {
AustinAbro321 marked this conversation as resolved.
Show resolved Hide resolved
return func(h *Helm) {
h.cfg = cfg
}
}

// StandardName generates a predictable full path for a helm chart for Zarf.
func StandardName(destination string, chart types.ZarfChart) string {
return filepath.Join(destination, chart.Name+"-"+chart.Version)
}

// StandardValuesName generates a predictable full path for the values file for a helm chart for zarf
func StandardValuesName(destination string, chart types.ZarfChart, idx int) string {
AustinAbro321 marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Sprintf("%s-%d", StandardName(destination, chart), idx)
}