From dd264c449804b79c088d1722a3811c2ab0878c97 Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Mon, 29 Jul 2024 14:29:29 -0700 Subject: [PATCH] feat(scaffold): add support for variables Signed-off-by: Kate Goldenring --- pkg/cmd/scaffold.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/cmd/scaffold.go b/pkg/cmd/scaffold.go index 561d0d5..3ef00aa 100644 --- a/pkg/cmd/scaffold.go +++ b/pkg/cmd/scaffold.go @@ -28,6 +28,7 @@ type ScaffoldOptions struct { replicas int32 targetCPUUtilizationPercentage int32 targetMemoryUtilizationPercentage int32 + variables map[string]string } var scaffoldOpts = ScaffoldOptions{} @@ -47,6 +48,7 @@ type appConfig struct { RuntimeConfig string TargetCPUUtilizationPercentage int32 TargetMemoryUtilizationPercentage int32 + Variables map[string]string } var manifestStr = `apiVersion: core.spinoperator.dev/v1alpha1 @@ -61,6 +63,13 @@ spec: {{- else }} replicas: {{ .Replicas }} {{- end}} +{{- if .Variables }} + variables: +{{- range $key, $value := .Variables }} + - name: {{ $key }} + value: {{ $value }} +{{- end }} +{{- end }} {{- if or .CPULimit .MemoryLimit }} resources: limits: @@ -253,6 +262,7 @@ func scaffold(opts ScaffoldOptions) ([]byte, error) { TargetMemoryUtilizationPercentage: opts.targetMemoryUtilizationPercentage, Autoscaler: opts.autoscaler, ImagePullSecrets: opts.imagePullSecrets, + Variables: opts.variables, } if opts.configfile != "" { @@ -312,6 +322,7 @@ func init() { scaffoldCmd.Flags().StringVarP(&scaffoldOpts.output, "out", "o", "", "Path to file to write manifest yaml") scaffoldCmd.Flags().StringVarP(&scaffoldOpts.configfile, "runtime-config-file", "c", "", "Path to runtime config file") scaffoldCmd.Flags().StringSliceVarP(&scaffoldOpts.imagePullSecrets, "image-pull-secret", "s", []string{}, "Secrets in the same namespace to use for pulling the image") + scaffoldCmd.PersistentFlags().StringToStringVarP(&scaffoldOpts.variables, "variable", "v", nil, "Application variables to be provided to the application") if err := scaffoldCmd.MarkFlagRequired("from"); err != nil { log.Fatal(err)