From 4ab2d0982ac5c22bda59f886fb96f4c27af881f5 Mon Sep 17 00:00:00 2001 From: Jonathan Perry Date: Tue, 29 Mar 2022 23:17:09 -0500 Subject: [PATCH] Override State Parameters During Init (#421) --- cli/cmd/initialize.go | 4 ++++ cli/config/config.go | 5 +---- cli/internal/packager/seed.go | 12 +++++++++++- cli/internal/template/template.go | 2 +- cli/types/types.go | 11 +++++++---- packages/zarf-registry/registry-values.yaml | 2 +- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/cli/cmd/initialize.go b/cli/cmd/initialize.go index 1baa449502..27e4ad0a00 100644 --- a/cli/cmd/initialize.go +++ b/cli/cmd/initialize.go @@ -33,4 +33,8 @@ func init() { rootCmd.AddCommand(initCmd) initCmd.Flags().BoolVar(&config.DeployOptions.Confirm, "confirm", false, "Confirm the install without prompting") initCmd.Flags().StringVar(&config.DeployOptions.Components, "components", "", "Comma-separated list of components to install. Adding this flag will skip the init prompts for which components to install") + + initCmd.Flags().StringVar(&config.DeployOptions.StorageClass, "storage-class", "", "Describe the StorageClass to be used") + initCmd.Flags().StringVar(&config.DeployOptions.Secret, "secret", "", "Root secret value that is used to 'seed' other secrets") + initCmd.Flags().StringVar(&config.DeployOptions.NodePort, "nodeport", "", "Nodeport to access the Zarf container registry. Between [30000-32767]") } diff --git a/cli/config/config.go b/cli/config/config.go index 9e980cfefa..46f9fb2261 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -28,9 +28,6 @@ const ( ZarfRegistryPullUser = "zarf-pull" ZarfRegistry = IPV4Localhost + ":45001" - ZarfSeedTypeCLIInject = "cli-inject" - ZarfSeedTypeInClusterRegistry = "in-cluster-registry" - ZarfConnectLabelName = "zarf.dev/connect-name" ZarfConnectAnnotationDescription = "zarf.dev/connect-description" ZarfConnectAnnotationUrl = "zarf.dev/connect-url" @@ -149,7 +146,7 @@ func GetState() types.ZarfState { } func GetRegistry() string { - return fmt.Sprintf("%s:%s", IPV4Localhost, state.Registry.NodePort) + return fmt.Sprintf("%s:%s", IPV4Localhost, state.NodePort) } func LoadConfig(path string) error { diff --git a/cli/internal/packager/seed.go b/cli/internal/packager/seed.go index f2c26359f3..6dc18a5ce4 100644 --- a/cli/internal/packager/seed.go +++ b/cli/internal/packager/seed.go @@ -57,7 +57,7 @@ func preSeedRegistry(tempPath tempPaths) { } // Defaults - state.Registry.NodePort = "31999" + state.NodePort = "31999" state.Secret = utils.RandomString(120) state.Distro = distro state.Architecture = config.GetArch() @@ -76,7 +76,17 @@ func preSeedRegistry(tempPath tempPaths) { case k8s.DistroIsDockerDesktop: state.StorageClass = "hostpath" + } + // CLI provided overrides that haven't been processed already + if config.DeployOptions.NodePort != "" { + state.NodePort = config.DeployOptions.NodePort + } + if config.DeployOptions.Secret != "" { + state.Secret = config.DeployOptions.Secret + } + if config.DeployOptions.StorageClass != "" { + state.StorageClass = config.DeployOptions.StorageClass } spinner.Success() diff --git a/cli/internal/template/template.go b/cli/internal/template/template.go index 9f6290072b..6d41bcc7da 100644 --- a/cli/internal/template/template.go +++ b/cli/internal/template/template.go @@ -76,7 +76,7 @@ func (values Values) Apply(path string) { "STORAGE_CLASS": values.state.StorageClass, "SEED_REGISTRY": values.seedRegistry, "REGISTRY": values.registry, - "REGISTRY_NODEPORT": values.state.Registry.NodePort, + "NODEPORT": values.state.NodePort, "REGISTRY_SECRET": values.secret.registrySecret, "REGISTRY_AUTH_PUSH": values.secret.registryPush, "REGISTRY_AUTH_PULL": values.secret.registryPull, diff --git a/cli/types/types.go b/cli/types/types.go index 4e87e5918e..a9a10afede 100644 --- a/cli/types/types.go +++ b/cli/types/types.go @@ -124,10 +124,7 @@ type ZarfState struct { Architecture string `json:"architecture"` StorageClass string `json:"storageClass"` Secret string `json:"secret"` - Registry struct { - SeedType string `json:"seedType"` - NodePort string `json:"nodePort"` - } `json:"registry"` + NodePort string `json:"nodePort"` } // TLSConfig tracks the user-defined options for TLS cert generation @@ -142,8 +139,14 @@ type ZarfDeployOptions struct { PackagePath string Confirm bool Components string + // Zarf init is installing the k3s component ApplianceMode bool + + // Zarf init override options + StorageClass string + Secret string + NodePort string } // ZarfImport structure for including imported zarf components diff --git a/packages/zarf-registry/registry-values.yaml b/packages/zarf-registry/registry-values.yaml index fb7887af8c..774d63e16a 100644 --- a/packages/zarf-registry/registry-values.yaml +++ b/packages/zarf-registry/registry-values.yaml @@ -11,7 +11,7 @@ secrets: # tlsSecretName: tls-pem service: type: NodePort - nodePort: "###ZARF_REGISTRY_NODEPORT###" + nodePort: "###ZARF_NODEPORT###" resources: requests: cpu: "500m"