Skip to content

Commit b4c1764

Browse files
committed
Updating templates and moving tests
1 parent 90f534e commit b4c1764

31 files changed

+1220
-582
lines changed

pkg/config/draftconfig.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type BuilderVar struct {
3737
Default BuilderVarDefault `yaml:"default"`
3838
Description string `yaml:"description"`
3939
ExampleValues []string `yaml:"exampleValues"`
40+
AllowedValues []string `yaml:"allowedValues"`
4041
Type string `yaml:"type"`
4142
Kind string `yaml:"kind"`
4243
Value string `yaml:"value"`
@@ -50,9 +51,10 @@ type BuilderVarDefault struct {
5051
Value string `yaml:"value"`
5152
}
5253

53-
// BuilderVarConditionalReference holds a reference to a variable thats value can effect validation/transformation of the associated variable
54+
// BuilderVarConditionalReference holds a reference to a variable thats value can effect usage/validation/transformation of the associated variable
5455
type BuilderVarConditionalReference struct {
55-
ReferenceVar string `yaml:"referenceVar"`
56+
ReferenceVar string `yaml:"referenceVar"`
57+
ConditionValue string `yaml:"conditionValue"`
5658
}
5759

5860
func NewConfigFromFS(fileSys fs.FS, path string) (*DraftConfig, error) {

pkg/config/draftconfig_template_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ var validVariableKinds = map[string]bool{
4444
"filePath": true,
4545
"flag": true,
4646
"helmChartOverrides": true,
47+
"imagePullPolicy": true,
4748
"ingressHostName": true,
4849
"kubernetesNamespace": true,
50+
"kubernetesProbeHttpPath": true,
4951
"kubernetesProbePeriod": true,
5052
"kubernetesProbeTimeout": true,
5153
"kubernetesProbeThreshold": true,
54+
"kubernetesProbeType": true,
5255
"kubernetesProbeDelay": true,
5356
"kubernetesResourceLimit": true,
5457
"kubernetesResourceName": true,

pkg/config/validators/validators.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,52 @@ import (
88
func GetValidator(variableKind string) func(string) error {
99
switch variableKind {
1010
case "envVarMap":
11-
return KeyValueMapValidator
11+
return keyValueMapValidator
12+
case "imagePullPolicy":
13+
return imagePullPolicyValidator
14+
case "kubernetesProbeType":
15+
return kubernetesProbeTypeValidator
16+
case "scalingResourceType":
17+
return scalingResourceTypeValidator
1218
default:
13-
return DefaultValidator
19+
return defaultValidator
1420
}
1521
}
1622

17-
func KeyValueMapValidator(input string) error {
23+
func imagePullPolicyValidator(input string) error {
24+
switch input {
25+
case "Always", "IfNotPresent", "Never":
26+
return nil
27+
default:
28+
return fmt.Errorf("invalid image pull policy: %s", input)
29+
}
30+
}
31+
32+
func scalingResourceTypeValidator(input string) error {
33+
switch input {
34+
case "cpu", "memory":
35+
return nil
36+
default:
37+
return fmt.Errorf("invalid scaling resource type: %s", input)
38+
}
39+
}
40+
41+
func kubernetesProbeTypeValidator(input string) error {
42+
switch input {
43+
case "httpGet", "tcpSocket":
44+
return nil
45+
default:
46+
return fmt.Errorf("invalid probe type: %s", input)
47+
}
48+
}
49+
50+
func keyValueMapValidator(input string) error {
1851
if err := json.Unmarshal([]byte(input), &map[string]string{}); err != nil {
1952
return fmt.Errorf("failed to unmarshal variable as map[string]string: %s", err)
2053
}
2154
return nil
2255
}
2356

24-
func DefaultValidator(input string) error {
57+
func defaultValidator(input string) error {
2558
return nil
2659
}

pkg/config/validators/validators_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,29 @@ func TestGetValidator(t *testing.T) {
1111
}
1212

1313
func TestDefaultValidator(t *testing.T) {
14-
assert.Nil(t, DefaultValidator("test"))
14+
assert.Nil(t, defaultValidator("test"))
15+
}
16+
17+
func TestKubernetesProbeTypeValidator(t *testing.T) {
18+
assert.Nil(t, kubernetesProbeTypeValidator("httpGet"))
19+
assert.Nil(t, kubernetesProbeTypeValidator("tcpSocket"))
20+
assert.NotNil(t, kubernetesProbeTypeValidator("exec"))
21+
}
22+
23+
func TestKeyValueMapValidator(t *testing.T) {
24+
assert.Nil(t, keyValueMapValidator(`{"key": "value"}`))
25+
assert.NotNil(t, keyValueMapValidator(`{"key": "value"`))
26+
}
27+
28+
func TestScalingResourceTypeValidator(t *testing.T) {
29+
assert.Nil(t, scalingResourceTypeValidator("cpu"))
30+
assert.Nil(t, scalingResourceTypeValidator("memory"))
31+
assert.NotNil(t, scalingResourceTypeValidator("disk"))
32+
}
33+
34+
func TestImagePullPolicyValidator(t *testing.T) {
35+
assert.Nil(t, imagePullPolicyValidator("Always"))
36+
assert.Nil(t, imagePullPolicyValidator("IfNotPresent"))
37+
assert.Nil(t, imagePullPolicyValidator("Never"))
38+
assert.NotNil(t, imagePullPolicyValidator("Sometimes"))
1539
}

pkg/fixtures/deployments/helm/charts/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ spec:
4242
{{- toYaml .Values.livenessProbe | nindent 12 }}
4343
readinessProbe:
4444
{{- toYaml .Values.readinessProbe | nindent 12 }}
45+
startupProbe:
46+
{{- toYaml .Values.startupProbe | nindent 12 }}
4547
resources:
4648
{{- toYaml .Values.resources | nindent 12 }}
4749
envFrom:

pkg/fixtures/deployments/helm/charts/values.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ resources:
3131
# resources, such as Minikube. If you do want to specify resources, uncomment the following
3232
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
3333
limits:
34-
cpu: "2"
34+
cpu: "1"
3535
memory: "1Gi"
3636
requests:
3737
cpu: "1"
38-
memory: "512Mi"
38+
memory: "1Gi"
3939

4040
autoscaling:
4141
enabled: false
@@ -55,6 +55,14 @@ readinessProbe:
5555
failureThreshold: 1
5656
successThreshold: 1
5757
initialDelaySeconds: 3
58+
startupProbe:
59+
tcpSocket:
60+
port: 80
61+
periodSeconds: 1
62+
timeoutSeconds: 3
63+
failureThreshold: 1
64+
successThreshold: 1
65+
initialDelaySeconds: 1
5866

5967
nodeSelector: {}
6068

pkg/fixtures/deployments/kustomize/base/deployment.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ spec:
2525
resources:
2626
requests:
2727
cpu: "1"
28-
memory: "512Mi"
28+
memory: "1Gi"
2929
limits:
30-
cpu: "2"
30+
cpu: "1"
3131
memory: "1Gi"
3232
envFrom:
3333
- configMapRef:
@@ -43,6 +43,14 @@ spec:
4343
failureThreshold: 1
4444
successThreshold: 1
4545
initialDelaySeconds: 3
46+
startupProbe:
47+
tcpSocket:
48+
port: 80
49+
periodSeconds: 1
50+
timeoutSeconds: 3
51+
failureThreshold: 1
52+
successThreshold: 1
53+
initialDelaySeconds: 1
4654
securityContext:
4755
seccompProfile:
4856
type: RuntimeDefault

pkg/fixtures/deployments/manifest/manifests/deployment.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ spec:
2525
resources:
2626
requests:
2727
cpu: "1"
28-
memory: "512Mi"
28+
memory: "1Gi"
2929
limits:
30-
cpu: "2"
30+
cpu: "1"
3131
memory: "1Gi"
3232
envFrom:
3333
- configMapRef:
@@ -43,6 +43,14 @@ spec:
4343
failureThreshold: 1
4444
successThreshold: 1
4545
initialDelaySeconds: 3
46+
startupProbe:
47+
tcpSocket:
48+
port: 80
49+
periodSeconds: 1
50+
timeoutSeconds: 3
51+
failureThreshold: 1
52+
successThreshold: 1
53+
initialDelaySeconds: 1
4654
securityContext:
4755
seccompProfile:
4856
type: RuntimeDefault
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: autoscaling/v2
2+
kind: HorizontalPodAutoscaler
3+
metadata:
4+
name: test-app
5+
labels:
6+
app.kubernetes.io/name: test-app
7+
app.kubernetes.io/part-of: test-app-project
8+
kubernetes.azure.com/generator: draft
9+
spec:
10+
scaleTargetRef:
11+
apiVersion: apps/v1
12+
kind: Deployment
13+
name: test-app
14+
minReplicas: 2
15+
maxReplicas: 5
16+
metrics:
17+
- type: Resource
18+
resource:
19+
name: memory
20+
target:
21+
type: Utilization
22+
averageUtilization: 80

0 commit comments

Comments
 (0)