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 Sep 3, 2024
1 parent 21333a3 commit 75a4575
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 2 deletions.
5 changes: 4 additions & 1 deletion internal/generator/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/distribution/reference"
"os"
"reflect"
"regexp"
"strconv"
"strings"

"github.com/distribution/reference"

composetypes "github.com/compose-spec/compose-go/types"
"github.com/drone/envsubst"
"github.com/uselagoon/build-deploy-tool/internal/helpers"
Expand All @@ -32,6 +33,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 @@ -63,6 +65,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 @@ -85,3 +86,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 @@ -58,6 +58,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
33 changes: 32 additions & 1 deletion 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",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1036,7 +1067,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
@@ -0,0 +1,91 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
lagoon.sh/branch: environment-name
lagoon.sh/version: v2.x.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: myservice
app.kubernetes.io/managed-by: build-deploy-tool
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-single
lagoon.sh/template: basic-single-0.1.0
name: myservice
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: myservice
app.kubernetes.io/name: basic-single
strategy:
type: Recreate
template:
metadata:
annotations:
lagoon.sh/branch: environment-name
lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273
lagoon.sh/version: v2.x.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: myservice
app.kubernetes.io/managed-by: build-deploy-tool
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-single
lagoon.sh/template: basic-single-0.1.0
spec:
containers:
- env:
- name: LAGOON_GIT_SHA
value: "0"
- name: CRONJOBS
- name: SERVICE_NAME
value: myservice
envFrom:
- configMapRef:
name: lagoon-env
image: harbor.example.com/example-project/environment-name/myservice@latest
imagePullPolicy: Always
livenessProbe:
initialDelaySeconds: 60
tcpSocket:
port: 8080
timeoutSeconds: 10
name: basic
ports:
- containerPort: 8080
name: http
protocol: TCP
readinessProbe:
initialDelaySeconds: 1
tcpSocket:
port: 8080
timeoutSeconds: 1
resources:
requests:
cpu: 10m
memory: 10Mi
securityContext: {}
volumeMounts:
- mountPath: ""
name: myservice
enableServiceLinks: false
imagePullSecrets:
- name: lagoon-internal-registry-secret
priorityClassName: lagoon-priority-production
volumes:
- name: myservice
persistentVolumeClaim:
claimName: myservice
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
k8up.io/backup: "true"
k8up.syn.tools/backup: "true"
lagoon.sh/branch: environment-name
lagoon.sh/version: v2.x.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: myservice
app.kubernetes.io/managed-by: build-deploy-tool
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-single
lagoon.sh/template: basic-single-0.1.0
name: myservice
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
apiVersion: v1
kind: Service
metadata:
annotations:
lagoon.sh/branch: environment-name
lagoon.sh/version: v2.x.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: myservice
app.kubernetes.io/managed-by: build-deploy-tool
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-single
lagoon.sh/template: basic-single-0.1.0
name: myservice
spec:
ports:
- name: http
port: 3000
protocol: TCP
targetPort: http
selector:
app.kubernetes.io/instance: myservice
app.kubernetes.io/name: basic-single
status:
loadBalancer: {}

0 comments on commit 75a4575

Please sign in to comment.