Skip to content

Commit 7e3766c

Browse files
kate-goldenringbacongobbler
authored andcommitted
feat: support specifying components in a SpinApp
Signed-off-by: Matthew Fisher <[email protected]> Signed-off-by: Kate Goldenring <[email protected]>
1 parent b6280bb commit 7e3766c

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

pkg/cmd/scaffold.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type ScaffoldOptions struct {
2929
targetCPUUtilizationPercentage int32
3030
targetMemoryUtilizationPercentage int32
3131
variables map[string]string
32+
components []string
3233
}
3334

3435
var scaffoldOpts = ScaffoldOptions{}
@@ -49,6 +50,7 @@ type appConfig struct {
4950
TargetCPUUtilizationPercentage int32
5051
TargetMemoryUtilizationPercentage int32
5152
Variables map[string]string
53+
Components []string
5254
}
5355

5456
var manifestStr = `apiVersion: core.spinkube.dev/v1alpha1
@@ -70,6 +72,12 @@ spec:
7072
value: {{ $value }}
7173
{{- end }}
7274
{{- end }}
75+
{{- if .Components }}
76+
components:
77+
{{- range $c := .Components }}
78+
- {{ $c }}
79+
{{- end }}
80+
{{- end }}
7381
{{- if or .CPULimit .MemoryLimit }}
7482
resources:
7583
limits:
@@ -263,6 +271,7 @@ func scaffold(opts ScaffoldOptions) ([]byte, error) {
263271
Autoscaler: opts.autoscaler,
264272
ImagePullSecrets: opts.imagePullSecrets,
265273
Variables: opts.variables,
274+
Components: opts.components,
266275
}
267276

268277
if opts.configfile != "" {
@@ -323,6 +332,7 @@ func init() {
323332
scaffoldCmd.Flags().StringVarP(&scaffoldOpts.configfile, "runtime-config-file", "c", "", "Path to runtime config file")
324333
scaffoldCmd.Flags().StringSliceVarP(&scaffoldOpts.imagePullSecrets, "image-pull-secret", "s", []string{}, "Secrets in the same namespace to use for pulling the image")
325334
scaffoldCmd.PersistentFlags().StringToStringVarP(&scaffoldOpts.variables, "variable", "v", nil, "Application variable (name=value) to be provided to the application")
335+
scaffoldCmd.PersistentFlags().StringSliceVarP(&scaffoldOpts.components, "component", "", nil, "Component ID to run. This can be specified multiple times. The default is all components.")
326336

327337
if err := scaffoldCmd.MarkFlagRequired("from"); err != nil {
328338
log.Fatal(err)

pkg/cmd/scaffold_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ func TestScaffoldOutput(t *testing.T) {
9898
},
9999
expected: "variables.yml",
100100
},
101+
{
102+
name: "components are specified",
103+
opts: ScaffoldOptions{
104+
from: "ghcr.io/foo/example-app:v0.1.0",
105+
replicas: 2,
106+
executor: "containerd-shim-spin",
107+
components: []string{
108+
"hello",
109+
"world",
110+
},
111+
},
112+
expected: "components.yml",
113+
},
101114
}
102115

103116
for _, tc := range testcases {

pkg/cmd/testdata/components.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: core.spinoperator.dev/v1alpha1
2+
kind: SpinApp
3+
metadata:
4+
name: example-app
5+
spec:
6+
image: "ghcr.io/foo/example-app:v0.1.0"
7+
executor: containerd-shim-spin
8+
replicas: 2
9+
components:
10+
- hello
11+
- world

0 commit comments

Comments
 (0)