diff --git a/pkg/cmd/scaffold.go b/pkg/cmd/scaffold.go index 865cd18..79b3a63 100644 --- a/pkg/cmd/scaffold.go +++ b/pkg/cmd/scaffold.go @@ -121,7 +121,7 @@ spec: averageUtilization: {{ .TargetCpuUtilizationPercentage }} - type: Resource resource: - name: memory + name: memory target: type: Utilization averageUtilization: {{ .TargetMemoryUtilizationPercentage }} @@ -132,20 +132,20 @@ metadata: name: {{ .Name }}-autoscaler spec: scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment + apiVersion: apps/v1 + kind: Deployment name: {{ .Name }} minReplicaCount: {{ .Replicas }} maxReplicaCount: {{ .MaxReplicas }} triggers: - - type: cpu - metricType: Utilization - metadata: - value: "{{ .TargetCpuUtilizationPercentage }}" - - type: memory - metricType: Utilization - metadata: - value: "{{ .TargetMemoryUtilizationPercentage }}" + - type: cpu + metricType: Utilization + metadata: + value: "{{ .TargetCpuUtilizationPercentage }}" + - type: memory + metricType: Utilization + metadata: + value: "{{ .TargetMemoryUtilizationPercentage }}" {{- end }} {{- end }} ` diff --git a/pkg/cmd/scaffold_test.go b/pkg/cmd/scaffold_test.go index 7814873..c941101 100644 --- a/pkg/cmd/scaffold_test.go +++ b/pkg/cmd/scaffold_test.go @@ -55,6 +55,36 @@ func TestScaffoldOutput(t *testing.T) { }, expected: "multiple_image_secrets.yml", }, + { + name: "HPA autoscaler support", + opts: ScaffoldOptions{ + from: "ghcr.io/foo/example-app:v0.1.0", + executor: "containerd-shim-spin", + autoscaler: "hpa", + cpuLimit: "100m", + memoryLimit: "128Mi", + replicas: 2, + maxReplicas: 3, + targetCpuUtilizationPercentage: 60, + targetMemoryUtilizationPercentage: 60, + }, + expected: "hpa_autoscaler.yml", + }, + { + name: "KEDA autoscaler support", + opts: ScaffoldOptions{ + from: "ghcr.io/foo/example-app:v0.1.0", + executor: "containerd-shim-spin", + autoscaler: "keda", + cpuLimit: "100m", + memoryLimit: "128Mi", + replicas: 2, + maxReplicas: 3, + targetCpuUtilizationPercentage: 60, + targetMemoryUtilizationPercentage: 60, + }, + expected: "keda_autoscaler.yml", + }, } for _, tc := range testcases { diff --git a/pkg/cmd/testdata/hpa_autoscaler.yml b/pkg/cmd/testdata/hpa_autoscaler.yml new file mode 100644 index 0000000..2a81e70 --- /dev/null +++ b/pkg/cmd/testdata/hpa_autoscaler.yml @@ -0,0 +1,37 @@ +apiVersion: core.spinoperator.dev/v1alpha1 +kind: SpinApp +metadata: + name: example-app +spec: + image: "ghcr.io/foo/example-app:v0.1.0" + executor: containerd-shim-spin + enableAutoscaling: true + resources: + limits: + cpu: 100m + memory: 128Mi +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: example-app-autoscaler +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: example-app + minReplicas: 2 + maxReplicas: 3 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 60 + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: 60 diff --git a/pkg/cmd/testdata/keda_autoscaler.yml b/pkg/cmd/testdata/keda_autoscaler.yml new file mode 100644 index 0000000..b5f792e --- /dev/null +++ b/pkg/cmd/testdata/keda_autoscaler.yml @@ -0,0 +1,33 @@ +apiVersion: core.spinoperator.dev/v1alpha1 +kind: SpinApp +metadata: + name: example-app +spec: + image: "ghcr.io/foo/example-app:v0.1.0" + executor: containerd-shim-spin + enableAutoscaling: true + resources: + limits: + cpu: 100m + memory: 128Mi +--- +apiVersion: keda.sh/v1alpha1 +kind: ScaledObject +metadata: + name: example-app-autoscaler +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: example-app + minReplicaCount: 2 + maxReplicaCount: 3 + triggers: + - type: cpu + metricType: Utilization + metadata: + value: "60" + - type: memory + metricType: Utilization + metadata: + value: "60"