Skip to content

Commit e9c4f7d

Browse files
feat: support for optional revision history setting (#471)
* feat: support for optional revision history setting * chore: update internal/templating/templates_deployment.go Co-authored-by: Brandon Williams <brandon.williams@amazee.io> * chore: reword error * chore: reword error for other admin flags --------- Co-authored-by: Brandon Williams <brandon.williams@amazee.io>
1 parent 00cae0a commit e9c4f7d

File tree

6 files changed

+168
-3
lines changed

6 files changed

+168
-3
lines changed

cmd/template_lagoonservices_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,28 @@ func TestTemplateLagoonServices(t *testing.T) {
659659
templatePath: "testoutput",
660660
want: "internal/testdata/basic/service-templates/test-basic-external-service-environment",
661661
},
662+
{
663+
name: "test-basic-deployment-revision-history",
664+
description: "tests a basic deployment with revision history set",
665+
args: testdata.GetSeedData(
666+
testdata.TestData{
667+
ProjectName: "example-project",
668+
EnvironmentName: "main",
669+
Branch: "main",
670+
LagoonYAML: "internal/testdata/basic/lagoon.yml",
671+
ImageReferences: map[string]string{
672+
"node": "harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
673+
},
674+
BuildPodVariables: []helpers.EnvironmentVariable{
675+
{
676+
Name: "ADMIN_LAGOON_FEATURE_FLAG_DEPLOYMENT_REVISION_HISTORY",
677+
Value: "5",
678+
},
679+
},
680+
}, true),
681+
templatePath: "testoutput",
682+
want: "internal/testdata/basic/service-templates/test-basic-deployment-revision-history",
683+
},
662684
}
663685
for _, tt := range tests {
664686
t.Run(tt.name, func(t *testing.T) {

internal/generator/buildvalues.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type BuildValues struct {
9292
LagoonEnvVariables map[string]string `json:"lagoonEnvVariables" description:"map of variables that will be saved into the lagoon-env secret"`
9393
LagoonPlatformEnvVariables map[string]string `json:"lagoonPlatformEnvVariables" description:"map of variables that will be saved into the lagoon-platform-env secret"`
9494
AutoMountServiceAccountToken bool `json:"autoMountServiceAccountToken" description:"flag to enable automounting the service account token"`
95+
DeploymentRevisionHistory *int32 `json:"deploymentRevisionHistory" description:"how many replicasets to retain"`
9596
}
9697

9798
type Resources struct {

internal/generator/generator.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,15 @@ func NewGenerator(
377377
}
378378

379379
// check admin features for resources
380+
revisionHistory := CheckAdminFeatureFlag("DEPLOYMENT_REVISION_HISTORY", false)
381+
if revisionHistory != "" {
382+
rhInt, err := strconv.Atoi(revisionHistory)
383+
if err != nil {
384+
return nil, fmt.Errorf("provided revision history %s is not a valid integer, contact your Lagoon administrator", revisionHistory)
385+
}
386+
rhInt32 := int32(rhInt)
387+
buildValues.DeploymentRevisionHistory = &rhInt32
388+
}
380389
buildValues.Resources.Limits.Memory = CheckAdminFeatureFlag("CONTAINER_MEMORY_LIMIT", false)
381390
buildValues.Resources.Limits.EphemeralStorage = CheckAdminFeatureFlag("EPHEMERAL_STORAGE_LIMIT", false)
382391
buildValues.Resources.Requests.EphemeralStorage = CheckAdminFeatureFlag("EPHEMERAL_STORAGE_REQUESTS", false)
@@ -386,19 +395,19 @@ func NewGenerator(
386395
if buildValues.Resources.Limits.Memory != "" {
387396
err := ValidateResourceQuantity(buildValues.Resources.Limits.Memory)
388397
if err != nil {
389-
return nil, fmt.Errorf("provided memory limit %s is not a valid resource quantity", buildValues.Resources.Limits.Memory)
398+
return nil, fmt.Errorf("provided memory limit %s is not a valid resource quantity, contact your Lagoon administrator", buildValues.Resources.Limits.Memory)
390399
}
391400
}
392401
if buildValues.Resources.Limits.EphemeralStorage != "" {
393402
err := ValidateResourceQuantity(buildValues.Resources.Limits.EphemeralStorage)
394403
if err != nil {
395-
return nil, fmt.Errorf("provided ephemeral storage limit %s is not a valid resource quantity", buildValues.Resources.Limits.EphemeralStorage)
404+
return nil, fmt.Errorf("provided ephemeral storage limit %s is not a valid resource quantity, contact your Lagoon administrator", buildValues.Resources.Limits.EphemeralStorage)
396405
}
397406
}
398407
if buildValues.Resources.Requests.EphemeralStorage != "" {
399408
err := ValidateResourceQuantity(buildValues.Resources.Requests.EphemeralStorage)
400409
if err != nil {
401-
return nil, fmt.Errorf("provided ephemeral storage requests %s is not a valid resource quantity", buildValues.Resources.Requests.EphemeralStorage)
410+
return nil, fmt.Errorf("provided ephemeral storage requests %s is not a valid resource quantity, contact your Lagoon administrator", buildValues.Resources.Requests.EphemeralStorage)
402411
}
403412
}
404413

internal/templating/templates_deployment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ func GenerateDeploymentTemplate(
187187
},
188188
}
189189
}
190+
deployment.Spec.RevisionHistoryLimit = buildValues.DeploymentRevisionHistory
190191

191192
// end deployment template
192193
deployments = append(deployments, *deployment)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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: node
11+
app.kubernetes.io/managed-by: build-deploy-tool
12+
app.kubernetes.io/name: basic
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: node
18+
lagoon.sh/service-type: basic
19+
lagoon.sh/template: basic-0.1.0
20+
name: node
21+
spec:
22+
replicas: 1
23+
revisionHistoryLimit: 5
24+
selector:
25+
matchLabels:
26+
app.kubernetes.io/instance: node
27+
app.kubernetes.io/name: basic
28+
strategy: {}
29+
template:
30+
metadata:
31+
annotations:
32+
lagoon.sh/branch: main
33+
lagoon.sh/configMapSha: abcdefg1234567890
34+
lagoon.sh/version: v2.7.x
35+
creationTimestamp: null
36+
labels:
37+
app.kubernetes.io/instance: node
38+
app.kubernetes.io/managed-by: build-deploy-tool
39+
app.kubernetes.io/name: basic
40+
lagoon.sh/buildType: branch
41+
lagoon.sh/environment: main
42+
lagoon.sh/environmentType: production
43+
lagoon.sh/project: example-project
44+
lagoon.sh/service: node
45+
lagoon.sh/service-type: basic
46+
lagoon.sh/template: basic-0.1.0
47+
spec:
48+
automountServiceAccountToken: false
49+
containers:
50+
- env:
51+
- name: LAGOON_GIT_SHA
52+
value: abcdefg123456
53+
- name: CRONJOBS
54+
- name: SERVICE_NAME
55+
value: node
56+
envFrom:
57+
- secretRef:
58+
name: lagoon-platform-env
59+
- secretRef:
60+
name: lagoon-env
61+
image: harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8
62+
imagePullPolicy: Always
63+
livenessProbe:
64+
initialDelaySeconds: 60
65+
tcpSocket:
66+
port: 1234
67+
timeoutSeconds: 10
68+
name: basic
69+
ports:
70+
- containerPort: 1234
71+
name: tcp-1234
72+
protocol: TCP
73+
- containerPort: 8191
74+
name: tcp-8191
75+
protocol: TCP
76+
- containerPort: 9001
77+
name: udp-9001
78+
protocol: UDP
79+
readinessProbe:
80+
initialDelaySeconds: 1
81+
tcpSocket:
82+
port: 1234
83+
timeoutSeconds: 1
84+
resources:
85+
requests:
86+
cpu: 10m
87+
memory: 10Mi
88+
securityContext: {}
89+
enableServiceLinks: false
90+
imagePullSecrets:
91+
- name: lagoon-internal-registry-secret
92+
priorityClassName: lagoon-priority-production
93+
status: {}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
apiVersion: v1
3+
kind: Service
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: node
11+
app.kubernetes.io/managed-by: build-deploy-tool
12+
app.kubernetes.io/name: basic
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: node
18+
lagoon.sh/service-type: basic
19+
lagoon.sh/template: basic-0.1.0
20+
name: node
21+
spec:
22+
ports:
23+
- name: tcp-1234
24+
port: 1234
25+
protocol: TCP
26+
targetPort: tcp-1234
27+
- name: tcp-8191
28+
port: 8191
29+
protocol: TCP
30+
targetPort: tcp-8191
31+
- name: udp-9001
32+
port: 9001
33+
protocol: UDP
34+
targetPort: udp-9001
35+
selector:
36+
app.kubernetes.io/instance: node
37+
app.kubernetes.io/name: basic
38+
status:
39+
loadBalancer: {}

0 commit comments

Comments
 (0)