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: moving cli config to --set for nodeport and storageclass #2083

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6a17d66
feat: moving cli config to --set for nodeport and storageclass
Oct 18, 2023
af54703
updated docs to be consistent with deprecated CLI flags, which will s…
Oct 18, 2023
b79bae9
updated fix docs test
Oct 18, 2023
74570e0
Merge branch 'main' into issue-1725
bdw617 Oct 18, 2023
3c0e9d5
removed a test for the existence of an init flag that is deprecated a…
Oct 19, 2023
3005fb6
we moved nodeport to --set REGISTRY_NODEPORT, and therefore not in th…
Oct 19, 2023
d67f9e8
CI testing, not sure if necessary
Oct 19, 2023
697554f
updated, using CI for testing
Oct 20, 2023
4fbadc0
updated, ready for testing
Oct 23, 2023
f49e4ad
should work now, testing via CI
Oct 23, 2023
6576d6b
fix test in CI
Oct 24, 2023
d5f7d35
updated for ci tests, some will break
Oct 27, 2023
0a7817f
Merge branch 'main' into issue-1725
bdw617 Oct 27, 2023
4cd06a1
fixed merge issue
Oct 27, 2023
cf0d90a
updated to fix an NPE in non-init
Oct 27, 2023
83175e1
updated
Oct 27, 2023
7c2fde7
moving to default storage class. makes us less distro complicated
Oct 27, 2023
e355116
fix upgrade test, will need to release notes this with --set STORAGE_…
Oct 28, 2023
ae7eff1
fixed typo
Oct 28, 2023
c1ed163
updated so if REGISTRY_STORAGE_CLASS isn't set, it will attempt to us…
Oct 29, 2023
b12026d
trying with just empty, fixing chart, need to update it.
Oct 30, 2023
8042767
Merge branch 'main' into issue-1725
bdw617 Oct 30, 2023
5874c1c
trying to always set the values for the storage class
Oct 30, 2023
8240867
hack, will need a better way to template state into ###ZARF_VAR_...###
Oct 30, 2023
8954308
a bit of cleanup
Oct 31, 2023
431a292
Merge branch 'main' into issue-1725
Oct 31, 2023
5c32128
immutable nodeport once created, need more testing
Oct 31, 2023
4fe956c
updated
Oct 31, 2023
7a043a6
tried to force the nodeport to always be the same, didn't work, this …
Nov 1, 2023
a5d9cf2
Merge branch 'main' into issue-1725
Nov 1, 2023
6698814
the address needs to change in this case
Nov 1, 2023
20f0821
Merge branch 'main' into issue-1725
Racer159 Nov 14, 2023
878d29d
Merge branch 'main' into issue-1725
Nov 15, 2023
294ffbe
updated to preserve the zarf state as it was, it simplifies config an…
Nov 15, 2023
f36a71d
Merge branch 'main' into issue-1725
bdw617 Nov 16, 2023
4e977f1
fixed NPE
Nov 16, 2023
5d21c11
must update this to the old way, since the release zarf won't have th…
Nov 16, 2023
43acd57
added a documentation line for an External function
Nov 16, 2023
db54848
Merge branch 'main' into issue-1725
bdw617 Nov 17, 2023
15eb1a8
Merge branch 'main' into issue-1725
bdw617 Nov 27, 2023
5e7e182
Merge branch 'main' into issue-1725
bdw617 Nov 28, 2023
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
4 changes: 1 addition & 3 deletions docs/2-the-zarf-cli/100-cli-commands/zarf_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $ zarf init --components=git-server
$ zarf init --components=git-server,logging

# Initializing w/ an internal registry but with a different nodeport:
$ zarf init --nodeport=30333
$ zarf init --set REGISTRY_NODEPORT=30333

# Initializing w/ an external registry:
$ zarf init --registry-push-password={PASSWORD} --registry-push-username={USERNAME} --registry-url={URL}
Expand Down Expand Up @@ -61,15 +61,13 @@ $ zarf init --artifact-push-password={PASSWORD} --artifact-push-username={USERNA
--git-push-username string Username to access to the git server Zarf is configured to use. User must be able to create repositories via 'git push' (default "zarf-git-user")
--git-url string External git server url to use for this Zarf cluster
-h, --help help for init
--nodeport int Nodeport to access a registry internal to the k8s cluster. Between [30000-32767]
--registry-pull-password string Password for the pull-only user to access the registry
--registry-pull-username string Username for pull-only access to the registry
--registry-push-password string Password for the push-user to connect to the registry
--registry-push-username string Username to access to the registry Zarf is configured to use (default "zarf-push")
--registry-secret string Registry secret value
--registry-url string External registry url address to use for this Zarf cluster
--set stringToString Specify deployment variables to set on the command line (KEY=value) (default [])
--storage-class string Specify the storage class to use for the registry and git server. E.g. --storage-class=standard
```

## Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion packages/gitea/gitea-values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
persistence:
storageClass: "###ZARF_STORAGE_CLASS###"
storageClass: "###ZARF_VAR_REGISTRY_STORAGE_CLASS###"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
storageClass: "###ZARF_VAR_REGISTRY_STORAGE_CLASS###"
storageClass: "###ZARF_VAR_GIT_SERVER_STORAGE_CLASS###"

existingClaim: "###ZARF_VAR_GIT_SERVER_EXISTING_PVC###"
size: "###ZARF_VAR_GIT_SERVER_PVC_SIZE###"
accessModes:
Expand Down
4 changes: 2 additions & 2 deletions packages/zarf-registry/registry-values.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
persistence:
enabled: ###ZARF_VAR_REGISTRY_PVC_ENABLED###
storageClass: "###ZARF_STORAGE_CLASS###"
storageClass: "###ZARF_VAR_REGISTRY_STORAGE_CLASS###"
size: "###ZARF_VAR_REGISTRY_PVC_SIZE###"
existingClaim: "###ZARF_VAR_REGISTRY_EXISTING_PVC###"
accessMode: "###ZARF_VAR_REGISTRY_PVC_ACCESS_MODE###"
Expand All @@ -19,7 +19,7 @@ secrets:
secret: "###ZARF_REGISTRY_SECRET###"

service:
nodePort: "###ZARF_NODEPORT###"
nodePort: "###ZARF_VAR_REGISTRY_NODEPORT###"

resources:
requests:
Expand Down
10 changes: 10 additions & 0 deletions packages/zarf-registry/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ variables:
default: ""
autoIndent: true

- name: REGISTRY_NODEPORT
description: NodePort for the registry
default: "31999"
autoIndent: true

- name: REGISTRY_STORAGE_CLASS
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be a corresponding variable for the GIT_SERVER

description: StorageClass for the registry PVC
default: ""
autoIndent: true

constants:
- name: REGISTRY_IMAGE
value: "###ZARF_PKG_TMPL_REGISTRY_IMAGE###"
Expand Down
75 changes: 73 additions & 2 deletions src/cmd/initialize.go
Copy link
Contributor

Choose a reason for hiding this comment

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

To be more consistent with other deprecated fields/flags in the codebase, it would probably be good to rename the deprecated fields to DeprecatedStorageClass in the ZarfInitOptions struct, and DeprecatedNodePort in the RegistryInfo struct. This way we wouldn't need to add the nodePortArg and storageClassArg variables or remove any struct fields at this time.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path"
"path/filepath"
"strconv"
"strings"

"github.com/AlecAivazis/survey/v2"
Expand All @@ -26,6 +27,9 @@ import (
"github.com/spf13/cobra"
)

var nodePortArg = 0
var storageClassArg = ""

// initCmd represents the init command.
var initCmd = &cobra.Command{
Use: "init",
Expand Down Expand Up @@ -61,6 +65,10 @@ var initCmd = &cobra.Command{
pkgConfig.PkgOpts.SetVariables = helpers.TransformAndMergeMap(
v.GetStringMapString(common.VPkgDeploySet), pkgConfig.PkgOpts.SetVariables, strings.ToUpper)

// DEPRECATED_V1.0.0: these functions will need cleanup
setRegistryStorageClass()
setRegistryNodePort()

// Configure the packager
pkgClient := packager.NewOrDie(&pkgConfig, packager.WithSource(src))
defer pkgClient.ClearTempPaths()
Expand All @@ -73,6 +81,62 @@ var initCmd = &cobra.Command{
},
}

// DEPRECATED_V1.0.0: --nodeport should be removed from the cli in v1.0.0
func setRegistryNodePort() {
configVar := "REGISTRY_NODEPORT"

internalRegistry := pkgConfig.InitOpts.RegistryInfo.Address == ""

// warn for deprecation
if nodePortArg != 0 {
message.Warn(lang.WarnNodePortDeprecated)
}

// check the --set REGISTRY_NODEPORT first
configuredNodePort, err := strconv.Atoi(pkgConfig.PkgOpts.SetVariables[configVar])
if err != nil {
configuredNodePort = 0
}

// check the old --nodeport flag second
if configuredNodePort == 0 {
configuredNodePort = nodePortArg
}

// the user can't set both that this is an external registry and the nodeport stuff.
if !internalRegistry && configuredNodePort != 0 {
message.Fatal(nil, "both --registry-url and --nodeport are set, please only use one")
}

if internalRegistry {
if configuredNodePort > 32767 || configuredNodePort < 30000 {
configuredNodePort = config.ZarfInClusterContainerRegistryNodePort
Copy link
Contributor

Choose a reason for hiding this comment

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

Would probably be good to notify the user that they provided an invalid nodeport number and that we're going to use the default Zarf nodeport of 31999 instead. Might save users some confusion on why their specified port number wasn't used by Zarf.

}
pkgConfig.PkgOpts.SetVariables[configVar] = strconv.Itoa(configuredNodePort)
pkgConfig.InitOpts.RegistryInfo.Address = fmt.Sprintf("%s:%d", helpers.IPV4Localhost, configuredNodePort)
pkgConfig.InitOpts.RegistryInfo.NodePort = configuredNodePort
} else {
// do not set the nodeport if this is an external registry
pkgConfig.PkgOpts.SetVariables[configVar] = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to remove this else block. If the user specifies an external registry, we shouldn't have to set the REGISTRY_NODEPORT var to an empty string

}

pkgConfig.InitOpts.RegistryInfo.InternalRegistry = internalRegistry

// TODO: test external registry and CLI.
Copy link
Contributor

Choose a reason for hiding this comment

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

todo

}

// DEPRECATED_V1.0.0: --storage-class should be removed from the CLI in v1.0.0
func setRegistryStorageClass() {
configVar := "REGISTRY_STORAGE_CLASS"
Copy link
Contributor

Choose a reason for hiding this comment

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

This would set both the registry and git server vars

// there is no validation if this storage class is valid
if storageClassArg != "" {
message.Warn(lang.WarnStorageClassDeprecated)
}
if pkgConfig.PkgOpts.SetVariables[configVar] == "" {
pkgConfig.PkgOpts.SetVariables[configVar] = storageClassArg
}
}

func findInitPackage(initPackageName string) (string, error) {
// First, look for the init package in the current working directory
if !utils.InvalidPath(initPackageName) {
Expand Down Expand Up @@ -188,7 +252,10 @@ func init() {
// Continue to require --confirm flag for init command to avoid accidental deployments
initCmd.Flags().BoolVar(&config.CommonOptions.Confirm, "confirm", false, lang.CmdInitFlagConfirm)
initCmd.Flags().StringVar(&pkgConfig.PkgOpts.OptionalComponents, "components", v.GetString(common.VInitComponents), lang.CmdInitFlagComponents)
initCmd.Flags().StringVar(&pkgConfig.InitOpts.StorageClass, "storage-class", v.GetString(common.VInitStorageClass), lang.CmdInitFlagStorageClass)

// [Deprecated] --storage-class is deprecated in favor of --set REGISTRY_STORAGE_CLASS (to be removed in v1.0.0)
initCmd.Flags().StringVar(&storageClassArg, "storage-class", v.GetString(common.VInitStorageClass), lang.CmdInitFlagStorageClass)
initCmd.Flags().MarkHidden("storage-class")

// Flags for using an external Git server
initCmd.Flags().StringVar(&pkgConfig.InitOpts.GitServer.Address, "git-url", v.GetString(common.VInitGitURL), lang.CmdInitFlagGitURL)
Expand All @@ -199,7 +266,11 @@ func init() {

// Flags for using an external registry
initCmd.Flags().StringVar(&pkgConfig.InitOpts.RegistryInfo.Address, "registry-url", v.GetString(common.VInitRegistryURL), lang.CmdInitFlagRegURL)
initCmd.Flags().IntVar(&pkgConfig.InitOpts.RegistryInfo.NodePort, "nodeport", v.GetInt(common.VInitRegistryNodeport), lang.CmdInitFlagRegNodePort)

// [Deprecated] --nodeport is deprecated in favor of --set REGISTRY_NODEPORT
initCmd.Flags().IntVar(&nodePortArg, "nodeport", v.GetInt(common.VInitRegistryNodeport), lang.CmdInitFlagRegNodePort)
initCmd.Flags().MarkHidden("nodeport")

initCmd.Flags().StringVar(&pkgConfig.InitOpts.RegistryInfo.PushUsername, "registry-push-username", v.GetString(common.VInitRegistryPushUser), lang.CmdInitFlagRegPushUser)
initCmd.Flags().StringVar(&pkgConfig.InitOpts.RegistryInfo.PushPassword, "registry-push-password", v.GetString(common.VInitRegistryPushPass), lang.CmdInitFlagRegPushPass)
initCmd.Flags().StringVar(&pkgConfig.InitOpts.RegistryInfo.PullUsername, "registry-pull-username", v.GetString(common.VInitRegistryPullUser), lang.CmdInitFlagRegPullUser)
Expand Down
33 changes: 33 additions & 0 deletions src/cmd/initialize_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// DEPRECATED_V1.0.0: do not check pkgConfig.InitOpts.RegistryInfo.NodePort, always overwrite it.
package cmd

import (
"testing"
)

func TestSetRegistryStorageClass(t *testing.T) {
// Test case 1: storageClass is set
pkgConfig.PkgOpts.SetVariables = map[string]string{"REGISTRY_STORAGE_CLASS": "test-storage-class"}
storageClassArg = ""
setRegistryStorageClass()
if storageClassArg != "test-storage-class" {
t.Errorf("Expected storage class to be set to 'test-storage-class', but got '%s'", storageClassArg)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use require.Equal() to be more consistent with the rest of our test suite assertions. When require.Equal() fails it prints an "expected but got" message by default for you.

}

// Test case 2: storageClass is not set, use old way
pkgConfig.PkgOpts.SetVariables = map[string]string{}
storageClassArg = "old-storage-class"
setRegistryStorageClass()
if pkgConfig.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"] != "old-storage-class" {
t.Errorf("Expected storage class to be set to old way value, but got '%s'", pkgConfig.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"])
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use require.Equal() to be more consistent with the rest of our test suite assertions. When require.Equal() fails it prints an "expected but got" message by default for you.

}

// Test case 3: neither is set, should be empty
pkgConfig.PkgOpts.SetVariables = map[string]string{}
storageClassArg = ""
setRegistryStorageClass()
if pkgConfig.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"] != "" {
t.Errorf("Expected storage class to be set to empty string, but got '%s'", pkgConfig.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"])
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use require.Equal() to be more consistent with the rest of our test suite assertions. When require.Equal() fails it prints an "expected but got" message by default for you.

}

}
13 changes: 10 additions & 3 deletions src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ const (
ErrFileNameExtract = "failed to extract filename from URL %s: %s"
)

// Zarf CLI deprecation warnings
const (
// remove deprecation in v1.0.0
WarnStorageClassDeprecated = "--storage-class <value> is deprecated, please use --set REGISTRY_STORAGE_CLASS=<value>"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
WarnStorageClassDeprecated = "--storage-class <value> is deprecated, please use --set REGISTRY_STORAGE_CLASS=<value>"
WarnStorageClassDeprecated = "--storage-class <value> is deprecated, please use --set REGISTRY_STORAGE_CLASS=<value> and --set GIT_SERVER_STORAGE_CLASS=<value>"

WarnNodePortDeprecated = "--nodeport <value> is deprecated, please use --set REGISTRY_NODEPORT=<value>"
)

// Zarf CLI commands.
const (
// common command language
Expand Down Expand Up @@ -128,7 +135,7 @@ $ zarf init --components=git-server
$ zarf init --components=git-server,logging

# Initializing w/ an internal registry but with a different nodeport:
$ zarf init --nodeport=30333
$ zarf init --set REGISTRY_NODEPORT=30333

# Initializing w/ an external registry:
$ zarf init --registry-push-password={PASSWORD} --registry-push-username={USERNAME} --registry-url={URL}
Expand Down Expand Up @@ -158,7 +165,7 @@ $ zarf init --artifact-push-password={PASSWORD} --artifact-push-username={USERNA

CmdInitFlagConfirm = "Confirms package deployment without prompting. ONLY use with packages you trust. Skips prompts to review SBOM, configure variables, select optional components and review potential breaking changes."
CmdInitFlagComponents = "Specify which optional components to install. E.g. --components=git-server,logging"
CmdInitFlagStorageClass = "Specify the storage class to use for the registry and git server. E.g. --storage-class=standard"
CmdInitFlagStorageClass = "[DEPRECATED] This command has been replaced by 'zarf init --set REGISTRY_STORAGE_CLASS=<value>' and will be removed in Zarf v1.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
CmdInitFlagStorageClass = "[DEPRECATED] This command has been replaced by 'zarf init --set REGISTRY_STORAGE_CLASS=<value>' and will be removed in Zarf v1.0.0"
CmdInitFlagStorageClass = "[Deprecated] Specify the storage class to use for the registry and git server. (use --set REGISTRY_STORAGE_CLASS=<value> and --set GIT_SERVER_STORAGE_CLASS=<value> instead)"

This should match other deprecated flags (see CmdPackageCreateFlagDeprecatedKey)


CmdInitFlagGitURL = "External git server url to use for this Zarf cluster"
CmdInitFlagGitPushUser = "Username to access to the git server Zarf is configured to use. User must be able to create repositories via 'git push'"
Expand All @@ -167,7 +174,7 @@ $ zarf init --artifact-push-password={PASSWORD} --artifact-push-username={USERNA
CmdInitFlagGitPullPass = "Password for the pull-only user to access the git server"

CmdInitFlagRegURL = "External registry url address to use for this Zarf cluster"
CmdInitFlagRegNodePort = "Nodeport to access a registry internal to the k8s cluster. Between [30000-32767]"
CmdInitFlagRegNodePort = "[DEPRECATED] Nodeport to access a registry internal to the k8s cluster. Between [30000-32767]"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
CmdInitFlagRegNodePort = "[DEPRECATED] Nodeport to access a registry internal to the k8s cluster. Between [30000-32767]"
CmdInitFlagRegNodePort = "[Deprecated] Nodeport to access a registry internal to the k8s cluster. Between [30000-32767] (use --set REGISTRY_NODEPORT=<value> instead)"

CmdInitFlagRegPushUser = "Username to access to the registry Zarf is configured to use"
CmdInitFlagRegPushPass = "Password for the push-user to connect to the registry"
CmdInitFlagRegPullUser = "Username for pull-only access to the registry"
Expand Down
28 changes: 0 additions & 28 deletions src/internal/cluster/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,6 @@ func (c *Cluster) InitZarfState(initOptions types.ZarfInitOptions) error {
}
}

switch state.Distro {
case k8s.DistroIsK3s, k8s.DistroIsK3d:
state.StorageClass = "local-path"

case k8s.DistroIsKind, k8s.DistroIsGKE:
state.StorageClass = "standard"

case k8s.DistroIsDockerDesktop:
state.StorageClass = "hostpath"
}

if initOptions.StorageClass != "" {
state.StorageClass = initOptions.StorageClass
}

spinner.Success()

// Save the state back to K8s
Expand Down Expand Up @@ -249,13 +234,6 @@ func (c *Cluster) MergeZarfState(oldState *types.ZarfState, initOptions types.Za

if slices.Contains(services, message.RegistryKey) {
newState.RegistryInfo = helpers.MergeNonZero(newState.RegistryInfo, initOptions.RegistryInfo)
// Set the state of the internal registry if it has changed
if newState.RegistryInfo.Address == fmt.Sprintf("%s:%d", helpers.IPV4Localhost, newState.RegistryInfo.NodePort) {
newState.RegistryInfo.InternalRegistry = true
} else {
newState.RegistryInfo.InternalRegistry = false
}
Comment on lines -253 to -257
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing this logic from here will break the library usages of zarf init - Nodeport should be pulled out of ZARF_VAR_REGISTRY_NODEPORT for now. (later this can be refactored to a more explicit mapping)


// Set the new passwords if they should be autogenerated
if newState.RegistryInfo.PushPassword == oldState.RegistryInfo.PushPassword && oldState.RegistryInfo.InternalRegistry {
newState.RegistryInfo.PushPassword = utils.RandomString(config.ZarfGeneratedPasswordLen)
Expand Down Expand Up @@ -310,12 +288,6 @@ func (c *Cluster) fillInEmptyContainerRegistryValues(containerRegistry types.Reg
containerRegistry.NodePort = config.ZarfInClusterContainerRegistryNodePort
}

// Set default url if an external registry was not provided
if containerRegistry.Address == "" {
containerRegistry.InternalRegistry = true
containerRegistry.Address = fmt.Sprintf("%s:%d", helpers.IPV4Localhost, containerRegistry.NodePort)
}

// Generate a push-user password if not provided by init flag
if containerRegistry.PushPassword == "" {
containerRegistry.PushPassword = utils.RandomString(config.ZarfGeneratedPasswordLen)
Expand Down
12 changes: 9 additions & 3 deletions src/internal/packager/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@ func (values *Values) GetVariables(component types.ZarfComponent) (templateMap m
regInfo := values.config.State.RegistryInfo
gitInfo := values.config.State.GitServer

builtinMap := map[string]string{
"STORAGE_CLASS": values.config.State.StorageClass,
if values.config.SetVariableMap != nil {
if regInfo.NodePort > 0 && values.config.SetVariableMap["REGISTRY_NODEPORT"] != nil {
values.config.SetVariableMap["REGISTRY_NODEPORT"].Value = fmt.Sprintf("%d", regInfo.NodePort)
}
if values.config.State.StorageClass != "" && values.config.SetVariableMap["REGISTRY_STORAGE_CLASS"] != nil {
values.config.SetVariableMap["REGISTRY_STORAGE_CLASS"].Value = values.config.State.StorageClass
}
}
Comment on lines +88 to +95
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't need to be here - variables in a zarf.yaml will just pass through


builtinMap := map[string]string{
// Registry info
"REGISTRY": values.registry,
"NODEPORT": fmt.Sprintf("%d", regInfo.NodePort),
"REGISTRY_AUTH_PUSH": regInfo.PushPassword,
"REGISTRY_AUTH_PULL": regInfo.PullPassword,

Expand Down
19 changes: 19 additions & 0 deletions src/pkg/k8s/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
package k8s

import (
"context"
"errors"
"fmt"
"regexp"

"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// List of supported distros via distro detection.
Expand Down Expand Up @@ -158,3 +161,19 @@ func MakeLabels(labels map[string]string) string {
}
return strings.Join(out, ",")
}

// GetDefaultStorageClass will query the cluster for the default storage class and return the name.
func (k *K8s) GetDefaultStorageClass() (string, error) {
storageV1Client := k.Clientset.StorageV1()
storageClasses, err := storageV1Client.StorageClasses().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return "", fmt.Errorf("unable to get Kubernetes default storage class from the cluster : %w", err)
}

for _, sc := range storageClasses.Items {
if sc.Annotations["storageclass.kubernetes.io/is-default-class"] == "true" {
return sc.Name, nil
}
}
return "", fmt.Errorf("unable to get Kubernetes default storage class from the cluster (no default storage class found)")
}
15 changes: 13 additions & 2 deletions src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func (p *Packager) deployComponents() (deployedComponents []types.DeployedCompon
}

func (p *Packager) deployInitComponent(component types.ZarfComponent) (charts []types.InstalledChart, err error) {
hasExternalRegistry := p.cfg.InitOpts.RegistryInfo.Address != ""
isSeedRegistry := component.Name == "zarf-seed-registry"
isRegistry := component.Name == "zarf-registry"
isInjector := component.Name == "zarf-injector"
Expand All @@ -203,7 +202,7 @@ func (p *Packager) deployInitComponent(component types.ZarfComponent) (charts []
}
}

if hasExternalRegistry && (isSeedRegistry || isInjector || isRegistry) {
if !p.cfg.InitOpts.RegistryInfo.InternalRegistry && (isSeedRegistry || isInjector || isRegistry) {
message.Notef("Not deploying the component (%s) since external registry information was provided during `zarf init`", component.Name)
return charts, nil
}
Expand All @@ -216,6 +215,18 @@ func (p *Packager) deployInitComponent(component types.ZarfComponent) (charts []
// Before deploying the seed registry, start the injector
if isSeedRegistry {
p.cluster.StartInjectionMadness(p.layout.Base, p.layout.Images.Base, component.Images)

// Retrieve the default storage class from the cluster, it will be the default
if p.cfg.PkgOpts.SetVariables == nil {
p.cfg.PkgOpts.SetVariables = map[string]string{}
}
if c := p.cfg.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"]; c == "" {
p.cfg.PkgOpts.SetVariables["REGISTRY_STORAGE_CLASS"], err = p.cluster.GetDefaultStorageClass()
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be needed if the storage class is empty

Copy link
Contributor

Choose a reason for hiding this comment

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

Tested this with k3d, kind, k3s, and minikube locally across zarf v0.31.3 and this build, new inits and upgrades... do you have a test case where this was needed?

}

if err != nil {
message.WarnErr(err, "Unable to get the default storage class from the cluster")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we have an opportunity to fail fast here. If REGISTRY_PVC_ENABLED is true (this is the default), the user did not specify a storage class to use, and there was no default storage class found in the cluster, we should fail fast and notify the user that a storage class is needed for the registry to deploy successfully.

RKE2 clusters come to mind since they don't provide a default storage class

}
}

charts, err = p.deployComponent(component, isAgent /* skip img checksum if isAgent */, isSeedRegistry /* skip image push if isSeedRegistry */)
Expand Down
Loading
Loading