Skip to content

Commit

Permalink
Override State Parameters During Init (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
YrrepNoj committed Mar 30, 2022
1 parent e3e5260 commit 4ab2d09
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
4 changes: 4 additions & 0 deletions cli/cmd/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
}
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

0 comments on commit 4ab2d09

Please sign in to comment.