-
Notifications
You must be signed in to change notification settings - Fork 218
feat(values): dev inspect #4268
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
base: main
Are you sure you want to change the base?
Changes from all commits
355d0f5
a6fb3eb
1d9d728
3df0a2c
4d2c610
23a8027
b2db2a3
eb2453f
96eec5d
6aeb2cd
9b9c5ad
6ab0bc3
3ec1b20
1b76f5b
2e98fa9
f542021
061858d
d5fb32d
d802aa7
f2cdbca
65e93db
dd33519
8bba1af
6b6d81e
92e1eb7
b42120b
a1dc7ec
909ab23
9a9c849
766974c
ba4701e
e29a11f
536caa2
c740a31
b5d9a0f
2fe95bd
740749f
87259bc
219b504
a6f467d
7f4228f
2b380a3
d938db7
4a256ee
ceb8cfb
ac88a4a
cc0e2c1
2a3ac66
75e7546
7a7a8c9
07c665e
6e02a3e
234b46d
587f7bd
8eb1283
e1328db
79b9075
9fbb27c
57f6a8a
1d841e0
b25defa
9a37372
f34bc2e
b13eab6
8669d72
174e494
b3f1588
23a60c9
de4a808
2c18659
ab14746
2c53189
89de456
3de01ab
c48dd07
b542964
473c41d
1f0f715
1c648b9
095fbfd
26eed44
e062bce
2d77714
d71a493
4669c88
2fe037f
ded9820
f42c346
26b0876
ba6f9a5
bcf417c
91b3c14
83a1f7c
862de4d
1128221
7810a7d
8ffc674
7b1ebff
7042d4c
d29718b
38d61b8
f9f9613
06d6bd4
f228644
f9a8c2c
1bdfcdf
e659540
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
mkcp marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import ( | |
| "github.com/zarf-dev/zarf/src/api/v1alpha1" | ||
| "github.com/zarf-dev/zarf/src/config" | ||
| "github.com/zarf-dev/zarf/src/config/lang" | ||
| "github.com/zarf-dev/zarf/src/internal/value" | ||
| "github.com/zarf-dev/zarf/src/pkg/archive" | ||
| "github.com/zarf-dev/zarf/src/pkg/lint" | ||
| "github.com/zarf-dev/zarf/src/pkg/logger" | ||
|
|
@@ -124,6 +125,8 @@ type devInspectManifestsOptions struct { | |
| flavor string | ||
| createSetVariables map[string]string | ||
| deploySetVariables map[string]string | ||
| valuesFiles []string | ||
| setValues map[string]string | ||
| kubeVersion string | ||
| outputWriter io.Writer | ||
| } | ||
|
|
@@ -149,6 +152,8 @@ func newDevInspectManifestsCommand(v *viper.Viper) *cobra.Command { | |
| cmd.Flags().StringVarP(&o.flavor, "flavor", "f", "", lang.CmdPackageCreateFlagFlavor) | ||
| cmd.Flags().StringToStringVar(&o.createSetVariables, "create-set", v.GetStringMapString(VPkgCreateSet), lang.CmdPackageCreateFlagSet) | ||
| cmd.Flags().StringToStringVar(&o.deploySetVariables, "deploy-set", v.GetStringMapString(VPkgDeploySet), lang.CmdPackageDeployFlagSet) | ||
| cmd.Flags().StringSliceVar(&o.valuesFiles, "values", []string{}, "Path to values file(s) for templating") | ||
| cmd.Flags().StringToStringVar(&o.setValues, "set-values", map[string]string{}, "Set specific values via command line (format: key.path=value)") | ||
| cmd.Flags().StringVar(&o.kubeVersion, "kube-version", "", lang.CmdDevFlagKubeVersion) | ||
|
|
||
| return cmd | ||
|
|
@@ -164,9 +169,29 @@ func (o *devInspectManifestsOptions) run(ctx context.Context, args []string) err | |
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Parse values from files | ||
| values, err := value.ParseFiles(ctx, o.valuesFiles, value.ParseFilesOptions{}) | ||
| if err != nil { | ||
| return fmt.Errorf("unable to parse values files: %w", err) | ||
| } | ||
|
|
||
| // Apply CLI --set-values overrides | ||
| for key, val := range o.setValues { | ||
| // Convert key to path format (ensure it starts with .) | ||
| path := value.Path(key) | ||
| if !strings.HasPrefix(key, ".") { | ||
| path = value.Path("." + key) | ||
| } | ||
| if err := values.Set(path, val); err != nil { | ||
| return fmt.Errorf("unable to set value at path %s: %w", key, err) | ||
| } | ||
| } | ||
|
|
||
| opts := packager.InspectDefinitionResourcesOptions{ | ||
| CreateSetVariables: o.createSetVariables, | ||
| DeploySetVariables: o.deploySetVariables, | ||
| Values: values, | ||
| Flavor: o.flavor, | ||
| KubeVersion: o.kubeVersion, | ||
| CachePath: cachePath, | ||
|
|
@@ -201,6 +226,8 @@ type devInspectValuesFilesOptions struct { | |
| flavor string | ||
| createSetVariables map[string]string | ||
| deploySetVariables map[string]string | ||
| valuesFiles []string | ||
| setValues map[string]string | ||
| kubeVersion string | ||
| outputWriter io.Writer | ||
| } | ||
|
|
@@ -227,6 +254,8 @@ func newDevInspectValuesFilesCommand(v *viper.Viper) *cobra.Command { | |
| cmd.Flags().StringVarP(&o.flavor, "flavor", "f", "", lang.CmdPackageCreateFlagFlavor) | ||
| cmd.Flags().StringToStringVar(&o.createSetVariables, "create-set", v.GetStringMapString(VPkgCreateSet), lang.CmdPackageCreateFlagSet) | ||
| cmd.Flags().StringToStringVar(&o.deploySetVariables, "deploy-set", v.GetStringMapString(VPkgDeploySet), lang.CmdPackageDeployFlagSet) | ||
| cmd.Flags().StringSliceVar(&o.valuesFiles, "values", []string{}, "Path to values file(s) for templating") | ||
| cmd.Flags().StringToStringVar(&o.setValues, "set-values", map[string]string{}, "Set specific values via command line (format: key.path=value)") | ||
| cmd.Flags().StringVar(&o.kubeVersion, "kube-version", "", lang.CmdDevFlagKubeVersion) | ||
|
|
||
| return cmd | ||
|
|
@@ -242,9 +271,29 @@ func (o *devInspectValuesFilesOptions) run(ctx context.Context, args []string) e | |
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Parse values from files | ||
| values, err := value.ParseFiles(ctx, o.valuesFiles, value.ParseFilesOptions{}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some duplication in this block, that can be pulled out into a common function. I know there's a few active PRs with blocks like this, so I think a follow up PR afterwards would be reasonable
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does how up pretty often. This makes sense to me as two steps in the CLI layer because it's coming from two different sources (rather than wrapping both load valuesfiles and setvalues in the same helper func). The setValue step would definitely benefit from abstracting out the loop and path parsing though. I'll make a followup issue for it |
||
| if err != nil { | ||
| return fmt.Errorf("unable to parse values files: %w", err) | ||
| } | ||
|
|
||
| // Apply CLI --set-values overrides | ||
| for key, val := range o.setValues { | ||
| // Convert key to path format (ensure it starts with .) | ||
| path := value.Path(key) | ||
| if !strings.HasPrefix(key, ".") { | ||
| path = value.Path("." + key) | ||
| } | ||
| if err := values.Set(path, val); err != nil { | ||
| return fmt.Errorf("unable to set value at path %s: %w", key, err) | ||
| } | ||
| } | ||
|
|
||
| opts := packager.InspectDefinitionResourcesOptions{ | ||
| CreateSetVariables: o.createSetVariables, | ||
| DeploySetVariables: o.deploySetVariables, | ||
| Values: values, | ||
| Flavor: o.flavor, | ||
| KubeVersion: o.kubeVersion, | ||
| CachePath: cachePath, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: {{ .Values.app.name }} | ||
| spec: | ||
| replicas: {{ .Values.app.replicas }} | ||
| selector: | ||
| matchLabels: | ||
| app: {{ .Values.app.name }} | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: {{ .Values.app.name }} | ||
| spec: | ||
| containers: | ||
| - name: httpd | ||
| image: {{ .Values.app.image.repository }}:{{ .Values.app.image.tag }} | ||
| ports: | ||
| - containerPort: {{ .Values.app.port }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #type: manifest | ||
| #source: /var/folders/2s/03x_k4gj0g30dv1qs_p39z3h0000gn/T/zarf-1945337041/httpd/manifests/deployment.yaml | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: my-httpd-app | ||
| spec: | ||
| replicas: 3 | ||
| selector: | ||
| matchLabels: | ||
| app: my-httpd-app | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: my-httpd-app | ||
| spec: | ||
| containers: | ||
| - name: httpd | ||
| image: httpd:2.4 | ||
| ports: | ||
| - containerPort: 80 | ||
| --- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #type: manifest | ||
| #source: /var/folders/2s/03x_k4gj0g30dv1qs_p39z3h0000gn/T/zarf-1945337041/httpd/manifests/deployment.yaml | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: overridden-app | ||
| spec: | ||
| replicas: 5 | ||
| selector: | ||
| matchLabels: | ||
| app: overridden-app | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: overridden-app | ||
| spec: | ||
| containers: | ||
| - name: httpd | ||
| image: nginx:latest | ||
| ports: | ||
| - containerPort: 8080 | ||
| --- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| app: | ||
| name: my-httpd-app | ||
| replicas: 3 | ||
| image: | ||
| repository: httpd | ||
| tag: "2.4" | ||
| port: 80 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| kind: ZarfPackageConfig | ||
| metadata: | ||
| name: manifest-with-package-values | ||
|
|
||
| values: | ||
| files: | ||
| - default-values.yaml | ||
|
|
||
| components: | ||
| - name: httpd | ||
| manifests: | ||
| - name: httpd-manifest | ||
| files: | ||
| - deployment.yaml | ||
| template: true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: httpd | ||
| spec: | ||
| replicas: {{ .Values.replicas }} | ||
| selector: | ||
| matchLabels: | ||
| app: httpd | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: httpd | ||
| spec: | ||
| containers: | ||
| - name: httpd | ||
| image: httpd:{{ .Values.imageTag }} | ||
| ports: | ||
| - containerPort: {{ .Values.port }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #type: manifest | ||
| #source: /var/folders/2s/03x_k4gj0g30dv1qs_p39z3h0000gn/T/zarf-1945337041/httpd/manifests/deployment.yaml | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: httpd | ||
| spec: | ||
| replicas: 5 | ||
| selector: | ||
| matchLabels: | ||
| app: httpd | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: httpd | ||
| spec: | ||
| containers: | ||
| - name: httpd | ||
| image: httpd:latest | ||
| ports: | ||
| - containerPort: 8080 | ||
| --- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| replicas: 2 | ||
| imageTag: 2.4 | ||
| port: 8080 |
Uh oh!
There was an error while loading. Please reload this page.