Skip to content

Commit 146c924

Browse files
authored
Merge pull request #96 from Mossaka/serviceAccountName
feat: add service account name to scaffold command
2 parents 04d5916 + 9df4969 commit 146c924

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed

pkg/cmd/scaffold.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type ScaffoldOptions struct {
2727
memoryRequest string
2828
output string
2929
replicas int32
30+
serviceAccountName string
3031
targetCPUUtilizationPercentage int32
3132
targetMemoryUtilizationPercentage int32
3233
variables map[string]string
@@ -49,6 +50,7 @@ type appConfig struct {
4950
Name string
5051
Replicas int32
5152
RuntimeConfig string
53+
ServiceAccountName string
5254
TargetCPUUtilizationPercentage int32
5355
TargetMemoryUtilizationPercentage int32
5456
Variables map[string]string
@@ -71,6 +73,9 @@ spec:
7173
podLabels:
7274
azure.workload.identity/use: "true"
7375
{{- end }}
76+
{{- if .ServiceAccountName }}
77+
serviceAccountName: {{ .ServiceAccountName }}
78+
{{- end }}
7479
{{- if .Variables }}
7580
variables:
7681
{{- range $key, $value := .Variables }}
@@ -279,6 +284,7 @@ func scaffold(opts ScaffoldOptions) ([]byte, error) {
279284
Variables: opts.variables,
280285
Components: opts.components,
281286
AzureWorkloadIdentity: opts.azureWorkloadIdentity,
287+
ServiceAccountName: opts.serviceAccountName,
282288
}
283289

284290
if opts.configfile != "" {
@@ -335,6 +341,7 @@ func init() {
335341
scaffoldCmd.Flags().StringVar(&scaffoldOpts.memoryLimit, "memory-limit", "", "The maximum amount of memory the application is allowed to use")
336342
scaffoldCmd.Flags().StringVar(&scaffoldOpts.memoryRequest, "memory-request", "", "The amount of memory requested by the application. Used to determine which node the application will run on")
337343
scaffoldCmd.Flags().BoolVar(&scaffoldOpts.azureWorkloadIdentity, "azure-identity", false, "Enable Azure Workload Identity for the application")
344+
scaffoldCmd.Flags().StringVar(&scaffoldOpts.serviceAccountName, "service-account-name", "", "The name of the service account to use for the application")
338345
scaffoldCmd.Flags().StringVarP(&scaffoldOpts.from, "from", "f", "", "Reference in the registry of the application")
339346
scaffoldCmd.Flags().StringVarP(&scaffoldOpts.output, "out", "o", "", "Path to file to write manifest yaml")
340347
scaffoldCmd.Flags().StringVarP(&scaffoldOpts.configfile, "runtime-config-file", "c", "", "Path to runtime config file")

pkg/cmd/scaffold_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,42 @@ func TestScaffoldOutput(t *testing.T) {
6565
},
6666
expected: "multiple_image_secrets.yml",
6767
},
68+
{
69+
name: "service account name is provided",
70+
opts: ScaffoldOptions{
71+
from: "ghcr.io/foo/example-app:v0.1.0",
72+
replicas: 2,
73+
executor: "containerd-shim-spin",
74+
serviceAccountName: "my-service-account",
75+
},
76+
expected: "service_account_name.yml",
77+
},
78+
{
79+
name: "service account name is not provided",
80+
opts: ScaffoldOptions{
81+
from: "ghcr.io/foo/example-app:v0.1.0",
82+
replicas: 2,
83+
executor: "containerd-shim-spin",
84+
serviceAccountName: "",
85+
},
86+
expected: "no_service_account_name.yml",
87+
},
88+
{
89+
name: "service account with HPA autoscaler",
90+
opts: ScaffoldOptions{
91+
from: "ghcr.io/foo/example-app:v0.1.0",
92+
executor: "containerd-shim-spin",
93+
autoscaler: "hpa",
94+
cpuLimit: "100m",
95+
memoryLimit: "128Mi",
96+
replicas: 2,
97+
maxReplicas: 3,
98+
targetCPUUtilizationPercentage: 60,
99+
targetMemoryUtilizationPercentage: 60,
100+
serviceAccountName: "my-service-account",
101+
},
102+
expected: "hpa_service_account.yml",
103+
},
68104
{
69105
name: "HPA autoscaler support",
70106
opts: ScaffoldOptions{
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: core.spinkube.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+
enableAutoscaling: true
9+
serviceAccountName: my-service-account
10+
resources:
11+
limits:
12+
cpu: 100m
13+
memory: 128Mi
14+
---
15+
apiVersion: autoscaling/v2
16+
kind: HorizontalPodAutoscaler
17+
metadata:
18+
name: example-app-autoscaler
19+
spec:
20+
scaleTargetRef:
21+
apiVersion: apps/v1
22+
kind: Deployment
23+
name: example-app
24+
minReplicas: 2
25+
maxReplicas: 3
26+
metrics:
27+
- type: Resource
28+
resource:
29+
name: cpu
30+
target:
31+
type: Utilization
32+
averageUtilization: 60
33+
- type: Resource
34+
resource:
35+
name: memory
36+
target:
37+
type: Utilization
38+
averageUtilization: 60
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: core.spinkube.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
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: core.spinkube.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+
serviceAccountName: my-service-account

0 commit comments

Comments
 (0)