Skip to content

Commit

Permalink
feat: override to be able to force cronjob into service pod (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon authored Aug 23, 2024
1 parent 141e919 commit 0401a0a
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 1 deletion.
15 changes: 15 additions & 0 deletions cmd/template_lagoonservices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,21 @@ func TestTemplateLagoonServices(t *testing.T) {
templatePath: "testoutput",
want: "internal/testdata/complex/service-templates/service4",
},
{
name: "test10 basic deployment native cronjobs disabled",
args: testdata.GetSeedData(
testdata.TestData{
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "internal/testdata/basic/lagoon-cronjob-native-disable.yml",
ImageReferences: map[string]string{
"node": "harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
},
}, true),
templatePath: "testoutput",
want: "internal/testdata/basic/service-templates/service8",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion internal/generator/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ func composeToServiceValues(
if err != nil {
return ServiceValues{}, fmt.Errorf("unable to convert crontab for cronjob %s: %v", cronjob.Name, err)
}
if inpod {
// if the cronjob is inpod, or the cronjob has an inpod flag override
if inpod || (cronjob.InPod != nil && *cronjob.InPod) {
inpodcronjobs = append(inpodcronjobs, cronjob)
} else {
// make the cronjob name kubernetes compliant
Expand Down
1 change: 1 addition & 0 deletions internal/lagoon/lagoon.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Cronjob struct {
Service string `json:"service"`
Schedule string `json:"schedule"`
Command string `json:"command"`
InPod *bool `json:"inPod"`
}

type Override struct {
Expand Down
32 changes: 32 additions & 0 deletions internal/lagoon/lagoon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,38 @@ func TestUnmarshalLagoonYAML(t *testing.T) {
},
},
},
{
name: "test-cronjobs-inpod-only",
args: args{
file: "test-resources/lagoon-yaml/test10/lagoon.yml",
l: &YAML{},
},
want: &YAML{
DockerComposeYAML: "docker-compose.yml",
Environments: Environments{
"main": Environment{
Routes: []map[string][]Route{
{
"nginx": {
{
Name: "a.example.com",
},
},
},
},
Cronjobs: []Cronjob{
{
Name: "drush cron",
Command: "drush cron",
Service: "cli",
Schedule: "*/30 * * * *",
InPod: helpers.BoolPtr(true),
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
16 changes: 16 additions & 0 deletions internal/lagoon/test-resources/lagoon-yaml/test10/lagoon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
docker-compose-yaml: docker-compose.yml

project: content-example-com

environments:
main:
cronjobs:
- name: drush cron
schedule: "*/30 * * * *"
command: 'drush cron'
service: cli
inPod: true
routes:
- nginx:
- a.example.com
21 changes: 21 additions & 0 deletions internal/testdata/basic/lagoon-cronjob-native-disable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
docker-compose-yaml: internal/testdata/basic/docker-compose.yml

environment_variables:
git_sha: "true"

environments:
main:
routes:
- node:
- example.com
cronjobs:
- name: drush cron
schedule: "*/15 * * * *"
command: drush cron
service: node
inPod: true # not required as the interval is suited to in pod already
- name: drush cron2
schedule: "*/30 * * * *"
command: drush cron
service: node
inPod: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: node
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: basic
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: basic
lagoon.sh/template: basic-0.1.0
name: node
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: node
app.kubernetes.io/name: basic
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: node
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: basic
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: basic
lagoon.sh/template: basic-0.1.0
spec:
containers:
- env:
- name: LAGOON_GIT_SHA
value: abcdefg123456
- name: CRONJOBS
value: |
3,18,33,48 * * * * drush cron
18,48 * * * * drush cron
- name: SERVICE_NAME
value: node
envFrom:
- configMapRef:
name: lagoon-env
image: harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8
imagePullPolicy: Always
livenessProbe:
initialDelaySeconds: 60
tcpSocket:
port: 1234
timeoutSeconds: 10
name: basic
ports:
- containerPort: 1234
name: tcp-1234
protocol: TCP
- containerPort: 8191
name: tcp-8191
protocol: TCP
- containerPort: 9001
name: udp-9001
protocol: UDP
readinessProbe:
initialDelaySeconds: 1
tcpSocket:
port: 1234
timeoutSeconds: 1
resources:
requests:
cpu: 10m
memory: 10Mi
securityContext: {}
enableServiceLinks: false
imagePullSecrets:
- name: lagoon-internal-registry-secret
priorityClassName: lagoon-priority-production
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
apiVersion: v1
kind: Service
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: node
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: basic
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: basic
lagoon.sh/template: basic-0.1.0
name: node
spec:
ports:
- name: tcp-1234
port: 1234
protocol: TCP
targetPort: tcp-1234
- name: tcp-8191
port: 8191
protocol: TCP
targetPort: tcp-8191
- name: udp-9001
port: 9001
protocol: UDP
targetPort: udp-9001
selector:
app.kubernetes.io/instance: node
app.kubernetes.io/name: basic
status:
loadBalancer: {}

0 comments on commit 0401a0a

Please sign in to comment.