Skip to content

Commit 475f206

Browse files
fix: better check if spot force is set (#352)
* fix: better check if spot force is set * test: add another test for spot force
1 parent f5866e5 commit 475f206

File tree

12 files changed

+800
-3
lines changed

12 files changed

+800
-3
lines changed

cmd/template_lagoonservices_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,47 @@ func TestTemplateLagoonServices(t *testing.T) {
152152
templatePath: "testoutput",
153153
want: "internal/testdata/complex/service-templates/service5",
154154
},
155+
{
156+
name: "test2c nginx-php deployment - spot workloads enabled",
157+
args: testdata.GetSeedData(
158+
testdata.TestData{
159+
ProjectName: "example-project",
160+
EnvironmentName: "main",
161+
Branch: "main",
162+
LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml",
163+
ImageReferences: map[string]string{
164+
"nginx": "harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
165+
"php": "harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
166+
"cli": "harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
167+
"redis": "harbor.example/example-project/main/redis@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
168+
"varnish": "harbor.example/example-project/main/varnish@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
169+
},
170+
ProjectVariables: []lagoon.EnvironmentVariable{
171+
{
172+
Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD",
173+
Value: "enabled",
174+
Scope: "build",
175+
},
176+
{
177+
Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION",
178+
Value: "enabled",
179+
Scope: "global",
180+
},
181+
{
182+
Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_TYPES",
183+
Value: "nginx,nginx-persistent,nginx-php,nginx-php-persistent",
184+
Scope: "global",
185+
},
186+
{
187+
Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES",
188+
Value: "cli,cli-persistent",
189+
Scope: "global",
190+
},
191+
},
192+
}, true),
193+
templatePath: "testoutput",
194+
want: "internal/testdata/complex/service-templates/service6",
195+
},
155196
{
156197
name: "test3 - funky pvcs",
157198
description: "only create pvcs of the requested persistent-name in the docker-compose file",

internal/generator/services.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ func composeToServiceValues(
360360
tt := strings.Split(t, ":")
361361
if tt[0] == lagoonType {
362362
useSpot = true
363-
if tt[1] == "force" {
363+
// check if the length of the split is more than one indicating that `force` is provided
364+
if len(tt) > 1 && tt[1] == "force" {
364365
forceSpot = true
365366
}
366367
}
@@ -372,7 +373,8 @@ func composeToServiceValues(
372373
tt := strings.Split(t, ":")
373374
if tt[0] == lagoonType {
374375
cronjobUseSpot = true
375-
if tt[1] == "force" {
376+
// check if the length of the split is more than one indicating that `force` is provided
377+
if len(tt) > 1 && tt[1] == "force" {
376378
cronjobForceSpot = true
377379
}
378380
}

internal/generator/services_test.go

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ func Test_composeToServiceValues(t *testing.T) {
624624
},
625625
},
626626
{
627-
name: "test14 - spot instances",
627+
name: "test14a - spot instances",
628628
args: args{
629629
buildValues: &BuildValues{
630630
Namespace: "example-project-main",
@@ -682,6 +682,65 @@ func Test_composeToServiceValues(t *testing.T) {
682682
},
683683
},
684684
},
685+
{
686+
name: "test14b - spot instance without force",
687+
args: args{
688+
buildValues: &BuildValues{
689+
Namespace: "example-project-main",
690+
Project: "example-project",
691+
ImageRegistry: "harbor.example",
692+
Environment: "main",
693+
EnvironmentType: "production",
694+
Branch: "main",
695+
BuildType: "branch",
696+
ServiceTypeOverrides: &lagoon.EnvironmentVariable{},
697+
EnvironmentVariables: []lagoon.EnvironmentVariable{
698+
{Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION", Value: "enabled", Scope: "global"},
699+
{Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT", Value: "enabled", Scope: "global"},
700+
{Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"},
701+
{Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"},
702+
{Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"},
703+
{Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT_CRONJOB_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"},
704+
},
705+
LagoonYAML: lagoon.YAML{
706+
Environments: lagoon.Environments{
707+
"main": lagoon.Environment{},
708+
},
709+
},
710+
},
711+
composeService: "nginx",
712+
composeServiceValues: composetypes.ServiceConfig{
713+
Labels: composetypes.Labels{
714+
"lagoon.type": "nginx",
715+
},
716+
Build: &composetypes.BuildConfig{
717+
Context: ".",
718+
Dockerfile: "../testdata/basic/docker/basic.dockerfile",
719+
},
720+
},
721+
},
722+
want: ServiceValues{
723+
Name: "nginx",
724+
OverrideName: "nginx",
725+
Type: "nginx",
726+
DBaaSEnvironment: "production",
727+
AutogeneratedRoutesEnabled: true,
728+
AutogeneratedRoutesTLSAcme: true,
729+
UseSpotInstances: true,
730+
CronjobUseSpotInstances: true,
731+
ForceSpotInstances: false,
732+
CronjobForceSpotInstances: false,
733+
InPodCronjobs: []lagoon.Cronjob{},
734+
NativeCronjobs: []lagoon.Cronjob{},
735+
Replicas: 2,
736+
ImageBuild: &ImageBuild{
737+
TemporaryImage: "example-project-main-nginx",
738+
Context: ".",
739+
DockerFile: "../testdata/basic/docker/basic.dockerfile",
740+
BuildImage: "harbor.example/example-project/main/nginx:latest",
741+
},
742+
},
743+
},
685744
{
686745
name: "test15 - multiple service ports",
687746
args: args{
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: CronJob
4+
metadata:
5+
annotations:
6+
lagoon.sh/branch: main
7+
lagoon.sh/version: v2.7.x
8+
creationTimestamp: null
9+
labels:
10+
app.kubernetes.io/managed-by: build-deploy-tool
11+
lagoon.sh/buildType: branch
12+
lagoon.sh/environment: main
13+
lagoon.sh/environmentType: production
14+
lagoon.sh/project: example-project
15+
lagoon.sh/service: cli
16+
lagoon.sh/service-type: cli-persistent
17+
lagoon.sh/spot: "true"
18+
lagoon.sh/template: cli-persistent-0.1.0
19+
name: cronjob-cli-drush-cron2
20+
spec:
21+
concurrencyPolicy: Forbid
22+
failedJobsHistoryLimit: 1
23+
jobTemplate:
24+
metadata:
25+
creationTimestamp: null
26+
spec:
27+
template:
28+
metadata:
29+
annotations:
30+
lagoon.sh/branch: main
31+
lagoon.sh/configMapSha: abcdefg1234567890
32+
lagoon.sh/version: v2.7.x
33+
creationTimestamp: null
34+
labels:
35+
app.kubernetes.io/managed-by: build-deploy-tool
36+
lagoon.sh/buildType: branch
37+
lagoon.sh/environment: main
38+
lagoon.sh/environmentType: production
39+
lagoon.sh/project: example-project
40+
lagoon.sh/service: cli
41+
lagoon.sh/service-type: cli-persistent
42+
lagoon.sh/spot: "true"
43+
lagoon.sh/template: cli-persistent-0.1.0
44+
spec:
45+
affinity:
46+
nodeAffinity:
47+
preferredDuringSchedulingIgnoredDuringExecution:
48+
- preference:
49+
matchExpressions:
50+
- key: lagoon.sh/spot
51+
operator: Exists
52+
weight: 1
53+
containers:
54+
- command:
55+
- /lagoon/cronjob.sh
56+
- drush cron
57+
env:
58+
- name: LAGOON_GIT_SHA
59+
value: "0000000000000000000000000000000000000000"
60+
- name: SERVICE_NAME
61+
value: cli
62+
envFrom:
63+
- configMapRef:
64+
name: lagoon-env
65+
image: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8
66+
imagePullPolicy: Always
67+
name: cronjob-cli-drush-cron2
68+
resources:
69+
requests:
70+
cpu: 10m
71+
memory: 10Mi
72+
securityContext: {}
73+
volumeMounts:
74+
- mountPath: /var/run/secrets/lagoon/sshkey/
75+
name: lagoon-sshkey
76+
readOnly: true
77+
- mountPath: /app/docroot/sites/default/files//php
78+
name: nginx-php-twig
79+
- mountPath: /app/docroot/sites/default/files/
80+
name: nginx-php
81+
dnsConfig:
82+
options:
83+
- name: timeout
84+
value: "60"
85+
- name: attempts
86+
value: "10"
87+
enableServiceLinks: false
88+
imagePullSecrets:
89+
- name: lagoon-internal-registry-secret
90+
priorityClassName: lagoon-priority-production
91+
restartPolicy: Never
92+
securityContext:
93+
fsGroup: 10001
94+
runAsGroup: 0
95+
runAsUser: 10000
96+
tolerations:
97+
- effect: NoSchedule
98+
key: lagoon.sh/spot
99+
operator: Exists
100+
- effect: PreferNoSchedule
101+
key: lagoon.sh/spot
102+
operator: Exists
103+
volumes:
104+
- name: lagoon-sshkey
105+
secret:
106+
defaultMode: 420
107+
secretName: lagoon-sshkey
108+
- emptyDir: {}
109+
name: nginx-php-twig
110+
- name: nginx-php
111+
persistentVolumeClaim:
112+
claimName: nginx-php
113+
schedule: 18,48 * * * *
114+
startingDeadlineSeconds: 240
115+
successfulJobsHistoryLimit: 0
116+
status: {}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
annotations:
6+
lagoon.sh/branch: main
7+
lagoon.sh/version: v2.7.x
8+
creationTimestamp: null
9+
labels:
10+
app.kubernetes.io/instance: cli
11+
app.kubernetes.io/managed-by: build-deploy-tool
12+
app.kubernetes.io/name: cli-persistent
13+
lagoon.sh/buildType: branch
14+
lagoon.sh/environment: main
15+
lagoon.sh/environmentType: production
16+
lagoon.sh/project: example-project
17+
lagoon.sh/service: cli
18+
lagoon.sh/service-type: cli-persistent
19+
lagoon.sh/template: cli-persistent-0.1.0
20+
name: cli
21+
spec:
22+
replicas: 1
23+
selector:
24+
matchLabels:
25+
app.kubernetes.io/instance: cli
26+
app.kubernetes.io/name: cli-persistent
27+
strategy: {}
28+
template:
29+
metadata:
30+
annotations:
31+
lagoon.sh/branch: main
32+
lagoon.sh/configMapSha: abcdefg1234567890
33+
lagoon.sh/version: v2.7.x
34+
creationTimestamp: null
35+
labels:
36+
app.kubernetes.io/instance: cli
37+
app.kubernetes.io/managed-by: build-deploy-tool
38+
app.kubernetes.io/name: cli-persistent
39+
lagoon.sh/buildType: branch
40+
lagoon.sh/environment: main
41+
lagoon.sh/environmentType: production
42+
lagoon.sh/project: example-project
43+
lagoon.sh/service: cli
44+
lagoon.sh/service-type: cli-persistent
45+
lagoon.sh/template: cli-persistent-0.1.0
46+
spec:
47+
containers:
48+
- env:
49+
- name: LAGOON_GIT_SHA
50+
value: "0000000000000000000000000000000000000000"
51+
- name: CRONJOBS
52+
value: |
53+
3,18,33,48 * * * * drush cron
54+
- name: SERVICE_NAME
55+
value: cli
56+
envFrom:
57+
- configMapRef:
58+
name: lagoon-env
59+
image: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8
60+
imagePullPolicy: Always
61+
name: cli
62+
readinessProbe:
63+
exec:
64+
command:
65+
- /bin/sh
66+
- -c
67+
- if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness;
68+
fi
69+
failureThreshold: 3
70+
initialDelaySeconds: 5
71+
periodSeconds: 2
72+
resources:
73+
requests:
74+
cpu: 10m
75+
memory: 10Mi
76+
securityContext: {}
77+
volumeMounts:
78+
- mountPath: /var/run/secrets/lagoon/sshkey/
79+
name: lagoon-sshkey
80+
readOnly: true
81+
- mountPath: /app/docroot/sites/default/files//php
82+
name: nginx-php-twig
83+
- mountPath: /app/docroot/sites/default/files/
84+
name: nginx-php
85+
enableServiceLinks: false
86+
imagePullSecrets:
87+
- name: lagoon-internal-registry-secret
88+
priorityClassName: lagoon-priority-production
89+
securityContext:
90+
fsGroup: 10001
91+
runAsGroup: 0
92+
runAsUser: 10000
93+
volumes:
94+
- name: lagoon-sshkey
95+
secret:
96+
defaultMode: 420
97+
secretName: lagoon-sshkey
98+
- emptyDir: {}
99+
name: nginx-php-twig
100+
- name: nginx-php
101+
persistentVolumeClaim:
102+
claimName: nginx-php
103+
status: {}

0 commit comments

Comments
 (0)