diff --git a/pkg/cmd/scaffold.go b/pkg/cmd/scaffold.go index 063c500..68d3a5b 100644 --- a/pkg/cmd/scaffold.go +++ b/pkg/cmd/scaffold.go @@ -29,6 +29,7 @@ type ScaffoldOptions struct { targetCPUUtilizationPercentage int32 targetMemoryUtilizationPercentage int32 variables map[string]string + components []string } var scaffoldOpts = ScaffoldOptions{} @@ -49,6 +50,7 @@ type appConfig struct { TargetCPUUtilizationPercentage int32 TargetMemoryUtilizationPercentage int32 Variables map[string]string + Components []string } var manifestStr = `apiVersion: core.spinkube.dev/v1alpha1 @@ -70,6 +72,12 @@ spec: value: {{ $value }} {{- end }} {{- end }} +{{- if .Components }} + components: +{{- range $c := .Components }} + - {{ $c }} +{{- end }} +{{- end }} {{- if or .CPULimit .MemoryLimit }} resources: limits: @@ -263,6 +271,7 @@ func scaffold(opts ScaffoldOptions) ([]byte, error) { Autoscaler: opts.autoscaler, ImagePullSecrets: opts.imagePullSecrets, Variables: opts.variables, + Components: opts.components, } if opts.configfile != "" { @@ -323,6 +332,7 @@ func init() { 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 variable (name=value) to be provided to the application") + scaffoldCmd.PersistentFlags().StringSliceVarP(&scaffoldOpts.components, "component", "", nil, "Component ID to run. This can be specified multiple times. The default is all components.") if err := scaffoldCmd.MarkFlagRequired("from"); err != nil { log.Fatal(err) diff --git a/pkg/cmd/scaffold_test.go b/pkg/cmd/scaffold_test.go index 75c7527..0c75b01 100644 --- a/pkg/cmd/scaffold_test.go +++ b/pkg/cmd/scaffold_test.go @@ -98,6 +98,19 @@ func TestScaffoldOutput(t *testing.T) { }, expected: "variables.yml", }, + { + name: "components are specified", + opts: ScaffoldOptions{ + from: "ghcr.io/foo/example-app:v0.1.0", + replicas: 2, + executor: "containerd-shim-spin", + components: []string{ + "hello", + "world", + }, + }, + expected: "components.yml", + }, } for _, tc := range testcases { diff --git a/pkg/cmd/testdata/components.yml b/pkg/cmd/testdata/components.yml new file mode 100644 index 0000000..4518db3 --- /dev/null +++ b/pkg/cmd/testdata/components.yml @@ -0,0 +1,11 @@ +apiVersion: core.spinkube.dev/v1alpha1 +kind: SpinApp +metadata: + name: example-app +spec: + image: "ghcr.io/foo/example-app:v0.1.0" + executor: containerd-shim-spin + replicas: 2 + components: + - hello + - world