Skip to content

Commit

Permalink
fix: better check if spot force is set (#352)
Browse files Browse the repository at this point in the history
* fix: better check if spot force is set

* test: add another test for spot force
  • Loading branch information
shreddedbacon authored Aug 13, 2024
1 parent f5866e5 commit 475f206
Show file tree
Hide file tree
Showing 12 changed files with 800 additions and 3 deletions.
41 changes: 41 additions & 0 deletions cmd/template_lagoonservices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,47 @@ func TestTemplateLagoonServices(t *testing.T) {
templatePath: "testoutput",
want: "internal/testdata/complex/service-templates/service5",
},
{
name: "test2c nginx-php deployment - spot workloads enabled",
args: testdata.GetSeedData(
testdata.TestData{
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml",
ImageReferences: map[string]string{
"nginx": "harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
"php": "harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
"cli": "harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
"redis": "harbor.example/example-project/main/redis@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
"varnish": "harbor.example/example-project/main/varnish@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
},
ProjectVariables: []lagoon.EnvironmentVariable{
{
Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD",
Value: "enabled",
Scope: "build",
},
{
Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION",
Value: "enabled",
Scope: "global",
},
{
Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_TYPES",
Value: "nginx,nginx-persistent,nginx-php,nginx-php-persistent",
Scope: "global",
},
{
Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES",
Value: "cli,cli-persistent",
Scope: "global",
},
},
}, true),
templatePath: "testoutput",
want: "internal/testdata/complex/service-templates/service6",
},
{
name: "test3 - funky pvcs",
description: "only create pvcs of the requested persistent-name in the docker-compose file",
Expand Down
6 changes: 4 additions & 2 deletions internal/generator/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ func composeToServiceValues(
tt := strings.Split(t, ":")
if tt[0] == lagoonType {
useSpot = true
if tt[1] == "force" {
// check if the length of the split is more than one indicating that `force` is provided
if len(tt) > 1 && tt[1] == "force" {
forceSpot = true
}
}
Expand All @@ -372,7 +373,8 @@ func composeToServiceValues(
tt := strings.Split(t, ":")
if tt[0] == lagoonType {
cronjobUseSpot = true
if tt[1] == "force" {
// check if the length of the split is more than one indicating that `force` is provided
if len(tt) > 1 && tt[1] == "force" {
cronjobForceSpot = true
}
}
Expand Down
61 changes: 60 additions & 1 deletion internal/generator/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ func Test_composeToServiceValues(t *testing.T) {
},
},
{
name: "test14 - spot instances",
name: "test14a - spot instances",
args: args{
buildValues: &BuildValues{
Namespace: "example-project-main",
Expand Down Expand Up @@ -682,6 +682,65 @@ func Test_composeToServiceValues(t *testing.T) {
},
},
},
{
name: "test14b - spot instance without force",
args: args{
buildValues: &BuildValues{
Namespace: "example-project-main",
Project: "example-project",
ImageRegistry: "harbor.example",
Environment: "main",
EnvironmentType: "production",
Branch: "main",
BuildType: "branch",
ServiceTypeOverrides: &lagoon.EnvironmentVariable{},
EnvironmentVariables: []lagoon.EnvironmentVariable{
{Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION", Value: "enabled", Scope: "global"},
{Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT", Value: "enabled", Scope: "global"},
{Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"},
{Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"},
{Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"},
{Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT_CRONJOB_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"},
},
LagoonYAML: lagoon.YAML{
Environments: lagoon.Environments{
"main": lagoon.Environment{},
},
},
},
composeService: "nginx",
composeServiceValues: composetypes.ServiceConfig{
Labels: composetypes.Labels{
"lagoon.type": "nginx",
},
Build: &composetypes.BuildConfig{
Context: ".",
Dockerfile: "../testdata/basic/docker/basic.dockerfile",
},
},
},
want: ServiceValues{
Name: "nginx",
OverrideName: "nginx",
Type: "nginx",
DBaaSEnvironment: "production",
AutogeneratedRoutesEnabled: true,
AutogeneratedRoutesTLSAcme: true,
UseSpotInstances: true,
CronjobUseSpotInstances: true,
ForceSpotInstances: false,
CronjobForceSpotInstances: false,
InPodCronjobs: []lagoon.Cronjob{},
NativeCronjobs: []lagoon.Cronjob{},
Replicas: 2,
ImageBuild: &ImageBuild{
TemporaryImage: "example-project-main-nginx",
Context: ".",
DockerFile: "../testdata/basic/docker/basic.dockerfile",
BuildImage: "harbor.example/example-project/main/nginx:latest",
},
},
},
{
name: "test15 - multiple service ports",
args: args{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
apiVersion: batch/v1
kind: CronJob
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/managed-by: build-deploy-tool
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: cli
lagoon.sh/service-type: cli-persistent
lagoon.sh/spot: "true"
lagoon.sh/template: cli-persistent-0.1.0
name: cronjob-cli-drush-cron2
spec:
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 1
jobTemplate:
metadata:
creationTimestamp: null
spec:
template:
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/configMapSha: abcdefg1234567890
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/managed-by: build-deploy-tool
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: cli
lagoon.sh/service-type: cli-persistent
lagoon.sh/spot: "true"
lagoon.sh/template: cli-persistent-0.1.0
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference:
matchExpressions:
- key: lagoon.sh/spot
operator: Exists
weight: 1
containers:
- command:
- /lagoon/cronjob.sh
- drush cron
env:
- name: LAGOON_GIT_SHA
value: "0000000000000000000000000000000000000000"
- name: SERVICE_NAME
value: cli
envFrom:
- configMapRef:
name: lagoon-env
image: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8
imagePullPolicy: Always
name: cronjob-cli-drush-cron2
resources:
requests:
cpu: 10m
memory: 10Mi
securityContext: {}
volumeMounts:
- mountPath: /var/run/secrets/lagoon/sshkey/
name: lagoon-sshkey
readOnly: true
- mountPath: /app/docroot/sites/default/files//php
name: nginx-php-twig
- mountPath: /app/docroot/sites/default/files/
name: nginx-php
dnsConfig:
options:
- name: timeout
value: "60"
- name: attempts
value: "10"
enableServiceLinks: false
imagePullSecrets:
- name: lagoon-internal-registry-secret
priorityClassName: lagoon-priority-production
restartPolicy: Never
securityContext:
fsGroup: 10001
runAsGroup: 0
runAsUser: 10000
tolerations:
- effect: NoSchedule
key: lagoon.sh/spot
operator: Exists
- effect: PreferNoSchedule
key: lagoon.sh/spot
operator: Exists
volumes:
- name: lagoon-sshkey
secret:
defaultMode: 420
secretName: lagoon-sshkey
- emptyDir: {}
name: nginx-php-twig
- name: nginx-php
persistentVolumeClaim:
claimName: nginx-php
schedule: 18,48 * * * *
startingDeadlineSeconds: 240
successfulJobsHistoryLimit: 0
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: cli
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: cli-persistent
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: cli
lagoon.sh/service-type: cli-persistent
lagoon.sh/template: cli-persistent-0.1.0
name: cli
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: cli
app.kubernetes.io/name: cli-persistent
strategy: {}
template:
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/configMapSha: abcdefg1234567890
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: cli
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: cli-persistent
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: cli
lagoon.sh/service-type: cli-persistent
lagoon.sh/template: cli-persistent-0.1.0
spec:
containers:
- env:
- name: LAGOON_GIT_SHA
value: "0000000000000000000000000000000000000000"
- name: CRONJOBS
value: |
3,18,33,48 * * * * drush cron
- name: SERVICE_NAME
value: cli
envFrom:
- configMapRef:
name: lagoon-env
image: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8
imagePullPolicy: Always
name: cli
readinessProbe:
exec:
command:
- /bin/sh
- -c
- if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness;
fi
failureThreshold: 3
initialDelaySeconds: 5
periodSeconds: 2
resources:
requests:
cpu: 10m
memory: 10Mi
securityContext: {}
volumeMounts:
- mountPath: /var/run/secrets/lagoon/sshkey/
name: lagoon-sshkey
readOnly: true
- mountPath: /app/docroot/sites/default/files//php
name: nginx-php-twig
- mountPath: /app/docroot/sites/default/files/
name: nginx-php
enableServiceLinks: false
imagePullSecrets:
- name: lagoon-internal-registry-secret
priorityClassName: lagoon-priority-production
securityContext:
fsGroup: 10001
runAsGroup: 0
runAsUser: 10000
volumes:
- name: lagoon-sshkey
secret:
defaultMode: 420
secretName: lagoon-sshkey
- emptyDir: {}
name: nginx-php-twig
- name: nginx-php
persistentVolumeClaim:
claimName: nginx-php
status: {}
Loading

0 comments on commit 475f206

Please sign in to comment.