Skip to content

Commit

Permalink
feat: support specifying components in a SpinApp
Browse files Browse the repository at this point in the history
Signed-off-by: Kate Goldenring <[email protected]>
Signed-off-by: Matthew Fisher <[email protected]>
  • Loading branch information
kate-goldenring authored and bacongobbler committed Nov 4, 2024
1 parent b6280bb commit e1289c5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type ScaffoldOptions struct {
targetCPUUtilizationPercentage int32
targetMemoryUtilizationPercentage int32
variables map[string]string
components []string
}

var scaffoldOpts = ScaffoldOptions{}
Expand All @@ -49,6 +50,7 @@ type appConfig struct {
TargetCPUUtilizationPercentage int32
TargetMemoryUtilizationPercentage int32
Variables map[string]string
Components []string
}

var manifestStr = `apiVersion: core.spinkube.dev/v1alpha1
Expand All @@ -70,6 +72,12 @@ spec:
value: {{ $value }}
{{- end }}
{{- end }}
{{- if .Components }}
components:
{{- range $c := .Components }}
- {{ $c }}
{{- end }}
{{- end }}
{{- if or .CPULimit .MemoryLimit }}
resources:
limits:
Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions pkg/cmd/scaffold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions pkg/cmd/testdata/components.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e1289c5

Please sign in to comment.