Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cmd/template_lagoonservices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,28 @@ func TestTemplateLagoonServices(t *testing.T) {
templatePath: "testoutput",
want: "internal/testdata/basic/service-templates/test-basic-external-service-environment",
},
{
name: "test-basic-deployment-revision-history",
description: "tests a basic deployment with revision history set",
args: testdata.GetSeedData(
testdata.TestData{
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "internal/testdata/basic/lagoon.yml",
ImageReferences: map[string]string{
"node": "harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
},
BuildPodVariables: []helpers.EnvironmentVariable{
{
Name: "ADMIN_LAGOON_FEATURE_FLAG_DEPLOYMENT_REVISION_HISTORY",
Value: "5",
},
},
}, true),
templatePath: "testoutput",
want: "internal/testdata/basic/service-templates/test-basic-deployment-revision-history",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions internal/generator/buildvalues.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type BuildValues struct {
LagoonEnvVariables map[string]string `json:"lagoonEnvVariables" description:"map of variables that will be saved into the lagoon-env secret"`
LagoonPlatformEnvVariables map[string]string `json:"lagoonPlatformEnvVariables" description:"map of variables that will be saved into the lagoon-platform-env secret"`
AutoMountServiceAccountToken bool `json:"autoMountServiceAccountToken" description:"flag to enable automounting the service account token"`
DeploymentRevisionHistory *int32 `json:"deploymentRevisionHistory" description:"how many replicasets to retain"`
}

type Resources struct {
Expand Down
15 changes: 12 additions & 3 deletions internal/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,15 @@ func NewGenerator(
}

// check admin features for resources
revisionHistory := CheckAdminFeatureFlag("DEPLOYMENT_REVISION_HISTORY", false)
if revisionHistory != "" {
rhInt, err := strconv.Atoi(revisionHistory)
if err != nil {
return nil, fmt.Errorf("provided revision history %s is not a valid integer, contact your Lagoon administrator", revisionHistory)
}
rhInt32 := int32(rhInt)
buildValues.DeploymentRevisionHistory = &rhInt32
}
buildValues.Resources.Limits.Memory = CheckAdminFeatureFlag("CONTAINER_MEMORY_LIMIT", false)
buildValues.Resources.Limits.EphemeralStorage = CheckAdminFeatureFlag("EPHEMERAL_STORAGE_LIMIT", false)
buildValues.Resources.Requests.EphemeralStorage = CheckAdminFeatureFlag("EPHEMERAL_STORAGE_REQUESTS", false)
Expand All @@ -386,19 +395,19 @@ func NewGenerator(
if buildValues.Resources.Limits.Memory != "" {
err := ValidateResourceQuantity(buildValues.Resources.Limits.Memory)
if err != nil {
return nil, fmt.Errorf("provided memory limit %s is not a valid resource quantity", buildValues.Resources.Limits.Memory)
return nil, fmt.Errorf("provided memory limit %s is not a valid resource quantity, contact your Lagoon administrator", buildValues.Resources.Limits.Memory)
}
}
if buildValues.Resources.Limits.EphemeralStorage != "" {
err := ValidateResourceQuantity(buildValues.Resources.Limits.EphemeralStorage)
if err != nil {
return nil, fmt.Errorf("provided ephemeral storage limit %s is not a valid resource quantity", buildValues.Resources.Limits.EphemeralStorage)
return nil, fmt.Errorf("provided ephemeral storage limit %s is not a valid resource quantity, contact your Lagoon administrator", buildValues.Resources.Limits.EphemeralStorage)
}
}
if buildValues.Resources.Requests.EphemeralStorage != "" {
err := ValidateResourceQuantity(buildValues.Resources.Requests.EphemeralStorage)
if err != nil {
return nil, fmt.Errorf("provided ephemeral storage requests %s is not a valid resource quantity", buildValues.Resources.Requests.EphemeralStorage)
return nil, fmt.Errorf("provided ephemeral storage requests %s is not a valid resource quantity, contact your Lagoon administrator", buildValues.Resources.Requests.EphemeralStorage)
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/templating/templates_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func GenerateDeploymentTemplate(
},
}
}
deployment.Spec.RevisionHistoryLimit = buildValues.DeploymentRevisionHistory

// end deployment template
deployments = append(deployments, *deployment)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
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
revisionHistoryLimit: 5
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:
automountServiceAccountToken: false
containers:
- env:
- name: LAGOON_GIT_SHA
value: abcdefg123456
- name: CRONJOBS
- name: SERVICE_NAME
value: node
envFrom:
- secretRef:
name: lagoon-platform-env
- secretRef:
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: {}