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

Override State Parameters During Init #421

Merged
merged 7 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
16 changes: 16 additions & 0 deletions cli/cmd/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,20 @@ 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")

addZarfStateOverrideFlags(initCmd, false)

}

// Add flags to override values that will be added to ZarfState during an init
func addZarfStateOverrideFlags(commad *cobra.Command, makeHidden bool) {
commad.Flags().StringVar(&config.DeployOptions.StorageClass, "storage-class", "", "Describe the StorageClass to be used")
commad.Flags().StringVar(&config.DeployOptions.Secret, "secret", "", "Root secret value that is used to 'seed' other secrets")
commad.Flags().StringVar(&config.DeployOptions.NodePort, "nodeport", "", "Nodeport to access the Zarf container registry. Between [30000-32767]")

if makeHidden {
packageDeployCmd.Flags().MarkHidden("storage-class")
packageDeployCmd.Flags().MarkHidden("secret")
packageDeployCmd.Flags().MarkHidden("nodeport")
}
}
3 changes: 3 additions & 0 deletions cli/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,7 @@ func init() {
packageDeployCmd.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")
packageDeployCmd.Flags().BoolVar(&insecureDeploy, "insecure", false, "Skip shasum validation of remote package. Required if deploying a remote package and `--shasum` is not provided")
packageDeployCmd.Flags().StringVar(&shasum, "shasum", "", "Shasum of the package to deploy. Required if deploying a remote package and `--insecure` is not provided")

// Make flags for initializing hidden
addZarfStateOverrideFlags(packageDeployCmd, true)
}
5 changes: 1 addition & 4 deletions cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion cli/internal/packager/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion cli/internal/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions cli/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/zarf-registry/registry-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ secrets:
# tlsSecretName: tls-pem
service:
type: NodePort
nodePort: "###ZARF_REGISTRY_NODEPORT###"
nodePort: "###ZARF_NODEPORT###"
resources:
requests:
cpu: "500m"
Expand Down