Skip to content

Commit

Permalink
feat: new basic-single service type
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Oct 3, 2024
1 parent 05887c3 commit 9d4b2d8
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 44 deletions.
2 changes: 2 additions & 0 deletions internal/generator/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var supportedAutogeneratedTypes = []string{
// "kibana", //@TODO: don't even need this anymore?
"basic",
"basic-persistent",
"basic-single",
"node",
"node-persistent",
"nginx",
Expand Down Expand Up @@ -60,6 +61,7 @@ var supportedDBTypes = []string{
// these are lagoon types that come with resources requiring backups
var typesWithBackups = []string{
"basic-persistent",
"basic-single",
"node-persistent",
"nginx-php-persistent",
"python-persistent",
Expand Down
20 changes: 20 additions & 0 deletions internal/servicetypes/basic.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package servicetypes

import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -88,3 +89,22 @@ var basicPersistent = ServiceType{
Backup: true,
},
}

// contains all the single type overrides that the basic service doesn't have
// basicSingle is like basic persistent except that the volume is not bulk, and the pod can only ever have 1 replica because of this
var basicSingle = ServiceType{
Name: "basic-single",
Ports: basic.Ports,
PrimaryContainer: ServiceContainer{
Name: basic.PrimaryContainer.Name,
Container: basic.PrimaryContainer.Container,
},
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RecreateDeploymentStrategyType,
},
Volumes: ServiceVolume{
PersistentVolumeSize: "5Gi",
PersistentVolumeType: corev1.ReadWriteOnce,
Backup: true,
},
}
1 change: 1 addition & 0 deletions internal/servicetypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type ServicePorts struct {
var ServiceTypes = map[string]ServiceType{
"basic": basic,
"basic-persistent": basicPersistent,
"basic-single": basicSingle,
"cli": cli,
"cli-persistent": cliPersistent,
"elasticsearch": elasticsearch,
Expand Down
35 changes: 33 additions & 2 deletions internal/templating/services/templates_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,37 @@ func TestGenerateDeploymentTemplate(t *testing.T) {
},
want: "test-resources/deployment/result-postgres-1.yaml",
},
{
name: "test20 - basic-single",
args: args{
buildValues: generator.BuildValues{
Project: "example-project",
Environment: "environment-name",
EnvironmentType: "production",
Namespace: "myexample-project-environment-name",
BuildType: "branch",
LagoonVersion: "v2.x.x",
Kubernetes: "generator.local",
Branch: "environment-name",
GitSHA: "0",
ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273",
ImageReferences: map[string]string{
"myservice": "harbor.example.com/example-project/environment-name/myservice@latest",
},
Services: []generator.ServiceValues{
{
Name: "myservice",
OverrideName: "myservice",
Type: "basic-single",
DBaaSEnvironment: "production",
ServicePort: 8080,
Replicas: 1,
},
},
},
},
want: "test-resources/deployment/result-basic-4.yaml",
},
{
name: "test-basic-antiaffinity",
args: args{
Expand Down Expand Up @@ -910,7 +941,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) {
},
},
},
want: "test-resources/deployment/result-basic-4.yaml",
want: "test-resources/deployment/result-basic-5.yaml",
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -1092,7 +1123,7 @@ func TestLinkedServiceCalculator(t *testing.T) {
lValues, _ := json.Marshal(got)
wValues, _ := json.Marshal(tt.want)
if !reflect.DeepEqual(string(lValues), string(wValues)) {
t.Errorf("LinkedServiceCalculator() = %v, want %v", string(lValues), string(wValues))
t.Errorf("LinkedServiceCalculator() = \n%v", diff.LineDiff(string(lValues), string(wValues)))
}
})
}
Expand Down
25 changes: 25 additions & 0 deletions internal/templating/services/templates_pvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,31 @@ func TestGeneratePVCTemplate(t *testing.T) {
},
want: "test-resources/pvc/result-basic-3.yaml",
},
{
name: "test8 - basic-single",
args: args{
buildValues: generator.BuildValues{
Project: "example-project",
Environment: "environment-name",
EnvironmentType: "production",
Namespace: "myexample-project-environment-name",
BuildType: "branch",
LagoonVersion: "v2.x.x",
Kubernetes: "generator.local",
Branch: "environment-name",
RWX2RWO: true,
Services: []generator.ServiceValues{
{
Name: "myservice",
OverrideName: "myservice",
Type: "basic-single",
DBaaSEnvironment: "development",
},
},
},
},
want: "test-resources/pvc/result-basic-4.yaml",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
24 changes: 24 additions & 0 deletions internal/templating/services/templates_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,30 @@ func TestGenerateServiceTemplate(t *testing.T) {
},
want: "test-resources/service/result-nginx-php-1.yaml",
},
{
name: "test6 - basic-single",
args: args{
buildValues: generator.BuildValues{
Project: "example-project",
Environment: "environment-name",
EnvironmentType: "production",
Namespace: "myexample-project-environment-name",
BuildType: "branch",
LagoonVersion: "v2.x.x",
Kubernetes: "generator.local",
Branch: "environment-name",
Services: []generator.ServiceValues{
{
Name: "myservice",
OverrideName: "myservice",
Type: "basic-single",
DBaaSEnvironment: "development",
},
},
},
},
want: "test-resources/service/result-basic-3.yaml",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ metadata:
labels:
app.kubernetes.io/instance: myservice
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: basic
app.kubernetes.io/name: basic-single
lagoon.sh/buildType: branch
lagoon.sh/environment: environment-name
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: myservice
lagoon.sh/service-type: basic
lagoon.sh/template: basic-0.1.0
lagoon.sh/service-type: basic-single
lagoon.sh/template: basic-single-0.1.0
name: myservice
spec:
replicas: 2
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: myservice
app.kubernetes.io/name: basic
strategy: {}
app.kubernetes.io/name: basic-single
strategy:
type: Recreate
template:
metadata:
annotations:
Expand All @@ -35,14 +36,14 @@ spec:
labels:
app.kubernetes.io/instance: myservice
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: basic
app.kubernetes.io/name: basic-single
lagoon.sh/buildType: branch
lagoon.sh/environment: environment-name
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: myservice
lagoon.sh/service-type: basic
lagoon.sh/template: basic-0.1.0
lagoon.sh/service-type: basic-single
lagoon.sh/template: basic-single-0.1.0
spec:
containers:
- env:
Expand All @@ -59,54 +60,32 @@ spec:
livenessProbe:
initialDelaySeconds: 60
tcpSocket:
port: 8191
port: 8080
timeoutSeconds: 10
name: basic
ports:
- containerPort: 8191
name: tcp-8191
protocol: TCP
- containerPort: 8211
name: tcp-8211
- containerPort: 8080
name: http
protocol: TCP
readinessProbe:
initialDelaySeconds: 1
tcpSocket:
port: 8191
port: 8080
timeoutSeconds: 1
resources:
limits:
ephemeral-storage: 160Gi
memory: 16Gi
requests:
cpu: 10m
ephemeral-storage: 1Gi
memory: 10Mi
securityContext: {}
volumeMounts:
- mountPath: ""
name: myservice
enableServiceLinks: false
imagePullSecrets:
- name: lagoon-internal-registry-secret
priorityClassName: lagoon-priority-production
topologySpreadConstraints:
- labelSelector:
matchExpressions:
- key: app.kubernetes.io/name
operator: In
values:
- basic
- key: app.kubernetes.io/instance
operator: In
values:
- myservice
- key: lagoon.sh/project
operator: In
values:
- example-project
- key: lagoon.sh/environment
operator: In
values:
- environment-name
maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
volumes:
- name: myservice
persistentVolumeClaim:
claimName: myservice
status: {}
Loading

0 comments on commit 9d4b2d8

Please sign in to comment.