From d8a335863243e4e9b156f4f5caff1fee409cd1a9 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 8 Dec 2022 12:17:26 +1100 Subject: [PATCH 01/92] feat: initial run at service-templates --- internal/generator/buildvalues.go | 51 +++- internal/generator/services.go | 38 +++ internal/helpers/helpers.go | 20 ++ internal/servicetypes/README.md | 3 + internal/servicetypes/basic.go | 81 ++++++ internal/servicetypes/cli.go | 10 + internal/servicetypes/elasticsearch.go | 29 +++ internal/servicetypes/mariadb.go | 29 +++ internal/servicetypes/mongodb.go | 29 +++ internal/servicetypes/node.go | 34 +++ internal/servicetypes/opensearch.go | 33 +++ internal/servicetypes/postgres.go | 33 +++ internal/servicetypes/python.go | 34 +++ internal/servicetypes/redis.go | 34 +++ internal/servicetypes/solr.go | 29 +++ internal/servicetypes/types.go | 55 ++++ .../templating/services/templates_cronjob.go | 1 + .../services/templates_deployment.go | 241 ++++++++++++++++++ .../services/templates_deployment_test.go | 200 +++++++++++++++ internal/templating/services/templates_pvc.go | 142 +++++++++++ .../templating/services/templates_pvc_test.go | 186 ++++++++++++++ .../templating/services/templates_service.go | 131 ++++++++++ .../services/templates_service_test.go | 176 +++++++++++++ .../deployment/result-basic-1.yaml | 77 ++++++ .../deployment/result-cli-1.yaml | 0 .../deployment/result-elasticsearch-1.yaml | 0 .../deployment/result-opensearch-1.yaml | 0 .../test-resources/pvc/result-basic-1.yaml | 87 +++++++ .../test-resources/pvc/result-cli-1.yaml | 0 .../pvc/result-elasticsearch-1.yaml | 58 +++++ .../pvc/result-opensearch-1.yaml | 58 +++++ .../service/result-basic-1.yaml | 120 +++++++++ .../test-resources/service/result-cli-1.yaml | 0 .../service/result-elasticsearch-1.yaml | 60 +++++ .../service/result-opensearch-1.yaml | 60 +++++ 35 files changed, 2130 insertions(+), 9 deletions(-) create mode 100644 internal/servicetypes/README.md create mode 100644 internal/servicetypes/basic.go create mode 100644 internal/servicetypes/cli.go create mode 100644 internal/servicetypes/elasticsearch.go create mode 100644 internal/servicetypes/mariadb.go create mode 100644 internal/servicetypes/mongodb.go create mode 100644 internal/servicetypes/node.go create mode 100644 internal/servicetypes/opensearch.go create mode 100644 internal/servicetypes/postgres.go create mode 100644 internal/servicetypes/python.go create mode 100644 internal/servicetypes/redis.go create mode 100644 internal/servicetypes/solr.go create mode 100644 internal/servicetypes/types.go create mode 100644 internal/templating/services/templates_cronjob.go create mode 100644 internal/templating/services/templates_deployment.go create mode 100644 internal/templating/services/templates_deployment_test.go create mode 100644 internal/templating/services/templates_pvc.go create mode 100644 internal/templating/services/templates_pvc_test.go create mode 100644 internal/templating/services/templates_service.go create mode 100644 internal/templating/services/templates_service_test.go create mode 100644 internal/templating/services/test-resources/deployment/result-basic-1.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-cli-1.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-opensearch-1.yaml create mode 100644 internal/templating/services/test-resources/pvc/result-basic-1.yaml create mode 100644 internal/templating/services/test-resources/pvc/result-cli-1.yaml create mode 100644 internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml create mode 100644 internal/templating/services/test-resources/pvc/result-opensearch-1.yaml create mode 100644 internal/templating/services/test-resources/service/result-basic-1.yaml create mode 100644 internal/templating/services/test-resources/service/result-cli-1.yaml create mode 100644 internal/templating/services/test-resources/service/result-elasticsearch-1.yaml create mode 100644 internal/templating/services/test-resources/service/result-opensearch-1.yaml diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index 6efd4b97..d0096d33 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -3,6 +3,7 @@ package generator import ( "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/lagoon" + corev1 "k8s.io/api/core/v1" ) // BuildValues is the values file data generated by the lagoon build @@ -24,15 +25,13 @@ type BuildValues struct { RunAsGroup int `json:"runAsGroup"` RunAsUser int `json:"runAsUser"` } `json:"podSecurityContext"` - ImagePullSecrets []struct { - Name string `json:"name"` - } `json:"imagePullSecrets"` - Branch string `json:"branch"` - PRNumber string `json:"prNumber"` - PRTitle string `json:"prTitle"` - PRHeadBranch string `json:"prHeadBranch"` - PRBaseBranch string `json:"prBaseBranch"` - Fastly struct { + ImagePullSecrets []ImagePullSecrets `json:"imagePullSecrets"` + Branch string `json:"branch"` + PRNumber string `json:"prNumber"` + PRTitle string `json:"prTitle"` + PRHeadBranch string `json:"prHeadBranch"` + PRBaseBranch string `json:"prBaseBranch"` + Fastly struct { ServiceID string `json:"serviceId"` APISecretName string `json:"apiSecretName"` Watch bool `json:"watch"` @@ -55,6 +54,8 @@ type BuildValues struct { IngressClass string `json:"ingressClass"` TaskScaleMaxIterations int `json:"taskScaleMaxIterations"` TaskScaleWaitTime int `json:"taskScaleWaitTime"` + DynamicSecretMounts []DynamicSecretMounts `json:"dynamicSecretMounts"` + DynamicSecretVolumes []DynamicSecretVolumes `json:"dynamicSecretVolumes"` DBaaSClient *dbaasclient.Client `json:"-"` } @@ -64,6 +65,26 @@ type MonitoringConfig struct { StatusPageID string `json:"statusPageID"` } +type ImagePullSecrets struct { + Name string `json:"name"` +} + +type DynamicSecretMounts struct { + Name string `json:"name"` + MountPath string `json:"mountPath"` + ReadOnly bool `json:"readOnly"` +} + +type DynamicSecretVolumes struct { + Name string `json:"name"` + Secret DynamicSecret `json:"secret"` +} + +type DynamicSecret struct { + SecretName string `json:"secretName"` + Optional bool `json:"optional"` +} + // ServiceValues is the values for a specific service used by a lagoon build type ServiceValues struct { Name string `json:"name"` // this is the actual compose service name @@ -78,6 +99,18 @@ type ServiceValues struct { InPodCronjobs string `json:"inPodCronjobs"` ImageName string `json:"imageName"` DeploymentServiceType string `json:"deploymentServiecType"` + ServicePort int32 `json:"servicePort,omitempty"` + PersistentVolumePath string `json:"persistentVolumePath,omitempty"` + PersistentVolumeName string `json:"persistentVolumeName,omitempty"` + PersistentVolumeSize string `json:"persistentVolumeSize,omitempty"` + UseSpotInstances bool `json:"useSpot"` + NodeSelectors *map[string]string `json:"nodeSelectors"` + Tolerations *[]corev1.Toleration `json:"tolerations"` + Affinity *corev1.Affinity `json:"affinity"` + CronjobUseSpotInstances bool `json:"cronjobUseSpot"` + CronjobNodeSelectors *map[string]string `json:"cronjobNodeSelectors"` + CronjobTolerations *[]corev1.Toleration `json:"cronjobTolerations"` + CronjobAffinity *corev1.Affinity `json:"cronjobAffinity"` } // CronjobValues is the values for cronjobs diff --git a/internal/generator/services.go b/internal/generator/services.go index e7f57d19..86d03e6a 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -9,6 +9,7 @@ import ( composetypes "github.com/compose-spec/compose-go/types" "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" + "github.com/uselagoon/build-deploy-tool/internal/servicetypes" ) // this is a map that maps old service types to their new service types @@ -166,6 +167,28 @@ func composeToServiceValues( lagoonOverrideName = composeService } + // check if the service has any persistent labels, this is the path that the volume will be mounted to + servicePersistentPath := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.persistent") + if servicePersistentPath == "" { + // if there is no persistent path, check if the service type has a default path + if val, ok := servicetypes.ServiceTypes[lagoonType]; ok { + servicePersistentPath = val.Volumes.PersistentVolumePath + } + } + servicePersistentName := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.persistent.name") + if servicePersistentName == "" && servicePersistentPath != "" { + // if there is a persistent path defined, then set the persistent name to be the compose service if no persistent name is provided + // persistent name is used by joined services like nginx/php or cli or worker pods to mount another service volume + servicePersistentName = composeService + } + servicePersistentSize := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.persistent.size") + if servicePersistentSize == "" { + // if there is no persistent size, check if the service type has a default size allocated + if val, ok := servicetypes.ServiceTypes[lagoonType]; ok { + servicePersistentPath = val.Volumes.PersistentVolumeSize + } + } + // if there are overrides defined in the lagoon API `LAGOON_SERVICE_TYPES` // handle those here if buildValues.ServiceTypeOverrides != nil { @@ -259,6 +282,21 @@ func composeToServiceValues( AutogeneratedRoutesEnabled: autogenEnabled, AutogeneratedRoutesTLSAcme: autogenTLSAcmeEnabled, DBaaSEnvironment: dbaasEnvironment, + PersistentVolumePath: servicePersistentPath, + PersistentVolumeName: servicePersistentName, + PersistentVolumeSize: servicePersistentSize, + } + // check if the service has a service port override (this only applies to basic(-persistent)) + servicePortOverride := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.service.port") + if servicePortOverride != "" { + sPort, err := strconv.Atoi(servicePortOverride) + if err != nil { + return ServiceValues{}, fmt.Errorf( + "The provided service port %s for service %s is not a valid integer: %v", + servicePortOverride, composeService, err, + ) + } + cService.ServicePort = int32(sPort) } return cService, nil } diff --git a/internal/helpers/helpers.go b/internal/helpers/helpers.go index 001dd977..56b63854 100644 --- a/internal/helpers/helpers.go +++ b/internal/helpers/helpers.go @@ -1,9 +1,11 @@ package helpers import ( + "bytes" "crypto/md5" "crypto/sha256" "encoding/base32" + "encoding/gob" "encoding/hex" "fmt" "os" @@ -28,6 +30,16 @@ func IntPtr(i int) *int { return &i } +// Int32PTr +func Int32Ptr(i int32) *int32 { + return &i +} + +// Int64PTr +func Int64Ptr(i int64) *int64 { + return &i +} + // GetMD5HashWithNewLine . // in Lagoon this bash is used to generated the hash, but the `echo "${ROUTE_DOMAIN}"` adds a new line at the end, so the generated // sum has this in it, we need to replicate this here @@ -204,3 +216,11 @@ func CheckLabelLength(labels map[string]string) error { } return nil } + +func DeepCopy(src, dist interface{}) (err error) { + buf := bytes.Buffer{} + if err = gob.NewEncoder(&buf).Encode(src); err != nil { + return + } + return gob.NewDecoder(&buf).Decode(dist) +} diff --git a/internal/servicetypes/README.md b/internal/servicetypes/README.md new file mode 100644 index 00000000..2d09d6e9 --- /dev/null +++ b/internal/servicetypes/README.md @@ -0,0 +1,3 @@ +# Service Types + +Defines defaults for Lagoon service types \ No newline at end of file diff --git a/internal/servicetypes/basic.go b/internal/servicetypes/basic.go new file mode 100644 index 00000000..353ce670 --- /dev/null +++ b/internal/servicetypes/basic.go @@ -0,0 +1,81 @@ +package servicetypes + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var basic = ServiceType{ + Name: "basic", + Ports: ServicePorts{ + CanChangePort: true, + Ports: []corev1.ServicePort{ + { + Port: 3000, + TargetPort: intstr.IntOrString{ + Type: intstr.String, + StrVal: "http", + }, + Protocol: corev1.ProtocolTCP, + Name: "http", + }, + }, + }, + PrimaryContainer: ServiceContainer{ + + Name: "basic", + ImagePullPolicy: corev1.PullAlways, + Container: corev1.Container{ + Ports: []corev1.ContainerPort{ + { + Name: "http", + ContainerPort: 3000, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 3000, + }, + }, + }, + InitialDelaySeconds: 1, + TimeoutSeconds: 1, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 3000, + }, + }, + }, + InitialDelaySeconds: 60, + TimeoutSeconds: 10, + }, + EnvFrom: []corev1.EnvFromSource{ + { + ConfigMapRef: &corev1.ConfigMapEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: "lagoon-env", + }, + }, + }, + }, + }, + }, +} + +var basicPersistent = ServiceType{ + Name: "basic-persistent", + Ports: basic.Ports, + Volumes: ServiceVolume{ + PersistentVolumeSize: "5Gi", + PersistentVolumeType: corev1.ReadWriteMany, + Backup: true, + }, +} diff --git a/internal/servicetypes/cli.go b/internal/servicetypes/cli.go new file mode 100644 index 00000000..4545381c --- /dev/null +++ b/internal/servicetypes/cli.go @@ -0,0 +1,10 @@ +package servicetypes + +var cli = ServiceType{ + Name: "cli", +} + +var cliPersistent = ServiceType{ + Name: "cli-persistent", + Volumes: ServiceVolume{}, +} diff --git a/internal/servicetypes/elasticsearch.go b/internal/servicetypes/elasticsearch.go new file mode 100644 index 00000000..6dd9222d --- /dev/null +++ b/internal/servicetypes/elasticsearch.go @@ -0,0 +1,29 @@ +package servicetypes + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var elasticsearch = ServiceType{ + Name: "elasticsearch", + Ports: ServicePorts{ + CanChangePort: true, + Ports: []corev1.ServicePort{ + { + Port: 9200, + TargetPort: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 9200, + }, + Protocol: corev1.ProtocolTCP, + Name: "9200-tcp", + }, + }, + }, + Volumes: ServiceVolume{ + PersistentVolumeSize: "5Gi", + PersistentVolumeType: corev1.ReadWriteOnce, + PersistentVolumePath: "/usr/share/elasticsearch/data", + }, +} diff --git a/internal/servicetypes/mariadb.go b/internal/servicetypes/mariadb.go new file mode 100644 index 00000000..648b25f2 --- /dev/null +++ b/internal/servicetypes/mariadb.go @@ -0,0 +1,29 @@ +package servicetypes + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var mariadbSingle = ServiceType{ + Name: "mariadb-single", + Ports: ServicePorts{ + CanChangePort: true, + Ports: []corev1.ServicePort{ + { + Port: 3306, + TargetPort: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 3306, + }, + Protocol: corev1.ProtocolTCP, + Name: "3306-tcp", + }, + }, + }, + Volumes: ServiceVolume{ + PersistentVolumeSize: "5Gi", + PersistentVolumeType: corev1.ReadWriteOnce, + PersistentVolumePath: "/var/lib/mysql", + }, +} diff --git a/internal/servicetypes/mongodb.go b/internal/servicetypes/mongodb.go new file mode 100644 index 00000000..6d450c88 --- /dev/null +++ b/internal/servicetypes/mongodb.go @@ -0,0 +1,29 @@ +package servicetypes + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var mongodbSingle = ServiceType{ + Name: "mongodb-single", + Ports: ServicePorts{ + CanChangePort: true, + Ports: []corev1.ServicePort{ + { + Port: 27017, + TargetPort: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 27017, + }, + Protocol: corev1.ProtocolTCP, + Name: "27017-tcp", + }, + }, + }, + Volumes: ServiceVolume{ + PersistentVolumeSize: "5Gi", + PersistentVolumeType: corev1.ReadWriteOnce, + PersistentVolumePath: "/data/db", + }, +} diff --git a/internal/servicetypes/node.go b/internal/servicetypes/node.go new file mode 100644 index 00000000..14ed1768 --- /dev/null +++ b/internal/servicetypes/node.go @@ -0,0 +1,34 @@ +package servicetypes + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var node = ServiceType{ + Name: "node", + Ports: ServicePorts{ + CanChangePort: true, + Ports: []corev1.ServicePort{ + { + Port: 3000, + TargetPort: intstr.IntOrString{ + Type: intstr.String, + StrVal: "http", + }, + Protocol: corev1.ProtocolTCP, + Name: "http", + }, + }, + }, +} + +var nodePersistent = ServiceType{ + Name: "node-persistent", + Ports: node.Ports, + Volumes: ServiceVolume{ + PersistentVolumeSize: "5Gi", + PersistentVolumeType: corev1.ReadWriteMany, + Backup: true, + }, +} diff --git a/internal/servicetypes/opensearch.go b/internal/servicetypes/opensearch.go new file mode 100644 index 00000000..f44d2694 --- /dev/null +++ b/internal/servicetypes/opensearch.go @@ -0,0 +1,33 @@ +package servicetypes + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var opensearch = ServiceType{ + Name: "opensearch", + Ports: ServicePorts{ + CanChangePort: true, + Ports: []corev1.ServicePort{ + { + Port: 9200, + TargetPort: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 9200, + }, + Protocol: corev1.ProtocolTCP, + Name: "9200-tcp", + }, + }, + }, + PodSecurityContext: ServicePodSecurityContext{ + HasDefault: true, + FSGroup: 0, + }, + Volumes: ServiceVolume{ + PersistentVolumeSize: "5Gi", + PersistentVolumeType: corev1.ReadWriteOnce, + PersistentVolumePath: "/usr/share/opensearch/data", + }, +} diff --git a/internal/servicetypes/postgres.go b/internal/servicetypes/postgres.go new file mode 100644 index 00000000..e64e396a --- /dev/null +++ b/internal/servicetypes/postgres.go @@ -0,0 +1,33 @@ +package servicetypes + +import ( + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var postgresSingle = ServiceType{ + Name: "postgres-single", + Ports: ServicePorts{ + CanChangePort: true, + Ports: []corev1.ServicePort{ + { + Port: 5432, + TargetPort: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 5432, + }, + Protocol: corev1.ProtocolTCP, + Name: "5432-tcp", + }, + }, + }, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RecreateDeploymentStrategyType, + }, + Volumes: ServiceVolume{ + PersistentVolumeSize: "5Gi", + PersistentVolumeType: corev1.ReadWriteOnce, + PersistentVolumePath: "/var/lib/postgresql/data", + }, +} diff --git a/internal/servicetypes/python.go b/internal/servicetypes/python.go new file mode 100644 index 00000000..7020b13a --- /dev/null +++ b/internal/servicetypes/python.go @@ -0,0 +1,34 @@ +package servicetypes + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var python = ServiceType{ + Name: "python", + Ports: ServicePorts{ + CanChangePort: true, + Ports: []corev1.ServicePort{ + { + Port: 8800, + TargetPort: intstr.IntOrString{ + Type: intstr.String, + StrVal: "http", + }, + Protocol: corev1.ProtocolTCP, + Name: "http", + }, + }, + }, +} + +var pythonPersistent = ServiceType{ + Name: "python-persistent", + Ports: python.Ports, + Volumes: ServiceVolume{ + PersistentVolumeSize: "5Gi", + PersistentVolumeType: corev1.ReadWriteMany, + Backup: true, + }, +} diff --git a/internal/servicetypes/redis.go b/internal/servicetypes/redis.go new file mode 100644 index 00000000..c65103c6 --- /dev/null +++ b/internal/servicetypes/redis.go @@ -0,0 +1,34 @@ +package servicetypes + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var redis = ServiceType{ + Name: "redis", + Ports: ServicePorts{ + CanChangePort: true, + Ports: []corev1.ServicePort{ + { + Port: 6379, + TargetPort: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 6379, + }, + Protocol: corev1.ProtocolTCP, + Name: "6379-tcp", + }, + }, + }, +} + +var redisPersistent = ServiceType{ + Name: "redis-persistent", + Ports: redis.Ports, + Volumes: ServiceVolume{ + PersistentVolumeSize: "5Gi", + PersistentVolumeType: corev1.ReadWriteOnce, + PersistentVolumePath: "/data", + }, +} diff --git a/internal/servicetypes/solr.go b/internal/servicetypes/solr.go new file mode 100644 index 00000000..8d595e58 --- /dev/null +++ b/internal/servicetypes/solr.go @@ -0,0 +1,29 @@ +package servicetypes + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var solr = ServiceType{ + Name: "solr-php-persistent", // this has to be like this because it is used in selectors, and is unchangeable now on existing deployed solr + Ports: ServicePorts{ + CanChangePort: true, + Ports: []corev1.ServicePort{ + { + Port: 8983, + TargetPort: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 8983, + }, + Protocol: corev1.ProtocolTCP, + Name: "tcp-8983", + }, + }, + }, + Volumes: ServiceVolume{ + PersistentVolumeSize: "5Gi", + PersistentVolumeType: corev1.ReadWriteOnce, + PersistentVolumePath: "/var/solr", + }, +} diff --git a/internal/servicetypes/types.go b/internal/servicetypes/types.go new file mode 100644 index 00000000..dc1f9a31 --- /dev/null +++ b/internal/servicetypes/types.go @@ -0,0 +1,55 @@ +package servicetypes + +import ( + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" +) + +type ServiceType struct { + Name string + Ports ServicePorts + Volumes ServiceVolume + Strategy appsv1.DeploymentStrategy + PrimaryContainer ServiceContainer + PodSecurityContext ServicePodSecurityContext +} + +type ServicePodSecurityContext struct { + HasDefault bool + FSGroup int64 +} + +type ServiceContainer struct { + Name string + ImagePullPolicy corev1.PullPolicy + Container corev1.Container +} + +type ServiceVolume struct { + PersistentVolumeSize string + PersistentVolumePath string + PersistentVolumeType corev1.PersistentVolumeAccessMode + Backup bool +} + +type ServicePorts struct { + CanChangePort bool + Ports []corev1.ServicePort +} + +// this is a map that maps the lagoon service-type that can be provided in the `lagoon.type` label to the default values for that service +var ServiceTypes = map[string]ServiceType{ + "basic": basic, + "basic-persistent": basicPersistent, + "cli": cli, + "cli-persistent": cliPersistent, + "elasticsearch": elasticsearch, + "opensearch": opensearch, + "mariadb-single": mariadbSingle, + "mongodb-single": mongodbSingle, + "postgres-single": postgresSingle, + "node": node, + "node-persistent": nodePersistent, + "python": python, + "python-persistent": pythonPersistent, +} diff --git a/internal/templating/services/templates_cronjob.go b/internal/templating/services/templates_cronjob.go new file mode 100644 index 00000000..5e568ea8 --- /dev/null +++ b/internal/templating/services/templates_cronjob.go @@ -0,0 +1 @@ +package services diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go new file mode 100644 index 00000000..99fe1cb4 --- /dev/null +++ b/internal/templating/services/templates_deployment.go @@ -0,0 +1,241 @@ +package services + +import ( + "fmt" + + "github.com/uselagoon/build-deploy-tool/internal/generator" + "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/servicetypes" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + apivalidation "k8s.io/apimachinery/pkg/api/validation" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" + "sigs.k8s.io/yaml" +) + +// GenerateDeploymentTemplate generates the lagoon template to apply. +func GenerateDeploymentTemplate( + buildValues generator.BuildValues, +) ([]byte, error) { + separator := []byte("---\n") + var result []byte + + // add the default labels + labels := map[string]string{ + "app.kubernetes.io/managed-by": "build-deploy-tool", + "lagoon.sh/project": buildValues.Project, + "lagoon.sh/environment": buildValues.Environment, + "lagoon.sh/environmentType": buildValues.EnvironmentType, + "lagoon.sh/buildType": buildValues.BuildType, + } + + // add the default annotations + annotations := map[string]string{ + "lagoon.sh/version": buildValues.LagoonVersion, + } + + // add any additional labels + additionalLabels := map[string]string{} + additionalAnnotations := map[string]string{} + if buildValues.BuildType == "branch" { + additionalAnnotations["lagoon.sh/branch"] = buildValues.Branch + } else if buildValues.BuildType == "pullrequest" { + additionalAnnotations["lagoon.sh/prNumber"] = buildValues.PRNumber + additionalAnnotations["lagoon.sh/prHeadBranch"] = buildValues.PRHeadBranch + additionalAnnotations["lagoon.sh/prBaseBranch"] = buildValues.PRBaseBranch + + } + + // for all the services that the build values generated + // iterate over them and generate any kubernetes deployments + for _, serviceValues := range buildValues.Services { + if val, ok := servicetypes.ServiceTypes[serviceValues.Type]; ok { + // if val.Volumes.PersistentVolumeSize != "" { + // if serviceValues.PersistentVolumePath == "" { + // return nil, fmt.Errorf("no persistent volume size defined for this service") + // } + // } + serviceTypeValues := &servicetypes.ServiceType{} + helpers.DeepCopy(val, serviceTypeValues) + + var deploymentBytes []byte + additionalLabels["app.kubernetes.io/name"] = serviceTypeValues.Name + additionalLabels["app.kubernetes.io/instance"] = serviceValues.Name + additionalLabels["lagoon.sh/template"] = fmt.Sprintf("%s-%s", serviceTypeValues.Name, "0.1.0") + additionalLabels["lagoon.sh/service"] = serviceValues.Name + additionalLabels["lagoon.sh/service-type"] = serviceTypeValues.Name + + if serviceValues.UseSpotInstances { + additionalLabels["lagoon.sh/spot"] = "true" + } + + deployment := &appsv1.Deployment{ + TypeMeta: metav1.TypeMeta{ + Kind: "Deployment", + APIVersion: fmt.Sprintf("%s/%s", appsv1.SchemeGroupVersion.Group, appsv1.SchemeGroupVersion.Version), + }, + ObjectMeta: metav1.ObjectMeta{ + Name: serviceValues.Name, + }, + } + deployment.ObjectMeta.Labels = labels + deployment.ObjectMeta.Annotations = annotations + for key, value := range additionalLabels { + deployment.ObjectMeta.Labels[key] = value + } + // add any additional annotations + for key, value := range additionalAnnotations { + deployment.ObjectMeta.Annotations[key] = value + } + // validate any annotations + if err := apivalidation.ValidateAnnotations(deployment.ObjectMeta.Annotations, nil); err != nil { + if len(err) != 0 { + return nil, fmt.Errorf("the annotations for %s are not valid: %v", serviceValues.Name, err) + } + } + // validate any labels + if err := metavalidation.ValidateLabels(deployment.ObjectMeta.Labels, nil); err != nil { + if len(err) != 0 { + return nil, fmt.Errorf("the labels for %s are not valid: %v", serviceValues.Name, err) + } + } + // check length of labels + err := helpers.CheckLabelLength(deployment.ObjectMeta.Labels) + if err != nil { + return nil, err + } + + // start deployment template + deployment.Spec.Template.ObjectMeta.Labels = labels + deployment.Spec.Template.ObjectMeta.Annotations = annotations + + deployment.Spec.Template.ObjectMeta.Annotations["lagoon.sh/configMapSha"] = buildValues.ConfigMapSha + + deployment.Spec.Replicas = helpers.Int32Ptr(1) + deployment.Spec.Selector = &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "app.kubernetes.io/name": serviceTypeValues.Name, + "app.kubernetes.io/instance": serviceValues.Name, + }, + } + deployment.Spec.Strategy = serviceTypeValues.Strategy + + // disable service links, this prevents some environment variables that confuse lagoon services being + // added to the containers + deployment.Spec.Template.Spec.EnableServiceLinks = helpers.BoolPtr(false) + // set the priority class + deployment.Spec.Template.Spec.PriorityClassName = fmt.Sprintf("lagoon-priority-%s", buildValues.EnvironmentType) + + // set up an volumes this deployment can use + for _, dsv := range buildValues.DynamicSecretVolumes { + volume := corev1.Volume{ + Name: dsv.Name, + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: dsv.Secret.SecretName, + Optional: &dsv.Secret.Optional, + }, + }, + } + deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, volume) + } + if serviceTypeValues.Volumes.PersistentVolumeSize != "" { + volume := corev1.Volume{ + Name: serviceValues.PersistentVolumeName, + VolumeSource: corev1.VolumeSource{ + PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ + ClaimName: serviceValues.PersistentVolumeName, + }, + }, + } + deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, volume) + } + + // handle any image pull secrets + pullsecrets := []corev1.LocalObjectReference{} + for _, pullsecret := range buildValues.ImagePullSecrets { + pullsecrets = append(pullsecrets, corev1.LocalObjectReference{ + Name: pullsecret.Name, + }) + } + deployment.Spec.Template.Spec.ImagePullSecrets = pullsecrets + + // handle node selectors, tolerations, and affinity configuration + if serviceValues.NodeSelectors != nil { + deployment.Spec.Template.Spec.NodeSelector = *serviceValues.NodeSelectors + } + if serviceValues.Tolerations != nil { + deployment.Spec.Template.Spec.Tolerations = *serviceValues.Tolerations + } + deployment.Spec.Template.Spec.Affinity = serviceValues.Affinity + if serviceTypeValues.PodSecurityContext.HasDefault { + deployment.Spec.Template.Spec.SecurityContext = &corev1.PodSecurityContext{ + FSGroup: &serviceTypeValues.PodSecurityContext.FSGroup, + } + } + + // start working out the containers to add + container := serviceTypeValues.PrimaryContainer + // if the service can change the port + if serviceTypeValues.Ports.CanChangePort { + // check if the port override is defined + if serviceValues.ServicePort != 0 { + // and change the port in the container definition to suit + container.Container.ReadinessProbe.ProbeHandler.TCPSocket.Port.IntVal = serviceValues.ServicePort + container.Container.LivenessProbe.ProbeHandler.TCPSocket.Port.IntVal = serviceValues.ServicePort + container.Container.ReadinessProbe.ProbeHandler.TCPSocket.Port.IntVal = serviceValues.ServicePort + container.Container.Ports[0].ContainerPort = serviceValues.ServicePort + } + } + + // handle setting the rest of the containers specs with values from the service or build values + container.Container.Name = container.Name + container.Container.Image = serviceValues.ImageName + container.Container.Env = []corev1.EnvVar{ + { + Name: "LAGOON_GIT_SHA", + Value: buildValues.GitSha, + }, + { + Name: "CRONJOBS", + Value: serviceValues.InPodCronjobs, + }, + } + + // mount the volumes in the primary container + for _, dsm := range buildValues.DynamicSecretMounts { + volumeMount := corev1.VolumeMount{ + Name: dsm.Name, + MountPath: dsm.MountPath, + ReadOnly: dsm.ReadOnly, + } + container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) + } + if serviceTypeValues.Volumes.PersistentVolumeSize != "" { + volumeMount := corev1.VolumeMount{ + Name: serviceValues.PersistentVolumeName, + MountPath: serviceValues.PersistentVolumePath, + } + container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) + } + // append the final defined container to the spec + deployment.Spec.Template.Spec.Containers = append(deployment.Spec.Template.Spec.Containers, container.Container) + + // end deployment template + + deploymentBytes, err = yaml.Marshal(deployment) + if err != nil { + return nil, err + } + + // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) + // add the seperator to the template so that it can be `kubectl apply` in bulk as part + // of the current build process + // join all dbaas-consumer templates together + restoreResult := append(separator[:], deploymentBytes[:]...) + result = append(result, restoreResult[:]...) + } + } + return result, nil +} diff --git a/internal/templating/services/templates_deployment_test.go b/internal/templating/services/templates_deployment_test.go new file mode 100644 index 00000000..d5b72cb7 --- /dev/null +++ b/internal/templating/services/templates_deployment_test.go @@ -0,0 +1,200 @@ +package services + +import ( + "os" + "reflect" + "testing" + + "github.com/uselagoon/build-deploy-tool/internal/generator" +) + +func TestGenerateDeploymentTemplate(t *testing.T) { + type args struct { + buildValues generator.BuildValues + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + { + name: "test1 - basic", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-with-really-really-reall-3fdb", + EnvironmentType: "production", + Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-with-really-really-reall-3fdb", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + GitSha: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + Services: []generator.ServiceValues{ + { + Name: "myservice", + OverrideName: "myservice", + Type: "basic", + DBaaSEnvironment: "development", + ImageName: "harbor.example.com/example-project/environment-with-really-really-reall-3fdb/basic@latest", + }, + // { + // Name: "myservice-po", + // OverrideName: "myservice-po", + // Type: "basic", + // DBaaSEnvironment: "development", + // ServicePort: 8080, + // }, + // { + // Name: "myservice-persist", + // OverrideName: "myservice-persist", + // Type: "basic-persistent", + // DBaaSEnvironment: "development", + // PersistentVolumeSize: "5Gi", + // PersistentVolumePath: "/storage/data", + // PersistentVolumeName: "basic", + // }, + // { + // Name: "myservice-persist-po", + // OverrideName: "myservice-persist-po", + // Type: "basic-persistent", + // DBaaSEnvironment: "development", + // ServicePort: 8080, + // PersistentVolumeSize: "5Gi", + // PersistentVolumePath: "/storage/data", + // PersistentVolumeName: "basic", + // }, + // { + // Name: "myservice-persist-po", + // OverrideName: "myservice-persist-po", + // Type: "basic-persistent", + // DBaaSEnvironment: "development", + // ServicePort: 8080, + // PersistentVolumeSize: "100Gi", + // PersistentVolumePath: "/storage/data", + // PersistentVolumeName: "basic", + // }, + }, + }, + }, + want: "test-resources/deployment/result-basic-1.yaml", + }, + // { + // name: "test2 - cli", + // args: args{ + // buildValues: generator.BuildValues{ + // Project: "example-project", + // Environment: "environment-with-really-really-reall-3fdb", + // EnvironmentType: "production", + // Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + // BuildType: "branch", + // LagoonVersion: "v2.x.x", + // Kubernetes: "generator.local", + // Branch: "environment-with-really-really-reall-3fdb", + // Services: []generator.ServiceValues{ + // { + // Name: "myservice", + // OverrideName: "myservice", + // Type: "cli", + // DBaaSEnvironment: "development", + // }, + // { + // Name: "myservice-persist", + // OverrideName: "myservice-persist", + // Type: "cli-persistent", + // DBaaSEnvironment: "development", + // }, + // }, + // }, + // }, + // want: "test-resources/deployment/result-cli-1.yaml", + // }, + // { + // name: "test3 - elasticsearch", + // args: args{ + // buildValues: generator.BuildValues{ + // Project: "example-project", + // Environment: "environment-with-really-really-reall-3fdb", + // EnvironmentType: "production", + // Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + // BuildType: "branch", + // LagoonVersion: "v2.x.x", + // Kubernetes: "generator.local", + // Branch: "environment-with-really-really-reall-3fdb", + // Services: []generator.ServiceValues{ + // { + // Name: "myservice", + // OverrideName: "myservice", + // Type: "elasticsearch", + // DBaaSEnvironment: "development", + // PersistentVolumeSize: "5Gi", + // }, + // { + // Name: "myservice-size", + // OverrideName: "myservice-size", + // Type: "elasticsearch", + // DBaaSEnvironment: "development", + // PersistentVolumeSize: "100Gi", + // }, + // }, + // }, + // }, + // want: "test-resources/deployment/result-elasticsearch-1.yaml", + // }, + // { + // name: "test4 - opensearch", + // args: args{ + // buildValues: generator.BuildValues{ + // Project: "example-project", + // Environment: "environment-with-really-really-reall-3fdb", + // EnvironmentType: "production", + // Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + // BuildType: "branch", + // LagoonVersion: "v2.x.x", + // Kubernetes: "generator.local", + // Branch: "environment-with-really-really-reall-3fdb", + // Services: []generator.ServiceValues{ + // { + // Name: "myservice", + // OverrideName: "myservice", + // Type: "opensearch", + // DBaaSEnvironment: "development", + // PersistentVolumeSize: "5Gi", + // }, + // { + // Name: "myservice-size", + // OverrideName: "myservice-size", + // Type: "opensearch", + // DBaaSEnvironment: "development", + // PersistentVolumeSize: "100Gi", + // }, + // }, + // }, + // }, + // want: "test-resources/deployment/result-opensearch-1.yaml", + // }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GenerateDeploymentTemplate(tt.args.buildValues) + if (err != nil) != tt.wantErr { + t.Errorf("GenerateDeploymentTemplate() error = %v, wantErr %v", err, tt.wantErr) + return + } + r1, err := os.ReadFile(tt.want) + if err != nil { + t.Errorf("couldn't read file %v: %v", tt.want, err) + } + if !reflect.DeepEqual(string(got), string(r1)) { + t.Errorf("GenerateDeploymentTemplate() = %v, want %v", string(got), string(r1)) + } + }) + } +} diff --git a/internal/templating/services/templates_pvc.go b/internal/templating/services/templates_pvc.go new file mode 100644 index 00000000..5025f17b --- /dev/null +++ b/internal/templating/services/templates_pvc.go @@ -0,0 +1,142 @@ +package services + +import ( + "fmt" + "strconv" + + "github.com/uselagoon/build-deploy-tool/internal/generator" + "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/servicetypes" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + apivalidation "k8s.io/apimachinery/pkg/api/validation" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" + "sigs.k8s.io/yaml" +) + +// GeneratePVCTemplate generates the lagoon template to apply. +func GeneratePVCTemplate( + buildValues generator.BuildValues, +) ([]byte, error) { + separator := []byte("---\n") + var result []byte + + // add the default labels + labels := map[string]string{ + "app.kubernetes.io/managed-by": "build-deploy-tool", + "lagoon.sh/project": buildValues.Project, + "lagoon.sh/environment": buildValues.Environment, + "lagoon.sh/environmentType": buildValues.EnvironmentType, + "lagoon.sh/buildType": buildValues.BuildType, + } + + // add the default annotations + annotations := map[string]string{ + "lagoon.sh/version": buildValues.LagoonVersion, + } + + // add any additional labels + additionalLabels := map[string]string{} + additionalAnnotations := map[string]string{} + if buildValues.BuildType == "branch" { + additionalAnnotations["lagoon.sh/branch"] = buildValues.Branch + } else if buildValues.BuildType == "pullrequest" { + additionalAnnotations["lagoon.sh/prNumber"] = buildValues.PRNumber + additionalAnnotations["lagoon.sh/prHeadBranch"] = buildValues.PRHeadBranch + additionalAnnotations["lagoon.sh/prBaseBranch"] = buildValues.PRBaseBranch + + } + + // for all the services that the build values generated + // iterate over them and generate any kubernetes pvcs + for _, serviceValues := range buildValues.Services { + if val, ok := servicetypes.ServiceTypes[serviceValues.Type]; ok { + if val.Volumes.PersistentVolumeSize != "" { + if serviceValues.PersistentVolumeSize == "" { + return nil, fmt.Errorf("no persistent volume size defined for this service") + } + serviceType := &servicetypes.ServiceType{} + helpers.DeepCopy(val, serviceType) + + var pvcBytes []byte + additionalLabels["app.kubernetes.io/name"] = serviceType.Name + additionalLabels["app.kubernetes.io/instance"] = serviceValues.Name + additionalLabels["lagoon.sh/template"] = fmt.Sprintf("%s-%s", serviceType.Name, "0.1.0") + additionalLabels["lagoon.sh/service"] = serviceValues.Name + additionalLabels["lagoon.sh/service-type"] = serviceType.Name + + additionalAnnotations["k8up.syn.tools/backup"] = strconv.FormatBool(val.Volumes.Backup) + additionalAnnotations["k8up.io/backup"] = strconv.FormatBool(val.Volumes.Backup) + + pvc := &corev1.PersistentVolumeClaim{ + TypeMeta: metav1.TypeMeta{ + Kind: corev1.SchemeGroupVersion.Group, + APIVersion: corev1.SchemeGroupVersion.Version, + }, + ObjectMeta: metav1.ObjectMeta{ + Name: serviceValues.Name, + }, + } + pvc.ObjectMeta.Labels = labels + pvc.ObjectMeta.Annotations = annotations + for key, value := range additionalLabels { + pvc.ObjectMeta.Labels[key] = value + } + // add any additional annotations + for key, value := range additionalAnnotations { + pvc.ObjectMeta.Annotations[key] = value + } + // validate any annotations + if err := apivalidation.ValidateAnnotations(pvc.ObjectMeta.Annotations, nil); err != nil { + if len(err) != 0 { + return nil, fmt.Errorf("the annotations for %s are not valid: %v", serviceValues.Name, err) + } + } + // validate any labels + if err := metavalidation.ValidateLabels(pvc.ObjectMeta.Labels, nil); err != nil { + if len(err) != 0 { + return nil, fmt.Errorf("the labels for %s are not valid: %v", serviceValues.Name, err) + } + } + // check length of labels + err := helpers.CheckLabelLength(pvc.ObjectMeta.Labels) + if err != nil { + return nil, err + } + + // start PVC template + q, err := resource.ParseQuantity(serviceValues.PersistentVolumeSize) + if err != nil { + return nil, fmt.Errorf("provided persistent volume size is not valid: %v", err) + } + volumeSize, _ := q.AsInt64() + pvc.Spec = corev1.PersistentVolumeClaimSpec{ + AccessModes: []corev1.PersistentVolumeAccessMode{ + val.Volumes.PersistentVolumeType, + }, + StorageClassName: helpers.StrPtr("bulk"), + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + "storage": *resource.NewQuantity(volumeSize, resource.BinarySI), + }, + }, + } + // end PVC template + + pvcBytes, err = yaml.Marshal(pvc) + if err != nil { + return nil, err + } + + // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) + // add the seperator to the template so that it can be `kubectl apply` in bulk as part + // of the current build process + // join all dbaas-consumer templates together + restoreResult := append(separator[:], pvcBytes[:]...) + result = append(result, restoreResult[:]...) + } + } + } + return result, nil +} diff --git a/internal/templating/services/templates_pvc_test.go b/internal/templating/services/templates_pvc_test.go new file mode 100644 index 00000000..51853190 --- /dev/null +++ b/internal/templating/services/templates_pvc_test.go @@ -0,0 +1,186 @@ +package services + +import ( + "os" + "reflect" + "testing" + + "github.com/uselagoon/build-deploy-tool/internal/generator" +) + +func TestGeneratePVCTemplate(t *testing.T) { + type args struct { + buildValues generator.BuildValues + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + { + name: "test1 - basic", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-with-really-really-reall-3fdb", + EnvironmentType: "production", + Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-with-really-really-reall-3fdb", + Services: []generator.ServiceValues{ + { + Name: "myservice", + OverrideName: "myservice", + Type: "basic", + DBaaSEnvironment: "development", + }, + { + Name: "myservice-po", + OverrideName: "myservice-po", + Type: "basic", + DBaaSEnvironment: "development", + ServicePort: 8080, + }, + { + Name: "myservice-persist", + OverrideName: "myservice-persist", + Type: "basic-persistent", + DBaaSEnvironment: "development", + PersistentVolumeSize: "5Gi", + }, + { + Name: "myservice-persist-po", + OverrideName: "myservice-persist-po", + Type: "basic-persistent", + DBaaSEnvironment: "development", + ServicePort: 8080, + PersistentVolumeSize: "5Gi", + }, + { + Name: "myservice-persist-po", + OverrideName: "myservice-persist-po", + Type: "basic-persistent", + DBaaSEnvironment: "development", + ServicePort: 8080, + PersistentVolumeSize: "100Gi", + }, + }, + }, + }, + want: "test-resources/pvc/result-basic-1.yaml", + }, + { + name: "test2 - cli", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-with-really-really-reall-3fdb", + EnvironmentType: "production", + Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-with-really-really-reall-3fdb", + Services: []generator.ServiceValues{ + { + Name: "myservice", + OverrideName: "myservice", + Type: "cli", + DBaaSEnvironment: "development", + }, + { + Name: "myservice-persist", + OverrideName: "myservice-persist", + Type: "cli-persistent", + DBaaSEnvironment: "development", + }, + }, + }, + }, + want: "test-resources/pvc/result-cli-1.yaml", + }, + { + name: "test3 - elasticsearch", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-with-really-really-reall-3fdb", + EnvironmentType: "production", + Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-with-really-really-reall-3fdb", + Services: []generator.ServiceValues{ + { + Name: "myservice", + OverrideName: "myservice", + Type: "elasticsearch", + DBaaSEnvironment: "development", + PersistentVolumeSize: "5Gi", + }, + { + Name: "myservice-size", + OverrideName: "myservice-size", + Type: "elasticsearch", + DBaaSEnvironment: "development", + PersistentVolumeSize: "100Gi", + }, + }, + }, + }, + want: "test-resources/pvc/result-elasticsearch-1.yaml", + }, + { + name: "test4 - opensearch", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-with-really-really-reall-3fdb", + EnvironmentType: "production", + Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-with-really-really-reall-3fdb", + Services: []generator.ServiceValues{ + { + Name: "myservice", + OverrideName: "myservice", + Type: "opensearch", + DBaaSEnvironment: "development", + PersistentVolumeSize: "5Gi", + }, + { + Name: "myservice-size", + OverrideName: "myservice-size", + Type: "opensearch", + DBaaSEnvironment: "development", + PersistentVolumeSize: "100Gi", + }, + }, + }, + }, + want: "test-resources/pvc/result-opensearch-1.yaml", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GeneratePVCTemplate(tt.args.buildValues) + if (err != nil) != tt.wantErr { + t.Errorf("GeneratePVCTemplate() error = %v, wantErr %v", err, tt.wantErr) + return + } + r1, err := os.ReadFile(tt.want) + if err != nil { + t.Errorf("couldn't read file %v: %v", tt.want, err) + } + if !reflect.DeepEqual(string(got), string(r1)) { + t.Errorf("GeneratePVCTemplate() = %v, want %v", string(got), string(r1)) + } + }) + } +} diff --git a/internal/templating/services/templates_service.go b/internal/templating/services/templates_service.go new file mode 100644 index 00000000..5d3959db --- /dev/null +++ b/internal/templating/services/templates_service.go @@ -0,0 +1,131 @@ +package services + +import ( + "fmt" + + "github.com/uselagoon/build-deploy-tool/internal/generator" + "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/servicetypes" + corev1 "k8s.io/api/core/v1" + apivalidation "k8s.io/apimachinery/pkg/api/validation" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" + "sigs.k8s.io/yaml" +) + +// GenerateServiceTemplate generates the lagoon template to apply. +func GenerateServiceTemplate( + buildValues generator.BuildValues, +) ([]byte, error) { + separator := []byte("---\n") + var result []byte + + // add the default labels + labels := map[string]string{ + "app.kubernetes.io/managed-by": "build-deploy-tool", + "lagoon.sh/project": buildValues.Project, + "lagoon.sh/environment": buildValues.Environment, + "lagoon.sh/environmentType": buildValues.EnvironmentType, + "lagoon.sh/buildType": buildValues.BuildType, + } + + // add the default annotations + annotations := map[string]string{ + "lagoon.sh/version": buildValues.LagoonVersion, + } + + // add any additional labels + additionalLabels := map[string]string{} + additionalAnnotations := map[string]string{} + if buildValues.BuildType == "branch" { + additionalAnnotations["lagoon.sh/branch"] = buildValues.Branch + } else if buildValues.BuildType == "pullrequest" { + additionalAnnotations["lagoon.sh/prNumber"] = buildValues.PRNumber + additionalAnnotations["lagoon.sh/prHeadBranch"] = buildValues.PRHeadBranch + additionalAnnotations["lagoon.sh/prBaseBranch"] = buildValues.PRBaseBranch + + } + + // for all the services that the build values generated + // iterate over them and generate any kubernetes services + for _, serviceValues := range buildValues.Services { + if val, ok := servicetypes.ServiceTypes[serviceValues.Type]; ok { + // if the service default has no ports, then don't generate any services + if val.Ports.Ports != nil { + serviceType := &servicetypes.ServiceType{} + helpers.DeepCopy(val, serviceType) + + var serviceBytes []byte + additionalLabels["app.kubernetes.io/name"] = serviceType.Name + additionalLabels["app.kubernetes.io/instance"] = serviceValues.Name + additionalLabels["lagoon.sh/template"] = fmt.Sprintf("%s-%s", serviceType.Name, "0.1.0") + additionalLabels["lagoon.sh/service"] = serviceValues.Name + additionalLabels["lagoon.sh/service-type"] = serviceType.Name + service := &corev1.Service{ + TypeMeta: metav1.TypeMeta{ + Kind: corev1.SchemeGroupVersion.Group, + APIVersion: corev1.SchemeGroupVersion.Version, + }, + ObjectMeta: metav1.ObjectMeta{ + Name: serviceValues.Name, + }, + } + service.ObjectMeta.Labels = labels + service.ObjectMeta.Annotations = annotations + for key, value := range additionalLabels { + service.ObjectMeta.Labels[key] = value + } + // add any additional annotations + for key, value := range additionalAnnotations { + service.ObjectMeta.Annotations[key] = value + } + // validate any annotations + if err := apivalidation.ValidateAnnotations(service.ObjectMeta.Annotations, nil); err != nil { + if len(err) != 0 { + return nil, fmt.Errorf("the annotations for %s are not valid: %v", serviceValues.Name, err) + } + } + // validate any labels + if err := metavalidation.ValidateLabels(service.ObjectMeta.Labels, nil); err != nil { + if len(err) != 0 { + return nil, fmt.Errorf("the labels for %s are not valid: %v", serviceValues.Name, err) + } + } + // check length of labels + err := helpers.CheckLabelLength(service.ObjectMeta.Labels) + if err != nil { + return nil, err + } + + // start service template + if serviceType.Ports.CanChangePort { + if serviceValues.ServicePort != 0 { + serviceType.Ports.Ports[0].Port = serviceValues.ServicePort + } + } + + service.Spec = corev1.ServiceSpec{ + Ports: serviceType.Ports.Ports, + } + + service.Spec.Selector = map[string]string{ + "app.kubernetes.io/name": serviceType.Name, + "app.kubernetes.io/instance": serviceValues.Name, + } + // end service template + + serviceBytes, err = yaml.Marshal(service) + if err != nil { + return nil, err + } + // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) + // add the seperator to the template so that it can be `kubectl apply` in bulk as part + // of the current build process + // join all dbaas-consumer templates together + restoreResult := append(separator[:], serviceBytes[:]...) + result = append(result, restoreResult[:]...) + } + } + } + return result, nil +} diff --git a/internal/templating/services/templates_service_test.go b/internal/templating/services/templates_service_test.go new file mode 100644 index 00000000..8fc1c696 --- /dev/null +++ b/internal/templating/services/templates_service_test.go @@ -0,0 +1,176 @@ +package services + +import ( + "os" + "reflect" + "testing" + + "github.com/uselagoon/build-deploy-tool/internal/generator" +) + +func TestGenerateServiceTemplate(t *testing.T) { + type args struct { + buildValues generator.BuildValues + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + { + name: "test1 - basic", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-with-really-really-reall-3fdb", + EnvironmentType: "production", + Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-with-really-really-reall-3fdb", + Services: []generator.ServiceValues{ + { + Name: "myservice", + OverrideName: "myservice", + Type: "basic", + DBaaSEnvironment: "development", + }, + { + Name: "myservice-po", + OverrideName: "myservice-po", + Type: "basic", + DBaaSEnvironment: "development", + ServicePort: 8080, + }, + { + Name: "myservice-persist", + OverrideName: "myservice-persist", + Type: "basic-persistent", + DBaaSEnvironment: "development", + }, + { + Name: "myservice-persist-po", + OverrideName: "myservice-persist-po", + Type: "basic-persistent", + DBaaSEnvironment: "development", + ServicePort: 8080, + }, + }, + }, + }, + want: "test-resources/service/result-basic-1.yaml", + }, + { + name: "test2 - cli", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-with-really-really-reall-3fdb", + EnvironmentType: "production", + Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-with-really-really-reall-3fdb", + Services: []generator.ServiceValues{ + { + Name: "myservice", + OverrideName: "myservice", + Type: "cli", + DBaaSEnvironment: "development", + }, + { + Name: "myservice-persist", + OverrideName: "myservice-persist", + Type: "cli-persistent", + DBaaSEnvironment: "development", + }, + }, + }, + }, + want: "test-resources/service/result-cli-1.yaml", + }, + { + name: "test3 - elasticsearch", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-with-really-really-reall-3fdb", + EnvironmentType: "production", + Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-with-really-really-reall-3fdb", + Services: []generator.ServiceValues{ + { + Name: "myservice", + OverrideName: "myservice", + Type: "elasticsearch", + DBaaSEnvironment: "development", + PersistentVolumeSize: "5Gi", + }, + { + Name: "myservice-size", + OverrideName: "myservice-size", + Type: "elasticsearch", + DBaaSEnvironment: "development", + PersistentVolumeSize: "100Gi", + }, + }, + }, + }, + want: "test-resources/service/result-elasticsearch-1.yaml", + }, + { + name: "test3 - opensearch", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-with-really-really-reall-3fdb", + EnvironmentType: "production", + Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-with-really-really-reall-3fdb", + Services: []generator.ServiceValues{ + { + Name: "myservice", + OverrideName: "myservice", + Type: "opensearch", + DBaaSEnvironment: "development", + PersistentVolumeSize: "5Gi", + }, + { + Name: "myservice-size", + OverrideName: "myservice-size", + Type: "opensearch", + DBaaSEnvironment: "development", + PersistentVolumeSize: "100Gi", + }, + }, + }, + }, + want: "test-resources/service/result-opensearch-1.yaml", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GenerateServiceTemplate(tt.args.buildValues) + if (err != nil) != tt.wantErr { + t.Errorf("GenerateServiceTemplate() error = %v, wantErr %v", err, tt.wantErr) + return + } + r1, err := os.ReadFile(tt.want) + if err != nil { + t.Errorf("couldn't read file %v: %v", tt.want, err) + } + if !reflect.DeepEqual(string(got), string(r1)) { + t.Errorf("GenerateServiceTemplate() = %v, want %v", string(got), string(r1)) + } + }) + } +} diff --git a/internal/templating/services/test-resources/deployment/result-basic-1.yaml b/internal/templating/services/test-resources/deployment/result-basic-1.yaml new file mode 100644 index 00000000..61c8ea4e --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-basic-1.yaml @@ -0,0 +1,77 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: environment-with-really-really-reall-3fdb + 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 + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + 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 + name: myservice +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: myservice + app.kubernetes.io/name: basic + strategy: {} + template: + metadata: + annotations: + lagoon.sh/branch: environment-with-really-really-reall-3fdb + 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 + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + 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 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-with-really-really-reall-3fdb/basic@latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 3000 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 3000 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 3000 + timeoutSeconds: 1 + resources: {} + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-cli-1.yaml b/internal/templating/services/test-resources/deployment/result-cli-1.yaml new file mode 100644 index 00000000..e69de29b diff --git a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml new file mode 100644 index 00000000..e69de29b diff --git a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml new file mode 100644 index 00000000..e69de29b diff --git a/internal/templating/services/test-resources/pvc/result-basic-1.yaml b/internal/templating/services/test-resources/pvc/result-basic-1.yaml new file mode 100644 index 00000000..f98b50af --- /dev/null +++ b/internal/templating/services/test-resources/pvc/result-basic-1.yaml @@ -0,0 +1,87 @@ +--- +apiVersion: v1 +metadata: + annotations: + k8up.io/backup: "true" + k8up.syn.tools/backup: "true" + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: myservice-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: myservice-persist +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 5Gi + storageClassName: bulk +status: {} +--- +apiVersion: v1 +metadata: + annotations: + k8up.io/backup: "true" + k8up.syn.tools/backup: "true" + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: myservice-persist-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist-po + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: myservice-persist-po +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 5Gi + storageClassName: bulk +status: {} +--- +apiVersion: v1 +metadata: + annotations: + k8up.io/backup: "true" + k8up.syn.tools/backup: "true" + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: myservice-persist-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist-po + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: myservice-persist-po +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 100Gi + storageClassName: bulk +status: {} diff --git a/internal/templating/services/test-resources/pvc/result-cli-1.yaml b/internal/templating/services/test-resources/pvc/result-cli-1.yaml new file mode 100644 index 00000000..e69de29b diff --git a/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml new file mode 100644 index 00000000..32e55c91 --- /dev/null +++ b/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml @@ -0,0 +1,58 @@ +--- +apiVersion: v1 +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + lagoon.sh/branch: environment-with-really-really-reall-3fdb + 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: elasticsearch + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice + lagoon.sh/service-type: elasticsearch + lagoon.sh/template: elasticsearch-0.1.0 + name: myservice +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi + storageClassName: bulk +status: {} +--- +apiVersion: v1 +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: myservice-size + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: elasticsearch + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-size + lagoon.sh/service-type: elasticsearch + lagoon.sh/template: elasticsearch-0.1.0 + name: myservice-size +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Gi + storageClassName: bulk +status: {} diff --git a/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml b/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml new file mode 100644 index 00000000..70f8e7ac --- /dev/null +++ b/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml @@ -0,0 +1,58 @@ +--- +apiVersion: v1 +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + lagoon.sh/branch: environment-with-really-really-reall-3fdb + 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: opensearch + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice + lagoon.sh/service-type: opensearch + lagoon.sh/template: opensearch-0.1.0 + name: myservice +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi + storageClassName: bulk +status: {} +--- +apiVersion: v1 +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: myservice-size + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: opensearch + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-size + lagoon.sh/service-type: opensearch + lagoon.sh/template: opensearch-0.1.0 + name: myservice-size +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Gi + storageClassName: bulk +status: {} diff --git a/internal/templating/services/test-resources/service/result-basic-1.yaml b/internal/templating/services/test-resources/service/result-basic-1.yaml new file mode 100644 index 00000000..5cbd475b --- /dev/null +++ b/internal/templating/services/test-resources/service/result-basic-1.yaml @@ -0,0 +1,120 @@ +--- +apiVersion: v1 +metadata: + annotations: + lagoon.sh/branch: environment-with-really-really-reall-3fdb + 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 + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + 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 + name: myservice +spec: + ports: + - name: http + port: 3000 + protocol: TCP + targetPort: http + selector: + app.kubernetes.io/instance: myservice + app.kubernetes.io/name: basic +status: + loadBalancer: {} +--- +apiVersion: v1 +metadata: + annotations: + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: myservice-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-po + lagoon.sh/service-type: basic + lagoon.sh/template: basic-0.1.0 + name: myservice-po +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: http + selector: + app.kubernetes.io/instance: myservice-po + app.kubernetes.io/name: basic +status: + loadBalancer: {} +--- +apiVersion: v1 +metadata: + annotations: + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: myservice-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: myservice-persist +spec: + ports: + - name: http + port: 3000 + protocol: TCP + targetPort: http + selector: + app.kubernetes.io/instance: myservice-persist + app.kubernetes.io/name: basic-persistent +status: + loadBalancer: {} +--- +apiVersion: v1 +metadata: + annotations: + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: myservice-persist-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist-po + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: myservice-persist-po +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: http + selector: + app.kubernetes.io/instance: myservice-persist-po + app.kubernetes.io/name: basic-persistent +status: + loadBalancer: {} diff --git a/internal/templating/services/test-resources/service/result-cli-1.yaml b/internal/templating/services/test-resources/service/result-cli-1.yaml new file mode 100644 index 00000000..e69de29b diff --git a/internal/templating/services/test-resources/service/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/service/result-elasticsearch-1.yaml new file mode 100644 index 00000000..c8de14c5 --- /dev/null +++ b/internal/templating/services/test-resources/service/result-elasticsearch-1.yaml @@ -0,0 +1,60 @@ +--- +apiVersion: v1 +metadata: + annotations: + lagoon.sh/branch: environment-with-really-really-reall-3fdb + 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: elasticsearch + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice + lagoon.sh/service-type: elasticsearch + lagoon.sh/template: elasticsearch-0.1.0 + name: myservice +spec: + ports: + - name: 9200-tcp + port: 9200 + protocol: TCP + targetPort: 9200 + selector: + app.kubernetes.io/instance: myservice + app.kubernetes.io/name: elasticsearch +status: + loadBalancer: {} +--- +apiVersion: v1 +metadata: + annotations: + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: myservice-size + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: elasticsearch + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-size + lagoon.sh/service-type: elasticsearch + lagoon.sh/template: elasticsearch-0.1.0 + name: myservice-size +spec: + ports: + - name: 9200-tcp + port: 9200 + protocol: TCP + targetPort: 9200 + selector: + app.kubernetes.io/instance: myservice-size + app.kubernetes.io/name: elasticsearch +status: + loadBalancer: {} diff --git a/internal/templating/services/test-resources/service/result-opensearch-1.yaml b/internal/templating/services/test-resources/service/result-opensearch-1.yaml new file mode 100644 index 00000000..5abaf744 --- /dev/null +++ b/internal/templating/services/test-resources/service/result-opensearch-1.yaml @@ -0,0 +1,60 @@ +--- +apiVersion: v1 +metadata: + annotations: + lagoon.sh/branch: environment-with-really-really-reall-3fdb + 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: opensearch + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice + lagoon.sh/service-type: opensearch + lagoon.sh/template: opensearch-0.1.0 + name: myservice +spec: + ports: + - name: 9200-tcp + port: 9200 + protocol: TCP + targetPort: 9200 + selector: + app.kubernetes.io/instance: myservice + app.kubernetes.io/name: opensearch +status: + loadBalancer: {} +--- +apiVersion: v1 +metadata: + annotations: + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: myservice-size + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: opensearch + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-size + lagoon.sh/service-type: opensearch + lagoon.sh/template: opensearch-0.1.0 + name: myservice-size +spec: + ports: + - name: 9200-tcp + port: 9200 + protocol: TCP + targetPort: 9200 + selector: + app.kubernetes.io/instance: myservice-size + app.kubernetes.io/name: opensearch +status: + loadBalancer: {} From 53addd93fd3bb931dba15f89259e377a2717d6bc Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 8 Dec 2022 13:43:46 +1100 Subject: [PATCH 02/92] feat: initial run at service-templates --- internal/templating/services/templates_deployment.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index 99fe1cb4..09252c17 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -107,8 +107,12 @@ func GenerateDeploymentTemplate( } // start deployment template - deployment.Spec.Template.ObjectMeta.Labels = labels - deployment.Spec.Template.ObjectMeta.Annotations = annotations + depMeta := metav1.ObjectMeta{ + Name: serviceValues.Name, + Labels: labels, + Annotations: annotations, + } + deployment.Spec.Template.ObjectMeta = depMeta deployment.Spec.Template.ObjectMeta.Annotations["lagoon.sh/configMapSha"] = buildValues.ConfigMapSha From d6ac43518d6d4abbf9b8cefa597d9836d18720c3 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 8 Dec 2022 17:30:55 +1100 Subject: [PATCH 03/92] feat: add inpod cronjob detection --- internal/helpers/helpers_cron.go | 30 +++++++++++++++++ internal/helpers/helpers_cron_test.go | 46 +++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/internal/helpers/helpers_cron.go b/internal/helpers/helpers_cron.go index b4486e1c..78405808 100644 --- a/internal/helpers/helpers_cron.go +++ b/internal/helpers/helpers_cron.go @@ -191,6 +191,36 @@ func ConvertCrontab(namespace, cron string) (string, error) { return "", fmt.Errorf("cron definition '%s' is invalid", cron) } +func IsInPodCronjob(cron string) (bool, error) { + splitCron := strings.Split(cron, " ") + // check the provided cron splits into 5 + if len(splitCron) == 5 { + for idx, val := range splitCron { + if idx == 0 { + match1, _ := regexp.MatchString("^(M|H|\\*)/([0-5]?[0-9])$", val) + if match1 { + // A Minute like M/15 (or H/15 or */15 for backwards compatibility) is defined, create a list of minutes with a random start + // like 4,19,34,49 or 6,21,36,51 + params := getCaptureBlocks("^(?PM|H|\\*)/(?P[0-5]?[0-9])$", val) + step, err := strconv.Atoi(params["P2"]) + if err != nil { + return false, fmt.Errorf("cron definition '%s' is invalid, unable to determine minutes value", cron) + } + if step <= 30 { + return true, nil + } + } + match2, _ := regexp.MatchString("^\\*$", val) + if match2 { + // this runs every minute + return true, nil + } + } + } + } + return false, nil +} + func getCaptureBlocks(regex, val string) (captureMap map[string]string) { var regexComp = regexp.MustCompile(regex) match := regexComp.FindStringSubmatch(val) diff --git a/internal/helpers/helpers_cron_test.go b/internal/helpers/helpers_cron_test.go index 5287db91..c7df20c0 100644 --- a/internal/helpers/helpers_cron_test.go +++ b/internal/helpers/helpers_cron_test.go @@ -162,3 +162,49 @@ func TestConvertCrontab(t *testing.T) { }) } } + +func Test_isInPodCronjob(t *testing.T) { + type args struct { + cron string + } + tests := []struct { + name string + args args + want bool + wantErr bool + }{ + { + name: "test1 - every 15 minutes, should be inpod", + args: args{ + cron: "M/15 * * 11 0-5", + }, + want: true, + }, + { + name: "test2 - every minute, should be in pod", + args: args{ + cron: "* * * 11 0-5", + }, + want: true, + }, + { + name: "test3 - on the 15 minute mark, should not be in pod", + args: args{ + cron: "15 * * 11 0-5", + }, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := IsInPodCronjob(tt.args.cron) + if (err != nil) != tt.wantErr { + t.Errorf("IsInPodCronjob() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("IsInPodCronjob() = %v, want %v", got, tt.want) + } + }) + } +} From 0afa5890a70857099c19cdc57f1bfcaa9941253c Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 8 Dec 2022 17:31:37 +1100 Subject: [PATCH 04/92] chore: add cronjob to lagoonyml --- internal/lagoon/lagoon.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/lagoon/lagoon.go b/internal/lagoon/lagoon.go index 47f85e10..77d61cd4 100644 --- a/internal/lagoon/lagoon.go +++ b/internal/lagoon/lagoon.go @@ -23,6 +23,14 @@ type Environment struct { AutogenerateRoutes *bool `json:"autogenerateRoutes"` Types map[string]string `json:"types"` Routes []map[string][]Route `json:"routes"` + Cronjobs []Cronjob `json:"cronjobs"` +} + +type Cronjob struct { + Name string `json:"name"` + Service string `json:"service"` + Schedule string `json:"schedule"` + Command string `json:"command"` } // Environments . From 14a3d451ee768873020afd22a40cb84ba3704613 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 8 Dec 2022 17:32:13 +1100 Subject: [PATCH 05/92] refactor: add cronjob to service calculations --- internal/generator/buildvalues.go | 48 ++++++++++++++--------------- internal/generator/services.go | 20 ++++++++++++ internal/generator/services_test.go | 22 +++++++++++++ 3 files changed, 66 insertions(+), 24 deletions(-) diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index d0096d33..274ace7a 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -87,30 +87,30 @@ type DynamicSecret struct { // ServiceValues is the values for a specific service used by a lagoon build type ServiceValues struct { - Name string `json:"name"` // this is the actual compose service name - OverrideName string `json:"overrideName"` // if an override name is provided, use it - Type string `json:"type"` - AutogeneratedRoutesEnabled bool `json:"autogeneratedRoutesEnabled"` - AutogeneratedRoutesTLSAcme bool `json:"autogeneratedRoutesTLSAcme"` - AutogeneratedRouteDomain string `json:"autogeneratedRouteDomain"` - ShortAutogeneratedRouteDomain string `json:"shortAutogeneratedRouteDomain"` - DBaaSEnvironment string `json:"dbaasEnvironment"` - NativeCronjobs map[string]CronjobValues `json:"nativeCronjobs"` - InPodCronjobs string `json:"inPodCronjobs"` - ImageName string `json:"imageName"` - DeploymentServiceType string `json:"deploymentServiecType"` - ServicePort int32 `json:"servicePort,omitempty"` - PersistentVolumePath string `json:"persistentVolumePath,omitempty"` - PersistentVolumeName string `json:"persistentVolumeName,omitempty"` - PersistentVolumeSize string `json:"persistentVolumeSize,omitempty"` - UseSpotInstances bool `json:"useSpot"` - NodeSelectors *map[string]string `json:"nodeSelectors"` - Tolerations *[]corev1.Toleration `json:"tolerations"` - Affinity *corev1.Affinity `json:"affinity"` - CronjobUseSpotInstances bool `json:"cronjobUseSpot"` - CronjobNodeSelectors *map[string]string `json:"cronjobNodeSelectors"` - CronjobTolerations *[]corev1.Toleration `json:"cronjobTolerations"` - CronjobAffinity *corev1.Affinity `json:"cronjobAffinity"` + Name string `json:"name"` // this is the actual compose service name + OverrideName string `json:"overrideName"` // if an override name is provided, use it + Type string `json:"type"` + AutogeneratedRoutesEnabled bool `json:"autogeneratedRoutesEnabled"` + AutogeneratedRoutesTLSAcme bool `json:"autogeneratedRoutesTLSAcme"` + AutogeneratedRouteDomain string `json:"autogeneratedRouteDomain"` + ShortAutogeneratedRouteDomain string `json:"shortAutogeneratedRouteDomain"` + DBaaSEnvironment string `json:"dbaasEnvironment"` + NativeCronjobs []lagoon.Cronjob `json:"nativeCronjobs"` + InPodCronjobs []lagoon.Cronjob `json:"inPodCronjobs"` + ImageName string `json:"imageName"` + DeploymentServiceType string `json:"deploymentServiecType"` + ServicePort int32 `json:"servicePort,omitempty"` + PersistentVolumePath string `json:"persistentVolumePath,omitempty"` + PersistentVolumeName string `json:"persistentVolumeName,omitempty"` + PersistentVolumeSize string `json:"persistentVolumeSize,omitempty"` + UseSpotInstances bool `json:"useSpot"` + NodeSelectors *map[string]string `json:"nodeSelectors"` + Tolerations *[]corev1.Toleration `json:"tolerations"` + Affinity *corev1.Affinity `json:"affinity"` + CronjobUseSpotInstances bool `json:"cronjobUseSpot"` + CronjobNodeSelectors *map[string]string `json:"cronjobNodeSelectors"` + CronjobTolerations *[]corev1.Toleration `json:"cronjobTolerations"` + CronjobAffinity *corev1.Affinity `json:"cronjobAffinity"` } // CronjobValues is the values for cronjobs diff --git a/internal/generator/services.go b/internal/generator/services.go index 86d03e6a..72cd42af 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -126,6 +126,24 @@ func composeToServiceValues( if value, ok := lYAML.Environments[buildValues.Environment].Types[composeService]; ok { lagoonType = value } + inpodcronjobs := []lagoon.Cronjob{} + nativecronjobs := []lagoon.Cronjob{} + for _, cronjob := range lYAML.Environments[buildValues.Branch].Cronjobs { + var err error + inpod, err := helpers.IsInPodCronjob(cronjob.Schedule) + if err != nil { + return ServiceValues{}, fmt.Errorf("Unable to validate crontab for cronjob %s: %v", cronjob.Name, err) + } + cronjob.Schedule, err = helpers.ConvertCrontab(buildValues.Namespace, cronjob.Schedule) + if err != nil { + return ServiceValues{}, fmt.Errorf("Unable to convert crontab for cronjob %s: %v", cronjob.Name, err) + } + if inpod { + inpodcronjobs = append(inpodcronjobs, cronjob) + } else { + nativecronjobs = append(nativecronjobs, cronjob) + } + } // check if the service has a specific override serviceAutogenerated := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.autogeneratedroute") if serviceAutogenerated != "" { @@ -285,6 +303,8 @@ func composeToServiceValues( PersistentVolumePath: servicePersistentPath, PersistentVolumeName: servicePersistentName, PersistentVolumeSize: servicePersistentSize, + InPodCronjobs: inpodcronjobs, + NativeCronjobs: nativecronjobs, } // check if the service has a service port override (this only applies to basic(-persistent)) servicePortOverride := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.service.port") diff --git a/internal/generator/services_test.go b/internal/generator/services_test.go index 87a0c2df..8649589d 100644 --- a/internal/generator/services_test.go +++ b/internal/generator/services_test.go @@ -52,6 +52,8 @@ func Test_composeToServiceValues(t *testing.T) { Type: "nginx", AutogeneratedRoutesEnabled: true, AutogeneratedRoutesTLSAcme: true, + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, }, }, { @@ -82,6 +84,8 @@ func Test_composeToServiceValues(t *testing.T) { Type: "nginx", AutogeneratedRoutesEnabled: true, AutogeneratedRoutesTLSAcme: true, + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, }, }, { @@ -115,6 +119,8 @@ func Test_composeToServiceValues(t *testing.T) { Type: "nginx-php-persistent", AutogeneratedRoutesEnabled: true, AutogeneratedRoutesTLSAcme: true, + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, }, }, { @@ -147,6 +153,8 @@ func Test_composeToServiceValues(t *testing.T) { Type: "nginx-php-persistent", AutogeneratedRoutesEnabled: true, AutogeneratedRoutesTLSAcme: true, + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, }, }, { @@ -178,6 +186,8 @@ func Test_composeToServiceValues(t *testing.T) { Type: "nginx", AutogeneratedRoutesEnabled: false, AutogeneratedRoutesTLSAcme: false, + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, }, }, { @@ -214,6 +224,8 @@ func Test_composeToServiceValues(t *testing.T) { Type: "nginx-php", AutogeneratedRoutesEnabled: true, AutogeneratedRoutesTLSAcme: true, + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, }, }, { @@ -251,6 +263,8 @@ func Test_composeToServiceValues(t *testing.T) { Type: "nginx-php", AutogeneratedRoutesEnabled: false, AutogeneratedRoutesTLSAcme: true, + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, }, }, { @@ -347,6 +361,8 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesEnabled: false, AutogeneratedRoutesTLSAcme: false, DBaaSEnvironment: "development", + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, }, }, { @@ -390,6 +406,8 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesEnabled: false, AutogeneratedRoutesTLSAcme: false, DBaaSEnvironment: "development2", + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, }, }, { @@ -428,6 +446,8 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesEnabled: false, AutogeneratedRoutesTLSAcme: false, DBaaSEnvironment: "development", + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, }, }, { @@ -457,6 +477,8 @@ func Test_composeToServiceValues(t *testing.T) { Type: "python", AutogeneratedRoutesEnabled: true, AutogeneratedRoutesTLSAcme: true, + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, }, }, } From 8338f720c168b57cbfa552df4563fbd1d3d96a4d Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 8 Dec 2022 17:35:15 +1100 Subject: [PATCH 06/92] refactor: add cronjob to service calculations --- internal/generator/services.go | 41 +++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/internal/generator/services.go b/internal/generator/services.go index 72cd42af..b1d2d44f 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -126,24 +126,6 @@ func composeToServiceValues( if value, ok := lYAML.Environments[buildValues.Environment].Types[composeService]; ok { lagoonType = value } - inpodcronjobs := []lagoon.Cronjob{} - nativecronjobs := []lagoon.Cronjob{} - for _, cronjob := range lYAML.Environments[buildValues.Branch].Cronjobs { - var err error - inpod, err := helpers.IsInPodCronjob(cronjob.Schedule) - if err != nil { - return ServiceValues{}, fmt.Errorf("Unable to validate crontab for cronjob %s: %v", cronjob.Name, err) - } - cronjob.Schedule, err = helpers.ConvertCrontab(buildValues.Namespace, cronjob.Schedule) - if err != nil { - return ServiceValues{}, fmt.Errorf("Unable to convert crontab for cronjob %s: %v", cronjob.Name, err) - } - if inpod { - inpodcronjobs = append(inpodcronjobs, cronjob) - } else { - nativecronjobs = append(nativecronjobs, cronjob) - } - } // check if the service has a specific override serviceAutogenerated := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.autogeneratedroute") if serviceAutogenerated != "" { @@ -207,6 +189,29 @@ func composeToServiceValues( } } + // work out cronjobs for this service + inpodcronjobs := []lagoon.Cronjob{} + nativecronjobs := []lagoon.Cronjob{} + for _, cronjob := range lYAML.Environments[buildValues.Branch].Cronjobs { + // if this cronjob is meant for this service, add it + if cronjob.Service == composeService { + var err error + inpod, err := helpers.IsInPodCronjob(cronjob.Schedule) + if err != nil { + return ServiceValues{}, fmt.Errorf("Unable to validate crontab for cronjob %s: %v", cronjob.Name, err) + } + cronjob.Schedule, err = helpers.ConvertCrontab(buildValues.Namespace, cronjob.Schedule) + if err != nil { + return ServiceValues{}, fmt.Errorf("Unable to convert crontab for cronjob %s: %v", cronjob.Name, err) + } + if inpod { + inpodcronjobs = append(inpodcronjobs, cronjob) + } else { + nativecronjobs = append(nativecronjobs, cronjob) + } + } + } + // if there are overrides defined in the lagoon API `LAGOON_SERVICE_TYPES` // handle those here if buildValues.ServiceTypeOverrides != nil { From de30e41dd0f562c1a4e0e3f3146fb5656992434e Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 8 Dec 2022 17:36:37 +1100 Subject: [PATCH 07/92] refactor: use diff in test outputs to show changes, and support cronjobs in deployments --- go.mod | 2 ++ go.sum | 2 ++ .../backups/template_schedule_test.go | 3 ++- .../templating/dbaas/template_dbaas_test.go | 3 ++- .../ingress/templates_ingress_test.go | 3 ++- .../services/templates_deployment.go | 16 ++++++----- .../services/templates_deployment_test.go | 27 ++++++++++++++++++- .../templating/services/templates_pvc_test.go | 3 ++- .../services/templates_service_test.go | 3 ++- .../deployment/result-basic-1.yaml | 3 +++ 10 files changed, 53 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 93dec25d..eec53b27 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.17 require ( github.com/PaesslerAG/gval v1.1.2 github.com/amazeeio/dbaas-operator v0.3.0 + github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 github.com/compose-spec/compose-go v1.2.7 github.com/cxmcc/unixsums v0.0.0-20131125091133-89564297d82f github.com/google/go-cmp v0.5.7 @@ -39,6 +40,7 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/sergi/go-diff v1.1.0 // indirect github.com/sirupsen/logrus v1.8.1 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/testify v1.7.1 // indirect diff --git a/go.sum b/go.sum index b908b10e..0fdefd6c 100644 --- a/go.sum +++ b/go.sum @@ -91,6 +91,7 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk5 github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/amazeeio/dbaas-operator v0.3.0 h1:+yd0RHp+TSAUMUo6o7f5/ReqIEpVJHqoRDzfsibtSzQ= github.com/amazeeio/dbaas-operator v0.3.0/go.mod h1:fbZuWO1a4JhEJZLrSdOg/+YEzGL6yZcGpfHiIqn72dc= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= @@ -714,6 +715,7 @@ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdh github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/securego/gosec v0.0.0-20191002120514-e680875ea14d/go.mod h1:w5+eXa0mYznDkHaMCXA4XYffjlH+cy1oyKbfzJXa2Do= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shirou/gopsutil v0.0.0-20190901111213-e4ec7b275ada/go.mod h1:WWnYX4lzhCH5h/3YBfyVA3VbLYjlMZZAQcW9ojMexNc= github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc= diff --git a/internal/templating/backups/template_schedule_test.go b/internal/templating/backups/template_schedule_test.go index f9946e9c..76f3981e 100644 --- a/internal/templating/backups/template_schedule_test.go +++ b/internal/templating/backups/template_schedule_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/generator" ) @@ -199,7 +200,7 @@ func TestGenerateBackupSchedule(t *testing.T) { t.Errorf("couldn't read file %v: %v", tt.want, err) } if !reflect.DeepEqual(string(got), string(r1)) { - t.Errorf("GenerateBackupSchedule() = %v, want %v", string(got), string(r1)) + t.Errorf("GenerateBackupSchedule() = \n%v", diff.LineDiff(string(r1), string(got))) } }) } diff --git a/internal/templating/dbaas/template_dbaas_test.go b/internal/templating/dbaas/template_dbaas_test.go index 31774af0..8e4f6c18 100644 --- a/internal/templating/dbaas/template_dbaas_test.go +++ b/internal/templating/dbaas/template_dbaas_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/generator" ) @@ -111,7 +112,7 @@ func TestGenerateDBaaSTemplate(t *testing.T) { t.Errorf("couldn't read file %v: %v", tt.want, err) } if !reflect.DeepEqual(string(got), string(r1)) { - t.Errorf("GenerateDBaaSTemplate() = %v, want %v", string(got), string(r1)) + t.Errorf("GenerateDBaaSTemplate() = \n%v", diff.LineDiff(string(r1), string(got))) } }) } diff --git a/internal/templating/ingress/templates_ingress_test.go b/internal/templating/ingress/templates_ingress_test.go index dc75733a..d2190ff3 100644 --- a/internal/templating/ingress/templates_ingress_test.go +++ b/internal/templating/ingress/templates_ingress_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" @@ -469,7 +470,7 @@ func TestGenerateKubeTemplate(t *testing.T) { t.Errorf("couldn't read file %v: %v", tt.want, err) } if !reflect.DeepEqual(string(got), string(r1)) { - t.Errorf("GenerateIngressTemplate() = %v, want %v", string(got), string(r1)) + t.Errorf("GenerateIngressTemplate() = \n%v", diff.LineDiff(string(r1), string(got))) } } }) diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index 09252c17..584549ec 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -65,6 +65,7 @@ func GenerateDeploymentTemplate( additionalLabels["lagoon.sh/template"] = fmt.Sprintf("%s-%s", serviceTypeValues.Name, "0.1.0") additionalLabels["lagoon.sh/service"] = serviceValues.Name additionalLabels["lagoon.sh/service-type"] = serviceTypeValues.Name + additionalAnnotations["lagoon.sh/configMapSha"] = buildValues.ConfigMapSha if serviceValues.UseSpotInstances { additionalLabels["lagoon.sh/spot"] = "true" @@ -76,7 +77,9 @@ func GenerateDeploymentTemplate( APIVersion: fmt.Sprintf("%s/%s", appsv1.SchemeGroupVersion.Group, appsv1.SchemeGroupVersion.Version), }, ObjectMeta: metav1.ObjectMeta{ - Name: serviceValues.Name, + Name: serviceValues.Name, + Labels: labels, + Annotations: annotations, }, } deployment.ObjectMeta.Labels = labels @@ -108,14 +111,10 @@ func GenerateDeploymentTemplate( // start deployment template depMeta := metav1.ObjectMeta{ - Name: serviceValues.Name, Labels: labels, Annotations: annotations, } deployment.Spec.Template.ObjectMeta = depMeta - - deployment.Spec.Template.ObjectMeta.Annotations["lagoon.sh/configMapSha"] = buildValues.ConfigMapSha - deployment.Spec.Replicas = helpers.Int32Ptr(1) deployment.Spec.Selector = &metav1.LabelSelector{ MatchLabels: map[string]string{ @@ -196,6 +195,11 @@ func GenerateDeploymentTemplate( // handle setting the rest of the containers specs with values from the service or build values container.Container.Name = container.Name container.Container.Image = serviceValues.ImageName + + cronjobs := "" + for _, cronjob := range serviceValues.InPodCronjobs { + cronjobs = fmt.Sprintf("%s%s %s\n", cronjobs, cronjob.Schedule, cronjob.Command) + } container.Container.Env = []corev1.EnvVar{ { Name: "LAGOON_GIT_SHA", @@ -203,7 +207,7 @@ func GenerateDeploymentTemplate( }, { Name: "CRONJOBS", - Value: serviceValues.InPodCronjobs, + Value: cronjobs, }, } diff --git a/internal/templating/services/templates_deployment_test.go b/internal/templating/services/templates_deployment_test.go index d5b72cb7..24800125 100644 --- a/internal/templating/services/templates_deployment_test.go +++ b/internal/templating/services/templates_deployment_test.go @@ -6,6 +6,9 @@ import ( "testing" "github.com/uselagoon/build-deploy-tool/internal/generator" + "github.com/uselagoon/build-deploy-tool/internal/lagoon" + + "github.com/andreyvit/diff" ) func TestGenerateDeploymentTemplate(t *testing.T) { @@ -44,6 +47,28 @@ func TestGenerateDeploymentTemplate(t *testing.T) { Type: "basic", DBaaSEnvironment: "development", ImageName: "harbor.example.com/example-project/environment-with-really-really-reall-3fdb/basic@latest", + InPodCronjobs: []lagoon.Cronjob{ + { + Name: "cron - inpod", + Schedule: "M/5 * * * *", + Command: "drush cron", + Service: "basic", + }, + { + Name: "cron2 - inpod", + Schedule: "M/15 * * * *", + Command: "other cronjob", + Service: "basic", + }, + }, + NativeCronjobs: []lagoon.Cronjob{ + { + Name: "cron3 - native", + Schedule: "35 * * * *", + Command: "drush cron", + Service: "basic", + }, + }, }, // { // Name: "myservice-po", @@ -193,7 +218,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { t.Errorf("couldn't read file %v: %v", tt.want, err) } if !reflect.DeepEqual(string(got), string(r1)) { - t.Errorf("GenerateDeploymentTemplate() = %v, want %v", string(got), string(r1)) + t.Errorf("GenerateDeploymentTemplate() = \n%v", diff.LineDiff(string(r1), string(got))) } }) } diff --git a/internal/templating/services/templates_pvc_test.go b/internal/templating/services/templates_pvc_test.go index 51853190..a463bf52 100644 --- a/internal/templating/services/templates_pvc_test.go +++ b/internal/templating/services/templates_pvc_test.go @@ -5,6 +5,7 @@ import ( "reflect" "testing" + "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/generator" ) @@ -179,7 +180,7 @@ func TestGeneratePVCTemplate(t *testing.T) { t.Errorf("couldn't read file %v: %v", tt.want, err) } if !reflect.DeepEqual(string(got), string(r1)) { - t.Errorf("GeneratePVCTemplate() = %v, want %v", string(got), string(r1)) + t.Errorf("GeneratePVCTemplate() = \n%v", diff.LineDiff(string(r1), string(got))) } }) } diff --git a/internal/templating/services/templates_service_test.go b/internal/templating/services/templates_service_test.go index 8fc1c696..dbf14bd9 100644 --- a/internal/templating/services/templates_service_test.go +++ b/internal/templating/services/templates_service_test.go @@ -5,6 +5,7 @@ import ( "reflect" "testing" + "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/generator" ) @@ -169,7 +170,7 @@ func TestGenerateServiceTemplate(t *testing.T) { t.Errorf("couldn't read file %v: %v", tt.want, err) } if !reflect.DeepEqual(string(got), string(r1)) { - t.Errorf("GenerateServiceTemplate() = %v, want %v", string(got), string(r1)) + t.Errorf("GenerateServiceTemplate() = \n%v", diff.LineDiff(string(r1), string(got))) } }) } diff --git a/internal/templating/services/test-resources/deployment/result-basic-1.yaml b/internal/templating/services/test-resources/deployment/result-basic-1.yaml index 61c8ea4e..10877a3c 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-1.yaml @@ -50,6 +50,9 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + value: | + M/5 * * * * drush cron + M/15 * * * * other cronjob envFrom: - configMapRef: name: lagoon-env From 9717fda1a7903ef59f788fedbcfffa9c461aef76 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 8 Dec 2022 18:09:35 +1100 Subject: [PATCH 08/92] chore: use same lessthan logic in cronjob check as old bash --- internal/helpers/helpers_cron.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/helpers/helpers_cron.go b/internal/helpers/helpers_cron.go index 78405808..0387cb97 100644 --- a/internal/helpers/helpers_cron.go +++ b/internal/helpers/helpers_cron.go @@ -206,7 +206,7 @@ func IsInPodCronjob(cron string) (bool, error) { if err != nil { return false, fmt.Errorf("cron definition '%s' is invalid, unable to determine minutes value", cron) } - if step <= 30 { + if step < 30 { return true, nil } } From 1c3cfd89b2ffb92ee4f5866d91ee710a44b28d0d Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 8 Dec 2022 18:12:13 +1100 Subject: [PATCH 09/92] chore: shorten name of environment for tests --- .../services/templates_deployment_test.go | 26 +++++++++---------- .../templating/services/templates_pvc_test.go | 24 ++++++++--------- .../services/templates_service_test.go | 24 ++++++++--------- .../deployment/result-basic-1.yaml | 10 +++---- .../test-resources/pvc/result-basic-1.yaml | 12 ++++----- .../pvc/result-elasticsearch-1.yaml | 8 +++--- .../pvc/result-opensearch-1.yaml | 8 +++--- .../service/result-basic-1.yaml | 16 ++++++------ .../service/result-elasticsearch-1.yaml | 8 +++--- .../service/result-opensearch-1.yaml | 8 +++--- 10 files changed, 72 insertions(+), 72 deletions(-) diff --git a/internal/templating/services/templates_deployment_test.go b/internal/templating/services/templates_deployment_test.go index 24800125..ea645be7 100644 --- a/internal/templating/services/templates_deployment_test.go +++ b/internal/templating/services/templates_deployment_test.go @@ -26,13 +26,13 @@ func TestGenerateDeploymentTemplate(t *testing.T) { args: args{ buildValues: generator.BuildValues{ Project: "example-project", - Environment: "environment-with-really-really-reall-3fdb", + Environment: "environment-name", EnvironmentType: "production", - Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + Namespace: "myexample-project-environment-name", BuildType: "branch", LagoonVersion: "v2.x.x", Kubernetes: "generator.local", - Branch: "environment-with-really-really-reall-3fdb", + Branch: "environment-name", ImagePullSecrets: []generator.ImagePullSecrets{ { Name: "lagoon-internal-registry-secret", @@ -46,7 +46,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { OverrideName: "myservice", Type: "basic", DBaaSEnvironment: "development", - ImageName: "harbor.example.com/example-project/environment-with-really-really-reall-3fdb/basic@latest", + ImageName: "harbor.example.com/example-project/environment-name/basic@latest", InPodCronjobs: []lagoon.Cronjob{ { Name: "cron - inpod", @@ -116,13 +116,13 @@ func TestGenerateDeploymentTemplate(t *testing.T) { // args: args{ // buildValues: generator.BuildValues{ // Project: "example-project", - // Environment: "environment-with-really-really-reall-3fdb", + // Environment: "environment-name", // EnvironmentType: "production", - // Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + // Namespace: "myexample-project-environment-name", // BuildType: "branch", // LagoonVersion: "v2.x.x", // Kubernetes: "generator.local", - // Branch: "environment-with-really-really-reall-3fdb", + // Branch: "environment-name", // Services: []generator.ServiceValues{ // { // Name: "myservice", @@ -146,13 +146,13 @@ func TestGenerateDeploymentTemplate(t *testing.T) { // args: args{ // buildValues: generator.BuildValues{ // Project: "example-project", - // Environment: "environment-with-really-really-reall-3fdb", + // Environment: "environment-name", // EnvironmentType: "production", - // Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + // Namespace: "myexample-project-environment-name", // BuildType: "branch", // LagoonVersion: "v2.x.x", // Kubernetes: "generator.local", - // Branch: "environment-with-really-really-reall-3fdb", + // Branch: "environment-name", // Services: []generator.ServiceValues{ // { // Name: "myservice", @@ -178,13 +178,13 @@ func TestGenerateDeploymentTemplate(t *testing.T) { // args: args{ // buildValues: generator.BuildValues{ // Project: "example-project", - // Environment: "environment-with-really-really-reall-3fdb", + // Environment: "environment-name", // EnvironmentType: "production", - // Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + // Namespace: "myexample-project-environment-name", // BuildType: "branch", // LagoonVersion: "v2.x.x", // Kubernetes: "generator.local", - // Branch: "environment-with-really-really-reall-3fdb", + // Branch: "environment-name", // Services: []generator.ServiceValues{ // { // Name: "myservice", diff --git a/internal/templating/services/templates_pvc_test.go b/internal/templating/services/templates_pvc_test.go index a463bf52..dd8ceaca 100644 --- a/internal/templating/services/templates_pvc_test.go +++ b/internal/templating/services/templates_pvc_test.go @@ -24,13 +24,13 @@ func TestGeneratePVCTemplate(t *testing.T) { args: args{ buildValues: generator.BuildValues{ Project: "example-project", - Environment: "environment-with-really-really-reall-3fdb", + Environment: "environment-name", EnvironmentType: "production", - Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + Namespace: "myexample-project-environment-name", BuildType: "branch", LagoonVersion: "v2.x.x", Kubernetes: "generator.local", - Branch: "environment-with-really-really-reall-3fdb", + Branch: "environment-name", Services: []generator.ServiceValues{ { Name: "myservice", @@ -78,13 +78,13 @@ func TestGeneratePVCTemplate(t *testing.T) { args: args{ buildValues: generator.BuildValues{ Project: "example-project", - Environment: "environment-with-really-really-reall-3fdb", + Environment: "environment-name", EnvironmentType: "production", - Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + Namespace: "myexample-project-environment-name", BuildType: "branch", LagoonVersion: "v2.x.x", Kubernetes: "generator.local", - Branch: "environment-with-really-really-reall-3fdb", + Branch: "environment-name", Services: []generator.ServiceValues{ { Name: "myservice", @@ -108,13 +108,13 @@ func TestGeneratePVCTemplate(t *testing.T) { args: args{ buildValues: generator.BuildValues{ Project: "example-project", - Environment: "environment-with-really-really-reall-3fdb", + Environment: "environment-name", EnvironmentType: "production", - Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + Namespace: "myexample-project-environment-name", BuildType: "branch", LagoonVersion: "v2.x.x", Kubernetes: "generator.local", - Branch: "environment-with-really-really-reall-3fdb", + Branch: "environment-name", Services: []generator.ServiceValues{ { Name: "myservice", @@ -140,13 +140,13 @@ func TestGeneratePVCTemplate(t *testing.T) { args: args{ buildValues: generator.BuildValues{ Project: "example-project", - Environment: "environment-with-really-really-reall-3fdb", + Environment: "environment-name", EnvironmentType: "production", - Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + Namespace: "myexample-project-environment-name", BuildType: "branch", LagoonVersion: "v2.x.x", Kubernetes: "generator.local", - Branch: "environment-with-really-really-reall-3fdb", + Branch: "environment-name", Services: []generator.ServiceValues{ { Name: "myservice", diff --git a/internal/templating/services/templates_service_test.go b/internal/templating/services/templates_service_test.go index dbf14bd9..06b2350b 100644 --- a/internal/templating/services/templates_service_test.go +++ b/internal/templating/services/templates_service_test.go @@ -24,13 +24,13 @@ func TestGenerateServiceTemplate(t *testing.T) { args: args{ buildValues: generator.BuildValues{ Project: "example-project", - Environment: "environment-with-really-really-reall-3fdb", + Environment: "environment-name", EnvironmentType: "production", - Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + Namespace: "myexample-project-environment-name", BuildType: "branch", LagoonVersion: "v2.x.x", Kubernetes: "generator.local", - Branch: "environment-with-really-really-reall-3fdb", + Branch: "environment-name", Services: []generator.ServiceValues{ { Name: "myservice", @@ -68,13 +68,13 @@ func TestGenerateServiceTemplate(t *testing.T) { args: args{ buildValues: generator.BuildValues{ Project: "example-project", - Environment: "environment-with-really-really-reall-3fdb", + Environment: "environment-name", EnvironmentType: "production", - Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + Namespace: "myexample-project-environment-name", BuildType: "branch", LagoonVersion: "v2.x.x", Kubernetes: "generator.local", - Branch: "environment-with-really-really-reall-3fdb", + Branch: "environment-name", Services: []generator.ServiceValues{ { Name: "myservice", @@ -98,13 +98,13 @@ func TestGenerateServiceTemplate(t *testing.T) { args: args{ buildValues: generator.BuildValues{ Project: "example-project", - Environment: "environment-with-really-really-reall-3fdb", + Environment: "environment-name", EnvironmentType: "production", - Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + Namespace: "myexample-project-environment-name", BuildType: "branch", LagoonVersion: "v2.x.x", Kubernetes: "generator.local", - Branch: "environment-with-really-really-reall-3fdb", + Branch: "environment-name", Services: []generator.ServiceValues{ { Name: "myservice", @@ -130,13 +130,13 @@ func TestGenerateServiceTemplate(t *testing.T) { args: args{ buildValues: generator.BuildValues{ Project: "example-project", - Environment: "environment-with-really-really-reall-3fdb", + Environment: "environment-name", EnvironmentType: "production", - Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + Namespace: "myexample-project-environment-name", BuildType: "branch", LagoonVersion: "v2.x.x", Kubernetes: "generator.local", - Branch: "environment-with-really-really-reall-3fdb", + Branch: "environment-name", Services: []generator.ServiceValues{ { Name: "myservice", diff --git a/internal/templating/services/test-resources/deployment/result-basic-1.yaml b/internal/templating/services/test-resources/deployment/result-basic-1.yaml index 10877a3c..8d333af6 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-1.yaml @@ -3,7 +3,7 @@ apiVersion: apps/v1 kind: Deployment metadata: annotations: - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null @@ -12,7 +12,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: basic lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice @@ -29,7 +29,7 @@ spec: template: metadata: annotations: - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null @@ -38,7 +38,7 @@ spec: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: basic lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice @@ -56,7 +56,7 @@ spec: envFrom: - configMapRef: name: lagoon-env - image: harbor.example.com/example-project/environment-with-really-really-reall-3fdb/basic@latest + image: harbor.example.com/example-project/environment-name/basic@latest livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/templating/services/test-resources/pvc/result-basic-1.yaml b/internal/templating/services/test-resources/pvc/result-basic-1.yaml index f98b50af..8d51a81c 100644 --- a/internal/templating/services/test-resources/pvc/result-basic-1.yaml +++ b/internal/templating/services/test-resources/pvc/result-basic-1.yaml @@ -4,7 +4,7 @@ metadata: annotations: k8up.io/backup: "true" k8up.syn.tools/backup: "true" - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -12,7 +12,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: basic-persistent lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-persist @@ -33,7 +33,7 @@ metadata: annotations: k8up.io/backup: "true" k8up.syn.tools/backup: "true" - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -41,7 +41,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: basic-persistent lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-persist-po @@ -62,7 +62,7 @@ metadata: annotations: k8up.io/backup: "true" k8up.syn.tools/backup: "true" - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -70,7 +70,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: basic-persistent lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-persist-po diff --git a/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml index 32e55c91..d8d3e7a7 100644 --- a/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml +++ b/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml @@ -4,7 +4,7 @@ metadata: annotations: k8up.io/backup: "false" k8up.syn.tools/backup: "false" - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -12,7 +12,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: elasticsearch lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice @@ -33,7 +33,7 @@ metadata: annotations: k8up.io/backup: "false" k8up.syn.tools/backup: "false" - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -41,7 +41,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: elasticsearch lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-size diff --git a/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml b/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml index 70f8e7ac..755899df 100644 --- a/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml @@ -4,7 +4,7 @@ metadata: annotations: k8up.io/backup: "false" k8up.syn.tools/backup: "false" - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -12,7 +12,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: opensearch lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice @@ -33,7 +33,7 @@ metadata: annotations: k8up.io/backup: "false" k8up.syn.tools/backup: "false" - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -41,7 +41,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: opensearch lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-size diff --git a/internal/templating/services/test-resources/service/result-basic-1.yaml b/internal/templating/services/test-resources/service/result-basic-1.yaml index 5cbd475b..081a19e5 100644 --- a/internal/templating/services/test-resources/service/result-basic-1.yaml +++ b/internal/templating/services/test-resources/service/result-basic-1.yaml @@ -2,7 +2,7 @@ apiVersion: v1 metadata: annotations: - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -10,7 +10,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: basic lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice @@ -32,7 +32,7 @@ status: apiVersion: v1 metadata: annotations: - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -40,7 +40,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: basic lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-po @@ -62,7 +62,7 @@ status: apiVersion: v1 metadata: annotations: - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -70,7 +70,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: basic-persistent lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-persist @@ -92,7 +92,7 @@ status: apiVersion: v1 metadata: annotations: - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -100,7 +100,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: basic-persistent lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-persist-po diff --git a/internal/templating/services/test-resources/service/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/service/result-elasticsearch-1.yaml index c8de14c5..155e2f8a 100644 --- a/internal/templating/services/test-resources/service/result-elasticsearch-1.yaml +++ b/internal/templating/services/test-resources/service/result-elasticsearch-1.yaml @@ -2,7 +2,7 @@ apiVersion: v1 metadata: annotations: - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -10,7 +10,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: elasticsearch lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice @@ -32,7 +32,7 @@ status: apiVersion: v1 metadata: annotations: - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -40,7 +40,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: elasticsearch lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-size diff --git a/internal/templating/services/test-resources/service/result-opensearch-1.yaml b/internal/templating/services/test-resources/service/result-opensearch-1.yaml index 5abaf744..2f75334c 100644 --- a/internal/templating/services/test-resources/service/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/service/result-opensearch-1.yaml @@ -2,7 +2,7 @@ apiVersion: v1 metadata: annotations: - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -10,7 +10,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: opensearch lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice @@ -32,7 +32,7 @@ status: apiVersion: v1 metadata: annotations: - lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/branch: environment-name lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -40,7 +40,7 @@ metadata: app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: opensearch lagoon.sh/buildType: branch - lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-size From 3bb037d7667232838918c8d6cda37615082bbeb3 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 8 Dec 2022 18:18:10 +1100 Subject: [PATCH 10/92] fix: kind in templates --- internal/templating/services/templates_pvc.go | 2 +- internal/templating/services/templates_service.go | 2 +- .../services/test-resources/pvc/result-basic-1.yaml | 3 +++ .../services/test-resources/pvc/result-elasticsearch-1.yaml | 2 ++ .../services/test-resources/pvc/result-opensearch-1.yaml | 2 ++ .../services/test-resources/service/result-basic-1.yaml | 4 ++++ .../test-resources/service/result-elasticsearch-1.yaml | 2 ++ .../services/test-resources/service/result-opensearch-1.yaml | 2 ++ 8 files changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/templating/services/templates_pvc.go b/internal/templating/services/templates_pvc.go index 5025f17b..8bc6aa97 100644 --- a/internal/templating/services/templates_pvc.go +++ b/internal/templating/services/templates_pvc.go @@ -71,7 +71,7 @@ func GeneratePVCTemplate( pvc := &corev1.PersistentVolumeClaim{ TypeMeta: metav1.TypeMeta{ - Kind: corev1.SchemeGroupVersion.Group, + Kind: "PersistentVolumeClaim", APIVersion: corev1.SchemeGroupVersion.Version, }, ObjectMeta: metav1.ObjectMeta{ diff --git a/internal/templating/services/templates_service.go b/internal/templating/services/templates_service.go index 5d3959db..24113b8d 100644 --- a/internal/templating/services/templates_service.go +++ b/internal/templating/services/templates_service.go @@ -63,7 +63,7 @@ func GenerateServiceTemplate( additionalLabels["lagoon.sh/service-type"] = serviceType.Name service := &corev1.Service{ TypeMeta: metav1.TypeMeta{ - Kind: corev1.SchemeGroupVersion.Group, + Kind: "Service", APIVersion: corev1.SchemeGroupVersion.Version, }, ObjectMeta: metav1.ObjectMeta{ diff --git a/internal/templating/services/test-resources/pvc/result-basic-1.yaml b/internal/templating/services/test-resources/pvc/result-basic-1.yaml index 8d51a81c..a1a33ca4 100644 --- a/internal/templating/services/test-resources/pvc/result-basic-1.yaml +++ b/internal/templating/services/test-resources/pvc/result-basic-1.yaml @@ -1,5 +1,6 @@ --- apiVersion: v1 +kind: PersistentVolumeClaim metadata: annotations: k8up.io/backup: "true" @@ -29,6 +30,7 @@ spec: status: {} --- apiVersion: v1 +kind: PersistentVolumeClaim metadata: annotations: k8up.io/backup: "true" @@ -58,6 +60,7 @@ spec: status: {} --- apiVersion: v1 +kind: PersistentVolumeClaim metadata: annotations: k8up.io/backup: "true" diff --git a/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml index d8d3e7a7..4e14e632 100644 --- a/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml +++ b/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml @@ -1,5 +1,6 @@ --- apiVersion: v1 +kind: PersistentVolumeClaim metadata: annotations: k8up.io/backup: "false" @@ -29,6 +30,7 @@ spec: status: {} --- apiVersion: v1 +kind: PersistentVolumeClaim metadata: annotations: k8up.io/backup: "false" diff --git a/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml b/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml index 755899df..b4ae8aa1 100644 --- a/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml @@ -1,5 +1,6 @@ --- apiVersion: v1 +kind: PersistentVolumeClaim metadata: annotations: k8up.io/backup: "false" @@ -29,6 +30,7 @@ spec: status: {} --- apiVersion: v1 +kind: PersistentVolumeClaim metadata: annotations: k8up.io/backup: "false" diff --git a/internal/templating/services/test-resources/service/result-basic-1.yaml b/internal/templating/services/test-resources/service/result-basic-1.yaml index 081a19e5..5d37a453 100644 --- a/internal/templating/services/test-resources/service/result-basic-1.yaml +++ b/internal/templating/services/test-resources/service/result-basic-1.yaml @@ -1,5 +1,6 @@ --- apiVersion: v1 +kind: Service metadata: annotations: lagoon.sh/branch: environment-name @@ -30,6 +31,7 @@ status: loadBalancer: {} --- apiVersion: v1 +kind: Service metadata: annotations: lagoon.sh/branch: environment-name @@ -60,6 +62,7 @@ status: loadBalancer: {} --- apiVersion: v1 +kind: Service metadata: annotations: lagoon.sh/branch: environment-name @@ -90,6 +93,7 @@ status: loadBalancer: {} --- apiVersion: v1 +kind: Service metadata: annotations: lagoon.sh/branch: environment-name diff --git a/internal/templating/services/test-resources/service/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/service/result-elasticsearch-1.yaml index 155e2f8a..c37f801e 100644 --- a/internal/templating/services/test-resources/service/result-elasticsearch-1.yaml +++ b/internal/templating/services/test-resources/service/result-elasticsearch-1.yaml @@ -1,5 +1,6 @@ --- apiVersion: v1 +kind: Service metadata: annotations: lagoon.sh/branch: environment-name @@ -30,6 +31,7 @@ status: loadBalancer: {} --- apiVersion: v1 +kind: Service metadata: annotations: lagoon.sh/branch: environment-name diff --git a/internal/templating/services/test-resources/service/result-opensearch-1.yaml b/internal/templating/services/test-resources/service/result-opensearch-1.yaml index 2f75334c..7f530e35 100644 --- a/internal/templating/services/test-resources/service/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/service/result-opensearch-1.yaml @@ -1,5 +1,6 @@ --- apiVersion: v1 +kind: Service metadata: annotations: lagoon.sh/branch: environment-name @@ -30,6 +31,7 @@ status: loadBalancer: {} --- apiVersion: v1 +kind: Service metadata: annotations: lagoon.sh/branch: environment-name From 0558aae72672df0c20d47155afc0ec44d77f03b3 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 8 Dec 2022 19:09:02 +1100 Subject: [PATCH 11/92] chore: add support for generating spot instance values --- internal/generator/buildvalues.go | 46 +++++++++----------- internal/generator/services.go | 66 ++++++++++++++++++++++++++++- internal/generator/services_test.go | 49 ++++++++++++++++++++- 3 files changed, 134 insertions(+), 27 deletions(-) diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index 274ace7a..abb750b4 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -3,7 +3,6 @@ package generator import ( "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/lagoon" - corev1 "k8s.io/api/core/v1" ) // BuildValues is the values file data generated by the lagoon build @@ -87,30 +86,27 @@ type DynamicSecret struct { // ServiceValues is the values for a specific service used by a lagoon build type ServiceValues struct { - Name string `json:"name"` // this is the actual compose service name - OverrideName string `json:"overrideName"` // if an override name is provided, use it - Type string `json:"type"` - AutogeneratedRoutesEnabled bool `json:"autogeneratedRoutesEnabled"` - AutogeneratedRoutesTLSAcme bool `json:"autogeneratedRoutesTLSAcme"` - AutogeneratedRouteDomain string `json:"autogeneratedRouteDomain"` - ShortAutogeneratedRouteDomain string `json:"shortAutogeneratedRouteDomain"` - DBaaSEnvironment string `json:"dbaasEnvironment"` - NativeCronjobs []lagoon.Cronjob `json:"nativeCronjobs"` - InPodCronjobs []lagoon.Cronjob `json:"inPodCronjobs"` - ImageName string `json:"imageName"` - DeploymentServiceType string `json:"deploymentServiecType"` - ServicePort int32 `json:"servicePort,omitempty"` - PersistentVolumePath string `json:"persistentVolumePath,omitempty"` - PersistentVolumeName string `json:"persistentVolumeName,omitempty"` - PersistentVolumeSize string `json:"persistentVolumeSize,omitempty"` - UseSpotInstances bool `json:"useSpot"` - NodeSelectors *map[string]string `json:"nodeSelectors"` - Tolerations *[]corev1.Toleration `json:"tolerations"` - Affinity *corev1.Affinity `json:"affinity"` - CronjobUseSpotInstances bool `json:"cronjobUseSpot"` - CronjobNodeSelectors *map[string]string `json:"cronjobNodeSelectors"` - CronjobTolerations *[]corev1.Toleration `json:"cronjobTolerations"` - CronjobAffinity *corev1.Affinity `json:"cronjobAffinity"` + Name string `json:"name"` // this is the actual compose service name + OverrideName string `json:"overrideName"` // if an override name is provided, use it + Type string `json:"type"` + AutogeneratedRoutesEnabled bool `json:"autogeneratedRoutesEnabled"` + AutogeneratedRoutesTLSAcme bool `json:"autogeneratedRoutesTLSAcme"` + AutogeneratedRouteDomain string `json:"autogeneratedRouteDomain"` + ShortAutogeneratedRouteDomain string `json:"shortAutogeneratedRouteDomain"` + DBaaSEnvironment string `json:"dbaasEnvironment"` + NativeCronjobs []lagoon.Cronjob `json:"nativeCronjobs"` + InPodCronjobs []lagoon.Cronjob `json:"inPodCronjobs"` + ImageName string `json:"imageName"` + DeploymentServiceType string `json:"deploymentServiceType"` + ServicePort int32 `json:"servicePort,omitempty"` + PersistentVolumePath string `json:"persistentVolumePath,omitempty"` + PersistentVolumeName string `json:"persistentVolumeName,omitempty"` + PersistentVolumeSize string `json:"persistentVolumeSize,omitempty"` + UseSpotInstances bool `json:"useSpot"` + ForceSpotInstances bool `json:"forceUseSpot"` + CronjobUseSpotInstances bool `json:"cronjobUseSpot"` + CronjobForceSpotInstances bool `json:"cronjobForceUseSpot"` + Replicas int32 `json:"replicas"` } // CronjobValues is the values for cronjobs diff --git a/internal/generator/services.go b/internal/generator/services.go index b1d2d44f..33321af1 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -63,7 +63,7 @@ func generateServicesFromDockerCompose( for _, service := range lComposeOrder { for _, composeServiceValues := range lCompose.Services { if service.Name == composeServiceValues.Name { - cService, err := composeToServiceValues(buildValues, lYAML, composeServiceValues.Name, composeServiceValues, debug) + cService, err := composeToServiceValues(buildValues, lagoonEnvVars, lYAML, composeServiceValues.Name, composeServiceValues, debug) if err != nil { return err } @@ -79,6 +79,7 @@ func generateServicesFromDockerCompose( // this is the "known state" of that service, and all subsequent steps to create templates will use this data unmodified func composeToServiceValues( buildValues *BuildValues, + lagoonEnvVars []lagoon.EnvironmentVariable, lYAML *lagoon.YAML, composeService string, composeServiceValues composetypes.ServiceConfig, @@ -291,6 +292,64 @@ func composeToServiceValues( } } + // start spot instance handling + useSpot := false + forceSpot := false + cronjobUseSpot := false + cronjobForceSpot := false + spotTypes := "" + cronjobSpotTypes := "" + spotReplicas := int32(0) + + // these services can support multiple replicas in production + // @TODO this should probably be an admin only feature flag though + spotReplicaTypes := "nginx,nginx-persistent,nginx-php,nginx-php-persistent" + // spotReplicaTypes := CheckAdminFeatureFlag("SPOT_REPLICAS_PRODUCTION", lagoonEnvVars, debug) // doesn't exist yet + + productionSpot := CheckFeatureFlag("SPOT_INSTANCE_PRODUCTION", lagoonEnvVars, debug) + developmentSpot := CheckFeatureFlag("SPOT_INSTANCE_DEVELOPMENT", lagoonEnvVars, debug) + if productionSpot == "enabled" && buildValues.EnvironmentType == "production" { + spotTypes = CheckFeatureFlag("SPOT_INSTANCE_PRODUCTION_TYPES", lagoonEnvVars, debug) + cronjobSpotTypes = CheckFeatureFlag("SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES", lagoonEnvVars, debug) + } + if developmentSpot == "enabled" && buildValues.EnvironmentType == "development" { + spotTypes = CheckFeatureFlag("SPOT_INSTANCE_DEVELOPMENT_TYPES", lagoonEnvVars, debug) + cronjobSpotTypes = CheckFeatureFlag("SPOT_INSTANCE_DEVELOPMENT_CRONJOB_TYPES", lagoonEnvVars, debug) + } + // check if the provided spot instance types against the current lagoonType + for _, t := range strings.Split(spotTypes, ",") { + if t != "" { + tt := strings.Split(t, ":") + if tt[0] == lagoonType { + useSpot = true + if tt[1] == "force" { + forceSpot = true + } + } + } + } + // check if the provided cronjob spot instance types against the current lagoonType + for _, t := range strings.Split(cronjobSpotTypes, ",") { + if t != "" { + tt := strings.Split(t, ":") + if tt[0] == lagoonType { + cronjobUseSpot = true + if tt[1] == "force" { + cronjobForceSpot = true + } + } + } + } + // check if the this service is production and can support 2 replicas on spot + for _, t := range strings.Split(spotReplicaTypes, ",") { + if t != "" { + if t == lagoonType && buildValues.EnvironmentType == "production" { + spotReplicas = 2 + } + } + } + // end spot instance handling + // check if this service is one that supports autogenerated routes if !helpers.Contains(supportedAutogeneratedTypes, lagoonType) { autogenEnabled = false @@ -308,6 +367,11 @@ func composeToServiceValues( PersistentVolumePath: servicePersistentPath, PersistentVolumeName: servicePersistentName, PersistentVolumeSize: servicePersistentSize, + UseSpotInstances: useSpot, + ForceSpotInstances: forceSpot, + CronjobUseSpotInstances: cronjobUseSpot, + CronjobForceSpotInstances: cronjobForceSpot, + Replicas: spotReplicas, InPodCronjobs: inpodcronjobs, NativeCronjobs: nativecronjobs, } diff --git a/internal/generator/services_test.go b/internal/generator/services_test.go index 8649589d..9239744d 100644 --- a/internal/generator/services_test.go +++ b/internal/generator/services_test.go @@ -18,6 +18,7 @@ func Test_composeToServiceValues(t *testing.T) { buildValues *BuildValues composeService string composeServiceValues composetypes.ServiceConfig + lagoonEnvVars []lagoon.EnvironmentVariable } tests := []struct { name string @@ -481,6 +482,52 @@ func Test_composeToServiceValues(t *testing.T) { NativeCronjobs: []lagoon.Cronjob{}, }, }, + { + name: "test14 - spot instances", + args: args{ + lYAML: &lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{}, + }, + }, + buildValues: &BuildValues{ + Environment: "main", + EnvironmentType: "production", + Branch: "main", + BuildType: "branch", + ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + }, + composeService: "nginx", + composeServiceValues: composetypes.ServiceConfig{ + Labels: composetypes.Labels{ + "lagoon.type": "nginx", + }, + }, + lagoonEnvVars: []lagoon.EnvironmentVariable{ + {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION", Value: "enabled", Scope: "global"}, + {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT", Value: "enabled", Scope: "global"}, + {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_TYPES", Value: "nginx:force,nginx-php-persistent,basic", Scope: "global"}, + {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"}, + {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES", Value: "nginx:force,nginx-php-persistent,basic", Scope: "global"}, + {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT_CRONJOB_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"}, + }, + }, + want: ServiceValues{ + Name: "nginx", + OverrideName: "nginx", + Type: "nginx", + DBaaSEnvironment: "production", + AutogeneratedRoutesEnabled: true, + AutogeneratedRoutesTLSAcme: true, + UseSpotInstances: true, + CronjobUseSpotInstances: true, + ForceSpotInstances: true, + CronjobForceSpotInstances: true, + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, + Replicas: 2, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -492,7 +539,7 @@ func Test_composeToServiceValues(t *testing.T) { RetryWaitMin: time.Duration(10) * time.Millisecond, RetryWaitMax: time.Duration(50) * time.Millisecond, }) - got, err := composeToServiceValues(tt.args.buildValues, tt.args.lYAML, tt.args.composeService, tt.args.composeServiceValues, false) + got, err := composeToServiceValues(tt.args.buildValues, tt.args.lagoonEnvVars, tt.args.lYAML, tt.args.composeService, tt.args.composeServiceValues, false) if (err != nil) != tt.wantErr { t.Errorf("composeToServiceValues() error = %v, wantErr %v", err, tt.wantErr) return From ff3355f1e6e5effabcf934993bfea444c4f04310 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 8 Dec 2022 19:09:25 +1100 Subject: [PATCH 12/92] chore: update tests for deployment with spot instances --- .../services/templates_deployment.go | 61 ++++++++---- .../services/templates_deployment_test.go | 39 ++++---- .../deployment/result-basic-1.yaml | 96 ++++++++++++++++++- 3 files changed, 159 insertions(+), 37 deletions(-) diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index 584549ec..0edf0c92 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -67,10 +67,6 @@ func GenerateDeploymentTemplate( additionalLabels["lagoon.sh/service-type"] = serviceTypeValues.Name additionalAnnotations["lagoon.sh/configMapSha"] = buildValues.ConfigMapSha - if serviceValues.UseSpotInstances { - additionalLabels["lagoon.sh/spot"] = "true" - } - deployment := &appsv1.Deployment{ TypeMeta: metav1.TypeMeta{ Kind: "Deployment", @@ -84,6 +80,46 @@ func GenerateDeploymentTemplate( } deployment.ObjectMeta.Labels = labels deployment.ObjectMeta.Annotations = annotations + + if serviceValues.UseSpotInstances { + // handle spot instance label and affinity/tolerations/selectors + additionalLabels["lagoon.sh/spot"] = "true" + deployment.Spec.Template.Spec.Affinity = &corev1.Affinity{ + NodeAffinity: &corev1.NodeAffinity{ + PreferredDuringSchedulingIgnoredDuringExecution: []corev1.PreferredSchedulingTerm{ + { + Weight: 1, + Preference: corev1.NodeSelectorTerm{ + MatchExpressions: []corev1.NodeSelectorRequirement{ + { + Key: "lagoon.sh/spot", + Operator: corev1.NodeSelectorOpExists, + }, + }, + }, + }, + }, + }, + } + deployment.Spec.Template.Spec.Tolerations = []corev1.Toleration{ + { + Key: "lagoon.sh/spot", + Operator: corev1.TolerationOpExists, + Effect: corev1.TaintEffectNoSchedule, + }, + { + Key: "lagoon.sh/spot", + Operator: corev1.TolerationOpExists, + Effect: corev1.TaintEffectPreferNoSchedule, + }, + } + if serviceValues.ForceSpotInstances { + deployment.Spec.Template.Spec.NodeSelector = map[string]string{ + "lagoon.sh/spot": "true", + } + } + } + for key, value := range additionalLabels { deployment.ObjectMeta.Labels[key] = value } @@ -116,6 +152,9 @@ func GenerateDeploymentTemplate( } deployment.Spec.Template.ObjectMeta = depMeta deployment.Spec.Replicas = helpers.Int32Ptr(1) + if serviceValues.Replicas != 0 { + deployment.Spec.Replicas = &serviceValues.Replicas + } deployment.Spec.Selector = &metav1.LabelSelector{ MatchLabels: map[string]string{ "app.kubernetes.io/name": serviceTypeValues.Name, @@ -164,20 +203,6 @@ func GenerateDeploymentTemplate( } deployment.Spec.Template.Spec.ImagePullSecrets = pullsecrets - // handle node selectors, tolerations, and affinity configuration - if serviceValues.NodeSelectors != nil { - deployment.Spec.Template.Spec.NodeSelector = *serviceValues.NodeSelectors - } - if serviceValues.Tolerations != nil { - deployment.Spec.Template.Spec.Tolerations = *serviceValues.Tolerations - } - deployment.Spec.Template.Spec.Affinity = serviceValues.Affinity - if serviceTypeValues.PodSecurityContext.HasDefault { - deployment.Spec.Template.Spec.SecurityContext = &corev1.PodSecurityContext{ - FSGroup: &serviceTypeValues.PodSecurityContext.FSGroup, - } - } - // start working out the containers to add container := serviceTypeValues.PrimaryContainer // if the service can change the port diff --git a/internal/templating/services/templates_deployment_test.go b/internal/templating/services/templates_deployment_test.go index ea645be7..f6d70324 100644 --- a/internal/templating/services/templates_deployment_test.go +++ b/internal/templating/services/templates_deployment_test.go @@ -45,8 +45,8 @@ func TestGenerateDeploymentTemplate(t *testing.T) { Name: "myservice", OverrideName: "myservice", Type: "basic", - DBaaSEnvironment: "development", - ImageName: "harbor.example.com/example-project/environment-name/basic@latest", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/myservice@latest", InPodCronjobs: []lagoon.Cronjob{ { Name: "cron - inpod", @@ -70,18 +70,21 @@ func TestGenerateDeploymentTemplate(t *testing.T) { }, }, }, - // { - // Name: "myservice-po", - // OverrideName: "myservice-po", - // Type: "basic", - // DBaaSEnvironment: "development", - // ServicePort: 8080, - // }, + { + Name: "myservice-po", + OverrideName: "myservice-po", + Type: "basic", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/myservice-po@latest", + ServicePort: 8080, // template should have port changed to 8080 from 3000 + UseSpotInstances: true, // template should have spot instance label and toleration/selector/affinity + Replicas: 2, + }, // { // Name: "myservice-persist", // OverrideName: "myservice-persist", // Type: "basic-persistent", - // DBaaSEnvironment: "development", + // DBaaSEnvironment: "production", // PersistentVolumeSize: "5Gi", // PersistentVolumePath: "/storage/data", // PersistentVolumeName: "basic", @@ -90,7 +93,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { // Name: "myservice-persist-po", // OverrideName: "myservice-persist-po", // Type: "basic-persistent", - // DBaaSEnvironment: "development", + // DBaaSEnvironment: "production", // ServicePort: 8080, // PersistentVolumeSize: "5Gi", // PersistentVolumePath: "/storage/data", @@ -100,7 +103,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { // Name: "myservice-persist-po", // OverrideName: "myservice-persist-po", // Type: "basic-persistent", - // DBaaSEnvironment: "development", + // DBaaSEnvironment: "production", // ServicePort: 8080, // PersistentVolumeSize: "100Gi", // PersistentVolumePath: "/storage/data", @@ -128,13 +131,13 @@ func TestGenerateDeploymentTemplate(t *testing.T) { // Name: "myservice", // OverrideName: "myservice", // Type: "cli", - // DBaaSEnvironment: "development", + // DBaaSEnvironment: "production", // }, // { // Name: "myservice-persist", // OverrideName: "myservice-persist", // Type: "cli-persistent", - // DBaaSEnvironment: "development", + // DBaaSEnvironment: "production", // }, // }, // }, @@ -158,14 +161,14 @@ func TestGenerateDeploymentTemplate(t *testing.T) { // Name: "myservice", // OverrideName: "myservice", // Type: "elasticsearch", - // DBaaSEnvironment: "development", + // DBaaSEnvironment: "production", // PersistentVolumeSize: "5Gi", // }, // { // Name: "myservice-size", // OverrideName: "myservice-size", // Type: "elasticsearch", - // DBaaSEnvironment: "development", + // DBaaSEnvironment: "production", // PersistentVolumeSize: "100Gi", // }, // }, @@ -190,14 +193,14 @@ func TestGenerateDeploymentTemplate(t *testing.T) { // Name: "myservice", // OverrideName: "myservice", // Type: "opensearch", - // DBaaSEnvironment: "development", + // DBaaSEnvironment: "production", // PersistentVolumeSize: "5Gi", // }, // { // Name: "myservice-size", // OverrideName: "myservice-size", // Type: "opensearch", - // DBaaSEnvironment: "development", + // DBaaSEnvironment: "production", // PersistentVolumeSize: "100Gi", // }, // }, diff --git a/internal/templating/services/test-resources/deployment/result-basic-1.yaml b/internal/templating/services/test-resources/deployment/result-basic-1.yaml index 8d333af6..8a812a1a 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-1.yaml @@ -56,7 +56,7 @@ spec: envFrom: - configMapRef: name: lagoon-env - image: harbor.example.com/example-project/environment-name/basic@latest + image: harbor.example.com/example-project/environment-name/myservice@latest livenessProbe: initialDelaySeconds: 60 tcpSocket: @@ -78,3 +78,97 @@ spec: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production status: {} +--- +apiVersion: apps/v1 +kind: Deployment +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-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-po + lagoon.sh/service-type: basic + lagoon.sh/spot: "true" + lagoon.sh/template: basic-0.1.0 + name: myservice-po +spec: + replicas: 2 + selector: + matchLabels: + app.kubernetes.io/instance: myservice-po + app.kubernetes.io/name: basic + strategy: {} + 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-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-po + lagoon.sh/service-type: basic + lagoon.sh/spot: "true" + lagoon.sh/template: basic-0.1.0 + spec: + affinity: + nodeAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - preference: + matchExpressions: + - key: lagoon.sh/spot + operator: Exists + weight: 1 + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice-po@latest + 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: {} + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + tolerations: + - effect: NoSchedule + key: lagoon.sh/spot + operator: Exists + - effect: PreferNoSchedule + key: lagoon.sh/spot + operator: Exists +status: {} From 6a6feab7012919810d103d8aa7c8304797c528ff Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 8 Dec 2022 19:18:44 +1100 Subject: [PATCH 13/92] test: add test for lagoon.yml cronjob --- internal/lagoon/lagoon_test.go | 32 +++++++++++++++++++++ test-resources/lagoon-yaml/test5/lagoon.yml | 15 ++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test-resources/lagoon-yaml/test5/lagoon.yml diff --git a/internal/lagoon/lagoon_test.go b/internal/lagoon/lagoon_test.go index 49a58b04..6c9ddacd 100644 --- a/internal/lagoon/lagoon_test.go +++ b/internal/lagoon/lagoon_test.go @@ -258,6 +258,38 @@ func TestUnmarshalLagoonYAML(t *testing.T) { }, }, }, + { + name: "test-cronjobs", + args: args{ + file: "../../test-resources/lagoon-yaml/test5/lagoon.yml", + l: &YAML{}, + p: &map[string]interface{}{}, + }, + 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: "*/15 * * * *", + }, + }, + }, + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/test-resources/lagoon-yaml/test5/lagoon.yml b/test-resources/lagoon-yaml/test5/lagoon.yml new file mode 100644 index 00000000..d6829f3c --- /dev/null +++ b/test-resources/lagoon-yaml/test5/lagoon.yml @@ -0,0 +1,15 @@ +--- +docker-compose-yaml: docker-compose.yml + +project: content-example-com + +environments: + main: + cronjobs: + - name: drush cron + schedule: "*/15 * * * *" + command: 'drush cron' + service: cli + routes: + - nginx: + - a.example.com From b946772aca100fa845a7e9ef08eb4590bc0cdc01 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 9 Dec 2022 09:58:34 +1100 Subject: [PATCH 14/92] refactor: move polysite handling into lagoon unmarshal function --- internal/generator/generator.go | 17 ++--------------- internal/lagoon/lagoon.go | 19 ++++++++++++++++--- internal/lagoon/lagoon_test.go | 13 ++++--------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 9f1aebcb..7ea70697 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -251,29 +251,16 @@ func NewGenerator( func LoadAndUnmarshalLagoonYml(lagoonYml string, lagoonYmlOverride string, lagoonYmlOverrideEnvVarName string, lYAML *lagoon.YAML, projectName string, debug bool) error { // First we load the primary file - lPolysite := make(map[string]interface{}) - if err := lagoon.UnmarshalLagoonYAML(lagoonYml, lYAML, &lPolysite); err != nil { + if err := lagoon.UnmarshalLagoonYAML(lagoonYml, lYAML, projectName); err != nil { return fmt.Errorf("couldn't unmarshal file %v: %v", lagoonYml, err) } - // if this is a polysite, then unmarshal the polysite data into a normal lagoon environments yaml - // this is done so that all other generators only need to know how to interact with one type of environment - if _, ok := lPolysite[projectName]; ok { - s, _ := yaml.Marshal(lPolysite[projectName]) - _ = yaml.Unmarshal(s, &lYAML) - } - // Here we try and merge in .lagoon.yml override if _, err := os.Stat(lagoonYmlOverride); err == nil { overLagoonYaml := &lagoon.YAML{} - overLEnvLagoonPolysite := make(map[string]interface{}) - if err := lagoon.UnmarshalLagoonYAML(lagoonYmlOverride, overLagoonYaml, &overLEnvLagoonPolysite); err != nil { + if err := lagoon.UnmarshalLagoonYAML(lagoonYmlOverride, overLagoonYaml, projectName); err != nil { return fmt.Errorf("couldn't unmarshal file %v: %v", lagoonYmlOverride, err) } - if _, ok := overLEnvLagoonPolysite[projectName]; ok { - s, _ := yaml.Marshal(overLEnvLagoonPolysite[projectName]) - _ = yaml.Unmarshal(s, &overLagoonYaml) - } //now we merge if err := lagoon.MergeLagoonYAMLs(lYAML, overLagoonYaml); err != nil { return fmt.Errorf("unable to merge %v over %v: %v", lagoonYmlOverride, lagoonYml, err) diff --git a/internal/lagoon/lagoon.go b/internal/lagoon/lagoon.go index 77d61cd4..46c71c30 100644 --- a/internal/lagoon/lagoon.go +++ b/internal/lagoon/lagoon.go @@ -128,7 +128,7 @@ func (a *Routes) UnmarshalJSON(data []byte) error { } // UnmarshalLagoonYAML unmarshal the lagoon.yml file into a YAML and map for consumption. -func UnmarshalLagoonYAML(file string, l *YAML, p *map[string]interface{}) error { +func UnmarshalLagoonYAML(file string, l *YAML, project string) error { rawYAML, err := os.ReadFile(file) if err != nil { return fmt.Errorf("couldn't read %v: %v", file, err) @@ -138,11 +138,24 @@ func UnmarshalLagoonYAML(file string, l *YAML, p *map[string]interface{}) error if err != nil { return err } - // polysite - err = yaml.Unmarshal(rawYAML, p) + + // if this is a polysite, then unmarshal the polysite data into a normal lagoon environments yaml + // this is done so that all other generators only need to know how to interact with one type of environment + p := map[string]interface{}{} + err = yaml.Unmarshal(rawYAML, &p) if err != nil { return err } + if _, ok := p[project]; ok { + s, err := yaml.Marshal(p[project]) + if err != nil { + return err + } + err = yaml.Unmarshal(s, l) + if err != nil { + return err + } + } return nil } diff --git a/internal/lagoon/lagoon_test.go b/internal/lagoon/lagoon_test.go index 6c9ddacd..33541fb0 100644 --- a/internal/lagoon/lagoon_test.go +++ b/internal/lagoon/lagoon_test.go @@ -9,9 +9,9 @@ import ( func TestUnmarshalLagoonYAML(t *testing.T) { type args struct { - file string - l *YAML - p *map[string]interface{} + file string + project string + l *YAML } tests := []struct { name string @@ -24,7 +24,6 @@ func TestUnmarshalLagoonYAML(t *testing.T) { args: args{ file: "../../test-resources/lagoon-yaml/test1/lagoon.yml", l: &YAML{}, - p: &map[string]interface{}{}, }, want: &YAML{ DockerComposeYAML: "docker-compose.yml", @@ -92,7 +91,6 @@ func TestUnmarshalLagoonYAML(t *testing.T) { args: args{ file: "../../test-resources/lagoon-yaml/test2/lagoon.yml", l: &YAML{}, - p: &map[string]interface{}{}, }, want: &YAML{ DockerComposeYAML: "docker-compose.yml", @@ -160,7 +158,6 @@ func TestUnmarshalLagoonYAML(t *testing.T) { args: args{ file: "../../test-resources/lagoon-yaml/test3/lagoon.yml", l: &YAML{}, - p: &map[string]interface{}{}, }, want: &YAML{ DockerComposeYAML: "docker-compose.yml", @@ -228,7 +225,6 @@ func TestUnmarshalLagoonYAML(t *testing.T) { args: args{ file: "../../test-resources/lagoon-yaml/test4/lagoon.yml", l: &YAML{}, - p: &map[string]interface{}{}, }, want: &YAML{ DockerComposeYAML: "docker-compose.yml", @@ -263,7 +259,6 @@ func TestUnmarshalLagoonYAML(t *testing.T) { args: args{ file: "../../test-resources/lagoon-yaml/test5/lagoon.yml", l: &YAML{}, - p: &map[string]interface{}{}, }, want: &YAML{ DockerComposeYAML: "docker-compose.yml", @@ -293,7 +288,7 @@ func TestUnmarshalLagoonYAML(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := UnmarshalLagoonYAML(tt.args.file, tt.args.l, tt.args.p); (err != nil) != tt.wantErr { + if err := UnmarshalLagoonYAML(tt.args.file, tt.args.l, tt.args.project); (err != nil) != tt.wantErr { t.Errorf("UnmarshalLagoonYAML() error = %v, wantErr %v", err, tt.wantErr) } if !reflect.DeepEqual(tt.args.l, tt.want) { From 26355581fda5656bdba09ca05e8db2f32b959bfe Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 9 Dec 2022 10:14:04 +1100 Subject: [PATCH 15/92] test: add polysite unmarshal test --- internal/lagoon/lagoon_test.go | 32 +++++++++++++++++++++ test-resources/lagoon-yaml/test6/lagoon.yml | 28 ++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 test-resources/lagoon-yaml/test6/lagoon.yml diff --git a/internal/lagoon/lagoon_test.go b/internal/lagoon/lagoon_test.go index 33541fb0..926857e7 100644 --- a/internal/lagoon/lagoon_test.go +++ b/internal/lagoon/lagoon_test.go @@ -285,6 +285,38 @@ func TestUnmarshalLagoonYAML(t *testing.T) { }, }, }, + { + name: "test-polysite", + args: args{ + file: "../../test-resources/lagoon-yaml/test6/lagoon.yml", + l: &YAML{}, + project: "multiproject1", + }, + 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: "*/15 * * * *", + }, + }, + }, + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/test-resources/lagoon-yaml/test6/lagoon.yml b/test-resources/lagoon-yaml/test6/lagoon.yml new file mode 100644 index 00000000..9a9aee32 --- /dev/null +++ b/test-resources/lagoon-yaml/test6/lagoon.yml @@ -0,0 +1,28 @@ +--- +docker-compose-yaml: docker-compose.yml + +project: content-example-com + +multiproject1: + environments: + main: + cronjobs: + - name: drush cron + schedule: "*/15 * * * *" + command: 'drush cron' + service: cli + routes: + - nginx: + - a.example.com + +multiproject2: + environments: + main: + cronjobs: + - name: notdrush cron + schedule: "*/15 * * * *" + command: 'notdrush cron' + service: cli + routes: + - nginx: + - a.example.com From 2d124f29793514b5181c197683d9934ecf66d698 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 13 Dec 2022 13:50:21 +1100 Subject: [PATCH 16/92] chore: add more templating --- internal/generator/buildvalues.go | 94 +++--- internal/generator/services.go | 3 +- internal/generator/services_test.go | 1 + internal/helpers/helpers.go | 34 +- internal/servicetypes/basic.go | 1 - internal/servicetypes/elasticsearch.go | 1 - internal/servicetypes/mariadb.go | 1 - internal/servicetypes/mongodb.go | 1 - internal/servicetypes/nginx.go | 221 +++++++++++++ internal/servicetypes/node.go | 1 - internal/servicetypes/opensearch.go | 1 - internal/servicetypes/postgres.go | 1 - internal/servicetypes/python.go | 1 - internal/servicetypes/redis.go | 1 - internal/servicetypes/solr.go | 1 - internal/servicetypes/types.go | 35 +- .../services/templates_deployment.go | 230 ++++++++++--- .../services/templates_deployment_test.go | 310 ++++++++++++++++-- .../deployment/result-cli-1.yaml | 126 +++++++ .../deployment/result-nginx-1.yaml | 228 +++++++++++++ 20 files changed, 1144 insertions(+), 148 deletions(-) create mode 100644 internal/servicetypes/nginx.go create mode 100644 internal/templating/services/test-resources/deployment/result-nginx-1.yaml diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index abb750b4..5f26ed4f 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -7,30 +7,26 @@ import ( // BuildValues is the values file data generated by the lagoon build type BuildValues struct { - Project string `json:"project"` - Environment string `json:"environment"` - EnvironmentType string `json:"environmentType"` - Namespace string `json:"namespace"` - GitSha string `json:"gitSha"` - BuildType string `json:"buildType"` - Kubernetes string `json:"kubernetes"` - LagoonVersion string `json:"lagoonVersion"` - ActiveEnvironment string `json:"activeEnvironment"` - StandbyEnvironment string `json:"standbyEnvironment"` - IsActiveEnvironment bool `json:"isActiveEnvironment"` - IsStandbyEnvironment bool `json:"isStandbyEnvironment"` - PodSecurityContext struct { - FsGroup int `json:"fsGroup"` - RunAsGroup int `json:"runAsGroup"` - RunAsUser int `json:"runAsUser"` - } `json:"podSecurityContext"` - ImagePullSecrets []ImagePullSecrets `json:"imagePullSecrets"` - Branch string `json:"branch"` - PRNumber string `json:"prNumber"` - PRTitle string `json:"prTitle"` - PRHeadBranch string `json:"prHeadBranch"` - PRBaseBranch string `json:"prBaseBranch"` - Fastly struct { + Project string `json:"project"` + Environment string `json:"environment"` + EnvironmentType string `json:"environmentType"` + Namespace string `json:"namespace"` + GitSha string `json:"gitSha"` + BuildType string `json:"buildType"` + Kubernetes string `json:"kubernetes"` + LagoonVersion string `json:"lagoonVersion"` + ActiveEnvironment string `json:"activeEnvironment"` + StandbyEnvironment string `json:"standbyEnvironment"` + IsActiveEnvironment bool `json:"isActiveEnvironment"` + IsStandbyEnvironment bool `json:"isStandbyEnvironment"` + PodSecurityContext PodSecurityContext `json:"podSecurityContext"` + ImagePullSecrets []ImagePullSecrets `json:"imagePullSecrets"` + Branch string `json:"branch"` + PRNumber string `json:"prNumber"` + PRTitle string `json:"prTitle"` + PRHeadBranch string `json:"prHeadBranch"` + PRBaseBranch string `json:"prBaseBranch"` + Fastly struct { ServiceID string `json:"serviceId"` APISecretName string `json:"apiSecretName"` Watch bool `json:"watch"` @@ -58,6 +54,12 @@ type BuildValues struct { DBaaSClient *dbaasclient.Client `json:"-"` } +type PodSecurityContext struct { + FsGroup int64 `json:"fsGroup"` + RunAsGroup int64 `json:"runAsGroup"` + RunAsUser int64 `json:"runAsUser"` +} + type MonitoringConfig struct { Enabled bool `json:"enabled"` AlertContact string `json:"alertContact"` @@ -86,27 +88,29 @@ type DynamicSecret struct { // ServiceValues is the values for a specific service used by a lagoon build type ServiceValues struct { - Name string `json:"name"` // this is the actual compose service name - OverrideName string `json:"overrideName"` // if an override name is provided, use it - Type string `json:"type"` - AutogeneratedRoutesEnabled bool `json:"autogeneratedRoutesEnabled"` - AutogeneratedRoutesTLSAcme bool `json:"autogeneratedRoutesTLSAcme"` - AutogeneratedRouteDomain string `json:"autogeneratedRouteDomain"` - ShortAutogeneratedRouteDomain string `json:"shortAutogeneratedRouteDomain"` - DBaaSEnvironment string `json:"dbaasEnvironment"` - NativeCronjobs []lagoon.Cronjob `json:"nativeCronjobs"` - InPodCronjobs []lagoon.Cronjob `json:"inPodCronjobs"` - ImageName string `json:"imageName"` - DeploymentServiceType string `json:"deploymentServiceType"` - ServicePort int32 `json:"servicePort,omitempty"` - PersistentVolumePath string `json:"persistentVolumePath,omitempty"` - PersistentVolumeName string `json:"persistentVolumeName,omitempty"` - PersistentVolumeSize string `json:"persistentVolumeSize,omitempty"` - UseSpotInstances bool `json:"useSpot"` - ForceSpotInstances bool `json:"forceUseSpot"` - CronjobUseSpotInstances bool `json:"cronjobUseSpot"` - CronjobForceSpotInstances bool `json:"cronjobForceUseSpot"` - Replicas int32 `json:"replicas"` + Name string `json:"name"` // this is the actual compose service name + OverrideName string `json:"overrideName"` // if an override name is provided, use it + Type string `json:"type"` + AutogeneratedRoutesEnabled bool `json:"autogeneratedRoutesEnabled"` + AutogeneratedRoutesTLSAcme bool `json:"autogeneratedRoutesTLSAcme"` + AutogeneratedRouteDomain string `json:"autogeneratedRouteDomain"` + ShortAutogeneratedRouteDomain string `json:"shortAutogeneratedRouteDomain"` + DBaaSEnvironment string `json:"dbaasEnvironment"` + NativeCronjobs []lagoon.Cronjob `json:"nativeCronjobs"` + InPodCronjobs []lagoon.Cronjob `json:"inPodCronjobs"` + ImageName string `json:"imageName"` + DeploymentServiceType string `json:"deploymentServiceType"` + ServicePort int32 `json:"servicePort,omitempty"` + PersistentVolumePath string `json:"persistentVolumePath,omitempty"` + PersistentVolumeName string `json:"persistentVolumeName,omitempty"` + PersistentVolumeSize string `json:"persistentVolumeSize,omitempty"` + UseSpotInstances bool `json:"useSpot"` + ForceSpotInstances bool `json:"forceUseSpot"` + CronjobUseSpotInstances bool `json:"cronjobUseSpot"` + CronjobForceSpotInstances bool `json:"cronjobForceUseSpot"` + Replicas int32 `json:"replicas"` + LinkedService *ServiceValues `json:"linkedService"` + PodSecurityContext PodSecurityContext `json:"podSecurityContext"` } // CronjobValues is the values for cronjobs diff --git a/internal/generator/services.go b/internal/generator/services.go index 33321af1..92e41e9a 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -186,7 +186,7 @@ func composeToServiceValues( if servicePersistentSize == "" { // if there is no persistent size, check if the service type has a default size allocated if val, ok := servicetypes.ServiceTypes[lagoonType]; ok { - servicePersistentPath = val.Volumes.PersistentVolumeSize + servicePersistentSize = val.Volumes.PersistentVolumeSize } } @@ -374,6 +374,7 @@ func composeToServiceValues( Replicas: spotReplicas, InPodCronjobs: inpodcronjobs, NativeCronjobs: nativecronjobs, + PodSecurityContext: buildValues.PodSecurityContext, } // check if the service has a service port override (this only applies to basic(-persistent)) servicePortOverride := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.service.port") diff --git a/internal/generator/services_test.go b/internal/generator/services_test.go index 9239744d..b5e18e3b 100644 --- a/internal/generator/services_test.go +++ b/internal/generator/services_test.go @@ -122,6 +122,7 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesTLSAcme: true, InPodCronjobs: []lagoon.Cronjob{}, NativeCronjobs: []lagoon.Cronjob{}, + PersistentVolumeSize: "5Gi", }, }, { diff --git a/internal/helpers/helpers.go b/internal/helpers/helpers.go index 56b63854..52fe181a 100644 --- a/internal/helpers/helpers.go +++ b/internal/helpers/helpers.go @@ -1,16 +1,18 @@ package helpers import ( - "bytes" "crypto/md5" "crypto/sha256" "encoding/base32" - "encoding/gob" "encoding/hex" + "encoding/json" "fmt" + "html/template" "os" "strconv" "strings" + + "sigs.k8s.io/yaml" ) // StrPtr . @@ -218,9 +220,29 @@ func CheckLabelLength(labels map[string]string) error { } func DeepCopy(src, dist interface{}) (err error) { - buf := bytes.Buffer{} - if err = gob.NewEncoder(&buf).Encode(src); err != nil { - return + origJSON, err := json.Marshal(src) + if err != nil { + return err + } + if err = json.Unmarshal(origJSON, &dist); err != nil { + return err + } + return nil +} + +func TemplateThings(values, src, dist interface{}) { + yb, _ := yaml.Marshal(src) + tmpl, _ := template.New("").Parse(string(yb)) + queryBuilder := strings.Builder{} + tmpl.Execute(&queryBuilder, values) + yaml.Unmarshal([]byte(queryBuilder.String()), &dist) +} + +func AppendIfMissing(slice []string, i string) []string { + for _, ele := range slice { + if ele == i { + return slice + } } - return gob.NewDecoder(&buf).Decode(dist) + return append(slice, i) } diff --git a/internal/servicetypes/basic.go b/internal/servicetypes/basic.go index 353ce670..7d763ead 100644 --- a/internal/servicetypes/basic.go +++ b/internal/servicetypes/basic.go @@ -22,7 +22,6 @@ var basic = ServiceType{ }, }, PrimaryContainer: ServiceContainer{ - Name: "basic", ImagePullPolicy: corev1.PullAlways, Container: corev1.Container{ diff --git a/internal/servicetypes/elasticsearch.go b/internal/servicetypes/elasticsearch.go index 6dd9222d..7935a15a 100644 --- a/internal/servicetypes/elasticsearch.go +++ b/internal/servicetypes/elasticsearch.go @@ -8,7 +8,6 @@ import ( var elasticsearch = ServiceType{ Name: "elasticsearch", Ports: ServicePorts{ - CanChangePort: true, Ports: []corev1.ServicePort{ { Port: 9200, diff --git a/internal/servicetypes/mariadb.go b/internal/servicetypes/mariadb.go index 648b25f2..1f800efb 100644 --- a/internal/servicetypes/mariadb.go +++ b/internal/servicetypes/mariadb.go @@ -8,7 +8,6 @@ import ( var mariadbSingle = ServiceType{ Name: "mariadb-single", Ports: ServicePorts{ - CanChangePort: true, Ports: []corev1.ServicePort{ { Port: 3306, diff --git a/internal/servicetypes/mongodb.go b/internal/servicetypes/mongodb.go index 6d450c88..3798a367 100644 --- a/internal/servicetypes/mongodb.go +++ b/internal/servicetypes/mongodb.go @@ -8,7 +8,6 @@ import ( var mongodbSingle = ServiceType{ Name: "mongodb-single", Ports: ServicePorts{ - CanChangePort: true, Ports: []corev1.ServicePort{ { Port: 27017, diff --git a/internal/servicetypes/nginx.go b/internal/servicetypes/nginx.go new file mode 100644 index 00000000..282e9208 --- /dev/null +++ b/internal/servicetypes/nginx.go @@ -0,0 +1,221 @@ +package servicetypes + +import ( + "github.com/uselagoon/build-deploy-tool/internal/helpers" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var nginx = ServiceType{ + Name: "nginx", + Ports: ServicePorts{ + Ports: []corev1.ServicePort{ + { + Port: 8080, + TargetPort: intstr.IntOrString{ + Type: intstr.String, + StrVal: "http", + }, + Protocol: corev1.ProtocolTCP, + Name: "http", + }, + }, + }, + PrimaryContainer: ServiceContainer{ + Name: "nginx", + ImagePullPolicy: corev1.PullAlways, + Container: corev1.Container{ + Ports: []corev1.ContainerPort{ + { + Name: "http", + ContainerPort: 8080, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/nginx_status", + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 50000, + }, + }, + }, + InitialDelaySeconds: 1, + TimeoutSeconds: 3, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/nginx_status", + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 50000, + }, + }, + }, + InitialDelaySeconds: 900, + TimeoutSeconds: 3, + FailureThreshold: 5, + }, + }, + }, +} + +var nginxPHP = ServiceType{ + Name: "nginx-php", + Ports: nginx.Ports, + PrimaryContainer: ServiceContainer{ + Name: "nginx", + ImagePullPolicy: corev1.PullAlways, + Container: corev1.Container{ + Ports: []corev1.ContainerPort{ + { + Name: "http", + ContainerPort: 8080, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/nginx_status", + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 50000, + }, + }, + }, + InitialDelaySeconds: 1, + TimeoutSeconds: 3, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/nginx_status", + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 50000, + }, + }, + }, + InitialDelaySeconds: 900, + TimeoutSeconds: 3, + FailureThreshold: 5, + }, + Env: []corev1.EnvVar{ + { + Name: "NGINX_FASTCGI_PASS", + Value: "127.0.0.1", + }, + }, + }, + }, + SecondaryContainer: ServiceContainer{ + Name: "php", + ImagePullPolicy: corev1.PullAlways, + Container: corev1.Container{ + Ports: []corev1.ContainerPort{ + { + Name: "http", + ContainerPort: 9000, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 9000, + }, + }, + }, + InitialDelaySeconds: 2, + PeriodSeconds: 10, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 9000, + }, + }, + }, + InitialDelaySeconds: 60, + PeriodSeconds: 10, + }, + Env: []corev1.EnvVar{ + { + Name: "NGINX_FASTCGI_PASS", + Value: "127.0.0.1", + }, + }, + }, + }, +} + +var nginxPHPPersistent = ServiceType{ + Name: "nginx-php-persistent", + Ports: nginx.Ports, + Volumes: ServiceVolume{ + PersistentVolumeSize: "5Gi", + PersistentVolumeType: corev1.ReadWriteMany, + Backup: true, + }, + InitContainer: ServiceContainer{ + Name: "fix-storage-permissions", + Command: []string{ + "sh", + "-c", + `set -e +SENTINEL="/storage/.lagoon-rootless-migration-complete" +if ! [ -f "$SENTINEL" ]; then + find /storage -exec chown {{ .PodSecurityContext.RunAsUser}}:0 {} + + find /storage -exec chmod a+r,u+w {} + + find /storage -type d -exec chmod a+x {} + + touch "$SENTINEL" +fi`, + }, + Container: corev1.Container{ + Name: "fix-storage-permissions", + Image: "busybox:musl", + ImagePullPolicy: corev1.PullIfNotPresent, + SecurityContext: &corev1.SecurityContext{ + RunAsUser: helpers.Int64Ptr(0), + }, + }, + VolumeMounts: []corev1.VolumeMount{ + { + Name: "{{ .PersistentVolumeName }}", + MountPath: "/storage", + }, + }, + }, + PrimaryContainer: ServiceContainer{ + Name: nginxPHP.PrimaryContainer.Name, + ImagePullPolicy: nginxPHP.PrimaryContainer.ImagePullPolicy, + Container: nginxPHP.PrimaryContainer.Container, + }, + SecondaryContainer: ServiceContainer{ + Name: nginxPHP.SecondaryContainer.Name, + ImagePullPolicy: nginxPHP.SecondaryContainer.ImagePullPolicy, + Container: nginxPHP.SecondaryContainer.Container, + Volumes: []corev1.Volume{ + { + Name: "{{ .PersistentVolumeName }}-twig", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + }, + VolumeMounts: []corev1.VolumeMount{ + { + Name: "{{ .PersistentVolumeName }}-twig", + MountPath: "{{ .PersistentVolumeName }}/php", + }, + }, + }, +} diff --git a/internal/servicetypes/node.go b/internal/servicetypes/node.go index 14ed1768..1d0913e8 100644 --- a/internal/servicetypes/node.go +++ b/internal/servicetypes/node.go @@ -8,7 +8,6 @@ import ( var node = ServiceType{ Name: "node", Ports: ServicePorts{ - CanChangePort: true, Ports: []corev1.ServicePort{ { Port: 3000, diff --git a/internal/servicetypes/opensearch.go b/internal/servicetypes/opensearch.go index f44d2694..1a93a209 100644 --- a/internal/servicetypes/opensearch.go +++ b/internal/servicetypes/opensearch.go @@ -8,7 +8,6 @@ import ( var opensearch = ServiceType{ Name: "opensearch", Ports: ServicePorts{ - CanChangePort: true, Ports: []corev1.ServicePort{ { Port: 9200, diff --git a/internal/servicetypes/postgres.go b/internal/servicetypes/postgres.go index e64e396a..1f149aea 100644 --- a/internal/servicetypes/postgres.go +++ b/internal/servicetypes/postgres.go @@ -9,7 +9,6 @@ import ( var postgresSingle = ServiceType{ Name: "postgres-single", Ports: ServicePorts{ - CanChangePort: true, Ports: []corev1.ServicePort{ { Port: 5432, diff --git a/internal/servicetypes/python.go b/internal/servicetypes/python.go index 7020b13a..427d22e5 100644 --- a/internal/servicetypes/python.go +++ b/internal/servicetypes/python.go @@ -8,7 +8,6 @@ import ( var python = ServiceType{ Name: "python", Ports: ServicePorts{ - CanChangePort: true, Ports: []corev1.ServicePort{ { Port: 8800, diff --git a/internal/servicetypes/redis.go b/internal/servicetypes/redis.go index c65103c6..29e342f7 100644 --- a/internal/servicetypes/redis.go +++ b/internal/servicetypes/redis.go @@ -8,7 +8,6 @@ import ( var redis = ServiceType{ Name: "redis", Ports: ServicePorts{ - CanChangePort: true, Ports: []corev1.ServicePort{ { Port: 6379, diff --git a/internal/servicetypes/solr.go b/internal/servicetypes/solr.go index 8d595e58..94810a58 100644 --- a/internal/servicetypes/solr.go +++ b/internal/servicetypes/solr.go @@ -8,7 +8,6 @@ import ( var solr = ServiceType{ Name: "solr-php-persistent", // this has to be like this because it is used in selectors, and is unchangeable now on existing deployed solr Ports: ServicePorts{ - CanChangePort: true, Ports: []corev1.ServicePort{ { Port: 8983, diff --git a/internal/servicetypes/types.go b/internal/servicetypes/types.go index dc1f9a31..ba76d965 100644 --- a/internal/servicetypes/types.go +++ b/internal/servicetypes/types.go @@ -11,6 +11,8 @@ type ServiceType struct { Volumes ServiceVolume Strategy appsv1.DeploymentStrategy PrimaryContainer ServiceContainer + InitContainer ServiceContainer + SecondaryContainer ServiceContainer PodSecurityContext ServicePodSecurityContext } @@ -23,6 +25,10 @@ type ServiceContainer struct { Name string ImagePullPolicy corev1.PullPolicy Container corev1.Container + // define additional volumes here, can leverage 'go template' with generator.ServiceValues + Volumes []corev1.Volume + VolumeMounts []corev1.VolumeMount + Command []string } type ServiceVolume struct { @@ -39,17 +45,20 @@ type ServicePorts struct { // this is a map that maps the lagoon service-type that can be provided in the `lagoon.type` label to the default values for that service var ServiceTypes = map[string]ServiceType{ - "basic": basic, - "basic-persistent": basicPersistent, - "cli": cli, - "cli-persistent": cliPersistent, - "elasticsearch": elasticsearch, - "opensearch": opensearch, - "mariadb-single": mariadbSingle, - "mongodb-single": mongodbSingle, - "postgres-single": postgresSingle, - "node": node, - "node-persistent": nodePersistent, - "python": python, - "python-persistent": pythonPersistent, + "basic": basic, + "basic-persistent": basicPersistent, + "cli": cli, + "cli-persistent": cliPersistent, + "elasticsearch": elasticsearch, + "opensearch": opensearch, + "mariadb-single": mariadbSingle, + "mongodb-single": mongodbSingle, + "postgres-single": postgresSingle, + "node": node, + "node-persistent": nodePersistent, + "python": python, + "python-persistent": pythonPersistent, + "nginx": nginx, + "nginx-php": nginxPHP, + "nginx-php-persistent": nginxPHPPersistent, } diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index 0edf0c92..82df5fb7 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -21,51 +21,48 @@ func GenerateDeploymentTemplate( separator := []byte("---\n") var result []byte - // add the default labels - labels := map[string]string{ - "app.kubernetes.io/managed-by": "build-deploy-tool", - "lagoon.sh/project": buildValues.Project, - "lagoon.sh/environment": buildValues.Environment, - "lagoon.sh/environmentType": buildValues.EnvironmentType, - "lagoon.sh/buildType": buildValues.BuildType, - } - - // add the default annotations - annotations := map[string]string{ - "lagoon.sh/version": buildValues.LagoonVersion, - } - - // add any additional labels - additionalLabels := map[string]string{} - additionalAnnotations := map[string]string{} - if buildValues.BuildType == "branch" { - additionalAnnotations["lagoon.sh/branch"] = buildValues.Branch - } else if buildValues.BuildType == "pullrequest" { - additionalAnnotations["lagoon.sh/prNumber"] = buildValues.PRNumber - additionalAnnotations["lagoon.sh/prHeadBranch"] = buildValues.PRHeadBranch - additionalAnnotations["lagoon.sh/prBaseBranch"] = buildValues.PRBaseBranch - - } + // check linked services + checkedServices := LinkedServiceCalculator(buildValues.Services) // for all the services that the build values generated // iterate over them and generate any kubernetes deployments - for _, serviceValues := range buildValues.Services { + for _, serviceValues := range checkedServices { if val, ok := servicetypes.ServiceTypes[serviceValues.Type]; ok { - // if val.Volumes.PersistentVolumeSize != "" { - // if serviceValues.PersistentVolumePath == "" { - // return nil, fmt.Errorf("no persistent volume size defined for this service") - // } - // } serviceTypeValues := &servicetypes.ServiceType{} helpers.DeepCopy(val, serviceTypeValues) var deploymentBytes []byte - additionalLabels["app.kubernetes.io/name"] = serviceTypeValues.Name - additionalLabels["app.kubernetes.io/instance"] = serviceValues.Name - additionalLabels["lagoon.sh/template"] = fmt.Sprintf("%s-%s", serviceTypeValues.Name, "0.1.0") - additionalLabels["lagoon.sh/service"] = serviceValues.Name - additionalLabels["lagoon.sh/service-type"] = serviceTypeValues.Name - additionalAnnotations["lagoon.sh/configMapSha"] = buildValues.ConfigMapSha + + // add the default labels + labels := map[string]string{ + "app.kubernetes.io/managed-by": "build-deploy-tool", + "lagoon.sh/project": buildValues.Project, + "lagoon.sh/environment": buildValues.Environment, + "lagoon.sh/environmentType": buildValues.EnvironmentType, + "lagoon.sh/buildType": buildValues.BuildType, + "app.kubernetes.io/name": serviceTypeValues.Name, + "app.kubernetes.io/instance": serviceValues.Name, + "lagoon.sh/template": fmt.Sprintf("%s-%s", serviceTypeValues.Name, "0.1.0"), + "lagoon.sh/service": serviceValues.Name, + "lagoon.sh/service-type": serviceTypeValues.Name, + } + + // add the default annotations + annotations := map[string]string{ + "lagoon.sh/version": buildValues.LagoonVersion, + "lagoon.sh/configMapSha": buildValues.ConfigMapSha, + } + + // add any additional labels + additionalLabels := make(map[string]string) + additionalAnnotations := make(map[string]string) + if buildValues.BuildType == "branch" { + additionalAnnotations["lagoon.sh/branch"] = buildValues.Branch + } else if buildValues.BuildType == "pullrequest" { + additionalAnnotations["lagoon.sh/prNumber"] = buildValues.PRNumber + additionalAnnotations["lagoon.sh/prHeadBranch"] = buildValues.PRHeadBranch + additionalAnnotations["lagoon.sh/prBaseBranch"] = buildValues.PRBaseBranch + } deployment := &appsv1.Deployment{ TypeMeta: metav1.TypeMeta{ @@ -147,8 +144,8 @@ func GenerateDeploymentTemplate( // start deployment template depMeta := metav1.ObjectMeta{ - Labels: labels, - Annotations: annotations, + Labels: deployment.ObjectMeta.Labels, + Annotations: deployment.ObjectMeta.Annotations, } deployment.Spec.Template.ObjectMeta = depMeta deployment.Spec.Replicas = helpers.Int32Ptr(1) @@ -169,7 +166,8 @@ func GenerateDeploymentTemplate( // set the priority class deployment.Spec.Template.Spec.PriorityClassName = fmt.Sprintf("lagoon-priority-%s", buildValues.EnvironmentType) - // set up an volumes this deployment can use + // start set up any volumes this deployment can use + // first handle any dynamic secret volumes that come from kubernetes secrets that are labeled for _, dsv := range buildValues.DynamicSecretVolumes { volume := corev1.Volume{ Name: dsv.Name, @@ -182,6 +180,7 @@ func GenerateDeploymentTemplate( } deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, volume) } + // if there is a persistent volume attached to this service, handle adding that here if serviceTypeValues.Volumes.PersistentVolumeSize != "" { volume := corev1.Volume{ Name: serviceValues.PersistentVolumeName, @@ -193,6 +192,18 @@ func GenerateDeploymentTemplate( } deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, volume) } + // if there are any specific container overrides provided, handle those here + for _, pcv := range serviceTypeValues.PrimaryContainer.Volumes { + volume := corev1.Volume{} + helpers.TemplateThings(serviceValues, pcv, &volume) + deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, volume) + } + for _, scv := range serviceTypeValues.SecondaryContainer.Volumes { + volume := corev1.Volume{} + helpers.TemplateThings(serviceValues, scv, &volume) + deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, volume) + } + // end set up any volumes this deployment can use // handle any image pull secrets pullsecrets := []corev1.LocalObjectReference{} @@ -204,6 +215,25 @@ func GenerateDeploymentTemplate( deployment.Spec.Template.Spec.ImagePullSecrets = pullsecrets // start working out the containers to add + // add any init containers + if serviceTypeValues.InitContainer.Name != "" && serviceValues.PodSecurityContext.RunAsUser == 10001 { + init := serviceTypeValues.InitContainer + for _, svm := range serviceTypeValues.InitContainer.VolumeMounts { + volumeMount := corev1.VolumeMount{} + helpers.TemplateThings(serviceValues, svm, &volumeMount) + init.Container.VolumeMounts = append(init.Container.VolumeMounts, volumeMount) + } + cmd := []string{} + for _, c := range init.Command { + var c2 string + helpers.TemplateThings(serviceValues, c, &c2) + cmd = append(cmd, c2) + } + init.Container.Command = cmd + deployment.Spec.Template.Spec.InitContainers = append(deployment.Spec.Template.Spec.InitContainers, init.Container) + } + + // handle the primary container container := serviceTypeValues.PrimaryContainer // if the service can change the port if serviceTypeValues.Ports.CanChangePort { @@ -221,11 +251,12 @@ func GenerateDeploymentTemplate( container.Container.Name = container.Name container.Container.Image = serviceValues.ImageName + // set up cronjobs if required cronjobs := "" for _, cronjob := range serviceValues.InPodCronjobs { cronjobs = fmt.Sprintf("%s%s %s\n", cronjobs, cronjob.Schedule, cronjob.Command) } - container.Container.Env = []corev1.EnvVar{ + envvars := []corev1.EnvVar{ { Name: "LAGOON_GIT_SHA", Value: buildValues.GitSha, @@ -235,6 +266,18 @@ func GenerateDeploymentTemplate( Value: cronjobs, }, } + for _, envvar := range envvars { + container.Container.Env = append(container.Container.Env, envvar) + } + container.Container.EnvFrom = []corev1.EnvFromSource{ + { + ConfigMapRef: &corev1.ConfigMapEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: "lagoon-env", + }, + }, + }, + } // mount the volumes in the primary container for _, dsm := range buildValues.DynamicSecretMounts { @@ -252,9 +295,69 @@ func GenerateDeploymentTemplate( } container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) } + for _, svm := range serviceTypeValues.PrimaryContainer.VolumeMounts { + volumeMount := corev1.VolumeMount{} + helpers.TemplateThings(serviceValues, svm, &volumeMount) + container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) + } // append the final defined container to the spec deployment.Spec.Template.Spec.Containers = append(deployment.Spec.Template.Spec.Containers, container.Container) + // if this service has a secondary container provided (mainly will be `nginx-php`, but could be others in the future) + if serviceValues.LinkedService == nil && serviceTypeValues.SecondaryContainer.Name != "" { + // if no linked service is found from the docker-compose services, drop an error + return nil, fmt.Errorf("service type %s has a secondary container defined, but no linked service was found", serviceValues.Type) + } + // if a linked service is provided, and the servicetype supports it, handle that here + if serviceValues.LinkedService != nil && serviceTypeValues.SecondaryContainer.Name != "" { + linkedContainer := serviceTypeValues.SecondaryContainer + + // handle setting the rest of the containers specs with values from the service or build values + linkedContainer.Container.Name = linkedContainer.Name + linkedContainer.Container.Image = serviceValues.LinkedService.ImageName + + envvars := []corev1.EnvVar{ + { + Name: "LAGOON_GIT_SHA", + Value: buildValues.GitSha, + }, + } + for _, envvar := range envvars { + linkedContainer.Container.Env = append(linkedContainer.Container.Env, envvar) + } + linkedContainer.Container.EnvFrom = []corev1.EnvFromSource{ + { + ConfigMapRef: &corev1.ConfigMapEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: "lagoon-env", + }, + }, + }, + } + for _, dsm := range buildValues.DynamicSecretMounts { + volumeMount := corev1.VolumeMount{ + Name: dsm.Name, + MountPath: dsm.MountPath, + ReadOnly: dsm.ReadOnly, + } + linkedContainer.Container.VolumeMounts = append(linkedContainer.Container.VolumeMounts, volumeMount) + } + if serviceTypeValues.Volumes.PersistentVolumeSize != "" { + volumeMount := corev1.VolumeMount{ + Name: serviceValues.PersistentVolumeName, + MountPath: serviceValues.PersistentVolumePath, + } + linkedContainer.Container.VolumeMounts = append(linkedContainer.Container.VolumeMounts, volumeMount) + } + + for _, svm := range serviceTypeValues.SecondaryContainer.VolumeMounts { + volumeMount := corev1.VolumeMount{} + helpers.TemplateThings(serviceValues, svm, &volumeMount) + linkedContainer.Container.VolumeMounts = append(linkedContainer.Container.VolumeMounts, volumeMount) + } + deployment.Spec.Template.Spec.Containers = append(deployment.Spec.Template.Spec.Containers, linkedContainer.Container) + } + // end deployment template deploymentBytes, err = yaml.Marshal(deployment) @@ -272,3 +375,48 @@ func GenerateDeploymentTemplate( } return result, nil } + +// LinkedServiceCalculator checks the provided services to see if there are any linked services +// linked services are mostly just `nginx-php` but lagoon has the possibility to support more than this in the future +func LinkedServiceCalculator(services []generator.ServiceValues) []generator.ServiceValues { + linkedMap := make(map[string][]generator.ServiceValues) + retServices := []generator.ServiceValues{} + linkedOrder := []string{} + + // go over the services twice to extract just the linked services (the override names will be the same in a linked service) + for _, s1 := range services { + for _, s2 := range services { + if s1.OverrideName == s2.OverrideName && s1.Name != s2.Name { + linkedMap[s1.OverrideName] = append(linkedMap[s1.OverrideName], s1) + linkedOrder = helpers.AppendIfMissing(linkedOrder, s1.OverrideName) + } + } + } + // go over the services again and any that are in the services that aren't in the linked map (again the override name is the key) + // add it as a standalone service + for _, s1 := range services { + if _, ok := linkedMap[s1.OverrideName]; !ok { + retServices = append(retServices, s1) + } + } + + // go over the linked services and add the linkedservice to the main service + // example would be adding the `php` service in docker-compose to the `nginx` service as a `LinkedService` definition + // this allows the generated service values to carry across + for _, name := range linkedOrder { + service := generator.ServiceValues{} + if len(linkedMap[name]) == 2 { + for idx, s := range linkedMap[name] { + if idx == 0 { + service = s + } + if idx == 1 { + service.LinkedService = &s + } + } + } + // then add it to the slice of services to return + retServices = append(retServices, service) + } + return retServices +} diff --git a/internal/templating/services/templates_deployment_test.go b/internal/templating/services/templates_deployment_test.go index f6d70324..7b3fed8a 100644 --- a/internal/templating/services/templates_deployment_test.go +++ b/internal/templating/services/templates_deployment_test.go @@ -1,14 +1,14 @@ package services import ( + "encoding/json" "os" "reflect" "testing" + "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/lagoon" - - "github.com/andreyvit/diff" ) func TestGenerateDeploymentTemplate(t *testing.T) { @@ -114,36 +114,107 @@ func TestGenerateDeploymentTemplate(t *testing.T) { }, want: "test-resources/deployment/result-basic-1.yaml", }, - // { - // name: "test2 - cli", - // 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: "cli", - // DBaaSEnvironment: "production", - // }, - // { - // Name: "myservice-persist", - // OverrideName: "myservice-persist", - // Type: "cli-persistent", - // DBaaSEnvironment: "production", - // }, - // }, - // }, - // }, - // want: "test-resources/deployment/result-cli-1.yaml", - // }, + { + name: "test2 - nginx-php", + 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", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + GitSha: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + Services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + }, + { + Name: "php", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/php@latest", + }, + { + Name: "nginx2", + OverrideName: "nginx2", + Type: "nginx-php-persistent", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/nginx2@latest", + PersistentVolumeSize: "10Gi", + PersistentVolumePath: "/storage/data", + PersistentVolumeName: "nginx2", + }, + { + Name: "php2", + OverrideName: "nginx2", + Type: "nginx-php-persistent", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/php2@latest", + PersistentVolumeSize: "10Gi", + PersistentVolumePath: "/storage/data", + PersistentVolumeName: "nginx2", + }, + }, + }, + }, + want: "test-resources/deployment/result-nginx-1.yaml", + }, + { + name: "test2 - cli", + 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", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + GitSha: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + Services: []generator.ServiceValues{ + { + Name: "myservice", + OverrideName: "myservice", + Type: "cli", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/myservice@latest", + }, + { + Name: "myservice-persist", + OverrideName: "myservice-persist", + Type: "cli-persistent", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/myservice-persistent@latest", + PersistentVolumeSize: "10Gi", + PersistentVolumePath: "/storage/data", + PersistentVolumeName: "myservice-persistent", + }, + }, + }, + }, + want: "test-resources/deployment/result-cli-1.yaml", + }, // { // name: "test3 - elasticsearch", // args: args{ @@ -226,3 +297,178 @@ func TestGenerateDeploymentTemplate(t *testing.T) { }) } } + +func TestLinkedServiceCalculator(t *testing.T) { + type args struct { + services []generator.ServiceValues + } + tests := []struct { + name string + args args + want []generator.ServiceValues + }{ + { + name: "test1 - standard nginx-php", + args: args{ + services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + }, + { + Name: "php", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/php@latest", + }, + }, + }, + want: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + LinkedService: &generator.ServiceValues{ + Name: "php", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/php@latest", + }, + }, + }, + }, + { + name: "test2 - multiple linked services (2 separate nginx-php)", + args: args{ + services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + }, + { + Name: "php", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/php@latest", + }, + { + Name: "nginx2", + OverrideName: "nginx2", + Type: "nginx-php-persistent", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/nginx2@latest", + }, + { + Name: "php2", + OverrideName: "nginx2", + Type: "nginx-php-persistent", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/php2@latest", + }, + }, + }, + want: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + LinkedService: &generator.ServiceValues{ + Name: "php", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/php@latest", + }, + }, + { + Name: "nginx2", + OverrideName: "nginx2", + Type: "nginx-php-persistent", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/nginx2@latest", + LinkedService: &generator.ServiceValues{ + Name: "php2", + OverrideName: "nginx2", + Type: "nginx-php-persistent", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/php2@latest", + }, + }, + }, + }, + { + name: "test3 - single nginx-php and a single nginx standalone", + args: args{ + services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + }, + { + Name: "php", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/php@latest", + }, + { + Name: "normalnginx", + OverrideName: "normalnginx", + Type: "nginx", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/normalnginx@latest", + }, + }, + }, + want: []generator.ServiceValues{ + { + Name: "normalnginx", + OverrideName: "normalnginx", + Type: "nginx", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/normalnginx@latest", + }, + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + LinkedService: &generator.ServiceValues{ + Name: "php", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/php@latest", + }, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := LinkedServiceCalculator(tt.args.services) + 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)) + } + }) + } +} diff --git a/internal/templating/services/test-resources/deployment/result-cli-1.yaml b/internal/templating/services/test-resources/deployment/result-cli-1.yaml index e69de29b..f69f4e5e 100644 --- a/internal/templating/services/test-resources/deployment/result-cli-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-cli-1.yaml @@ -0,0 +1,126 @@ +--- +apiVersion: apps/v1 +kind: Deployment +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: cli + 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: cli + lagoon.sh/template: cli-0.1.0 + name: myservice +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: myservice + app.kubernetes.io/name: cli + strategy: {} + 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: cli + 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: cli + lagoon.sh/template: cli-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice@latest + name: "" + resources: {} + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production +status: {} +--- +apiVersion: apps/v1 +kind: Deployment +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-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + name: myservice-persist +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: myservice-persist + app.kubernetes.io/name: cli-persistent + strategy: {} + 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-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice-persistent@latest + name: "" + resources: {} + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml new file mode 100644 index 00000000..6f2cc20d --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml @@ -0,0 +1,228 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx + lagoon.sh/service-type: nginx-php + lagoon.sh/template: nginx-php-0.1.0 + name: nginx +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: nginx + app.kubernetes.io/name: nginx-php + strategy: {} + 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: nginx + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx + lagoon.sh/service-type: nginx-php + lagoon.sh/template: nginx-php-0.1.0 + spec: + containers: + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/nginx@latest + livenessProbe: + failureThreshold: 5 + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 900 + timeoutSeconds: 3 + name: nginx + ports: + - containerPort: 8080 + name: http + protocol: TCP + readinessProbe: + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 1 + timeoutSeconds: 3 + resources: {} + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + value: "0" + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/php@latest + livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + tcpSocket: + port: 9000 + name: php + ports: + - containerPort: 9000 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 2 + periodSeconds: 10 + tcpSocket: + port: 9000 + resources: {} + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production +status: {} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx2 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx2 + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + name: nginx2 +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: nginx2 + app.kubernetes.io/name: nginx-php-persistent + strategy: {} + 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: nginx2 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx2 + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + spec: + containers: + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/nginx2@latest + livenessProbe: + failureThreshold: 5 + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 900 + timeoutSeconds: 3 + name: nginx + ports: + - containerPort: 8080 + name: http + protocol: TCP + readinessProbe: + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 1 + timeoutSeconds: 3 + resources: {} + volumeMounts: + - mountPath: /storage/data + name: nginx2 + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + value: "0" + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/php2@latest + livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + tcpSocket: + port: 9000 + name: php + ports: + - containerPort: 9000 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 2 + periodSeconds: 10 + tcpSocket: + port: 9000 + resources: {} + volumeMounts: + - mountPath: /storage/data + name: nginx2 + - mountPath: nginx2/php + name: nginx2-twig + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: nginx2 + persistentVolumeClaim: + claimName: nginx2 + - emptyDir: {} + name: nginx2-twig +status: {} From cb3931fb5e59cefb515625e3609953ea4d5b231b Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 21 Jul 2023 16:56:53 +1000 Subject: [PATCH 17/92] chore: tidy up servicetypes a bit and add more default values --- internal/servicetypes/README.md | 4 +- internal/servicetypes/basic.go | 17 +++-- internal/servicetypes/cli.go | 75 +++++++++++++++++++- internal/servicetypes/elasticsearch.go | 27 ++++++++ internal/servicetypes/mariadb.go | 4 ++ internal/servicetypes/mongodb.go | 4 ++ internal/servicetypes/nginx.go | 24 ++++++- internal/servicetypes/node.go | 49 +++++++++++++ internal/servicetypes/opensearch.go | 31 +++++++++ internal/servicetypes/postgres.go | 52 ++++++++++++++ internal/servicetypes/python.go | 49 +++++++++++++ internal/servicetypes/redis.go | 48 +++++++++++++ internal/servicetypes/solr.go | 49 +++++++++++++ internal/servicetypes/types.go | 33 ++++++--- internal/servicetypes/varnish.go | 96 ++++++++++++++++++++++++++ internal/servicetypes/worker.go | 10 +++ 16 files changed, 552 insertions(+), 20 deletions(-) create mode 100644 internal/servicetypes/varnish.go create mode 100644 internal/servicetypes/worker.go diff --git a/internal/servicetypes/README.md b/internal/servicetypes/README.md index 2d09d6e9..dcd64068 100644 --- a/internal/servicetypes/README.md +++ b/internal/servicetypes/README.md @@ -1,3 +1,5 @@ # Service Types -Defines defaults for Lagoon service types \ No newline at end of file +Defines defaults for Lagoon service types, hese replace the old helm based templates + +This allows for the existing service types built with helm to be transferred over to a new templating system that allows easier customizability of resulting service types, and allows for the possibility of allowing more flexible service type creation beyond the standard template offerings (additional port/services, multiple volumes, etc.) \ No newline at end of file diff --git a/internal/servicetypes/basic.go b/internal/servicetypes/basic.go index 7d763ead..c17619a0 100644 --- a/internal/servicetypes/basic.go +++ b/internal/servicetypes/basic.go @@ -2,6 +2,7 @@ package servicetypes import ( corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -56,13 +57,10 @@ var basic = ServiceType{ InitialDelaySeconds: 60, TimeoutSeconds: 10, }, - EnvFrom: []corev1.EnvFromSource{ - { - ConfigMapRef: &corev1.ConfigMapEnvSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "lagoon-env", - }, - }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("100M"), }, }, }, @@ -72,6 +70,11 @@ var basic = ServiceType{ var basicPersistent = ServiceType{ Name: "basic-persistent", Ports: basic.Ports, + PrimaryContainer: ServiceContainer{ + Name: basic.PrimaryContainer.Name, + ImagePullPolicy: basic.PrimaryContainer.ImagePullPolicy, + Container: basic.PrimaryContainer.Container, + }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteMany, diff --git a/internal/servicetypes/cli.go b/internal/servicetypes/cli.go index 4545381c..8b675631 100644 --- a/internal/servicetypes/cli.go +++ b/internal/servicetypes/cli.go @@ -1,10 +1,81 @@ package servicetypes +import ( + "github.com/uselagoon/build-deploy-tool/internal/helpers" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" +) + var cli = ServiceType{ Name: "cli", + PrimaryContainer: ServiceContainer{ + Name: "cli", + ImagePullPolicy: corev1.PullAlways, + Volumes: []corev1.Volume{ + { + Name: "lagoon-sshkey", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + DefaultMode: helpers.Int32Ptr(420), + SecretName: "lagoon-sshkey", + }, + }, + }, + }, + Container: corev1.Container{ + VolumeMounts: []corev1.VolumeMount{ + { + Name: "lagoon-sshkey", + ReadOnly: true, + MountPath: "/var/run/secrets/lagoon/sshkey/", + }, + }, + Ports: []corev1.ContainerPort{ + { + Name: "http", + ContainerPort: 3000, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + Exec: &corev1.ExecAction{ + Command: []string{ + "/bin/sh", + "-c", + "if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; fi", + }, + }, + }, + InitialDelaySeconds: 5, + PeriodSeconds: 2, + FailureThreshold: 3, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("100M"), + }, + }, + }, + }, } var cliPersistent = ServiceType{ - Name: "cli-persistent", - Volumes: ServiceVolume{}, + Name: "cli-persistent", + PrimaryContainer: ServiceContainer{ + Name: cli.PrimaryContainer.Name, + ImagePullPolicy: cli.PrimaryContainer.ImagePullPolicy, + Container: cli.PrimaryContainer.Container, + Volumes: append(cli.PrimaryContainer.Volumes, corev1.Volume{ + Name: "{{ .PersistentVolumeName }}-twig", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }), + VolumeMounts: append(cli.PrimaryContainer.VolumeMounts, corev1.VolumeMount{ + Name: "{{ .PersistentVolumeName }}-twig", + MountPath: "{{ .PersistentVolumePath }}/php", + }), + }, } diff --git a/internal/servicetypes/elasticsearch.go b/internal/servicetypes/elasticsearch.go index 7935a15a..07047d5e 100644 --- a/internal/servicetypes/elasticsearch.go +++ b/internal/servicetypes/elasticsearch.go @@ -1,6 +1,7 @@ package servicetypes import ( + "github.com/uselagoon/build-deploy-tool/internal/helpers" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -20,9 +21,35 @@ var elasticsearch = ServiceType{ }, }, }, + InitContainer: ServiceContainer{ + Name: "set-max-map-count", + Command: []string{ + "sh", + "-c", + `set -xe +DESIRED="262144" +CURRENT=$(sysctl -n vm.max_map_count) +if [ "$DESIRED" -gt "$CURRENT" ]; then + sysctl -w vm.max_map_count=$DESIRED +fi`, + }, + Container: corev1.Container{ + Name: "set-max-map-count", + Image: "busybox:latest", + ImagePullPolicy: corev1.PullIfNotPresent, + SecurityContext: &corev1.SecurityContext{ + Privileged: helpers.BoolPtr(true), + RunAsUser: helpers.Int64Ptr(0), + }, + }, + }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/usr/share/elasticsearch/data", + BackupConfiguration: BackupConfiguration{ + Command: `/bin/sh -c "tar -cf - -C /usr/share/elasticsearch/data ."`, + FileExtension: ".{{ .OverrideName }}.tar", + }, }, } diff --git a/internal/servicetypes/mariadb.go b/internal/servicetypes/mariadb.go index 1f800efb..4d1cf3cd 100644 --- a/internal/servicetypes/mariadb.go +++ b/internal/servicetypes/mariadb.go @@ -24,5 +24,9 @@ var mariadbSingle = ServiceType{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/var/lib/mysql", + BackupConfiguration: BackupConfiguration{ + Command: `/bin/sh -c 'mysqldump --max-allowed-packet=500M --events --routines --quick --add-locks --no-autocommit --single-transaction --all-databases'`, + FileExtension: ".{{ .OverrideName }}.sql", + }, }, } diff --git a/internal/servicetypes/mongodb.go b/internal/servicetypes/mongodb.go index 3798a367..3d7031b2 100644 --- a/internal/servicetypes/mongodb.go +++ b/internal/servicetypes/mongodb.go @@ -24,5 +24,9 @@ var mongodbSingle = ServiceType{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/data/db", + BackupConfiguration: BackupConfiguration{ + Command: `/bin/sh -c 'tar -cf - -C "/data/db" --exclude="lost\+found" . || [ $? -eq 1 ]'`, + FileExtension: ".{{ .OverrideName }}.tar", + }, }, } diff --git a/internal/servicetypes/nginx.go b/internal/servicetypes/nginx.go index 282e9208..10296991 100644 --- a/internal/servicetypes/nginx.go +++ b/internal/servicetypes/nginx.go @@ -3,6 +3,7 @@ package servicetypes import ( "github.com/uselagoon/build-deploy-tool/internal/helpers" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -59,6 +60,12 @@ var nginx = ServiceType{ TimeoutSeconds: 3, FailureThreshold: 5, }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("10M"), + }, + }, }, }, } @@ -110,6 +117,12 @@ var nginxPHP = ServiceType{ Value: "127.0.0.1", }, }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("10M"), + }, + }, }, }, SecondaryContainer: ServiceContainer{ @@ -153,6 +166,12 @@ var nginxPHP = ServiceType{ Value: "127.0.0.1", }, }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("100M"), + }, + }, }, }, } @@ -167,6 +186,9 @@ var nginxPHPPersistent = ServiceType{ }, InitContainer: ServiceContainer{ Name: "fix-storage-permissions", + Flags: map[string]bool{ + "rootlessworkloads": true, + }, Command: []string{ "sh", "-c", @@ -214,7 +236,7 @@ fi`, VolumeMounts: []corev1.VolumeMount{ { Name: "{{ .PersistentVolumeName }}-twig", - MountPath: "{{ .PersistentVolumeName }}/php", + MountPath: "{{ .PersistentVolumePath }}/php", }, }, }, diff --git a/internal/servicetypes/node.go b/internal/servicetypes/node.go index 1d0913e8..32052665 100644 --- a/internal/servicetypes/node.go +++ b/internal/servicetypes/node.go @@ -2,6 +2,7 @@ package servicetypes import ( corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -20,11 +21,59 @@ var node = ServiceType{ }, }, }, + PrimaryContainer: ServiceContainer{ + Name: "node", + ImagePullPolicy: corev1.PullAlways, + Container: corev1.Container{ + Ports: []corev1.ContainerPort{ + { + Name: "http", + ContainerPort: 3000, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 3000, + }, + }, + }, + InitialDelaySeconds: 1, + TimeoutSeconds: 1, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 3000, + }, + }, + }, + InitialDelaySeconds: 60, + TimeoutSeconds: 10, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("100M"), + }, + }, + }, + }, } var nodePersistent = ServiceType{ Name: "node-persistent", Ports: node.Ports, + PrimaryContainer: ServiceContainer{ + Name: node.PrimaryContainer.Name, + ImagePullPolicy: node.PrimaryContainer.ImagePullPolicy, + Container: node.PrimaryContainer.Container, + }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteMany, diff --git a/internal/servicetypes/opensearch.go b/internal/servicetypes/opensearch.go index 1a93a209..9dd5578e 100644 --- a/internal/servicetypes/opensearch.go +++ b/internal/servicetypes/opensearch.go @@ -1,6 +1,7 @@ package servicetypes import ( + "github.com/uselagoon/build-deploy-tool/internal/helpers" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -20,6 +21,32 @@ var opensearch = ServiceType{ }, }, }, + PrimaryContainer: ServiceContainer{ + Name: "opensearch", + ImagePullPolicy: corev1.PullAlways, + }, + InitContainer: ServiceContainer{ + Name: "set-max-map-count", + Command: []string{ + "sh", + "-c", + `set -xe +DESIRED="262144" +CURRENT=$(sysctl -n vm.max_map_count) +if [ "$DESIRED" -gt "$CURRENT" ]; then + sysctl -w vm.max_map_count=$DESIRED +fi`, + }, + Container: corev1.Container{ + Name: "set-max-map-count", + Image: "busybox:latest", + ImagePullPolicy: corev1.PullIfNotPresent, + SecurityContext: &corev1.SecurityContext{ + Privileged: helpers.BoolPtr(true), + RunAsUser: helpers.Int64Ptr(0), + }, + }, + }, PodSecurityContext: ServicePodSecurityContext{ HasDefault: true, FSGroup: 0, @@ -28,5 +55,9 @@ var opensearch = ServiceType{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/usr/share/opensearch/data", + BackupConfiguration: BackupConfiguration{ + Command: `/bin/sh -c "tar -cf - -C /usr/share/opensearch/data ."`, + FileExtension: ".{{ .OverrideName }}.tar", + }, }, } diff --git a/internal/servicetypes/postgres.go b/internal/servicetypes/postgres.go index 1f149aea..0515e856 100644 --- a/internal/servicetypes/postgres.go +++ b/internal/servicetypes/postgres.go @@ -3,6 +3,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" ) @@ -21,6 +22,53 @@ var postgresSingle = ServiceType{ }, }, }, + PrimaryContainer: ServiceContainer{ + Name: "postgres", + ImagePullPolicy: corev1.PullAlways, + Container: corev1.Container{ + Ports: []corev1.ContainerPort{ + { + Name: "5432-tcp", + ContainerPort: 5432, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 5432, + }, + }, + }, + InitialDelaySeconds: 1, + TimeoutSeconds: 1, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 5432, + }, + }, + }, + InitialDelaySeconds: 120, + PeriodSeconds: 5, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("100M"), + }, + }, + }, + }, + PodSecurityContext: ServicePodSecurityContext{ + HasDefault: true, + FSGroup: 0, + }, Strategy: appsv1.DeploymentStrategy{ Type: appsv1.RecreateDeploymentStrategyType, }, @@ -28,5 +76,9 @@ var postgresSingle = ServiceType{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/var/lib/postgresql/data", + BackupConfiguration: BackupConfiguration{ + Command: `/bin/sh -c "PGPASSWORD=${{ .OverrideName | FixServiceName }}_PASSWORD pg_dump --host=localhost --port=${{ .OverrideName | FixServiceName }}_SERVICE_PORT --dbname=${{ .OverrideName | FixServiceName }}_DB --username=${{ .OverrideName | FixServiceName }}_USER --format=t -w"`, + FileExtension: ".{{ .OverrideName }}.tar", + }, }, } diff --git a/internal/servicetypes/python.go b/internal/servicetypes/python.go index 427d22e5..fb0a524b 100644 --- a/internal/servicetypes/python.go +++ b/internal/servicetypes/python.go @@ -2,6 +2,7 @@ package servicetypes import ( corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -20,11 +21,59 @@ var python = ServiceType{ }, }, }, + PrimaryContainer: ServiceContainer{ + Name: "python", + ImagePullPolicy: corev1.PullAlways, + Container: corev1.Container{ + Ports: []corev1.ContainerPort{ + { + Name: "http", + ContainerPort: 8800, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 8800, + }, + }, + }, + InitialDelaySeconds: 1, + TimeoutSeconds: 1, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 3000, + }, + }, + }, + InitialDelaySeconds: 60, + TimeoutSeconds: 10, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("100M"), + }, + }, + }, + }, } var pythonPersistent = ServiceType{ Name: "python-persistent", Ports: python.Ports, + PrimaryContainer: ServiceContainer{ + Name: python.PrimaryContainer.Name, + ImagePullPolicy: python.PrimaryContainer.ImagePullPolicy, + Container: python.PrimaryContainer.Container, + }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteMany, diff --git a/internal/servicetypes/redis.go b/internal/servicetypes/redis.go index 29e342f7..3d1395a5 100644 --- a/internal/servicetypes/redis.go +++ b/internal/servicetypes/redis.go @@ -2,6 +2,7 @@ package servicetypes import ( corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -20,6 +21,49 @@ var redis = ServiceType{ }, }, }, + PrimaryContainer: ServiceContainer{ + Name: "redis", + ImagePullPolicy: corev1.PullAlways, + Container: corev1.Container{ + Ports: []corev1.ContainerPort{ + { + Name: "6379-tcp", + ContainerPort: 6379, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 6379, + }, + }, + }, + InitialDelaySeconds: 1, + TimeoutSeconds: 1, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 6379, + }, + }, + }, + InitialDelaySeconds: 120, + TimeoutSeconds: 10, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("100M"), + }, + }, + }, + }, } var redisPersistent = ServiceType{ @@ -29,5 +73,9 @@ var redisPersistent = ServiceType{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/data", + BackupConfiguration: BackupConfiguration{ + Command: `/bin/sh -c "/bin/busybox tar -cf - -C /data ."`, + FileExtension: ".{{ .OverrideName }}.tar", + }, }, } diff --git a/internal/servicetypes/solr.go b/internal/servicetypes/solr.go index 94810a58..6be63aff 100644 --- a/internal/servicetypes/solr.go +++ b/internal/servicetypes/solr.go @@ -2,6 +2,7 @@ package servicetypes import ( corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -20,9 +21,57 @@ var solr = ServiceType{ }, }, }, + PrimaryContainer: ServiceContainer{ + Name: "solr", + ImagePullPolicy: corev1.PullAlways, + Container: corev1.Container{ + Ports: []corev1.ContainerPort{ + { + Name: "tcp-8983", + ContainerPort: 8983, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 8983, + }, + }, + }, + InitialDelaySeconds: 1, + PeriodSeconds: 3, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 8983, + }, + }, + }, + InitialDelaySeconds: 90, + TimeoutSeconds: 3, + FailureThreshold: 5, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("100M"), + }, + }, + }, + }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/var/solr", + BackupConfiguration: BackupConfiguration{ + Command: `/bin/sh -c 'tar -cf - -C "/var/solr" --exclude="lost\+found" . || [ $? -eq 1 ]'`, + FileExtension: ".{{ .OverrideName }}.tar", + }, }, } diff --git a/internal/servicetypes/types.go b/internal/servicetypes/types.go index ba76d965..de49d8bd 100644 --- a/internal/servicetypes/types.go +++ b/internal/servicetypes/types.go @@ -29,13 +29,21 @@ type ServiceContainer struct { Volumes []corev1.Volume VolumeMounts []corev1.VolumeMount Command []string + Flags map[string]bool } type ServiceVolume struct { - PersistentVolumeSize string - PersistentVolumePath string - PersistentVolumeType corev1.PersistentVolumeAccessMode - Backup bool + PersistentVolumeSize string + PersistentVolumePath string + PersistentVolumeType corev1.PersistentVolumeAccessMode + SourceFromOtherService string + Backup bool + BackupConfiguration BackupConfiguration +} + +type BackupConfiguration struct { + Command string + FileExtension string } type ServicePorts struct { @@ -50,15 +58,22 @@ var ServiceTypes = map[string]ServiceType{ "cli": cli, "cli-persistent": cliPersistent, "elasticsearch": elasticsearch, - "opensearch": opensearch, "mariadb-single": mariadbSingle, "mongodb-single": mongodbSingle, - "postgres-single": postgresSingle, + "nginx": nginx, + "nginx-php": nginxPHP, + "nginx-php-persistent": nginxPHPPersistent, "node": node, "node-persistent": nodePersistent, + "opensearch": opensearch, + "postgres-single": postgresSingle, "python": python, "python-persistent": pythonPersistent, - "nginx": nginx, - "nginx-php": nginxPHP, - "nginx-php-persistent": nginxPHPPersistent, + "redis": redis, + "redis-persistent": redisPersistent, + "varnish": varnish, + "varnish-persistent": varnishPersistent, + "solr": solr, + "worker": worker, + "worker-persistent": workerPersistent, } diff --git a/internal/servicetypes/varnish.go b/internal/servicetypes/varnish.go new file mode 100644 index 00000000..4957ce21 --- /dev/null +++ b/internal/servicetypes/varnish.go @@ -0,0 +1,96 @@ +package servicetypes + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var varnish = ServiceType{ + Name: "varnish", + Ports: ServicePorts{ + CanChangePort: true, + Ports: []corev1.ServicePort{ + { + Port: 8080, + TargetPort: intstr.IntOrString{ + Type: intstr.String, + StrVal: "http", + }, + Protocol: corev1.ProtocolTCP, + Name: "http", + }, + { + Port: 6082, + TargetPort: intstr.IntOrString{ + Type: intstr.String, + StrVal: "controlport", + }, + Protocol: corev1.ProtocolTCP, + Name: "controlport", + }, + }, + }, + PrimaryContainer: ServiceContainer{ + Name: "varnish", + ImagePullPolicy: corev1.PullAlways, + Container: corev1.Container{ + Ports: []corev1.ContainerPort{ + { + Name: "http", + ContainerPort: 8080, + Protocol: corev1.ProtocolTCP, + }, + { + Name: "controlport", + ContainerPort: 6082, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 8080, + }, + }, + }, + InitialDelaySeconds: 1, + TimeoutSeconds: 1, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: 8080, + }, + }, + }, + InitialDelaySeconds: 60, + TimeoutSeconds: 10, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("100M"), + }, + }, + }, + }, +} + +var varnishPersistent = ServiceType{ + Name: "varnish-persistent", + Ports: varnish.Ports, + Volumes: ServiceVolume{ + PersistentVolumeSize: "5Gi", + PersistentVolumeType: corev1.ReadWriteOnce, + PersistentVolumePath: "/var/cache/varnish", + BackupConfiguration: BackupConfiguration{ + Command: `/bin/sh -c "/bin/busybox tar -cf - -C /var/cache/varnish ."`, + FileExtension: ".{{ .OverrideName }}.tar", + }, + }, +} diff --git a/internal/servicetypes/worker.go b/internal/servicetypes/worker.go new file mode 100644 index 00000000..142a5b94 --- /dev/null +++ b/internal/servicetypes/worker.go @@ -0,0 +1,10 @@ +package servicetypes + +var worker = ServiceType{ + Name: "worker", +} + +var workerPersistent = ServiceType{ + Name: "worker-persistent", + Volumes: ServiceVolume{}, +} From a7e705de5c85606b2ef217a3bf0ce996cd01b04c Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 21 Jul 2023 16:57:27 +1000 Subject: [PATCH 18/92] chore: update templating engines some more --- .../templating/services/template_helpers.go | 51 +++ .../services/templates_deployment.go | 256 ++++++++---- .../services/templates_deployment_test.go | 368 +++++++++++++----- internal/templating/services/templates_pvc.go | 36 +- .../templating/services/templates_pvc_test.go | 64 +-- .../templating/services/templates_service.go | 189 +++++---- .../services/templates_service_test.go | 81 +++- .../deployment/result-basic-1.yaml | 267 ++++++++++++- .../deployment/result-basic-2.yaml | 99 +++++ .../deployment/result-basic-3.yaml | 103 +++++ .../deployment/result-cli-1.yaml | 71 +++- .../deployment/result-elasticsearch-1.yaml | 172 ++++++++ .../deployment/result-nginx-1.yaml | 61 ++- .../deployment/result-opensearch-1.yaml | 172 ++++++++ .../deployment/result-postgres-single-1.yaml | 89 +++++ .../deployment/result-solr-1.yaml | 88 +++++ .../pvc/result-elasticsearch-1.yaml | 2 - .../pvc/result-opensearch-1.yaml | 2 - .../pvc/result-postgres-single-1.yaml | 29 ++ .../service/result-basic-2.yaml | 62 +++ .../service/result-nginx-php-1.yaml | 31 ++ 21 files changed, 1978 insertions(+), 315 deletions(-) create mode 100644 internal/templating/services/template_helpers.go create mode 100644 internal/templating/services/test-resources/deployment/result-basic-2.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-basic-3.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-solr-1.yaml create mode 100644 internal/templating/services/test-resources/pvc/result-postgres-single-1.yaml create mode 100644 internal/templating/services/test-resources/service/result-basic-2.yaml create mode 100644 internal/templating/services/test-resources/service/result-nginx-php-1.yaml diff --git a/internal/templating/services/template_helpers.go b/internal/templating/services/template_helpers.go new file mode 100644 index 00000000..26364d2d --- /dev/null +++ b/internal/templating/services/template_helpers.go @@ -0,0 +1,51 @@ +package services + +import ( + "github.com/uselagoon/build-deploy-tool/internal/generator" + "github.com/uselagoon/build-deploy-tool/internal/helpers" +) + +// LinkedServiceCalculator checks the provided services to see if there are any linked services +// linked services are mostly just `nginx-php` but lagoon has the possibility to support more than this in the future +func LinkedServiceCalculator(services []generator.ServiceValues) []generator.ServiceValues { + linkedMap := make(map[string][]generator.ServiceValues) + retServices := []generator.ServiceValues{} + linkedOrder := []string{} + + // go over the services twice to extract just the linked services (the override names will be the same in a linked service) + for _, s1 := range services { + for _, s2 := range services { + if s1.OverrideName == s2.OverrideName && s1.Name != s2.Name { + linkedMap[s1.OverrideName] = append(linkedMap[s1.OverrideName], s1) + linkedOrder = helpers.AppendIfMissing(linkedOrder, s1.OverrideName) + } + } + } + // go over the services again and any that are in the services that aren't in the linked map (again the override name is the key) + // add it as a standalone service + for _, s1 := range services { + if _, ok := linkedMap[s1.OverrideName]; !ok { + retServices = append(retServices, s1) + } + } + + // go over the linked services and add the linkedservice to the main service + // example would be adding the `php` service in docker-compose to the `nginx` service as a `LinkedService` definition + // this allows the generated service values to carry across + for _, name := range linkedOrder { + service := generator.ServiceValues{} + if len(linkedMap[name]) == 2 { + for idx, s := range linkedMap[name] { + if idx == 0 { + service = s + } + if idx == 1 { + service.LinkedService = &s + } + } + } + // then add it to the slice of services to return + retServices = append(retServices, service) + } + return retServices +} diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index 82df5fb7..b81671d7 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -2,15 +2,18 @@ package services import ( "fmt" + "strings" "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/servicetypes" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" apivalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" + "k8s.io/apimachinery/pkg/util/intstr" "sigs.k8s.io/yaml" ) @@ -36,21 +39,20 @@ func GenerateDeploymentTemplate( // add the default labels labels := map[string]string{ "app.kubernetes.io/managed-by": "build-deploy-tool", + "app.kubernetes.io/name": serviceTypeValues.Name, + "app.kubernetes.io/instance": serviceValues.OverrideName, "lagoon.sh/project": buildValues.Project, "lagoon.sh/environment": buildValues.Environment, "lagoon.sh/environmentType": buildValues.EnvironmentType, "lagoon.sh/buildType": buildValues.BuildType, - "app.kubernetes.io/name": serviceTypeValues.Name, - "app.kubernetes.io/instance": serviceValues.Name, "lagoon.sh/template": fmt.Sprintf("%s-%s", serviceTypeValues.Name, "0.1.0"), - "lagoon.sh/service": serviceValues.Name, + "lagoon.sh/service": serviceValues.OverrideName, "lagoon.sh/service-type": serviceTypeValues.Name, } // add the default annotations annotations := map[string]string{ - "lagoon.sh/version": buildValues.LagoonVersion, - "lagoon.sh/configMapSha": buildValues.ConfigMapSha, + "lagoon.sh/version": buildValues.LagoonVersion, } // add any additional labels @@ -64,13 +66,22 @@ func GenerateDeploymentTemplate( additionalAnnotations["lagoon.sh/prBaseBranch"] = buildValues.PRBaseBranch } + templateAnnotations := make(map[string]string) + templateAnnotations["lagoon.sh/configMapSha"] = buildValues.ConfigMapSha + if serviceTypeValues.Volumes.BackupConfiguration.Command != "" { + bc := servicetypes.BackupConfiguration{} + helpers.TemplateThings(serviceValues, serviceTypeValues.Volumes.BackupConfiguration, &bc) + templateAnnotations["k8up.syn.tools/backupcommand"] = bc.Command + templateAnnotations["k8up.syn.tools/file-extension"] = bc.FileExtension + } + deployment := &appsv1.Deployment{ TypeMeta: metav1.TypeMeta{ Kind: "Deployment", APIVersion: fmt.Sprintf("%s/%s", appsv1.SchemeGroupVersion.Group, appsv1.SchemeGroupVersion.Version), }, ObjectMeta: metav1.ObjectMeta{ - Name: serviceValues.Name, + Name: serviceValues.OverrideName, Labels: labels, Annotations: annotations, }, @@ -127,13 +138,13 @@ func GenerateDeploymentTemplate( // validate any annotations if err := apivalidation.ValidateAnnotations(deployment.ObjectMeta.Annotations, nil); err != nil { if len(err) != 0 { - return nil, fmt.Errorf("the annotations for %s are not valid: %v", serviceValues.Name, err) + return nil, fmt.Errorf("the annotations for %s are not valid: %v", serviceValues.OverrideName, err) } } // validate any labels if err := metavalidation.ValidateLabels(deployment.ObjectMeta.Labels, nil); err != nil { if len(err) != 0 { - return nil, fmt.Errorf("the labels for %s are not valid: %v", serviceValues.Name, err) + return nil, fmt.Errorf("the labels for %s are not valid: %v", serviceValues.OverrideName, err) } } // check length of labels @@ -143,11 +154,20 @@ func GenerateDeploymentTemplate( } // start deployment template - depMeta := metav1.ObjectMeta{ - Labels: deployment.ObjectMeta.Labels, - Annotations: deployment.ObjectMeta.Annotations, + deployment.Spec.Template.ObjectMeta = metav1.ObjectMeta{ + Labels: map[string]string{}, + Annotations: map[string]string{}, + } + for key, value := range deployment.ObjectMeta.Labels { + deployment.Spec.Template.ObjectMeta.Labels[key] = value + } + // add any additional annotations + for key, value := range deployment.ObjectMeta.Annotations { + deployment.Spec.Template.ObjectMeta.Annotations[key] = value + } + for key, value := range templateAnnotations { + deployment.Spec.Template.ObjectMeta.Annotations[key] = value } - deployment.Spec.Template.ObjectMeta = depMeta deployment.Spec.Replicas = helpers.Int32Ptr(1) if serviceValues.Replicas != 0 { deployment.Spec.Replicas = &serviceValues.Replicas @@ -155,7 +175,7 @@ func GenerateDeploymentTemplate( deployment.Spec.Selector = &metav1.LabelSelector{ MatchLabels: map[string]string{ "app.kubernetes.io/name": serviceTypeValues.Name, - "app.kubernetes.io/instance": serviceValues.Name, + "app.kubernetes.io/instance": serviceValues.OverrideName, }, } deployment.Spec.Strategy = serviceTypeValues.Strategy @@ -166,6 +186,15 @@ func GenerateDeploymentTemplate( // set the priority class deployment.Spec.Template.Spec.PriorityClassName = fmt.Sprintf("lagoon-priority-%s", buildValues.EnvironmentType) + // handle the podescurity from rootless workloads + if buildValues.PodSecurityContext.RunAsUser != 0 { + deployment.Spec.Template.Spec.SecurityContext = &corev1.PodSecurityContext{ + RunAsUser: helpers.Int64Ptr(buildValues.PodSecurityContext.RunAsUser), + RunAsGroup: helpers.Int64Ptr(buildValues.PodSecurityContext.RunAsGroup), + FSGroup: helpers.Int64Ptr(buildValues.PodSecurityContext.FsGroup), + } + } + // start set up any volumes this deployment can use // first handle any dynamic secret volumes that come from kubernetes secrets that are labeled for _, dsv := range buildValues.DynamicSecretVolumes { @@ -180,6 +209,7 @@ func GenerateDeploymentTemplate( } deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, volume) } + // if there is a persistent volume attached to this service, handle adding that here if serviceTypeValues.Volumes.PersistentVolumeSize != "" { volume := corev1.Volume{ @@ -190,9 +220,15 @@ func GenerateDeploymentTemplate( }, }, } + // if this servicetype has defaults, use them if one is not provided + if serviceValues.PersistentVolumePath == "" { + volume.Name = serviceValues.OverrideName + volume.VolumeSource.PersistentVolumeClaim.ClaimName = serviceValues.OverrideName + } deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, volume) } - // if there are any specific container overrides provided, handle those here + + // if there are any specific container volume overrides provided, handle those here for _, pcv := range serviceTypeValues.PrimaryContainer.Volumes { volume := corev1.Volume{} helpers.TemplateThings(serviceValues, pcv, &volume) @@ -203,6 +239,10 @@ func GenerateDeploymentTemplate( helpers.TemplateThings(serviceValues, scv, &volume) deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, volume) } + + // future handle any additional volume mounts here + // @TODO + // end set up any volumes this deployment can use // handle any image pull secrets @@ -215,35 +255,92 @@ func GenerateDeploymentTemplate( deployment.Spec.Template.Spec.ImagePullSecrets = pullsecrets // start working out the containers to add - // add any init containers - if serviceTypeValues.InitContainer.Name != "" && serviceValues.PodSecurityContext.RunAsUser == 10001 { + // add any init container that the service may have + if serviceTypeValues.InitContainer.Name != "" { + enableInit := false init := serviceTypeValues.InitContainer - for _, svm := range serviceTypeValues.InitContainer.VolumeMounts { - volumeMount := corev1.VolumeMount{} - helpers.TemplateThings(serviceValues, svm, &volumeMount) - init.Container.VolumeMounts = append(init.Container.VolumeMounts, volumeMount) + // check if the init container has any flags required to add it + for k, v := range buildValues.Flags { + if init.Flags[k] == v { + enableInit = true + } } - cmd := []string{} - for _, c := range init.Command { - var c2 string - helpers.TemplateThings(serviceValues, c, &c2) - cmd = append(cmd, c2) + // otherwise if there are no flags + if enableInit || init.Flags == nil { + for _, svm := range serviceTypeValues.InitContainer.VolumeMounts { + volumeMount := corev1.VolumeMount{} + helpers.TemplateThings(serviceValues, svm, &volumeMount) + init.Container.VolumeMounts = append(init.Container.VolumeMounts, volumeMount) + } + cmd := []string{} + for _, c := range init.Command { + var c2 string + helpers.TemplateThings(serviceValues, c, &c2) + cmd = append(cmd, c2) + } + init.Container.Command = cmd + deployment.Spec.Template.Spec.InitContainers = append(deployment.Spec.Template.Spec.InitContainers, init.Container) } - init.Container.Command = cmd - deployment.Spec.Template.Spec.InitContainers = append(deployment.Spec.Template.Spec.InitContainers, init.Container) } - // handle the primary container + // handle the primary container for the service type container := serviceTypeValues.PrimaryContainer - // if the service can change the port - if serviceTypeValues.Ports.CanChangePort { - // check if the port override is defined - if serviceValues.ServicePort != 0 { - // and change the port in the container definition to suit - container.Container.ReadinessProbe.ProbeHandler.TCPSocket.Port.IntVal = serviceValues.ServicePort - container.Container.LivenessProbe.ProbeHandler.TCPSocket.Port.IntVal = serviceValues.ServicePort - container.Container.ReadinessProbe.ProbeHandler.TCPSocket.Port.IntVal = serviceValues.ServicePort - container.Container.Ports[0].ContainerPort = serviceValues.ServicePort + // if the service is set to consume the additional service ports only, then generate those here + if serviceValues.AdditionalServicePorts != nil { + // nulify the existing ports + container.Container.Ports = []corev1.ContainerPort{} + // start compose service port override templating here + for idx, addPort := range serviceValues.AdditionalServicePorts { + if idx == 0 { + // first port in the docker compose file should be a tcp based port (default unless udp or other is provided in the docker-compose file) + // the first port in the list will be used for any liveness/readiness probes, and will override the default option the container has + switch addPort.ServicePort.Protocol { + case "tcp": + container.Container.ReadinessProbe = &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: int32(addPort.ServicePort.Target), + }, + }, + }, + InitialDelaySeconds: 1, // @TODO make the timeout/delays configurable? + TimeoutSeconds: 1, + } + container.Container.LivenessProbe = &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: int32(addPort.ServicePort.Target), + }, + }, + }, + InitialDelaySeconds: 60, // @TODO make the timeout/delays configurable? + TimeoutSeconds: 10, + } + default: + return nil, fmt.Errorf("first port defined is not a tcp port, please ensure the first port is tcp") + } + } + // set the ports into the container + container.Container.Ports = append(container.Container.Ports, corev1.ContainerPort{ + Name: addPort.ServiceName, + ContainerPort: int32(addPort.ServicePort.Target), + Protocol: corev1.Protocol(strings.ToUpper(addPort.ServicePort.Protocol)), + }) + } + } else { + // otherwise if the service has a default port, and it can be changed, handle changing it here + if serviceTypeValues.Ports.CanChangePort { + // check if the port override is defined + if serviceValues.ServicePort != 0 { + // and change the port in the container definition to suit + container.Container.ReadinessProbe.ProbeHandler.TCPSocket.Port.IntVal = serviceValues.ServicePort + container.Container.LivenessProbe.ProbeHandler.TCPSocket.Port.IntVal = serviceValues.ServicePort + container.Container.Ports[0].ContainerPort = serviceValues.ServicePort + } } } @@ -293,6 +390,11 @@ func GenerateDeploymentTemplate( Name: serviceValues.PersistentVolumeName, MountPath: serviceValues.PersistentVolumePath, } + // if this servicetype has a default volume path, use them it if one isn't provided + if serviceValues.PersistentVolumePath == "" { + volumeMount.MountPath = serviceTypeValues.Volumes.PersistentVolumePath + volumeMount.Name = serviceValues.OverrideName + } container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) } for _, svm := range serviceTypeValues.PrimaryContainer.VolumeMounts { @@ -300,6 +402,41 @@ func GenerateDeploymentTemplate( helpers.TemplateThings(serviceValues, svm, &volumeMount) container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) } + if serviceValues.PersistentVolumeName != "" && serviceValues.PersistentVolumePath != "" && serviceTypeValues.Volumes.PersistentVolumeSize == "" { + container.Container.VolumeMounts = append(container.Container.VolumeMounts, corev1.VolumeMount{ + Name: serviceValues.PersistentVolumeName, + MountPath: serviceValues.PersistentVolumePath, + }) + volume := corev1.Volume{ + Name: serviceValues.PersistentVolumeName, + VolumeSource: corev1.VolumeSource{ + PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ + ClaimName: serviceValues.PersistentVolumeName, + }, + }, + } + deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, volume) + } + + if buildValues.Resources.Limits.Memory != "" { + if container.Container.Resources.Limits == nil { + container.Container.Resources.Limits = corev1.ResourceList{} + } + container.Container.Resources.Limits[corev1.ResourceMemory] = resource.MustParse(buildValues.Resources.Limits.Memory) + } + if buildValues.Resources.Limits.EphemeralStorage != "" { + if container.Container.Resources.Limits == nil { + container.Container.Resources.Limits = corev1.ResourceList{} + } + container.Container.Resources.Limits[corev1.ResourceEphemeralStorage] = resource.MustParse(buildValues.Resources.Limits.EphemeralStorage) + } + if buildValues.Resources.Requests.EphemeralStorage != "" { + if container.Container.Resources.Requests == nil { + container.Container.Resources.Requests = corev1.ResourceList{} + } + container.Container.Resources.Requests[corev1.ResourceEphemeralStorage] = resource.MustParse(buildValues.Resources.Requests.EphemeralStorage) + } + // append the final defined container to the spec deployment.Spec.Template.Spec.Containers = append(deployment.Spec.Template.Spec.Containers, container.Container) @@ -375,48 +512,3 @@ func GenerateDeploymentTemplate( } return result, nil } - -// LinkedServiceCalculator checks the provided services to see if there are any linked services -// linked services are mostly just `nginx-php` but lagoon has the possibility to support more than this in the future -func LinkedServiceCalculator(services []generator.ServiceValues) []generator.ServiceValues { - linkedMap := make(map[string][]generator.ServiceValues) - retServices := []generator.ServiceValues{} - linkedOrder := []string{} - - // go over the services twice to extract just the linked services (the override names will be the same in a linked service) - for _, s1 := range services { - for _, s2 := range services { - if s1.OverrideName == s2.OverrideName && s1.Name != s2.Name { - linkedMap[s1.OverrideName] = append(linkedMap[s1.OverrideName], s1) - linkedOrder = helpers.AppendIfMissing(linkedOrder, s1.OverrideName) - } - } - } - // go over the services again and any that are in the services that aren't in the linked map (again the override name is the key) - // add it as a standalone service - for _, s1 := range services { - if _, ok := linkedMap[s1.OverrideName]; !ok { - retServices = append(retServices, s1) - } - } - - // go over the linked services and add the linkedservice to the main service - // example would be adding the `php` service in docker-compose to the `nginx` service as a `LinkedService` definition - // this allows the generated service values to carry across - for _, name := range linkedOrder { - service := generator.ServiceValues{} - if len(linkedMap[name]) == 2 { - for idx, s := range linkedMap[name] { - if idx == 0 { - service = s - } - if idx == 1 { - service.LinkedService = &s - } - } - } - // then add it to the slice of services to return - retServices = append(retServices, service) - } - return retServices -} diff --git a/internal/templating/services/templates_deployment_test.go b/internal/templating/services/templates_deployment_test.go index 7b3fed8a..72d10ebb 100644 --- a/internal/templating/services/templates_deployment_test.go +++ b/internal/templating/services/templates_deployment_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/andreyvit/diff" + "github.com/compose-spec/compose-go/types" "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/lagoon" ) @@ -80,35 +81,33 @@ func TestGenerateDeploymentTemplate(t *testing.T) { UseSpotInstances: true, // template should have spot instance label and toleration/selector/affinity Replicas: 2, }, - // { - // Name: "myservice-persist", - // OverrideName: "myservice-persist", - // Type: "basic-persistent", - // DBaaSEnvironment: "production", - // PersistentVolumeSize: "5Gi", - // PersistentVolumePath: "/storage/data", - // PersistentVolumeName: "basic", - // }, - // { - // Name: "myservice-persist-po", - // OverrideName: "myservice-persist-po", - // Type: "basic-persistent", - // DBaaSEnvironment: "production", - // ServicePort: 8080, - // PersistentVolumeSize: "5Gi", - // PersistentVolumePath: "/storage/data", - // PersistentVolumeName: "basic", - // }, - // { - // Name: "myservice-persist-po", - // OverrideName: "myservice-persist-po", - // Type: "basic-persistent", - // DBaaSEnvironment: "production", - // ServicePort: 8080, - // PersistentVolumeSize: "100Gi", - // PersistentVolumePath: "/storage/data", - // PersistentVolumeName: "basic", - // }, + { + Name: "myservice-persist", + OverrideName: "myservice-persist", + Type: "basic-persistent", + DBaaSEnvironment: "production", + PersistentVolumePath: "/storage/data", + PersistentVolumeName: "basic", + }, + { + Name: "myservice-persist-po", + OverrideName: "myservice-persist-po", + Type: "basic-persistent", + DBaaSEnvironment: "production", + ServicePort: 8080, + PersistentVolumePath: "/storage/data", + PersistentVolumeName: "basic", + }, + { + Name: "myservice-persist-po", + OverrideName: "myservice-persist-po", + Type: "basic-persistent", + DBaaSEnvironment: "production", + ServicePort: 8080, + PersistentVolumeSize: "100Gi", + PersistentVolumePath: "/storage/data", + PersistentVolumeName: "basic", + }, }, }, }, @@ -131,6 +130,14 @@ func TestGenerateDeploymentTemplate(t *testing.T) { Name: "lagoon-internal-registry-secret", }, }, + Flags: map[string]bool{ + "rootlessworkloads": true, + }, + PodSecurityContext: generator.PodSecurityContext{ + RunAsGroup: 0, + RunAsUser: 10001, + FsGroup: 10000, + }, GitSha: "0", ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", Services: []generator.ServiceValues{ @@ -150,17 +157,16 @@ func TestGenerateDeploymentTemplate(t *testing.T) { }, { Name: "nginx2", - OverrideName: "nginx2", + OverrideName: "nginx-2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", ImageName: "harbor.example.com/example-project/environment-name/nginx2@latest", - PersistentVolumeSize: "10Gi", PersistentVolumePath: "/storage/data", PersistentVolumeName: "nginx2", }, { Name: "php2", - OverrideName: "nginx2", + OverrideName: "nginx-2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", ImageName: "harbor.example.com/example-project/environment-name/php2@latest", @@ -206,79 +212,245 @@ func TestGenerateDeploymentTemplate(t *testing.T) { Type: "cli-persistent", DBaaSEnvironment: "production", ImageName: "harbor.example.com/example-project/environment-name/myservice-persistent@latest", - PersistentVolumeSize: "10Gi", PersistentVolumePath: "/storage/data", - PersistentVolumeName: "myservice-persistent", + PersistentVolumeName: "nginx-php", }, }, }, }, want: "test-resources/deployment/result-cli-1.yaml", }, - // { - // name: "test3 - elasticsearch", - // 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: "elasticsearch", - // DBaaSEnvironment: "production", - // PersistentVolumeSize: "5Gi", - // }, - // { - // Name: "myservice-size", - // OverrideName: "myservice-size", - // Type: "elasticsearch", - // DBaaSEnvironment: "production", - // PersistentVolumeSize: "100Gi", - // }, - // }, - // }, - // }, - // want: "test-resources/deployment/result-elasticsearch-1.yaml", - // }, - // { - // name: "test4 - opensearch", - // 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: "opensearch", - // DBaaSEnvironment: "production", - // PersistentVolumeSize: "5Gi", - // }, - // { - // Name: "myservice-size", - // OverrideName: "myservice-size", - // Type: "opensearch", - // DBaaSEnvironment: "production", - // PersistentVolumeSize: "100Gi", - // }, - // }, - // }, - // }, - // want: "test-resources/deployment/result-opensearch-1.yaml", - // }, + { + name: "test5 - postgres-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", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + Services: []generator.ServiceValues{ + { + Name: "myservice", + OverrideName: "myservice", + Type: "postgres-single", + DBaaSEnvironment: "development", + }, + }, + }, + }, + want: "test-resources/deployment/result-postgres-single-1.yaml", + }, + { + name: "test3 - elasticsearch", + 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: "elasticsearch", + DBaaSEnvironment: "production", + PersistentVolumeSize: "5Gi", + }, + { + Name: "myservice-size", + OverrideName: "myservice-size", + Type: "elasticsearch", + DBaaSEnvironment: "production", + PersistentVolumeSize: "100Gi", + }, + }, + }, + }, + want: "test-resources/deployment/result-elasticsearch-1.yaml", + }, + { + name: "test4 - opensearch", + 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: "opensearch", + DBaaSEnvironment: "production", + PersistentVolumeSize: "5Gi", + }, + { + Name: "myservice-size", + OverrideName: "myservice-size", + Type: "opensearch", + DBaaSEnvironment: "production", + PersistentVolumeSize: "100Gi", + }, + }, + }, + }, + want: "test-resources/deployment/result-opensearch-1.yaml", + }, + { + name: "test5 - basic compose ports", + 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", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + GitSha: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + Services: []generator.ServiceValues{ + { + Name: "myservice-po", + OverrideName: "myservice-po", + Type: "basic", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/myservice-po@latest", + AdditionalServicePorts: []generator.AdditionalServicePort{ + { + ServiceName: "myservice-po-8191", + ServicePort: types.ServicePortConfig{ + Target: 8191, + Protocol: "tcp", + }, + }, + { + ServiceName: "myservice-po-8211", + ServicePort: types.ServicePortConfig{ + Target: 8211, + Protocol: "tcp", + }, + }, + }, + UseSpotInstances: true, // template should have spot instance label and toleration/selector/affinity + Replicas: 2, + }, + }, + }, + }, + want: "test-resources/deployment/result-basic-2.yaml", + }, + { + name: "test5 - solr", + 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", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + Services: []generator.ServiceValues{ + { + Name: "solr", + OverrideName: "solr", + Type: "solr", + DBaaSEnvironment: "development", + }, + }, + }, + }, + want: "test-resources/deployment/result-solr-1.yaml", + }, + { + name: "test7 - basic resources", + 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", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + Resources: generator.Resources{ + Limits: generator.ResourceLimits{ + Memory: "16Gi", + EphemeralStorage: "160Gi", + }, + Requests: generator.ResourceRequests{ + EphemeralStorage: "1Gi", + }, + }, + GitSha: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + Services: []generator.ServiceValues{ + { + Name: "myservice-po", + OverrideName: "myservice-po", + Type: "basic", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/myservice-po@latest", + AdditionalServicePorts: []generator.AdditionalServicePort{ + { + ServiceName: "myservice-po-8191", + ServicePort: types.ServicePortConfig{ + Target: 8191, + Protocol: "tcp", + }, + }, + { + ServiceName: "myservice-po-8211", + ServicePort: types.ServicePortConfig{ + Target: 8211, + Protocol: "tcp", + }, + }, + }, + UseSpotInstances: true, // template should have spot instance label and toleration/selector/affinity + Replicas: 2, + }, + }, + }, + }, + want: "test-resources/deployment/result-basic-3.yaml", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/templating/services/templates_pvc.go b/internal/templating/services/templates_pvc.go index 8bc6aa97..1ad26997 100644 --- a/internal/templating/services/templates_pvc.go +++ b/internal/templating/services/templates_pvc.go @@ -48,26 +48,32 @@ func GeneratePVCTemplate( } + // check linked services + checkedServices := LinkedServiceCalculator(buildValues.Services) + // for all the services that the build values generated - // iterate over them and generate any kubernetes pvcs - for _, serviceValues := range buildValues.Services { + // iterate over them and generate any kubernetes services + for _, serviceValues := range checkedServices { if val, ok := servicetypes.ServiceTypes[serviceValues.Type]; ok { if val.Volumes.PersistentVolumeSize != "" { - if serviceValues.PersistentVolumeSize == "" { - return nil, fmt.Errorf("no persistent volume size defined for this service") + serviceTypeValues := &servicetypes.ServiceType{} + helpers.DeepCopy(val, serviceTypeValues) + persistentVolumeSize := serviceTypeValues.Volumes.PersistentVolumeSize + if serviceValues.PersistentVolumeSize != "" { + persistentVolumeSize = serviceValues.PersistentVolumeSize } serviceType := &servicetypes.ServiceType{} helpers.DeepCopy(val, serviceType) var pvcBytes []byte additionalLabels["app.kubernetes.io/name"] = serviceType.Name - additionalLabels["app.kubernetes.io/instance"] = serviceValues.Name + additionalLabels["app.kubernetes.io/instance"] = serviceValues.OverrideName additionalLabels["lagoon.sh/template"] = fmt.Sprintf("%s-%s", serviceType.Name, "0.1.0") - additionalLabels["lagoon.sh/service"] = serviceValues.Name + additionalLabels["lagoon.sh/service"] = serviceValues.OverrideName additionalLabels["lagoon.sh/service-type"] = serviceType.Name - additionalAnnotations["k8up.syn.tools/backup"] = strconv.FormatBool(val.Volumes.Backup) - additionalAnnotations["k8up.io/backup"] = strconv.FormatBool(val.Volumes.Backup) + additionalAnnotations["k8up.syn.tools/backup"] = strconv.FormatBool(serviceTypeValues.Volumes.Backup) + additionalAnnotations["k8up.io/backup"] = strconv.FormatBool(serviceTypeValues.Volumes.Backup) pvc := &corev1.PersistentVolumeClaim{ TypeMeta: metav1.TypeMeta{ @@ -75,7 +81,7 @@ func GeneratePVCTemplate( APIVersion: corev1.SchemeGroupVersion.Version, }, ObjectMeta: metav1.ObjectMeta{ - Name: serviceValues.Name, + Name: serviceValues.OverrideName, }, } pvc.ObjectMeta.Labels = labels @@ -90,13 +96,13 @@ func GeneratePVCTemplate( // validate any annotations if err := apivalidation.ValidateAnnotations(pvc.ObjectMeta.Annotations, nil); err != nil { if len(err) != 0 { - return nil, fmt.Errorf("the annotations for %s are not valid: %v", serviceValues.Name, err) + return nil, fmt.Errorf("the annotations for %s are not valid: %v", serviceValues.OverrideName, err) } } // validate any labels if err := metavalidation.ValidateLabels(pvc.ObjectMeta.Labels, nil); err != nil { if len(err) != 0 { - return nil, fmt.Errorf("the labels for %s are not valid: %v", serviceValues.Name, err) + return nil, fmt.Errorf("the labels for %s are not valid: %v", serviceValues.OverrideName, err) } } // check length of labels @@ -106,22 +112,24 @@ func GeneratePVCTemplate( } // start PVC template - q, err := resource.ParseQuantity(serviceValues.PersistentVolumeSize) + q, err := resource.ParseQuantity(persistentVolumeSize) if err != nil { return nil, fmt.Errorf("provided persistent volume size is not valid: %v", err) } volumeSize, _ := q.AsInt64() pvc.Spec = corev1.PersistentVolumeClaimSpec{ AccessModes: []corev1.PersistentVolumeAccessMode{ - val.Volumes.PersistentVolumeType, + serviceTypeValues.Volumes.PersistentVolumeType, }, - StorageClassName: helpers.StrPtr("bulk"), Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ "storage": *resource.NewQuantity(volumeSize, resource.BinarySI), }, }, } + if serviceTypeValues.Volumes.PersistentVolumeType == corev1.ReadWriteMany { + pvc.Spec.StorageClassName = helpers.StrPtr("bulk") + } // end PVC template pvcBytes, err = yaml.Marshal(pvc) diff --git a/internal/templating/services/templates_pvc_test.go b/internal/templating/services/templates_pvc_test.go index dd8ceaca..4e94f330 100644 --- a/internal/templating/services/templates_pvc_test.go +++ b/internal/templating/services/templates_pvc_test.go @@ -46,19 +46,17 @@ func TestGeneratePVCTemplate(t *testing.T) { ServicePort: 8080, }, { - Name: "myservice-persist", - OverrideName: "myservice-persist", - Type: "basic-persistent", - DBaaSEnvironment: "development", - PersistentVolumeSize: "5Gi", + Name: "myservice-persist", + OverrideName: "myservice-persist", + Type: "basic-persistent", + DBaaSEnvironment: "development", }, { - Name: "myservice-persist-po", - OverrideName: "myservice-persist-po", - Type: "basic-persistent", - DBaaSEnvironment: "development", - ServicePort: 8080, - PersistentVolumeSize: "5Gi", + Name: "myservice-persist-po", + OverrideName: "myservice-persist-po", + Type: "basic-persistent", + DBaaSEnvironment: "development", + ServicePort: 8080, }, { Name: "myservice-persist-po", @@ -74,7 +72,7 @@ func TestGeneratePVCTemplate(t *testing.T) { want: "test-resources/pvc/result-basic-1.yaml", }, { - name: "test2 - cli", + name: "test2 - cli (no volumes)", args: args{ buildValues: generator.BuildValues{ Project: "example-project", @@ -117,11 +115,10 @@ func TestGeneratePVCTemplate(t *testing.T) { Branch: "environment-name", Services: []generator.ServiceValues{ { - Name: "myservice", - OverrideName: "myservice", - Type: "elasticsearch", - DBaaSEnvironment: "development", - PersistentVolumeSize: "5Gi", + Name: "myservice", + OverrideName: "myservice", + Type: "elasticsearch", + DBaaSEnvironment: "development", }, { Name: "myservice-size", @@ -149,11 +146,10 @@ func TestGeneratePVCTemplate(t *testing.T) { Branch: "environment-name", Services: []generator.ServiceValues{ { - Name: "myservice", - OverrideName: "myservice", - Type: "opensearch", - DBaaSEnvironment: "development", - PersistentVolumeSize: "5Gi", + Name: "myservice", + OverrideName: "myservice", + Type: "opensearch", + DBaaSEnvironment: "development", }, { Name: "myservice-size", @@ -167,6 +163,30 @@ func TestGeneratePVCTemplate(t *testing.T) { }, want: "test-resources/pvc/result-opensearch-1.yaml", }, + { + name: "test5 - postgres-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: "postgres-single", + DBaaSEnvironment: "development", + }, + }, + }, + }, + want: "test-resources/pvc/result-postgres-single-1.yaml", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/templating/services/templates_service.go b/internal/templating/services/templates_service.go index 24113b8d..789ec70d 100644 --- a/internal/templating/services/templates_service.go +++ b/internal/templating/services/templates_service.go @@ -10,14 +10,17 @@ import ( apivalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" + "k8s.io/apimachinery/pkg/util/intstr" "sigs.k8s.io/yaml" ) +var separator = []byte("---\n") + // GenerateServiceTemplate generates the lagoon template to apply. func GenerateServiceTemplate( buildValues generator.BuildValues, ) ([]byte, error) { - separator := []byte("---\n") + var result []byte // add the default labels @@ -46,86 +49,130 @@ func GenerateServiceTemplate( } + // check linked services + checkedServices := LinkedServiceCalculator(buildValues.Services) + // for all the services that the build values generated // iterate over them and generate any kubernetes services - for _, serviceValues := range buildValues.Services { + for _, serviceValues := range checkedServices { if val, ok := servicetypes.ServiceTypes[serviceValues.Type]; ok { - // if the service default has no ports, then don't generate any services - if val.Ports.Ports != nil { - serviceType := &servicetypes.ServiceType{} - helpers.DeepCopy(val, serviceType) - - var serviceBytes []byte - additionalLabels["app.kubernetes.io/name"] = serviceType.Name - additionalLabels["app.kubernetes.io/instance"] = serviceValues.Name - additionalLabels["lagoon.sh/template"] = fmt.Sprintf("%s-%s", serviceType.Name, "0.1.0") - additionalLabels["lagoon.sh/service"] = serviceValues.Name - additionalLabels["lagoon.sh/service-type"] = serviceType.Name - service := &corev1.Service{ - TypeMeta: metav1.TypeMeta{ - Kind: "Service", - APIVersion: corev1.SchemeGroupVersion.Version, - }, - ObjectMeta: metav1.ObjectMeta{ - Name: serviceValues.Name, - }, - } - service.ObjectMeta.Labels = labels - service.ObjectMeta.Annotations = annotations - for key, value := range additionalLabels { - service.ObjectMeta.Labels[key] = value - } - // add any additional annotations - for key, value := range additionalAnnotations { - service.ObjectMeta.Annotations[key] = value - } - // validate any annotations - if err := apivalidation.ValidateAnnotations(service.ObjectMeta.Annotations, nil); err != nil { - if len(err) != 0 { - return nil, fmt.Errorf("the annotations for %s are not valid: %v", serviceValues.Name, err) - } - } - // validate any labels - if err := metavalidation.ValidateLabels(service.ObjectMeta.Labels, nil); err != nil { - if len(err) != 0 { - return nil, fmt.Errorf("the labels for %s are not valid: %v", serviceValues.Name, err) + if serviceValues.AdditionalServicePorts != nil { + // if the service is set to consume the additional services only, then generate those here + for _, addPort := range serviceValues.AdditionalServicePorts { + // copy the service type so we can transform it as required + serviceType := &servicetypes.ServiceType{} + helpers.DeepCopy(val, serviceType) + restoreResult, err := GenerateService(result, serviceType, serviceValues, addPort, labels, annotations, additionalLabels, additionalAnnotations) + if err != nil { + return nil, err } + result = append(result, restoreResult[:]...) } - // check length of labels - err := helpers.CheckLabelLength(service.ObjectMeta.Labels) - if err != nil { - return nil, err - } - - // start service template - if serviceType.Ports.CanChangePort { - if serviceValues.ServicePort != 0 { - serviceType.Ports.Ports[0].Port = serviceValues.ServicePort + } else { + // if the service default has no ports, then don't generate any services + if val.Ports.Ports != nil { + // otherwise handle creating the default service port here + // copy the service type so we can transform it as required + serviceType := &servicetypes.ServiceType{} + helpers.DeepCopy(val, serviceType) + restoreResult, err := GenerateService(result, serviceType, serviceValues, generator.AdditionalServicePort{}, labels, annotations, additionalLabels, additionalAnnotations) + if err != nil { + return nil, err } + result = append(result, restoreResult[:]...) } + } + } + } + return result, nil +} - service.Spec = corev1.ServiceSpec{ - Ports: serviceType.Ports.Ports, - } +func GenerateService(result []byte, serviceType *servicetypes.ServiceType, serviceValues generator.ServiceValues, portOverride generator.AdditionalServicePort, labels, annotations, additionalLabels, additionalAnnotations map[string]string) ([]byte, error) { + var serviceBytes []byte + additionalLabels["app.kubernetes.io/name"] = serviceType.Name + additionalLabels["app.kubernetes.io/instance"] = serviceValues.OverrideName + additionalLabels["lagoon.sh/template"] = fmt.Sprintf("%s-%s", serviceType.Name, "0.1.0") + additionalLabels["lagoon.sh/service"] = serviceValues.OverrideName + additionalLabels["lagoon.sh/service-type"] = serviceType.Name + service := &corev1.Service{ + TypeMeta: metav1.TypeMeta{ + Kind: "Service", + APIVersion: corev1.SchemeGroupVersion.Version, + }, + ObjectMeta: metav1.ObjectMeta{ + Name: serviceValues.OverrideName, + }, + } + if portOverride.ServiceName != "" { + service.ObjectMeta.Name = portOverride.ServiceName + } + service.ObjectMeta.Labels = labels + service.ObjectMeta.Annotations = annotations + for key, value := range additionalLabels { + service.ObjectMeta.Labels[key] = value + } + // add any additional annotations + for key, value := range additionalAnnotations { + service.ObjectMeta.Annotations[key] = value + } + // validate any annotations + if err := apivalidation.ValidateAnnotations(service.ObjectMeta.Annotations, nil); err != nil { + if len(err) != 0 { + return nil, fmt.Errorf("the annotations for %s are not valid: %v", serviceValues.OverrideName, err) + } + } + // validate any labels + if err := metavalidation.ValidateLabels(service.ObjectMeta.Labels, nil); err != nil { + if len(err) != 0 { + return nil, fmt.Errorf("the labels for %s are not valid: %v", serviceValues.OverrideName, err) + } + } + // check length of labels + err := helpers.CheckLabelLength(service.ObjectMeta.Labels) + if err != nil { + return nil, err + } - service.Spec.Selector = map[string]string{ - "app.kubernetes.io/name": serviceType.Name, - "app.kubernetes.io/instance": serviceValues.Name, - } - // end service template + // start service template + if serviceType.Ports.CanChangePort { + if serviceValues.ServicePort != 0 { + serviceType.Ports.Ports[0].Port = serviceValues.ServicePort + } + } - serviceBytes, err = yaml.Marshal(service) - if err != nil { - return nil, err - } - // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) - // add the seperator to the template so that it can be `kubectl apply` in bulk as part - // of the current build process - // join all dbaas-consumer templates together - restoreResult := append(separator[:], serviceBytes[:]...) - result = append(result, restoreResult[:]...) - } + // start compose service port override templating here + if portOverride.ServicePort.Target != 0 { + switch portOverride.ServicePort.Protocol { + case "udp": + serviceType.Ports.Ports[0].Protocol = corev1.ProtocolUDP + } + serviceType.Ports.Ports[0].Name = portOverride.ServiceName + serviceType.Ports.Ports[0].TargetPort = intstr.IntOrString{ + StrVal: portOverride.ServiceName, + Type: intstr.String, } + serviceType.Ports.Ports[0].Port = int32(portOverride.ServicePort.Target) } - return result, nil + // end compose service port override templating here + + service.Spec = corev1.ServiceSpec{ + Ports: serviceType.Ports.Ports, + } + + service.Spec.Selector = map[string]string{ + "app.kubernetes.io/name": serviceType.Name, + "app.kubernetes.io/instance": serviceValues.OverrideName, + } + // end service template + + serviceBytes, err = yaml.Marshal(service) + if err != nil { + return nil, err + } + // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) + // add the seperator to the template so that it can be `kubectl apply` in bulk as part + // of the current build process + // join all dbaas-consumer templates together + restoreResult := append(separator[:], serviceBytes[:]...) + return restoreResult, nil } diff --git a/internal/templating/services/templates_service_test.go b/internal/templating/services/templates_service_test.go index 06b2350b..3df754c4 100644 --- a/internal/templating/services/templates_service_test.go +++ b/internal/templating/services/templates_service_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/andreyvit/diff" + "github.com/compose-spec/compose-go/types" "github.com/uselagoon/build-deploy-tool/internal/generator" ) @@ -126,7 +127,7 @@ func TestGenerateServiceTemplate(t *testing.T) { want: "test-resources/service/result-elasticsearch-1.yaml", }, { - name: "test3 - opensearch", + name: "test4 - opensearch", args: args{ buildValues: generator.BuildValues{ Project: "example-project", @@ -157,6 +158,84 @@ func TestGenerateServiceTemplate(t *testing.T) { }, want: "test-resources/service/result-opensearch-1.yaml", }, + { + name: "test5 - basic compose ports", + 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-po", + OverrideName: "myservice-po", + Type: "basic", + DBaaSEnvironment: "development", + AdditionalServicePorts: []generator.AdditionalServicePort{ + generator.AdditionalServicePort{ + ServicePort: types.ServicePortConfig{ + Target: 8191, + Protocol: "tcp", + }, + ServiceName: "myservice-po-8191", + }, + }, + }, + { + Name: "myservice-persist-po", + OverrideName: "myservice-persist-po", + Type: "basic-persistent", + DBaaSEnvironment: "development", + AdditionalServicePorts: []generator.AdditionalServicePort{ + generator.AdditionalServicePort{ + ServicePort: types.ServicePortConfig{ + Target: 8191, + Protocol: "tcp", + }, + ServiceName: "myservice-persist-po-8191", + }, + }, + }, + }, + }, + }, + want: "test-resources/service/result-basic-2.yaml", + }, + { + name: "test6 - nginx-php", + 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: "nginx-php", + DBaaSEnvironment: "development", + LinkedService: &generator.ServiceValues{ + Name: "myservice-php", + OverrideName: "myservice", + Type: "nginx-php", + DBaaSEnvironment: "production", + }, + }, + }, + }, + }, + want: "test-resources/service/result-nginx-php-1.yaml", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/templating/services/test-resources/deployment/result-basic-1.yaml b/internal/templating/services/test-resources/deployment/result-basic-1.yaml index 8a812a1a..dda8846e 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-1.yaml @@ -4,7 +4,6 @@ kind: Deployment metadata: annotations: lagoon.sh/branch: environment-name - lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -72,7 +71,10 @@ spec: tcpSocket: port: 3000 timeoutSeconds: 1 - resources: {} + resources: + requests: + cpu: 10m + memory: 100M enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret @@ -84,7 +86,6 @@ kind: Deployment metadata: annotations: lagoon.sh/branch: environment-name - lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -159,7 +160,10 @@ spec: tcpSocket: port: 8080 timeoutSeconds: 1 - resources: {} + resources: + requests: + cpu: 10m + memory: 100M enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret @@ -172,3 +176,258 @@ spec: key: lagoon.sh/spot operator: Exists status: {} +--- +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-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: myservice-persist +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: myservice-persist + app.kubernetes.io/name: basic-persistent + strategy: {} + 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-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 3000 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 3000 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 3000 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /storage/data + name: basic + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: basic + persistentVolumeClaim: + claimName: basic +status: {} +--- +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-persist-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist-po + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: myservice-persist-po +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: myservice-persist-po + app.kubernetes.io/name: basic-persistent + strategy: {} + 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-persist-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist-po + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + 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: 100M + volumeMounts: + - mountPath: /storage/data + name: basic + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: basic + persistentVolumeClaim: + claimName: basic +status: {} +--- +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-persist-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist-po + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: myservice-persist-po +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: myservice-persist-po + app.kubernetes.io/name: basic-persistent + strategy: {} + 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-persist-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist-po + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + 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: 100M + volumeMounts: + - mountPath: /storage/data + name: basic + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: basic + persistentVolumeClaim: + claimName: basic +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-basic-2.yaml b/internal/templating/services/test-resources/deployment/result-basic-2.yaml new file mode 100644 index 00000000..ddb6bb2b --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-basic-2.yaml @@ -0,0 +1,99 @@ +--- +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-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-po + lagoon.sh/service-type: basic + lagoon.sh/spot: "true" + lagoon.sh/template: basic-0.1.0 + name: myservice-po +spec: + replicas: 2 + selector: + matchLabels: + app.kubernetes.io/instance: myservice-po + app.kubernetes.io/name: basic + strategy: {} + 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-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-po + lagoon.sh/service-type: basic + lagoon.sh/spot: "true" + lagoon.sh/template: basic-0.1.0 + spec: + affinity: + nodeAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - preference: + matchExpressions: + - key: lagoon.sh/spot + operator: Exists + weight: 1 + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice-po@latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8191 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 8191 + name: myservice-po-8191 + protocol: TCP + - containerPort: 8211 + name: myservice-po-8211 + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8191 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + tolerations: + - effect: NoSchedule + key: lagoon.sh/spot + operator: Exists + - effect: PreferNoSchedule + key: lagoon.sh/spot + operator: Exists +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-basic-3.yaml b/internal/templating/services/test-resources/deployment/result-basic-3.yaml new file mode 100644 index 00000000..628afdd8 --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-basic-3.yaml @@ -0,0 +1,103 @@ +--- +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-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-po + lagoon.sh/service-type: basic + lagoon.sh/spot: "true" + lagoon.sh/template: basic-0.1.0 + name: myservice-po +spec: + replicas: 2 + selector: + matchLabels: + app.kubernetes.io/instance: myservice-po + app.kubernetes.io/name: basic + strategy: {} + 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-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-po + lagoon.sh/service-type: basic + lagoon.sh/spot: "true" + lagoon.sh/template: basic-0.1.0 + spec: + affinity: + nodeAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - preference: + matchExpressions: + - key: lagoon.sh/spot + operator: Exists + weight: 1 + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice-po@latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8191 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 8191 + name: myservice-po-8191 + protocol: TCP + - containerPort: 8211 + name: myservice-po-8211 + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8191 + timeoutSeconds: 1 + resources: + limits: + ephemeral-storage: 160Gi + memory: 16Gi + requests: + cpu: 10m + ephemeral-storage: 1Gi + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + tolerations: + - effect: NoSchedule + key: lagoon.sh/spot + operator: Exists + - effect: PreferNoSchedule + key: lagoon.sh/spot + operator: Exists +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-cli-1.yaml b/internal/templating/services/test-resources/deployment/result-cli-1.yaml index f69f4e5e..108ab2d4 100644 --- a/internal/templating/services/test-resources/deployment/result-cli-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-cli-1.yaml @@ -4,7 +4,6 @@ kind: Deployment metadata: annotations: lagoon.sh/branch: environment-name - lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -54,12 +53,38 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice@latest - name: "" - resources: {} + name: cli + ports: + - containerPort: 3000 + name: http + protocol: TCP + readinessProbe: + exec: + command: + - /bin/sh + - -c + - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; + fi + failureThreshold: 3 + initialDelaySeconds: 5 + periodSeconds: 2 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production + volumes: + - name: lagoon-sshkey + secret: + defaultMode: 420 + secretName: lagoon-sshkey status: {} --- apiVersion: apps/v1 @@ -67,7 +92,6 @@ kind: Deployment metadata: annotations: lagoon.sh/branch: environment-name - lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -117,10 +141,45 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice-persistent@latest - name: "" - resources: {} + name: cli + ports: + - containerPort: 3000 + name: http + protocol: TCP + readinessProbe: + exec: + command: + - /bin/sh + - -c + - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; + fi + failureThreshold: 3 + initialDelaySeconds: 5 + periodSeconds: 2 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + - mountPath: /storage/data/php + name: nginx-php-twig + - mountPath: /storage/data + name: nginx-php enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production + volumes: + - name: lagoon-sshkey + secret: + defaultMode: 420 + secretName: lagoon-sshkey + - emptyDir: {} + name: nginx-php-twig + - name: nginx-php + persistentVolumeClaim: + claimName: nginx-php status: {} diff --git a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml index e69de29b..340a57d3 100644 --- a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml @@ -0,0 +1,172 @@ +--- +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: elasticsearch + 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: elasticsearch + lagoon.sh/template: elasticsearch-0.1.0 + name: myservice +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: myservice + app.kubernetes.io/name: elasticsearch + strategy: {} + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c "tar -cf - -C /usr/share/elasticsearch/data + ." + k8up.syn.tools/file-extension: .myservice.tar + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: "" + 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: elasticsearch + 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: elasticsearch + lagoon.sh/template: elasticsearch-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + name: "" + resources: {} + volumeMounts: + - mountPath: /usr/share/elasticsearch/data + name: myservice + enableServiceLinks: false + initContainers: + - command: + - sh + - -c + - |- + set -xe + DESIRED="262144" + CURRENT=$(sysctl -n vm.max_map_count) + if [ "$DESIRED" -gt "$CURRENT" ]; then + sysctl -w vm.max_map_count=$DESIRED + fi + image: busybox:latest + imagePullPolicy: IfNotPresent + name: set-max-map-count + resources: {} + securityContext: + privileged: true + runAsUser: 0 + priorityClassName: lagoon-priority-production + volumes: + - name: myservice + persistentVolumeClaim: + claimName: myservice +status: {} +--- +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-size + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: elasticsearch + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-size + lagoon.sh/service-type: elasticsearch + lagoon.sh/template: elasticsearch-0.1.0 + name: myservice-size +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: myservice-size + app.kubernetes.io/name: elasticsearch + strategy: {} + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c "tar -cf - -C /usr/share/elasticsearch/data + ." + k8up.syn.tools/file-extension: .myservice-size.tar + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: "" + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: myservice-size + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: elasticsearch + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-size + lagoon.sh/service-type: elasticsearch + lagoon.sh/template: elasticsearch-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + name: "" + resources: {} + volumeMounts: + - mountPath: /usr/share/elasticsearch/data + name: myservice-size + enableServiceLinks: false + initContainers: + - command: + - sh + - -c + - |- + set -xe + DESIRED="262144" + CURRENT=$(sysctl -n vm.max_map_count) + if [ "$DESIRED" -gt "$CURRENT" ]; then + sysctl -w vm.max_map_count=$DESIRED + fi + image: busybox:latest + imagePullPolicy: IfNotPresent + name: set-max-map-count + resources: {} + securityContext: + privileged: true + runAsUser: 0 + priorityClassName: lagoon-priority-production + volumes: + - name: myservice-size + persistentVolumeClaim: + claimName: myservice-size +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml index 6f2cc20d..a52bf387 100644 --- a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml @@ -4,7 +4,6 @@ kind: Deployment metadata: annotations: lagoon.sh/branch: environment-name - lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -74,7 +73,10 @@ spec: port: 50000 initialDelaySeconds: 1 timeoutSeconds: 3 - resources: {} + resources: + requests: + cpu: 10m + memory: 10M - env: - name: NGINX_FASTCGI_PASS value: 127.0.0.1 @@ -99,11 +101,18 @@ spec: periodSeconds: 10 tcpSocket: port: 9000 - resources: {} + resources: + requests: + cpu: 10m + memory: 100M enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10000 + runAsGroup: 0 + runAsUser: 10001 status: {} --- apiVersion: apps/v1 @@ -111,26 +120,25 @@ kind: Deployment metadata: annotations: lagoon.sh/branch: environment-name - lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null labels: - app.kubernetes.io/instance: nginx2 + app.kubernetes.io/instance: nginx-2 app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: nginx-php-persistent lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project - lagoon.sh/service: nginx2 + lagoon.sh/service: nginx-2 lagoon.sh/service-type: nginx-php-persistent lagoon.sh/template: nginx-php-persistent-0.1.0 - name: nginx2 + name: nginx-2 spec: replicas: 1 selector: matchLabels: - app.kubernetes.io/instance: nginx2 + app.kubernetes.io/instance: nginx-2 app.kubernetes.io/name: nginx-php-persistent strategy: {} template: @@ -141,14 +149,14 @@ spec: lagoon.sh/version: v2.x.x creationTimestamp: null labels: - app.kubernetes.io/instance: nginx2 + app.kubernetes.io/instance: nginx-2 app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: nginx-php-persistent lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project - lagoon.sh/service: nginx2 + lagoon.sh/service: nginx-2 lagoon.sh/service-type: nginx-php-persistent lagoon.sh/template: nginx-php-persistent-0.1.0 spec: @@ -181,7 +189,10 @@ spec: port: 50000 initialDelaySeconds: 1 timeoutSeconds: 3 - resources: {} + resources: + requests: + cpu: 10m + memory: 10M volumeMounts: - mountPath: /storage/data name: nginx2 @@ -209,16 +220,40 @@ spec: periodSeconds: 10 tcpSocket: port: 9000 - resources: {} + resources: + requests: + cpu: 10m + memory: 100M volumeMounts: - mountPath: /storage/data name: nginx2 - - mountPath: nginx2/php + - mountPath: /storage/data/php name: nginx2-twig enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret + initContainers: + - command: + - sh + - -c + - "set -e\nSENTINEL=\"/storage/.lagoon-rootless-migration-complete\"\nif ! + [ -f \"$SENTINEL\" ]; then\n\tfind /storage -exec chown 0:0 {} +\n\tfind + /storage -exec chmod a+r,u+w {} +\n\tfind /storage -type d -exec chmod a+x + {} +\n\ttouch \"$SENTINEL\"\nfi" + image: busybox:musl + imagePullPolicy: IfNotPresent + name: fix-storage-permissions + resources: {} + securityContext: + runAsUser: 0 + volumeMounts: + - mountPath: /storage + name: nginx2 priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10000 + runAsGroup: 0 + runAsUser: 10001 volumes: - name: nginx2 persistentVolumeClaim: diff --git a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml index e69de29b..3d254632 100644 --- a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml @@ -0,0 +1,172 @@ +--- +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: opensearch + 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: opensearch + lagoon.sh/template: opensearch-0.1.0 + name: myservice +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: myservice + app.kubernetes.io/name: opensearch + strategy: {} + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c "tar -cf - -C /usr/share/opensearch/data + ." + k8up.syn.tools/file-extension: .myservice.tar + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: "" + 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: opensearch + 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: opensearch + lagoon.sh/template: opensearch-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + name: opensearch + resources: {} + volumeMounts: + - mountPath: /usr/share/opensearch/data + name: myservice + enableServiceLinks: false + initContainers: + - command: + - sh + - -c + - |- + set -xe + DESIRED="262144" + CURRENT=$(sysctl -n vm.max_map_count) + if [ "$DESIRED" -gt "$CURRENT" ]; then + sysctl -w vm.max_map_count=$DESIRED + fi + image: busybox:latest + imagePullPolicy: IfNotPresent + name: set-max-map-count + resources: {} + securityContext: + privileged: true + runAsUser: 0 + priorityClassName: lagoon-priority-production + volumes: + - name: myservice + persistentVolumeClaim: + claimName: myservice +status: {} +--- +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-size + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: opensearch + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-size + lagoon.sh/service-type: opensearch + lagoon.sh/template: opensearch-0.1.0 + name: myservice-size +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: myservice-size + app.kubernetes.io/name: opensearch + strategy: {} + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c "tar -cf - -C /usr/share/opensearch/data + ." + k8up.syn.tools/file-extension: .myservice-size.tar + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: "" + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: myservice-size + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: opensearch + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-size + lagoon.sh/service-type: opensearch + lagoon.sh/template: opensearch-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + name: opensearch + resources: {} + volumeMounts: + - mountPath: /usr/share/opensearch/data + name: myservice-size + enableServiceLinks: false + initContainers: + - command: + - sh + - -c + - |- + set -xe + DESIRED="262144" + CURRENT=$(sysctl -n vm.max_map_count) + if [ "$DESIRED" -gt "$CURRENT" ]; then + sysctl -w vm.max_map_count=$DESIRED + fi + image: busybox:latest + imagePullPolicy: IfNotPresent + name: set-max-map-count + resources: {} + securityContext: + privileged: true + runAsUser: 0 + priorityClassName: lagoon-priority-production + volumes: + - name: myservice-size + persistentVolumeClaim: + claimName: myservice-size +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml new file mode 100644 index 00000000..b7701094 --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml @@ -0,0 +1,89 @@ +--- +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: postgres-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: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + name: myservice +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: myservice + app.kubernetes.io/name: postgres-single + strategy: + type: Recreate + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c "PGPASSWORD=$MYSERVICE_PASSWORD pg_dump + --host=localhost --port=$MYSERVICE_SERVICE_PORT --dbname=$MYSERVICE_DB --username=$MYSERVICE_USER + --format=t -w" + k8up.syn.tools/file-extension: .myservice.tar + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: "" + 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: postgres-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: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 5432 + name: postgres + ports: + - containerPort: 5432 + name: 5432-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 5432 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: myservice + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: myservice + persistentVolumeClaim: + claimName: myservice +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-solr-1.yaml b/internal/templating/services/test-resources/deployment/result-solr-1.yaml new file mode 100644 index 00000000..e1b870f4 --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-solr-1.yaml @@ -0,0 +1,88 @@ +--- +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: solr + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: solr-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: solr + lagoon.sh/service-type: solr-php-persistent + lagoon.sh/template: solr-php-persistent-0.1.0 + name: solr +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: solr + app.kubernetes.io/name: solr-php-persistent + strategy: {} + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c 'tar -cf - -C "/var/solr" --exclude="lost\+found" + . || [ $? -eq 1 ]' + k8up.syn.tools/file-extension: .solr.tar + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: "" + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: solr + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: solr-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: solr + lagoon.sh/service-type: solr-php-persistent + lagoon.sh/template: solr-php-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + livenessProbe: + failureThreshold: 5 + initialDelaySeconds: 90 + tcpSocket: + port: 8983 + timeoutSeconds: 3 + name: solr + ports: + - containerPort: 8983 + name: tcp-8983 + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + periodSeconds: 3 + tcpSocket: + port: 8983 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/solr + name: solr + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: solr + persistentVolumeClaim: + claimName: solr +status: {} diff --git a/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml index 4e14e632..c7fe23c8 100644 --- a/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml +++ b/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml @@ -26,7 +26,6 @@ spec: resources: requests: storage: 5Gi - storageClassName: bulk status: {} --- apiVersion: v1 @@ -56,5 +55,4 @@ spec: resources: requests: storage: 100Gi - storageClassName: bulk status: {} diff --git a/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml b/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml index b4ae8aa1..bba20827 100644 --- a/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml @@ -26,7 +26,6 @@ spec: resources: requests: storage: 5Gi - storageClassName: bulk status: {} --- apiVersion: v1 @@ -56,5 +55,4 @@ spec: resources: requests: storage: 100Gi - storageClassName: bulk status: {} diff --git a/internal/templating/services/test-resources/pvc/result-postgres-single-1.yaml b/internal/templating/services/test-resources/pvc/result-postgres-single-1.yaml new file mode 100644 index 00000000..459a6246 --- /dev/null +++ b/internal/templating/services/test-resources/pvc/result-postgres-single-1.yaml @@ -0,0 +1,29 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + 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: postgres-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: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + name: myservice +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi +status: {} diff --git a/internal/templating/services/test-resources/service/result-basic-2.yaml b/internal/templating/services/test-resources/service/result-basic-2.yaml new file mode 100644 index 00000000..11ef5d26 --- /dev/null +++ b/internal/templating/services/test-resources/service/result-basic-2.yaml @@ -0,0 +1,62 @@ +--- +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-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-po + lagoon.sh/service-type: basic + lagoon.sh/template: basic-0.1.0 + name: myservice-po-8191 +spec: + ports: + - name: myservice-po-8191 + port: 8191 + protocol: TCP + targetPort: myservice-po-8191 + selector: + app.kubernetes.io/instance: myservice-po + app.kubernetes.io/name: basic +status: + loadBalancer: {} +--- +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-persist-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist-po + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: myservice-persist-po-8191 +spec: + ports: + - name: myservice-persist-po-8191 + port: 8191 + protocol: TCP + targetPort: myservice-persist-po-8191 + selector: + app.kubernetes.io/instance: myservice-persist-po + app.kubernetes.io/name: basic-persistent +status: + loadBalancer: {} diff --git a/internal/templating/services/test-resources/service/result-nginx-php-1.yaml b/internal/templating/services/test-resources/service/result-nginx-php-1.yaml new file mode 100644 index 00000000..071689b6 --- /dev/null +++ b/internal/templating/services/test-resources/service/result-nginx-php-1.yaml @@ -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: nginx-php + 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: nginx-php + lagoon.sh/template: nginx-php-0.1.0 + name: myservice +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: http + selector: + app.kubernetes.io/instance: myservice + app.kubernetes.io/name: nginx-php +status: + loadBalancer: {} From 7a98bd62d9fb3825a8bceb95b24416139987c463 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 21 Jul 2023 16:57:53 +1000 Subject: [PATCH 19/92] chore: remove unneeded helmchart templates --- .../templates/deployment.yaml | 91 ---------- .../basic-persistent/templates/pvc.yaml | 16 -- .../basic-persistent/templates/service.yaml | 17 -- .../basic/templates/deployment.yaml | 88 ---------- .../helmcharts/basic/templates/service.yaml | 17 -- .../cli-persistent/templates/deployment.yaml | 104 ----------- .../helmcharts/cli/templates/deployment.yaml | 95 ----------- .../templates/deployment.yaml | 161 ------------------ .../nginx-php-persistent/templates/pvc.yaml | 16 -- .../templates/service.yaml | 17 -- .../nginx-php/templates/deployment.yaml | 124 -------------- .../nginx-php/templates/service.yaml | 17 -- .../nginx/templates/deployment.yaml | 89 ---------- .../helmcharts/nginx/templates/service.yaml | 17 -- .../postgres-single/templates/deployment.yaml | 91 ---------- .../postgres-single/templates/pvc.yaml | 16 -- .../postgres-single/templates/service.yaml | 17 -- .../templates/deployment.yaml | 97 ----------- .../redis-persistent/templates/pvc.yaml | 15 -- .../redis-persistent/templates/service.yaml | 17 -- .../redis/templates/deployment.yaml | 86 ---------- .../helmcharts/redis/templates/service.yaml | 17 -- .../helmcharts/solr/templates/deployment.yaml | 81 --------- legacy/helmcharts/solr/templates/pvc.yaml | 15 -- legacy/helmcharts/solr/templates/service.yaml | 17 -- .../templates/deployment.yaml | 96 ----------- .../varnish-persistent/templates/pvc.yaml | 15 -- .../varnish-persistent/templates/service.yaml | 21 --- .../varnish/templates/deployment.yaml | 85 --------- .../helmcharts/varnish/templates/service.yaml | 21 --- .../templates/deployment.yaml | 97 ----------- .../worker/templates/deployment.yaml | 88 ---------- 32 files changed, 1761 deletions(-) delete mode 100644 legacy/helmcharts/basic-persistent/templates/deployment.yaml delete mode 100644 legacy/helmcharts/basic-persistent/templates/pvc.yaml delete mode 100644 legacy/helmcharts/basic-persistent/templates/service.yaml delete mode 100644 legacy/helmcharts/basic/templates/deployment.yaml delete mode 100644 legacy/helmcharts/basic/templates/service.yaml delete mode 100644 legacy/helmcharts/cli-persistent/templates/deployment.yaml delete mode 100644 legacy/helmcharts/cli/templates/deployment.yaml delete mode 100644 legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml delete mode 100644 legacy/helmcharts/nginx-php-persistent/templates/pvc.yaml delete mode 100644 legacy/helmcharts/nginx-php-persistent/templates/service.yaml delete mode 100644 legacy/helmcharts/nginx-php/templates/deployment.yaml delete mode 100644 legacy/helmcharts/nginx-php/templates/service.yaml delete mode 100644 legacy/helmcharts/nginx/templates/deployment.yaml delete mode 100644 legacy/helmcharts/nginx/templates/service.yaml delete mode 100644 legacy/helmcharts/postgres-single/templates/deployment.yaml delete mode 100644 legacy/helmcharts/postgres-single/templates/pvc.yaml delete mode 100644 legacy/helmcharts/postgres-single/templates/service.yaml delete mode 100644 legacy/helmcharts/redis-persistent/templates/deployment.yaml delete mode 100644 legacy/helmcharts/redis-persistent/templates/pvc.yaml delete mode 100644 legacy/helmcharts/redis-persistent/templates/service.yaml delete mode 100644 legacy/helmcharts/redis/templates/deployment.yaml delete mode 100644 legacy/helmcharts/redis/templates/service.yaml delete mode 100644 legacy/helmcharts/solr/templates/deployment.yaml delete mode 100644 legacy/helmcharts/solr/templates/pvc.yaml delete mode 100644 legacy/helmcharts/solr/templates/service.yaml delete mode 100644 legacy/helmcharts/varnish-persistent/templates/deployment.yaml delete mode 100644 legacy/helmcharts/varnish-persistent/templates/pvc.yaml delete mode 100644 legacy/helmcharts/varnish-persistent/templates/service.yaml delete mode 100644 legacy/helmcharts/varnish/templates/deployment.yaml delete mode 100644 legacy/helmcharts/varnish/templates/service.yaml delete mode 100644 legacy/helmcharts/worker-persistent/templates/deployment.yaml delete mode 100644 legacy/helmcharts/worker/templates/deployment.yaml diff --git a/legacy/helmcharts/basic-persistent/templates/deployment.yaml b/legacy/helmcharts/basic-persistent/templates/deployment.yaml deleted file mode 100644 index 5a158d67..00000000 --- a/legacy/helmcharts/basic-persistent/templates/deployment.yaml +++ /dev/null @@ -1,91 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "basic-persistent.fullname" . }} - labels: - {{- include "basic-persistent.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "basic-persistent.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "basic-persistent.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "basic-persistent.labels" . | nindent 8 }} - {{- include "basic-persistent.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "basic-persistent.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ include "basic-persistent.persistentStorageName" . }} - persistentVolumeClaim: - claimName: {{ include "basic-persistent.persistentStorageName" . }} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - priorityClassName: {{ include "basic-persistent.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - name: http - containerPort: {{ .Values.service.port }} - protocol: TCP - readinessProbe: - tcpSocket: - port: {{ .Values.service.port }} - initialDelaySeconds: 1 - timeoutSeconds: 1 - livenessProbe: - tcpSocket: - port: {{ .Values.service.port }} - initialDelaySeconds: 60 - periodSeconds: 10 - env: - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - envFrom: - - configMapRef: - name: lagoon-env - volumeMounts: - - name: {{ include "basic-persistent.persistentStorageName" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/basic-persistent/templates/pvc.yaml b/legacy/helmcharts/basic-persistent/templates/pvc.yaml deleted file mode 100644 index dbd65121..00000000 --- a/legacy/helmcharts/basic-persistent/templates/pvc.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "basic-persistent.persistentStorageName" . }} - labels: - {{- include "basic-persistent.labels" . | nindent 4 }} - annotations: - k8up.syn.tools/backup: "true" - {{- include "basic-persistent.annotations" . | nindent 4 }} -spec: - accessModes: - - ReadWriteMany - storageClassName: bulk - resources: - requests: - storage: {{ .Values.persistentStorage.size | quote }} diff --git a/legacy/helmcharts/basic-persistent/templates/service.yaml b/legacy/helmcharts/basic-persistent/templates/service.yaml deleted file mode 100644 index 176dd0c8..00000000 --- a/legacy/helmcharts/basic-persistent/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "basic-persistent.fullname" . }} - labels: - {{- include "basic-persistent.labels" . | nindent 4 }} - annotations: - {{- include "basic-persistent.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "basic-persistent.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/basic/templates/deployment.yaml b/legacy/helmcharts/basic/templates/deployment.yaml deleted file mode 100644 index 5fe66595..00000000 --- a/legacy/helmcharts/basic/templates/deployment.yaml +++ /dev/null @@ -1,88 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "basic.fullname" . }} - labels: - {{- include "basic.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "basic.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "basic.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "basic.labels" . | nindent 8 }} - {{- include "basic.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "basic.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - priorityClassName: {{ include "basic.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- if .Values.dynamicSecretVolumes }} - volumes: - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - name: http - containerPort: {{ .Values.service.port }} - protocol: TCP - readinessProbe: - tcpSocket: - port: {{ .Values.service.port }} - initialDelaySeconds: 1 - timeoutSeconds: 1 - livenessProbe: - tcpSocket: - port: {{ .Values.service.port }} - initialDelaySeconds: 60 - periodSeconds: 10 - env: - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- if .Values.dynamicSecretMounts }} - volumeMounts: - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/basic/templates/service.yaml b/legacy/helmcharts/basic/templates/service.yaml deleted file mode 100644 index 1edd2850..00000000 --- a/legacy/helmcharts/basic/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "basic.fullname" . }} - labels: - {{- include "basic.labels" . | nindent 4 }} - annotations: - {{- include "basic.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "basic.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/cli-persistent/templates/deployment.yaml b/legacy/helmcharts/cli-persistent/templates/deployment.yaml deleted file mode 100644 index 86935666..00000000 --- a/legacy/helmcharts/cli-persistent/templates/deployment.yaml +++ /dev/null @@ -1,104 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "cli-persistent.fullname" . }} - labels: - {{- include "cli-persistent.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "cli-persistent.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "cli-persistent.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "cli-persistent.labels" . | nindent 8 }} - {{- include "cli-persistent.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "cli-persistent.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - - name: {{ .Values.persistentStorage.name }} - persistentVolumeClaim: - claimName: {{ .Values.persistentStorage.name }} - - name: {{ include "cli-persistent.twig-storage.name" . | quote }} - emptyDir: {} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - priorityClassName: {{ include "cli-persistent.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - image: {{ .Values.image | quote }} - name: {{ include "cli-persistent.fullname" . }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - env: - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ .Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - name: {{ .Values.persistentStorage.name }} - mountPath: {{ .Values.persistentStorage.path | quote }} - - name: {{ include "cli-persistent.twig-storage.name" . | quote }} - mountPath: {{ include "cli-persistent.twig-storage.path" . | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - readinessProbe: - initialDelaySeconds: 5 - periodSeconds: 2 - failureThreshold: 3 - exec: - command: - - "/bin/sh" - - "-c" - - > - if [ -x /bin/entrypoint-readiness ]; then - /bin/entrypoint-readiness; - fi - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/cli/templates/deployment.yaml b/legacy/helmcharts/cli/templates/deployment.yaml deleted file mode 100644 index dc4b9fe7..00000000 --- a/legacy/helmcharts/cli/templates/deployment.yaml +++ /dev/null @@ -1,95 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "cli.fullname" . }} - labels: - {{- include "cli.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "cli.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "cli.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "cli.labels" . | nindent 8 }} - {{- include "cli.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "cli.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - priorityClassName: {{ include "cli.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - containers: - - image: {{ .Values.image | quote }} - name: {{ include "cli.fullname" . }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - env: - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ .Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml .Values.resources | nindent 12 }} - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - readinessProbe: - initialDelaySeconds: 5 - periodSeconds: 2 - failureThreshold: 3 - exec: - command: - - "/bin/sh" - - "-c" - - > - if [ -x /bin/entrypoint-readiness ]; then - /bin/entrypoint-readiness; - fi - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml b/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml deleted file mode 100644 index 579f1158..00000000 --- a/legacy/helmcharts/nginx-php-persistent/templates/deployment.yaml +++ /dev/null @@ -1,161 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "nginx-php-persistent.fullname" . }} - labels: - {{- include "nginx-php-persistent.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "nginx-php-persistent.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "nginx-php-persistent.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "nginx-php-persistent.labels" . | nindent 8 }} - {{- include "nginx-php-persistent.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "nginx-php-persistent.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ include "nginx-php-persistent.persistentStorageName" . }} - persistentVolumeClaim: - claimName: {{ include "nginx-php-persistent.persistentStorageName" . }} - - name: {{ include "nginx-php-persistent.twig-storage.name" . | quote }} - emptyDir: {} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - priorityClassName: {{ include "nginx-php-persistent.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{/* This is a test for "rootless" configuration. It will be true if the ROOTLESS_WORKLOAD feature flag is enabled. */}} - {{- if eq (int .Values.podSecurityContext.fsGroup) 10001 }} - # This initContainer sets permissions on the RWX storage compatible with - # the pod securityContext. - initContainers: - - command: - - "sh" - - "-c" - - | - set -e - SENTINEL="/storage/.lagoon-rootless-migration-complete" - if ! [ -f "$SENTINEL" ]; then - find /storage -exec chown {{ .Values.podSecurityContext.runAsUser }}:0 {} + - find /storage -exec chmod a+r,u+w {} + - find /storage -type d -exec chmod a+x {} + - touch "$SENTINEL" - fi - image: busybox:musl - imagePullPolicy: IfNotPresent - name: fix-storage-permissions - securityContext: - runAsUser: 0 - volumeMounts: - - mountPath: /storage - name: {{ include "nginx-php-persistent.persistentStorageName" . }} - {{- end }} - containers: - - image: {{ .Values.images.nginx | quote }} - name: "nginx" - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - name: http - containerPort: 8080 - protocol: TCP - readinessProbe: - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 1 - timeoutSeconds: 3 - livenessProbe: - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 90 - timeoutSeconds: 3 - failureThreshold: 5 - env: - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: NGINX_FASTCGI_PASS - value: '127.0.0.1' - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - envFrom: - - configMapRef: - name: lagoon-env - volumeMounts: - - name: {{ include "nginx-php-persistent.persistentStorageName" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources.nginx | nindent 12 }} - - - image: {{ .Values.images.php | quote }} - name: "php" - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - containerPort: 9000 - protocol: TCP - readinessProbe: - tcpSocket: - port: 9000 - initialDelaySeconds: 2 - periodSeconds: 10 - livenessProbe: - tcpSocket: - port: 9000 - initialDelaySeconds: 60 - periodSeconds: 10 - envFrom: - - configMapRef: - name: lagoon-env - env: - # LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - # This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: NGINX_FASTCGI_PASS - value: '127.0.0.1' - volumeMounts: - - name: {{ include "nginx-php-persistent.persistentStorageName" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - - name: {{ include "nginx-php-persistent.twig-storage.name" . | quote }} - mountPath: {{ include "nginx-php-persistent.twig-storage.path" . | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources.php | nindent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/nginx-php-persistent/templates/pvc.yaml b/legacy/helmcharts/nginx-php-persistent/templates/pvc.yaml deleted file mode 100644 index b186a58c..00000000 --- a/legacy/helmcharts/nginx-php-persistent/templates/pvc.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "nginx-php-persistent.persistentStorageName" . }} - labels: - {{- include "nginx-php-persistent.labels" . | nindent 4 }} - annotations: - {{- include "nginx-php-persistent.annotations" . | nindent 4 }} - k8up.syn.tools/backup: "true" -spec: - accessModes: - - ReadWriteMany - storageClassName: bulk - resources: - requests: - storage: {{ .Values.persistentStorage.size | quote }} diff --git a/legacy/helmcharts/nginx-php-persistent/templates/service.yaml b/legacy/helmcharts/nginx-php-persistent/templates/service.yaml deleted file mode 100644 index 3c7abf66..00000000 --- a/legacy/helmcharts/nginx-php-persistent/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "nginx-php-persistent.fullname" . }} - labels: - {{- include "nginx-php-persistent.labels" . | nindent 4 }} - annotations: - {{- include "nginx-php-persistent.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "nginx-php-persistent.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/nginx-php/templates/deployment.yaml b/legacy/helmcharts/nginx-php/templates/deployment.yaml deleted file mode 100644 index c8eba938..00000000 --- a/legacy/helmcharts/nginx-php/templates/deployment.yaml +++ /dev/null @@ -1,124 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "nginx-php.fullname" . }} - labels: - {{- include "nginx-php.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "nginx-php.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "nginx-php.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "nginx-php.labels" . | nindent 8 }} - {{- include "nginx-php.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "nginx-php.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - priorityClassName: {{ include "nginx-php.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- if .Values.dynamicSecretVolumes }} - volumes: - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - containers: - - image: {{ .Values.images.nginx | quote }} - name: "nginx" - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - name: http - containerPort: 8080 - protocol: TCP - readinessProbe: - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 1 - timeoutSeconds: 3 - livenessProbe: - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 90 - timeoutSeconds: 3 - failureThreshold: 5 - env: - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: NGINX_FASTCGI_PASS - value: '127.0.0.1' - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml .Values.resources.nginx | nindent 12 }} - {{- if .Values.dynamicSecretMounts }} - volumeMounts: - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - - - image: {{ .Values.images.php | quote }} - name: "php" - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - containerPort: 9000 - protocol: TCP - readinessProbe: - tcpSocket: - port: 9000 - initialDelaySeconds: 2 - periodSeconds: 10 - livenessProbe: - tcpSocket: - port: 9000 - initialDelaySeconds: 60 - periodSeconds: 10 - envFrom: - - configMapRef: - name: lagoon-env - env: - # LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - # This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: NGINX_FASTCGI_PASS - value: '127.0.0.1' - resources: - {{- toYaml .Values.resources.php | nindent 12 }} - {{- if .Values.dynamicSecretMounts }} - volumeMounts: - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/nginx-php/templates/service.yaml b/legacy/helmcharts/nginx-php/templates/service.yaml deleted file mode 100644 index 651bdff4..00000000 --- a/legacy/helmcharts/nginx-php/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "nginx-php.fullname" . }} - labels: - {{- include "nginx-php.labels" . | nindent 4 }} - annotations: - {{- include "nginx-php.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "nginx-php.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/nginx/templates/deployment.yaml b/legacy/helmcharts/nginx/templates/deployment.yaml deleted file mode 100644 index 726d1b08..00000000 --- a/legacy/helmcharts/nginx/templates/deployment.yaml +++ /dev/null @@ -1,89 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "nginx.fullname" . }} - labels: - {{- include "nginx.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "nginx.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "nginx.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "nginx.labels" . | nindent 8 }} - {{- include "nginx.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "nginx.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- if .Values.dynamicSecretVolumes }} - volumes: - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - name: http - containerPort: 8080 - protocol: TCP - readinessProbe: - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 1 - timeoutSeconds: 3 - livenessProbe: - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 90 - timeoutSeconds: 3 - failureThreshold: 5 - env: - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- if .Values.dynamicSecretMounts }} - volumeMounts: - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/nginx/templates/service.yaml b/legacy/helmcharts/nginx/templates/service.yaml deleted file mode 100644 index 293c3741..00000000 --- a/legacy/helmcharts/nginx/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "nginx.fullname" . }} - labels: - {{- include "nginx.labels" . | nindent 4 }} - annotations: - {{- include "nginx.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "nginx.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/postgres-single/templates/deployment.yaml b/legacy/helmcharts/postgres-single/templates/deployment.yaml deleted file mode 100644 index 0ed14996..00000000 --- a/legacy/helmcharts/postgres-single/templates/deployment.yaml +++ /dev/null @@ -1,91 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "postgres-single.fullname" . }} - labels: - {{- include "postgres-single.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "postgres-single.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: Recreate - selector: - matchLabels: - {{- include "postgres-single.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "postgres-single.labels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "postgres-single.annotations" . | nindent 8 }} - k8up.syn.tools/backupcommand: /bin/sh -c "PGPASSWORD=${{ regexReplaceAll "\\W+" .Release.Name "_" | upper }}_PASSWORD pg_dump --host=localhost --port=${{ regexReplaceAll "\\W+" .Release.Name "_" | upper }}_SERVICE_PORT --dbname=${{ regexReplaceAll "\\W+" .Release.Name "_" | upper }}_DB --username=${{ regexReplaceAll "\\W+" .Release.Name "_" | upper }}_USER --format=t -w" - k8up.syn.tools/file-extension: .{{ include "postgres-single.fullname" . }}.tar - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ include "postgres-single.fullname" . }} - persistentVolumeClaim: - claimName: {{ include "postgres-single.fullname" . }} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image }}" - imagePullPolicy: {{ .Values.imagePullPolicy }} - env: - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - envFrom: - - configMapRef: - name: lagoon-env - ports: - - containerPort: 5432 - protocol: TCP - readinessProbe: - tcpSocket: - port: 5432 - initialDelaySeconds: 1 - timeoutSeconds: 1 - livenessProbe: - tcpSocket: - port: 5432 - initialDelaySeconds: 120 - periodSeconds: 5 - volumeMounts: - - name: {{ include "postgres-single.fullname" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/postgres-single/templates/pvc.yaml b/legacy/helmcharts/postgres-single/templates/pvc.yaml deleted file mode 100644 index 020ad758..00000000 --- a/legacy/helmcharts/postgres-single/templates/pvc.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: "{{ include "postgres-single.fullname" . }}" - labels: - {{- include "postgres-single.labels" . | nindent 4 }} - annotations: - {{- include "postgres-single.annotations" . | nindent 4 }} - annotations: - k8up.syn.tools/backup: "false" -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.persistentStorage.size | quote }} diff --git a/legacy/helmcharts/postgres-single/templates/service.yaml b/legacy/helmcharts/postgres-single/templates/service.yaml deleted file mode 100644 index 55d5e22b..00000000 --- a/legacy/helmcharts/postgres-single/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "postgres-single.fullname" . }} - labels: - {{- include "postgres-single.labels" . | nindent 4 }} - annotations: - {{- include "postgres-single.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: 5432 - protocol: TCP - name: 5432-tcp - selector: - {{- include "postgres-single.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/redis-persistent/templates/deployment.yaml b/legacy/helmcharts/redis-persistent/templates/deployment.yaml deleted file mode 100644 index 02f1b53e..00000000 --- a/legacy/helmcharts/redis-persistent/templates/deployment.yaml +++ /dev/null @@ -1,97 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "redis-persistent.fullname" . }} - labels: - {{- include "redis-persistent.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "redis-persistent.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: Recreate - selector: - matchLabels: - {{- include "redis-persistent.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "redis-persistent.labels" . | nindent 8 }} - {{- include "redis-persistent.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "redis-persistent.annotations" . | nindent 8 }} - k8up.syn.tools/backupcommand: /bin/sh -c "/bin/busybox tar -cf - -C {{ .Values.persistentStorage.path }} ." - k8up.syn.tools/file-extension: .{{ include "redis-persistent.fullname" . }}.tar - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ include "redis-persistent.persistentStorageName" . }} - persistentVolumeClaim: - claimName: {{ include "redis-persistent.persistentStorageName" . }} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - priorityClassName: {{ include "redis-persistent.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - name: 6379-tcp - containerPort: 6379 - protocol: TCP - readinessProbe: - tcpSocket: - port: 6379 - initialDelaySeconds: 1 - timeoutSeconds: 1 - livenessProbe: - tcpSocket: - port: 6379 - initialDelaySeconds: 120 - periodSeconds: 10 - env: - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - envFrom: - - configMapRef: - name: lagoon-env - volumeMounts: - - name: {{ include "redis-persistent.persistentStorageName" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/redis-persistent/templates/pvc.yaml b/legacy/helmcharts/redis-persistent/templates/pvc.yaml deleted file mode 100644 index b36bb405..00000000 --- a/legacy/helmcharts/redis-persistent/templates/pvc.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "redis-persistent.persistentStorageName" . }} - labels: - {{- include "redis-persistent.labels" . | nindent 4 }} - annotations: - k8up.syn.tools/backup: "false" - {{- include "redis-persistent.annotations" . | nindent 4 }} -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.persistentStorage.size | quote }} diff --git a/legacy/helmcharts/redis-persistent/templates/service.yaml b/legacy/helmcharts/redis-persistent/templates/service.yaml deleted file mode 100644 index 3ad417d3..00000000 --- a/legacy/helmcharts/redis-persistent/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "redis-persistent.fullname" . }} - labels: - {{- include "redis-persistent.labels" . | nindent 4 }} - annotations: - {{- include "redis-persistent.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: 6379 - protocol: TCP - name: 6379-tcp - selector: - {{- include "redis-persistent.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/redis/templates/deployment.yaml b/legacy/helmcharts/redis/templates/deployment.yaml deleted file mode 100644 index 80234e3d..00000000 --- a/legacy/helmcharts/redis/templates/deployment.yaml +++ /dev/null @@ -1,86 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "redis.fullname" . }} - labels: - {{- include "redis.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "redis.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: RollingUpdate - selector: - matchLabels: - {{- include "redis.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "redis.labels" . | nindent 8 }} - {{- include "redis.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "redis.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- if .Values.dynamicSecretVolumes }} - volumes: - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - env: - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - envFrom: - - configMapRef: - name: lagoon-env - ports: - - name: 6379-tcp - containerPort: 6379 - protocol: TCP - readinessProbe: - tcpSocket: - port: 6379 - initialDelaySeconds: 1 - timeoutSeconds: 1 - livenessProbe: - tcpSocket: - port: 6379 - initialDelaySeconds: 120 - periodSeconds: 10 - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- if .Values.dynamicSecretMounts }} - volumeMounts: - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/redis/templates/service.yaml b/legacy/helmcharts/redis/templates/service.yaml deleted file mode 100644 index c05a124a..00000000 --- a/legacy/helmcharts/redis/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "redis.fullname" . }} - labels: - {{- include "redis.labels" . | nindent 4 }} - annotations: - {{- include "redis.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: 6379 - protocol: TCP - name: 6379-tcp - selector: - {{- include "redis.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/solr/templates/deployment.yaml b/legacy/helmcharts/solr/templates/deployment.yaml deleted file mode 100644 index 01c2de37..00000000 --- a/legacy/helmcharts/solr/templates/deployment.yaml +++ /dev/null @@ -1,81 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "solr.fullname" . }} - labels: - {{- include "solr.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "solr.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: Recreate - selector: - matchLabels: - {{- include "solr.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "solr.labels" . | nindent 8 }} - {{- include "solr.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "solr.annotations" . | nindent 8 }} - k8up.syn.tools/backupcommand: /bin/sh -c 'tar -cf - -C {{ .Values.persistentStorage.path | quote }} --exclude="lost\+found" . || [ $? -eq 1 ]' - k8up.syn.tools/file-extension: .{{ include "solr.fullname" . }}.tar - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ include "solr.persistentStorageName" . }} - persistentVolumeClaim: - claimName: {{ include "solr.persistentStorageName" . }} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - priorityClassName: {{ include "solr.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - image: {{ .Values.image | quote }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - name: {{ .Chart.Name }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - containerPort: 8983 - protocol: TCP - readinessProbe: - tcpSocket: - port: 8983 - initialDelaySeconds: 1 - periodSeconds: 3 - livenessProbe: - tcpSocket: - port: 8983 - initialDelaySeconds: 90 - timeoutSeconds: 3 - failureThreshold: 5 - envFrom: - - configMapRef: - name: lagoon-env - env: - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - volumeMounts: - - name: {{ include "solr.persistentStorageName" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} diff --git a/legacy/helmcharts/solr/templates/pvc.yaml b/legacy/helmcharts/solr/templates/pvc.yaml deleted file mode 100644 index 78e6f13d..00000000 --- a/legacy/helmcharts/solr/templates/pvc.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "solr.persistentStorageName" . }} - labels: - {{- include "solr.labels" . | nindent 4 }} - annotations: - k8up.syn.tools/backup: "false" - {{- include "solr.annotations" . | nindent 4 }} -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.persistentStorage.size | quote }} diff --git a/legacy/helmcharts/solr/templates/service.yaml b/legacy/helmcharts/solr/templates/service.yaml deleted file mode 100644 index dc288638..00000000 --- a/legacy/helmcharts/solr/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "solr.fullname" . }} - labels: - {{- include "solr.labels" . | nindent 4 }} - annotations: - {{- include "solr.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: 8983 - protocol: TCP - name: tcp-8983 - selector: - {{- include "solr.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/varnish-persistent/templates/deployment.yaml b/legacy/helmcharts/varnish-persistent/templates/deployment.yaml deleted file mode 100644 index c97d3f45..00000000 --- a/legacy/helmcharts/varnish-persistent/templates/deployment.yaml +++ /dev/null @@ -1,96 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "varnish-persistent.fullname" . }} - labels: - {{- include "varnish-persistent.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "varnish-persistent.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: Recreate - selector: - matchLabels: - {{- include "varnish-persistent.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "varnish-persistent.labels" . | nindent 8 }} - {{- include "varnish-persistent.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "varnish-persistent.annotations" . | nindent 8 }} - k8up.syn.tools/backupcommand: /bin/sh -c "/bin/busybox tar -cf - -C {{ .Values.persistentStorage.path }} ." - k8up.syn.tools/file-extension: .{{ include "varnish-persistent.fullname" . }}.tar - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ include "varnish-persistent.persistentStorageName" . }} - persistentVolumeClaim: - claimName: {{ include "varnish-persistent.persistentStorageName" . }} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - priorityClassName: {{ include "varnish-persistent.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - env: - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ .Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - ports: - - name: http - containerPort: 8080 - protocol: TCP - - name: controlport - containerPort: 6082 - protocol: TCP - livenessProbe: - tcpSocket: - port: http - readinessProbe: - tcpSocket: - port: http - volumeMounts: - - name: {{ include "varnish-persistent.persistentStorageName" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/varnish-persistent/templates/pvc.yaml b/legacy/helmcharts/varnish-persistent/templates/pvc.yaml deleted file mode 100644 index 0c715597..00000000 --- a/legacy/helmcharts/varnish-persistent/templates/pvc.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "varnish-persistent.persistentStorageName" . }} - labels: - {{- include "varnish-persistent.labels" . | nindent 4 }} - annotations: - k8up.syn.tools/backup: "false" - {{- include "varnish-persistent.annotations" . | nindent 4 }} -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.persistentStorage.size | quote }} diff --git a/legacy/helmcharts/varnish-persistent/templates/service.yaml b/legacy/helmcharts/varnish-persistent/templates/service.yaml deleted file mode 100644 index 623ddf32..00000000 --- a/legacy/helmcharts/varnish-persistent/templates/service.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "varnish-persistent.fullname" . }} - labels: - {{- include "varnish-persistent.labels" . | nindent 4 }} - annotations: - {{- include "varnish-persistent.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - - port: 6082 - targetPort: controlport - protocol: TCP - name: controlport - selector: - {{- include "varnish-persistent.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/varnish/templates/deployment.yaml b/legacy/helmcharts/varnish/templates/deployment.yaml deleted file mode 100644 index 4a700128..00000000 --- a/legacy/helmcharts/varnish/templates/deployment.yaml +++ /dev/null @@ -1,85 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "varnish.fullname" . }} - labels: - {{- include "varnish.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "varnish.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "varnish.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "varnish.labels" . | nindent 8 }} - {{- include "varnish.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "varnish.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - priorityClassName: {{ include "varnish.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- if .Values.dynamicSecretVolumes }} - volumes: - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - env: - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - envFrom: - - configMapRef: - name: lagoon-env - ports: - - name: http - containerPort: 8080 - protocol: TCP - - name: controlport - containerPort: 6082 - protocol: TCP - livenessProbe: - tcpSocket: - port: http - readinessProbe: - tcpSocket: - port: http - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- if .Values.dynamicSecretMounts }} - volumeMounts: - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/varnish/templates/service.yaml b/legacy/helmcharts/varnish/templates/service.yaml deleted file mode 100644 index 79d3f6bc..00000000 --- a/legacy/helmcharts/varnish/templates/service.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "varnish.fullname" . }} - labels: - {{- include "varnish.labels" . | nindent 4 }} - annotations: - {{- include "varnish.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - - port: 6082 - targetPort: controlport - protocol: TCP - name: controlport - selector: - {{- include "varnish.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/worker-persistent/templates/deployment.yaml b/legacy/helmcharts/worker-persistent/templates/deployment.yaml deleted file mode 100644 index ea2203e5..00000000 --- a/legacy/helmcharts/worker-persistent/templates/deployment.yaml +++ /dev/null @@ -1,97 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "worker-persistent.fullname" . }} - labels: - {{- include "worker-persistent.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "worker-persistent.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "worker-persistent.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "worker-persistent.labels" . | nindent 8 }} - {{- include "worker-persistent.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "worker-persistent.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ .Values.persistentStorage.name }} - persistentVolumeClaim: - claimName: {{ .Values.persistentStorage.name }} - - name: {{ include "worker-persistent.twig-storage.name" . | quote }} - emptyDir: {} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - priorityClassName: {{ include "worker-persistent.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - image: {{ .Values.image | quote }} - name: {{ include "worker-persistent.fullname" . }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - env: - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ .Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - volumeMounts: - - name: {{ .Values.persistentStorage.name }} - mountPath: {{ .Values.persistentStorage.path | quote }} - - name: {{ include "worker-persistent.twig-storage.name" . | quote }} - mountPath: {{ include "worker-persistent.twig-storage.path" . | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - readinessProbe: - initialDelaySeconds: 5 - periodSeconds: 2 - failureThreshold: 3 - exec: - command: - - "/bin/sh" - - "-c" - - > - if [ -x /bin/entrypoint-readiness ]; then - /bin/entrypoint-readiness; - fi - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/worker/templates/deployment.yaml b/legacy/helmcharts/worker/templates/deployment.yaml deleted file mode 100644 index 88947198..00000000 --- a/legacy/helmcharts/worker/templates/deployment.yaml +++ /dev/null @@ -1,88 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "worker.fullname" . }} - labels: - {{- include "worker.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "worker.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "worker.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "worker.labels" . | nindent 8 }} - {{- include "worker.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "worker.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - priorityClassName: {{ include "worker.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- if .Values.dynamicSecretVolumes }} - volumes: - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - containers: - - image: {{ .Values.image | quote }} - name: {{ include "worker.fullname" . }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - env: - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ .Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- if .Values.dynamicSecretMounts }} - volumeMounts: - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - readinessProbe: - initialDelaySeconds: 5 - periodSeconds: 2 - failureThreshold: 3 - exec: - command: - - "/bin/sh" - - "-c" - - > - if [ -x /bin/entrypoint-readiness ]; then - /bin/entrypoint-readiness; - fi - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} From a98ee4f60676840a2820f8ad1f6a9dfa0720b2b2 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 21 Jul 2023 16:58:36 +1000 Subject: [PATCH 20/92] chore: update generator and helpers with additional supporting functions for templating --- internal/generator/buildvalues.go | 70 +++++++++++----- internal/generator/generator.go | 72 ++++++++++++++++ internal/generator/generator_test.go | 120 +++++++++++++++++++++++++++ internal/generator/services.go | 16 +++- internal/generator/services_test.go | 49 +++++++++++ internal/helpers/helpers.go | 14 +++- 6 files changed, 316 insertions(+), 25 deletions(-) diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index 5f26ed4f..3c0d22de 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -1,6 +1,7 @@ package generator import ( + composetypes "github.com/compose-spec/compose-go/types" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/lagoon" ) @@ -52,6 +53,23 @@ type BuildValues struct { DynamicSecretMounts []DynamicSecretMounts `json:"dynamicSecretMounts"` DynamicSecretVolumes []DynamicSecretVolumes `json:"dynamicSecretVolumes"` DBaaSClient *dbaasclient.Client `json:"-"` + ImageReferences map[string]string `json:"imageReferences"` + Resources Resources `json:"resources"` + Flags map[string]bool `json:"-"` +} + +type Resources struct { + Limits ResourceLimits `json:"limits"` + Requests ResourceRequests `json:"requests"` +} + +type ResourceLimits struct { + Memory string `json:"memory"` + EphemeralStorage string `json:"ephemeral-storage"` +} + +type ResourceRequests struct { + EphemeralStorage string `json:"ephemeral-storage"` } type PodSecurityContext struct { @@ -88,29 +106,35 @@ type DynamicSecret struct { // ServiceValues is the values for a specific service used by a lagoon build type ServiceValues struct { - Name string `json:"name"` // this is the actual compose service name - OverrideName string `json:"overrideName"` // if an override name is provided, use it - Type string `json:"type"` - AutogeneratedRoutesEnabled bool `json:"autogeneratedRoutesEnabled"` - AutogeneratedRoutesTLSAcme bool `json:"autogeneratedRoutesTLSAcme"` - AutogeneratedRouteDomain string `json:"autogeneratedRouteDomain"` - ShortAutogeneratedRouteDomain string `json:"shortAutogeneratedRouteDomain"` - DBaaSEnvironment string `json:"dbaasEnvironment"` - NativeCronjobs []lagoon.Cronjob `json:"nativeCronjobs"` - InPodCronjobs []lagoon.Cronjob `json:"inPodCronjobs"` - ImageName string `json:"imageName"` - DeploymentServiceType string `json:"deploymentServiceType"` - ServicePort int32 `json:"servicePort,omitempty"` - PersistentVolumePath string `json:"persistentVolumePath,omitempty"` - PersistentVolumeName string `json:"persistentVolumeName,omitempty"` - PersistentVolumeSize string `json:"persistentVolumeSize,omitempty"` - UseSpotInstances bool `json:"useSpot"` - ForceSpotInstances bool `json:"forceUseSpot"` - CronjobUseSpotInstances bool `json:"cronjobUseSpot"` - CronjobForceSpotInstances bool `json:"cronjobForceUseSpot"` - Replicas int32 `json:"replicas"` - LinkedService *ServiceValues `json:"linkedService"` - PodSecurityContext PodSecurityContext `json:"podSecurityContext"` + Name string `json:"name"` // this is the actual compose service name + OverrideName string `json:"overrideName"` // if an override name is provided, use it + Type string `json:"type"` + AutogeneratedRoutesEnabled bool `json:"autogeneratedRoutesEnabled"` + AutogeneratedRoutesTLSAcme bool `json:"autogeneratedRoutesTLSAcme"` + AutogeneratedRouteDomain string `json:"autogeneratedRouteDomain"` + ShortAutogeneratedRouteDomain string `json:"shortAutogeneratedRouteDomain"` + DBaaSEnvironment string `json:"dbaasEnvironment"` + NativeCronjobs []lagoon.Cronjob `json:"nativeCronjobs"` + InPodCronjobs []lagoon.Cronjob `json:"inPodCronjobs"` + ImageName string `json:"imageName"` + DeploymentServiceType string `json:"deploymentServiceType"` + ServicePort int32 `json:"servicePort,omitempty"` + PersistentVolumePath string `json:"persistentVolumePath,omitempty"` + PersistentVolumeName string `json:"persistentVolumeName,omitempty"` + PersistentVolumeSize string `json:"persistentVolumeSize,omitempty"` + UseSpotInstances bool `json:"useSpot"` + ForceSpotInstances bool `json:"forceUseSpot"` + CronjobUseSpotInstances bool `json:"cronjobUseSpot"` + CronjobForceSpotInstances bool `json:"cronjobForceUseSpot"` + Replicas int32 `json:"replicas"` + LinkedService *ServiceValues `json:"linkedService"` + PodSecurityContext PodSecurityContext `json:"podSecurityContext"` + AdditionalServicePorts []AdditionalServicePort `json:"additionalServicePorts,omitempty"` +} + +type AdditionalServicePort struct { + ServicePort composetypes.ServicePortConfig `json:"servicePort,omitempty"` + ServiceName string `json:"serviceName,omitempty"` } // CronjobValues is the values for cronjobs diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 7ea70697..393db950 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -3,6 +3,7 @@ package generator import ( "encoding/base64" "encoding/json" + "errors" "fmt" "os" "strings" @@ -10,6 +11,7 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" + "k8s.io/apimachinery/pkg/api/resource" "sigs.k8s.io/yaml" ) @@ -50,6 +52,8 @@ type GeneratorInput struct { IgnoreMissingEnvFiles bool Debug bool DBaaSClient *dbaasclient.Client + ImageReferences map[string]string + ImagePullSecret string } func NewGenerator( @@ -58,6 +62,7 @@ func NewGenerator( // create some initial variables to be passed through the generators buildValues := BuildValues{} + buildValues.Flags = map[string]bool{} lYAML := &lagoon.YAML{} lagoonEnvVars := []lagoon.EnvironmentVariable{} autogenRoutes := &lagoon.RoutesV2{} @@ -84,6 +89,11 @@ func NewGenerator( fastlyAPISecretPrefix := helpers.GetEnv("ROUTE_FASTLY_SERVICE_ID", generator.FastlyAPISecretPrefix, generator.Debug) lagoonVersion := helpers.GetEnv("LAGOON_VERSION", generator.LagoonVersion, generator.Debug) + // get the image references values from the build images output + buildValues.ImageReferences = generator.ImageReferences + // add standard lagoon imagepull secret name + buildValues.ImagePullSecrets = append(buildValues.ImagePullSecrets, ImagePullSecrets{Name: "lagoon-internal-registry-secret"}) + // get the project and environment variables projectVariables := helpers.GetEnv("LAGOON_PROJECT_VARIABLES", generator.ProjectVariables, generator.Debug) environmentVariables := helpers.GetEnv("LAGOON_ENVIRONMENT_VARIABLES", generator.EnvironmentVariables, generator.Debug) @@ -176,6 +186,41 @@ func NewGenerator( ingressClass := CheckFeatureFlag("INGRESS_CLASS", lagoonEnvVars, generator.Debug) buildValues.IngressClass = ingressClass + // check for rootless workloads + rootlessWorkloads := CheckFeatureFlag("ROOTLESS_WORKLOAD", lagoonEnvVars, generator.Debug) + if rootlessWorkloads == "enabled" { + buildValues.Flags["rootlessworkloads"] = true + buildValues.PodSecurityContext = PodSecurityContext{ + RunAsGroup: 0, + RunAsUser: 10001, + FsGroup: 10000, + } + } + + // check admin features for resources + 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) + // validate that what is provided + 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) + } + } + 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) + } + } + 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) + } + } + // get any variables from the API here lagoonServiceTypes, _ := lagoon.GetLagoonVariable("LAGOON_SERVICE_TYPES", nil, lagoonEnvVars) buildValues.ServiceTypeOverrides = lagoonServiceTypes @@ -356,3 +401,30 @@ func CheckFeatureFlag(key string, envVariables []lagoon.EnvironmentVariable, deb // otherwise nothing return "" } + +func CheckAdminFeatureFlag(key string, debug bool) string { + if value, ok := os.LookupEnv(fmt.Sprintf("ADMIN_LAGOON_FEATURE_FLAG_%s", key)); ok { + if debug { + fmt.Println(fmt.Sprintf("Using admin feature flag value from build variable %s", fmt.Sprintf("ADMIN_LAGOON_FEATURE_FLAG_%s", key))) + } + return value + } + return "" +} + +func ValidateResourceQuantity(s string) (err error) { + defer func() { + if r := recover(); r != nil { + switch x := r.(type) { + case string: + err = errors.New(x) + case error: + err = x + default: + err = errors.New(fmt.Sprint(x)) + } + } + }() + resource.MustParse(s) + return nil +} diff --git a/internal/generator/generator_test.go b/internal/generator/generator_test.go index c0227a05..c0641457 100644 --- a/internal/generator/generator_test.go +++ b/internal/generator/generator_test.go @@ -95,3 +95,123 @@ func TestCheckFeatureFlag(t *testing.T) { }) } } + +func TestCheckAdminFeatureFlag(t *testing.T) { + type args struct { + key string + debug bool + } + tests := []struct { + name string + vars []helpers.EnvironmentVariable + args args + want string + }{ + { + name: "test1 - container memory limit", + vars: []helpers.EnvironmentVariable{ + { + Name: "ADMIN_LAGOON_FEATURE_FLAG_CONTAINER_MEMORY_LIMIT", + Value: "16Gi", + }, + }, + args: args{ + key: "CONTAINER_MEMORY_LIMIT", + }, + want: "16Gi", + }, + { + name: "test2 - ephemeral storage requests", + vars: []helpers.EnvironmentVariable{ + { + Name: "ADMIN_LAGOON_FEATURE_FLAG_EPHEMERAL_STORAGE_REQUESTS", + Value: "16Gi", + }, + }, + args: args{ + key: "EPHEMERAL_STORAGE_REQUESTS", + }, + want: "16Gi", + }, + { + name: "test2 - ephemeral storage limit", + vars: []helpers.EnvironmentVariable{ + { + Name: "ADMIN_LAGOON_FEATURE_FLAG_CONTAINER_MEMORY_LIMIT", + Value: "disabled", + }, + { + Name: "ADMIN_LAGOON_FEATURE_FLAG_EPHEMERAL_STORAGE_LIMIT", + Value: "160Gi", + }, + }, + args: args{ + key: "EPHEMERAL_STORAGE_LIMIT", + }, + want: "160Gi", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + for _, envVar := range tt.vars { + err := os.Setenv(envVar.Name, envVar.Value) + if err != nil { + t.Errorf("%v", err) + } + } + if got := CheckAdminFeatureFlag(tt.args.key, tt.args.debug); got != tt.want { + t.Errorf("CheckAdminFeatureFlag() = %v, want %v", got, tt.want) + } + t.Cleanup(func() { + helpers.UnsetEnvVars(tt.vars) + }) + }) + } +} + +func TestValidateResourceQuantity(t *testing.T) { + type args struct { + s string + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "test1", + args: args{ + s: "100m", + }, + wantErr: false, + }, + { + name: "test2", + args: args{ + s: "100M", + }, + wantErr: false, + }, + { + name: "test3", + args: args{ + s: "10Gi", + }, + wantErr: false, + }, + { + name: "test4", + args: args{ + s: "aa11", + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := ValidateResourceQuantity(tt.args.s); (err != nil) != tt.wantErr { + t.Errorf("ValidateResourceQuantity() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/internal/generator/services.go b/internal/generator/services.go index 7592ba45..1936907e 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -182,7 +182,7 @@ func composeToServiceValues( if servicePersistentName == "" && servicePersistentPath != "" { // if there is a persistent path defined, then set the persistent name to be the compose service if no persistent name is provided // persistent name is used by joined services like nginx/php or cli or worker pods to mount another service volume - servicePersistentName = composeService + servicePersistentName = lagoonOverrideName } servicePersistentSize := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.persistent.size") if servicePersistentSize == "" { @@ -378,6 +378,10 @@ func composeToServiceValues( NativeCronjobs: nativecronjobs, PodSecurityContext: buildValues.PodSecurityContext, } + + // handle extracting the built image name from the provided image references + cService.ImageName = buildValues.ImageReferences[composeService] + // check if the service has a service port override (this only applies to basic(-persistent)) servicePortOverride := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.service.port") if servicePortOverride != "" { @@ -390,6 +394,16 @@ func composeToServiceValues( } cService.ServicePort = int32(sPort) } + useComposeServices := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.service.usecomposeports") + if useComposeServices == "true" { + for _, compPort := range composeServiceValues.Ports { + newService := AdditionalServicePort{ + ServicePort: compPort, + ServiceName: fmt.Sprintf("%s-%d", composeService, compPort.Target), + } + cService.AdditionalServicePorts = append(cService.AdditionalServicePorts, newService) + } + } return cService, nil } } diff --git a/internal/generator/services_test.go b/internal/generator/services_test.go index c084e5d2..42d44bf3 100644 --- a/internal/generator/services_test.go +++ b/internal/generator/services_test.go @@ -530,6 +530,55 @@ func Test_composeToServiceValues(t *testing.T) { Replicas: 2, }, }, + { + name: "test15 - multiple service ports", + args: args{ + lYAML: &lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{}, + }, + }, + buildValues: &BuildValues{ + Environment: "main", + EnvironmentType: "production", + Branch: "main", + BuildType: "branch", + ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + }, + composeService: "service-a", + composeServiceValues: composetypes.ServiceConfig{ + Labels: composetypes.Labels{ + "lagoon.type": "basic", + "lagoon.service.usecomposeports": "true", + }, + Ports: []composetypes.ServicePortConfig{ + composetypes.ServicePortConfig{ + Target: 8181, + Protocol: "tcp", + }, + }, + }, + }, + want: ServiceValues{ + Name: "service-a", + OverrideName: "service-a", + Type: "basic", + DBaaSEnvironment: "production", + AutogeneratedRoutesEnabled: true, + AutogeneratedRoutesTLSAcme: true, + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, + AdditionalServicePorts: []AdditionalServicePort{ + AdditionalServicePort{ + ServicePort: composetypes.ServicePortConfig{ + Target: 8181, + Protocol: "tcp", + }, + ServiceName: "service-a-8181", + }, + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/helpers/helpers.go b/internal/helpers/helpers.go index 52fe181a..383eb5ed 100644 --- a/internal/helpers/helpers.go +++ b/internal/helpers/helpers.go @@ -230,14 +230,26 @@ func DeepCopy(src, dist interface{}) (err error) { return nil } +// just a generic anything template helper func TemplateThings(values, src, dist interface{}) { yb, _ := yaml.Marshal(src) - tmpl, _ := template.New("").Parse(string(yb)) + tmpl, _ := template.New("").Funcs(funcMap).Parse(string(yb)) queryBuilder := strings.Builder{} tmpl.Execute(&queryBuilder, values) yaml.Unmarshal([]byte(queryBuilder.String()), &dist) } +var funcMap = template.FuncMap{ + "ToUpper": strings.ToUpper, + "ToLower": strings.ToLower, + "FixServiceName": FixServiceName, +} + +func FixServiceName(str string) string { + replaceHyphen := strings.ReplaceAll(str, "-", "_") + return strings.ToUpper(replaceHyphen) +} + func AppendIfMissing(slice []string, i string) []string { for _, ele := range slice { if ele == i { From 0b41761bc5dbc7f766639ffa3a35b56bb505e4eb Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 21 Jul 2023 17:03:03 +1000 Subject: [PATCH 21/92] chore: add the command to run the template generation --- cmd/root.go | 2 + cmd/template_lagoonservices.go | 77 ++++ cmd/template_lagoonservices_test.go | 282 ++++++++++++ .../test1-results/deployments.yaml | 84 ++++ .../test1-results/pvcs.yaml | 0 .../test1-results/services.yaml | 93 ++++ .../test1/docker-compose.yml | 22 + .../template-lagoon-services/test1/lagoon.yml | 10 + .../test2-results-a/deployments.yaml | 381 ++++++++++++++++ .../test2-results-a/pvcs.yaml | 30 ++ .../test2-results-a/services.yaml | 97 ++++ .../test2-results-b/deployments.yaml | 414 ++++++++++++++++++ .../test2-results-b/pvcs.yaml | 30 ++ .../test2-results-b/services.yaml | 97 ++++ .../test2/docker-compose.yml | 160 +++++++ .../template-lagoon-services/test2/lagoon.yml | 19 + 16 files changed, 1798 insertions(+) create mode 100644 cmd/template_lagoonservices.go create mode 100644 cmd/template_lagoonservices_test.go create mode 100644 test-resources/template-lagoon-services/test1-results/deployments.yaml create mode 100644 test-resources/template-lagoon-services/test1-results/pvcs.yaml create mode 100644 test-resources/template-lagoon-services/test1-results/services.yaml create mode 100644 test-resources/template-lagoon-services/test1/docker-compose.yml create mode 100644 test-resources/template-lagoon-services/test1/lagoon.yml create mode 100644 test-resources/template-lagoon-services/test2-results-a/deployments.yaml create mode 100644 test-resources/template-lagoon-services/test2-results-a/pvcs.yaml create mode 100644 test-resources/template-lagoon-services/test2-results-a/services.yaml create mode 100644 test-resources/template-lagoon-services/test2-results-b/deployments.yaml create mode 100644 test-resources/template-lagoon-services/test2-results-b/pvcs.yaml create mode 100644 test-resources/template-lagoon-services/test2-results-b/services.yaml create mode 100644 test-resources/template-lagoon-services/test2/docker-compose.yml create mode 100644 test-resources/template-lagoon-services/test2/lagoon.yml diff --git a/cmd/root.go b/cmd/root.go index 2df51d83..d662dcf5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -150,6 +150,8 @@ func init() { "Ignore non-string-key docker-compose errors (true by default, subject to change).") rootCmd.PersistentFlags().BoolP("ignore-missing-env-files", "", true, "Ignore missing env_file files (true by default, subject to change).") + rootCmd.PersistentFlags().StringP("images", "", "", + "JSON representation of service:image reference") } // initConfig reads in config file and ENV variables if set. diff --git a/cmd/template_lagoonservices.go b/cmd/template_lagoonservices.go new file mode 100644 index 00000000..f24f3baf --- /dev/null +++ b/cmd/template_lagoonservices.go @@ -0,0 +1,77 @@ +package cmd + +import ( + "encoding/base64" + "encoding/json" + "fmt" + + "github.com/spf13/cobra" + generator "github.com/uselagoon/build-deploy-tool/internal/generator" + "github.com/uselagoon/build-deploy-tool/internal/helpers" + servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating/services" +) + +var lagoonServiceGeneration = &cobra.Command{ + Use: "lagoon-services", + Aliases: []string{"ls"}, + Short: "Generate the lagoon service templates for a Lagoon build", + RunE: func(cmd *cobra.Command, args []string) error { + gen, err := generatorInput(true) + if err != nil { + return err + } + images, err := rootCmd.PersistentFlags().GetString("images") + if err != nil { + return fmt.Errorf("error reading images flag: %v", err) + } + var imageRefs struct { + Images map[string]string `json:"images"` + } + imagesStr, _ := base64.StdEncoding.DecodeString(images) + json.Unmarshal(imagesStr, &imageRefs) + gen.ImageReferences = imageRefs.Images + return LagoonServiceTemplateGeneration(gen) + }, +} + +// LagoonServiceTemplateGeneration . +func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { + lagoonBuild, err := generator.NewGenerator( + g, + ) + if err != nil { + return err + } + savedTemplates := g.SavedTemplatesPath + + // generate the templates + if g.Debug { + fmt.Println(fmt.Sprintf("Templating service manifests %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "services"))) + } + serviceTemplateYAML, err := servicestemplates.GenerateServiceTemplate(*lagoonBuild.BuildValues) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "services"), serviceTemplateYAML) + if g.Debug { + fmt.Println(fmt.Sprintf("Templating pvc manifests %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "pvcs"))) + } + pvcTemplateYAML, err := servicestemplates.GeneratePVCTemplate(*lagoonBuild.BuildValues) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "pvcs"), pvcTemplateYAML) + if g.Debug { + fmt.Println(fmt.Sprintf("Templating deployment manifest %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "deployments"))) + } + deploymentTemplateYAML, err := servicestemplates.GenerateDeploymentTemplate(*lagoonBuild.BuildValues) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "deployments"), deploymentTemplateYAML) + return nil +} + +func init() { + templateCmd.AddCommand(lagoonServiceGeneration) +} diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go new file mode 100644 index 00000000..e977d2db --- /dev/null +++ b/cmd/template_lagoonservices_test.go @@ -0,0 +1,282 @@ +package cmd + +import ( + "fmt" + "io/ioutil" + "os" + "reflect" + "testing" + "time" + + "github.com/andreyvit/diff" + "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" + "github.com/uselagoon/build-deploy-tool/internal/helpers" +) + +func TestTemplateLagoonServices(t *testing.T) { + type args struct { + alertContact string + statusPageID string + projectName string + environmentName string + branch string + prNumber string + prHeadBranch string + prBaseBranch string + environmentType string + buildType string + activeEnvironment string + standbyEnvironment string + cacheNoCache string + serviceID string + secretPrefix string + ingressClass string + rootlessWorkloads string + projectVars string + envVars string + lagoonVersion string + lagoonYAML string + valuesFilePath string + templatePath string + imageReferences map[string]string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "test1 basic deployment", + args: args{ + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, + envVars: `[]`, + lagoonYAML: "../test-resources/template-lagoon-services/test1/lagoon.yml", + templatePath: "../test-resources/template-lagoon-services/output", + imageReferences: map[string]string{ + "node": "harbor.example/example-project/main/node:latest", + }, + }, + want: "../test-resources/template-lagoon-services/test1-results", + }, + { + name: "test2a nginx-php deployment", + args: args{ + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, + envVars: `[]`, + lagoonYAML: "../test-resources/template-lagoon-services/test2/lagoon.yml", + templatePath: "../test-resources/template-lagoon-services/output", + imageReferences: map[string]string{ + "nginx": "harbor.example/example-project/main/nginx:latest", + "php": "harbor.example/example-project/main/php:latest", + "cli": "harbor.example/example-project/main/cli:latest", + "redis": "harbor.example/example-project/main/redis:latest", + "varnish": "harbor.example/example-project/main/varnish:latest", + }, + }, + want: "../test-resources/template-lagoon-services/test2-results-a", + }, + { + name: "test2b nginx-php deployment - rootless", + args: args{ + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, + envVars: `[]`, + rootlessWorkloads: "enabled", + lagoonYAML: "../test-resources/template-lagoon-services/test2/lagoon.yml", + templatePath: "../test-resources/template-lagoon-services/output", + imageReferences: map[string]string{ + "nginx": "harbor.example/example-project/main/nginx:latest", + "php": "harbor.example/example-project/main/php:latest", + "cli": "harbor.example/example-project/main/cli:latest", + "redis": "harbor.example/example-project/main/redis:latest", + "varnish": "harbor.example/example-project/main/varnish:latest", + }, + }, + want: "../test-resources/template-lagoon-services/test2-results-b", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // set the environment variables from args + err := os.Setenv("MONITORING_ALERTCONTACT", tt.args.alertContact) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("MONITORING_STATUSPAGEID", tt.args.statusPageID) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("PROJECT", tt.args.projectName) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("ENVIRONMENT", tt.args.environmentName) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("BRANCH", tt.args.branch) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("PR_NUMBER", tt.args.prNumber) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("PR_HEAD_BRANCH", tt.args.prHeadBranch) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("PR_BASE_BRANCH", tt.args.prBaseBranch) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("ENVIRONMENT_TYPE", tt.args.environmentType) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("BUILD_TYPE", tt.args.buildType) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("ACTIVE_ENVIRONMENT", tt.args.activeEnvironment) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("STANDBY_ENVIRONMENT", tt.args.standbyEnvironment) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_FASTLY_NOCACHE_SERVICE_ID", tt.args.cacheNoCache) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_PROJECT_VARIABLES", tt.args.projectVars) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_ENVIRONMENT_VARIABLES", tt.args.envVars) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_VERSION", tt.args.lagoonVersion) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_FEATURE_FLAG_DEFAULT_INGRESS_CLASS", tt.args.ingressClass) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_FEATURE_FLAG_DEFAULT_ROOTLESS_WORKLOAD", tt.args.rootlessWorkloads) + if err != nil { + t.Errorf("%v", err) + } + generator, err := generatorInput(false) + if err != nil { + t.Errorf("%v", err) + } + generator.LagoonYAML = tt.args.lagoonYAML + generator.ImageReferences = tt.args.imageReferences + generator.SavedTemplatesPath = tt.args.templatePath + // add dbaasclient overrides for tests + generator.DBaaSClient = dbaasclient.NewClient(dbaasclient.Client{ + RetryMax: 5, + RetryWaitMin: time.Duration(10) * time.Millisecond, + RetryWaitMax: time.Duration(50) * time.Millisecond, + }) + + savedTemplates := tt.args.templatePath + err = os.MkdirAll(tt.args.templatePath, 0755) + if err != nil { + t.Errorf("couldn't create directory %v: %v", savedTemplates, err) + } + + defer os.RemoveAll(savedTemplates) + + ts := dbaasclient.TestDBaaSHTTPServer() + defer ts.Close() + err = os.Setenv("DBAAS_OPERATOR_HTTP", ts.URL) + if err != nil { + t.Errorf("%v", err) + } + + err = LagoonServiceTemplateGeneration(generator) + if err != nil { + t.Errorf("%v", err) + } + + files, err := ioutil.ReadDir(savedTemplates) + if err != nil { + t.Errorf("couldn't read directory %v: %v", savedTemplates, err) + } + results, err := ioutil.ReadDir(tt.want) + if err != nil { + t.Errorf("couldn't read directory %v: %v", tt.want, err) + } + if len(files) != len(results) { + for _, f := range files { + f1, err := os.ReadFile(fmt.Sprintf("%s/%s", savedTemplates, f.Name())) + if err != nil { + t.Errorf("couldn't read file %v: %v", savedTemplates, err) + } + fmt.Println(string(f1)) + } + t.Errorf("number of generated templates doesn't match results %v/%v: %v", len(files), len(results), err) + } + fCount := 0 + for _, f := range files { + for _, r := range results { + if f.Name() == r.Name() { + fCount++ + f1, err := os.ReadFile(fmt.Sprintf("%s/%s", savedTemplates, f.Name())) + if err != nil { + t.Errorf("couldn't read file %v: %v", savedTemplates, err) + } + r1, err := os.ReadFile(fmt.Sprintf("%s/%s", tt.want, f.Name())) + if err != nil { + t.Errorf("couldn't read file %v: %v", tt.want, err) + } + if !reflect.DeepEqual(f1, r1) { + t.Errorf("TemplateLagoonServices() = \n%v", diff.LineDiff(string(r1), string(f1))) + } + } + } + } + if fCount != len(files) { + for _, f := range files { + f1, err := os.ReadFile(fmt.Sprintf("%s/%s", savedTemplates, f.Name())) + if err != nil { + t.Errorf("couldn't read file %v: %v", savedTemplates, err) + } + fmt.Println(string(f1)) + } + t.Errorf("resulting templates do not match") + } + t.Cleanup(func() { + helpers.UnsetEnvVars([]helpers.EnvironmentVariable{{Name: "LAGOON_FEATURE_FLAG_DEFAULT_INGRESS_CLASS"}, {Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD"}}) + }) + }) + } +} diff --git a/test-resources/template-lagoon-services/test1-results/deployments.yaml b/test-resources/template-lagoon-services/test1-results/deployments.yaml new file mode 100644 index 00000000..656fa2bf --- /dev/null +++ b/test-resources/template-lagoon-services/test1-results/deployments.yaml @@ -0,0 +1,84 @@ +--- +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: "" + 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 + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/node:latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 1234 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 1234 + name: node-1234 + protocol: TCP + - containerPort: 8191 + name: node-8191 + protocol: TCP + - containerPort: 9001 + name: node-9001 + protocol: UDP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 1234 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production +status: {} diff --git a/test-resources/template-lagoon-services/test1-results/pvcs.yaml b/test-resources/template-lagoon-services/test1-results/pvcs.yaml new file mode 100644 index 00000000..e69de29b diff --git a/test-resources/template-lagoon-services/test1-results/services.yaml b/test-resources/template-lagoon-services/test1-results/services.yaml new file mode 100644 index 00000000..e79fae07 --- /dev/null +++ b/test-resources/template-lagoon-services/test1-results/services.yaml @@ -0,0 +1,93 @@ +--- +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-1234 +spec: + ports: + - name: node-1234 + port: 1234 + protocol: TCP + targetPort: node-1234 + selector: + app.kubernetes.io/instance: node + app.kubernetes.io/name: basic +status: + loadBalancer: {} +--- +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-8191 +spec: + ports: + - name: node-8191 + port: 8191 + protocol: TCP + targetPort: node-8191 + selector: + app.kubernetes.io/instance: node + app.kubernetes.io/name: basic +status: + loadBalancer: {} +--- +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-9001 +spec: + ports: + - name: node-9001 + port: 9001 + protocol: UDP + targetPort: node-9001 + selector: + app.kubernetes.io/instance: node + app.kubernetes.io/name: basic +status: + loadBalancer: {} diff --git a/test-resources/template-lagoon-services/test1/docker-compose.yml b/test-resources/template-lagoon-services/test1/docker-compose.yml new file mode 100644 index 00000000..66b9415e --- /dev/null +++ b/test-resources/template-lagoon-services/test1/docker-compose.yml @@ -0,0 +1,22 @@ +version: '2' +services: + node: + networks: + - amazeeio-network + - default + build: + context: . + dockerfile: basic.dockerfile + labels: + lagoon.type: basic + lagoon.service.usecomposeports: true + volumes: + - .:/app:delegated + ports: + - '1234' + - '8191' + - '9001/udp' + +networks: + amazeeio-network: + external: true \ No newline at end of file diff --git a/test-resources/template-lagoon-services/test1/lagoon.yml b/test-resources/template-lagoon-services/test1/lagoon.yml new file mode 100644 index 00000000..4f9c49c7 --- /dev/null +++ b/test-resources/template-lagoon-services/test1/lagoon.yml @@ -0,0 +1,10 @@ +docker-compose-yaml: ../test-resources/template-lagoon-services/test1/docker-compose.yml + +environment_variables: + git_sha: "true" + +environments: + main: + routes: + - node: + - example.com diff --git a/test-resources/template-lagoon-services/test2-results-a/deployments.yaml b/test-resources/template-lagoon-services/test2-results-a/deployments.yaml new file mode 100644 index 00000000..cc6a8125 --- /dev/null +++ b/test-resources/template-lagoon-services/test2-results-a/deployments.yaml @@ -0,0 +1,381 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: cli + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: cli + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + name: cli +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: cli + app.kubernetes.io/name: cli-persistent + strategy: {} + template: + metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/configMapSha: "" + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: cli + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: cli + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + value: | + 5,20,35,50 * * * * drush cron + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/cli:latest + name: cli + ports: + - containerPort: 3000 + name: http + protocol: TCP + readinessProbe: + exec: + command: + - /bin/sh + - -c + - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; + fi + failureThreshold: 3 + initialDelaySeconds: 5 + periodSeconds: 2 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + - mountPath: /app/docroot/sites/default/files//php + name: nginx-php-twig + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: lagoon-sshkey + secret: + defaultMode: 420 + secretName: lagoon-sshkey + - emptyDir: {} + name: nginx-php-twig + - name: nginx-php + persistentVolumeClaim: + claimName: nginx-php +status: {} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + name: redis +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: redis + app.kubernetes.io/name: redis + strategy: {} + template: + metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/configMapSha: "" + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/redis:latest + livenessProbe: + initialDelaySeconds: 120 + tcpSocket: + port: 6379 + timeoutSeconds: 10 + name: redis + ports: + - containerPort: 6379 + name: 6379-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 6379 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production +status: {} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + name: varnish +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/name: varnish + strategy: {} + template: + metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/configMapSha: "" + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/varnish:latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8080 + timeoutSeconds: 10 + name: varnish + ports: + - containerPort: 8080 + name: http + protocol: TCP + - containerPort: 6082 + name: controlport + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8080 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production +status: {} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + name: nginx-php +spec: + replicas: 2 + selector: + matchLabels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/name: nginx-php-persistent + strategy: {} + template: + metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/configMapSha: "" + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + spec: + containers: + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/nginx:latest + livenessProbe: + failureThreshold: 5 + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 900 + timeoutSeconds: 3 + name: nginx + ports: + - containerPort: 8080 + name: http + protocol: TCP + readinessProbe: + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 1 + timeoutSeconds: 3 + resources: + requests: + cpu: 10m + memory: 10M + volumeMounts: + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/php:latest + livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + tcpSocket: + port: 9000 + name: php + ports: + - containerPort: 9000 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 2 + periodSeconds: 10 + tcpSocket: + port: 9000 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + - mountPath: /app/docroot/sites/default/files//php + name: nginx-php-twig + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: nginx-php + persistentVolumeClaim: + claimName: nginx-php + - emptyDir: {} + name: nginx-php-twig +status: {} diff --git a/test-resources/template-lagoon-services/test2-results-a/pvcs.yaml b/test-resources/template-lagoon-services/test2-results-a/pvcs.yaml new file mode 100644 index 00000000..9705d159 --- /dev/null +++ b/test-resources/template-lagoon-services/test2-results-a/pvcs.yaml @@ -0,0 +1,30 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "true" + k8up.syn.tools/backup: "true" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + name: nginx-php +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 5Gi + storageClassName: bulk +status: {} diff --git a/test-resources/template-lagoon-services/test2-results-a/services.yaml b/test-resources/template-lagoon-services/test2-results-a/services.yaml new file mode 100644 index 00000000..6f8f096a --- /dev/null +++ b/test-resources/template-lagoon-services/test2-results-a/services.yaml @@ -0,0 +1,97 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + name: redis +spec: + ports: + - name: 6379-tcp + port: 6379 + protocol: TCP + targetPort: 6379 + selector: + app.kubernetes.io/instance: redis + app.kubernetes.io/name: redis +status: + loadBalancer: {} +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + name: varnish +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: http + - name: controlport + port: 6082 + protocol: TCP + targetPort: controlport + selector: + app.kubernetes.io/instance: varnish + app.kubernetes.io/name: varnish +status: + loadBalancer: {} +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + name: nginx-php +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: http + selector: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/name: nginx-php-persistent +status: + loadBalancer: {} diff --git a/test-resources/template-lagoon-services/test2-results-b/deployments.yaml b/test-resources/template-lagoon-services/test2-results-b/deployments.yaml new file mode 100644 index 00000000..1118d7c8 --- /dev/null +++ b/test-resources/template-lagoon-services/test2-results-b/deployments.yaml @@ -0,0 +1,414 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: cli + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: cli + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + name: cli +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: cli + app.kubernetes.io/name: cli-persistent + strategy: {} + template: + metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/configMapSha: "" + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: cli + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: cli + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + value: | + 5,20,35,50 * * * * drush cron + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/cli:latest + name: cli + ports: + - containerPort: 3000 + name: http + protocol: TCP + readinessProbe: + exec: + command: + - /bin/sh + - -c + - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; + fi + failureThreshold: 3 + initialDelaySeconds: 5 + periodSeconds: 2 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + - mountPath: /app/docroot/sites/default/files//php + name: nginx-php-twig + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10000 + runAsGroup: 0 + runAsUser: 10001 + volumes: + - name: lagoon-sshkey + secret: + defaultMode: 420 + secretName: lagoon-sshkey + - emptyDir: {} + name: nginx-php-twig + - name: nginx-php + persistentVolumeClaim: + claimName: nginx-php +status: {} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + name: redis +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: redis + app.kubernetes.io/name: redis + strategy: {} + template: + metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/configMapSha: "" + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/redis:latest + livenessProbe: + initialDelaySeconds: 120 + tcpSocket: + port: 6379 + timeoutSeconds: 10 + name: redis + ports: + - containerPort: 6379 + name: 6379-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 6379 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10000 + runAsGroup: 0 + runAsUser: 10001 +status: {} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + name: varnish +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/name: varnish + strategy: {} + template: + metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/configMapSha: "" + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/varnish:latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8080 + timeoutSeconds: 10 + name: varnish + ports: + - containerPort: 8080 + name: http + protocol: TCP + - containerPort: 6082 + name: controlport + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8080 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10000 + runAsGroup: 0 + runAsUser: 10001 +status: {} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + name: nginx-php +spec: + replicas: 2 + selector: + matchLabels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/name: nginx-php-persistent + strategy: {} + template: + metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/configMapSha: "" + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + spec: + containers: + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/nginx:latest + livenessProbe: + failureThreshold: 5 + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 900 + timeoutSeconds: 3 + name: nginx + ports: + - containerPort: 8080 + name: http + protocol: TCP + readinessProbe: + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 1 + timeoutSeconds: 3 + resources: + requests: + cpu: 10m + memory: 10M + volumeMounts: + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/php:latest + livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + tcpSocket: + port: 9000 + name: php + ports: + - containerPort: 9000 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 2 + periodSeconds: 10 + tcpSocket: + port: 9000 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + - mountPath: /app/docroot/sites/default/files//php + name: nginx-php-twig + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + initContainers: + - command: + - sh + - -c + - "set -e\nSENTINEL=\"/storage/.lagoon-rootless-migration-complete\"\nif ! + [ -f \"$SENTINEL\" ]; then\n\tfind /storage -exec chown 10001:0 {} +\n\tfind + /storage -exec chmod a+r,u+w {} +\n\tfind /storage -type d -exec chmod a+x + {} +\n\ttouch \"$SENTINEL\"\nfi" + image: busybox:musl + imagePullPolicy: IfNotPresent + name: fix-storage-permissions + resources: {} + securityContext: + runAsUser: 0 + volumeMounts: + - mountPath: /storage + name: nginx-php + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10000 + runAsGroup: 0 + runAsUser: 10001 + volumes: + - name: nginx-php + persistentVolumeClaim: + claimName: nginx-php + - emptyDir: {} + name: nginx-php-twig +status: {} diff --git a/test-resources/template-lagoon-services/test2-results-b/pvcs.yaml b/test-resources/template-lagoon-services/test2-results-b/pvcs.yaml new file mode 100644 index 00000000..9705d159 --- /dev/null +++ b/test-resources/template-lagoon-services/test2-results-b/pvcs.yaml @@ -0,0 +1,30 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "true" + k8up.syn.tools/backup: "true" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + name: nginx-php +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 5Gi + storageClassName: bulk +status: {} diff --git a/test-resources/template-lagoon-services/test2-results-b/services.yaml b/test-resources/template-lagoon-services/test2-results-b/services.yaml new file mode 100644 index 00000000..6f8f096a --- /dev/null +++ b/test-resources/template-lagoon-services/test2-results-b/services.yaml @@ -0,0 +1,97 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + name: redis +spec: + ports: + - name: 6379-tcp + port: 6379 + protocol: TCP + targetPort: 6379 + selector: + app.kubernetes.io/instance: redis + app.kubernetes.io/name: redis +status: + loadBalancer: {} +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + name: varnish +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: http + - name: controlport + port: 6082 + protocol: TCP + targetPort: controlport + selector: + app.kubernetes.io/instance: varnish + app.kubernetes.io/name: varnish +status: + loadBalancer: {} +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + name: nginx-php +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: http + selector: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/name: nginx-php-persistent +status: + loadBalancer: {} diff --git a/test-resources/template-lagoon-services/test2/docker-compose.yml b/test-resources/template-lagoon-services/test2/docker-compose.yml new file mode 100644 index 00000000..5efe6c55 --- /dev/null +++ b/test-resources/template-lagoon-services/test2/docker-compose.yml @@ -0,0 +1,160 @@ +version: '2.3' + +x-example-image-version: + &example-image-version ${EXAMPLE_IMAGE_VERSION:-4.x} + +x-project: + &project ${PROJECT_NAME:-mysite} + +x-volumes: + &default-volumes + volumes: + - .:/app:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. + - ./docroot/sites/default/files:/app/docroot/sites/default/files:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. + +x-environment: + &default-environment + LAGOON_PROJECT: *project + DRUPAL_HASH_SALT: fakehashsaltfakehashsaltfakehashsalt + LAGOON_LOCALDEV_URL: ${LOCALDEV_URL:-http://mysite.docker.amazee.io} + LAGOON_ROUTE: ${LOCALDEV_URL:-http://mysite.docker.amazee.io} + GITHUB_TOKEN: ${GITHUB_TOKEN:-} + EXAMPLE_KEY: ${EXAMPLE_KEY:-} + EXAMPLE_IMAGE_VERSION: ${EXAMPLE_IMAGE_VERSION:-latest} + LAGOON_ENVIRONMENT_TYPE: ${LAGOON_ENVIRONMENT_TYPE:-local} + DRUPAL_REFRESH_SEARCHAPI: ${DRUPAL_REFRESH_SEARCHAPI:-} + EXAMPLE_INGRESS_PSK: ${EXAMPLE_INGRESS_PSK:-} + EXAMPLE_INGRESS_HEADER: ${EXAMPLE_INGRESS_HEADER:-} + EXAMPLE_INGRESS_ENABLED: ${EXAMPLE_INGRESS_ENABLED:-} + REDIS_CACHE_PREFIX: "tide_" + DB_ALIAS: ${DB_ALIAS:-bay.production} + + +services: + + cli: + build: + context: . + dockerfile: .docker/Dockerfile.cli + args: + COMPOSER: ${COMPOSER:-composer.json} + EXAMPLE_IMAGE_VERSION: *example-image-version + image: *project + environment: + << : *default-environment + << : *default-volumes + volumes_from: ### Local overrides to mount host SSH keys. Automatically removed in CI. + - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. + labels: + lagoon.type: cli-persistent + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.persistent.name: nginx-php + lagoon.persistent.size: 5Gi + + nginx: + build: + context: . + dockerfile: .docker/Dockerfile.nginx-drupal + args: + CLI_IMAGE: *project + EXAMPLE_IMAGE_VERSION: *example-image-version + << : *default-volumes + environment: + << : *default-environment + depends_on: + - cli + networks: + - amazeeio-network + - default + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.persistent.size: 5Gi + lagoon.name: nginx-php + expose: + - "8080" + php: + build: + context: . + dockerfile: .docker/Dockerfile.php + args: + CLI_IMAGE: *project + EXAMPLE_IMAGE_VERSION: *example-image-version + environment: + << : *default-environment + << : *default-volumes + depends_on: + - cli + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.persistent.size: 5Gi + lagoon.name: nginx-php + + mariadb: + image: amazeeio/mariadb-drupal + environment: + << : *default-environment + ports: + - "3306" # Find port on host with `ahoy info` or `docker-compose port mariadb 3306` + labels: + lagoon.type: mariadb + + redis: + image: amazeeio/redis + labels: + lagoon.type: redis + + elasticsearch: + build: + context: . + dockerfile: .docker/Dockerfile.elasticsearch + args: + - ES_TPL=${ES_TPL:-elasticsearch.yml} + environment: + - discovery.type=single-node + labels: + lagoon.type: none + + chrome: + image: selenium/standalone-chrome:3.141.59-oxygen + shm_size: '1gb' + environment: + << : *default-environment + << : *default-volumes + depends_on: + - cli + labels: + lagoon.type: none + + clamav: + image: clamav/clamav:${EXAMPLE_IMAGE_VERSION:-4.x} + environment: + << : *default-environment + ports: + - "3310" + labels: + lagoon.type: none + + varnish: + image: uselagoon/varnish-5-drupal:latest + labels: + lagoon.type: varnish + lando.type: varnish-drupal + links: + - nginx # links varnish to the nginx in this docker-compose project, or it would try to connect to any nginx running in docker + environment: + << : *default-environment + VARNISH_BYPASS: "true" # by default we bypass varnish, change to 'false' or remove in order to tell varnish to cache if possible + networks: + - amazeeio-network + - default + + +networks: + amazeeio-network: + external: true + +volumes: + app: {} + files: {} \ No newline at end of file diff --git a/test-resources/template-lagoon-services/test2/lagoon.yml b/test-resources/template-lagoon-services/test2/lagoon.yml new file mode 100644 index 00000000..bdc55a33 --- /dev/null +++ b/test-resources/template-lagoon-services/test2/lagoon.yml @@ -0,0 +1,19 @@ +docker-compose-yaml: ../test-resources/template-lagoon-services/test2/docker-compose.yml + +environment_variables: + git_sha: "true" + +environments: + main: + routes: + - nginx: + - example.com + cronjobs: + - name: drush cron + schedule: "*/15 * * * *" + command: drush cron + service: cli + - name: drush cron2 + schedule: "*/30 * * * *" + command: drush cron + service: cli \ No newline at end of file From 5323296e4bef4a1e473c419ca8e5222e633d1686 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 21 Jul 2023 17:03:36 +1000 Subject: [PATCH 22/92] chore: update bash script to execute the templating command now and remove unused code that the templating command replaces --- legacy/build-deploy-docker-compose.sh | 36 +++++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 60191587..eb713da0 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -1075,6 +1075,7 @@ else # end custom route fi +## TODO: remove this entire for loop as it won't be required once dbaas consumers are created via the go templating engine for SERVICE_TYPES_ENTRY in "${SERVICE_TYPES[@]}" do echo "=== BEGIN route processing for service ${SERVICE_TYPES_ENTRY} ===" @@ -1087,12 +1088,6 @@ do touch /kubectl-build-deploy/${SERVICE_NAME}-values.yaml - HELM_SERVICE_TEMPLATE="templates/service.yaml" - if [ -f /kubectl-build-deploy/helmcharts/${SERVICE_TYPE}/$HELM_SERVICE_TEMPLATE ]; then - cat /kubectl-build-deploy/values.yaml - helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -s $HELM_SERVICE_TEMPLATE -f /kubectl-build-deploy/values.yaml "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/service-${SERVICE_NAME}.yaml - fi - HELM_DBAAS_TEMPLATE="templates/dbaas.yaml" if [ -f /kubectl-build-deploy/helmcharts/${SERVICE_TYPE}/$HELM_DBAAS_TEMPLATE ]; then # Load the requested class and plan for this service @@ -1530,6 +1525,21 @@ do done set +x + +# generate a map of servicename>imagename+hash json for the build-deploy-tool to use when templating +# this reduces the need for the crazy logic with how services are currently mapped together in the case of nginx-php type deploymentss +touch /kubectl-build-deploy/images.yaml +for COMPOSE_SERVICE in "${COMPOSE_SERVICES[@]}" +do + SERVICE_NAME_IMAGE_HASH="${IMAGE_HASHES[${COMPOSE_SERVICE}]}" + yq3 write -i -- /kubectl-build-deploy/images.yaml 'images.'$COMPOSE_SERVICE'' ${SERVICE_NAME_IMAGE_HASH} +done + +echo "=== BEGIN deployment template for services ===" +LAGOON_SERVICES_YAML_FOLDER="/kubectl-build-deploy/lagoon/service-deployments" +mkdir -p $LAGOON_SERVICES_YAML_FOLDER +build-deploy-tool template lagoon-services --saved-templates-path ${LAGOON_SERVICES_YAML_FOLDER} --images $(yq3 r -j /kubectl-build-deploy/images.yaml | jq -M -c | base64 -w0) + currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "deploymentTemplatingComplete" "Deployment Templating" previousStepEnd=${currentStepEnd} @@ -1553,8 +1563,18 @@ if [ "$(ls -A $YAML_FOLDER/)" ]; then find $YAML_FOLDER -type f -print0 | xargs -0 sed -i s/ReadWriteMany/ReadWriteOnce/g fi - find $YAML_FOLDER -type f -exec cat {} \; - kubectl apply -n ${NAMESPACE} -f $YAML_FOLDER/ + if [ "$(ls -A $YAML_FOLDER)" ]; then + # TODO: this will only be cronjobs until cronjobs are done via the go templating system + find $YAML_FOLDER -type f -exec cat {} \; + kubectl apply -n ${NAMESPACE} -f $YAML_FOLDER/ + fi + + # cat $LAGOON_SERVICES_YAML_FOLDER/services.yaml + # cat $LAGOON_SERVICES_YAML_FOLDER/pvcs.yaml + # cat $LAGOON_SERVICES_YAML_FOLDER/deployments.yaml + kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/services.yaml + kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/pvcs.yaml + kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/deployments.yaml fi set -x From 95bc35e61a75b07011ddf052b6dc7bf336f322a0 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 24 Jul 2023 16:34:36 +1000 Subject: [PATCH 23/92] chore: add cronjob templating --- cmd/identify_native_cronjobs.go | 52 +++ cmd/identify_native_cronjobs_test.go | 235 ++++++++++ cmd/template_lagoonservices.go | 5 + internal/generator/buildvalues.go | 1 + internal/generator/generator.go | 9 + internal/generator/services.go | 37 +- internal/generator/services_test.go | 106 +++++ internal/lagoon/fastly.go | 12 +- .../templating/services/templates_cronjob.go | 414 ++++++++++++++++++ .../services/templates_cronjob_test.go | 95 ++++ .../test-resources/cronjob/result-cli-1.yaml | 176 ++++++++ .../test1-results/cronjobs.yaml | 0 .../test2-results-a/cronjobs.yaml | 96 ++++ .../test2-results-b/cronjobs.yaml | 100 +++++ 14 files changed, 1321 insertions(+), 17 deletions(-) create mode 100644 cmd/identify_native_cronjobs.go create mode 100644 cmd/identify_native_cronjobs_test.go create mode 100644 internal/templating/services/templates_cronjob_test.go create mode 100644 internal/templating/services/test-resources/cronjob/result-cli-1.yaml create mode 100644 test-resources/template-lagoon-services/test1-results/cronjobs.yaml create mode 100644 test-resources/template-lagoon-services/test2-results-a/cronjobs.yaml create mode 100644 test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml diff --git a/cmd/identify_native_cronjobs.go b/cmd/identify_native_cronjobs.go new file mode 100644 index 00000000..f3fc3a3a --- /dev/null +++ b/cmd/identify_native_cronjobs.go @@ -0,0 +1,52 @@ +package cmd + +import ( + "encoding/json" + "fmt" + + "github.com/spf13/cobra" + generator "github.com/uselagoon/build-deploy-tool/internal/generator" +) + +var nativeCronjobsIdentify = &cobra.Command{ + Use: "native-cronjobs", + Aliases: []string{"nc"}, + Short: "Identify any native cronjobs for a specific environment", + RunE: func(cmd *cobra.Command, args []string) error { + generator, err := generatorInput(false) + if err != nil { + return err + } + cronjobs, err := IdentifyNativeCronjobs(generator) + if err != nil { + return err + } + fmt.Println(cronjobs) + return nil + }, +} + +// IdentifyNativeCronjobs . +func IdentifyNativeCronjobs(g generator.GeneratorInput) (string, error) { + lagoonBuild, err := generator.NewGenerator( + g, + ) + if err != nil { + return "", err + } + + nativeCronjobs := []string{} + for _, service := range lagoonBuild.BuildValues.Services { + for _, nc := range service.NativeCronjobs { + nativeCronjobs = append(nativeCronjobs, nc.Name) + } + } + nativeCronjobsBytes, _ := json.Marshal(nativeCronjobs) + + return string(nativeCronjobsBytes), nil +} + +func init() { + identifyCmd.AddCommand(nativeCronjobsIdentify) + identifyCmd.AddCommand(ingressIdentify) +} diff --git a/cmd/identify_native_cronjobs_test.go b/cmd/identify_native_cronjobs_test.go new file mode 100644 index 00000000..ca4a6757 --- /dev/null +++ b/cmd/identify_native_cronjobs_test.go @@ -0,0 +1,235 @@ +package cmd + +import ( + "os" + "testing" + "time" + + "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" + "github.com/uselagoon/build-deploy-tool/internal/helpers" +) + +func TestIdentifyNativeCronjobs(t *testing.T) { + type args struct { + alertContact string + statusPageID string + projectName string + environmentName string + branch string + prNumber string + prHeadBranch string + prBaseBranch string + environmentType string + buildType string + activeEnvironment string + standbyEnvironment string + cacheNoCache string + serviceID string + secretPrefix string + ingressClass string + rootlessWorkloads string + projectVars string + envVars string + lagoonVersion string + lagoonYAML string + valuesFilePath string + templatePath string + imageReferences map[string]string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "test1 basic deployment", + args: args{ + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, + envVars: `[]`, + lagoonYAML: "../test-resources/template-lagoon-services/test1/lagoon.yml", + templatePath: "../test-resources/template-lagoon-services/output", + imageReferences: map[string]string{ + "node": "harbor.example/example-project/main/node:latest", + }, + }, + want: "[]", + }, + { + name: "test2a nginx-php deployment", + args: args{ + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, + envVars: `[]`, + lagoonYAML: "../test-resources/template-lagoon-services/test2/lagoon.yml", + templatePath: "../test-resources/template-lagoon-services/output", + imageReferences: map[string]string{ + "nginx": "harbor.example/example-project/main/nginx:latest", + "php": "harbor.example/example-project/main/php:latest", + "cli": "harbor.example/example-project/main/cli:latest", + "redis": "harbor.example/example-project/main/redis:latest", + "varnish": "harbor.example/example-project/main/varnish:latest", + }, + }, + want: `["cronjob-cli-drush-cron2"]`, + }, + { + name: "test2b nginx-php deployment - rootless", + args: args{ + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, + envVars: `[]`, + rootlessWorkloads: "enabled", + lagoonYAML: "../test-resources/template-lagoon-services/test2/lagoon.yml", + templatePath: "../test-resources/template-lagoon-services/output", + imageReferences: map[string]string{ + "nginx": "harbor.example/example-project/main/nginx:latest", + "php": "harbor.example/example-project/main/php:latest", + "cli": "harbor.example/example-project/main/cli:latest", + "redis": "harbor.example/example-project/main/redis:latest", + "varnish": "harbor.example/example-project/main/varnish:latest", + }, + }, + want: `["cronjob-cli-drush-cron2"]`, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // set the environment variables from args + err := os.Setenv("MONITORING_ALERTCONTACT", tt.args.alertContact) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("MONITORING_STATUSPAGEID", tt.args.statusPageID) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("PROJECT", tt.args.projectName) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("ENVIRONMENT", tt.args.environmentName) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("BRANCH", tt.args.branch) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("PR_NUMBER", tt.args.prNumber) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("PR_HEAD_BRANCH", tt.args.prHeadBranch) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("PR_BASE_BRANCH", tt.args.prBaseBranch) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("ENVIRONMENT_TYPE", tt.args.environmentType) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("BUILD_TYPE", tt.args.buildType) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("ACTIVE_ENVIRONMENT", tt.args.activeEnvironment) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("STANDBY_ENVIRONMENT", tt.args.standbyEnvironment) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_FASTLY_NOCACHE_SERVICE_ID", tt.args.cacheNoCache) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_PROJECT_VARIABLES", tt.args.projectVars) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_ENVIRONMENT_VARIABLES", tt.args.envVars) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_VERSION", tt.args.lagoonVersion) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_FEATURE_FLAG_DEFAULT_INGRESS_CLASS", tt.args.ingressClass) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_FEATURE_FLAG_DEFAULT_ROOTLESS_WORKLOAD", tt.args.rootlessWorkloads) + if err != nil { + t.Errorf("%v", err) + } + generator, err := generatorInput(false) + if err != nil { + t.Errorf("%v", err) + } + generator.LagoonYAML = tt.args.lagoonYAML + generator.ImageReferences = tt.args.imageReferences + generator.SavedTemplatesPath = tt.args.templatePath + // add dbaasclient overrides for tests + generator.DBaaSClient = dbaasclient.NewClient(dbaasclient.Client{ + RetryMax: 5, + RetryWaitMin: time.Duration(10) * time.Millisecond, + RetryWaitMax: time.Duration(50) * time.Millisecond, + }) + + savedTemplates := tt.args.templatePath + err = os.MkdirAll(tt.args.templatePath, 0755) + if err != nil { + t.Errorf("couldn't create directory %v: %v", savedTemplates, err) + } + + defer os.RemoveAll(savedTemplates) + + ts := dbaasclient.TestDBaaSHTTPServer() + defer ts.Close() + err = os.Setenv("DBAAS_OPERATOR_HTTP", ts.URL) + if err != nil { + t.Errorf("%v", err) + } + + got, err := IdentifyNativeCronjobs(generator) + if err != nil { + t.Errorf("%v", err) + } + + if got != tt.want { + t.Errorf("IdentifyNativeCronjobs() = %v, want %v", got, tt.want) + } + + t.Cleanup(func() { + helpers.UnsetEnvVars([]helpers.EnvironmentVariable{{Name: "LAGOON_FEATURE_FLAG_DEFAULT_INGRESS_CLASS"}, {Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD"}}) + }) + }) + } +} diff --git a/cmd/template_lagoonservices.go b/cmd/template_lagoonservices.go index f24f3baf..f7bd8f13 100644 --- a/cmd/template_lagoonservices.go +++ b/cmd/template_lagoonservices.go @@ -69,6 +69,11 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { return fmt.Errorf("couldn't generate template: %v", err) } helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "deployments"), deploymentTemplateYAML) + cronjobTemplateYaml, err := servicestemplates.GenerateCronjobTemplate(*lagoonBuild.BuildValues) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "cronjobs"), cronjobTemplateYaml) return nil } diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index 3c0d22de..ca77983c 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -55,6 +55,7 @@ type BuildValues struct { DBaaSClient *dbaasclient.Client `json:"-"` ImageReferences map[string]string `json:"imageReferences"` Resources Resources `json:"resources"` + CronjobsDisabled bool `json:"cronjobsDisabled"` Flags map[string]bool `json:"-"` } diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 393db950..3d1738d6 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -244,6 +244,15 @@ func NewGenerator( buildValues.AutogeneratedRoutesFastly = false } } + // check legacy variable in envvars + cronjobsDisabled, _ := lagoon.GetLagoonVariable("LAGOON_CRONJOBS_DISABLED", nil, lagoonEnvVars) + if cronjobsDisabled != nil { + if cronjobsDisabled.Value == "true" { + buildValues.CronjobsDisabled = true + } else { + buildValues.CronjobsDisabled = false + } + } // @TODO: eventually fail builds if this is not set https://github.com/uselagoon/build-deploy-tool/issues/56 // lagoonDBaaSFallbackSingle, _ := lagoon.GetLagoonVariable("LAGOON_FEATURE_FLAG_DBAAS_FALLBACK_SINGLE", nil, lagoonEnvVars) diff --git a/internal/generator/services.go b/internal/generator/services.go index 1936907e..ed59a103 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -3,6 +3,7 @@ package generator import ( "fmt" "reflect" + "regexp" "strconv" "strings" @@ -195,22 +196,26 @@ func composeToServiceValues( // work out cronjobs for this service inpodcronjobs := []lagoon.Cronjob{} nativecronjobs := []lagoon.Cronjob{} - for _, cronjob := range lYAML.Environments[buildValues.Branch].Cronjobs { - // if this cronjob is meant for this service, add it - if cronjob.Service == composeService { - var err error - inpod, err := helpers.IsInPodCronjob(cronjob.Schedule) - if err != nil { - return ServiceValues{}, fmt.Errorf("Unable to validate crontab for cronjob %s: %v", cronjob.Name, err) - } - cronjob.Schedule, err = helpers.ConvertCrontab(buildValues.Namespace, cronjob.Schedule) - if err != nil { - return ServiceValues{}, fmt.Errorf("Unable to convert crontab for cronjob %s: %v", cronjob.Name, err) - } - if inpod { - inpodcronjobs = append(inpodcronjobs, cronjob) - } else { - nativecronjobs = append(nativecronjobs, cronjob) + if !buildValues.CronjobsDisabled { + for _, cronjob := range lYAML.Environments[buildValues.Branch].Cronjobs { + // if this cronjob is meant for this service, add it + if cronjob.Service == composeService { + var err error + inpod, err := helpers.IsInPodCronjob(cronjob.Schedule) + if err != nil { + return ServiceValues{}, fmt.Errorf("Unable to validate crontab for cronjob %s: %v", cronjob.Name, err) + } + cronjob.Schedule, err = helpers.ConvertCrontab(buildValues.Namespace, cronjob.Schedule) + if err != nil { + return ServiceValues{}, fmt.Errorf("Unable to convert crontab for cronjob %s: %v", cronjob.Name, err) + } + if inpod { + inpodcronjobs = append(inpodcronjobs, cronjob) + } else { + // make the cronjob name kubernetes compliant + cronjob.Name = regexp.MustCompile(`[^a-zA-Z0-9]+`).ReplaceAllString(fmt.Sprintf("cronjob-%s-%s", lagoonOverrideName, strings.ToLower(cronjob.Name)), "-") + nativecronjobs = append(nativecronjobs, cronjob) + } } } } diff --git a/internal/generator/services_test.go b/internal/generator/services_test.go index 42d44bf3..df0b7e88 100644 --- a/internal/generator/services_test.go +++ b/internal/generator/services_test.go @@ -579,6 +579,112 @@ func Test_composeToServiceValues(t *testing.T) { }, }, }, + { + name: "test16 - cronjobs", + args: args{ + lYAML: &lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Cronjobs: []lagoon.Cronjob{ + { + Name: "My Cronjob", + Command: "env", + Service: "cli", + Schedule: "5 2 * * *", + }, + { + Name: "My Cronjob2", + Command: "drush cron", + Service: "cli", + Schedule: "*/5 * * * *", + }, + }, + }, + }, + }, + buildValues: &BuildValues{ + Environment: "main", + Branch: "main", + BuildType: "branch", + ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + }, + composeService: "cli", + composeServiceValues: composetypes.ServiceConfig{ + Labels: composetypes.Labels{ + "lagoon.type": "cli", + }, + }, + }, + want: ServiceValues{ + Name: "cli", + OverrideName: "cli", + Type: "cli", + AutogeneratedRoutesEnabled: false, + AutogeneratedRoutesTLSAcme: false, + InPodCronjobs: []lagoon.Cronjob{ + { + Name: "My Cronjob2", + Service: "cli", + Schedule: "0,5,10,15,20,25,30,35,40,45,50,55 * * * *", + Command: "drush cron", + }, + }, + NativeCronjobs: []lagoon.Cronjob{ + { + Name: "cronjob-cli-my-cronjob", + Service: "cli", + Schedule: "5 2 * * *", + Command: "env", + }}, + }, + }, + { + name: "test16 - cronjobs disabled", + args: args{ + lYAML: &lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Cronjobs: []lagoon.Cronjob{ + { + Name: "My Cronjob", + Command: "env", + Service: "cli", + Schedule: "5 2 * * *", + }, + { + Name: "My Cronjob2", + Command: "drush cron", + Service: "cli", + Schedule: "*/5 * * * *", + }, + }, + }, + }, + }, + buildValues: &BuildValues{ + Environment: "main", + Branch: "main", + BuildType: "branch", + ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + CronjobsDisabled: true, + }, + composeService: "cli", + composeServiceValues: composetypes.ServiceConfig{ + Labels: composetypes.Labels{ + "lagoon.type": "cli", + }, + }, + }, + want: ServiceValues{ + Name: "cli", + OverrideName: "cli", + Type: "cli", + AutogeneratedRoutesEnabled: false, + AutogeneratedRoutesTLSAcme: false, + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/lagoon/fastly.go b/internal/lagoon/fastly.go index 188731f9..1b42a882 100644 --- a/internal/lagoon/fastly.go +++ b/internal/lagoon/fastly.go @@ -46,7 +46,17 @@ func GenerateFastlyConfiguration(f *Fastly, noCacheServiceID, serviceID, route, // check the `LAGOON_FASTLY_SERVICE_IDS` to see if we have a domain specific override // this is useful if all domains are using the nocache service, but you have a specific domain that should use a different service // and you haven't defined it in the lagoon.yml file - // see section `FASTLY SERVICE ID PER INGRESS OVERRIDE` in `build-deploy-docker-compose.sh` for info on `LAGOON_FASTLY_SERVICE_IDS` + // # FASTLY SERVICE ID PER INGRESS OVERRIDE FROM LAGOON API VARIABLE + // # Allow the fastly serviceid for specific ingress to be overridden by the lagoon API + // # This accepts colon separated values like so `INGRESS_DOMAIN:FASTLY_SERVICE_ID:WATCH_STATUS:SECRET_NAME(OPTIONAL)`, and multiple overrides + // # separated by commas + // # Example 1: www.example.com:x1s8asfafasf7ssf:true + // # ^^^ tells the ingress creation to use the service id x1s8asfafasf7ssf for ingress www.example.com, with the watch status of true + // # Example 2: www.example.com:x1s8asfafasf7ssf:true,www.not-example.com:fa23rsdgsdgas:false + // # ^^^ same as above, but also tells the ingress creation to use the service id fa23rsdgsdgas for ingress www.not-example.com, with the watch status of false + // # Example 3: www.example.com:x1s8asfafasf7ssf:true:examplecom + // # ^^^ tells the ingress creation to use the service id x1s8asfafasf7ssf for ingress www.example.com, with the watch status of true + // # but it will also be annotated to be told to use the secret named `examplecom` that could be defined elsewhere lfsIDs, err := GetLagoonVariable("LAGOON_FASTLY_SERVICE_IDS", []string{"build", "global"}, variables) if err == nil { lfsIDsSplit := strings.Split(lfsIDs.Value, ",") diff --git a/internal/templating/services/templates_cronjob.go b/internal/templating/services/templates_cronjob.go index 5e568ea8..161cd99b 100644 --- a/internal/templating/services/templates_cronjob.go +++ b/internal/templating/services/templates_cronjob.go @@ -1 +1,415 @@ package services + +import ( + "fmt" + + "github.com/uselagoon/build-deploy-tool/internal/generator" + "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/servicetypes" + batchv1 "k8s.io/api/batch/v1beta1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + apivalidation "k8s.io/apimachinery/pkg/api/validation" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" + "sigs.k8s.io/yaml" +) + +// GenerateCronjobTemplate generates the lagoon template to apply. +func GenerateCronjobTemplate( + buildValues generator.BuildValues, +) ([]byte, error) { + separator := []byte("---\n") + var result []byte + + // check linked services + checkedServices := LinkedServiceCalculator(buildValues.Services) + + // for all the services that the build values generated + // iterate over them and generate any kubernetes cronjobs + for _, serviceValues := range checkedServices { + if val, ok := servicetypes.ServiceTypes[serviceValues.Type]; ok { + for _, nCronjob := range serviceValues.NativeCronjobs { + serviceTypeValues := &servicetypes.ServiceType{} + helpers.DeepCopy(val, serviceTypeValues) + + var cronjobBytes []byte + + // add the default labels + labels := map[string]string{ + "app.kubernetes.io/managed-by": "build-deploy-tool", + "app.kubernetes.io/name": serviceTypeValues.Name, + "app.kubernetes.io/instance": serviceValues.OverrideName, + "lagoon.sh/project": buildValues.Project, + "lagoon.sh/environment": buildValues.Environment, + "lagoon.sh/environmentType": buildValues.EnvironmentType, + "lagoon.sh/buildType": buildValues.BuildType, + "lagoon.sh/template": fmt.Sprintf("%s-%s", serviceTypeValues.Name, "0.1.0"), + "lagoon.sh/service": serviceValues.OverrideName, + "lagoon.sh/service-type": serviceTypeValues.Name, + } + + // add the default annotations + annotations := map[string]string{ + "lagoon.sh/version": buildValues.LagoonVersion, + } + + // add any additional labels + additionalLabels := make(map[string]string) + additionalAnnotations := make(map[string]string) + if buildValues.BuildType == "branch" { + additionalAnnotations["lagoon.sh/branch"] = buildValues.Branch + } else if buildValues.BuildType == "pullrequest" { + additionalAnnotations["lagoon.sh/prNumber"] = buildValues.PRNumber + additionalAnnotations["lagoon.sh/prHeadBranch"] = buildValues.PRHeadBranch + additionalAnnotations["lagoon.sh/prBaseBranch"] = buildValues.PRBaseBranch + } + + templateAnnotations := make(map[string]string) + templateAnnotations["lagoon.sh/configMapSha"] = buildValues.ConfigMapSha + if serviceTypeValues.Volumes.BackupConfiguration.Command != "" { + bc := servicetypes.BackupConfiguration{} + helpers.TemplateThings(serviceValues, serviceTypeValues.Volumes.BackupConfiguration, &bc) + templateAnnotations["k8up.syn.tools/backupcommand"] = bc.Command + templateAnnotations["k8up.syn.tools/file-extension"] = bc.FileExtension + } + + cronjob := &batchv1.CronJob{ + TypeMeta: metav1.TypeMeta{ + Kind: "CronJob", + APIVersion: fmt.Sprintf("%s/%s", batchv1.SchemeGroupVersion.Group, batchv1.SchemeGroupVersion.Version), + }, + ObjectMeta: metav1.ObjectMeta{ + Name: nCronjob.Name, + Labels: labels, + Annotations: annotations, + }, + } + cronjob.ObjectMeta.Labels = labels + cronjob.ObjectMeta.Annotations = annotations + cronjob.Spec.JobTemplate.Spec.Template.Spec.DNSConfig = &corev1.PodDNSConfig{ + Options: []corev1.PodDNSConfigOption{ + { + Name: "timeout", + Value: helpers.StrPtr("60"), + }, + { + Name: "attempts", + Value: helpers.StrPtr("10"), + }, + }, + } + cronjob.Spec.Schedule = nCronjob.Schedule + cronjob.Spec.ConcurrencyPolicy = batchv1.ForbidConcurrent + cronjob.Spec.SuccessfulJobsHistoryLimit = helpers.Int32Ptr(0) + cronjob.Spec.FailedJobsHistoryLimit = helpers.Int32Ptr(1) + cronjob.Spec.StartingDeadlineSeconds = helpers.Int64Ptr(240) + cronjob.Spec.JobTemplate.Spec.Template.Spec.RestartPolicy = corev1.RestartPolicyNever + + if serviceValues.CronjobUseSpotInstances { + // handle spot instance label and affinity/tolerations/selectors + additionalLabels["lagoon.sh/spot"] = "true" + cronjob.Spec.JobTemplate.Spec.Template.Spec.Affinity = &corev1.Affinity{ + NodeAffinity: &corev1.NodeAffinity{ + PreferredDuringSchedulingIgnoredDuringExecution: []corev1.PreferredSchedulingTerm{ + { + Weight: 1, + Preference: corev1.NodeSelectorTerm{ + MatchExpressions: []corev1.NodeSelectorRequirement{ + { + Key: "lagoon.sh/spot", + Operator: corev1.NodeSelectorOpExists, + }, + }, + }, + }, + }, + }, + } + cronjob.Spec.JobTemplate.Spec.Template.Spec.Tolerations = []corev1.Toleration{ + { + Key: "lagoon.sh/spot", + Operator: corev1.TolerationOpExists, + Effect: corev1.TaintEffectNoSchedule, + }, + { + Key: "lagoon.sh/spot", + Operator: corev1.TolerationOpExists, + Effect: corev1.TaintEffectPreferNoSchedule, + }, + } + if serviceValues.CronjobForceSpotInstances { + cronjob.Spec.JobTemplate.Spec.Template.Spec.NodeSelector = map[string]string{ + "lagoon.sh/spot": "true", + } + } + } + + for key, value := range additionalLabels { + cronjob.ObjectMeta.Labels[key] = value + } + // add any additional annotations + for key, value := range additionalAnnotations { + cronjob.ObjectMeta.Annotations[key] = value + } + // validate any annotations + if err := apivalidation.ValidateAnnotations(cronjob.ObjectMeta.Annotations, nil); err != nil { + if len(err) != 0 { + return nil, fmt.Errorf("the annotations for %s are not valid: %v", serviceValues.OverrideName, err) + } + } + // validate any labels + if err := metavalidation.ValidateLabels(cronjob.ObjectMeta.Labels, nil); err != nil { + if len(err) != 0 { + return nil, fmt.Errorf("the labels for %s are not valid: %v", serviceValues.OverrideName, err) + } + } + // check length of labels + err := helpers.CheckLabelLength(cronjob.ObjectMeta.Labels) + if err != nil { + return nil, err + } + + // start cronjob template + cronjob.Spec.JobTemplate.Spec.Template.ObjectMeta = metav1.ObjectMeta{ + Labels: map[string]string{}, + Annotations: map[string]string{}, + } + for key, value := range cronjob.ObjectMeta.Labels { + cronjob.Spec.JobTemplate.Spec.Template.ObjectMeta.Labels[key] = value + } + // add any additional annotations + for key, value := range cronjob.ObjectMeta.Annotations { + cronjob.Spec.JobTemplate.Spec.Template.ObjectMeta.Annotations[key] = value + } + for key, value := range templateAnnotations { + cronjob.Spec.JobTemplate.Spec.Template.ObjectMeta.Annotations[key] = value + } + + // disable service links, this prevents some environment variables that confuse lagoon services being + // added to the containers + cronjob.Spec.JobTemplate.Spec.Template.Spec.EnableServiceLinks = helpers.BoolPtr(false) + // set the priority class + cronjob.Spec.JobTemplate.Spec.Template.Spec.PriorityClassName = fmt.Sprintf("lagoon-priority-%s", buildValues.EnvironmentType) + + // handle the podescurity from rootless workloads + if buildValues.PodSecurityContext.RunAsUser != 0 { + cronjob.Spec.JobTemplate.Spec.Template.Spec.SecurityContext = &corev1.PodSecurityContext{ + RunAsUser: helpers.Int64Ptr(buildValues.PodSecurityContext.RunAsUser), + RunAsGroup: helpers.Int64Ptr(buildValues.PodSecurityContext.RunAsGroup), + FSGroup: helpers.Int64Ptr(buildValues.PodSecurityContext.FsGroup), + } + } + + // start set up any volumes this cronjob can use + // first handle any dynamic secret volumes that come from kubernetes secrets that are labeled + for _, dsv := range buildValues.DynamicSecretVolumes { + volume := corev1.Volume{ + Name: dsv.Name, + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: dsv.Secret.SecretName, + Optional: &dsv.Secret.Optional, + }, + }, + } + cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes = append(cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes, volume) + } + + // if there is a persistent volume attached to this service, handle adding that here + if serviceTypeValues.Volumes.PersistentVolumeSize != "" { + volume := corev1.Volume{ + Name: serviceValues.PersistentVolumeName, + VolumeSource: corev1.VolumeSource{ + PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ + ClaimName: serviceValues.PersistentVolumeName, + }, + }, + } + // if this servicetype has defaults, use them if one is not provided + if serviceValues.PersistentVolumePath == "" { + volume.Name = serviceValues.OverrideName + volume.VolumeSource.PersistentVolumeClaim.ClaimName = serviceValues.OverrideName + } + cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes = append(cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes, volume) + } + + // if there are any specific container volume overrides provided, handle those here + for _, pcv := range serviceTypeValues.PrimaryContainer.Volumes { + volume := corev1.Volume{} + helpers.TemplateThings(serviceValues, pcv, &volume) + cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes = append(cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes, volume) + } + for _, scv := range serviceTypeValues.SecondaryContainer.Volumes { + volume := corev1.Volume{} + helpers.TemplateThings(serviceValues, scv, &volume) + cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes = append(cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes, volume) + } + + // future handle any additional volume mounts here + // @TODO + + // end set up any volumes this cronjob can use + + // handle any image pull secrets + pullsecrets := []corev1.LocalObjectReference{} + for _, pullsecret := range buildValues.ImagePullSecrets { + pullsecrets = append(pullsecrets, corev1.LocalObjectReference{ + Name: pullsecret.Name, + }) + } + cronjob.Spec.JobTemplate.Spec.Template.Spec.ImagePullSecrets = pullsecrets + + // start working out the containers to add + // add any init container that the service may have + if serviceTypeValues.InitContainer.Name != "" { + enableInit := false + init := serviceTypeValues.InitContainer + // check if the init container has any flags required to add it + for k, v := range buildValues.Flags { + if init.Flags[k] == v { + enableInit = true + } + } + // otherwise if there are no flags + if enableInit || init.Flags == nil { + for _, svm := range serviceTypeValues.InitContainer.VolumeMounts { + volumeMount := corev1.VolumeMount{} + helpers.TemplateThings(serviceValues, svm, &volumeMount) + init.Container.VolumeMounts = append(init.Container.VolumeMounts, volumeMount) + } + cmd := []string{} + for _, c := range init.Command { + var c2 string + helpers.TemplateThings(serviceValues, c, &c2) + cmd = append(cmd, c2) + } + init.Container.Command = cmd + cronjob.Spec.JobTemplate.Spec.Template.Spec.InitContainers = append(cronjob.Spec.JobTemplate.Spec.Template.Spec.InitContainers, init.Container) + } + } + + // handle the primary container for the service type + container := serviceTypeValues.PrimaryContainer + + // handle setting the rest of the containers specs with values from the service or build values + container.Container.Name = nCronjob.Name + container.Container.Image = serviceValues.ImageName + + // set up cronjobs if required + cronjobs := "" + for _, cronjob := range serviceValues.InPodCronjobs { + cronjobs = fmt.Sprintf("%s%s %s\n", cronjobs, cronjob.Schedule, cronjob.Command) + } + envvars := []corev1.EnvVar{ + { + Name: "LAGOON_GIT_SHA", + Value: buildValues.GitSha, + }, + { + Name: "SERVICE_NAME", + Value: serviceValues.OverrideName, + }, + } + for _, envvar := range envvars { + container.Container.Env = append(container.Container.Env, envvar) + } + container.Container.EnvFrom = []corev1.EnvFromSource{ + { + ConfigMapRef: &corev1.ConfigMapEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: "lagoon-env", + }, + }, + }, + } + + // mount the volumes in the primary container + for _, dsm := range buildValues.DynamicSecretMounts { + volumeMount := corev1.VolumeMount{ + Name: dsm.Name, + MountPath: dsm.MountPath, + ReadOnly: dsm.ReadOnly, + } + container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) + } + if serviceTypeValues.Volumes.PersistentVolumeSize != "" { + volumeMount := corev1.VolumeMount{ + Name: serviceValues.PersistentVolumeName, + MountPath: serviceValues.PersistentVolumePath, + } + // if this servicetype has a default volume path, use them it if one isn't provided + if serviceValues.PersistentVolumePath == "" { + volumeMount.MountPath = serviceTypeValues.Volumes.PersistentVolumePath + volumeMount.Name = serviceValues.OverrideName + } + container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) + } + for _, svm := range serviceTypeValues.PrimaryContainer.VolumeMounts { + volumeMount := corev1.VolumeMount{} + helpers.TemplateThings(serviceValues, svm, &volumeMount) + container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) + } + if serviceValues.PersistentVolumeName != "" && serviceValues.PersistentVolumePath != "" && serviceTypeValues.Volumes.PersistentVolumeSize == "" { + container.Container.VolumeMounts = append(container.Container.VolumeMounts, corev1.VolumeMount{ + Name: serviceValues.PersistentVolumeName, + MountPath: serviceValues.PersistentVolumePath, + }) + volume := corev1.Volume{ + Name: serviceValues.PersistentVolumeName, + VolumeSource: corev1.VolumeSource{ + PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ + ClaimName: serviceValues.PersistentVolumeName, + }, + }, + } + cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes = append(cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes, volume) + } + + if buildValues.Resources.Limits.Memory != "" { + if container.Container.Resources.Limits == nil { + container.Container.Resources.Limits = corev1.ResourceList{} + } + container.Container.Resources.Limits[corev1.ResourceMemory] = resource.MustParse(buildValues.Resources.Limits.Memory) + } + if buildValues.Resources.Limits.EphemeralStorage != "" { + if container.Container.Resources.Limits == nil { + container.Container.Resources.Limits = corev1.ResourceList{} + } + container.Container.Resources.Limits[corev1.ResourceEphemeralStorage] = resource.MustParse(buildValues.Resources.Limits.EphemeralStorage) + } + if buildValues.Resources.Requests.EphemeralStorage != "" { + if container.Container.Resources.Requests == nil { + container.Container.Resources.Requests = corev1.ResourceList{} + } + container.Container.Resources.Requests[corev1.ResourceEphemeralStorage] = resource.MustParse(buildValues.Resources.Requests.EphemeralStorage) + } + + // strip ports from the cronjobs + container.Container.Ports = nil + container.Container.ReadinessProbe = nil + container.Container.LivenessProbe = nil + + container.Container.Command = []string{"/lagoon/cronjob.sh", nCronjob.Command} + + // append the final defined container to the spec + cronjob.Spec.JobTemplate.Spec.Template.Spec.Containers = append(cronjob.Spec.JobTemplate.Spec.Template.Spec.Containers, container.Container) + + // end cronjob template + + cronjobBytes, err = yaml.Marshal(cronjob) + if err != nil { + return nil, err + } + + // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) + // add the seperator to the template so that it can be `kubectl apply` in bulk as part + // of the current build process + // join all dbaas-consumer templates together + restoreResult := append(separator[:], cronjobBytes[:]...) + result = append(result, restoreResult[:]...) + } + } + } + return result, nil +} diff --git a/internal/templating/services/templates_cronjob_test.go b/internal/templating/services/templates_cronjob_test.go new file mode 100644 index 00000000..92cd4994 --- /dev/null +++ b/internal/templating/services/templates_cronjob_test.go @@ -0,0 +1,95 @@ +package services + +import ( + "os" + "reflect" + "testing" + + "github.com/andreyvit/diff" + "github.com/uselagoon/build-deploy-tool/internal/generator" + "github.com/uselagoon/build-deploy-tool/internal/lagoon" +) + +func TestGenerateCronjobTemplate(t *testing.T) { + type args struct { + buildValues generator.BuildValues + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + { + name: "test1 - cli", + 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", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + GitSha: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + Services: []generator.ServiceValues{ + { + Name: "myservice", + OverrideName: "myservice", + Type: "cli", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/myservice@latest", + NativeCronjobs: []lagoon.Cronjob{ + { + Name: "cronjob-myservice-my-cronjobbb", + Service: "myservice", + Command: "sleep 300", + Schedule: "5 2 * * *", + }, + { + Name: "cronjob-myservice-my-other-cronjobbb", + Service: "myservice", + Command: "env", + Schedule: "25 6 * * *", + }, + }, + }, + // { + // Name: "myservice-persist", + // OverrideName: "myservice-persist", + // Type: "cli-persistent", + // DBaaSEnvironment: "production", + // ImageName: "harbor.example.com/example-project/environment-name/myservice-persistent@latest", + // PersistentVolumePath: "/storage/data", + // PersistentVolumeName: "nginx-php", + // }, + }, + }, + }, + want: "test-resources/cronjob/result-cli-1.yaml", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GenerateCronjobTemplate(tt.args.buildValues) + if (err != nil) != tt.wantErr { + t.Errorf("GenerateCronjobTemplate() error = %v, wantErr %v", err, tt.wantErr) + return + } + r1, err := os.ReadFile(tt.want) + if err != nil { + t.Errorf("couldn't read file %v: %v", tt.want, err) + } + if !reflect.DeepEqual(string(got), string(r1)) { + t.Errorf("GenerateCronjobTemplate() = \n%v", diff.LineDiff(string(r1), string(got))) + } + }) + } +} diff --git a/internal/templating/services/test-resources/cronjob/result-cli-1.yaml b/internal/templating/services/test-resources/cronjob/result-cli-1.yaml new file mode 100644 index 00000000..f645ec33 --- /dev/null +++ b/internal/templating/services/test-resources/cronjob/result-cli-1.yaml @@ -0,0 +1,176 @@ +--- +apiVersion: batch/v1beta1 +kind: CronJob +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: cli + 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: cli + lagoon.sh/template: cli-0.1.0 + name: cronjob-myservice-my-cronjobbb +spec: + concurrencyPolicy: Forbid + failedJobsHistoryLimit: 1 + jobTemplate: + metadata: + creationTimestamp: null + spec: + 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: cli + 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: cli + lagoon.sh/template: cli-0.1.0 + spec: + containers: + - command: + - /lagoon/cronjob.sh + - sleep 300 + env: + - name: LAGOON_GIT_SHA + value: "0" + - name: SERVICE_NAME + value: myservice + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice@latest + name: cronjob-myservice-my-cronjobbb + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + dnsConfig: + options: + - name: timeout + value: "60" + - name: attempts + value: "10" + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + restartPolicy: Never + volumes: + - name: lagoon-sshkey + secret: + defaultMode: 420 + secretName: lagoon-sshkey + schedule: 5 2 * * * + startingDeadlineSeconds: 240 + successfulJobsHistoryLimit: 0 +status: {} +--- +apiVersion: batch/v1beta1 +kind: CronJob +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: cli + 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: cli + lagoon.sh/template: cli-0.1.0 + name: cronjob-myservice-my-other-cronjobbb +spec: + concurrencyPolicy: Forbid + failedJobsHistoryLimit: 1 + jobTemplate: + metadata: + creationTimestamp: null + spec: + 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: cli + 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: cli + lagoon.sh/template: cli-0.1.0 + spec: + containers: + - command: + - /lagoon/cronjob.sh + - env + env: + - name: LAGOON_GIT_SHA + value: "0" + - name: SERVICE_NAME + value: myservice + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice@latest + name: cronjob-myservice-my-other-cronjobbb + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + dnsConfig: + options: + - name: timeout + value: "60" + - name: attempts + value: "10" + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + restartPolicy: Never + volumes: + - name: lagoon-sshkey + secret: + defaultMode: 420 + secretName: lagoon-sshkey + schedule: 25 6 * * * + startingDeadlineSeconds: 240 + successfulJobsHistoryLimit: 0 +status: {} diff --git a/test-resources/template-lagoon-services/test1-results/cronjobs.yaml b/test-resources/template-lagoon-services/test1-results/cronjobs.yaml new file mode 100644 index 00000000..e69de29b diff --git a/test-resources/template-lagoon-services/test2-results-a/cronjobs.yaml b/test-resources/template-lagoon-services/test2-results-a/cronjobs.yaml new file mode 100644 index 00000000..da171713 --- /dev/null +++ b/test-resources/template-lagoon-services/test2-results-a/cronjobs.yaml @@ -0,0 +1,96 @@ +--- +apiVersion: batch/v1beta1 +kind: CronJob +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: cli + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: cli + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + name: cronjob-cli-drush-cron2 +spec: + concurrencyPolicy: Forbid + failedJobsHistoryLimit: 1 + jobTemplate: + metadata: + creationTimestamp: null + spec: + template: + metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/configMapSha: "" + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: cli + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: cli + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + spec: + containers: + - command: + - /lagoon/cronjob.sh + - drush cron + env: + - name: LAGOON_GIT_SHA + - name: SERVICE_NAME + value: cli + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/cli:latest + name: cronjob-cli-drush-cron2 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + - mountPath: /app/docroot/sites/default/files//php + name: nginx-php-twig + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + dnsConfig: + options: + - name: timeout + value: "60" + - name: attempts + value: "10" + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + restartPolicy: Never + volumes: + - name: lagoon-sshkey + secret: + defaultMode: 420 + secretName: lagoon-sshkey + - emptyDir: {} + name: nginx-php-twig + - name: nginx-php + persistentVolumeClaim: + claimName: nginx-php + schedule: 5,35 * * * * + startingDeadlineSeconds: 240 + successfulJobsHistoryLimit: 0 +status: {} diff --git a/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml b/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml new file mode 100644 index 00000000..ac1a1bc6 --- /dev/null +++ b/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml @@ -0,0 +1,100 @@ +--- +apiVersion: batch/v1beta1 +kind: CronJob +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: cli + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: cli + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + name: cronjob-cli-drush-cron2 +spec: + concurrencyPolicy: Forbid + failedJobsHistoryLimit: 1 + jobTemplate: + metadata: + creationTimestamp: null + spec: + template: + metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/configMapSha: "" + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: cli + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: cli + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + spec: + containers: + - command: + - /lagoon/cronjob.sh + - drush cron + env: + - name: LAGOON_GIT_SHA + - name: SERVICE_NAME + value: cli + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/cli:latest + name: cronjob-cli-drush-cron2 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + - mountPath: /app/docroot/sites/default/files//php + name: nginx-php-twig + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + dnsConfig: + options: + - name: timeout + value: "60" + - name: attempts + value: "10" + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + restartPolicy: Never + securityContext: + fsGroup: 10000 + runAsGroup: 0 + runAsUser: 10001 + volumes: + - name: lagoon-sshkey + secret: + defaultMode: 420 + secretName: lagoon-sshkey + - emptyDir: {} + name: nginx-php-twig + - name: nginx-php + persistentVolumeClaim: + claimName: nginx-php + schedule: 5,35 * * * * + startingDeadlineSeconds: 240 + successfulJobsHistoryLimit: 0 +status: {} From fdba50bfa9aa4688d5f4794026a0b78e0f6fdd0c Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 24 Jul 2023 16:37:09 +1000 Subject: [PATCH 24/92] chore: remove old templating code from bash, use build-deploy-tool now --- legacy/build-deploy-docker-compose.sh | 160 +----------------- legacy/scripts/exec-autogenerated-pattern.sh | 99 ----------- .../exec-kubectl-resources-with-images.sh | 30 ---- legacy/scripts/exec-spot-generation.sh | 96 ----------- 4 files changed, 9 insertions(+), 376 deletions(-) delete mode 100644 legacy/scripts/exec-autogenerated-pattern.sh delete mode 100755 legacy/scripts/exec-kubectl-resources-with-images.sh delete mode 100644 legacy/scripts/exec-spot-generation.sh diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index eb713da0..c3d0672d 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -1382,148 +1382,6 @@ set -x ############################################## ### CREATE PVC, DEPLOYMENTS AND CRONJOBS ############################################## - -YAML_FOLDER="/kubectl-build-deploy/lagoon/deploymentconfigs-pvcs-cronjobs-backups" -mkdir -p $YAML_FOLDER - -for SERVICE_TYPES_ENTRY in "${SERVICE_TYPES[@]}" -do - IFS=':' read -ra SERVICE_TYPES_ENTRY_SPLIT <<< "$SERVICE_TYPES_ENTRY" - - SERVICE_NAME=${SERVICE_TYPES_ENTRY_SPLIT[0]} - SERVICE_TYPE=${SERVICE_TYPES_ENTRY_SPLIT[1]} - - SERVICE_NAME_IMAGE="${MAP_SERVICE_NAME_TO_IMAGENAME[${SERVICE_NAME}]}" - SERVICE_NAME_IMAGE_HASH="${IMAGE_HASHES[${SERVICE_NAME_IMAGE}]}" - - SERVICE_NAME_UPPERCASE=$(echo "$SERVICE_NAME" | tr '[:lower:]' '[:upper:]') - - COMPOSE_SERVICE=${MAP_SERVICE_TYPE_TO_COMPOSE_SERVICE["${SERVICE_TYPES_ENTRY}"]} - - # Some Templates need additonal Parameters, like where persistent storage can be found. - HELM_SET_VALUES=() - - # PERSISTENT_STORAGE_CLASS=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$COMPOSE_SERVICE.labels.lagoon\\.persistent\\.class false) - # if [ ! $PERSISTENT_STORAGE_CLASS == "false" ]; then - # TEMPLATE_PARAMETERS+=(-p PERSISTENT_STORAGE_CLASS="${PERSISTENT_STORAGE_CLASS}") - # fi - - PERSISTENT_STORAGE_SIZE=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$COMPOSE_SERVICE.labels.lagoon\\.persistent\\.size false) - if [ ! $PERSISTENT_STORAGE_SIZE == "false" ]; then - HELM_SET_VALUES+=(--set "persistentStorage.size=${PERSISTENT_STORAGE_SIZE}") - fi - - PERSISTENT_STORAGE_PATH=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$COMPOSE_SERVICE.labels.lagoon\\.persistent false) - if [ ! $PERSISTENT_STORAGE_PATH == "false" ]; then - HELM_SET_VALUES+=(--set "persistentStorage.path=${PERSISTENT_STORAGE_PATH}") - - PERSISTENT_STORAGE_NAME=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$COMPOSE_SERVICE.labels.lagoon\\.persistent\\.name false) - if [ ! $PERSISTENT_STORAGE_NAME == "false" ]; then - HELM_SET_VALUES+=(--set "persistentStorage.name=${PERSISTENT_STORAGE_NAME}") - else - HELM_SET_VALUES+=(--set "persistentStorage.name=${SERVICE_NAME}") - fi - fi - - # all our templates appear to support this if they have a service defined in them, but only `basic` properly supports this - # as all services will get re-written in the future into build-deploy-tool, just handle basic only for now and don't - # support it in other templates (yet) - if [[ "$SERVICE_TYPE" == "basic" ]] || - [[ "$SERVICE_TYPE" == "basic-persistent" ]]; then - SERVICE_PORT_NUMBER=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$COMPOSE_SERVICE.labels.lagoon\\.service\\.port false) - if [ ! $SERVICE_PORT_NUMBER == "false" ]; then - # check if the port provided is actually a number - if ! [[ $SERVICE_PORT_NUMBER =~ ^[0-9]+$ ]] ; then - echo "Provided service port is not a number"; exit 1; - fi - HELM_SET_VALUES+=(--set "service.port=${SERVICE_PORT_NUMBER}") - fi - fi - - # handle spot configurations - . /kubectl-build-deploy/scripts/exec-spot-generation.sh - - # handle dynamically added secrets - . /kubectl-build-deploy/scripts/exec-dynamic-secret-volumes.sh - -# TODO: we don't need this anymore - # DEPLOYMENT_STRATEGY=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$COMPOSE_SERVICE.labels.lagoon\\.deployment\\.strategy false) - # if [ ! $DEPLOYMENT_STRATEGY == "false" ]; then - # TEMPLATE_PARAMETERS+=(-p DEPLOYMENT_STRATEGY="${DEPLOYMENT_STRATEGY}") - # fi - - # start cronjob disabled - CRONJOBS_DISABLED=false - if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then - CRONJOBS_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "LAGOON_CRONJOBS_DISABLED") | "\(.value)"')) - fi - if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then - TEMP_CRONJOBS_DISABLED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "LAGOON_CRONJOBS_DISABLED") | "\(.value)"')) - if [ ! -z $TEMP_CRONJOBS_DISABLED ]; then - CRONJOBS_DISABLED=$TEMP_CRONJOBS_DISABLED - fi - fi - - if [ ! "$CRONJOBS_DISABLED" == true ]; then - CRONJOB_COUNTER=0 - CRONJOBS_ARRAY_INSIDE_POD=() #crons run inside an existing pod more frequently than every 15 minutes - while [ -n "$(cat .lagoon.yml | shyaml keys environments.${BRANCH//./\\.}.cronjobs.$CRONJOB_COUNTER 2> /dev/null)" ] - do - - CRONJOB_SERVICE=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH//./\\.}.cronjobs.$CRONJOB_COUNTER.service) - - # Only implement the cronjob for the services we are currently handling - if [ $CRONJOB_SERVICE == $SERVICE_NAME ]; then - - CRONJOB_NAME=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH//./\\.}.cronjobs.$CRONJOB_COUNTER.name | sed "s/[^[:alnum:]-]/-/g" | sed "s/^-//g") - - CRONJOB_SCHEDULE_RAW=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH//./\\.}.cronjobs.$CRONJOB_COUNTER.schedule) - - # Convert the Cronjob Schedule for additional features and better spread - CRONJOB_SCHEDULE=$( /kubectl-build-deploy/scripts/convert-crontab.sh "${NAMESPACE}" "$CRONJOB_SCHEDULE_RAW") - CRONJOB_COMMAND=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH//./\\.}.cronjobs.$CRONJOB_COUNTER.command) - - if cronScheduleMoreOftenThan30Minutes "$CRONJOB_SCHEDULE_RAW" ; then - # If this cronjob is more often than 30 minutes, we run the cronjob inside the pod itself - CRONJOBS_ARRAY_INSIDE_POD+=("${CRONJOB_SCHEDULE} ${CRONJOB_COMMAND}") - else - # This cronjob runs less ofen than every 30 minutes, we create a kubernetes native cronjob for it. - - # Add this cronjob to the native cleanup array, this will remove native cronjobs at the end of this script - NATIVE_CRONJOB_CLEANUP_ARRAY+=($(echo "cronjob-${SERVICE_NAME}-${CRONJOB_NAME}" | awk '{print tolower($0)}')) - # kubectl stores this cronjob name lowercased - - # if [ ! -f $OPENSHIFT_TEMPLATE ]; then - # echo "No cronjob support for service '${SERVICE_NAME}' with type '${SERVICE_TYPE}', please contact the Lagoon maintainers to implement cronjob support"; exit 1; - # else - - yq3 write -i -- /kubectl-build-deploy/${SERVICE_NAME}-values.yaml "nativeCronjobs.${CRONJOB_NAME,,}.schedule" "$CRONJOB_SCHEDULE" - yq3 write -i -- /kubectl-build-deploy/${SERVICE_NAME}-values.yaml "nativeCronjobs.${CRONJOB_NAME,,}.command" "$CRONJOB_COMMAND" - - # fi - fi - fi - - let CRONJOB_COUNTER=CRONJOB_COUNTER+1 - done - - - # if there are cronjobs running inside pods, add them to the deploymentconfig. - if [[ ${#CRONJOBS_ARRAY_INSIDE_POD[@]} -ge 1 ]]; then - yq3 write -i -- /kubectl-build-deploy/${SERVICE_NAME}-values.yaml 'inPodCronjobs' "$(printf '%s\n' "${CRONJOBS_ARRAY_INSIDE_POD[@]}")" - else - yq3 write -i --tag '!!str' -- /kubectl-build-deploy/${SERVICE_NAME}-values.yaml 'inPodCronjobs' '' - fi - - else - echo ">> Cronjob configurations disabled for this build" - fi - # end cronjob disabled - - . /kubectl-build-deploy/scripts/exec-kubectl-resources-with-images.sh - -done - set +x # generate a map of servicename>imagename+hash json for the build-deploy-tool to use when templating @@ -1551,30 +1409,29 @@ set -x ############################################## set +x -if [ "$(ls -A $YAML_FOLDER/)" ]; then +if [ "$(ls -A $LAGOON_SERVICES_YAML_FOLDER/)" ]; then if [ "$CI" == "true" ]; then # During CI tests of Lagoon itself we only have a single compute node, so we change podAntiAffinity to podAffinity - find $YAML_FOLDER -type f -print0 | xargs -0 sed -i s/podAntiAffinity/podAffinity/g + find $LAGOON_SERVICES_YAML_FOLDER -type f -print0 | xargs -0 sed -i s/podAntiAffinity/podAffinity/g # During CI tests of Lagoon itself we only have a single compute node, so we change ReadWriteMany to ReadWriteOnce - find $YAML_FOLDER -type f -print0 | xargs -0 sed -i s/ReadWriteMany/ReadWriteOnce/g + find $LAGOON_SERVICES_YAML_FOLDER -type f -print0 | xargs -0 sed -i s/ReadWriteMany/ReadWriteOnce/g fi if [ "$(featureFlag RWX_TO_RWO)" = enabled ]; then # If there is only a single compute node, this can be used to change RWX to RWO - find $YAML_FOLDER -type f -print0 | xargs -0 sed -i s/ReadWriteMany/ReadWriteOnce/g + find $LAGOON_SERVICES_YAML_FOLDER -type f -print0 | xargs -0 sed -i s/ReadWriteMany/ReadWriteOnce/g fi - if [ "$(ls -A $YAML_FOLDER)" ]; then - # TODO: this will only be cronjobs until cronjobs are done via the go templating system - find $YAML_FOLDER -type f -exec cat {} \; - kubectl apply -n ${NAMESPACE} -f $YAML_FOLDER/ - fi + echo "=== deployment templates for services ===" + ls -A $LAGOON_SERVICES_YAML_FOLDER # cat $LAGOON_SERVICES_YAML_FOLDER/services.yaml # cat $LAGOON_SERVICES_YAML_FOLDER/pvcs.yaml # cat $LAGOON_SERVICES_YAML_FOLDER/deployments.yaml + # cat $LAGOON_SERVICES_YAML_FOLDER/cronjobs.yaml kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/services.yaml kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/pvcs.yaml kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/deployments.yaml + kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/cronjobs.yaml fi set -x @@ -1630,6 +1487,7 @@ CURRENT_CRONJOBS=$(kubectl -n ${NAMESPACE} get cronjobs --no-headers | cut -d " IFS=' ' read -a SPLIT_CURRENT_CRONJOBS <<< $CURRENT_CRONJOBS +NATIVE_CRONJOB_CLEANUP_ARRAY=($(build-deploy-tool identify native-cronjobs | jq -r '.[]')) for SINGLE_NATIVE_CRONJOB in ${SPLIT_CURRENT_CRONJOBS[@]} do re="\<$SINGLE_NATIVE_CRONJOB\>" diff --git a/legacy/scripts/exec-autogenerated-pattern.sh b/legacy/scripts/exec-autogenerated-pattern.sh deleted file mode 100644 index c614da52..00000000 --- a/legacy/scripts/exec-autogenerated-pattern.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash - -############################################## -### Function to generate the url used by autogenerated ingress objects -### Given a router pattern, it will create the required domains -############################################## -function routerPattern2DomainGenerator { - DOMAIN_PARTS=${1} - SERVICE=${2} - PROJECT=${3} - ENVIRONMENT=${4} - - HAS_SERVICE_PATTERN=false - - re='(.*)\$\{service\}(.*)' - if [[ $DOMAIN_PARTS =~ $re ]]; then - HAS_SERVICE_PATTERN=true - DOMAIN_PARTS2=${BASH_REMATCH[1]}${SERVICE} - DOMAIN_PARTS=${DOMAIN_PARTS2}${BASH_REMATCH[2]} - fi - - re='(.*)\$\{project\}(.*)' - if [[ $DOMAIN_PARTS =~ $re ]]; then - DOMAIN_PARTS2=${BASH_REMATCH[1]}${PROJECT} - DOMAIN_PARTS=${DOMAIN_PARTS2}${BASH_REMATCH[2]} - fi - - re='(.*)\$\{environment\}(.*)' - if [[ $DOMAIN_PARTS =~ $re ]]; then - DOMAIN_PARTS2=${BASH_REMATCH[1]}${ENVIRONMENT} - DOMAIN_PARTS=${DOMAIN_PARTS2}${BASH_REMATCH[2]} - fi - - # fallback to the default behaviour which adds the service with a dot - # if the pattern doesn't have a service pattern defined in it - if [ $HAS_SERVICE_PATTERN == "false" ]; then - DOMAIN_PARTS=${SERVICE}.${DOMAIN_PARTS} - fi - - - # once all the parts of the router pattern have been - DOMAIN_HASH=$(echo $DOMAIN_PARTS | sha256sum | awk '{print $1}' | cut -c -8) - FINAL_DOMAIN="" - # split the domain up by the dot and iterate over each part to check its length - IFS='.' read -ra DOMAIN_PARTS_SPLIT <<< "$DOMAIN_PARTS" - for DOMAIN_PART in ${DOMAIN_PARTS_SPLIT[@]} - do - if [ ${#DOMAIN_PART} -gt 63 ]; then - # if the part of the domain is greater than 63, then keep 54 characters and add the domain hash (8) and a dash (1) - # to the remaining domain part (54+1+8=63) - DOMAIN_PART=$(echo ${DOMAIN_PART} | cut -c -54 | sed -e 's/-$//')-${DOMAIN_HASH} - fi - # combine the parts - FINAL_DOMAIN=${FINAL_DOMAIN}${DOMAIN_PART}. - done - # strip the trailing dot from the domain - echo "$(echo ${FINAL_DOMAIN} | rev | cut -c 2- | rev)" -} - -############################################## -### Function to generate the short url used by some ingress objects -### Performs the same function that the build-deploy controller currently does -############################################## -function generateShortUrl { - DOMAIN_PARTS=${1} - SERVICE=${2} - PROJECT=${3} - ENVIRONMENT=${4} - - HAS_SERVICE_PATTERN=false - - re='(.*)\$\{service\}(.*)' - if [[ $DOMAIN_PARTS =~ $re ]]; then - HAS_SERVICE_PATTERN=true - DOMAIN_PARTS2=${BASH_REMATCH[1]}${SERVICE} - DOMAIN_PARTS=${DOMAIN_PARTS2}${BASH_REMATCH[2]} - fi - - re='(.*)\$\{project\}(.*)' - if [[ $DOMAIN_PARTS =~ $re ]]; then - SHA256_B32_PROJECT=$(echo -e "import sys\nimport base64\nimport hashlib\nprint(base64.b32encode(bytearray(hashlib.sha256(sys.argv[1].encode()).digest())).decode('utf-8'))" | python3 - "${PROJECT}" | tr '[:upper:]' '[:lower:]' | cut -c -8) - DOMAIN_PARTS2=${BASH_REMATCH[1]}${SHA256_B32_PROJECT} - DOMAIN_PARTS=${DOMAIN_PARTS2}${BASH_REMATCH[2]} - fi - - re='(.*)\$\{environment\}(.*)' - if [[ $DOMAIN_PARTS =~ $re ]]; then - SHA256_B32_ENVIRONMENT=$(echo -e "import sys\nimport base64\nimport hashlib\nprint(base64.b32encode(bytearray(hashlib.sha256(sys.argv[1].encode()).digest())).decode('utf-8'))" | python3 - "${ENVIRONMENT}" | tr '[:upper:]' '[:lower:]' | cut -c -8) - DOMAIN_PARTS2=${BASH_REMATCH[1]}${SHA256_B32_ENVIRONMENT} - DOMAIN_PARTS=${DOMAIN_PARTS2}${BASH_REMATCH[2]} - fi - - # fallback to the default behaviour which adds the service with a dot - # if the pattern doesn't have a service pattern defined in it - if [ $HAS_SERVICE_PATTERN == "false" ]; then - DOMAIN_PARTS=${SERVICE}.${DOMAIN_PARTS} - fi - echo $DOMAIN_PARTS -} \ No newline at end of file diff --git a/legacy/scripts/exec-kubectl-resources-with-images.sh b/legacy/scripts/exec-kubectl-resources-with-images.sh deleted file mode 100755 index 669026d5..00000000 --- a/legacy/scripts/exec-kubectl-resources-with-images.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -# First check if we need multiple Images in this Template (check for `_SERVICE_IMAGE` - see underline) -if [[ $(helm show values /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} | grep "images:") ]]; then - # Inject Pullable Images into Template - while read line - do - # SERVICE_IMAGE Parameters are configured like "[SERVICETYPE]_SERVICE_IMAGE", we split the servicetype away and lowercase it - DEPLOYMENT_SERVICETYPE=$line - - # Load which pushed image matches this servicetype of this service name - DEPLOYMENT_SERVICETYPE_IMAGE_NAME="${MAP_DEPLOYMENT_SERVICETYPE_TO_IMAGENAME[${SERVICE_NAME}:${DEPLOYMENT_SERVICETYPE}]}" - # Load the Image Hash of the loaded Image - DEPLOYMENT_SERVICETYPE_IMAGE_NAME_HASH="${IMAGE_HASHES[${DEPLOYMENT_SERVICETYPE_IMAGE_NAME}]}" - - # Add the Image Hash as Parameter of "[SERVICETYPE]_SERVICE_IMAGE" - HELM_SET_VALUES+=(--set "images.${line}=${DEPLOYMENT_SERVICETYPE_IMAGE_NAME_HASH}") - done < <(cat /kubectl-build-deploy/helmcharts/${SERVICE_TYPE}/values.yaml | shyaml keys images) - helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml --set service_name="${SERVICE_NAME}" "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml - -# check if we need a single image to inject -elif [[ $(helm show values /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} | grep image) ]]; then - SERVICE_NAME_IMAGE="${MAP_SERVICE_NAME_TO_IMAGENAME[${SERVICE_NAME}]}" - SERVICE_NAME_IMAGE_HASH="${IMAGE_HASHES[${SERVICE_NAME_IMAGE}]}" - cat /kubectl-build-deploy/${SERVICE_NAME}-values.yaml - helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml --set image="${SERVICE_NAME_IMAGE_HASH}" "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml -elif [ -d /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} ]; then - cat /kubectl-build-deploy/${SERVICE_NAME}-values.yaml - helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml "${HELM_SET_VALUES[@]}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/${SERVICE_NAME}.yaml -fi diff --git a/legacy/scripts/exec-spot-generation.sh b/legacy/scripts/exec-spot-generation.sh deleted file mode 100644 index dff616f6..00000000 --- a/legacy/scripts/exec-spot-generation.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash - -# spot instance configuration - -# some service types can properly support multiple replicas under spot, this list defines them -SPOT_REPLICA_TYPES=nginx,nginx-persistent,nginx-php,nginx-php-persistent -SPOT_SERVICE_TYPES="" - -if [[ "$(featureFlag SPOT_INSTANCE_PRODUCTION)" = enabled && "${ENVIRONMENT_TYPE}" == "production" ]] || -[[ "$(featureFlag SPOT_INSTANCE_DEVELOPMENT)" = enabled && "${ENVIRONMENT_TYPE}" == "development" ]]; then - if [ "${ENVIRONMENT_TYPE}" == "production" ]; then - # production environments can support different spot instance types than development environments - SPOT_INSTANCE_PRODUCTION_TYPES="$(featureFlag SPOT_INSTANCE_PRODUCTION_TYPES)" - if [ ! -z "${SPOT_INSTANCE_PRODUCTION_TYPES}" ]; then - SPOT_SERVICE_TYPES="${SPOT_INSTANCE_PRODUCTION_TYPES}" - fi - SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES="$(featureFlag SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES)" - if [ ! -z "${SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES}" ]; then - SPOT_SERVICE_CRONJOB_TYPES="${SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES}" - fi - else - SPOT_INSTANCE_DEVELOPMENT_TYPES="$(featureFlag SPOT_INSTANCE_DEVELOPMENT_TYPES)" - if [ ! -z "${SPOT_INSTANCE_DEVELOPMENT_TYPES}" ]; then - SPOT_SERVICE_TYPES="${SPOT_INSTANCE_DEVELOPMENT_TYPES}" - fi - SPOT_INSTANCE_DEVELOPMENT_CRONJOB_TYPES="$(featureFlag SPOT_INSTANCE_DEVELOPMENT_CRONJOB_TYPES)" - if [ ! -z "${SPOT_INSTANCE_DEVELOPMENT_CRONJOB_TYPES}" ]; then - SPOT_SERVICE_CRONJOB_TYPES="${SPOT_INSTANCE_DEVELOPMENT_CRONJOB_TYPES}" - fi - fi - - # set deployment spot configurations - if [[ ${SPOT_SERVICE_TYPES} =~ (^|,)"${SERVICE_TYPE}"(,|$) ]]; then - FORCE_NODESELECTOR=${BASH_REMATCH[2]} - HELM_SET_VALUES+=(--set "useSpot=true") - # spot on production gets 2 replicas if the service type is in the supported SPOT_REPLICA_TYPES list - if [ "${ENVIRONMENT_TYPE}" == "production" ]; then - if [[ ${SPOT_REPLICA_TYPES} =~ (^|,)"${SERVICE_TYPE}"(,|$) ]]; then - HELM_SET_VALUES+=(--set "replicaCount=2") - fi - fi - echo -e "\ -tolerations: -- key: lagoon.sh/spot - operator: Exists - effect: NoSchedule -- key: lagoon.sh/spot - operator: Exists - effect: PreferNoSchedule -affinity: - nodeAffinity: - preferredDuringSchedulingIgnoredDuringExecution: - - weight: 1 - preference: - matchExpressions: - - key: lagoon.sh/spot - operator: Exists -" >> /kubectl-build-deploy/${SERVICE_NAME}-values.yaml - if [ "$FORCE_NODESELECTOR" == ":force" ]; then - echo -e "\ -nodeSelector: - lagoon.sh/spot: 'true' -" >> /kubectl-build-deploy/${SERVICE_NAME}-values.yaml - fi - fi - - # set cronjob spot configurations - if [[ ${SPOT_SERVICE_CRONJOB_TYPES} =~ (^|,)"${SERVICE_TYPE}"(,|$) ]]; then - FORCE_NODESELECTOR=${BASH_REMATCH[2]} - HELM_SET_VALUES+=(--set "cronjobUseSpot=true") - # spot on production gets 2 replicas if the service type is in the supported SPOT_REPLICA_TYPES list - echo -e "\ -cronjobTolerations: -- key: lagoon.sh/spot - operator: Exists - effect: NoSchedule -- key: lagoon.sh/spot - operator: Exists - effect: PreferNoSchedule -cronjobAffinity: - nodeAffinity: - preferredDuringSchedulingIgnoredDuringExecution: - - weight: 1 - preference: - matchExpressions: - - key: lagoon.sh/spot - operator: Exists -" >> /kubectl-build-deploy/${SERVICE_NAME}-values.yaml - if [ "$FORCE_NODESELECTOR" == ":force" ]; then - echo -e "\ -cronjobNodeSelector: - lagoon.sh/spot: 'true' -" >> /kubectl-build-deploy/${SERVICE_NAME}-values.yaml - fi - fi -fi \ No newline at end of file From f9a87cfb87fb671f3c6bf84a55c0dca8f312144b Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 25 Jul 2023 09:16:26 +1000 Subject: [PATCH 25/92] chore: first service should be named the same as the default service would have been --- internal/generator/buildvalues.go | 1 + .../templating/services/templates_service.go | 5 +-- .../services/templates_service_test.go | 7 ++++ .../service/result-basic-2.yaml | 35 +++++++++++++++++-- .../test1-results/services.yaml | 2 +- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index ca77983c..b3dec5d0 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -136,6 +136,7 @@ type ServiceValues struct { type AdditionalServicePort struct { ServicePort composetypes.ServicePortConfig `json:"servicePort,omitempty"` ServiceName string `json:"serviceName,omitempty"` + Index int `json:"-"` } // CronjobValues is the values for cronjobs diff --git a/internal/templating/services/templates_service.go b/internal/templating/services/templates_service.go index 789ec70d..d4628f10 100644 --- a/internal/templating/services/templates_service.go +++ b/internal/templating/services/templates_service.go @@ -58,10 +58,11 @@ func GenerateServiceTemplate( if val, ok := servicetypes.ServiceTypes[serviceValues.Type]; ok { if serviceValues.AdditionalServicePorts != nil { // if the service is set to consume the additional services only, then generate those here - for _, addPort := range serviceValues.AdditionalServicePorts { + for idx, addPort := range serviceValues.AdditionalServicePorts { // copy the service type so we can transform it as required serviceType := &servicetypes.ServiceType{} helpers.DeepCopy(val, serviceType) + addPort.Index = idx restoreResult, err := GenerateService(result, serviceType, serviceValues, addPort, labels, annotations, additionalLabels, additionalAnnotations) if err != nil { return nil, err @@ -103,7 +104,7 @@ func GenerateService(result []byte, serviceType *servicetypes.ServiceType, servi Name: serviceValues.OverrideName, }, } - if portOverride.ServiceName != "" { + if portOverride.ServiceName != "" && portOverride.Index != 0 { service.ObjectMeta.Name = portOverride.ServiceName } service.ObjectMeta.Labels = labels diff --git a/internal/templating/services/templates_service_test.go b/internal/templating/services/templates_service_test.go index 3df754c4..048fac14 100644 --- a/internal/templating/services/templates_service_test.go +++ b/internal/templating/services/templates_service_test.go @@ -199,6 +199,13 @@ func TestGenerateServiceTemplate(t *testing.T) { }, ServiceName: "myservice-persist-po-8191", }, + generator.AdditionalServicePort{ + ServicePort: types.ServicePortConfig{ + Target: 8192, + Protocol: "tcp", + }, + ServiceName: "myservice-persist-po-8192", + }, }, }, }, diff --git a/internal/templating/services/test-resources/service/result-basic-2.yaml b/internal/templating/services/test-resources/service/result-basic-2.yaml index 11ef5d26..59d0a902 100644 --- a/internal/templating/services/test-resources/service/result-basic-2.yaml +++ b/internal/templating/services/test-resources/service/result-basic-2.yaml @@ -17,7 +17,7 @@ metadata: lagoon.sh/service: myservice-po lagoon.sh/service-type: basic lagoon.sh/template: basic-0.1.0 - name: myservice-po-8191 + name: myservice-po spec: ports: - name: myservice-po-8191 @@ -48,7 +48,7 @@ metadata: lagoon.sh/service: myservice-persist-po lagoon.sh/service-type: basic-persistent lagoon.sh/template: basic-persistent-0.1.0 - name: myservice-persist-po-8191 + name: myservice-persist-po spec: ports: - name: myservice-persist-po-8191 @@ -60,3 +60,34 @@ spec: app.kubernetes.io/name: basic-persistent status: loadBalancer: {} +--- +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-persist-po + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist-po + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: myservice-persist-po-8192 +spec: + ports: + - name: myservice-persist-po-8192 + port: 8192 + protocol: TCP + targetPort: myservice-persist-po-8192 + selector: + app.kubernetes.io/instance: myservice-persist-po + app.kubernetes.io/name: basic-persistent +status: + loadBalancer: {} diff --git a/test-resources/template-lagoon-services/test1-results/services.yaml b/test-resources/template-lagoon-services/test1-results/services.yaml index e79fae07..77012133 100644 --- a/test-resources/template-lagoon-services/test1-results/services.yaml +++ b/test-resources/template-lagoon-services/test1-results/services.yaml @@ -17,7 +17,7 @@ metadata: lagoon.sh/service: node lagoon.sh/service-type: basic lagoon.sh/template: basic-0.1.0 - name: node-1234 + name: node spec: ports: - name: node-1234 From 1634ff76f6ce1007440ee5ddf21fea1a76ae94f5 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 26 Jul 2023 16:30:01 +1000 Subject: [PATCH 26/92] chore: update ingress template to support additional services --- .../templating/ingress/templates_ingress.go | 32 +++-- .../ingress/templates_ingress_test.go | 119 ++++++++++++++++++ .../result-custom-ingress7.yaml | 51 ++++++++ .../result-custom-ingress8.yaml | 51 ++++++++ 4 files changed, 241 insertions(+), 12 deletions(-) create mode 100644 internal/templating/ingress/test-resources/result-custom-ingress7.yaml create mode 100644 internal/templating/ingress/test-resources/result-custom-ingress8.yaml diff --git a/internal/templating/ingress/templates_ingress.go b/internal/templating/ingress/templates_ingress.go index 2fee60c9..2519c862 100644 --- a/internal/templating/ingress/templates_ingress.go +++ b/internal/templating/ingress/templates_ingress.go @@ -233,16 +233,24 @@ func GenerateIngressTemplate( Name: "http", } - // if a port number is provided, use it - if route.ServicePortNumber != nil { - servicePort = networkv1.ServiceBackendPort{ - Number: *route.ServicePortNumber, - } - } - // if a different port name is provided use it above all else - if route.ServicePortName != nil { - servicePort = networkv1.ServiceBackendPort{ - Name: *route.ServicePortName, + backendService := route.LagoonService + // check the additional service ports if they are there, and check if the provided route service is in this list of additional ports + // and use the name in the ingress + for _, service := range lValues.Services { + for idx, addPort := range service.AdditionalServicePorts { + if addPort.ServiceName == route.LagoonService { + servicePort = networkv1.ServiceBackendPort{ + Name: addPort.ServiceName, + } + backendService = service.OverrideName + } + // if this service is for the default named lagoonservice + if service.OverrideName == route.LagoonService && idx == 0 { + // and set the portname to the name of the first service in the list + servicePort = networkv1.ServiceBackendPort{ + Name: addPort.ServiceName, + } + } } } @@ -260,7 +268,7 @@ func GenerateIngressTemplate( PathType: &pt, Backend: networkv1.IngressBackend{ Service: &networkv1.IngressServiceBackend{ - Name: route.LagoonService, + Name: backendService, Port: servicePort, }, }, @@ -283,7 +291,7 @@ func GenerateIngressTemplate( PathType: &pt, Backend: networkv1.IngressBackend{ Service: &networkv1.IngressServiceBackend{ - Name: route.LagoonService, + Name: backendService, Port: servicePort, }, }, diff --git a/internal/templating/ingress/templates_ingress_test.go b/internal/templating/ingress/templates_ingress_test.go index 157cbb72..cdb1c194 100644 --- a/internal/templating/ingress/templates_ingress_test.go +++ b/internal/templating/ingress/templates_ingress_test.go @@ -7,6 +7,7 @@ import ( "time" "github.com/andreyvit/diff" + "github.com/compose-spec/compose-go/types" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" @@ -446,6 +447,124 @@ func TestGenerateKubeTemplate(t *testing.T) { }, want: "test-resources/result-custom-ingress6.yaml", }, + { + name: "custom-ingress1 with specific port service", + args: args{ + route: lagoon.RouteV2{ + Domain: "extra-long-name.a-really-long-name-that-should-truncate.www.example.com", + LagoonService: "myservice-po", + MonitoringPath: "/", + Insecure: helpers.StrPtr("Redirect"), + TLSAcme: helpers.BoolPtr(true), + Migrate: helpers.BoolPtr(false), + Annotations: map[string]string{ + "custom-annotation": "custom annotation value", + }, + Fastly: lagoon.Fastly{ + Watch: false, + }, + }, + values: generator.BuildValues{ + Project: "example-project", + Environment: "environment-with-really-really-reall-3fdb", + EnvironmentType: "production", + Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "lagoon.local", + Branch: "environment-with-really-really-reall-3fdb", + Monitoring: generator.MonitoringConfig{ + AlertContact: "abcdefg", + StatusPageID: "12345", + Enabled: true, + }, + Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/", + Services: []generator.ServiceValues{ + { + Name: "myservice-po", + OverrideName: "myservice-po", + AdditionalServicePorts: []generator.AdditionalServicePort{ + { + ServiceName: "myservice-po-8192", + ServicePort: types.ServicePortConfig{ + Target: 8192, + Protocol: "tcp", + }, + }, + { + ServiceName: "myservice-po-8211", + ServicePort: types.ServicePortConfig{ + Target: 8211, + Protocol: "tcp", + }, + }, + }, + }, + }, + }, + activeStandby: false, + }, + want: "test-resources/result-custom-ingress7.yaml", + }, + { + name: "custom-ingress1 with specific port service", + args: args{ + route: lagoon.RouteV2{ + Domain: "extra-long-name.a-really-long-name-that-should-truncate.www.example.com", + LagoonService: "myservice-po-8192", + MonitoringPath: "/", + Insecure: helpers.StrPtr("Redirect"), + TLSAcme: helpers.BoolPtr(true), + Migrate: helpers.BoolPtr(false), + Annotations: map[string]string{ + "custom-annotation": "custom annotation value", + }, + Fastly: lagoon.Fastly{ + Watch: false, + }, + }, + values: generator.BuildValues{ + Project: "example-project", + Environment: "environment-with-really-really-reall-3fdb", + EnvironmentType: "production", + Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "lagoon.local", + Branch: "environment-with-really-really-reall-3fdb", + Monitoring: generator.MonitoringConfig{ + AlertContact: "abcdefg", + StatusPageID: "12345", + Enabled: true, + }, + Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/", + Services: []generator.ServiceValues{ + { + Name: "myservice-po", + OverrideName: "myservice-po", + AdditionalServicePorts: []generator.AdditionalServicePort{ + { + ServiceName: "myservice-po-8192", + ServicePort: types.ServicePortConfig{ + Target: 8192, + Protocol: "tcp", + }, + }, + { + ServiceName: "myservice-po-8211", + ServicePort: types.ServicePortConfig{ + Target: 8211, + Protocol: "tcp", + }, + }, + }, + }, + }, + }, + activeStandby: false, + }, + want: "test-resources/result-custom-ingress8.yaml", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/templating/ingress/test-resources/result-custom-ingress7.yaml b/internal/templating/ingress/test-resources/result-custom-ingress7.yaml new file mode 100644 index 00000000..74d9a370 --- /dev/null +++ b/internal/templating/ingress/test-resources/result-custom-ingress7.yaml @@ -0,0 +1,51 @@ +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + custom-annotation: custom annotation value + fastly.amazee.io/watch: "false" + ingress.kubernetes.io/ssl-redirect: "true" + kubernetes.io/tls-acme: "true" + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + monitor.stakater.com/enabled: "true" + monitor.stakater.com/overridePath: / + nginx.ingress.kubernetes.io/ssl-redirect: "true" + uptimerobot.monitor.stakater.com/alert-contacts: abcdefg + uptimerobot.monitor.stakater.com/interval: "60" + uptimerobot.monitor.stakater.com/status-pages: "12345" + creationTimestamp: null + labels: + app.kubernetes.io/instance: extra-long-name-f6c8a + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: custom-ingress + dioscuri.amazee.io/migrate: "false" + helm.sh/chart: custom-ingress-0.1.0 + lagoon.sh/autogenerated: "false" + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/primaryIngress: "true" + lagoon.sh/project: example-project + lagoon.sh/service: extra-long-name-f6c8a + lagoon.sh/service-type: custom-ingress + name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com +spec: + rules: + - host: extra-long-name.a-really-long-name-that-should-truncate.www.example.com + http: + paths: + - backend: + service: + name: myservice-po + port: + name: myservice-po-8192 + path: / + pathType: Prefix + tls: + - hosts: + - extra-long-name.a-really-long-name-that-should-truncate.www.example.com + secretName: extra-long-name-f6c8a-tls +status: + loadBalancer: {} diff --git a/internal/templating/ingress/test-resources/result-custom-ingress8.yaml b/internal/templating/ingress/test-resources/result-custom-ingress8.yaml new file mode 100644 index 00000000..74d9a370 --- /dev/null +++ b/internal/templating/ingress/test-resources/result-custom-ingress8.yaml @@ -0,0 +1,51 @@ +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + custom-annotation: custom annotation value + fastly.amazee.io/watch: "false" + ingress.kubernetes.io/ssl-redirect: "true" + kubernetes.io/tls-acme: "true" + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + monitor.stakater.com/enabled: "true" + monitor.stakater.com/overridePath: / + nginx.ingress.kubernetes.io/ssl-redirect: "true" + uptimerobot.monitor.stakater.com/alert-contacts: abcdefg + uptimerobot.monitor.stakater.com/interval: "60" + uptimerobot.monitor.stakater.com/status-pages: "12345" + creationTimestamp: null + labels: + app.kubernetes.io/instance: extra-long-name-f6c8a + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: custom-ingress + dioscuri.amazee.io/migrate: "false" + helm.sh/chart: custom-ingress-0.1.0 + lagoon.sh/autogenerated: "false" + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/primaryIngress: "true" + lagoon.sh/project: example-project + lagoon.sh/service: extra-long-name-f6c8a + lagoon.sh/service-type: custom-ingress + name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com +spec: + rules: + - host: extra-long-name.a-really-long-name-that-should-truncate.www.example.com + http: + paths: + - backend: + service: + name: myservice-po + port: + name: myservice-po-8192 + path: / + pathType: Prefix + tls: + - hosts: + - extra-long-name.a-really-long-name-that-should-truncate.www.example.com + secretName: extra-long-name-f6c8a-tls +status: + loadBalancer: {} From 587d49eabfd0e14b95a084c8e3d21f8f469ef6a8 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 26 Jul 2023 16:30:19 +1000 Subject: [PATCH 27/92] chore: fix runasuser and fsgroup --- internal/generator/generator.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 3d1738d6..6d0e03f4 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -192,8 +192,8 @@ func NewGenerator( buildValues.Flags["rootlessworkloads"] = true buildValues.PodSecurityContext = PodSecurityContext{ RunAsGroup: 0, - RunAsUser: 10001, - FsGroup: 10000, + RunAsUser: 10000, + FsGroup: 10001, } } From 11db8e308cb97b5ffc830a03abd22ccc55c10069 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 26 Jul 2023 16:30:32 +1000 Subject: [PATCH 28/92] chore: remove unused options on routes --- internal/lagoon/routes.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/lagoon/routes.go b/internal/lagoon/routes.go index 571ba6b6..705c1eec 100644 --- a/internal/lagoon/routes.go +++ b/internal/lagoon/routes.go @@ -26,8 +26,6 @@ type RouteV2 struct { Annotations map[string]string `json:"annotations"` Labels map[string]string `json:"labels"` AlternativeNames []string `json:"alternativeNames"` - ServicePortNumber *int32 `json:"servicePortNumber"` - ServicePortName *string `json:"servicePortName"` IngressName string `json:"ingressName"` IngressClass string `json:"ingressClass"` HSTSEnabled *bool `json:"hstsEnabled,omitempty"` From 3cc527eaf05df45d13677fd89067bd86bfa0e409 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 26 Jul 2023 16:31:34 +1000 Subject: [PATCH 29/92] chore: fix runasuser and fsgroup --- internal/templating/services/templates_deployment_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/templating/services/templates_deployment_test.go b/internal/templating/services/templates_deployment_test.go index 72d10ebb..15655e89 100644 --- a/internal/templating/services/templates_deployment_test.go +++ b/internal/templating/services/templates_deployment_test.go @@ -135,8 +135,8 @@ func TestGenerateDeploymentTemplate(t *testing.T) { }, PodSecurityContext: generator.PodSecurityContext{ RunAsGroup: 0, - RunAsUser: 10001, - FsGroup: 10000, + RunAsUser: 10000, + FsGroup: 10001, }, GitSha: "0", ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", From addfe98f51bc4a4726d5022b7f1cf41693c75fdd Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 26 Jul 2023 16:33:04 +1000 Subject: [PATCH 30/92] chore: combine additional ports into one service object and fix tests --- .../templating/services/templates_service.go | 73 +++++++++---------- .../deployment/result-nginx-1.yaml | 8 +- .../service/result-basic-2.yaml | 27 ------- .../test22/docker-compose.yml | 10 +++ .../test1-results/services.yaml | 54 -------------- .../test2-results-b/cronjobs.yaml | 4 +- .../test2-results-b/deployments.yaml | 18 ++--- 7 files changed, 58 insertions(+), 136 deletions(-) diff --git a/internal/templating/services/templates_service.go b/internal/templating/services/templates_service.go index d4628f10..d2941d56 100644 --- a/internal/templating/services/templates_service.go +++ b/internal/templating/services/templates_service.go @@ -56,40 +56,26 @@ func GenerateServiceTemplate( // iterate over them and generate any kubernetes services for _, serviceValues := range checkedServices { if val, ok := servicetypes.ServiceTypes[serviceValues.Type]; ok { - if serviceValues.AdditionalServicePorts != nil { - // if the service is set to consume the additional services only, then generate those here - for idx, addPort := range serviceValues.AdditionalServicePorts { - // copy the service type so we can transform it as required - serviceType := &servicetypes.ServiceType{} - helpers.DeepCopy(val, serviceType) - addPort.Index = idx - restoreResult, err := GenerateService(result, serviceType, serviceValues, addPort, labels, annotations, additionalLabels, additionalAnnotations) - if err != nil { - return nil, err - } - result = append(result, restoreResult[:]...) - } - } else { - // if the service default has no ports, then don't generate any services - if val.Ports.Ports != nil { - // otherwise handle creating the default service port here - // copy the service type so we can transform it as required - serviceType := &servicetypes.ServiceType{} - helpers.DeepCopy(val, serviceType) - restoreResult, err := GenerateService(result, serviceType, serviceValues, generator.AdditionalServicePort{}, labels, annotations, additionalLabels, additionalAnnotations) - if err != nil { - return nil, err - } - result = append(result, restoreResult[:]...) - } + serviceType := &servicetypes.ServiceType{} + helpers.DeepCopy(val, serviceType) + restoreResult, err := GenerateService(result, serviceType, serviceValues, labels, annotations, additionalLabels, additionalAnnotations) + if err != nil { + return nil, err } + result = append(result, restoreResult[:]...) } } return result, nil } -func GenerateService(result []byte, serviceType *servicetypes.ServiceType, serviceValues generator.ServiceValues, portOverride generator.AdditionalServicePort, labels, annotations, additionalLabels, additionalAnnotations map[string]string) ([]byte, error) { +func GenerateService(result []byte, serviceType *servicetypes.ServiceType, serviceValues generator.ServiceValues, labels, annotations, additionalLabels, additionalAnnotations map[string]string) ([]byte, error) { + if serviceValues.AdditionalServicePorts == nil && serviceType.Ports.Ports == nil { + // there are no additional ports provided, and this servicetype has no default ports associated to it + // just drop out + return nil, nil + } var serviceBytes []byte + additionalLabels["app.kubernetes.io/name"] = serviceType.Name additionalLabels["app.kubernetes.io/instance"] = serviceValues.OverrideName additionalLabels["lagoon.sh/template"] = fmt.Sprintf("%s-%s", serviceType.Name, "0.1.0") @@ -104,9 +90,6 @@ func GenerateService(result []byte, serviceType *servicetypes.ServiceType, servi Name: serviceValues.OverrideName, }, } - if portOverride.ServiceName != "" && portOverride.Index != 0 { - service.ObjectMeta.Name = portOverride.ServiceName - } service.ObjectMeta.Labels = labels service.ObjectMeta.Annotations = annotations for key, value := range additionalLabels { @@ -142,17 +125,27 @@ func GenerateService(result []byte, serviceType *servicetypes.ServiceType, servi } // start compose service port override templating here - if portOverride.ServicePort.Target != 0 { - switch portOverride.ServicePort.Protocol { - case "udp": - serviceType.Ports.Ports[0].Protocol = corev1.ProtocolUDP - } - serviceType.Ports.Ports[0].Name = portOverride.ServiceName - serviceType.Ports.Ports[0].TargetPort = intstr.IntOrString{ - StrVal: portOverride.ServiceName, - Type: intstr.String, + if serviceValues.AdditionalServicePorts != nil { + // blank out the provided ports from the servicetype + serviceType.Ports.Ports = nil + // if the service is set to consume the additional services only, then generate those here + for _, addPort := range serviceValues.AdditionalServicePorts { + port := corev1.ServicePort{ + Protocol: corev1.ProtocolTCP, + Name: addPort.ServiceName, + TargetPort: intstr.IntOrString{ + StrVal: addPort.ServiceName, + Type: intstr.String, + }, + Port: int32(addPort.ServicePort.Target), + } + // set protocol to anything but tcp if required + switch addPort.ServicePort.Protocol { + case "udp": + port.Protocol = corev1.ProtocolUDP + } + serviceType.Ports.Ports = append(serviceType.Ports.Ports, port) } - serviceType.Ports.Ports[0].Port = int32(portOverride.ServicePort.Target) } // end compose service port override templating here diff --git a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml index a52bf387..569af5a7 100644 --- a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml @@ -110,9 +110,9 @@ spec: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production securityContext: - fsGroup: 10000 + fsGroup: 10001 runAsGroup: 0 - runAsUser: 10001 + runAsUser: 10000 status: {} --- apiVersion: apps/v1 @@ -251,9 +251,9 @@ spec: name: nginx2 priorityClassName: lagoon-priority-production securityContext: - fsGroup: 10000 + fsGroup: 10001 runAsGroup: 0 - runAsUser: 10001 + runAsUser: 10000 volumes: - name: nginx2 persistentVolumeClaim: diff --git a/internal/templating/services/test-resources/service/result-basic-2.yaml b/internal/templating/services/test-resources/service/result-basic-2.yaml index 59d0a902..3d8c2011 100644 --- a/internal/templating/services/test-resources/service/result-basic-2.yaml +++ b/internal/templating/services/test-resources/service/result-basic-2.yaml @@ -55,33 +55,6 @@ spec: port: 8191 protocol: TCP targetPort: myservice-persist-po-8191 - selector: - app.kubernetes.io/instance: myservice-persist-po - app.kubernetes.io/name: basic-persistent -status: - loadBalancer: {} ---- -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-persist-po - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: environment-name - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: myservice-persist-po - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: myservice-persist-po-8192 -spec: - ports: - name: myservice-persist-po-8192 port: 8192 protocol: TCP diff --git a/test-resources/template-autogenerated/test22/docker-compose.yml b/test-resources/template-autogenerated/test22/docker-compose.yml index 8489d7fe..caaf0425 100644 --- a/test-resources/template-autogenerated/test22/docker-compose.yml +++ b/test-resources/template-autogenerated/test22/docker-compose.yml @@ -16,6 +16,16 @@ services: - LAGOON_LOCALDEV_HTTP_PORT=3000 - LAGOON_ROUTE=http://node.docker.amazee.io + php: + build: + context: . + dockerfile: php.dockerfile + depends_on: + - cli + labels: + lagoon.type: nginx-php + lagoon.name: nginx-php + networks: amazeeio-network: external: true \ No newline at end of file diff --git a/test-resources/template-lagoon-services/test1-results/services.yaml b/test-resources/template-lagoon-services/test1-results/services.yaml index 77012133..1330aa84 100644 --- a/test-resources/template-lagoon-services/test1-results/services.yaml +++ b/test-resources/template-lagoon-services/test1-results/services.yaml @@ -24,64 +24,10 @@ spec: port: 1234 protocol: TCP targetPort: node-1234 - selector: - app.kubernetes.io/instance: node - app.kubernetes.io/name: basic -status: - loadBalancer: {} ---- -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-8191 -spec: - ports: - name: node-8191 port: 8191 protocol: TCP targetPort: node-8191 - selector: - app.kubernetes.io/instance: node - app.kubernetes.io/name: basic -status: - loadBalancer: {} ---- -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-9001 -spec: - ports: - name: node-9001 port: 9001 protocol: UDP diff --git a/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml b/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml index ac1a1bc6..23b2576b 100644 --- a/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml +++ b/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml @@ -81,9 +81,9 @@ spec: priorityClassName: lagoon-priority-production restartPolicy: Never securityContext: - fsGroup: 10000 + fsGroup: 10001 runAsGroup: 0 - runAsUser: 10001 + runAsUser: 10000 volumes: - name: lagoon-sshkey secret: diff --git a/test-resources/template-lagoon-services/test2-results-b/deployments.yaml b/test-resources/template-lagoon-services/test2-results-b/deployments.yaml index 1118d7c8..ad7ee77e 100644 --- a/test-resources/template-lagoon-services/test2-results-b/deployments.yaml +++ b/test-resources/template-lagoon-services/test2-results-b/deployments.yaml @@ -86,9 +86,9 @@ spec: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production securityContext: - fsGroup: 10000 + fsGroup: 10001 runAsGroup: 0 - runAsUser: 10001 + runAsUser: 10000 volumes: - name: lagoon-sshkey secret: @@ -178,9 +178,9 @@ spec: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production securityContext: - fsGroup: 10000 + fsGroup: 10001 runAsGroup: 0 - runAsUser: 10001 + runAsUser: 10000 status: {} --- apiVersion: apps/v1 @@ -263,9 +263,9 @@ spec: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production securityContext: - fsGroup: 10000 + fsGroup: 10001 runAsGroup: 0 - runAsUser: 10001 + runAsUser: 10000 status: {} --- apiVersion: apps/v1 @@ -388,7 +388,7 @@ spec: - sh - -c - "set -e\nSENTINEL=\"/storage/.lagoon-rootless-migration-complete\"\nif ! - [ -f \"$SENTINEL\" ]; then\n\tfind /storage -exec chown 10001:0 {} +\n\tfind + [ -f \"$SENTINEL\" ]; then\n\tfind /storage -exec chown 10000:0 {} +\n\tfind /storage -exec chmod a+r,u+w {} +\n\tfind /storage -type d -exec chmod a+x {} +\n\ttouch \"$SENTINEL\"\nfi" image: busybox:musl @@ -402,9 +402,9 @@ spec: name: nginx-php priorityClassName: lagoon-priority-production securityContext: - fsGroup: 10000 + fsGroup: 10001 runAsGroup: 0 - runAsUser: 10001 + runAsUser: 10000 volumes: - name: nginx-php persistentVolumeClaim: From 608868eaf067fb7ccf4e5a41e6f5a0368a49bf51 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 27 Jul 2023 10:02:24 +1000 Subject: [PATCH 31/92] chore: only create templates if there is anything to create --- cmd/template_lagoonservices.go | 16 ++++++++++++---- legacy/build-deploy-docker-compose.sh | 8 ++++---- .../test1-results/cronjobs.yaml | 0 .../test1-results/pvcs.yaml | 0 4 files changed, 16 insertions(+), 8 deletions(-) delete mode 100644 test-resources/template-lagoon-services/test1-results/cronjobs.yaml delete mode 100644 test-resources/template-lagoon-services/test1-results/pvcs.yaml diff --git a/cmd/template_lagoonservices.go b/cmd/template_lagoonservices.go index f7bd8f13..2f8b335e 100644 --- a/cmd/template_lagoonservices.go +++ b/cmd/template_lagoonservices.go @@ -52,7 +52,9 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "services"), serviceTemplateYAML) + if serviceTemplateYAML != nil { + helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "services"), serviceTemplateYAML) + } if g.Debug { fmt.Println(fmt.Sprintf("Templating pvc manifests %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "pvcs"))) } @@ -60,7 +62,9 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "pvcs"), pvcTemplateYAML) + if pvcTemplateYAML != nil { + helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "pvcs"), pvcTemplateYAML) + } if g.Debug { fmt.Println(fmt.Sprintf("Templating deployment manifest %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "deployments"))) } @@ -68,12 +72,16 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "deployments"), deploymentTemplateYAML) + if deploymentTemplateYAML != nil { + helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "deployments"), deploymentTemplateYAML) + } cronjobTemplateYaml, err := servicestemplates.GenerateCronjobTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "cronjobs"), cronjobTemplateYaml) + if cronjobTemplateYaml != nil { + helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "cronjobs"), cronjobTemplateYaml) + } return nil } diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index c3d0672d..ac09c514 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -1428,10 +1428,10 @@ if [ "$(ls -A $LAGOON_SERVICES_YAML_FOLDER/)" ]; then # cat $LAGOON_SERVICES_YAML_FOLDER/pvcs.yaml # cat $LAGOON_SERVICES_YAML_FOLDER/deployments.yaml # cat $LAGOON_SERVICES_YAML_FOLDER/cronjobs.yaml - kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/services.yaml - kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/pvcs.yaml - kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/deployments.yaml - kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/cronjobs.yaml + if [ "$(ls -A $LAGOON_SERVICES_YAML_FOLDER/)" ]; then + find $LAGOON_SERVICES_YAML_FOLDER -type f -exec cat {} \; + kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/ + fi fi set -x diff --git a/test-resources/template-lagoon-services/test1-results/cronjobs.yaml b/test-resources/template-lagoon-services/test1-results/cronjobs.yaml deleted file mode 100644 index e69de29b..00000000 diff --git a/test-resources/template-lagoon-services/test1-results/pvcs.yaml b/test-resources/template-lagoon-services/test1-results/pvcs.yaml deleted file mode 100644 index e69de29b..00000000 From 66acfa496295fb22d5c88a9d5f75480b63c23c83 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 31 Jul 2023 09:18:30 +1000 Subject: [PATCH 32/92] chore: support configmapsha --- cmd/template_lagoonservices_test.go | 35 ++++++++++++++++++++++++++++- internal/generator/generator.go | 3 +++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index e977d2db..e960908e 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -31,6 +31,7 @@ func TestTemplateLagoonServices(t *testing.T) { serviceID string secretPrefix string ingressClass string + configMapSha string rootlessWorkloads string projectVars string envVars string @@ -60,6 +61,7 @@ func TestTemplateLagoonServices(t *testing.T) { envVars: `[]`, lagoonYAML: "../test-resources/template-lagoon-services/test1/lagoon.yml", templatePath: "../test-resources/template-lagoon-services/output", + configMapSha: "abcdefg1234567890", imageReferences: map[string]string{ "node": "harbor.example/example-project/main/node:latest", }, @@ -81,6 +83,7 @@ func TestTemplateLagoonServices(t *testing.T) { envVars: `[]`, lagoonYAML: "../test-resources/template-lagoon-services/test2/lagoon.yml", templatePath: "../test-resources/template-lagoon-services/output", + configMapSha: "abcdefg1234567890", imageReferences: map[string]string{ "nginx": "harbor.example/example-project/main/nginx:latest", "php": "harbor.example/example-project/main/php:latest", @@ -107,6 +110,7 @@ func TestTemplateLagoonServices(t *testing.T) { rootlessWorkloads: "enabled", lagoonYAML: "../test-resources/template-lagoon-services/test2/lagoon.yml", templatePath: "../test-resources/template-lagoon-services/output", + configMapSha: "abcdefg1234567890", imageReferences: map[string]string{ "nginx": "harbor.example/example-project/main/nginx:latest", "php": "harbor.example/example-project/main/php:latest", @@ -117,6 +121,31 @@ func TestTemplateLagoonServices(t *testing.T) { }, want: "../test-resources/template-lagoon-services/test2-results-b", }, + { + name: "test3 - funky pvcs", + args: args{ + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, + envVars: `[]`, + rootlessWorkloads: "enabled", + lagoonYAML: "../test-resources/template-lagoon-services/test3/lagoon.yml", + templatePath: "../test-resources/template-lagoon-services/output", + configMapSha: "abcdefg1234567890", + imageReferences: map[string]string{ + "lnd": "harbor.example/example-project/main/lnd:latest", + "thunderhub": "harbor.example/example-project/main/thunderhub:latest", + "tor": "harbor.example/example-project/main/tor:latest", + }, + }, + want: "../test-resources/template-lagoon-services/test3-results", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -169,6 +198,10 @@ func TestTemplateLagoonServices(t *testing.T) { if err != nil { t.Errorf("%v", err) } + err = os.Setenv("CONFIG_MAP_SHA", tt.args.configMapSha) + if err != nil { + t.Errorf("%v", err) + } err = os.Setenv("LAGOON_FASTLY_NOCACHE_SERVICE_ID", tt.args.cacheNoCache) if err != nil { t.Errorf("%v", err) @@ -275,7 +308,7 @@ func TestTemplateLagoonServices(t *testing.T) { t.Errorf("resulting templates do not match") } t.Cleanup(func() { - helpers.UnsetEnvVars([]helpers.EnvironmentVariable{{Name: "LAGOON_FEATURE_FLAG_DEFAULT_INGRESS_CLASS"}, {Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD"}}) + helpers.UnsetEnvVars([]helpers.EnvironmentVariable{{Name: "LAGOON_FEATURE_FLAG_DEFAULT_INGRESS_CLASS"}, {Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD"}, {Name: "CONFIG_MAP_SHA"}}) }) }) } diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 6d0e03f4..0e690aa8 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -48,6 +48,7 @@ type GeneratorInput struct { FastlyCacheNoCahce string FastlyAPISecretPrefix string SavedTemplatesPath string + ConfigMapSha string IgnoreNonStringKeyErrors bool IgnoreMissingEnvFiles bool Debug bool @@ -88,7 +89,9 @@ func NewGenerator( fastlyCacheNoCahce := helpers.GetEnv("LAGOON_FASTLY_NOCACHE_SERVICE_ID", generator.FastlyCacheNoCahce, generator.Debug) fastlyAPISecretPrefix := helpers.GetEnv("ROUTE_FASTLY_SERVICE_ID", generator.FastlyAPISecretPrefix, generator.Debug) lagoonVersion := helpers.GetEnv("LAGOON_VERSION", generator.LagoonVersion, generator.Debug) + configMapSha := helpers.GetEnv("CONFIG_MAP_SHA", generator.ConfigMapSha, generator.Debug) + buildValues.ConfigMapSha = configMapSha // get the image references values from the build images output buildValues.ImageReferences = generator.ImageReferences // add standard lagoon imagepull secret name From fd56129e8ad301eeb52b089fa62472d8313550f5 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 31 Jul 2023 09:20:49 +1000 Subject: [PATCH 33/92] chore: use protocol in service names instead for shorter names --- internal/servicetypes/elasticsearch.go | 4 ++++ .../templating/ingress/templates_ingress.go | 9 +++----- .../result-custom-ingress7.yaml | 2 +- .../result-custom-ingress8.yaml | 2 +- .../services/templates_deployment.go | 15 ++++++++---- internal/templating/services/templates_pvc.go | 8 +++++++ .../templating/services/templates_service.go | 23 +++++++++++++++++-- .../deployment/result-basic-2.yaml | 4 ++-- .../deployment/result-basic-3.yaml | 4 ++-- .../deployment/result-elasticsearch-1.yaml | 4 ++-- .../service/result-basic-2.yaml | 12 +++++----- 11 files changed, 60 insertions(+), 27 deletions(-) diff --git a/internal/servicetypes/elasticsearch.go b/internal/servicetypes/elasticsearch.go index 07047d5e..5b1ae258 100644 --- a/internal/servicetypes/elasticsearch.go +++ b/internal/servicetypes/elasticsearch.go @@ -21,6 +21,10 @@ var elasticsearch = ServiceType{ }, }, }, + PrimaryContainer: ServiceContainer{ + Name: "elasticsearch", + ImagePullPolicy: corev1.PullAlways, + }, InitContainer: ServiceContainer{ Name: "set-max-map-count", Command: []string{ diff --git a/internal/templating/ingress/templates_ingress.go b/internal/templating/ingress/templates_ingress.go index 2519c862..41ea0ca0 100644 --- a/internal/templating/ingress/templates_ingress.go +++ b/internal/templating/ingress/templates_ingress.go @@ -9,6 +9,7 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" + "github.com/uselagoon/build-deploy-tool/internal/templating/services" networkv1 "k8s.io/api/networking/v1" apivalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -239,17 +240,13 @@ func GenerateIngressTemplate( for _, service := range lValues.Services { for idx, addPort := range service.AdditionalServicePorts { if addPort.ServiceName == route.LagoonService { - servicePort = networkv1.ServiceBackendPort{ - Name: addPort.ServiceName, - } + servicePort = services.GenerateServiceBackendPort(addPort) backendService = service.OverrideName } // if this service is for the default named lagoonservice if service.OverrideName == route.LagoonService && idx == 0 { // and set the portname to the name of the first service in the list - servicePort = networkv1.ServiceBackendPort{ - Name: addPort.ServiceName, - } + servicePort = services.GenerateServiceBackendPort(addPort) } } } diff --git a/internal/templating/ingress/test-resources/result-custom-ingress7.yaml b/internal/templating/ingress/test-resources/result-custom-ingress7.yaml index 74d9a370..d39ed65d 100644 --- a/internal/templating/ingress/test-resources/result-custom-ingress7.yaml +++ b/internal/templating/ingress/test-resources/result-custom-ingress7.yaml @@ -40,7 +40,7 @@ spec: service: name: myservice-po port: - name: myservice-po-8192 + name: tcp-8192 path: / pathType: Prefix tls: diff --git a/internal/templating/ingress/test-resources/result-custom-ingress8.yaml b/internal/templating/ingress/test-resources/result-custom-ingress8.yaml index 74d9a370..d39ed65d 100644 --- a/internal/templating/ingress/test-resources/result-custom-ingress8.yaml +++ b/internal/templating/ingress/test-resources/result-custom-ingress8.yaml @@ -40,7 +40,7 @@ spec: service: name: myservice-po port: - name: myservice-po-8192 + name: tcp-8192 path: / pathType: Prefix tls: diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index b81671d7..c3b26485 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -291,6 +291,11 @@ func GenerateDeploymentTemplate( container.Container.Ports = []corev1.ContainerPort{} // start compose service port override templating here for idx, addPort := range serviceValues.AdditionalServicePorts { + port := corev1.ContainerPort{ + Name: fmt.Sprintf("tcp-%d", addPort.ServicePort.Target), + ContainerPort: int32(addPort.ServicePort.Target), + Protocol: corev1.Protocol(strings.ToUpper(addPort.ServicePort.Protocol)), + } if idx == 0 { // first port in the docker compose file should be a tcp based port (default unless udp or other is provided in the docker-compose file) // the first port in the list will be used for any liveness/readiness probes, and will override the default option the container has @@ -324,12 +329,12 @@ func GenerateDeploymentTemplate( return nil, fmt.Errorf("first port defined is not a tcp port, please ensure the first port is tcp") } } + switch addPort.ServicePort.Protocol { + case "udp": + port.Name = fmt.Sprintf("udp-%d", addPort.ServicePort.Target) + } // set the ports into the container - container.Container.Ports = append(container.Container.Ports, corev1.ContainerPort{ - Name: addPort.ServiceName, - ContainerPort: int32(addPort.ServicePort.Target), - Protocol: corev1.Protocol(strings.ToUpper(addPort.ServicePort.Protocol)), - }) + container.Container.Ports = append(container.Container.Ports, port) } } else { // otherwise if the service has a default port, and it can be changed, handle changing it here diff --git a/internal/templating/services/templates_pvc.go b/internal/templating/services/templates_pvc.go index 1ad26997..104d66b1 100644 --- a/internal/templating/services/templates_pvc.go +++ b/internal/templating/services/templates_pvc.go @@ -56,6 +56,14 @@ func GeneratePVCTemplate( for _, serviceValues := range checkedServices { if val, ok := servicetypes.ServiceTypes[serviceValues.Type]; ok { if val.Volumes.PersistentVolumeSize != "" { + if serviceValues.PersistentVolumeName != "" { + if serviceValues.PersistentVolumeName != serviceValues.OverrideName { + // this service base volume is not needed because it is created by a different service + // lagoon legacy templates allowed due to a funny templating issue, for multiple "basic" types to mount one volume + // from one main service, across multiple services of the same type + continue + } + } serviceTypeValues := &servicetypes.ServiceType{} helpers.DeepCopy(val, serviceTypeValues) persistentVolumeSize := serviceTypeValues.Volumes.PersistentVolumeSize diff --git a/internal/templating/services/templates_service.go b/internal/templating/services/templates_service.go index d2941d56..b70f8c91 100644 --- a/internal/templating/services/templates_service.go +++ b/internal/templating/services/templates_service.go @@ -7,6 +7,7 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/servicetypes" corev1 "k8s.io/api/core/v1" + networkv1 "k8s.io/api/networking/v1" apivalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" @@ -132,9 +133,9 @@ func GenerateService(result []byte, serviceType *servicetypes.ServiceType, servi for _, addPort := range serviceValues.AdditionalServicePorts { port := corev1.ServicePort{ Protocol: corev1.ProtocolTCP, - Name: addPort.ServiceName, + Name: fmt.Sprintf("tcp-%d", addPort.ServicePort.Target), TargetPort: intstr.IntOrString{ - StrVal: addPort.ServiceName, + StrVal: fmt.Sprintf("tcp-%d", addPort.ServicePort.Target), Type: intstr.String, }, Port: int32(addPort.ServicePort.Target), @@ -142,6 +143,11 @@ func GenerateService(result []byte, serviceType *servicetypes.ServiceType, servi // set protocol to anything but tcp if required switch addPort.ServicePort.Protocol { case "udp": + port.Name = fmt.Sprintf("udp-%d", addPort.ServicePort.Target) + port.TargetPort = intstr.IntOrString{ + StrVal: fmt.Sprintf("udp-%d", addPort.ServicePort.Target), + Type: intstr.String, + } port.Protocol = corev1.ProtocolUDP } serviceType.Ports.Ports = append(serviceType.Ports.Ports, port) @@ -170,3 +176,16 @@ func GenerateService(result []byte, serviceType *servicetypes.ServiceType, servi restoreResult := append(separator[:], serviceBytes[:]...) return restoreResult, nil } + +func GenerateServiceBackendPort(addPort generator.AdditionalServicePort) networkv1.ServiceBackendPort { + switch addPort.ServicePort.Protocol { + case "udp": + return networkv1.ServiceBackendPort{ + Name: fmt.Sprintf("udp-%d", addPort.ServicePort.Target), + } + default: + return networkv1.ServiceBackendPort{ + Name: fmt.Sprintf("tcp-%d", addPort.ServicePort.Target), + } + } +} diff --git a/internal/templating/services/test-resources/deployment/result-basic-2.yaml b/internal/templating/services/test-resources/deployment/result-basic-2.yaml index ddb6bb2b..9ddd46f9 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-2.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-2.yaml @@ -71,10 +71,10 @@ spec: name: basic ports: - containerPort: 8191 - name: myservice-po-8191 + name: tcp-8191 protocol: TCP - containerPort: 8211 - name: myservice-po-8211 + name: tcp-8211 protocol: TCP readinessProbe: initialDelaySeconds: 1 diff --git a/internal/templating/services/test-resources/deployment/result-basic-3.yaml b/internal/templating/services/test-resources/deployment/result-basic-3.yaml index 628afdd8..3d2d7a35 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-3.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-3.yaml @@ -71,10 +71,10 @@ spec: name: basic ports: - containerPort: 8191 - name: myservice-po-8191 + name: tcp-8191 protocol: TCP - containerPort: 8211 - name: myservice-po-8211 + name: tcp-8211 protocol: TCP readinessProbe: initialDelaySeconds: 1 diff --git a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml index 340a57d3..bf9b369d 100644 --- a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml @@ -54,7 +54,7 @@ spec: envFrom: - configMapRef: name: lagoon-env - name: "" + name: elasticsearch resources: {} volumeMounts: - mountPath: /usr/share/elasticsearch/data @@ -140,7 +140,7 @@ spec: envFrom: - configMapRef: name: lagoon-env - name: "" + name: elasticsearch resources: {} volumeMounts: - mountPath: /usr/share/elasticsearch/data diff --git a/internal/templating/services/test-resources/service/result-basic-2.yaml b/internal/templating/services/test-resources/service/result-basic-2.yaml index 3d8c2011..20de7b42 100644 --- a/internal/templating/services/test-resources/service/result-basic-2.yaml +++ b/internal/templating/services/test-resources/service/result-basic-2.yaml @@ -20,10 +20,10 @@ metadata: name: myservice-po spec: ports: - - name: myservice-po-8191 + - name: tcp-8191 port: 8191 protocol: TCP - targetPort: myservice-po-8191 + targetPort: tcp-8191 selector: app.kubernetes.io/instance: myservice-po app.kubernetes.io/name: basic @@ -51,14 +51,14 @@ metadata: name: myservice-persist-po spec: ports: - - name: myservice-persist-po-8191 + - name: tcp-8191 port: 8191 protocol: TCP - targetPort: myservice-persist-po-8191 - - name: myservice-persist-po-8192 + targetPort: tcp-8191 + - name: tcp-8192 port: 8192 protocol: TCP - targetPort: myservice-persist-po-8192 + targetPort: tcp-8192 selector: app.kubernetes.io/instance: myservice-persist-po app.kubernetes.io/name: basic-persistent From 3e95f5319b1807f89805e09725e35de474031643 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 31 Jul 2023 09:21:17 +1000 Subject: [PATCH 34/92] chore: export configmapsha in builds for generator to consume --- legacy/build-deploy-docker-compose.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index ac09c514..d9971dda 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -1286,6 +1286,7 @@ done ############################################## CONFIG_MAP_SHA=$(kubectl -n ${NAMESPACE} get configmap lagoon-env -o yaml | shyaml get-value data | sha256sum | awk '{print $1}') +export CONFIG_MAP_SHA # write the configmap to the values file so when we `exec-kubectl-resources-with-images.sh` the deployments will get the value of the config map # which will cause a change in the deployment and trigger a rollout if only the configmap has changed yq3 write -i -- /kubectl-build-deploy/values.yaml 'configMapSha' $CONFIG_MAP_SHA From d373366d0ea3634ef8fca7b528591e545ff9311f Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 31 Jul 2023 09:21:33 +1000 Subject: [PATCH 35/92] test: update cases --- .../test1-results/deployments.yaml | 8 +- .../test1-results/services.yaml | 12 +- .../test2-results-a/cronjobs.yaml | 2 +- .../test2-results-a/deployments.yaml | 8 +- .../test2-results-b/cronjobs.yaml | 2 +- .../test2-results-b/deployments.yaml | 8 +- .../test3-results/deployments.yaml | 266 ++++++++++++++++++ .../test3-results/pvcs.yaml | 30 ++ .../test3-results/services.yaml | 101 +++++++ .../test3/docker-compose.yml | 92 ++++++ .../template-lagoon-services/test3/lagoon.yml | 1 + 11 files changed, 510 insertions(+), 20 deletions(-) create mode 100644 test-resources/template-lagoon-services/test3-results/deployments.yaml create mode 100644 test-resources/template-lagoon-services/test3-results/pvcs.yaml create mode 100644 test-resources/template-lagoon-services/test3-results/services.yaml create mode 100644 test-resources/template-lagoon-services/test3/docker-compose.yml create mode 100644 test-resources/template-lagoon-services/test3/lagoon.yml diff --git a/test-resources/template-lagoon-services/test1-results/deployments.yaml b/test-resources/template-lagoon-services/test1-results/deployments.yaml index 656fa2bf..1a0d8667 100644 --- a/test-resources/template-lagoon-services/test1-results/deployments.yaml +++ b/test-resources/template-lagoon-services/test1-results/deployments.yaml @@ -29,7 +29,7 @@ spec: metadata: annotations: lagoon.sh/branch: main - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: abcdefg1234567890 lagoon.sh/version: v2.7.x creationTimestamp: null labels: @@ -60,13 +60,13 @@ spec: name: basic ports: - containerPort: 1234 - name: node-1234 + name: tcp-1234 protocol: TCP - containerPort: 8191 - name: node-8191 + name: tcp-8191 protocol: TCP - containerPort: 9001 - name: node-9001 + name: udp-9001 protocol: UDP readinessProbe: initialDelaySeconds: 1 diff --git a/test-resources/template-lagoon-services/test1-results/services.yaml b/test-resources/template-lagoon-services/test1-results/services.yaml index 1330aa84..6b286993 100644 --- a/test-resources/template-lagoon-services/test1-results/services.yaml +++ b/test-resources/template-lagoon-services/test1-results/services.yaml @@ -20,18 +20,18 @@ metadata: name: node spec: ports: - - name: node-1234 + - name: tcp-1234 port: 1234 protocol: TCP - targetPort: node-1234 - - name: node-8191 + targetPort: tcp-1234 + - name: tcp-8191 port: 8191 protocol: TCP - targetPort: node-8191 - - name: node-9001 + targetPort: tcp-8191 + - name: udp-9001 port: 9001 protocol: UDP - targetPort: node-9001 + targetPort: udp-9001 selector: app.kubernetes.io/instance: node app.kubernetes.io/name: basic diff --git a/test-resources/template-lagoon-services/test2-results-a/cronjobs.yaml b/test-resources/template-lagoon-services/test2-results-a/cronjobs.yaml index da171713..4c5e273b 100644 --- a/test-resources/template-lagoon-services/test2-results-a/cronjobs.yaml +++ b/test-resources/template-lagoon-services/test2-results-a/cronjobs.yaml @@ -29,7 +29,7 @@ spec: metadata: annotations: lagoon.sh/branch: main - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: abcdefg1234567890 lagoon.sh/version: v2.7.x creationTimestamp: null labels: diff --git a/test-resources/template-lagoon-services/test2-results-a/deployments.yaml b/test-resources/template-lagoon-services/test2-results-a/deployments.yaml index cc6a8125..c42929fd 100644 --- a/test-resources/template-lagoon-services/test2-results-a/deployments.yaml +++ b/test-resources/template-lagoon-services/test2-results-a/deployments.yaml @@ -29,7 +29,7 @@ spec: metadata: annotations: lagoon.sh/branch: main - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: abcdefg1234567890 lagoon.sh/version: v2.7.x creationTimestamp: null labels: @@ -127,7 +127,7 @@ spec: metadata: annotations: lagoon.sh/branch: main - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: abcdefg1234567890 lagoon.sh/version: v2.7.x creationTimestamp: null labels: @@ -205,7 +205,7 @@ spec: metadata: annotations: lagoon.sh/branch: main - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: abcdefg1234567890 lagoon.sh/version: v2.7.x creationTimestamp: null labels: @@ -286,7 +286,7 @@ spec: metadata: annotations: lagoon.sh/branch: main - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: abcdefg1234567890 lagoon.sh/version: v2.7.x creationTimestamp: null labels: diff --git a/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml b/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml index 23b2576b..a1701991 100644 --- a/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml +++ b/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml @@ -29,7 +29,7 @@ spec: metadata: annotations: lagoon.sh/branch: main - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: abcdefg1234567890 lagoon.sh/version: v2.7.x creationTimestamp: null labels: diff --git a/test-resources/template-lagoon-services/test2-results-b/deployments.yaml b/test-resources/template-lagoon-services/test2-results-b/deployments.yaml index ad7ee77e..a4724f72 100644 --- a/test-resources/template-lagoon-services/test2-results-b/deployments.yaml +++ b/test-resources/template-lagoon-services/test2-results-b/deployments.yaml @@ -29,7 +29,7 @@ spec: metadata: annotations: lagoon.sh/branch: main - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: abcdefg1234567890 lagoon.sh/version: v2.7.x creationTimestamp: null labels: @@ -131,7 +131,7 @@ spec: metadata: annotations: lagoon.sh/branch: main - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: abcdefg1234567890 lagoon.sh/version: v2.7.x creationTimestamp: null labels: @@ -213,7 +213,7 @@ spec: metadata: annotations: lagoon.sh/branch: main - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: abcdefg1234567890 lagoon.sh/version: v2.7.x creationTimestamp: null labels: @@ -298,7 +298,7 @@ spec: metadata: annotations: lagoon.sh/branch: main - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: abcdefg1234567890 lagoon.sh/version: v2.7.x creationTimestamp: null labels: diff --git a/test-resources/template-lagoon-services/test3-results/deployments.yaml b/test-resources/template-lagoon-services/test3-results/deployments.yaml new file mode 100644 index 00000000..27d19ed3 --- /dev/null +++ b/test-resources/template-lagoon-services/test3-results/deployments.yaml @@ -0,0 +1,266 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: lnd + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: lnd + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: lnd +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: lnd + app.kubernetes.io/name: basic-persistent + 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: lnd + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: lnd + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/lnd:latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8080 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 8080 + name: tcp-8080 + protocol: TCP + - containerPort: 10009 + name: tcp-10009 + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8080 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /app/storage + name: lnd + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: lnd + persistentVolumeClaim: + claimName: lnd +status: {} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: thunderhub + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: thunderhub + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: thunderhub +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: thunderhub + app.kubernetes.io/name: basic-persistent + 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: thunderhub + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: thunderhub + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/thunderhub:latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 3000 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 3000 + name: tcp-3000 + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 3000 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /data + name: lnd + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: lnd + persistentVolumeClaim: + claimName: lnd +status: {} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: tor + 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: tor + lagoon.sh/service-type: basic + lagoon.sh/template: basic-0.1.0 + name: tor +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: tor + 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: tor + 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: tor + lagoon.sh/service-type: basic + lagoon.sh/template: basic-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/tor:latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 9050 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 9050 + name: tcp-9050 + protocol: TCP + - containerPort: 9051 + name: tcp-9051 + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 9050 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 +status: {} diff --git a/test-resources/template-lagoon-services/test3-results/pvcs.yaml b/test-resources/template-lagoon-services/test3-results/pvcs.yaml new file mode 100644 index 00000000..f8377573 --- /dev/null +++ b/test-resources/template-lagoon-services/test3-results/pvcs.yaml @@ -0,0 +1,30 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "true" + k8up.syn.tools/backup: "true" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: lnd + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: lnd + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: lnd +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 5Gi + storageClassName: bulk +status: {} diff --git a/test-resources/template-lagoon-services/test3-results/services.yaml b/test-resources/template-lagoon-services/test3-results/services.yaml new file mode 100644 index 00000000..21e8c8ad --- /dev/null +++ b/test-resources/template-lagoon-services/test3-results/services.yaml @@ -0,0 +1,101 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: lnd + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: lnd + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: lnd +spec: + ports: + - name: tcp-8080 + port: 8080 + protocol: TCP + targetPort: tcp-8080 + - name: tcp-10009 + port: 10009 + protocol: TCP + targetPort: tcp-10009 + selector: + app.kubernetes.io/instance: lnd + app.kubernetes.io/name: basic-persistent +status: + loadBalancer: {} +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: thunderhub + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: thunderhub + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: thunderhub +spec: + ports: + - name: tcp-3000 + port: 3000 + protocol: TCP + targetPort: tcp-3000 + selector: + app.kubernetes.io/instance: thunderhub + app.kubernetes.io/name: basic-persistent +status: + loadBalancer: {} +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: tor + 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: tor + lagoon.sh/service-type: basic + lagoon.sh/template: basic-0.1.0 + name: tor +spec: + ports: + - name: tcp-9050 + port: 9050 + protocol: TCP + targetPort: tcp-9050 + - name: tcp-9051 + port: 9051 + protocol: TCP + targetPort: tcp-9051 + selector: + app.kubernetes.io/instance: tor + app.kubernetes.io/name: basic +status: + loadBalancer: {} diff --git a/test-resources/template-lagoon-services/test3/docker-compose.yml b/test-resources/template-lagoon-services/test3/docker-compose.yml new file mode 100644 index 00000000..04115bee --- /dev/null +++ b/test-resources/template-lagoon-services/test3/docker-compose.yml @@ -0,0 +1,92 @@ +version: '2' +services: + lnd: + networks: + - amazeeio-network + - default + build: + context: . + dockerfile: Dockerfile + user: '10000' + labels: + lagoon.type: basic-persistent + lagoon.persistent: /app/storage + lagoon.service.usecomposeports: true + environment: + LAGOON_LOCALDEV_HTTP_PORT: 8080 + LAGOON_ROUTE: http://lnd.docker.amazee.io + volumes: + - ./storage:/app/storage:delegated + env_file: + - .env.local + ports: + - "8080" # exposes the port 8080 with a random local port, find it with `docker-compose port lnd 8080` + - "10009" # exposes the port 10009 with a random local port, find it with `docker-compose port lnd 10009` + + thunderhub: + networks: + - amazeeio-network + - default + build: + context: thunderhub + dockerfile: Dockerfile + user: '10000' + environment: + LOG_LEVEL: silly + LAGOON_LOCALDEV_HTTP_PORT: 3000 + LAGOON_ROUTE: http://thunderhub.docker.amazee.io + volumes: + - ./storage:/data:delegated + labels: + lagoon.type: basic-persistent + lagoon.persistent: /data + lagoon.persistent.name: lnd + lagoon.service.usecomposeports: true + ports: + - "3000" # exposes the port 3000 with a random local port, find it with `docker-compose port thunderhub 3000` + env_file: + - .env.local + + tor: + networks: + - amazeeio-network + - default + build: + context: tor + dockerfile: Dockerfile + user: '10000' + labels: + lagoon.type: basic + lagoon.service.usecomposeports: true + lagoon.autogeneratedroute: false + ports: + - "9050" + - "9051" + + # lit: + # networks: + # - amazeeio-network + # - default + # build: + # context: lit + # dockerfile: Dockerfile + # user: '10000' + # environment: + # LOG_LEVEL: silly + # LAGOON_LOCALDEV_HTTP_PORT: 8443 + # LAGOON_ROUTE: http://lit.docker.amazee.io + # volumes: + # - ./storage:/app/storage:delegated + # labels: + # lagoon.type: basic-persistent + # lagoon.persistent: /app/storage + # lagoon.persistent.name: lnd + # lagoon.autogeneratedroute: false + # lagoon.service.usecomposeports: true + # ports: + # - "8443" # exposes the port 3000 with a random local port, find it with `docker-compose port thunderhub 3000` + # env_file: + # - .env.local +networks: + amazeeio-network: + external: true diff --git a/test-resources/template-lagoon-services/test3/lagoon.yml b/test-resources/template-lagoon-services/test3/lagoon.yml new file mode 100644 index 00000000..31a423e0 --- /dev/null +++ b/test-resources/template-lagoon-services/test3/lagoon.yml @@ -0,0 +1 @@ +docker-compose-yaml: ../test-resources/template-lagoon-services/test3/docker-compose.yml From 504b20c6a40fc2b414b54f1095e2af63e5379e3b Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 10 Nov 2023 13:03:39 +1100 Subject: [PATCH 36/92] chore: minor fixes and backport imagecache injection --- cmd/template_lagoonservices_test.go | 10 +- internal/generator/buildvalues.go | 7 +- internal/generator/generator.go | 5 + internal/generator/services_test.go | 4 +- internal/servicetypes/README.md | 4 +- internal/servicetypes/basic.go | 2 + internal/servicetypes/cli.go | 2 + internal/servicetypes/elasticsearch.go | 2 +- internal/servicetypes/nginx.go | 2 +- internal/servicetypes/opensearch.go | 2 +- .../services/templates_cronjob_test.go | 26 +- .../services/templates_deployment.go | 14 + .../services/templates_deployment_test.go | 82 +++++- .../test-resources/cronjob/result-cli-1.yaml | 97 +++++++ .../deployment/result-elasticsearch-1.yaml | 4 +- .../deployment/result-nginx-1.yaml | 2 +- .../deployment/result-nginx-2.yaml | 265 ++++++++++++++++++ .../deployment/result-opensearch-1.yaml | 4 +- .../test2-results-b/deployments.yaml | 2 +- 19 files changed, 500 insertions(+), 36 deletions(-) create mode 100644 internal/templating/services/test-resources/deployment/result-nginx-2.yaml diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index e960908e..d1b16766 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -42,9 +42,10 @@ func TestTemplateLagoonServices(t *testing.T) { imageReferences map[string]string } tests := []struct { - name string - args args - want string + name string + description string + args args + want string }{ { name: "test1 basic deployment", @@ -122,7 +123,8 @@ func TestTemplateLagoonServices(t *testing.T) { want: "../test-resources/template-lagoon-services/test2-results-b", }, { - name: "test3 - funky pvcs", + name: "test3 - funky pvcs", + description: "only create pvcs of the requested persistent-name in the docker-compose file", args: args{ alertContact: "alertcontact", statusPageID: "statuspageid", diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index c801c435..0d0b4ee9 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -73,9 +73,10 @@ type ResourceRequests struct { } type PodSecurityContext struct { - FsGroup int64 `json:"fsGroup"` - RunAsGroup int64 `json:"runAsGroup"` - RunAsUser int64 `json:"runAsUser"` + FsGroup int64 `json:"fsGroup"` + RunAsGroup int64 `json:"runAsGroup"` + RunAsUser int64 `json:"runAsUser"` + OnRootMismatch bool `json:"onRootMismatch"` } type Fastly struct { diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 63eb3f8d..52e94521 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -211,6 +211,11 @@ func NewGenerator( } } + fsOnRootMismatch := CheckFeatureFlag("FS_ON_ROOT_MISMATCH", lagoonEnvVars, generator.Debug) + if fsOnRootMismatch == "enabled" { + buildValues.PodSecurityContext.OnRootMismatch = true + } + // check admin features for resources buildValues.Resources.Limits.Memory = CheckAdminFeatureFlag("CONTAINER_MEMORY_LIMIT", false) buildValues.Resources.Limits.EphemeralStorage = CheckAdminFeatureFlag("EPHEMERAL_STORAGE_LIMIT", false) diff --git a/internal/generator/services_test.go b/internal/generator/services_test.go index a4beb5c8..cc80dbd1 100644 --- a/internal/generator/services_test.go +++ b/internal/generator/services_test.go @@ -552,7 +552,7 @@ func Test_composeToServiceValues(t *testing.T) { "lagoon.service.usecomposeports": "true", }, Ports: []composetypes.ServicePortConfig{ - composetypes.ServicePortConfig{ + { Target: 8181, Protocol: "tcp", }, @@ -569,7 +569,7 @@ func Test_composeToServiceValues(t *testing.T) { InPodCronjobs: []lagoon.Cronjob{}, NativeCronjobs: []lagoon.Cronjob{}, AdditionalServicePorts: []AdditionalServicePort{ - AdditionalServicePort{ + { ServicePort: composetypes.ServicePortConfig{ Target: 8181, Protocol: "tcp", diff --git a/internal/servicetypes/README.md b/internal/servicetypes/README.md index dcd64068..7d25dee2 100644 --- a/internal/servicetypes/README.md +++ b/internal/servicetypes/README.md @@ -1,5 +1,5 @@ # Service Types -Defines defaults for Lagoon service types, hese replace the old helm based templates +Defines defaults for Lagoon service types, these replace the old helm based templates -This allows for the existing service types built with helm to be transferred over to a new templating system that allows easier customizability of resulting service types, and allows for the possibility of allowing more flexible service type creation beyond the standard template offerings (additional port/services, multiple volumes, etc.) \ No newline at end of file +This allows for the existing service types built with helm to be transferred over to a new templating system that allows easier customizability of resulting service types, and allows for the possibility of more flexible service type creation beyond the standard template offerings (additional port/services, multiple volumes, etc.) \ No newline at end of file diff --git a/internal/servicetypes/basic.go b/internal/servicetypes/basic.go index c17619a0..d9b49d35 100644 --- a/internal/servicetypes/basic.go +++ b/internal/servicetypes/basic.go @@ -6,6 +6,7 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" ) +// defines all the basic service type defaults var basic = ServiceType{ Name: "basic", Ports: ServicePorts{ @@ -67,6 +68,7 @@ var basic = ServiceType{ }, } +// contains all the persistent type overrides that the basic service doesn't have var basicPersistent = ServiceType{ Name: "basic-persistent", Ports: basic.Ports, diff --git a/internal/servicetypes/cli.go b/internal/servicetypes/cli.go index 8b675631..7812a8b3 100644 --- a/internal/servicetypes/cli.go +++ b/internal/servicetypes/cli.go @@ -6,6 +6,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" ) +// defines all the cli service type defaults var cli = ServiceType{ Name: "cli", PrimaryContainer: ServiceContainer{ @@ -61,6 +62,7 @@ var cli = ServiceType{ }, } +// contains all the persistent type overrides that the cli service doesn't have var cliPersistent = ServiceType{ Name: "cli-persistent", PrimaryContainer: ServiceContainer{ diff --git a/internal/servicetypes/elasticsearch.go b/internal/servicetypes/elasticsearch.go index 5b1ae258..d9dc9bf8 100644 --- a/internal/servicetypes/elasticsearch.go +++ b/internal/servicetypes/elasticsearch.go @@ -39,7 +39,7 @@ fi`, }, Container: corev1.Container{ Name: "set-max-map-count", - Image: "busybox:latest", + Image: "library/busybox:latest", ImagePullPolicy: corev1.PullIfNotPresent, SecurityContext: &corev1.SecurityContext{ Privileged: helpers.BoolPtr(true), diff --git a/internal/servicetypes/nginx.go b/internal/servicetypes/nginx.go index 10296991..85cc2a96 100644 --- a/internal/servicetypes/nginx.go +++ b/internal/servicetypes/nginx.go @@ -203,7 +203,7 @@ fi`, }, Container: corev1.Container{ Name: "fix-storage-permissions", - Image: "busybox:musl", + Image: "library/busybox:musl", ImagePullPolicy: corev1.PullIfNotPresent, SecurityContext: &corev1.SecurityContext{ RunAsUser: helpers.Int64Ptr(0), diff --git a/internal/servicetypes/opensearch.go b/internal/servicetypes/opensearch.go index 9dd5578e..4926f6bb 100644 --- a/internal/servicetypes/opensearch.go +++ b/internal/servicetypes/opensearch.go @@ -39,7 +39,7 @@ fi`, }, Container: corev1.Container{ Name: "set-max-map-count", - Image: "busybox:latest", + Image: "library/busybox:latest", ImagePullPolicy: corev1.PullIfNotPresent, SecurityContext: &corev1.SecurityContext{ Privileged: helpers.BoolPtr(true), diff --git a/internal/templating/services/templates_cronjob_test.go b/internal/templating/services/templates_cronjob_test.go index 92cd4994..af0e2b7f 100644 --- a/internal/templating/services/templates_cronjob_test.go +++ b/internal/templating/services/templates_cronjob_test.go @@ -61,15 +61,23 @@ func TestGenerateCronjobTemplate(t *testing.T) { }, }, }, - // { - // Name: "myservice-persist", - // OverrideName: "myservice-persist", - // Type: "cli-persistent", - // DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/myservice-persistent@latest", - // PersistentVolumePath: "/storage/data", - // PersistentVolumeName: "nginx-php", - // }, + { + Name: "myservice-persist", + OverrideName: "myservice-persist", + Type: "cli-persistent", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/myservice-persistent@latest", + PersistentVolumePath: "/storage/data", + PersistentVolumeName: "nginx-php", + NativeCronjobs: []lagoon.Cronjob{ + { + Name: "cronjob-myservice-my-cronjobbb", + Service: "myservice", + Command: "sleep 300", + Schedule: "5 2 * * *", + }, + }, + }, }, }, }, diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index c3b26485..d9f9380d 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -194,6 +194,16 @@ func GenerateDeploymentTemplate( FSGroup: helpers.Int64Ptr(buildValues.PodSecurityContext.FsGroup), } } + if buildValues.PodSecurityContext.OnRootMismatch { + fsGroupChangePolicy := corev1.FSGroupChangeOnRootMismatch + if deployment.Spec.Template.Spec.SecurityContext != nil { + deployment.Spec.Template.Spec.SecurityContext.FSGroupChangePolicy = &fsGroupChangePolicy + } else { + deployment.Spec.Template.Spec.SecurityContext = &corev1.PodSecurityContext{ + FSGroupChangePolicy: &fsGroupChangePolicy, + } + } + } // start set up any volumes this deployment can use // first handle any dynamic secret volumes that come from kubernetes secrets that are labeled @@ -279,6 +289,10 @@ func GenerateDeploymentTemplate( cmd = append(cmd, c2) } init.Container.Command = cmd + // init containers contain will more than likely contain public images, we should add a provided pull through imagecache if one is defined + if buildValues.ImageCache != "" { + init.Container.Image = fmt.Sprintf("%s%s", buildValues.ImageCache, init.Container.Image) + } deployment.Spec.Template.Spec.InitContainers = append(deployment.Spec.Template.Spec.InitContainers, init.Container) } } diff --git a/internal/templating/services/templates_deployment_test.go b/internal/templating/services/templates_deployment_test.go index 15655e89..48fa58ab 100644 --- a/internal/templating/services/templates_deployment_test.go +++ b/internal/templating/services/templates_deployment_test.go @@ -180,7 +180,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { want: "test-resources/deployment/result-nginx-1.yaml", }, { - name: "test2 - cli", + name: "test3 - cli", args: args{ buildValues: generator.BuildValues{ Project: "example-project", @@ -221,7 +221,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { want: "test-resources/deployment/result-cli-1.yaml", }, { - name: "test5 - postgres-single", + name: "test4 - postgres-single", args: args{ buildValues: generator.BuildValues{ Project: "example-project", @@ -250,7 +250,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { want: "test-resources/deployment/result-postgres-single-1.yaml", }, { - name: "test3 - elasticsearch", + name: "test5 - elasticsearch", args: args{ buildValues: generator.BuildValues{ Project: "example-project", @@ -282,7 +282,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { want: "test-resources/deployment/result-elasticsearch-1.yaml", }, { - name: "test4 - opensearch", + name: "test6 - opensearch", args: args{ buildValues: generator.BuildValues{ Project: "example-project", @@ -314,7 +314,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { want: "test-resources/deployment/result-opensearch-1.yaml", }, { - name: "test5 - basic compose ports", + name: "test7 - basic compose ports", args: args{ buildValues: generator.BuildValues{ Project: "example-project", @@ -364,7 +364,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { want: "test-resources/deployment/result-basic-2.yaml", }, { - name: "test5 - solr", + name: "test8 - solr", args: args{ buildValues: generator.BuildValues{ Project: "example-project", @@ -393,7 +393,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { want: "test-resources/deployment/result-solr-1.yaml", }, { - name: "test7 - basic resources", + name: "test9 - basic resources", args: args{ buildValues: generator.BuildValues{ Project: "example-project", @@ -451,6 +451,74 @@ func TestGenerateDeploymentTemplate(t *testing.T) { }, want: "test-resources/deployment/result-basic-3.yaml", }, + { + name: "test10 - nginx-php with imagecache override", + 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", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + ImageCache: "imagecache.example.com/", + Flags: map[string]bool{ + "rootlessworkloads": true, + }, + PodSecurityContext: generator.PodSecurityContext{ + RunAsGroup: 0, + RunAsUser: 10000, + FsGroup: 10001, + OnRootMismatch: true, + }, + GitSha: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + Services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + }, + { + Name: "php", + OverrideName: "nginx", + Type: "nginx-php", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/php@latest", + }, + { + Name: "nginx2", + OverrideName: "nginx-2", + Type: "nginx-php-persistent", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/nginx2@latest", + PersistentVolumePath: "/storage/data", + PersistentVolumeName: "nginx2", + }, + { + Name: "php2", + OverrideName: "nginx-2", + Type: "nginx-php-persistent", + DBaaSEnvironment: "production", + ImageName: "harbor.example.com/example-project/environment-name/php2@latest", + PersistentVolumeSize: "10Gi", + PersistentVolumePath: "/storage/data", + PersistentVolumeName: "nginx2", + }, + }, + }, + }, + want: "test-resources/deployment/result-nginx-2.yaml", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/templating/services/test-resources/cronjob/result-cli-1.yaml b/internal/templating/services/test-resources/cronjob/result-cli-1.yaml index f645ec33..79a6b539 100644 --- a/internal/templating/services/test-resources/cronjob/result-cli-1.yaml +++ b/internal/templating/services/test-resources/cronjob/result-cli-1.yaml @@ -174,3 +174,100 @@ spec: startingDeadlineSeconds: 240 successfulJobsHistoryLimit: 0 status: {} +--- +apiVersion: batch/v1beta1 +kind: CronJob +metadata: + annotations: + lagoon.sh/branch: environment-name + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: myservice-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + name: cronjob-myservice-my-cronjobbb +spec: + concurrencyPolicy: Forbid + failedJobsHistoryLimit: 1 + jobTemplate: + metadata: + creationTimestamp: null + spec: + 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-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + spec: + containers: + - command: + - /lagoon/cronjob.sh + - sleep 300 + env: + - name: LAGOON_GIT_SHA + value: "0" + - name: SERVICE_NAME + value: myservice-persist + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice-persistent@latest + name: cronjob-myservice-my-cronjobbb + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + - mountPath: /storage/data/php + name: nginx-php-twig + - mountPath: /storage/data + name: nginx-php + dnsConfig: + options: + - name: timeout + value: "60" + - name: attempts + value: "10" + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + restartPolicy: Never + volumes: + - name: lagoon-sshkey + secret: + defaultMode: 420 + secretName: lagoon-sshkey + - emptyDir: {} + name: nginx-php-twig + - name: nginx-php + persistentVolumeClaim: + claimName: nginx-php + schedule: 5 2 * * * + startingDeadlineSeconds: 240 + successfulJobsHistoryLimit: 0 +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml index bf9b369d..d9240d02 100644 --- a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml @@ -71,7 +71,7 @@ spec: if [ "$DESIRED" -gt "$CURRENT" ]; then sysctl -w vm.max_map_count=$DESIRED fi - image: busybox:latest + image: library/busybox:latest imagePullPolicy: IfNotPresent name: set-max-map-count resources: {} @@ -157,7 +157,7 @@ spec: if [ "$DESIRED" -gt "$CURRENT" ]; then sysctl -w vm.max_map_count=$DESIRED fi - image: busybox:latest + image: library/busybox:latest imagePullPolicy: IfNotPresent name: set-max-map-count resources: {} diff --git a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml index 569af5a7..f366e2a3 100644 --- a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml @@ -240,7 +240,7 @@ spec: [ -f \"$SENTINEL\" ]; then\n\tfind /storage -exec chown 0:0 {} +\n\tfind /storage -exec chmod a+r,u+w {} +\n\tfind /storage -type d -exec chmod a+x {} +\n\ttouch \"$SENTINEL\"\nfi" - image: busybox:musl + image: library/busybox:musl imagePullPolicy: IfNotPresent name: fix-storage-permissions resources: {} diff --git a/internal/templating/services/test-resources/deployment/result-nginx-2.yaml b/internal/templating/services/test-resources/deployment/result-nginx-2.yaml new file mode 100644 index 00000000..8fd783ad --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-nginx-2.yaml @@ -0,0 +1,265 @@ +--- +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: nginx + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx + lagoon.sh/service-type: nginx-php + lagoon.sh/template: nginx-php-0.1.0 + name: nginx +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: nginx + app.kubernetes.io/name: nginx-php + strategy: {} + 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: nginx + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx + lagoon.sh/service-type: nginx-php + lagoon.sh/template: nginx-php-0.1.0 + spec: + containers: + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/nginx@latest + livenessProbe: + failureThreshold: 5 + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 900 + timeoutSeconds: 3 + name: nginx + ports: + - containerPort: 8080 + name: http + protocol: TCP + readinessProbe: + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 1 + timeoutSeconds: 3 + resources: + requests: + cpu: 10m + memory: 10M + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + value: "0" + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/php@latest + livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + tcpSocket: + port: 9000 + name: php + ports: + - containerPort: 9000 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 2 + periodSeconds: 10 + tcpSocket: + port: 9000 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 +status: {} +--- +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: nginx-2 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-2 + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + name: nginx-2 +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: nginx-2 + app.kubernetes.io/name: nginx-php-persistent + strategy: {} + 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: nginx-2 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-2 + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + spec: + containers: + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/nginx2@latest + livenessProbe: + failureThreshold: 5 + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 900 + timeoutSeconds: 3 + name: nginx + ports: + - containerPort: 8080 + name: http + protocol: TCP + readinessProbe: + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 1 + timeoutSeconds: 3 + resources: + requests: + cpu: 10m + memory: 10M + volumeMounts: + - mountPath: /storage/data + name: nginx2 + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + value: "0" + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/php2@latest + livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + tcpSocket: + port: 9000 + name: php + ports: + - containerPort: 9000 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 2 + periodSeconds: 10 + tcpSocket: + port: 9000 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /storage/data + name: nginx2 + - mountPath: /storage/data/php + name: nginx2-twig + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + initContainers: + - command: + - sh + - -c + - "set -e\nSENTINEL=\"/storage/.lagoon-rootless-migration-complete\"\nif ! + [ -f \"$SENTINEL\" ]; then\n\tfind /storage -exec chown 0:0 {} +\n\tfind + /storage -exec chmod a+r,u+w {} +\n\tfind /storage -type d -exec chmod a+x + {} +\n\ttouch \"$SENTINEL\"\nfi" + image: imagecache.example.com/library/busybox:musl + imagePullPolicy: IfNotPresent + name: fix-storage-permissions + resources: {} + securityContext: + runAsUser: 0 + volumeMounts: + - mountPath: /storage + name: nginx2 + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: nginx2 + persistentVolumeClaim: + claimName: nginx2 + - emptyDir: {} + name: nginx2-twig +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml index 3d254632..b0cebda0 100644 --- a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml @@ -71,7 +71,7 @@ spec: if [ "$DESIRED" -gt "$CURRENT" ]; then sysctl -w vm.max_map_count=$DESIRED fi - image: busybox:latest + image: library/busybox:latest imagePullPolicy: IfNotPresent name: set-max-map-count resources: {} @@ -157,7 +157,7 @@ spec: if [ "$DESIRED" -gt "$CURRENT" ]; then sysctl -w vm.max_map_count=$DESIRED fi - image: busybox:latest + image: library/busybox:latest imagePullPolicy: IfNotPresent name: set-max-map-count resources: {} diff --git a/test-resources/template-lagoon-services/test2-results-b/deployments.yaml b/test-resources/template-lagoon-services/test2-results-b/deployments.yaml index a4724f72..93692a13 100644 --- a/test-resources/template-lagoon-services/test2-results-b/deployments.yaml +++ b/test-resources/template-lagoon-services/test2-results-b/deployments.yaml @@ -391,7 +391,7 @@ spec: [ -f \"$SENTINEL\" ]; then\n\tfind /storage -exec chown 10000:0 {} +\n\tfind /storage -exec chmod a+r,u+w {} +\n\tfind /storage -type d -exec chmod a+x {} +\n\ttouch \"$SENTINEL\"\nfi" - image: busybox:musl + image: library/busybox:musl imagePullPolicy: IfNotPresent name: fix-storage-permissions resources: {} From b14e5a0ad70677801e90ea54b5b27d5e1c15e9ce Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 13 Nov 2023 19:18:01 +1100 Subject: [PATCH 37/92] chore: add worker servicetype config --- cmd/template_lagoonservices_test.go | 25 +++ internal/servicetypes/worker.go | 39 +++- .../test4-results/deployments.yaml | 184 ++++++++++++++++++ .../test4-results/pvcs.yaml | 30 +++ .../test4-results/services.yaml | 35 ++++ .../test4/docker-compose.yml | 41 ++++ .../template-lagoon-services/test4/lagoon.yml | 1 + 7 files changed, 353 insertions(+), 2 deletions(-) create mode 100644 test-resources/template-lagoon-services/test4-results/deployments.yaml create mode 100644 test-resources/template-lagoon-services/test4-results/pvcs.yaml create mode 100644 test-resources/template-lagoon-services/test4-results/services.yaml create mode 100644 test-resources/template-lagoon-services/test4/docker-compose.yml create mode 100644 test-resources/template-lagoon-services/test4/lagoon.yml diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index d1b16766..bfe09856 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -148,6 +148,31 @@ func TestTemplateLagoonServices(t *testing.T) { }, want: "../test-resources/template-lagoon-services/test3-results", }, + { + name: "test4 - basic-persistent with worker-persistent", + description: "create a basic-persistent that gets a pvc and mount that volume on a worker-persistent type", + args: args{ + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, + envVars: `[]`, + rootlessWorkloads: "enabled", + lagoonYAML: "../test-resources/template-lagoon-services/test4/lagoon.yml", + templatePath: "../test-resources/template-lagoon-services/output", + configMapSha: "abcdefg1234567890", + imageReferences: map[string]string{ + "lnd": "harbor.example/example-project/main/lnd:latest", + "tor": "harbor.example/example-project/main/tor:latest", + }, + }, + want: "../test-resources/template-lagoon-services/test4-results", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/servicetypes/worker.go b/internal/servicetypes/worker.go index 142a5b94..93ce7976 100644 --- a/internal/servicetypes/worker.go +++ b/internal/servicetypes/worker.go @@ -1,10 +1,45 @@ package servicetypes +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" +) + var worker = ServiceType{ Name: "worker", + PrimaryContainer: ServiceContainer{ + Name: "worker", + ImagePullPolicy: corev1.PullAlways, + Container: corev1.Container{ + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + Exec: &corev1.ExecAction{ + Command: []string{ + "/bin/sh", + "-c", + "if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; fi", + }, + }, + }, + InitialDelaySeconds: 5, + PeriodSeconds: 2, + FailureThreshold: 3, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("100M"), + }, + }, + }, + }, } var workerPersistent = ServiceType{ - Name: "worker-persistent", - Volumes: ServiceVolume{}, + Name: "worker-persistent", + PrimaryContainer: ServiceContainer{ + Name: cli.PrimaryContainer.Name, + ImagePullPolicy: cli.PrimaryContainer.ImagePullPolicy, + Container: cli.PrimaryContainer.Container, + }, } diff --git a/test-resources/template-lagoon-services/test4-results/deployments.yaml b/test-resources/template-lagoon-services/test4-results/deployments.yaml new file mode 100644 index 00000000..935432ca --- /dev/null +++ b/test-resources/template-lagoon-services/test4-results/deployments.yaml @@ -0,0 +1,184 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: lnd + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: lnd + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: lnd +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: lnd + app.kubernetes.io/name: basic-persistent + 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: lnd + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: lnd + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/lnd:latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8080 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 8080 + name: tcp-8080 + protocol: TCP + - containerPort: 10009 + name: tcp-10009 + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8080 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /app/storage + name: lnd + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: lnd + persistentVolumeClaim: + claimName: lnd +status: {} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: tor + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: worker-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: tor + lagoon.sh/service-type: worker-persistent + lagoon.sh/template: worker-persistent-0.1.0 + name: tor +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: tor + app.kubernetes.io/name: worker-persistent + 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: tor + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: worker-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: tor + lagoon.sh/service-type: worker-persistent + lagoon.sh/template: worker-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/tor:latest + name: cli + ports: + - containerPort: 3000 + name: http + protocol: TCP + readinessProbe: + exec: + command: + - /bin/sh + - -c + - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; + fi + failureThreshold: 3 + initialDelaySeconds: 5 + periodSeconds: 2 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + - mountPath: /data + name: lnd + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: lnd + persistentVolumeClaim: + claimName: lnd +status: {} diff --git a/test-resources/template-lagoon-services/test4-results/pvcs.yaml b/test-resources/template-lagoon-services/test4-results/pvcs.yaml new file mode 100644 index 00000000..f8377573 --- /dev/null +++ b/test-resources/template-lagoon-services/test4-results/pvcs.yaml @@ -0,0 +1,30 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "true" + k8up.syn.tools/backup: "true" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: lnd + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: lnd + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: lnd +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 5Gi + storageClassName: bulk +status: {} diff --git a/test-resources/template-lagoon-services/test4-results/services.yaml b/test-resources/template-lagoon-services/test4-results/services.yaml new file mode 100644 index 00000000..c193ba18 --- /dev/null +++ b/test-resources/template-lagoon-services/test4-results/services.yaml @@ -0,0 +1,35 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: lnd + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: lnd + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: lnd +spec: + ports: + - name: tcp-8080 + port: 8080 + protocol: TCP + targetPort: tcp-8080 + - name: tcp-10009 + port: 10009 + protocol: TCP + targetPort: tcp-10009 + selector: + app.kubernetes.io/instance: lnd + app.kubernetes.io/name: basic-persistent +status: + loadBalancer: {} diff --git a/test-resources/template-lagoon-services/test4/docker-compose.yml b/test-resources/template-lagoon-services/test4/docker-compose.yml new file mode 100644 index 00000000..d8e39aaa --- /dev/null +++ b/test-resources/template-lagoon-services/test4/docker-compose.yml @@ -0,0 +1,41 @@ +version: '2' +services: + lnd: + networks: + - amazeeio-network + - default + build: + context: . + dockerfile: Dockerfile + user: '10000' + labels: + lagoon.type: basic-persistent + lagoon.persistent: /app/storage + lagoon.service.usecomposeports: true + environment: + LAGOON_LOCALDEV_HTTP_PORT: 8080 + LAGOON_ROUTE: http://lnd.docker.amazee.io + volumes: + - ./storage:/app/storage:delegated + env_file: + - .env.local + ports: + - "8080" # exposes the port 8080 with a random local port, find it with `docker-compose port lnd 8080` + - "10009" # exposes the port 10009 with a random local port, find it with `docker-compose port lnd 10009` + + tor: + networks: + - amazeeio-network + - default + build: + context: tor + dockerfile: Dockerfile + user: '10000' + labels: + lagoon.type: worker-persistent + lagoon.persistent: /data + lagoon.persistent.name: lnd + +networks: + amazeeio-network: + external: true diff --git a/test-resources/template-lagoon-services/test4/lagoon.yml b/test-resources/template-lagoon-services/test4/lagoon.yml new file mode 100644 index 00000000..2b4f3290 --- /dev/null +++ b/test-resources/template-lagoon-services/test4/lagoon.yml @@ -0,0 +1 @@ +docker-compose-yaml: ../test-resources/template-lagoon-services/test4/docker-compose.yml From 00644cb23d168d9691fd355196a90dc72b270e5d Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 29 Nov 2023 10:18:15 +1100 Subject: [PATCH 38/92] feat: check duplicate cronjobs and return error if found --- internal/generator/services.go | 38 +++++++++ internal/generator/services_test.go | 124 +++++++++++++++++++++++++++- 2 files changed, 160 insertions(+), 2 deletions(-) diff --git a/internal/generator/services.go b/internal/generator/services.go index 96530454..b57fcf36 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -1,6 +1,7 @@ package generator import ( + "encoding/json" "fmt" "reflect" "regexp" @@ -197,6 +198,10 @@ func composeToServiceValues( // work out cronjobs for this service inpodcronjobs := []lagoon.Cronjob{} nativecronjobs := []lagoon.Cronjob{} + // check if there are any duplicate named cronjobs + if err := checkDuplicateCronjobs(lYAML.Environments[buildValues.Branch].Cronjobs); err != nil { + return ServiceValues{}, err + } if !buildValues.CronjobsDisabled { for _, cronjob := range lYAML.Environments[buildValues.Branch].Cronjobs { // if this cronjob is meant for this service, add it @@ -437,3 +442,36 @@ func getDBaasEnvironment( } return exists, nil } + +func checkDuplicateCronjobs(cronjobs []lagoon.Cronjob) error { + var unique []lagoon.Cronjob + var duplicates []lagoon.Cronjob + for _, v := range cronjobs { + skip := false + for _, u := range unique { + if v.Name == u.Name { + skip = true + duplicates = append(duplicates, v) + break + } + } + if !skip { + unique = append(unique, v) + } + } + var uniqueDuplicates []lagoon.Cronjob + for _, d := range duplicates { + for _, u := range unique { + if d.Name == u.Name { + uniqueDuplicates = append(uniqueDuplicates, u) + } + } + } + // join the two together + result := append(duplicates, uniqueDuplicates...) + if result != nil { + b, _ := json.Marshal(result) + return fmt.Errorf("duplicate named cronjobs detected: %v", string(b)) + } + return nil +} diff --git a/internal/generator/services_test.go b/internal/generator/services_test.go index cc80dbd1..c787a137 100644 --- a/internal/generator/services_test.go +++ b/internal/generator/services_test.go @@ -639,7 +639,7 @@ func Test_composeToServiceValues(t *testing.T) { }, }, { - name: "test16 - cronjobs disabled", + name: "test17 - cronjobs disabled", args: args{ lYAML: &lagoon.YAML{ Environments: lagoon.Environments{ @@ -686,7 +686,7 @@ func Test_composeToServiceValues(t *testing.T) { }, }, { - name: "test14 - invalid service port", + name: "test18 - invalid service port", args: args{ lYAML: &lagoon.YAML{ Environments: lagoon.Environments{ @@ -710,6 +710,50 @@ func Test_composeToServiceValues(t *testing.T) { want: ServiceValues{}, wantErr: true, }, + { + name: "test19 - duplicate cronjobs", + args: args{ + lYAML: &lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Cronjobs: []lagoon.Cronjob{ + { + Name: "My Cronjob", + Command: "env", + Service: "cli", + Schedule: "5 2 * * *", + }, + { + Name: "My Cronjob2", + Command: "drush cron", + Service: "cli", + Schedule: "*/5 * * * *", + }, + { + Name: "My Cronjob", + Command: "env", + Service: "cli", + Schedule: "15 5 4 * 0", + }, + }, + }, + }, + }, + buildValues: &BuildValues{ + Environment: "main", + Branch: "main", + BuildType: "branch", + ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + }, + composeService: "cli", + composeServiceValues: composetypes.ServiceConfig{ + Labels: composetypes.Labels{ + "lagoon.type": "cli", + }, + }, + }, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -734,3 +778,79 @@ func Test_composeToServiceValues(t *testing.T) { }) } } + +func Test_checkDuplicateCronjobs(t *testing.T) { + type args struct { + cronjobs []lagoon.Cronjob + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "test1 - no duplicate cronjob names", + args: args{ + cronjobs: []lagoon.Cronjob{ + { + Name: "drush uli", + Command: "drush uli", + Service: "cli", + Schedule: "5 * * * *", + }, + { + Name: "drush cron", + Command: "drush cron", + Service: "cli", + Schedule: "5 * * * *", + }, + { + Name: "drush cr", + Command: "drush cr", + Service: "cli", + Schedule: "5 * * * *", + }, + }, + }, + }, + { + name: "test2 - duplicate cronjob names", + args: args{ + cronjobs: []lagoon.Cronjob{ + { + Name: "drush uli", + Command: "drush uli", + Service: "cli", + Schedule: "5 * * * *", + }, + { + Name: "drush cr", + Command: "drush cr", + Service: "cli", + Schedule: "5,25,2 4 * * *", + }, + { + Name: "drush cron", + Command: "drush cron", + Service: "cli", + Schedule: "5 * * * *", + }, + { + Name: "drush cr", + Command: "drush cr", + Service: "cli", + Schedule: "5 * * * *", + }, + }, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := checkDuplicateCronjobs(tt.args.cronjobs); (err != nil) != tt.wantErr { + t.Errorf("checkDuplicateCronjobs() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} From a7652bc82af2b0b32e83b48d20262d3e2d072367 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 9 Jan 2024 10:00:07 +1100 Subject: [PATCH 39/92] test: fix tests after merge --- cmd/identify_native_cronjobs.go | 2 +- cmd/identify_native_cronjobs_test.go | 210 +++------ cmd/template_dbaas_test.go | 2 +- cmd/template_ingress_test.go | 2 +- cmd/template_lagoonservices.go | 2 +- cmd/template_lagoonservices_test.go | 329 ++++++-------- test-resources/lagoon-yaml/test5/lagoon.yml | 15 - test-resources/lagoon-yaml/test6/lagoon.yml | 28 -- .../test1-results/deployments.yaml | 84 ---- .../test1-results/services.yaml | 39 -- .../test1/docker-compose.yml | 22 - .../template-lagoon-services/test1/lagoon.yml | 10 - .../test2-results-a/cronjobs.yaml | 96 ---- .../test2-results-a/deployments.yaml | 381 ---------------- .../test2-results-a/pvcs.yaml | 30 -- .../test2-results-a/services.yaml | 97 ---- .../test2-results-b/cronjobs.yaml | 100 ----- .../test2-results-b/deployments.yaml | 414 ------------------ .../test2-results-b/pvcs.yaml | 30 -- .../test2-results-b/services.yaml | 97 ---- .../test2/docker-compose.yml | 160 ------- .../template-lagoon-services/test2/lagoon.yml | 19 - .../test3-results/deployments.yaml | 266 ----------- .../test3-results/pvcs.yaml | 30 -- .../test3-results/services.yaml | 101 ----- .../test3/docker-compose.yml | 92 ---- .../template-lagoon-services/test3/lagoon.yml | 1 - .../test4-results/deployments.yaml | 184 -------- .../test4-results/pvcs.yaml | 30 -- .../test4-results/services.yaml | 35 -- .../test4/docker-compose.yml | 41 -- .../template-lagoon-services/test4/lagoon.yml | 1 - 32 files changed, 188 insertions(+), 2762 deletions(-) delete mode 100644 test-resources/lagoon-yaml/test5/lagoon.yml delete mode 100644 test-resources/lagoon-yaml/test6/lagoon.yml delete mode 100644 test-resources/template-lagoon-services/test1-results/deployments.yaml delete mode 100644 test-resources/template-lagoon-services/test1-results/services.yaml delete mode 100644 test-resources/template-lagoon-services/test1/docker-compose.yml delete mode 100644 test-resources/template-lagoon-services/test1/lagoon.yml delete mode 100644 test-resources/template-lagoon-services/test2-results-a/cronjobs.yaml delete mode 100644 test-resources/template-lagoon-services/test2-results-a/deployments.yaml delete mode 100644 test-resources/template-lagoon-services/test2-results-a/pvcs.yaml delete mode 100644 test-resources/template-lagoon-services/test2-results-a/services.yaml delete mode 100644 test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml delete mode 100644 test-resources/template-lagoon-services/test2-results-b/deployments.yaml delete mode 100644 test-resources/template-lagoon-services/test2-results-b/pvcs.yaml delete mode 100644 test-resources/template-lagoon-services/test2-results-b/services.yaml delete mode 100644 test-resources/template-lagoon-services/test2/docker-compose.yml delete mode 100644 test-resources/template-lagoon-services/test2/lagoon.yml delete mode 100644 test-resources/template-lagoon-services/test3-results/deployments.yaml delete mode 100644 test-resources/template-lagoon-services/test3-results/pvcs.yaml delete mode 100644 test-resources/template-lagoon-services/test3-results/services.yaml delete mode 100644 test-resources/template-lagoon-services/test3/docker-compose.yml delete mode 100644 test-resources/template-lagoon-services/test3/lagoon.yml delete mode 100644 test-resources/template-lagoon-services/test4-results/deployments.yaml delete mode 100644 test-resources/template-lagoon-services/test4-results/pvcs.yaml delete mode 100644 test-resources/template-lagoon-services/test4-results/services.yaml delete mode 100644 test-resources/template-lagoon-services/test4/docker-compose.yml delete mode 100644 test-resources/template-lagoon-services/test4/lagoon.yml diff --git a/cmd/identify_native_cronjobs.go b/cmd/identify_native_cronjobs.go index f3fc3a3a..cbc4c633 100644 --- a/cmd/identify_native_cronjobs.go +++ b/cmd/identify_native_cronjobs.go @@ -13,7 +13,7 @@ var nativeCronjobsIdentify = &cobra.Command{ Aliases: []string{"nc"}, Short: "Identify any native cronjobs for a specific environment", RunE: func(cmd *cobra.Command, args []string) error { - generator, err := generatorInput(false) + generator, err := generator.GenerateInput(*rootCmd, false) if err != nil { return err } diff --git a/cmd/identify_native_cronjobs_test.go b/cmd/identify_native_cronjobs_test.go index ca4a6757..dce72fdd 100644 --- a/cmd/identify_native_cronjobs_test.go +++ b/cmd/identify_native_cronjobs_test.go @@ -3,10 +3,11 @@ package cmd import ( "os" "testing" - "time" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/lagoon" + "github.com/uselagoon/build-deploy-tool/internal/testdata" ) func TestIdentifyNativeCronjobs(t *testing.T) { @@ -37,174 +38,79 @@ func TestIdentifyNativeCronjobs(t *testing.T) { imageReferences map[string]string } tests := []struct { - name string - args args - want string + name string + args testdata.TestData + templatePath string + want string }{ { name: "test1 basic deployment", - args: args{ - alertContact: "alertcontact", - statusPageID: "statuspageid", - projectName: "example-project", - environmentName: "main", - environmentType: "production", - buildType: "branch", - lagoonVersion: "v2.7.x", - branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, - envVars: `[]`, - lagoonYAML: "../test-resources/template-lagoon-services/test1/lagoon.yml", - templatePath: "../test-resources/template-lagoon-services/output", - imageReferences: map[string]string{ - "node": "harbor.example/example-project/main/node:latest", - }, - }, - want: "[]", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/node/lagoon.yml", + }, true), + templatePath: "testdata/output", + want: "[]", }, { name: "test2a nginx-php deployment", - args: args{ - alertContact: "alertcontact", - statusPageID: "statuspageid", - projectName: "example-project", - environmentName: "main", - environmentType: "production", - buildType: "branch", - lagoonVersion: "v2.7.x", - branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, - envVars: `[]`, - lagoonYAML: "../test-resources/template-lagoon-services/test2/lagoon.yml", - templatePath: "../test-resources/template-lagoon-services/output", - imageReferences: map[string]string{ - "nginx": "harbor.example/example-project/main/nginx:latest", - "php": "harbor.example/example-project/main/php:latest", - "cli": "harbor.example/example-project/main/cli:latest", - "redis": "harbor.example/example-project/main/redis:latest", - "varnish": "harbor.example/example-project/main/varnish:latest", - }, - }, - want: `["cronjob-cli-drush-cron2"]`, + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/complex/lagoon.yml", + ImageReferences: map[string]string{ + "nginx": "harbor.example/example-project/main/nginx:latest", + "php": "harbor.example/example-project/main/php:latest", + "cli": "harbor.example/example-project/main/cli:latest", + "redis": "harbor.example/example-project/main/redis:latest", + "varnish": "harbor.example/example-project/main/varnish:latest", + }, + }, true), + templatePath: "testdata/output", + want: `["cronjob-cli-drush-cron2"]`, }, { name: "test2b nginx-php deployment - rootless", - args: args{ - alertContact: "alertcontact", - statusPageID: "statuspageid", - projectName: "example-project", - environmentName: "main", - environmentType: "production", - buildType: "branch", - lagoonVersion: "v2.7.x", - branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, - envVars: `[]`, - rootlessWorkloads: "enabled", - lagoonYAML: "../test-resources/template-lagoon-services/test2/lagoon.yml", - templatePath: "../test-resources/template-lagoon-services/output", - imageReferences: map[string]string{ - "nginx": "harbor.example/example-project/main/nginx:latest", - "php": "harbor.example/example-project/main/php:latest", - "cli": "harbor.example/example-project/main/cli:latest", - "redis": "harbor.example/example-project/main/redis:latest", - "varnish": "harbor.example/example-project/main/varnish:latest", - }, - }, - want: `["cronjob-cli-drush-cron2"]`, + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/complex/lagoon.yml", + ImageReferences: map[string]string{ + "nginx": "harbor.example/example-project/main/nginx:latest", + "php": "harbor.example/example-project/main/php:latest", + "cli": "harbor.example/example-project/main/cli:latest", + "redis": "harbor.example/example-project/main/redis:latest", + "varnish": "harbor.example/example-project/main/varnish:latest", + }, + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", + Value: "enabled", + Scope: "build", + }, + }, + }, true), + templatePath: "testdata/output", + want: `["cronjob-cli-drush-cron2"]`, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // set the environment variables from args - err := os.Setenv("MONITORING_ALERTCONTACT", tt.args.alertContact) + savedTemplates := tt.templatePath + generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) if err != nil { t.Errorf("%v", err) } - err = os.Setenv("MONITORING_STATUSPAGEID", tt.args.statusPageID) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("PROJECT", tt.args.projectName) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("ENVIRONMENT", tt.args.environmentName) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("BRANCH", tt.args.branch) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("PR_NUMBER", tt.args.prNumber) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("PR_HEAD_BRANCH", tt.args.prHeadBranch) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("PR_BASE_BRANCH", tt.args.prBaseBranch) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("ENVIRONMENT_TYPE", tt.args.environmentType) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("BUILD_TYPE", tt.args.buildType) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("ACTIVE_ENVIRONMENT", tt.args.activeEnvironment) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("STANDBY_ENVIRONMENT", tt.args.standbyEnvironment) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_FASTLY_NOCACHE_SERVICE_ID", tt.args.cacheNoCache) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_PROJECT_VARIABLES", tt.args.projectVars) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_ENVIRONMENT_VARIABLES", tt.args.envVars) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_VERSION", tt.args.lagoonVersion) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_FEATURE_FLAG_DEFAULT_INGRESS_CLASS", tt.args.ingressClass) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_FEATURE_FLAG_DEFAULT_ROOTLESS_WORKLOAD", tt.args.rootlessWorkloads) - if err != nil { - t.Errorf("%v", err) - } - generator, err := generatorInput(false) - if err != nil { - t.Errorf("%v", err) - } - generator.LagoonYAML = tt.args.lagoonYAML - generator.ImageReferences = tt.args.imageReferences - generator.SavedTemplatesPath = tt.args.templatePath - // add dbaasclient overrides for tests - generator.DBaaSClient = dbaasclient.NewClient(dbaasclient.Client{ - RetryMax: 5, - RetryWaitMin: time.Duration(10) * time.Millisecond, - RetryWaitMax: time.Duration(50) * time.Millisecond, - }) - savedTemplates := tt.args.templatePath - err = os.MkdirAll(tt.args.templatePath, 0755) + err = os.MkdirAll(savedTemplates, 0755) if err != nil { t.Errorf("couldn't create directory %v: %v", savedTemplates, err) } @@ -228,7 +134,7 @@ func TestIdentifyNativeCronjobs(t *testing.T) { } t.Cleanup(func() { - helpers.UnsetEnvVars([]helpers.EnvironmentVariable{{Name: "LAGOON_FEATURE_FLAG_DEFAULT_INGRESS_CLASS"}, {Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD"}}) + helpers.UnsetEnvVars(nil) }) }) } diff --git a/cmd/template_dbaas_test.go b/cmd/template_dbaas_test.go index bff3765b..fb32942f 100644 --- a/cmd/template_dbaas_test.go +++ b/cmd/template_dbaas_test.go @@ -107,7 +107,7 @@ func TestDBaaSTemplateGeneration(t *testing.T) { t.Errorf("resulting templates do not match") } t.Cleanup(func() { - helpers.UnsetEnvVars([]helpers.EnvironmentVariable{{Name: "DBAAS_OPERATOR_HTTP"}}) + helpers.UnsetEnvVars(nil) }) }) } diff --git a/cmd/template_ingress_test.go b/cmd/template_ingress_test.go index a85fe839..fbdb3986 100644 --- a/cmd/template_ingress_test.go +++ b/cmd/template_ingress_test.go @@ -449,7 +449,7 @@ func TestTemplateRoutes(t *testing.T) { t.Errorf("resulting templates do not match") } t.Cleanup(func() { - helpers.UnsetEnvVars([]helpers.EnvironmentVariable{{Name: "LAGOON_FEATURE_FLAG_DEFAULT_INGRESS_CLASS"}}) + helpers.UnsetEnvVars(nil) }) }) } diff --git a/cmd/template_lagoonservices.go b/cmd/template_lagoonservices.go index 2f8b335e..cefc6846 100644 --- a/cmd/template_lagoonservices.go +++ b/cmd/template_lagoonservices.go @@ -16,7 +16,7 @@ var lagoonServiceGeneration = &cobra.Command{ Aliases: []string{"ls"}, Short: "Generate the lagoon service templates for a Lagoon build", RunE: func(cmd *cobra.Command, args []string) error { - gen, err := generatorInput(true) + gen, err := generator.GenerateInput(*rootCmd, true) if err != nil { return err } diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index bfe09856..49541d11 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -6,11 +6,12 @@ import ( "os" "reflect" "testing" - "time" "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/lagoon" + "github.com/uselagoon/build-deploy-tool/internal/testdata" ) func TestTemplateLagoonServices(t *testing.T) { @@ -42,233 +43,155 @@ func TestTemplateLagoonServices(t *testing.T) { imageReferences map[string]string } tests := []struct { - name string - description string - args args - want string + name string + description string + args args + args2 testdata.TestData + templatePath string + want string }{ { name: "test1 basic deployment", - args: args{ - alertContact: "alertcontact", - statusPageID: "statuspageid", - projectName: "example-project", - environmentName: "main", - environmentType: "production", - buildType: "branch", - lagoonVersion: "v2.7.x", - branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, - envVars: `[]`, - lagoonYAML: "../test-resources/template-lagoon-services/test1/lagoon.yml", - templatePath: "../test-resources/template-lagoon-services/output", - configMapSha: "abcdefg1234567890", - imageReferences: map[string]string{ - "node": "harbor.example/example-project/main/node:latest", - }, - }, - want: "../test-resources/template-lagoon-services/test1-results", + args2: 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:latest", + }, + }, true), + templatePath: "testdata/output", + want: "../internal/testdata/basic/service-templates/service1", }, { name: "test2a nginx-php deployment", - args: args{ - alertContact: "alertcontact", - statusPageID: "statuspageid", - projectName: "example-project", - environmentName: "main", - environmentType: "production", - buildType: "branch", - lagoonVersion: "v2.7.x", - branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, - envVars: `[]`, - lagoonYAML: "../test-resources/template-lagoon-services/test2/lagoon.yml", - templatePath: "../test-resources/template-lagoon-services/output", - configMapSha: "abcdefg1234567890", - imageReferences: map[string]string{ - "nginx": "harbor.example/example-project/main/nginx:latest", - "php": "harbor.example/example-project/main/php:latest", - "cli": "harbor.example/example-project/main/cli:latest", - "redis": "harbor.example/example-project/main/redis:latest", - "varnish": "harbor.example/example-project/main/varnish:latest", - }, - }, - want: "../test-resources/template-lagoon-services/test2-results-a", + args2: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/complex/lagoon.varnish.yml", + ImageReferences: map[string]string{ + "nginx": "harbor.example/example-project/main/nginx:latest", + "php": "harbor.example/example-project/main/php:latest", + "cli": "harbor.example/example-project/main/cli:latest", + "redis": "harbor.example/example-project/main/redis:latest", + "varnish": "harbor.example/example-project/main/varnish:latest", + }, + }, true), + templatePath: "testdata/output", + want: "../internal/testdata/complex/service-templates/service1", }, { name: "test2b nginx-php deployment - rootless", - args: args{ - alertContact: "alertcontact", - statusPageID: "statuspageid", - projectName: "example-project", - environmentName: "main", - environmentType: "production", - buildType: "branch", - lagoonVersion: "v2.7.x", - branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, - envVars: `[]`, - rootlessWorkloads: "enabled", - lagoonYAML: "../test-resources/template-lagoon-services/test2/lagoon.yml", - templatePath: "../test-resources/template-lagoon-services/output", - configMapSha: "abcdefg1234567890", - imageReferences: map[string]string{ - "nginx": "harbor.example/example-project/main/nginx:latest", - "php": "harbor.example/example-project/main/php:latest", - "cli": "harbor.example/example-project/main/cli:latest", - "redis": "harbor.example/example-project/main/redis:latest", - "varnish": "harbor.example/example-project/main/varnish:latest", - }, - }, - want: "../test-resources/template-lagoon-services/test2-results-b", + args2: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/complex/lagoon.varnish.yml", + ImageReferences: map[string]string{ + "nginx": "harbor.example/example-project/main/nginx:latest", + "php": "harbor.example/example-project/main/php:latest", + "cli": "harbor.example/example-project/main/cli:latest", + "redis": "harbor.example/example-project/main/redis:latest", + "varnish": "harbor.example/example-project/main/varnish:latest", + }, + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", + Value: "enabled", + Scope: "build", + }, + }, + }, true), + templatePath: "testdata/output", + want: "../internal/testdata/complex/service-templates/service2", }, { name: "test3 - funky pvcs", description: "only create pvcs of the requested persistent-name in the docker-compose file", - args: args{ - alertContact: "alertcontact", - statusPageID: "statuspageid", - projectName: "example-project", - environmentName: "main", - environmentType: "production", - buildType: "branch", - lagoonVersion: "v2.7.x", - branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, - envVars: `[]`, - rootlessWorkloads: "enabled", - lagoonYAML: "../test-resources/template-lagoon-services/test3/lagoon.yml", - templatePath: "../test-resources/template-lagoon-services/output", - configMapSha: "abcdefg1234567890", - imageReferences: map[string]string{ - "lnd": "harbor.example/example-project/main/lnd:latest", - "thunderhub": "harbor.example/example-project/main/thunderhub:latest", - "tor": "harbor.example/example-project/main/tor:latest", - }, - }, - want: "../test-resources/template-lagoon-services/test3-results", + args2: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/basic/lagoon.thunderhub.yml", + ImageReferences: map[string]string{ + "lnd": "harbor.example/example-project/main/lnd:latest", + "thunderhub": "harbor.example/example-project/main/thunderhub:latest", + "tor": "harbor.example/example-project/main/tor:latest", + }, + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", + Value: "enabled", + Scope: "build", + }, + }, + }, true), + templatePath: "testdata/output", + want: "../internal/testdata/basic/service-templates/service2", }, { name: "test4 - basic-persistent with worker-persistent", description: "create a basic-persistent that gets a pvc and mount that volume on a worker-persistent type", - args: args{ - alertContact: "alertcontact", - statusPageID: "statuspageid", - projectName: "example-project", - environmentName: "main", - environmentType: "production", - buildType: "branch", - lagoonVersion: "v2.7.x", - branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, - envVars: `[]`, - rootlessWorkloads: "enabled", - lagoonYAML: "../test-resources/template-lagoon-services/test4/lagoon.yml", - templatePath: "../test-resources/template-lagoon-services/output", - configMapSha: "abcdefg1234567890", - imageReferences: map[string]string{ - "lnd": "harbor.example/example-project/main/lnd:latest", - "tor": "harbor.example/example-project/main/tor:latest", - }, - }, - want: "../test-resources/template-lagoon-services/test4-results", + // args: args{ + // alertContact: "alertcontact", + // statusPageID: "statuspageid", + // projectName: "example-project", + // environmentName: "main", + // environmentType: "production", + // buildType: "branch", + // lagoonVersion: "v2.7.x", + // branch: "main", + // projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, + // envVars: `[]`, + // rootlessWorkloads: "enabled", + // lagoonYAML: "../test-resources/template-lagoon-services/test4/lagoon.yml", + // templatePath: "../test-resources/template-lagoon-services/output", + // configMapSha: "abcdefg1234567890", + // imageReferences: map[string]string{ + // "lnd": "harbor.example/example-project/main/lnd:latest", + // "tor": "harbor.example/example-project/main/tor:latest", + // }, + // }, + // templatePath: "testdata/output", + // want: "../test-resources/template-lagoon-services/test4-results", + args2: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/basic/lagoon.thunderhub-2.yml", + ImageReferences: map[string]string{ + "lnd": "harbor.example/example-project/main/lnd:latest", + "tor": "harbor.example/example-project/main/tor:latest", + }, + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", + Value: "enabled", + Scope: "build", + }, + }, + }, true), + templatePath: "testdata/output", + want: "../internal/testdata/basic/service-templates/service3", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // set the environment variables from args - err := os.Setenv("MONITORING_ALERTCONTACT", tt.args.alertContact) + savedTemplates := tt.templatePath + generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args2) if err != nil { t.Errorf("%v", err) } - err = os.Setenv("MONITORING_STATUSPAGEID", tt.args.statusPageID) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("PROJECT", tt.args.projectName) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("ENVIRONMENT", tt.args.environmentName) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("BRANCH", tt.args.branch) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("PR_NUMBER", tt.args.prNumber) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("PR_HEAD_BRANCH", tt.args.prHeadBranch) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("PR_BASE_BRANCH", tt.args.prBaseBranch) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("ENVIRONMENT_TYPE", tt.args.environmentType) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("BUILD_TYPE", tt.args.buildType) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("ACTIVE_ENVIRONMENT", tt.args.activeEnvironment) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("STANDBY_ENVIRONMENT", tt.args.standbyEnvironment) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("CONFIG_MAP_SHA", tt.args.configMapSha) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_FASTLY_NOCACHE_SERVICE_ID", tt.args.cacheNoCache) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_PROJECT_VARIABLES", tt.args.projectVars) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_ENVIRONMENT_VARIABLES", tt.args.envVars) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_VERSION", tt.args.lagoonVersion) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_FEATURE_FLAG_DEFAULT_INGRESS_CLASS", tt.args.ingressClass) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_FEATURE_FLAG_DEFAULT_ROOTLESS_WORKLOAD", tt.args.rootlessWorkloads) - if err != nil { - t.Errorf("%v", err) - } - generator, err := generatorInput(false) - if err != nil { - t.Errorf("%v", err) - } - generator.LagoonYAML = tt.args.lagoonYAML - generator.ImageReferences = tt.args.imageReferences - generator.SavedTemplatesPath = tt.args.templatePath - // add dbaasclient overrides for tests - generator.DBaaSClient = dbaasclient.NewClient(dbaasclient.Client{ - RetryMax: 5, - RetryWaitMin: time.Duration(10) * time.Millisecond, - RetryWaitMax: time.Duration(50) * time.Millisecond, - }) - savedTemplates := tt.args.templatePath - err = os.MkdirAll(tt.args.templatePath, 0755) + err = os.MkdirAll(savedTemplates, 0755) if err != nil { t.Errorf("couldn't create directory %v: %v", savedTemplates, err) } @@ -335,7 +258,7 @@ func TestTemplateLagoonServices(t *testing.T) { t.Errorf("resulting templates do not match") } t.Cleanup(func() { - helpers.UnsetEnvVars([]helpers.EnvironmentVariable{{Name: "LAGOON_FEATURE_FLAG_DEFAULT_INGRESS_CLASS"}, {Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD"}, {Name: "CONFIG_MAP_SHA"}}) + helpers.UnsetEnvVars(nil) }) }) } diff --git a/test-resources/lagoon-yaml/test5/lagoon.yml b/test-resources/lagoon-yaml/test5/lagoon.yml deleted file mode 100644 index d6829f3c..00000000 --- a/test-resources/lagoon-yaml/test5/lagoon.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -docker-compose-yaml: docker-compose.yml - -project: content-example-com - -environments: - main: - cronjobs: - - name: drush cron - schedule: "*/15 * * * *" - command: 'drush cron' - service: cli - routes: - - nginx: - - a.example.com diff --git a/test-resources/lagoon-yaml/test6/lagoon.yml b/test-resources/lagoon-yaml/test6/lagoon.yml deleted file mode 100644 index 9a9aee32..00000000 --- a/test-resources/lagoon-yaml/test6/lagoon.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- -docker-compose-yaml: docker-compose.yml - -project: content-example-com - -multiproject1: - environments: - main: - cronjobs: - - name: drush cron - schedule: "*/15 * * * *" - command: 'drush cron' - service: cli - routes: - - nginx: - - a.example.com - -multiproject2: - environments: - main: - cronjobs: - - name: notdrush cron - schedule: "*/15 * * * *" - command: 'notdrush cron' - service: cli - routes: - - nginx: - - a.example.com diff --git a/test-resources/template-lagoon-services/test1-results/deployments.yaml b/test-resources/template-lagoon-services/test1-results/deployments.yaml deleted file mode 100644 index 1a0d8667..00000000 --- a/test-resources/template-lagoon-services/test1-results/deployments.yaml +++ /dev/null @@ -1,84 +0,0 @@ ---- -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 - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/node:latest - 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: 100M - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production -status: {} diff --git a/test-resources/template-lagoon-services/test1-results/services.yaml b/test-resources/template-lagoon-services/test1-results/services.yaml deleted file mode 100644 index 6b286993..00000000 --- a/test-resources/template-lagoon-services/test1-results/services.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- -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: {} diff --git a/test-resources/template-lagoon-services/test1/docker-compose.yml b/test-resources/template-lagoon-services/test1/docker-compose.yml deleted file mode 100644 index 66b9415e..00000000 --- a/test-resources/template-lagoon-services/test1/docker-compose.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: '2' -services: - node: - networks: - - amazeeio-network - - default - build: - context: . - dockerfile: basic.dockerfile - labels: - lagoon.type: basic - lagoon.service.usecomposeports: true - volumes: - - .:/app:delegated - ports: - - '1234' - - '8191' - - '9001/udp' - -networks: - amazeeio-network: - external: true \ No newline at end of file diff --git a/test-resources/template-lagoon-services/test1/lagoon.yml b/test-resources/template-lagoon-services/test1/lagoon.yml deleted file mode 100644 index 4f9c49c7..00000000 --- a/test-resources/template-lagoon-services/test1/lagoon.yml +++ /dev/null @@ -1,10 +0,0 @@ -docker-compose-yaml: ../test-resources/template-lagoon-services/test1/docker-compose.yml - -environment_variables: - git_sha: "true" - -environments: - main: - routes: - - node: - - example.com diff --git a/test-resources/template-lagoon-services/test2-results-a/cronjobs.yaml b/test-resources/template-lagoon-services/test2-results-a/cronjobs.yaml deleted file mode 100644 index 4c5e273b..00000000 --- a/test-resources/template-lagoon-services/test2-results-a/cronjobs.yaml +++ /dev/null @@ -1,96 +0,0 @@ ---- -apiVersion: batch/v1beta1 -kind: CronJob -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: cli - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: cli - lagoon.sh/service-type: cli-persistent - lagoon.sh/template: cli-persistent-0.1.0 - name: cronjob-cli-drush-cron2 -spec: - concurrencyPolicy: Forbid - failedJobsHistoryLimit: 1 - jobTemplate: - metadata: - creationTimestamp: null - spec: - template: - metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/configMapSha: abcdefg1234567890 - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: cli - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: cli - lagoon.sh/service-type: cli-persistent - lagoon.sh/template: cli-persistent-0.1.0 - spec: - containers: - - command: - - /lagoon/cronjob.sh - - drush cron - env: - - name: LAGOON_GIT_SHA - - name: SERVICE_NAME - value: cli - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/cli:latest - name: cronjob-cli-drush-cron2 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - mountPath: /app/docroot/sites/default/files//php - name: nginx-php-twig - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - restartPolicy: Never - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - - emptyDir: {} - name: nginx-php-twig - - name: nginx-php - persistentVolumeClaim: - claimName: nginx-php - schedule: 5,35 * * * * - startingDeadlineSeconds: 240 - successfulJobsHistoryLimit: 0 -status: {} diff --git a/test-resources/template-lagoon-services/test2-results-a/deployments.yaml b/test-resources/template-lagoon-services/test2-results-a/deployments.yaml deleted file mode 100644 index c42929fd..00000000 --- a/test-resources/template-lagoon-services/test2-results-a/deployments.yaml +++ /dev/null @@ -1,381 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: cli - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: cli - lagoon.sh/service-type: cli-persistent - lagoon.sh/template: cli-persistent-0.1.0 - name: cli -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: cli - app.kubernetes.io/name: cli-persistent - 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: cli - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: cli - lagoon.sh/service-type: cli-persistent - lagoon.sh/template: cli-persistent-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - value: | - 5,20,35,50 * * * * drush cron - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/cli:latest - name: cli - ports: - - containerPort: 3000 - name: http - protocol: TCP - readinessProbe: - exec: - command: - - /bin/sh - - -c - - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; - fi - failureThreshold: 3 - initialDelaySeconds: 5 - periodSeconds: 2 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - mountPath: /app/docroot/sites/default/files//php - name: nginx-php-twig - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - - emptyDir: {} - name: nginx-php-twig - - name: nginx-php - persistentVolumeClaim: - claimName: nginx-php -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: redis - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: redis - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: redis - lagoon.sh/service-type: redis - lagoon.sh/template: redis-0.1.0 - name: redis -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: redis - app.kubernetes.io/name: redis - 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: redis - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: redis - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: redis - lagoon.sh/service-type: redis - lagoon.sh/template: redis-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/redis:latest - livenessProbe: - initialDelaySeconds: 120 - tcpSocket: - port: 6379 - timeoutSeconds: 10 - name: redis - ports: - - containerPort: 6379 - name: 6379-tcp - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 6379 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: varnish - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: varnish - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: varnish - lagoon.sh/service-type: varnish - lagoon.sh/template: varnish-0.1.0 - name: varnish -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: varnish - app.kubernetes.io/name: varnish - 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: varnish - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: varnish - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: varnish - lagoon.sh/service-type: varnish - lagoon.sh/template: varnish-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/varnish:latest - livenessProbe: - initialDelaySeconds: 60 - tcpSocket: - port: 8080 - timeoutSeconds: 10 - name: varnish - ports: - - containerPort: 8080 - name: http - protocol: TCP - - containerPort: 6082 - name: controlport - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 8080 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - name: nginx-php -spec: - replicas: 2 - selector: - matchLabels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/name: nginx-php-persistent - 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: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - spec: - containers: - - env: - - name: NGINX_FASTCGI_PASS - value: 127.0.0.1 - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/nginx:latest - livenessProbe: - failureThreshold: 5 - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 900 - timeoutSeconds: 3 - name: nginx - ports: - - containerPort: 8080 - name: http - protocol: TCP - readinessProbe: - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 1 - timeoutSeconds: 3 - resources: - requests: - cpu: 10m - memory: 10M - volumeMounts: - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - - env: - - name: NGINX_FASTCGI_PASS - value: 127.0.0.1 - - name: LAGOON_GIT_SHA - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/php:latest - livenessProbe: - initialDelaySeconds: 60 - periodSeconds: 10 - tcpSocket: - port: 9000 - name: php - ports: - - containerPort: 9000 - name: http - protocol: TCP - readinessProbe: - initialDelaySeconds: 2 - periodSeconds: 10 - tcpSocket: - port: 9000 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - - mountPath: /app/docroot/sites/default/files//php - name: nginx-php-twig - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - volumes: - - name: nginx-php - persistentVolumeClaim: - claimName: nginx-php - - emptyDir: {} - name: nginx-php-twig -status: {} diff --git a/test-resources/template-lagoon-services/test2-results-a/pvcs.yaml b/test-resources/template-lagoon-services/test2-results-a/pvcs.yaml deleted file mode 100644 index 9705d159..00000000 --- a/test-resources/template-lagoon-services/test2-results-a/pvcs.yaml +++ /dev/null @@ -1,30 +0,0 @@ ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - annotations: - k8up.io/backup: "true" - k8up.syn.tools/backup: "true" - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - name: nginx-php -spec: - accessModes: - - ReadWriteMany - resources: - requests: - storage: 5Gi - storageClassName: bulk -status: {} diff --git a/test-resources/template-lagoon-services/test2-results-a/services.yaml b/test-resources/template-lagoon-services/test2-results-a/services.yaml deleted file mode 100644 index 6f8f096a..00000000 --- a/test-resources/template-lagoon-services/test2-results-a/services.yaml +++ /dev/null @@ -1,97 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: redis - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: redis - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: redis - lagoon.sh/service-type: redis - lagoon.sh/template: redis-0.1.0 - name: redis -spec: - ports: - - name: 6379-tcp - port: 6379 - protocol: TCP - targetPort: 6379 - selector: - app.kubernetes.io/instance: redis - app.kubernetes.io/name: redis -status: - loadBalancer: {} ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: varnish - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: varnish - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: varnish - lagoon.sh/service-type: varnish - lagoon.sh/template: varnish-0.1.0 - name: varnish -spec: - ports: - - name: http - port: 8080 - protocol: TCP - targetPort: http - - name: controlport - port: 6082 - protocol: TCP - targetPort: controlport - selector: - app.kubernetes.io/instance: varnish - app.kubernetes.io/name: varnish -status: - loadBalancer: {} ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - name: nginx-php -spec: - ports: - - name: http - port: 8080 - protocol: TCP - targetPort: http - selector: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/name: nginx-php-persistent -status: - loadBalancer: {} diff --git a/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml b/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml deleted file mode 100644 index a1701991..00000000 --- a/test-resources/template-lagoon-services/test2-results-b/cronjobs.yaml +++ /dev/null @@ -1,100 +0,0 @@ ---- -apiVersion: batch/v1beta1 -kind: CronJob -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: cli - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: cli - lagoon.sh/service-type: cli-persistent - lagoon.sh/template: cli-persistent-0.1.0 - name: cronjob-cli-drush-cron2 -spec: - concurrencyPolicy: Forbid - failedJobsHistoryLimit: 1 - jobTemplate: - metadata: - creationTimestamp: null - spec: - template: - metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/configMapSha: abcdefg1234567890 - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: cli - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: cli - lagoon.sh/service-type: cli-persistent - lagoon.sh/template: cli-persistent-0.1.0 - spec: - containers: - - command: - - /lagoon/cronjob.sh - - drush cron - env: - - name: LAGOON_GIT_SHA - - name: SERVICE_NAME - value: cli - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/cli:latest - name: cronjob-cli-drush-cron2 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - mountPath: /app/docroot/sites/default/files//php - name: nginx-php-twig - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - restartPolicy: Never - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - - emptyDir: {} - name: nginx-php-twig - - name: nginx-php - persistentVolumeClaim: - claimName: nginx-php - schedule: 5,35 * * * * - startingDeadlineSeconds: 240 - successfulJobsHistoryLimit: 0 -status: {} diff --git a/test-resources/template-lagoon-services/test2-results-b/deployments.yaml b/test-resources/template-lagoon-services/test2-results-b/deployments.yaml deleted file mode 100644 index 93692a13..00000000 --- a/test-resources/template-lagoon-services/test2-results-b/deployments.yaml +++ /dev/null @@ -1,414 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: cli - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: cli - lagoon.sh/service-type: cli-persistent - lagoon.sh/template: cli-persistent-0.1.0 - name: cli -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: cli - app.kubernetes.io/name: cli-persistent - 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: cli - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: cli - lagoon.sh/service-type: cli-persistent - lagoon.sh/template: cli-persistent-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - value: | - 5,20,35,50 * * * * drush cron - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/cli:latest - name: cli - ports: - - containerPort: 3000 - name: http - protocol: TCP - readinessProbe: - exec: - command: - - /bin/sh - - -c - - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; - fi - failureThreshold: 3 - initialDelaySeconds: 5 - periodSeconds: 2 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - mountPath: /app/docroot/sites/default/files//php - name: nginx-php-twig - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - - emptyDir: {} - name: nginx-php-twig - - name: nginx-php - persistentVolumeClaim: - claimName: nginx-php -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: redis - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: redis - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: redis - lagoon.sh/service-type: redis - lagoon.sh/template: redis-0.1.0 - name: redis -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: redis - app.kubernetes.io/name: redis - 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: redis - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: redis - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: redis - lagoon.sh/service-type: redis - lagoon.sh/template: redis-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/redis:latest - livenessProbe: - initialDelaySeconds: 120 - tcpSocket: - port: 6379 - timeoutSeconds: 10 - name: redis - ports: - - containerPort: 6379 - name: 6379-tcp - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 6379 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: varnish - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: varnish - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: varnish - lagoon.sh/service-type: varnish - lagoon.sh/template: varnish-0.1.0 - name: varnish -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: varnish - app.kubernetes.io/name: varnish - 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: varnish - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: varnish - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: varnish - lagoon.sh/service-type: varnish - lagoon.sh/template: varnish-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/varnish:latest - livenessProbe: - initialDelaySeconds: 60 - tcpSocket: - port: 8080 - timeoutSeconds: 10 - name: varnish - ports: - - containerPort: 8080 - name: http - protocol: TCP - - containerPort: 6082 - name: controlport - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 8080 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - name: nginx-php -spec: - replicas: 2 - selector: - matchLabels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/name: nginx-php-persistent - 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: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - spec: - containers: - - env: - - name: NGINX_FASTCGI_PASS - value: 127.0.0.1 - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/nginx:latest - livenessProbe: - failureThreshold: 5 - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 900 - timeoutSeconds: 3 - name: nginx - ports: - - containerPort: 8080 - name: http - protocol: TCP - readinessProbe: - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 1 - timeoutSeconds: 3 - resources: - requests: - cpu: 10m - memory: 10M - volumeMounts: - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - - env: - - name: NGINX_FASTCGI_PASS - value: 127.0.0.1 - - name: LAGOON_GIT_SHA - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/php:latest - livenessProbe: - initialDelaySeconds: 60 - periodSeconds: 10 - tcpSocket: - port: 9000 - name: php - ports: - - containerPort: 9000 - name: http - protocol: TCP - readinessProbe: - initialDelaySeconds: 2 - periodSeconds: 10 - tcpSocket: - port: 9000 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - - mountPath: /app/docroot/sites/default/files//php - name: nginx-php-twig - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - initContainers: - - command: - - sh - - -c - - "set -e\nSENTINEL=\"/storage/.lagoon-rootless-migration-complete\"\nif ! - [ -f \"$SENTINEL\" ]; then\n\tfind /storage -exec chown 10000:0 {} +\n\tfind - /storage -exec chmod a+r,u+w {} +\n\tfind /storage -type d -exec chmod a+x - {} +\n\ttouch \"$SENTINEL\"\nfi" - image: library/busybox:musl - imagePullPolicy: IfNotPresent - name: fix-storage-permissions - resources: {} - securityContext: - runAsUser: 0 - volumeMounts: - - mountPath: /storage - name: nginx-php - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 - volumes: - - name: nginx-php - persistentVolumeClaim: - claimName: nginx-php - - emptyDir: {} - name: nginx-php-twig -status: {} diff --git a/test-resources/template-lagoon-services/test2-results-b/pvcs.yaml b/test-resources/template-lagoon-services/test2-results-b/pvcs.yaml deleted file mode 100644 index 9705d159..00000000 --- a/test-resources/template-lagoon-services/test2-results-b/pvcs.yaml +++ /dev/null @@ -1,30 +0,0 @@ ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - annotations: - k8up.io/backup: "true" - k8up.syn.tools/backup: "true" - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - name: nginx-php -spec: - accessModes: - - ReadWriteMany - resources: - requests: - storage: 5Gi - storageClassName: bulk -status: {} diff --git a/test-resources/template-lagoon-services/test2-results-b/services.yaml b/test-resources/template-lagoon-services/test2-results-b/services.yaml deleted file mode 100644 index 6f8f096a..00000000 --- a/test-resources/template-lagoon-services/test2-results-b/services.yaml +++ /dev/null @@ -1,97 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: redis - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: redis - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: redis - lagoon.sh/service-type: redis - lagoon.sh/template: redis-0.1.0 - name: redis -spec: - ports: - - name: 6379-tcp - port: 6379 - protocol: TCP - targetPort: 6379 - selector: - app.kubernetes.io/instance: redis - app.kubernetes.io/name: redis -status: - loadBalancer: {} ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: varnish - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: varnish - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: varnish - lagoon.sh/service-type: varnish - lagoon.sh/template: varnish-0.1.0 - name: varnish -spec: - ports: - - name: http - port: 8080 - protocol: TCP - targetPort: http - - name: controlport - port: 6082 - protocol: TCP - targetPort: controlport - selector: - app.kubernetes.io/instance: varnish - app.kubernetes.io/name: varnish -status: - loadBalancer: {} ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - name: nginx-php -spec: - ports: - - name: http - port: 8080 - protocol: TCP - targetPort: http - selector: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/name: nginx-php-persistent -status: - loadBalancer: {} diff --git a/test-resources/template-lagoon-services/test2/docker-compose.yml b/test-resources/template-lagoon-services/test2/docker-compose.yml deleted file mode 100644 index 5efe6c55..00000000 --- a/test-resources/template-lagoon-services/test2/docker-compose.yml +++ /dev/null @@ -1,160 +0,0 @@ -version: '2.3' - -x-example-image-version: - &example-image-version ${EXAMPLE_IMAGE_VERSION:-4.x} - -x-project: - &project ${PROJECT_NAME:-mysite} - -x-volumes: - &default-volumes - volumes: - - .:/app:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. - - ./docroot/sites/default/files:/app/docroot/sites/default/files:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. - -x-environment: - &default-environment - LAGOON_PROJECT: *project - DRUPAL_HASH_SALT: fakehashsaltfakehashsaltfakehashsalt - LAGOON_LOCALDEV_URL: ${LOCALDEV_URL:-http://mysite.docker.amazee.io} - LAGOON_ROUTE: ${LOCALDEV_URL:-http://mysite.docker.amazee.io} - GITHUB_TOKEN: ${GITHUB_TOKEN:-} - EXAMPLE_KEY: ${EXAMPLE_KEY:-} - EXAMPLE_IMAGE_VERSION: ${EXAMPLE_IMAGE_VERSION:-latest} - LAGOON_ENVIRONMENT_TYPE: ${LAGOON_ENVIRONMENT_TYPE:-local} - DRUPAL_REFRESH_SEARCHAPI: ${DRUPAL_REFRESH_SEARCHAPI:-} - EXAMPLE_INGRESS_PSK: ${EXAMPLE_INGRESS_PSK:-} - EXAMPLE_INGRESS_HEADER: ${EXAMPLE_INGRESS_HEADER:-} - EXAMPLE_INGRESS_ENABLED: ${EXAMPLE_INGRESS_ENABLED:-} - REDIS_CACHE_PREFIX: "tide_" - DB_ALIAS: ${DB_ALIAS:-bay.production} - - -services: - - cli: - build: - context: . - dockerfile: .docker/Dockerfile.cli - args: - COMPOSER: ${COMPOSER:-composer.json} - EXAMPLE_IMAGE_VERSION: *example-image-version - image: *project - environment: - << : *default-environment - << : *default-volumes - volumes_from: ### Local overrides to mount host SSH keys. Automatically removed in CI. - - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. - labels: - lagoon.type: cli-persistent - lagoon.persistent: /app/docroot/sites/default/files/ - lagoon.persistent.name: nginx-php - lagoon.persistent.size: 5Gi - - nginx: - build: - context: . - dockerfile: .docker/Dockerfile.nginx-drupal - args: - CLI_IMAGE: *project - EXAMPLE_IMAGE_VERSION: *example-image-version - << : *default-volumes - environment: - << : *default-environment - depends_on: - - cli - networks: - - amazeeio-network - - default - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: /app/docroot/sites/default/files/ - lagoon.persistent.size: 5Gi - lagoon.name: nginx-php - expose: - - "8080" - php: - build: - context: . - dockerfile: .docker/Dockerfile.php - args: - CLI_IMAGE: *project - EXAMPLE_IMAGE_VERSION: *example-image-version - environment: - << : *default-environment - << : *default-volumes - depends_on: - - cli - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: /app/docroot/sites/default/files/ - lagoon.persistent.size: 5Gi - lagoon.name: nginx-php - - mariadb: - image: amazeeio/mariadb-drupal - environment: - << : *default-environment - ports: - - "3306" # Find port on host with `ahoy info` or `docker-compose port mariadb 3306` - labels: - lagoon.type: mariadb - - redis: - image: amazeeio/redis - labels: - lagoon.type: redis - - elasticsearch: - build: - context: . - dockerfile: .docker/Dockerfile.elasticsearch - args: - - ES_TPL=${ES_TPL:-elasticsearch.yml} - environment: - - discovery.type=single-node - labels: - lagoon.type: none - - chrome: - image: selenium/standalone-chrome:3.141.59-oxygen - shm_size: '1gb' - environment: - << : *default-environment - << : *default-volumes - depends_on: - - cli - labels: - lagoon.type: none - - clamav: - image: clamav/clamav:${EXAMPLE_IMAGE_VERSION:-4.x} - environment: - << : *default-environment - ports: - - "3310" - labels: - lagoon.type: none - - varnish: - image: uselagoon/varnish-5-drupal:latest - labels: - lagoon.type: varnish - lando.type: varnish-drupal - links: - - nginx # links varnish to the nginx in this docker-compose project, or it would try to connect to any nginx running in docker - environment: - << : *default-environment - VARNISH_BYPASS: "true" # by default we bypass varnish, change to 'false' or remove in order to tell varnish to cache if possible - networks: - - amazeeio-network - - default - - -networks: - amazeeio-network: - external: true - -volumes: - app: {} - files: {} \ No newline at end of file diff --git a/test-resources/template-lagoon-services/test2/lagoon.yml b/test-resources/template-lagoon-services/test2/lagoon.yml deleted file mode 100644 index bdc55a33..00000000 --- a/test-resources/template-lagoon-services/test2/lagoon.yml +++ /dev/null @@ -1,19 +0,0 @@ -docker-compose-yaml: ../test-resources/template-lagoon-services/test2/docker-compose.yml - -environment_variables: - git_sha: "true" - -environments: - main: - routes: - - nginx: - - example.com - cronjobs: - - name: drush cron - schedule: "*/15 * * * *" - command: drush cron - service: cli - - name: drush cron2 - schedule: "*/30 * * * *" - command: drush cron - service: cli \ No newline at end of file diff --git a/test-resources/template-lagoon-services/test3-results/deployments.yaml b/test-resources/template-lagoon-services/test3-results/deployments.yaml deleted file mode 100644 index 27d19ed3..00000000 --- a/test-resources/template-lagoon-services/test3-results/deployments.yaml +++ /dev/null @@ -1,266 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: lnd - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: lnd - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: lnd -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: lnd - app.kubernetes.io/name: basic-persistent - 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: lnd - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: lnd - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/lnd:latest - livenessProbe: - initialDelaySeconds: 60 - tcpSocket: - port: 8080 - timeoutSeconds: 10 - name: basic - ports: - - containerPort: 8080 - name: tcp-8080 - protocol: TCP - - containerPort: 10009 - name: tcp-10009 - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 8080 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /app/storage - name: lnd - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 - volumes: - - name: lnd - persistentVolumeClaim: - claimName: lnd -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: thunderhub - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: thunderhub - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: thunderhub -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: thunderhub - app.kubernetes.io/name: basic-persistent - 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: thunderhub - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: thunderhub - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/thunderhub:latest - livenessProbe: - initialDelaySeconds: 60 - tcpSocket: - port: 3000 - timeoutSeconds: 10 - name: basic - ports: - - containerPort: 3000 - name: tcp-3000 - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 3000 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /data - name: lnd - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 - volumes: - - name: lnd - persistentVolumeClaim: - claimName: lnd -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: tor - 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: tor - lagoon.sh/service-type: basic - lagoon.sh/template: basic-0.1.0 - name: tor -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: tor - 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: tor - 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: tor - lagoon.sh/service-type: basic - lagoon.sh/template: basic-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/tor:latest - livenessProbe: - initialDelaySeconds: 60 - tcpSocket: - port: 9050 - timeoutSeconds: 10 - name: basic - ports: - - containerPort: 9050 - name: tcp-9050 - protocol: TCP - - containerPort: 9051 - name: tcp-9051 - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 9050 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 -status: {} diff --git a/test-resources/template-lagoon-services/test3-results/pvcs.yaml b/test-resources/template-lagoon-services/test3-results/pvcs.yaml deleted file mode 100644 index f8377573..00000000 --- a/test-resources/template-lagoon-services/test3-results/pvcs.yaml +++ /dev/null @@ -1,30 +0,0 @@ ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - annotations: - k8up.io/backup: "true" - k8up.syn.tools/backup: "true" - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: lnd - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: lnd - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: lnd -spec: - accessModes: - - ReadWriteMany - resources: - requests: - storage: 5Gi - storageClassName: bulk -status: {} diff --git a/test-resources/template-lagoon-services/test3-results/services.yaml b/test-resources/template-lagoon-services/test3-results/services.yaml deleted file mode 100644 index 21e8c8ad..00000000 --- a/test-resources/template-lagoon-services/test3-results/services.yaml +++ /dev/null @@ -1,101 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: lnd - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: lnd - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: lnd -spec: - ports: - - name: tcp-8080 - port: 8080 - protocol: TCP - targetPort: tcp-8080 - - name: tcp-10009 - port: 10009 - protocol: TCP - targetPort: tcp-10009 - selector: - app.kubernetes.io/instance: lnd - app.kubernetes.io/name: basic-persistent -status: - loadBalancer: {} ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: thunderhub - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: thunderhub - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: thunderhub -spec: - ports: - - name: tcp-3000 - port: 3000 - protocol: TCP - targetPort: tcp-3000 - selector: - app.kubernetes.io/instance: thunderhub - app.kubernetes.io/name: basic-persistent -status: - loadBalancer: {} ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: tor - 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: tor - lagoon.sh/service-type: basic - lagoon.sh/template: basic-0.1.0 - name: tor -spec: - ports: - - name: tcp-9050 - port: 9050 - protocol: TCP - targetPort: tcp-9050 - - name: tcp-9051 - port: 9051 - protocol: TCP - targetPort: tcp-9051 - selector: - app.kubernetes.io/instance: tor - app.kubernetes.io/name: basic -status: - loadBalancer: {} diff --git a/test-resources/template-lagoon-services/test3/docker-compose.yml b/test-resources/template-lagoon-services/test3/docker-compose.yml deleted file mode 100644 index 04115bee..00000000 --- a/test-resources/template-lagoon-services/test3/docker-compose.yml +++ /dev/null @@ -1,92 +0,0 @@ -version: '2' -services: - lnd: - networks: - - amazeeio-network - - default - build: - context: . - dockerfile: Dockerfile - user: '10000' - labels: - lagoon.type: basic-persistent - lagoon.persistent: /app/storage - lagoon.service.usecomposeports: true - environment: - LAGOON_LOCALDEV_HTTP_PORT: 8080 - LAGOON_ROUTE: http://lnd.docker.amazee.io - volumes: - - ./storage:/app/storage:delegated - env_file: - - .env.local - ports: - - "8080" # exposes the port 8080 with a random local port, find it with `docker-compose port lnd 8080` - - "10009" # exposes the port 10009 with a random local port, find it with `docker-compose port lnd 10009` - - thunderhub: - networks: - - amazeeio-network - - default - build: - context: thunderhub - dockerfile: Dockerfile - user: '10000' - environment: - LOG_LEVEL: silly - LAGOON_LOCALDEV_HTTP_PORT: 3000 - LAGOON_ROUTE: http://thunderhub.docker.amazee.io - volumes: - - ./storage:/data:delegated - labels: - lagoon.type: basic-persistent - lagoon.persistent: /data - lagoon.persistent.name: lnd - lagoon.service.usecomposeports: true - ports: - - "3000" # exposes the port 3000 with a random local port, find it with `docker-compose port thunderhub 3000` - env_file: - - .env.local - - tor: - networks: - - amazeeio-network - - default - build: - context: tor - dockerfile: Dockerfile - user: '10000' - labels: - lagoon.type: basic - lagoon.service.usecomposeports: true - lagoon.autogeneratedroute: false - ports: - - "9050" - - "9051" - - # lit: - # networks: - # - amazeeio-network - # - default - # build: - # context: lit - # dockerfile: Dockerfile - # user: '10000' - # environment: - # LOG_LEVEL: silly - # LAGOON_LOCALDEV_HTTP_PORT: 8443 - # LAGOON_ROUTE: http://lit.docker.amazee.io - # volumes: - # - ./storage:/app/storage:delegated - # labels: - # lagoon.type: basic-persistent - # lagoon.persistent: /app/storage - # lagoon.persistent.name: lnd - # lagoon.autogeneratedroute: false - # lagoon.service.usecomposeports: true - # ports: - # - "8443" # exposes the port 3000 with a random local port, find it with `docker-compose port thunderhub 3000` - # env_file: - # - .env.local -networks: - amazeeio-network: - external: true diff --git a/test-resources/template-lagoon-services/test3/lagoon.yml b/test-resources/template-lagoon-services/test3/lagoon.yml deleted file mode 100644 index 31a423e0..00000000 --- a/test-resources/template-lagoon-services/test3/lagoon.yml +++ /dev/null @@ -1 +0,0 @@ -docker-compose-yaml: ../test-resources/template-lagoon-services/test3/docker-compose.yml diff --git a/test-resources/template-lagoon-services/test4-results/deployments.yaml b/test-resources/template-lagoon-services/test4-results/deployments.yaml deleted file mode 100644 index 935432ca..00000000 --- a/test-resources/template-lagoon-services/test4-results/deployments.yaml +++ /dev/null @@ -1,184 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: lnd - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: lnd - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: lnd -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: lnd - app.kubernetes.io/name: basic-persistent - 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: lnd - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: lnd - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/lnd:latest - livenessProbe: - initialDelaySeconds: 60 - tcpSocket: - port: 8080 - timeoutSeconds: 10 - name: basic - ports: - - containerPort: 8080 - name: tcp-8080 - protocol: TCP - - containerPort: 10009 - name: tcp-10009 - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 8080 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /app/storage - name: lnd - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 - volumes: - - name: lnd - persistentVolumeClaim: - claimName: lnd -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: tor - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: worker-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: tor - lagoon.sh/service-type: worker-persistent - lagoon.sh/template: worker-persistent-0.1.0 - name: tor -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: tor - app.kubernetes.io/name: worker-persistent - 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: tor - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: worker-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: tor - lagoon.sh/service-type: worker-persistent - lagoon.sh/template: worker-persistent-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/tor:latest - name: cli - ports: - - containerPort: 3000 - name: http - protocol: TCP - readinessProbe: - exec: - command: - - /bin/sh - - -c - - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; - fi - failureThreshold: 3 - initialDelaySeconds: 5 - periodSeconds: 2 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - mountPath: /data - name: lnd - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 - volumes: - - name: lnd - persistentVolumeClaim: - claimName: lnd -status: {} diff --git a/test-resources/template-lagoon-services/test4-results/pvcs.yaml b/test-resources/template-lagoon-services/test4-results/pvcs.yaml deleted file mode 100644 index f8377573..00000000 --- a/test-resources/template-lagoon-services/test4-results/pvcs.yaml +++ /dev/null @@ -1,30 +0,0 @@ ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - annotations: - k8up.io/backup: "true" - k8up.syn.tools/backup: "true" - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: lnd - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: lnd - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: lnd -spec: - accessModes: - - ReadWriteMany - resources: - requests: - storage: 5Gi - storageClassName: bulk -status: {} diff --git a/test-resources/template-lagoon-services/test4-results/services.yaml b/test-resources/template-lagoon-services/test4-results/services.yaml deleted file mode 100644 index c193ba18..00000000 --- a/test-resources/template-lagoon-services/test4-results/services.yaml +++ /dev/null @@ -1,35 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: lnd - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: lnd - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: lnd -spec: - ports: - - name: tcp-8080 - port: 8080 - protocol: TCP - targetPort: tcp-8080 - - name: tcp-10009 - port: 10009 - protocol: TCP - targetPort: tcp-10009 - selector: - app.kubernetes.io/instance: lnd - app.kubernetes.io/name: basic-persistent -status: - loadBalancer: {} diff --git a/test-resources/template-lagoon-services/test4/docker-compose.yml b/test-resources/template-lagoon-services/test4/docker-compose.yml deleted file mode 100644 index d8e39aaa..00000000 --- a/test-resources/template-lagoon-services/test4/docker-compose.yml +++ /dev/null @@ -1,41 +0,0 @@ -version: '2' -services: - lnd: - networks: - - amazeeio-network - - default - build: - context: . - dockerfile: Dockerfile - user: '10000' - labels: - lagoon.type: basic-persistent - lagoon.persistent: /app/storage - lagoon.service.usecomposeports: true - environment: - LAGOON_LOCALDEV_HTTP_PORT: 8080 - LAGOON_ROUTE: http://lnd.docker.amazee.io - volumes: - - ./storage:/app/storage:delegated - env_file: - - .env.local - ports: - - "8080" # exposes the port 8080 with a random local port, find it with `docker-compose port lnd 8080` - - "10009" # exposes the port 10009 with a random local port, find it with `docker-compose port lnd 10009` - - tor: - networks: - - amazeeio-network - - default - build: - context: tor - dockerfile: Dockerfile - user: '10000' - labels: - lagoon.type: worker-persistent - lagoon.persistent: /data - lagoon.persistent.name: lnd - -networks: - amazeeio-network: - external: true diff --git a/test-resources/template-lagoon-services/test4/lagoon.yml b/test-resources/template-lagoon-services/test4/lagoon.yml deleted file mode 100644 index 2b4f3290..00000000 --- a/test-resources/template-lagoon-services/test4/lagoon.yml +++ /dev/null @@ -1 +0,0 @@ -docker-compose-yaml: ../test-resources/template-lagoon-services/test4/docker-compose.yml From ef3f3f912d52ba97f26826a6e0d4403b88307658 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 9 Jan 2024 13:09:06 +1100 Subject: [PATCH 40/92] refactor: split service templates down individually --- cmd/template_lagoonservices.go | 57 ++- cmd/template_lagoonservices_test.go | 22 - internal/generator/buildvalues.go | 2 +- internal/generator/generator.go | 4 +- internal/servicetypes/basic.go | 18 +- internal/servicetypes/cli.go | 7 - internal/servicetypes/elasticsearch.go | 10 +- internal/servicetypes/mariadb.go | 10 +- internal/servicetypes/mongodb.go | 10 +- internal/servicetypes/nginx.go | 17 +- internal/servicetypes/node.go | 10 +- internal/servicetypes/opensearch.go | 10 +- internal/servicetypes/postgres.go | 18 +- internal/servicetypes/python.go | 10 +- internal/servicetypes/redis.go | 18 +- internal/servicetypes/solr.go | 18 +- internal/servicetypes/types.go | 2 +- internal/servicetypes/varnish.go | 15 +- internal/servicetypes/worker.go | 15 +- .../templating/services/templates_cronjob.go | 27 +- .../services/templates_cronjob_test.go | 15 +- .../services/templates_deployment.go | 44 +- .../services/templates_deployment_test.go | 19 +- internal/templating/services/templates_pvc.go | 48 +- .../templating/services/templates_pvc_test.go | 15 +- .../templating/services/templates_service.go | 56 ++- .../services/templates_service_test.go | 15 +- .../deployment/result-basic-1.yaml | 10 +- .../deployment/result-cli-1.yaml | 8 - .../deployment/result-solr-1.yaml | 2 +- .../service/result-basic-1.yaml | 16 +- ...{deployments.yaml => deployment-node.yaml} | 0 .../{services.yaml => service-node.yaml} | 0 .../service2/deployment-lnd.yaml | 92 ++++ .../service2/deployment-thunderhub.yaml | 89 ++++ .../service2/deployment-tor.yaml | 85 ++++ .../service2/deployments.yaml | 266 ----------- .../service2/{pvcs.yaml => pvc-lnd.yaml} | 0 .../service-lnd.yaml} | 0 .../service2/service-thunderhub.yaml | 31 ++ .../service2/service-tor.yaml | 35 ++ .../service-templates/service2/services.yaml | 101 ----- .../service3/deployment-lnd.yaml | 92 ++++ .../service3/deployment-tor.yaml | 88 ++++ .../service3/deployments.yaml | 184 -------- .../service3/{pvcs.yaml => pvc-lnd.yaml} | 0 .../service3/service-lnd.yaml | 35 ++ ...l => cronjob-cronjob-cli-drush-cron2.yaml} | 0 .../service1/deployment-cli.yaml | 94 ++++ .../service1/deployment-nginx-php.yaml | 124 ++++++ .../service1/deployment-redis.yaml | 78 ++++ .../service1/deployment-varnish.yaml | 81 ++++ .../service1/deployments.yaml | 381 ---------------- .../{pvcs.yaml => pvc-nginx-php.yaml} | 0 .../service1/service-nginx-php.yaml | 31 ++ .../service1/service-redis.yaml | 31 ++ .../service1/service-varnish.yaml | 35 ++ .../service-templates/service1/services.yaml | 97 ---- ...l => cronjob-cronjob-cli-drush-cron2.yaml} | 0 .../service2/deployment-cli.yaml | 98 +++++ .../service2/deployment-nginx-php.yaml | 145 ++++++ .../service2/deployment-redis.yaml | 82 ++++ .../service2/deployment-varnish.yaml | 85 ++++ .../service2/deployments.yaml | 414 ------------------ .../{pvcs.yaml => pvc-nginx-php.yaml} | 0 .../service2/service-nginx-php.yaml | 31 ++ .../service2/service-redis.yaml | 31 ++ .../service2/service-varnish.yaml | 35 ++ .../service-templates/service2/services.yaml | 97 ---- 69 files changed, 1829 insertions(+), 1787 deletions(-) rename internal/testdata/basic/service-templates/service1/{deployments.yaml => deployment-node.yaml} (100%) rename internal/testdata/basic/service-templates/service1/{services.yaml => service-node.yaml} (100%) create mode 100644 internal/testdata/basic/service-templates/service2/deployment-lnd.yaml create mode 100644 internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml create mode 100644 internal/testdata/basic/service-templates/service2/deployment-tor.yaml delete mode 100644 internal/testdata/basic/service-templates/service2/deployments.yaml rename internal/testdata/basic/service-templates/service2/{pvcs.yaml => pvc-lnd.yaml} (100%) rename internal/testdata/basic/service-templates/{service3/services.yaml => service2/service-lnd.yaml} (100%) create mode 100644 internal/testdata/basic/service-templates/service2/service-thunderhub.yaml create mode 100644 internal/testdata/basic/service-templates/service2/service-tor.yaml delete mode 100644 internal/testdata/basic/service-templates/service2/services.yaml create mode 100644 internal/testdata/basic/service-templates/service3/deployment-lnd.yaml create mode 100644 internal/testdata/basic/service-templates/service3/deployment-tor.yaml delete mode 100644 internal/testdata/basic/service-templates/service3/deployments.yaml rename internal/testdata/basic/service-templates/service3/{pvcs.yaml => pvc-lnd.yaml} (100%) create mode 100644 internal/testdata/basic/service-templates/service3/service-lnd.yaml rename internal/testdata/complex/service-templates/service1/{cronjobs.yaml => cronjob-cronjob-cli-drush-cron2.yaml} (100%) create mode 100644 internal/testdata/complex/service-templates/service1/deployment-cli.yaml create mode 100644 internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml create mode 100644 internal/testdata/complex/service-templates/service1/deployment-redis.yaml create mode 100644 internal/testdata/complex/service-templates/service1/deployment-varnish.yaml delete mode 100644 internal/testdata/complex/service-templates/service1/deployments.yaml rename internal/testdata/complex/service-templates/service1/{pvcs.yaml => pvc-nginx-php.yaml} (100%) create mode 100644 internal/testdata/complex/service-templates/service1/service-nginx-php.yaml create mode 100644 internal/testdata/complex/service-templates/service1/service-redis.yaml create mode 100644 internal/testdata/complex/service-templates/service1/service-varnish.yaml delete mode 100644 internal/testdata/complex/service-templates/service1/services.yaml rename internal/testdata/complex/service-templates/service2/{cronjobs.yaml => cronjob-cronjob-cli-drush-cron2.yaml} (100%) create mode 100644 internal/testdata/complex/service-templates/service2/deployment-cli.yaml create mode 100644 internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml create mode 100644 internal/testdata/complex/service-templates/service2/deployment-redis.yaml create mode 100644 internal/testdata/complex/service-templates/service2/deployment-varnish.yaml delete mode 100644 internal/testdata/complex/service-templates/service2/deployments.yaml rename internal/testdata/complex/service-templates/service2/{pvcs.yaml => pvc-nginx-php.yaml} (100%) create mode 100644 internal/testdata/complex/service-templates/service2/service-nginx-php.yaml create mode 100644 internal/testdata/complex/service-templates/service2/service-redis.yaml create mode 100644 internal/testdata/complex/service-templates/service2/service-varnish.yaml delete mode 100644 internal/testdata/complex/service-templates/service2/services.yaml diff --git a/cmd/template_lagoonservices.go b/cmd/template_lagoonservices.go index cefc6846..7039ef45 100644 --- a/cmd/template_lagoonservices.go +++ b/cmd/template_lagoonservices.go @@ -9,6 +9,7 @@ import ( generator "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating/services" + "sigs.k8s.io/yaml" ) var lagoonServiceGeneration = &cobra.Command{ @@ -48,39 +49,71 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { if g.Debug { fmt.Println(fmt.Sprintf("Templating service manifests %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "services"))) } - serviceTemplateYAML, err := servicestemplates.GenerateServiceTemplate(*lagoonBuild.BuildValues) + services, err := servicestemplates.GenerateServiceTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - if serviceTemplateYAML != nil { - helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "services"), serviceTemplateYAML) + if services != nil { + for _, d := range services { + serviceBytes, err := yaml.Marshal(d) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + separator := []byte("---\n") + restoreResult := append(separator[:], serviceBytes[:]...) + helpers.WriteTemplateFile(fmt.Sprintf("%s/service-%s.yaml", savedTemplates, d.Name), restoreResult) + } } if g.Debug { fmt.Println(fmt.Sprintf("Templating pvc manifests %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "pvcs"))) } - pvcTemplateYAML, err := servicestemplates.GeneratePVCTemplate(*lagoonBuild.BuildValues) + pvcs, err := servicestemplates.GeneratePVCTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - if pvcTemplateYAML != nil { - helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "pvcs"), pvcTemplateYAML) + if pvcs != nil { + for _, d := range pvcs { + serviceBytes, err := yaml.Marshal(d) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + separator := []byte("---\n") + restoreResult := append(separator[:], serviceBytes[:]...) + helpers.WriteTemplateFile(fmt.Sprintf("%s/pvc-%s.yaml", savedTemplates, d.Name), restoreResult) + } } if g.Debug { fmt.Println(fmt.Sprintf("Templating deployment manifest %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "deployments"))) } - deploymentTemplateYAML, err := servicestemplates.GenerateDeploymentTemplate(*lagoonBuild.BuildValues) + deployments, err := servicestemplates.GenerateDeploymentTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - if deploymentTemplateYAML != nil { - helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "deployments"), deploymentTemplateYAML) + if deployments != nil { + for _, d := range deployments { + deploymentBytes, err := yaml.Marshal(d) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + separator := []byte("---\n") + restoreResult := append(separator[:], deploymentBytes[:]...) + helpers.WriteTemplateFile(fmt.Sprintf("%s/deployment-%s.yaml", savedTemplates, d.Name), restoreResult) + } } - cronjobTemplateYaml, err := servicestemplates.GenerateCronjobTemplate(*lagoonBuild.BuildValues) + cronjobs, err := servicestemplates.GenerateCronjobTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - if cronjobTemplateYaml != nil { - helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "cronjobs"), cronjobTemplateYaml) + if cronjobs != nil { + for _, d := range cronjobs { + deploymentBytes, err := yaml.Marshal(d) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + separator := []byte("---\n") + restoreResult := append(separator[:], deploymentBytes[:]...) + helpers.WriteTemplateFile(fmt.Sprintf("%s/cronjob-%s.yaml", savedTemplates, d.Name), restoreResult) + } } return nil } diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index 49541d11..c985759a 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -138,28 +138,6 @@ func TestTemplateLagoonServices(t *testing.T) { { name: "test4 - basic-persistent with worker-persistent", description: "create a basic-persistent that gets a pvc and mount that volume on a worker-persistent type", - // args: args{ - // alertContact: "alertcontact", - // statusPageID: "statuspageid", - // projectName: "example-project", - // environmentName: "main", - // environmentType: "production", - // buildType: "branch", - // lagoonVersion: "v2.7.x", - // branch: "main", - // projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, - // envVars: `[]`, - // rootlessWorkloads: "enabled", - // lagoonYAML: "../test-resources/template-lagoon-services/test4/lagoon.yml", - // templatePath: "../test-resources/template-lagoon-services/output", - // configMapSha: "abcdefg1234567890", - // imageReferences: map[string]string{ - // "lnd": "harbor.example/example-project/main/lnd:latest", - // "tor": "harbor.example/example-project/main/tor:latest", - // }, - // }, - // templatePath: "testdata/output", - // want: "../test-resources/template-lagoon-services/test4-results", args2: testdata.GetSeedData( testdata.TestData{ ProjectName: "example-project", diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index c244e0da..f7f44324 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -56,7 +56,7 @@ type BuildValues struct { ImageReferences map[string]string `json:"imageReferences"` Resources Resources `json:"resources"` CronjobsDisabled bool `json:"cronjobsDisabled"` - Flags map[string]bool `json:"-"` + FeatureFlags map[string]bool `json:"-"` } type Resources struct { diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 421aa309..1ad0f939 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -66,7 +66,7 @@ func NewGenerator( // create some initial variables to be passed through the generators buildValues := BuildValues{} - buildValues.Flags = map[string]bool{} + buildValues.FeatureFlags = map[string]bool{} lYAML := &lagoon.YAML{} lagoonEnvVars := []lagoon.EnvironmentVariable{} autogenRoutes := &lagoon.RoutesV2{} @@ -222,7 +222,7 @@ func NewGenerator( // check for rootless workloads rootlessWorkloads := CheckFeatureFlag("ROOTLESS_WORKLOAD", lagoonEnvVars, generator.Debug) if rootlessWorkloads == "enabled" { - buildValues.Flags["rootlessworkloads"] = true + buildValues.FeatureFlags["rootlessworkloads"] = true buildValues.PodSecurityContext = PodSecurityContext{ RunAsGroup: 0, RunAsUser: 10000, diff --git a/internal/servicetypes/basic.go b/internal/servicetypes/basic.go index d9b49d35..149cac96 100644 --- a/internal/servicetypes/basic.go +++ b/internal/servicetypes/basic.go @@ -6,20 +6,22 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" ) +var defaultBasicPort int32 = 3000 + // defines all the basic service type defaults var basic = ServiceType{ Name: "basic", Ports: ServicePorts{ - CanChangePort: true, + CanChangePort: true, // this service has the ability to change its default port Ports: []corev1.ServicePort{ { - Port: 3000, + Port: defaultBasicPort, // this is the default port for basic service type TargetPort: intstr.IntOrString{ Type: intstr.String, - StrVal: "http", + StrVal: "basic", }, Protocol: corev1.ProtocolTCP, - Name: "http", + Name: "basic", }, }, }, @@ -29,8 +31,8 @@ var basic = ServiceType{ Container: corev1.Container{ Ports: []corev1.ContainerPort{ { - Name: "http", - ContainerPort: 3000, + Name: "basic", + ContainerPort: defaultBasicPort, Protocol: corev1.ProtocolTCP, }, }, @@ -39,7 +41,7 @@ var basic = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 3000, + IntVal: defaultBasicPort, }, }, }, @@ -51,7 +53,7 @@ var basic = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 3000, + IntVal: defaultBasicPort, }, }, }, diff --git a/internal/servicetypes/cli.go b/internal/servicetypes/cli.go index 7812a8b3..ba96f07d 100644 --- a/internal/servicetypes/cli.go +++ b/internal/servicetypes/cli.go @@ -31,13 +31,6 @@ var cli = ServiceType{ MountPath: "/var/run/secrets/lagoon/sshkey/", }, }, - Ports: []corev1.ContainerPort{ - { - Name: "http", - ContainerPort: 3000, - Protocol: corev1.ProtocolTCP, - }, - }, ReadinessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ Exec: &corev1.ExecAction{ diff --git a/internal/servicetypes/elasticsearch.go b/internal/servicetypes/elasticsearch.go index d9dc9bf8..5b1f7f2b 100644 --- a/internal/servicetypes/elasticsearch.go +++ b/internal/servicetypes/elasticsearch.go @@ -1,23 +1,27 @@ package servicetypes import ( + "fmt" + "github.com/uselagoon/build-deploy-tool/internal/helpers" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" ) +var defaultElasticsearchPort int32 = 9200 + var elasticsearch = ServiceType{ Name: "elasticsearch", Ports: ServicePorts{ Ports: []corev1.ServicePort{ { - Port: 9200, + Port: defaultElasticsearchPort, TargetPort: intstr.IntOrString{ Type: intstr.Int, - IntVal: 9200, + IntVal: defaultElasticsearchPort, }, Protocol: corev1.ProtocolTCP, - Name: "9200-tcp", + Name: fmt.Sprintf("%d-tcp", defaultElasticsearchPort), }, }, }, diff --git a/internal/servicetypes/mariadb.go b/internal/servicetypes/mariadb.go index 4d1cf3cd..6f2b933d 100644 --- a/internal/servicetypes/mariadb.go +++ b/internal/servicetypes/mariadb.go @@ -1,22 +1,26 @@ package servicetypes import ( + "fmt" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" ) +var defaultMariaDBPort int32 = 3306 + var mariadbSingle = ServiceType{ Name: "mariadb-single", Ports: ServicePorts{ Ports: []corev1.ServicePort{ { - Port: 3306, + Port: defaultMariaDBPort, TargetPort: intstr.IntOrString{ Type: intstr.Int, - IntVal: 3306, + IntVal: defaultMariaDBPort, }, Protocol: corev1.ProtocolTCP, - Name: "3306-tcp", + Name: fmt.Sprintf("%d-tcp", defaultMariaDBPort), }, }, }, diff --git a/internal/servicetypes/mongodb.go b/internal/servicetypes/mongodb.go index 3d7031b2..f1392a2a 100644 --- a/internal/servicetypes/mongodb.go +++ b/internal/servicetypes/mongodb.go @@ -1,22 +1,26 @@ package servicetypes import ( + "fmt" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" ) +var defaultMongoDBPort int32 = 27017 + var mongodbSingle = ServiceType{ Name: "mongodb-single", Ports: ServicePorts{ Ports: []corev1.ServicePort{ { - Port: 27017, + Port: defaultMongoDBPort, TargetPort: intstr.IntOrString{ Type: intstr.Int, - IntVal: 27017, + IntVal: defaultMongoDBPort, }, Protocol: corev1.ProtocolTCP, - Name: "27017-tcp", + Name: fmt.Sprintf("%d-tcp", defaultMongoDBPort), }, }, }, diff --git a/internal/servicetypes/nginx.go b/internal/servicetypes/nginx.go index 85cc2a96..326932cf 100644 --- a/internal/servicetypes/nginx.go +++ b/internal/servicetypes/nginx.go @@ -7,12 +7,15 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" ) +var defaultNginxPort int32 = 8080 +var defaultPHPPort int32 = 9000 + var nginx = ServiceType{ Name: "nginx", Ports: ServicePorts{ Ports: []corev1.ServicePort{ { - Port: 8080, + Port: defaultNginxPort, TargetPort: intstr.IntOrString{ Type: intstr.String, StrVal: "http", @@ -29,7 +32,7 @@ var nginx = ServiceType{ Ports: []corev1.ContainerPort{ { Name: "http", - ContainerPort: 8080, + ContainerPort: defaultNginxPort, Protocol: corev1.ProtocolTCP, }, }, @@ -80,7 +83,7 @@ var nginxPHP = ServiceType{ Ports: []corev1.ContainerPort{ { Name: "http", - ContainerPort: 8080, + ContainerPort: defaultNginxPort, Protocol: corev1.ProtocolTCP, }, }, @@ -132,7 +135,7 @@ var nginxPHP = ServiceType{ Ports: []corev1.ContainerPort{ { Name: "http", - ContainerPort: 9000, + ContainerPort: defaultPHPPort, Protocol: corev1.ProtocolTCP, }, }, @@ -141,7 +144,7 @@ var nginxPHP = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 9000, + IntVal: defaultPHPPort, }, }, }, @@ -153,7 +156,7 @@ var nginxPHP = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 9000, + IntVal: defaultPHPPort, }, }, }, @@ -186,7 +189,7 @@ var nginxPHPPersistent = ServiceType{ }, InitContainer: ServiceContainer{ Name: "fix-storage-permissions", - Flags: map[string]bool{ + FeatureFlags: map[string]bool{ "rootlessworkloads": true, }, Command: []string{ diff --git a/internal/servicetypes/node.go b/internal/servicetypes/node.go index 32052665..3dcc630b 100644 --- a/internal/servicetypes/node.go +++ b/internal/servicetypes/node.go @@ -6,12 +6,14 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" ) +var defaultNodePort int32 = 3000 + var node = ServiceType{ Name: "node", Ports: ServicePorts{ Ports: []corev1.ServicePort{ { - Port: 3000, + Port: defaultNodePort, TargetPort: intstr.IntOrString{ Type: intstr.String, StrVal: "http", @@ -28,7 +30,7 @@ var node = ServiceType{ Ports: []corev1.ContainerPort{ { Name: "http", - ContainerPort: 3000, + ContainerPort: defaultNodePort, Protocol: corev1.ProtocolTCP, }, }, @@ -37,7 +39,7 @@ var node = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 3000, + IntVal: defaultNodePort, }, }, }, @@ -49,7 +51,7 @@ var node = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 3000, + IntVal: defaultNodePort, }, }, }, diff --git a/internal/servicetypes/opensearch.go b/internal/servicetypes/opensearch.go index 4926f6bb..b70a508c 100644 --- a/internal/servicetypes/opensearch.go +++ b/internal/servicetypes/opensearch.go @@ -1,23 +1,27 @@ package servicetypes import ( + "fmt" + "github.com/uselagoon/build-deploy-tool/internal/helpers" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" ) +var defaultOpensearchPort int32 = 9200 + var opensearch = ServiceType{ Name: "opensearch", Ports: ServicePorts{ Ports: []corev1.ServicePort{ { - Port: 9200, + Port: defaultOpensearchPort, TargetPort: intstr.IntOrString{ Type: intstr.Int, - IntVal: 9200, + IntVal: defaultOpensearchPort, }, Protocol: corev1.ProtocolTCP, - Name: "9200-tcp", + Name: fmt.Sprintf("%d-tcp", defaultOpensearchPort), }, }, }, diff --git a/internal/servicetypes/postgres.go b/internal/servicetypes/postgres.go index 0515e856..f4657bbd 100644 --- a/internal/servicetypes/postgres.go +++ b/internal/servicetypes/postgres.go @@ -1,24 +1,28 @@ package servicetypes import ( + "fmt" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" ) +var defaultPostgresPort int32 = 5432 + var postgresSingle = ServiceType{ Name: "postgres-single", Ports: ServicePorts{ Ports: []corev1.ServicePort{ { - Port: 5432, + Port: defaultPostgresPort, TargetPort: intstr.IntOrString{ Type: intstr.Int, - IntVal: 5432, + IntVal: defaultPostgresPort, }, Protocol: corev1.ProtocolTCP, - Name: "5432-tcp", + Name: fmt.Sprintf("%d-tcp", defaultPostgresPort), }, }, }, @@ -28,8 +32,8 @@ var postgresSingle = ServiceType{ Container: corev1.Container{ Ports: []corev1.ContainerPort{ { - Name: "5432-tcp", - ContainerPort: 5432, + Name: fmt.Sprintf("%d-tcp", defaultPostgresPort), + ContainerPort: defaultPostgresPort, Protocol: corev1.ProtocolTCP, }, }, @@ -38,7 +42,7 @@ var postgresSingle = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 5432, + IntVal: defaultPostgresPort, }, }, }, @@ -50,7 +54,7 @@ var postgresSingle = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 5432, + IntVal: defaultPostgresPort, }, }, }, diff --git a/internal/servicetypes/python.go b/internal/servicetypes/python.go index fb0a524b..d3c9ca4b 100644 --- a/internal/servicetypes/python.go +++ b/internal/servicetypes/python.go @@ -6,12 +6,14 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" ) +var defaultPythonPort int32 = 8800 + var python = ServiceType{ Name: "python", Ports: ServicePorts{ Ports: []corev1.ServicePort{ { - Port: 8800, + Port: defaultPythonPort, TargetPort: intstr.IntOrString{ Type: intstr.String, StrVal: "http", @@ -28,7 +30,7 @@ var python = ServiceType{ Ports: []corev1.ContainerPort{ { Name: "http", - ContainerPort: 8800, + ContainerPort: defaultPythonPort, Protocol: corev1.ProtocolTCP, }, }, @@ -37,7 +39,7 @@ var python = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 8800, + IntVal: defaultPythonPort, }, }, }, @@ -49,7 +51,7 @@ var python = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 3000, + IntVal: defaultPythonPort, }, }, }, diff --git a/internal/servicetypes/redis.go b/internal/servicetypes/redis.go index 3d1395a5..c85ecb39 100644 --- a/internal/servicetypes/redis.go +++ b/internal/servicetypes/redis.go @@ -1,23 +1,27 @@ package servicetypes import ( + "fmt" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" ) +var defaultRedisPort int32 = 6379 + var redis = ServiceType{ Name: "redis", Ports: ServicePorts{ Ports: []corev1.ServicePort{ { - Port: 6379, + Port: defaultRedisPort, TargetPort: intstr.IntOrString{ Type: intstr.Int, - IntVal: 6379, + IntVal: defaultRedisPort, }, Protocol: corev1.ProtocolTCP, - Name: "6379-tcp", + Name: fmt.Sprintf("%d-tcp", defaultRedisPort), }, }, }, @@ -27,8 +31,8 @@ var redis = ServiceType{ Container: corev1.Container{ Ports: []corev1.ContainerPort{ { - Name: "6379-tcp", - ContainerPort: 6379, + Name: fmt.Sprintf("%d-tcp", defaultRedisPort), + ContainerPort: defaultRedisPort, Protocol: corev1.ProtocolTCP, }, }, @@ -37,7 +41,7 @@ var redis = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 6379, + IntVal: defaultRedisPort, }, }, }, @@ -49,7 +53,7 @@ var redis = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 6379, + IntVal: defaultRedisPort, }, }, }, diff --git a/internal/servicetypes/solr.go b/internal/servicetypes/solr.go index 6be63aff..93d87fe0 100644 --- a/internal/servicetypes/solr.go +++ b/internal/servicetypes/solr.go @@ -1,23 +1,27 @@ package servicetypes import ( + "fmt" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" ) +var defaultSolrPort int32 = 8983 + var solr = ServiceType{ Name: "solr-php-persistent", // this has to be like this because it is used in selectors, and is unchangeable now on existing deployed solr Ports: ServicePorts{ Ports: []corev1.ServicePort{ { - Port: 8983, + Port: defaultSolrPort, TargetPort: intstr.IntOrString{ Type: intstr.Int, - IntVal: 8983, + IntVal: defaultSolrPort, }, Protocol: corev1.ProtocolTCP, - Name: "tcp-8983", + Name: fmt.Sprintf("%d-tcp", defaultSolrPort), }, }, }, @@ -27,8 +31,8 @@ var solr = ServiceType{ Container: corev1.Container{ Ports: []corev1.ContainerPort{ { - Name: "tcp-8983", - ContainerPort: 8983, + Name: fmt.Sprintf("%d-tcp", defaultSolrPort), + ContainerPort: defaultSolrPort, Protocol: corev1.ProtocolTCP, }, }, @@ -37,7 +41,7 @@ var solr = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 8983, + IntVal: defaultSolrPort, }, }, }, @@ -49,7 +53,7 @@ var solr = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 8983, + IntVal: defaultSolrPort, }, }, }, diff --git a/internal/servicetypes/types.go b/internal/servicetypes/types.go index de49d8bd..946f7cd9 100644 --- a/internal/servicetypes/types.go +++ b/internal/servicetypes/types.go @@ -29,7 +29,7 @@ type ServiceContainer struct { Volumes []corev1.Volume VolumeMounts []corev1.VolumeMount Command []string - Flags map[string]bool + FeatureFlags map[string]bool } type ServiceVolume struct { diff --git a/internal/servicetypes/varnish.go b/internal/servicetypes/varnish.go index 4957ce21..2d479581 100644 --- a/internal/servicetypes/varnish.go +++ b/internal/servicetypes/varnish.go @@ -6,13 +6,16 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" ) +var defaultVarnishPort int32 = 8080 +var defaultVarnishControlPort int32 = 6082 + var varnish = ServiceType{ Name: "varnish", Ports: ServicePorts{ CanChangePort: true, Ports: []corev1.ServicePort{ { - Port: 8080, + Port: defaultVarnishPort, TargetPort: intstr.IntOrString{ Type: intstr.String, StrVal: "http", @@ -21,7 +24,7 @@ var varnish = ServiceType{ Name: "http", }, { - Port: 6082, + Port: defaultVarnishControlPort, TargetPort: intstr.IntOrString{ Type: intstr.String, StrVal: "controlport", @@ -38,12 +41,12 @@ var varnish = ServiceType{ Ports: []corev1.ContainerPort{ { Name: "http", - ContainerPort: 8080, + ContainerPort: defaultVarnishPort, Protocol: corev1.ProtocolTCP, }, { Name: "controlport", - ContainerPort: 6082, + ContainerPort: defaultVarnishControlPort, Protocol: corev1.ProtocolTCP, }, }, @@ -52,7 +55,7 @@ var varnish = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 8080, + IntVal: defaultVarnishPort, }, }, }, @@ -64,7 +67,7 @@ var varnish = ServiceType{ TCPSocket: &corev1.TCPSocketAction{ Port: intstr.IntOrString{ Type: intstr.Int, - IntVal: 8080, + IntVal: defaultVarnishPort, }, }, }, diff --git a/internal/servicetypes/worker.go b/internal/servicetypes/worker.go index 93ce7976..cd613d75 100644 --- a/internal/servicetypes/worker.go +++ b/internal/servicetypes/worker.go @@ -5,6 +5,8 @@ import ( "k8s.io/apimachinery/pkg/api/resource" ) +var defaultWorkerPort int32 = 3000 + var worker = ServiceType{ Name: "worker", PrimaryContainer: ServiceContainer{ @@ -25,6 +27,13 @@ var worker = ServiceType{ PeriodSeconds: 2, FailureThreshold: 3, }, + VolumeMounts: []corev1.VolumeMount{ + { + Name: "lagoon-sshkey", + ReadOnly: true, + MountPath: "/var/run/secrets/lagoon/sshkey/", + }, + }, Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), @@ -38,8 +47,8 @@ var worker = ServiceType{ var workerPersistent = ServiceType{ Name: "worker-persistent", PrimaryContainer: ServiceContainer{ - Name: cli.PrimaryContainer.Name, - ImagePullPolicy: cli.PrimaryContainer.ImagePullPolicy, - Container: cli.PrimaryContainer.Container, + Name: worker.PrimaryContainer.Name, + ImagePullPolicy: worker.PrimaryContainer.ImagePullPolicy, + Container: worker.PrimaryContainer.Container, }, } diff --git a/internal/templating/services/templates_cronjob.go b/internal/templating/services/templates_cronjob.go index 161cd99b..b43b99ec 100644 --- a/internal/templating/services/templates_cronjob.go +++ b/internal/templating/services/templates_cronjob.go @@ -12,15 +12,13 @@ import ( apivalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" - "sigs.k8s.io/yaml" ) // GenerateCronjobTemplate generates the lagoon template to apply. func GenerateCronjobTemplate( buildValues generator.BuildValues, -) ([]byte, error) { - separator := []byte("---\n") - var result []byte +) ([]batchv1.CronJob, error) { + var result []batchv1.CronJob // check linked services checkedServices := LinkedServiceCalculator(buildValues.Services) @@ -33,8 +31,6 @@ func GenerateCronjobTemplate( serviceTypeValues := &servicetypes.ServiceType{} helpers.DeepCopy(val, serviceTypeValues) - var cronjobBytes []byte - // add the default labels labels := map[string]string{ "app.kubernetes.io/managed-by": "build-deploy-tool", @@ -266,13 +262,13 @@ func GenerateCronjobTemplate( enableInit := false init := serviceTypeValues.InitContainer // check if the init container has any flags required to add it - for k, v := range buildValues.Flags { - if init.Flags[k] == v { + for k, v := range buildValues.FeatureFlags { + if init.FeatureFlags[k] == v { enableInit = true } } // otherwise if there are no flags - if enableInit || init.Flags == nil { + if enableInit || init.FeatureFlags == nil { for _, svm := range serviceTypeValues.InitContainer.VolumeMounts { volumeMount := corev1.VolumeMount{} helpers.TemplateThings(serviceValues, svm, &volumeMount) @@ -396,18 +392,7 @@ func GenerateCronjobTemplate( cronjob.Spec.JobTemplate.Spec.Template.Spec.Containers = append(cronjob.Spec.JobTemplate.Spec.Template.Spec.Containers, container.Container) // end cronjob template - - cronjobBytes, err = yaml.Marshal(cronjob) - if err != nil { - return nil, err - } - - // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) - // add the seperator to the template so that it can be `kubectl apply` in bulk as part - // of the current build process - // join all dbaas-consumer templates together - restoreResult := append(separator[:], cronjobBytes[:]...) - result = append(result, restoreResult[:]...) + result = append(result, *cronjob) } } } diff --git a/internal/templating/services/templates_cronjob_test.go b/internal/templating/services/templates_cronjob_test.go index af0e2b7f..8be07cad 100644 --- a/internal/templating/services/templates_cronjob_test.go +++ b/internal/templating/services/templates_cronjob_test.go @@ -8,6 +8,7 @@ import ( "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/lagoon" + "sigs.k8s.io/yaml" ) func TestGenerateCronjobTemplate(t *testing.T) { @@ -95,8 +96,18 @@ func TestGenerateCronjobTemplate(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", tt.want, err) } - if !reflect.DeepEqual(string(got), string(r1)) { - t.Errorf("GenerateCronjobTemplate() = \n%v", diff.LineDiff(string(r1), string(got))) + separator := []byte("---\n") + var result []byte + for _, d := range got { + deploymentBytes, err := yaml.Marshal(d) + if err != nil { + t.Errorf("couldn't generate template %v", err) + } + restoreResult := append(separator[:], deploymentBytes[:]...) + result = append(result, restoreResult[:]...) + } + if !reflect.DeepEqual(string(result), string(r1)) { + t.Errorf("GenerateCronjobTemplate() = \n%v", diff.LineDiff(string(r1), string(result))) } }) } diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index d9f9380d..a2dd5a3c 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -14,15 +14,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" "k8s.io/apimachinery/pkg/util/intstr" - "sigs.k8s.io/yaml" ) // GenerateDeploymentTemplate generates the lagoon template to apply. func GenerateDeploymentTemplate( buildValues generator.BuildValues, -) ([]byte, error) { - separator := []byte("---\n") - var result []byte +) ([]appsv1.Deployment, error) { + var deployments []appsv1.Deployment // check linked services checkedServices := LinkedServiceCalculator(buildValues.Services) @@ -34,8 +32,6 @@ func GenerateDeploymentTemplate( serviceTypeValues := &servicetypes.ServiceType{} helpers.DeepCopy(val, serviceTypeValues) - var deploymentBytes []byte - // add the default labels labels := map[string]string{ "app.kubernetes.io/managed-by": "build-deploy-tool", @@ -75,6 +71,7 @@ func GenerateDeploymentTemplate( templateAnnotations["k8up.syn.tools/file-extension"] = bc.FileExtension } + // create the initial deployment spec deployment := &appsv1.Deployment{ TypeMeta: metav1.TypeMeta{ Kind: "Deployment", @@ -170,7 +167,7 @@ func GenerateDeploymentTemplate( } deployment.Spec.Replicas = helpers.Int32Ptr(1) if serviceValues.Replicas != 0 { - deployment.Spec.Replicas = &serviceValues.Replicas + deployment.Spec.Replicas = helpers.Int32Ptr(serviceValues.Replicas) } deployment.Spec.Selector = &metav1.LabelSelector{ MatchLabels: map[string]string{ @@ -270,13 +267,14 @@ func GenerateDeploymentTemplate( enableInit := false init := serviceTypeValues.InitContainer // check if the init container has any flags required to add it - for k, v := range buildValues.Flags { - if init.Flags[k] == v { + for k, v := range buildValues.FeatureFlags { + if init.FeatureFlags[k] == v { enableInit = true } } // otherwise if there are no flags - if enableInit || init.Flags == nil { + if enableInit || init.FeatureFlags == nil { + // add any volume mounts to the init container as required for _, svm := range serviceTypeValues.InitContainer.VolumeMounts { volumeMount := corev1.VolumeMount{} helpers.TemplateThings(serviceValues, svm, &volumeMount) @@ -289,7 +287,7 @@ func GenerateDeploymentTemplate( cmd = append(cmd, c2) } init.Container.Command = cmd - // init containers contain will more than likely contain public images, we should add a provided pull through imagecache if one is defined + // init containers will more than likely contain public images, we should add a provided pull through imagecache if one is defined if buildValues.ImageCache != "" { init.Container.Image = fmt.Sprintf("%s%s", buildValues.ImageCache, init.Container.Image) } @@ -299,7 +297,8 @@ func GenerateDeploymentTemplate( // handle the primary container for the service type container := serviceTypeValues.PrimaryContainer - // if the service is set to consume the additional service ports only, then generate those here + // if the service is set to consume the additional service ports from the docker-compose file (lagoon.sh/usecomposeports label on service) + // then generate those additional service ports in the deploymeny here if serviceValues.AdditionalServicePorts != nil { // nulify the existing ports container.Container.Ports = []corev1.ContainerPort{} @@ -382,9 +381,11 @@ func GenerateDeploymentTemplate( Value: cronjobs, }, } + // expose any container envvars as required here for _, envvar := range envvars { container.Container.Env = append(container.Container.Env, envvar) } + // consume the lagoon-env configmap here container.Container.EnvFrom = []corev1.EnvFromSource{ { ConfigMapRef: &corev1.ConfigMapEnvSource{ @@ -404,6 +405,7 @@ func GenerateDeploymentTemplate( } container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) } + // handle the default storage volumemount if serviceTypeValues.Volumes.PersistentVolumeSize != "" { volumeMount := corev1.VolumeMount{ Name: serviceValues.PersistentVolumeName, @@ -416,11 +418,13 @@ func GenerateDeploymentTemplate( } container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) } + // create the container volume mounts for _, svm := range serviceTypeValues.PrimaryContainer.VolumeMounts { volumeMount := corev1.VolumeMount{} helpers.TemplateThings(serviceValues, svm, &volumeMount) container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) } + // mount the default storage volume if one exists if serviceValues.PersistentVolumeName != "" && serviceValues.PersistentVolumePath != "" && serviceTypeValues.Volumes.PersistentVolumeSize == "" { container.Container.VolumeMounts = append(container.Container.VolumeMounts, corev1.VolumeMount{ Name: serviceValues.PersistentVolumeName, @@ -437,6 +441,7 @@ func GenerateDeploymentTemplate( deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, volume) } + // set the resource limit overrides if htey are provided if buildValues.Resources.Limits.Memory != "" { if container.Container.Resources.Limits == nil { container.Container.Resources.Limits = corev1.ResourceList{} @@ -515,19 +520,8 @@ func GenerateDeploymentTemplate( } // end deployment template - - deploymentBytes, err = yaml.Marshal(deployment) - if err != nil { - return nil, err - } - - // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) - // add the seperator to the template so that it can be `kubectl apply` in bulk as part - // of the current build process - // join all dbaas-consumer templates together - restoreResult := append(separator[:], deploymentBytes[:]...) - result = append(result, restoreResult[:]...) + deployments = append(deployments, *deployment) } } - return result, nil + return deployments, nil } diff --git a/internal/templating/services/templates_deployment_test.go b/internal/templating/services/templates_deployment_test.go index 48fa58ab..4b21f480 100644 --- a/internal/templating/services/templates_deployment_test.go +++ b/internal/templating/services/templates_deployment_test.go @@ -10,6 +10,7 @@ import ( "github.com/compose-spec/compose-go/types" "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/lagoon" + "sigs.k8s.io/yaml" ) func TestGenerateDeploymentTemplate(t *testing.T) { @@ -130,7 +131,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { Name: "lagoon-internal-registry-secret", }, }, - Flags: map[string]bool{ + FeatureFlags: map[string]bool{ "rootlessworkloads": true, }, PodSecurityContext: generator.PodSecurityContext{ @@ -469,7 +470,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { }, }, ImageCache: "imagecache.example.com/", - Flags: map[string]bool{ + FeatureFlags: map[string]bool{ "rootlessworkloads": true, }, PodSecurityContext: generator.PodSecurityContext{ @@ -531,8 +532,18 @@ func TestGenerateDeploymentTemplate(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", tt.want, err) } - if !reflect.DeepEqual(string(got), string(r1)) { - t.Errorf("GenerateDeploymentTemplate() = \n%v", diff.LineDiff(string(r1), string(got))) + separator := []byte("---\n") + var result []byte + for _, d := range got { + deploymentBytes, err := yaml.Marshal(d) + if err != nil { + t.Errorf("couldn't generate template %v", err) + } + restoreResult := append(separator[:], deploymentBytes[:]...) + result = append(result, restoreResult[:]...) + } + if !reflect.DeepEqual(string(result), string(r1)) { + t.Errorf("GenerateDeploymentTemplate() = \n%v", diff.LineDiff(string(r1), string(result))) } }) } diff --git a/internal/templating/services/templates_pvc.go b/internal/templating/services/templates_pvc.go index 104d66b1..7eb5c51e 100644 --- a/internal/templating/services/templates_pvc.go +++ b/internal/templating/services/templates_pvc.go @@ -12,15 +12,13 @@ import ( apivalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" - "sigs.k8s.io/yaml" ) // GeneratePVCTemplate generates the lagoon template to apply. func GeneratePVCTemplate( buildValues generator.BuildValues, -) ([]byte, error) { - separator := []byte("---\n") - var result []byte +) ([]corev1.PersistentVolumeClaim, error) { + var result []corev1.PersistentVolumeClaim // add the default labels labels := map[string]string{ @@ -37,15 +35,12 @@ func GeneratePVCTemplate( } // add any additional labels - additionalLabels := map[string]string{} - additionalAnnotations := map[string]string{} if buildValues.BuildType == "branch" { - additionalAnnotations["lagoon.sh/branch"] = buildValues.Branch + annotations["lagoon.sh/branch"] = buildValues.Branch } else if buildValues.BuildType == "pullrequest" { - additionalAnnotations["lagoon.sh/prNumber"] = buildValues.PRNumber - additionalAnnotations["lagoon.sh/prHeadBranch"] = buildValues.PRHeadBranch - additionalAnnotations["lagoon.sh/prBaseBranch"] = buildValues.PRBaseBranch - + annotations["lagoon.sh/prNumber"] = buildValues.PRNumber + annotations["lagoon.sh/prHeadBranch"] = buildValues.PRHeadBranch + annotations["lagoon.sh/prBaseBranch"] = buildValues.PRBaseBranch } // check linked services @@ -73,7 +68,9 @@ func GeneratePVCTemplate( serviceType := &servicetypes.ServiceType{} helpers.DeepCopy(val, serviceType) - var pvcBytes []byte + additionalLabels := map[string]string{} + additionalAnnotations := map[string]string{} + additionalLabels["app.kubernetes.io/name"] = serviceType.Name additionalLabels["app.kubernetes.io/instance"] = serviceValues.OverrideName additionalLabels["lagoon.sh/template"] = fmt.Sprintf("%s-%s", serviceType.Name, "0.1.0") @@ -92,15 +89,21 @@ func GeneratePVCTemplate( Name: serviceValues.OverrideName, }, } - pvc.ObjectMeta.Labels = labels - pvc.ObjectMeta.Annotations = annotations + + labelsCopy := &map[string]string{} + helpers.DeepCopy(labels, labelsCopy) + annotationsCopy := &map[string]string{} + helpers.DeepCopy(annotations, annotationsCopy) + for key, value := range additionalLabels { - pvc.ObjectMeta.Labels[key] = value + (*labelsCopy)[key] = value } // add any additional annotations for key, value := range additionalAnnotations { - pvc.ObjectMeta.Annotations[key] = value + (*annotationsCopy)[key] = value } + pvc.ObjectMeta.Labels = *labelsCopy + pvc.ObjectMeta.Annotations = *annotationsCopy // validate any annotations if err := apivalidation.ValidateAnnotations(pvc.ObjectMeta.Annotations, nil); err != nil { if len(err) != 0 { @@ -139,18 +142,7 @@ func GeneratePVCTemplate( pvc.Spec.StorageClassName = helpers.StrPtr("bulk") } // end PVC template - - pvcBytes, err = yaml.Marshal(pvc) - if err != nil { - return nil, err - } - - // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) - // add the seperator to the template so that it can be `kubectl apply` in bulk as part - // of the current build process - // join all dbaas-consumer templates together - restoreResult := append(separator[:], pvcBytes[:]...) - result = append(result, restoreResult[:]...) + result = append(result, *pvc) } } } diff --git a/internal/templating/services/templates_pvc_test.go b/internal/templating/services/templates_pvc_test.go index 4e94f330..1ed01abc 100644 --- a/internal/templating/services/templates_pvc_test.go +++ b/internal/templating/services/templates_pvc_test.go @@ -7,6 +7,7 @@ import ( "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/generator" + "sigs.k8s.io/yaml" ) func TestGeneratePVCTemplate(t *testing.T) { @@ -199,8 +200,18 @@ func TestGeneratePVCTemplate(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", tt.want, err) } - if !reflect.DeepEqual(string(got), string(r1)) { - t.Errorf("GeneratePVCTemplate() = \n%v", diff.LineDiff(string(r1), string(got))) + separator := []byte("---\n") + var result []byte + for _, d := range got { + deploymentBytes, err := yaml.Marshal(d) + if err != nil { + t.Errorf("couldn't generate template %v", err) + } + restoreResult := append(separator[:], deploymentBytes[:]...) + result = append(result, restoreResult[:]...) + } + if !reflect.DeepEqual(string(result), string(r1)) { + t.Errorf("GeneratePVCTemplate() = \n%v", diff.LineDiff(string(r1), string(result))) } }) } diff --git a/internal/templating/services/templates_service.go b/internal/templating/services/templates_service.go index b70f8c91..d76fd6ae 100644 --- a/internal/templating/services/templates_service.go +++ b/internal/templating/services/templates_service.go @@ -12,7 +12,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" "k8s.io/apimachinery/pkg/util/intstr" - "sigs.k8s.io/yaml" ) var separator = []byte("---\n") @@ -20,10 +19,8 @@ var separator = []byte("---\n") // GenerateServiceTemplate generates the lagoon template to apply. func GenerateServiceTemplate( buildValues generator.BuildValues, -) ([]byte, error) { - - var result []byte - +) ([]corev1.Service, error) { + var services []corev1.Service // add the default labels labels := map[string]string{ "app.kubernetes.io/managed-by": "build-deploy-tool", @@ -39,14 +36,12 @@ func GenerateServiceTemplate( } // add any additional labels - additionalLabels := map[string]string{} - additionalAnnotations := map[string]string{} if buildValues.BuildType == "branch" { - additionalAnnotations["lagoon.sh/branch"] = buildValues.Branch + annotations["lagoon.sh/branch"] = buildValues.Branch } else if buildValues.BuildType == "pullrequest" { - additionalAnnotations["lagoon.sh/prNumber"] = buildValues.PRNumber - additionalAnnotations["lagoon.sh/prHeadBranch"] = buildValues.PRHeadBranch - additionalAnnotations["lagoon.sh/prBaseBranch"] = buildValues.PRBaseBranch + annotations["lagoon.sh/prNumber"] = buildValues.PRNumber + annotations["lagoon.sh/prHeadBranch"] = buildValues.PRHeadBranch + annotations["lagoon.sh/prBaseBranch"] = buildValues.PRBaseBranch } @@ -59,23 +54,26 @@ func GenerateServiceTemplate( if val, ok := servicetypes.ServiceTypes[serviceValues.Type]; ok { serviceType := &servicetypes.ServiceType{} helpers.DeepCopy(val, serviceType) - restoreResult, err := GenerateService(result, serviceType, serviceValues, labels, annotations, additionalLabels, additionalAnnotations) + service, err := GenerateService(serviceType, serviceValues, labels, annotations) if err != nil { return nil, err } - result = append(result, restoreResult[:]...) + if service != nil { + services = append(services, *service) + } } } - return result, nil + return services, nil } -func GenerateService(result []byte, serviceType *servicetypes.ServiceType, serviceValues generator.ServiceValues, labels, annotations, additionalLabels, additionalAnnotations map[string]string) ([]byte, error) { +func GenerateService(serviceType *servicetypes.ServiceType, serviceValues generator.ServiceValues, labels, annotations map[string]string) (*corev1.Service, error) { if serviceValues.AdditionalServicePorts == nil && serviceType.Ports.Ports == nil { // there are no additional ports provided, and this servicetype has no default ports associated to it // just drop out return nil, nil } - var serviceBytes []byte + additionalLabels := map[string]string{} + additionalAnnotations := map[string]string{} additionalLabels["app.kubernetes.io/name"] = serviceType.Name additionalLabels["app.kubernetes.io/instance"] = serviceValues.OverrideName @@ -91,15 +89,21 @@ func GenerateService(result []byte, serviceType *servicetypes.ServiceType, servi Name: serviceValues.OverrideName, }, } - service.ObjectMeta.Labels = labels - service.ObjectMeta.Annotations = annotations + + labelsCopy := &map[string]string{} + helpers.DeepCopy(labels, labelsCopy) + annotationsCopy := &map[string]string{} + helpers.DeepCopy(annotations, annotationsCopy) + for key, value := range additionalLabels { - service.ObjectMeta.Labels[key] = value + (*labelsCopy)[key] = value } // add any additional annotations for key, value := range additionalAnnotations { - service.ObjectMeta.Annotations[key] = value + (*annotationsCopy)[key] = value } + service.ObjectMeta.Labels = *labelsCopy + service.ObjectMeta.Annotations = *annotationsCopy // validate any annotations if err := apivalidation.ValidateAnnotations(service.ObjectMeta.Annotations, nil); err != nil { if len(err) != 0 { @@ -164,17 +168,7 @@ func GenerateService(result []byte, serviceType *servicetypes.ServiceType, servi "app.kubernetes.io/instance": serviceValues.OverrideName, } // end service template - - serviceBytes, err = yaml.Marshal(service) - if err != nil { - return nil, err - } - // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) - // add the seperator to the template so that it can be `kubectl apply` in bulk as part - // of the current build process - // join all dbaas-consumer templates together - restoreResult := append(separator[:], serviceBytes[:]...) - return restoreResult, nil + return service, nil } func GenerateServiceBackendPort(addPort generator.AdditionalServicePort) networkv1.ServiceBackendPort { diff --git a/internal/templating/services/templates_service_test.go b/internal/templating/services/templates_service_test.go index b6b00137..1dad3d26 100644 --- a/internal/templating/services/templates_service_test.go +++ b/internal/templating/services/templates_service_test.go @@ -8,6 +8,7 @@ import ( "github.com/andreyvit/diff" "github.com/compose-spec/compose-go/types" "github.com/uselagoon/build-deploy-tool/internal/generator" + "sigs.k8s.io/yaml" ) func TestGenerateServiceTemplate(t *testing.T) { @@ -255,8 +256,18 @@ func TestGenerateServiceTemplate(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", tt.want, err) } - if !reflect.DeepEqual(string(got), string(r1)) { - t.Errorf("GenerateServiceTemplate() = \n%v", diff.LineDiff(string(r1), string(got))) + separator := []byte("---\n") + var result []byte + for _, d := range got { + sBytes, err := yaml.Marshal(d) + if err != nil { + t.Errorf("couldn't generate template %v", err) + } + restoreResult := append(separator[:], sBytes[:]...) + result = append(result, restoreResult[:]...) + } + if !reflect.DeepEqual(string(result), string(r1)) { + t.Errorf("GenerateServiceTemplate() = \n%v", diff.LineDiff(string(r1), string(result))) } }) } diff --git a/internal/templating/services/test-resources/deployment/result-basic-1.yaml b/internal/templating/services/test-resources/deployment/result-basic-1.yaml index dda8846e..c0979386 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-1.yaml @@ -64,7 +64,7 @@ spec: name: basic ports: - containerPort: 3000 - name: http + name: basic protocol: TCP readinessProbe: initialDelaySeconds: 1 @@ -153,7 +153,7 @@ spec: name: basic ports: - containerPort: 8080 - name: http + name: basic protocol: TCP readinessProbe: initialDelaySeconds: 1 @@ -238,7 +238,7 @@ spec: name: basic ports: - containerPort: 3000 - name: http + name: basic protocol: TCP readinessProbe: initialDelaySeconds: 1 @@ -323,7 +323,7 @@ spec: name: basic ports: - containerPort: 8080 - name: http + name: basic protocol: TCP readinessProbe: initialDelaySeconds: 1 @@ -408,7 +408,7 @@ spec: name: basic ports: - containerPort: 8080 - name: http + name: basic protocol: TCP readinessProbe: initialDelaySeconds: 1 diff --git a/internal/templating/services/test-resources/deployment/result-cli-1.yaml b/internal/templating/services/test-resources/deployment/result-cli-1.yaml index 108ab2d4..cbb22958 100644 --- a/internal/templating/services/test-resources/deployment/result-cli-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-cli-1.yaml @@ -54,10 +54,6 @@ spec: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice@latest name: cli - ports: - - containerPort: 3000 - name: http - protocol: TCP readinessProbe: exec: command: @@ -142,10 +138,6 @@ spec: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice-persistent@latest name: cli - ports: - - containerPort: 3000 - name: http - protocol: TCP readinessProbe: exec: command: diff --git a/internal/templating/services/test-resources/deployment/result-solr-1.yaml b/internal/templating/services/test-resources/deployment/result-solr-1.yaml index e1b870f4..6fb57ab1 100644 --- a/internal/templating/services/test-resources/deployment/result-solr-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-solr-1.yaml @@ -63,7 +63,7 @@ spec: name: solr ports: - containerPort: 8983 - name: tcp-8983 + name: 8983-tcp protocol: TCP readinessProbe: initialDelaySeconds: 1 diff --git a/internal/templating/services/test-resources/service/result-basic-1.yaml b/internal/templating/services/test-resources/service/result-basic-1.yaml index 5d37a453..19e0ae6e 100644 --- a/internal/templating/services/test-resources/service/result-basic-1.yaml +++ b/internal/templating/services/test-resources/service/result-basic-1.yaml @@ -20,10 +20,10 @@ metadata: name: myservice spec: ports: - - name: http + - name: basic port: 3000 protocol: TCP - targetPort: http + targetPort: basic selector: app.kubernetes.io/instance: myservice app.kubernetes.io/name: basic @@ -51,10 +51,10 @@ metadata: name: myservice-po spec: ports: - - name: http + - name: basic port: 8080 protocol: TCP - targetPort: http + targetPort: basic selector: app.kubernetes.io/instance: myservice-po app.kubernetes.io/name: basic @@ -82,10 +82,10 @@ metadata: name: myservice-persist spec: ports: - - name: http + - name: basic port: 3000 protocol: TCP - targetPort: http + targetPort: basic selector: app.kubernetes.io/instance: myservice-persist app.kubernetes.io/name: basic-persistent @@ -113,10 +113,10 @@ metadata: name: myservice-persist-po spec: ports: - - name: http + - name: basic port: 8080 protocol: TCP - targetPort: http + targetPort: basic selector: app.kubernetes.io/instance: myservice-persist-po app.kubernetes.io/name: basic-persistent diff --git a/internal/testdata/basic/service-templates/service1/deployments.yaml b/internal/testdata/basic/service-templates/service1/deployment-node.yaml similarity index 100% rename from internal/testdata/basic/service-templates/service1/deployments.yaml rename to internal/testdata/basic/service-templates/service1/deployment-node.yaml diff --git a/internal/testdata/basic/service-templates/service1/services.yaml b/internal/testdata/basic/service-templates/service1/service-node.yaml similarity index 100% rename from internal/testdata/basic/service-templates/service1/services.yaml rename to internal/testdata/basic/service-templates/service1/service-node.yaml diff --git a/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml new file mode 100644 index 00000000..fe94c93d --- /dev/null +++ b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml @@ -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: lnd + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: lnd + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: lnd +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: lnd + app.kubernetes.io/name: basic-persistent + 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: lnd + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: lnd + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/lnd:latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8080 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 8080 + name: tcp-8080 + protocol: TCP + - containerPort: 10009 + name: tcp-10009 + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8080 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /app/storage + name: lnd + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: lnd + persistentVolumeClaim: + claimName: lnd +status: {} diff --git a/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml new file mode 100644 index 00000000..71cc158e --- /dev/null +++ b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml @@ -0,0 +1,89 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: thunderhub + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: thunderhub + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: thunderhub +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: thunderhub + app.kubernetes.io/name: basic-persistent + 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: thunderhub + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: thunderhub + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/thunderhub:latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 3000 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 3000 + name: tcp-3000 + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 3000 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /data + name: lnd + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: lnd + persistentVolumeClaim: + claimName: lnd +status: {} diff --git a/internal/testdata/basic/service-templates/service2/deployment-tor.yaml b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml new file mode 100644 index 00000000..ef0c864f --- /dev/null +++ b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml @@ -0,0 +1,85 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: tor + 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: tor + lagoon.sh/service-type: basic + lagoon.sh/template: basic-0.1.0 + name: tor +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: tor + 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: tor + 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: tor + lagoon.sh/service-type: basic + lagoon.sh/template: basic-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/tor:latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 9050 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 9050 + name: tcp-9050 + protocol: TCP + - containerPort: 9051 + name: tcp-9051 + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 9050 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 +status: {} diff --git a/internal/testdata/basic/service-templates/service2/deployments.yaml b/internal/testdata/basic/service-templates/service2/deployments.yaml deleted file mode 100644 index 27d19ed3..00000000 --- a/internal/testdata/basic/service-templates/service2/deployments.yaml +++ /dev/null @@ -1,266 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: lnd - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: lnd - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: lnd -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: lnd - app.kubernetes.io/name: basic-persistent - 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: lnd - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: lnd - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/lnd:latest - livenessProbe: - initialDelaySeconds: 60 - tcpSocket: - port: 8080 - timeoutSeconds: 10 - name: basic - ports: - - containerPort: 8080 - name: tcp-8080 - protocol: TCP - - containerPort: 10009 - name: tcp-10009 - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 8080 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /app/storage - name: lnd - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 - volumes: - - name: lnd - persistentVolumeClaim: - claimName: lnd -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: thunderhub - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: thunderhub - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: thunderhub -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: thunderhub - app.kubernetes.io/name: basic-persistent - 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: thunderhub - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: thunderhub - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/thunderhub:latest - livenessProbe: - initialDelaySeconds: 60 - tcpSocket: - port: 3000 - timeoutSeconds: 10 - name: basic - ports: - - containerPort: 3000 - name: tcp-3000 - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 3000 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /data - name: lnd - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 - volumes: - - name: lnd - persistentVolumeClaim: - claimName: lnd -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: tor - 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: tor - lagoon.sh/service-type: basic - lagoon.sh/template: basic-0.1.0 - name: tor -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: tor - 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: tor - 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: tor - lagoon.sh/service-type: basic - lagoon.sh/template: basic-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/tor:latest - livenessProbe: - initialDelaySeconds: 60 - tcpSocket: - port: 9050 - timeoutSeconds: 10 - name: basic - ports: - - containerPort: 9050 - name: tcp-9050 - protocol: TCP - - containerPort: 9051 - name: tcp-9051 - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 9050 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 -status: {} diff --git a/internal/testdata/basic/service-templates/service2/pvcs.yaml b/internal/testdata/basic/service-templates/service2/pvc-lnd.yaml similarity index 100% rename from internal/testdata/basic/service-templates/service2/pvcs.yaml rename to internal/testdata/basic/service-templates/service2/pvc-lnd.yaml diff --git a/internal/testdata/basic/service-templates/service3/services.yaml b/internal/testdata/basic/service-templates/service2/service-lnd.yaml similarity index 100% rename from internal/testdata/basic/service-templates/service3/services.yaml rename to internal/testdata/basic/service-templates/service2/service-lnd.yaml diff --git a/internal/testdata/basic/service-templates/service2/service-thunderhub.yaml b/internal/testdata/basic/service-templates/service2/service-thunderhub.yaml new file mode 100644 index 00000000..b53d353b --- /dev/null +++ b/internal/testdata/basic/service-templates/service2/service-thunderhub.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: thunderhub + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: thunderhub + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: thunderhub +spec: + ports: + - name: tcp-3000 + port: 3000 + protocol: TCP + targetPort: tcp-3000 + selector: + app.kubernetes.io/instance: thunderhub + app.kubernetes.io/name: basic-persistent +status: + loadBalancer: {} diff --git a/internal/testdata/basic/service-templates/service2/service-tor.yaml b/internal/testdata/basic/service-templates/service2/service-tor.yaml new file mode 100644 index 00000000..dd691516 --- /dev/null +++ b/internal/testdata/basic/service-templates/service2/service-tor.yaml @@ -0,0 +1,35 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: tor + 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: tor + lagoon.sh/service-type: basic + lagoon.sh/template: basic-0.1.0 + name: tor +spec: + ports: + - name: tcp-9050 + port: 9050 + protocol: TCP + targetPort: tcp-9050 + - name: tcp-9051 + port: 9051 + protocol: TCP + targetPort: tcp-9051 + selector: + app.kubernetes.io/instance: tor + app.kubernetes.io/name: basic +status: + loadBalancer: {} diff --git a/internal/testdata/basic/service-templates/service2/services.yaml b/internal/testdata/basic/service-templates/service2/services.yaml deleted file mode 100644 index 21e8c8ad..00000000 --- a/internal/testdata/basic/service-templates/service2/services.yaml +++ /dev/null @@ -1,101 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: lnd - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: lnd - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: lnd -spec: - ports: - - name: tcp-8080 - port: 8080 - protocol: TCP - targetPort: tcp-8080 - - name: tcp-10009 - port: 10009 - protocol: TCP - targetPort: tcp-10009 - selector: - app.kubernetes.io/instance: lnd - app.kubernetes.io/name: basic-persistent -status: - loadBalancer: {} ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: thunderhub - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: thunderhub - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: thunderhub -spec: - ports: - - name: tcp-3000 - port: 3000 - protocol: TCP - targetPort: tcp-3000 - selector: - app.kubernetes.io/instance: thunderhub - app.kubernetes.io/name: basic-persistent -status: - loadBalancer: {} ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: tor - 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: tor - lagoon.sh/service-type: basic - lagoon.sh/template: basic-0.1.0 - name: tor -spec: - ports: - - name: tcp-9050 - port: 9050 - protocol: TCP - targetPort: tcp-9050 - - name: tcp-9051 - port: 9051 - protocol: TCP - targetPort: tcp-9051 - selector: - app.kubernetes.io/instance: tor - app.kubernetes.io/name: basic -status: - loadBalancer: {} diff --git a/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml new file mode 100644 index 00000000..fe94c93d --- /dev/null +++ b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml @@ -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: lnd + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: lnd + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: lnd +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: lnd + app.kubernetes.io/name: basic-persistent + 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: lnd + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: lnd + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/lnd:latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8080 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 8080 + name: tcp-8080 + protocol: TCP + - containerPort: 10009 + name: tcp-10009 + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8080 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /app/storage + name: lnd + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: lnd + persistentVolumeClaim: + claimName: lnd +status: {} diff --git a/internal/testdata/basic/service-templates/service3/deployment-tor.yaml b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml new file mode 100644 index 00000000..97762e89 --- /dev/null +++ b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml @@ -0,0 +1,88 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: tor + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: worker-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: tor + lagoon.sh/service-type: worker-persistent + lagoon.sh/template: worker-persistent-0.1.0 + name: tor +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: tor + app.kubernetes.io/name: worker-persistent + 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: tor + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: worker-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: tor + lagoon.sh/service-type: worker-persistent + lagoon.sh/template: worker-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/tor:latest + name: worker + readinessProbe: + exec: + command: + - /bin/sh + - -c + - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; + fi + failureThreshold: 3 + initialDelaySeconds: 5 + periodSeconds: 2 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + - mountPath: /data + name: lnd + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: lnd + persistentVolumeClaim: + claimName: lnd +status: {} diff --git a/internal/testdata/basic/service-templates/service3/deployments.yaml b/internal/testdata/basic/service-templates/service3/deployments.yaml deleted file mode 100644 index 935432ca..00000000 --- a/internal/testdata/basic/service-templates/service3/deployments.yaml +++ /dev/null @@ -1,184 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: lnd - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: lnd - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - name: lnd -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: lnd - app.kubernetes.io/name: basic-persistent - 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: lnd - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: basic-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: lnd - lagoon.sh/service-type: basic-persistent - lagoon.sh/template: basic-persistent-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/lnd:latest - livenessProbe: - initialDelaySeconds: 60 - tcpSocket: - port: 8080 - timeoutSeconds: 10 - name: basic - ports: - - containerPort: 8080 - name: tcp-8080 - protocol: TCP - - containerPort: 10009 - name: tcp-10009 - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 8080 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /app/storage - name: lnd - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 - volumes: - - name: lnd - persistentVolumeClaim: - claimName: lnd -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: tor - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: worker-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: tor - lagoon.sh/service-type: worker-persistent - lagoon.sh/template: worker-persistent-0.1.0 - name: tor -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: tor - app.kubernetes.io/name: worker-persistent - 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: tor - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: worker-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: tor - lagoon.sh/service-type: worker-persistent - lagoon.sh/template: worker-persistent-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/tor:latest - name: cli - ports: - - containerPort: 3000 - name: http - protocol: TCP - readinessProbe: - exec: - command: - - /bin/sh - - -c - - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; - fi - failureThreshold: 3 - initialDelaySeconds: 5 - periodSeconds: 2 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - mountPath: /data - name: lnd - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 - volumes: - - name: lnd - persistentVolumeClaim: - claimName: lnd -status: {} diff --git a/internal/testdata/basic/service-templates/service3/pvcs.yaml b/internal/testdata/basic/service-templates/service3/pvc-lnd.yaml similarity index 100% rename from internal/testdata/basic/service-templates/service3/pvcs.yaml rename to internal/testdata/basic/service-templates/service3/pvc-lnd.yaml diff --git a/internal/testdata/basic/service-templates/service3/service-lnd.yaml b/internal/testdata/basic/service-templates/service3/service-lnd.yaml new file mode 100644 index 00000000..c193ba18 --- /dev/null +++ b/internal/testdata/basic/service-templates/service3/service-lnd.yaml @@ -0,0 +1,35 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: lnd + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: lnd + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: lnd +spec: + ports: + - name: tcp-8080 + port: 8080 + protocol: TCP + targetPort: tcp-8080 + - name: tcp-10009 + port: 10009 + protocol: TCP + targetPort: tcp-10009 + selector: + app.kubernetes.io/instance: lnd + app.kubernetes.io/name: basic-persistent +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service1/cronjobs.yaml b/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml similarity index 100% rename from internal/testdata/complex/service-templates/service1/cronjobs.yaml rename to internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml diff --git a/internal/testdata/complex/service-templates/service1/deployment-cli.yaml b/internal/testdata/complex/service-templates/service1/deployment-cli.yaml new file mode 100644 index 00000000..b8400b7a --- /dev/null +++ b/internal/testdata/complex/service-templates/service1/deployment-cli.yaml @@ -0,0 +1,94 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: cli + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: cli + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + name: cli +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: cli + app.kubernetes.io/name: cli-persistent + 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: cli + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: cli + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + value: | + 3,18,33,48 * * * * drush cron + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/cli:latest + name: cli + readinessProbe: + exec: + command: + - /bin/sh + - -c + - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; + fi + failureThreshold: 3 + initialDelaySeconds: 5 + periodSeconds: 2 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + - mountPath: /app/docroot/sites/default/files//php + name: nginx-php-twig + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: lagoon-sshkey + secret: + defaultMode: 420 + secretName: lagoon-sshkey + - emptyDir: {} + name: nginx-php-twig + - name: nginx-php + persistentVolumeClaim: + claimName: nginx-php +status: {} diff --git a/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml new file mode 100644 index 00000000..586bcbfb --- /dev/null +++ b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml @@ -0,0 +1,124 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + name: nginx-php +spec: + replicas: 2 + selector: + matchLabels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/name: nginx-php-persistent + 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: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + spec: + containers: + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/nginx:latest + livenessProbe: + failureThreshold: 5 + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 900 + timeoutSeconds: 3 + name: nginx + ports: + - containerPort: 8080 + name: http + protocol: TCP + readinessProbe: + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 1 + timeoutSeconds: 3 + resources: + requests: + cpu: 10m + memory: 10M + volumeMounts: + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/php:latest + livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + tcpSocket: + port: 9000 + name: php + ports: + - containerPort: 9000 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 2 + periodSeconds: 10 + tcpSocket: + port: 9000 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + - mountPath: /app/docroot/sites/default/files//php + name: nginx-php-twig + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: nginx-php + persistentVolumeClaim: + claimName: nginx-php + - emptyDir: {} + name: nginx-php-twig +status: {} diff --git a/internal/testdata/complex/service-templates/service1/deployment-redis.yaml b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml new file mode 100644 index 00000000..48822935 --- /dev/null +++ b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml @@ -0,0 +1,78 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + name: redis +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: redis + app.kubernetes.io/name: redis + 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: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/redis:latest + livenessProbe: + initialDelaySeconds: 120 + tcpSocket: + port: 6379 + timeoutSeconds: 10 + name: redis + ports: + - containerPort: 6379 + name: 6379-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 6379 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production +status: {} diff --git a/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml new file mode 100644 index 00000000..01c0bf35 --- /dev/null +++ b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml @@ -0,0 +1,81 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + name: varnish +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/name: varnish + 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: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/varnish:latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8080 + timeoutSeconds: 10 + name: varnish + ports: + - containerPort: 8080 + name: http + protocol: TCP + - containerPort: 6082 + name: controlport + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8080 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production +status: {} diff --git a/internal/testdata/complex/service-templates/service1/deployments.yaml b/internal/testdata/complex/service-templates/service1/deployments.yaml deleted file mode 100644 index 345537d8..00000000 --- a/internal/testdata/complex/service-templates/service1/deployments.yaml +++ /dev/null @@ -1,381 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: cli - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: cli - lagoon.sh/service-type: cli-persistent - lagoon.sh/template: cli-persistent-0.1.0 - name: cli -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: cli - app.kubernetes.io/name: cli-persistent - 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: cli - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: cli - lagoon.sh/service-type: cli-persistent - lagoon.sh/template: cli-persistent-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - value: | - 3,18,33,48 * * * * drush cron - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/cli:latest - name: cli - ports: - - containerPort: 3000 - name: http - protocol: TCP - readinessProbe: - exec: - command: - - /bin/sh - - -c - - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; - fi - failureThreshold: 3 - initialDelaySeconds: 5 - periodSeconds: 2 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - mountPath: /app/docroot/sites/default/files//php - name: nginx-php-twig - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - - emptyDir: {} - name: nginx-php-twig - - name: nginx-php - persistentVolumeClaim: - claimName: nginx-php -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: redis - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: redis - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: redis - lagoon.sh/service-type: redis - lagoon.sh/template: redis-0.1.0 - name: redis -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: redis - app.kubernetes.io/name: redis - 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: redis - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: redis - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: redis - lagoon.sh/service-type: redis - lagoon.sh/template: redis-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/redis:latest - livenessProbe: - initialDelaySeconds: 120 - tcpSocket: - port: 6379 - timeoutSeconds: 10 - name: redis - ports: - - containerPort: 6379 - name: 6379-tcp - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 6379 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: varnish - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: varnish - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: varnish - lagoon.sh/service-type: varnish - lagoon.sh/template: varnish-0.1.0 - name: varnish -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: varnish - app.kubernetes.io/name: varnish - 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: varnish - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: varnish - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: varnish - lagoon.sh/service-type: varnish - lagoon.sh/template: varnish-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/varnish:latest - livenessProbe: - initialDelaySeconds: 60 - tcpSocket: - port: 8080 - timeoutSeconds: 10 - name: varnish - ports: - - containerPort: 8080 - name: http - protocol: TCP - - containerPort: 6082 - name: controlport - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 8080 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - name: nginx-php -spec: - replicas: 2 - selector: - matchLabels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/name: nginx-php-persistent - 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: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - spec: - containers: - - env: - - name: NGINX_FASTCGI_PASS - value: 127.0.0.1 - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/nginx:latest - livenessProbe: - failureThreshold: 5 - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 900 - timeoutSeconds: 3 - name: nginx - ports: - - containerPort: 8080 - name: http - protocol: TCP - readinessProbe: - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 1 - timeoutSeconds: 3 - resources: - requests: - cpu: 10m - memory: 10M - volumeMounts: - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - - env: - - name: NGINX_FASTCGI_PASS - value: 127.0.0.1 - - name: LAGOON_GIT_SHA - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/php:latest - livenessProbe: - initialDelaySeconds: 60 - periodSeconds: 10 - tcpSocket: - port: 9000 - name: php - ports: - - containerPort: 9000 - name: http - protocol: TCP - readinessProbe: - initialDelaySeconds: 2 - periodSeconds: 10 - tcpSocket: - port: 9000 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - - mountPath: /app/docroot/sites/default/files//php - name: nginx-php-twig - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - volumes: - - name: nginx-php - persistentVolumeClaim: - claimName: nginx-php - - emptyDir: {} - name: nginx-php-twig -status: {} diff --git a/internal/testdata/complex/service-templates/service1/pvcs.yaml b/internal/testdata/complex/service-templates/service1/pvc-nginx-php.yaml similarity index 100% rename from internal/testdata/complex/service-templates/service1/pvcs.yaml rename to internal/testdata/complex/service-templates/service1/pvc-nginx-php.yaml diff --git a/internal/testdata/complex/service-templates/service1/service-nginx-php.yaml b/internal/testdata/complex/service-templates/service1/service-nginx-php.yaml new file mode 100644 index 00000000..0e8aba6e --- /dev/null +++ b/internal/testdata/complex/service-templates/service1/service-nginx-php.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + name: nginx-php +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: http + selector: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/name: nginx-php-persistent +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service1/service-redis.yaml b/internal/testdata/complex/service-templates/service1/service-redis.yaml new file mode 100644 index 00000000..e0c26762 --- /dev/null +++ b/internal/testdata/complex/service-templates/service1/service-redis.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + name: redis +spec: + ports: + - name: 6379-tcp + port: 6379 + protocol: TCP + targetPort: 6379 + selector: + app.kubernetes.io/instance: redis + app.kubernetes.io/name: redis +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service1/service-varnish.yaml b/internal/testdata/complex/service-templates/service1/service-varnish.yaml new file mode 100644 index 00000000..9a9ae6c8 --- /dev/null +++ b/internal/testdata/complex/service-templates/service1/service-varnish.yaml @@ -0,0 +1,35 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + name: varnish +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: http + - name: controlport + port: 6082 + protocol: TCP + targetPort: controlport + selector: + app.kubernetes.io/instance: varnish + app.kubernetes.io/name: varnish +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service1/services.yaml b/internal/testdata/complex/service-templates/service1/services.yaml deleted file mode 100644 index 6f8f096a..00000000 --- a/internal/testdata/complex/service-templates/service1/services.yaml +++ /dev/null @@ -1,97 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: redis - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: redis - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: redis - lagoon.sh/service-type: redis - lagoon.sh/template: redis-0.1.0 - name: redis -spec: - ports: - - name: 6379-tcp - port: 6379 - protocol: TCP - targetPort: 6379 - selector: - app.kubernetes.io/instance: redis - app.kubernetes.io/name: redis -status: - loadBalancer: {} ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: varnish - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: varnish - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: varnish - lagoon.sh/service-type: varnish - lagoon.sh/template: varnish-0.1.0 - name: varnish -spec: - ports: - - name: http - port: 8080 - protocol: TCP - targetPort: http - - name: controlport - port: 6082 - protocol: TCP - targetPort: controlport - selector: - app.kubernetes.io/instance: varnish - app.kubernetes.io/name: varnish -status: - loadBalancer: {} ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - name: nginx-php -spec: - ports: - - name: http - port: 8080 - protocol: TCP - targetPort: http - selector: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/name: nginx-php-persistent -status: - loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service2/cronjobs.yaml b/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml similarity index 100% rename from internal/testdata/complex/service-templates/service2/cronjobs.yaml rename to internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml diff --git a/internal/testdata/complex/service-templates/service2/deployment-cli.yaml b/internal/testdata/complex/service-templates/service2/deployment-cli.yaml new file mode 100644 index 00000000..d09af656 --- /dev/null +++ b/internal/testdata/complex/service-templates/service2/deployment-cli.yaml @@ -0,0 +1,98 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: cli + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: cli + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + name: cli +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: cli + app.kubernetes.io/name: cli-persistent + 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: cli + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: cli-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: cli + lagoon.sh/service-type: cli-persistent + lagoon.sh/template: cli-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + value: | + 3,18,33,48 * * * * drush cron + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/cli:latest + name: cli + readinessProbe: + exec: + command: + - /bin/sh + - -c + - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; + fi + failureThreshold: 3 + initialDelaySeconds: 5 + periodSeconds: 2 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + - mountPath: /app/docroot/sites/default/files//php + name: nginx-php-twig + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: lagoon-sshkey + secret: + defaultMode: 420 + secretName: lagoon-sshkey + - emptyDir: {} + name: nginx-php-twig + - name: nginx-php + persistentVolumeClaim: + claimName: nginx-php +status: {} diff --git a/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml new file mode 100644 index 00000000..817dd923 --- /dev/null +++ b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml @@ -0,0 +1,145 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + name: nginx-php +spec: + replicas: 2 + selector: + matchLabels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/name: nginx-php-persistent + 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: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + spec: + containers: + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/nginx:latest + livenessProbe: + failureThreshold: 5 + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 900 + timeoutSeconds: 3 + name: nginx + ports: + - containerPort: 8080 + name: http + protocol: TCP + readinessProbe: + httpGet: + path: /nginx_status + port: 50000 + initialDelaySeconds: 1 + timeoutSeconds: 3 + resources: + requests: + cpu: 10m + memory: 10M + volumeMounts: + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + - env: + - name: NGINX_FASTCGI_PASS + value: 127.0.0.1 + - name: LAGOON_GIT_SHA + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/php:latest + livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + tcpSocket: + port: 9000 + name: php + ports: + - containerPort: 9000 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 2 + periodSeconds: 10 + tcpSocket: + port: 9000 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /app/docroot/sites/default/files/ + name: nginx-php + - mountPath: /app/docroot/sites/default/files//php + name: nginx-php-twig + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + initContainers: + - command: + - sh + - -c + - "set -e\nSENTINEL=\"/storage/.lagoon-rootless-migration-complete\"\nif ! + [ -f \"$SENTINEL\" ]; then\n\tfind /storage -exec chown 10000:0 {} +\n\tfind + /storage -exec chmod a+r,u+w {} +\n\tfind /storage -type d -exec chmod a+x + {} +\n\ttouch \"$SENTINEL\"\nfi" + image: library/busybox:musl + imagePullPolicy: IfNotPresent + name: fix-storage-permissions + resources: {} + securityContext: + runAsUser: 0 + volumeMounts: + - mountPath: /storage + name: nginx-php + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: nginx-php + persistentVolumeClaim: + claimName: nginx-php + - emptyDir: {} + name: nginx-php-twig +status: {} diff --git a/internal/testdata/complex/service-templates/service2/deployment-redis.yaml b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml new file mode 100644 index 00000000..d4cc970e --- /dev/null +++ b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml @@ -0,0 +1,82 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + name: redis +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: redis + app.kubernetes.io/name: redis + 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: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/redis:latest + livenessProbe: + initialDelaySeconds: 120 + tcpSocket: + port: 6379 + timeoutSeconds: 10 + name: redis + ports: + - containerPort: 6379 + name: 6379-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 6379 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 +status: {} diff --git a/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml new file mode 100644 index 00000000..dd142ca5 --- /dev/null +++ b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml @@ -0,0 +1,85 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + name: varnish +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/name: varnish + 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: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/varnish:latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8080 + timeoutSeconds: 10 + name: varnish + ports: + - containerPort: 8080 + name: http + protocol: TCP + - containerPort: 6082 + name: controlport + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8080 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + runAsGroup: 0 + runAsUser: 10000 +status: {} diff --git a/internal/testdata/complex/service-templates/service2/deployments.yaml b/internal/testdata/complex/service-templates/service2/deployments.yaml deleted file mode 100644 index 0e274cc4..00000000 --- a/internal/testdata/complex/service-templates/service2/deployments.yaml +++ /dev/null @@ -1,414 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: cli - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: cli - lagoon.sh/service-type: cli-persistent - lagoon.sh/template: cli-persistent-0.1.0 - name: cli -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: cli - app.kubernetes.io/name: cli-persistent - 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: cli - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: cli - lagoon.sh/service-type: cli-persistent - lagoon.sh/template: cli-persistent-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - value: | - 3,18,33,48 * * * * drush cron - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/cli:latest - name: cli - ports: - - containerPort: 3000 - name: http - protocol: TCP - readinessProbe: - exec: - command: - - /bin/sh - - -c - - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; - fi - failureThreshold: 3 - initialDelaySeconds: 5 - periodSeconds: 2 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - mountPath: /app/docroot/sites/default/files//php - name: nginx-php-twig - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - - emptyDir: {} - name: nginx-php-twig - - name: nginx-php - persistentVolumeClaim: - claimName: nginx-php -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: redis - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: redis - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: redis - lagoon.sh/service-type: redis - lagoon.sh/template: redis-0.1.0 - name: redis -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: redis - app.kubernetes.io/name: redis - 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: redis - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: redis - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: redis - lagoon.sh/service-type: redis - lagoon.sh/template: redis-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/redis:latest - livenessProbe: - initialDelaySeconds: 120 - tcpSocket: - port: 6379 - timeoutSeconds: 10 - name: redis - ports: - - containerPort: 6379 - name: 6379-tcp - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 6379 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: varnish - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: varnish - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: varnish - lagoon.sh/service-type: varnish - lagoon.sh/template: varnish-0.1.0 - name: varnish -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: varnish - app.kubernetes.io/name: varnish - 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: varnish - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: varnish - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: varnish - lagoon.sh/service-type: varnish - lagoon.sh/template: varnish-0.1.0 - spec: - containers: - - env: - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/varnish:latest - livenessProbe: - initialDelaySeconds: 60 - tcpSocket: - port: 8080 - timeoutSeconds: 10 - name: varnish - ports: - - containerPort: 8080 - name: http - protocol: TCP - - containerPort: 6082 - name: controlport - protocol: TCP - readinessProbe: - initialDelaySeconds: 1 - tcpSocket: - port: 8080 - timeoutSeconds: 1 - resources: - requests: - cpu: 10m - memory: 100M - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 -status: {} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - name: nginx-php -spec: - replicas: 2 - selector: - matchLabels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/name: nginx-php-persistent - 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: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - spec: - containers: - - env: - - name: NGINX_FASTCGI_PASS - value: 127.0.0.1 - - name: LAGOON_GIT_SHA - - name: CRONJOBS - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/nginx:latest - livenessProbe: - failureThreshold: 5 - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 900 - timeoutSeconds: 3 - name: nginx - ports: - - containerPort: 8080 - name: http - protocol: TCP - readinessProbe: - httpGet: - path: /nginx_status - port: 50000 - initialDelaySeconds: 1 - timeoutSeconds: 3 - resources: - requests: - cpu: 10m - memory: 10M - volumeMounts: - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - - env: - - name: NGINX_FASTCGI_PASS - value: 127.0.0.1 - - name: LAGOON_GIT_SHA - envFrom: - - configMapRef: - name: lagoon-env - image: harbor.example/example-project/main/php:latest - livenessProbe: - initialDelaySeconds: 60 - periodSeconds: 10 - tcpSocket: - port: 9000 - name: php - ports: - - containerPort: 9000 - name: http - protocol: TCP - readinessProbe: - initialDelaySeconds: 2 - periodSeconds: 10 - tcpSocket: - port: 9000 - resources: - requests: - cpu: 10m - memory: 100M - volumeMounts: - - mountPath: /app/docroot/sites/default/files/ - name: nginx-php - - mountPath: /app/docroot/sites/default/files//php - name: nginx-php-twig - enableServiceLinks: false - imagePullSecrets: - - name: lagoon-internal-registry-secret - initContainers: - - command: - - sh - - -c - - "set -e\nSENTINEL=\"/storage/.lagoon-rootless-migration-complete\"\nif ! - [ -f \"$SENTINEL\" ]; then\n\tfind /storage -exec chown 10000:0 {} +\n\tfind - /storage -exec chmod a+r,u+w {} +\n\tfind /storage -type d -exec chmod a+x - {} +\n\ttouch \"$SENTINEL\"\nfi" - image: library/busybox:musl - imagePullPolicy: IfNotPresent - name: fix-storage-permissions - resources: {} - securityContext: - runAsUser: 0 - volumeMounts: - - mountPath: /storage - name: nginx-php - priorityClassName: lagoon-priority-production - securityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 - volumes: - - name: nginx-php - persistentVolumeClaim: - claimName: nginx-php - - emptyDir: {} - name: nginx-php-twig -status: {} diff --git a/internal/testdata/complex/service-templates/service2/pvcs.yaml b/internal/testdata/complex/service-templates/service2/pvc-nginx-php.yaml similarity index 100% rename from internal/testdata/complex/service-templates/service2/pvcs.yaml rename to internal/testdata/complex/service-templates/service2/pvc-nginx-php.yaml diff --git a/internal/testdata/complex/service-templates/service2/service-nginx-php.yaml b/internal/testdata/complex/service-templates/service2/service-nginx-php.yaml new file mode 100644 index 00000000..0e8aba6e --- /dev/null +++ b/internal/testdata/complex/service-templates/service2/service-nginx-php.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: nginx-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: nginx-php + lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: nginx-php-persistent-0.1.0 + name: nginx-php +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: http + selector: + app.kubernetes.io/instance: nginx-php + app.kubernetes.io/name: nginx-php-persistent +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service2/service-redis.yaml b/internal/testdata/complex/service-templates/service2/service-redis.yaml new file mode 100644 index 00000000..e0c26762 --- /dev/null +++ b/internal/testdata/complex/service-templates/service2/service-redis.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + name: redis +spec: + ports: + - name: 6379-tcp + port: 6379 + protocol: TCP + targetPort: 6379 + selector: + app.kubernetes.io/instance: redis + app.kubernetes.io/name: redis +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service2/service-varnish.yaml b/internal/testdata/complex/service-templates/service2/service-varnish.yaml new file mode 100644 index 00000000..9a9ae6c8 --- /dev/null +++ b/internal/testdata/complex/service-templates/service2/service-varnish.yaml @@ -0,0 +1,35 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + name: varnish +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: http + - name: controlport + port: 6082 + protocol: TCP + targetPort: controlport + selector: + app.kubernetes.io/instance: varnish + app.kubernetes.io/name: varnish +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service2/services.yaml b/internal/testdata/complex/service-templates/service2/services.yaml deleted file mode 100644 index 6f8f096a..00000000 --- a/internal/testdata/complex/service-templates/service2/services.yaml +++ /dev/null @@ -1,97 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: redis - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: redis - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: redis - lagoon.sh/service-type: redis - lagoon.sh/template: redis-0.1.0 - name: redis -spec: - ports: - - name: 6379-tcp - port: 6379 - protocol: TCP - targetPort: 6379 - selector: - app.kubernetes.io/instance: redis - app.kubernetes.io/name: redis -status: - loadBalancer: {} ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: varnish - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: varnish - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: varnish - lagoon.sh/service-type: varnish - lagoon.sh/template: varnish-0.1.0 - name: varnish -spec: - ports: - - name: http - port: 8080 - protocol: TCP - targetPort: http - - name: controlport - port: 6082 - protocol: TCP - targetPort: controlport - selector: - app.kubernetes.io/instance: varnish - app.kubernetes.io/name: varnish -status: - loadBalancer: {} ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - lagoon.sh/branch: main - lagoon.sh/version: v2.7.x - creationTimestamp: null - labels: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: nginx-php-persistent - lagoon.sh/buildType: branch - lagoon.sh/environment: main - lagoon.sh/environmentType: production - lagoon.sh/project: example-project - lagoon.sh/service: nginx-php - lagoon.sh/service-type: nginx-php-persistent - lagoon.sh/template: nginx-php-persistent-0.1.0 - name: nginx-php -spec: - ports: - - name: http - port: 8080 - protocol: TCP - targetPort: http - selector: - app.kubernetes.io/instance: nginx-php - app.kubernetes.io/name: nginx-php-persistent -status: - loadBalancer: {} From 51a15c21a73622d6b825014cdf4bc7fd70d49d19 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 9 Jan 2024 13:12:07 +1100 Subject: [PATCH 41/92] chore: remove ioutil --- cmd/template_autogen_ingress_test.go | 7 +++---- cmd/template_backups_test.go | 5 ++--- cmd/template_dbaas_test.go | 5 ++--- cmd/template_ingress_test.go | 5 ++--- cmd/template_lagoonservices_test.go | 5 ++--- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/cmd/template_autogen_ingress_test.go b/cmd/template_autogen_ingress_test.go index ded28cae..46356664 100644 --- a/cmd/template_autogen_ingress_test.go +++ b/cmd/template_autogen_ingress_test.go @@ -3,7 +3,6 @@ package cmd import ( "fmt" "io/fs" - "io/ioutil" "os" "reflect" "testing" @@ -496,14 +495,14 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { t.Errorf("AutogeneratedIngressGeneration() error = %v, wantErr %v", err, tt.wantErr) } - files, err := ioutil.ReadDir(savedTemplates) + files, err := os.ReadDir(savedTemplates) if err != nil { t.Errorf("couldn't read directory %v: %v", savedTemplates, err) } resultSize := 0 - results := []fs.FileInfo{} + results := []fs.DirEntry{} if !tt.emptyDir { - results, err = ioutil.ReadDir(tt.want) + results, err = os.ReadDir(tt.want) if err != nil { t.Errorf("couldn't read directory %v: %v", tt.want, err) } diff --git a/cmd/template_backups_test.go b/cmd/template_backups_test.go index 0fddbd1f..446b21c9 100644 --- a/cmd/template_backups_test.go +++ b/cmd/template_backups_test.go @@ -2,7 +2,6 @@ package cmd import ( "fmt" - "io/ioutil" "os" "reflect" "testing" @@ -213,11 +212,11 @@ func TestBackupTemplateGeneration(t *testing.T) { if err := BackupTemplateGeneration(generator); (err != nil) != tt.wantErr { t.Errorf("BackupTemplateGeneration() error = %v, wantErr %v", err, tt.wantErr) } - files, err := ioutil.ReadDir(savedTemplates) + files, err := os.ReadDir(savedTemplates) if err != nil { t.Errorf("couldn't read directory %v: %v", savedTemplates, err) } - results, err := ioutil.ReadDir(tt.want) + results, err := os.ReadDir(tt.want) if err != nil { t.Errorf("couldn't read directory %v: %v", tt.want, err) } diff --git a/cmd/template_dbaas_test.go b/cmd/template_dbaas_test.go index fb32942f..a245787e 100644 --- a/cmd/template_dbaas_test.go +++ b/cmd/template_dbaas_test.go @@ -2,7 +2,6 @@ package cmd import ( "fmt" - "io/ioutil" "os" "reflect" "testing" @@ -58,11 +57,11 @@ func TestDBaaSTemplateGeneration(t *testing.T) { if err := DBaaSTemplateGeneration(generator); (err != nil) != tt.wantErr { t.Errorf("DBaaSTemplateGeneration() error = %v, wantErr %v", err, tt.wantErr) } - files, err := ioutil.ReadDir(savedTemplates) + files, err := os.ReadDir(savedTemplates) if err != nil { t.Errorf("couldn't read directory %v: %v", savedTemplates, err) } - results, err := ioutil.ReadDir(tt.want) + results, err := os.ReadDir(tt.want) if err != nil { t.Errorf("couldn't read directory %v: %v", tt.want, err) } diff --git a/cmd/template_ingress_test.go b/cmd/template_ingress_test.go index fbdb3986..64cb341f 100644 --- a/cmd/template_ingress_test.go +++ b/cmd/template_ingress_test.go @@ -3,7 +3,6 @@ package cmd import ( "encoding/base64" "fmt" - "io/ioutil" "os" "reflect" "testing" @@ -400,11 +399,11 @@ func TestTemplateRoutes(t *testing.T) { t.Errorf("%v", err) } - files, err := ioutil.ReadDir(savedTemplates) + files, err := os.ReadDir(savedTemplates) if err != nil { t.Errorf("couldn't read directory %v: %v", savedTemplates, err) } - results, err := ioutil.ReadDir(tt.want) + results, err := os.ReadDir(tt.want) if err != nil { t.Errorf("couldn't read directory %v: %v", tt.want, err) } diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index c985759a..7d0de720 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -2,7 +2,6 @@ package cmd import ( "fmt" - "io/ioutil" "os" "reflect" "testing" @@ -188,11 +187,11 @@ func TestTemplateLagoonServices(t *testing.T) { t.Errorf("%v", err) } - files, err := ioutil.ReadDir(savedTemplates) + files, err := os.ReadDir(savedTemplates) if err != nil { t.Errorf("couldn't read directory %v: %v", savedTemplates, err) } - results, err := ioutil.ReadDir(tt.want) + results, err := os.ReadDir(tt.want) if err != nil { t.Errorf("couldn't read directory %v: %v", tt.want, err) } From 9fe290bd5413242b3c8b9d316f1708599cc76812 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 9 Jan 2024 18:30:45 +1100 Subject: [PATCH 42/92] refactor: add identify services command --- cmd/identify_lagoonservices.go | 94 ++++++++ cmd/identify_lagoonservices_test.go | 343 ++++++++++++++++++++++++++++ cmd/template_lagoonservices.go | 21 +- cmd/template_lagoonservices_test.go | 42 +--- 4 files changed, 456 insertions(+), 44 deletions(-) create mode 100644 cmd/identify_lagoonservices.go create mode 100644 cmd/identify_lagoonservices_test.go diff --git a/cmd/identify_lagoonservices.go b/cmd/identify_lagoonservices.go new file mode 100644 index 00000000..a8c77589 --- /dev/null +++ b/cmd/identify_lagoonservices.go @@ -0,0 +1,94 @@ +package cmd + +import ( + "encoding/base64" + "encoding/json" + "fmt" + + "github.com/spf13/cobra" + generator "github.com/uselagoon/build-deploy-tool/internal/generator" + servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating/services" +) + +type identifyServices struct { + Name string `json:"name"` + Type string `json:"type"` + Containers []containers `json:"containers,omitempty"` +} + +type containers struct { + Name string `json:"name"` + Ports []ports `json:"ports,omitempty"` +} + +type ports struct { + Port int32 `json:"port"` +} + +var lagoonServiceIdentify = &cobra.Command{ + Use: "lagoon-services", + Aliases: []string{"ls"}, + Short: "Identify the lagoon services for a Lagoon build", + RunE: func(cmd *cobra.Command, args []string) error { + gen, err := generator.GenerateInput(*rootCmd, true) + if err != nil { + return err + } + images, err := rootCmd.PersistentFlags().GetString("images") + if err != nil { + return fmt.Errorf("error reading images flag: %v", err) + } + var imageRefs struct { + Images map[string]string `json:"images"` + } + imagesStr, _ := base64.StdEncoding.DecodeString(images) + json.Unmarshal(imagesStr, &imageRefs) + gen.ImageReferences = imageRefs.Images + out, err := LagoonServiceTemplateIdentification(gen) + if err != nil { + return err + } + fmt.Println(out) + return nil + }, +} + +// LagoonServiceTemplateIdentification . +func LagoonServiceTemplateIdentification(g generator.GeneratorInput) ([]identifyServices, error) { + + lServices := []identifyServices{} + lagoonBuild, err := generator.NewGenerator( + g, + ) + if err != nil { + return nil, err + } + + // generate the templates + deployments, err := servicestemplates.GenerateDeploymentTemplate(*lagoonBuild.BuildValues) + if err != nil { + return nil, fmt.Errorf("couldn't generate template: %v", err) + } + if deployments != nil { + for _, d := range deployments { + dcs := []containers{} + for _, dc := range d.Spec.Template.Spec.Containers { + dcp := []ports{} + for _, p := range dc.Ports { + dcp = append(dcp, ports{Port: p.ContainerPort}) + } + dcs = append(dcs, containers{Name: dc.Name, Ports: dcp}) + } + lServices = append(lServices, identifyServices{ + Name: d.Name, + Type: d.ObjectMeta.Labels["lagoon.sh/service-type"], + Containers: dcs, + }) + } + } + return lServices, nil +} + +func init() { + identifyCmd.AddCommand(lagoonServiceIdentify) +} diff --git a/cmd/identify_lagoonservices_test.go b/cmd/identify_lagoonservices_test.go new file mode 100644 index 00000000..b75a0d24 --- /dev/null +++ b/cmd/identify_lagoonservices_test.go @@ -0,0 +1,343 @@ +package cmd + +import ( + "os" + "reflect" + "testing" + + "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" + "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/lagoon" + "github.com/uselagoon/build-deploy-tool/internal/testdata" +) + +func TestIdentifyLagoonServices(t *testing.T) { + tests := []struct { + name string + description string + args testdata.TestData + want []identifyServices + }{ + { + name: "test1 basic deployment", + 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:latest", + }, + }, true), + want: []identifyServices{ + { + Name: "node", + Type: "basic", + Containers: []containers{ + { + Name: "basic", + Ports: []ports{ + {Port: 1234}, + {Port: 8191}, + {Port: 9001}, + }, + }, + }, + }, + }, + }, + { + name: "test2a nginx-php deployment", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/complex/lagoon.varnish.yml", + ImageReferences: map[string]string{ + "nginx": "harbor.example/example-project/main/nginx:latest", + "php": "harbor.example/example-project/main/php:latest", + "cli": "harbor.example/example-project/main/cli:latest", + "redis": "harbor.example/example-project/main/redis:latest", + "varnish": "harbor.example/example-project/main/varnish:latest", + }, + }, true), + want: []identifyServices{ + { + Name: "cli", + Type: "cli-persistent", + Containers: []containers{ + { + Name: "cli", + Ports: []ports{}, + }, + }, + }, + { + Name: "redis", + Type: "redis", + Containers: []containers{ + { + Name: "redis", + Ports: []ports{ + {Port: 6379}, + }, + }, + }, + }, + { + Name: "varnish", + Type: "varnish", + Containers: []containers{ + { + Name: "varnish", + Ports: []ports{ + {Port: 8080}, + {Port: 6082}, + }, + }, + }, + }, + { + Name: "nginx-php", + Type: "nginx-php-persistent", + Containers: []containers{ + { + Name: "nginx", + Ports: []ports{ + {Port: 8080}, + }, + }, + { + Name: "php", + Ports: []ports{ + {Port: 9000}, + }, + }, + }, + }, + }, + }, + { + name: "test2b nginx-php deployment - rootless", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/complex/lagoon.varnish.yml", + ImageReferences: map[string]string{ + "nginx": "harbor.example/example-project/main/nginx:latest", + "php": "harbor.example/example-project/main/php:latest", + "cli": "harbor.example/example-project/main/cli:latest", + "redis": "harbor.example/example-project/main/redis:latest", + "varnish": "harbor.example/example-project/main/varnish:latest", + }, + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", + Value: "enabled", + Scope: "build", + }, + }, + }, true), + want: []identifyServices{ + { + Name: "cli", + Type: "cli-persistent", + Containers: []containers{ + { + Name: "cli", + Ports: []ports{}, + }, + }, + }, + { + Name: "redis", + Type: "redis", + Containers: []containers{ + { + Name: "redis", + Ports: []ports{ + {Port: 6379}, + }, + }, + }, + }, + { + Name: "varnish", + Type: "varnish", + Containers: []containers{ + { + Name: "varnish", + Ports: []ports{ + {Port: 8080}, + {Port: 6082}, + }, + }, + }, + }, + { + Name: "nginx-php", + Type: "nginx-php-persistent", + Containers: []containers{ + { + Name: "nginx", + Ports: []ports{ + {Port: 8080}, + }, + }, + { + Name: "php", + Ports: []ports{ + {Port: 9000}, + }, + }, + }, + }, + }, + }, + { + name: "test3 - funky pvcs", + description: "only create pvcs of the requested persistent-name in the docker-compose file", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/basic/lagoon.thunderhub.yml", + ImageReferences: map[string]string{ + "lnd": "harbor.example/example-project/main/lnd:latest", + "thunderhub": "harbor.example/example-project/main/thunderhub:latest", + "tor": "harbor.example/example-project/main/tor:latest", + }, + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", + Value: "enabled", + Scope: "build", + }, + }, + }, true), + want: []identifyServices{ + { + Name: "lnd", + Type: "basic-persistent", + Containers: []containers{ + { + Name: "basic", + Ports: []ports{ + {Port: 8080}, + {Port: 10009}, + }, + }, + }, + }, + { + Name: "thunderhub", + Type: "basic-persistent", + Containers: []containers{ + { + Name: "basic", + Ports: []ports{ + {Port: 3000}, + }, + }, + }, + }, + { + Name: "tor", + Type: "basic", + Containers: []containers{ + { + Name: "basic", + Ports: []ports{ + {Port: 9050}, + {Port: 9051}, + }, + }, + }, + }, + }, + }, + { + name: "test4 - basic-persistent with worker-persistent", + description: "create a basic-persistent that gets a pvc and mount that volume on a worker-persistent type", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/basic/lagoon.thunderhub-2.yml", + ImageReferences: map[string]string{ + "lnd": "harbor.example/example-project/main/lnd:latest", + "tor": "harbor.example/example-project/main/tor:latest", + }, + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", + Value: "enabled", + Scope: "build", + }, + }, + }, true), + want: []identifyServices{ + { + Name: "lnd", + Type: "basic-persistent", + Containers: []containers{ + {Name: "basic", + Ports: []ports{ + {Port: 8080}, + {Port: 10009}, + }}, + }, + }, + { + Name: "tor", + Type: "worker-persistent", + Containers: []containers{ + {Name: "worker", + Ports: []ports{}}, + }, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // set the environment variables from args + savedTemplates := "testdata/output" + generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) + if err != nil { + t.Errorf("%v", err) + } + + err = os.MkdirAll(savedTemplates, 0755) + if err != nil { + t.Errorf("couldn't create directory %v: %v", savedTemplates, err) + } + + defer os.RemoveAll(savedTemplates) + + ts := dbaasclient.TestDBaaSHTTPServer() + defer ts.Close() + err = os.Setenv("DBAAS_OPERATOR_HTTP", ts.URL) + if err != nil { + t.Errorf("%v", err) + } + + out, err := LagoonServiceTemplateIdentification(generator) + if err != nil { + t.Errorf("%v", err) + } + if !reflect.DeepEqual(out, tt.want) { + t.Errorf("returned output %v doesn't match want %v", out, tt.want) + } + t.Cleanup(func() { + helpers.UnsetEnvVars(nil) + }) + }) + } +} diff --git a/cmd/template_lagoonservices.go b/cmd/template_lagoonservices.go index 7039ef45..fc00c55b 100644 --- a/cmd/template_lagoonservices.go +++ b/cmd/template_lagoonservices.go @@ -46,9 +46,6 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { savedTemplates := g.SavedTemplatesPath // generate the templates - if g.Debug { - fmt.Println(fmt.Sprintf("Templating service manifests %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "services"))) - } services, err := servicestemplates.GenerateServiceTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) @@ -61,12 +58,12 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { } separator := []byte("---\n") restoreResult := append(separator[:], serviceBytes[:]...) + if g.Debug { + fmt.Println(fmt.Sprintf("Templating service manifests %s", fmt.Sprintf("%s/service-%s.yaml", savedTemplates, d.Name))) + } helpers.WriteTemplateFile(fmt.Sprintf("%s/service-%s.yaml", savedTemplates, d.Name), restoreResult) } } - if g.Debug { - fmt.Println(fmt.Sprintf("Templating pvc manifests %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "pvcs"))) - } pvcs, err := servicestemplates.GeneratePVCTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) @@ -79,12 +76,12 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { } separator := []byte("---\n") restoreResult := append(separator[:], serviceBytes[:]...) + if g.Debug { + fmt.Println(fmt.Sprintf("Templating pvc manifests %s", fmt.Sprintf("%s/pvc-%s.yaml", savedTemplates, d.Name))) + } helpers.WriteTemplateFile(fmt.Sprintf("%s/pvc-%s.yaml", savedTemplates, d.Name), restoreResult) } } - if g.Debug { - fmt.Println(fmt.Sprintf("Templating deployment manifest %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "deployments"))) - } deployments, err := servicestemplates.GenerateDeploymentTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) @@ -97,6 +94,9 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { } separator := []byte("---\n") restoreResult := append(separator[:], deploymentBytes[:]...) + if g.Debug { + fmt.Println(fmt.Sprintf("Templating deployment manifests %s", fmt.Sprintf("%s/deployment-%s.yaml", savedTemplates, d.Name))) + } helpers.WriteTemplateFile(fmt.Sprintf("%s/deployment-%s.yaml", savedTemplates, d.Name), restoreResult) } } @@ -112,6 +112,9 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { } separator := []byte("---\n") restoreResult := append(separator[:], deploymentBytes[:]...) + if g.Debug { + fmt.Println(fmt.Sprintf("Templating cronjob manifests %s", fmt.Sprintf("%s/cronjob-%s.yaml", savedTemplates, d.Name))) + } helpers.WriteTemplateFile(fmt.Sprintf("%s/cronjob-%s.yaml", savedTemplates, d.Name), restoreResult) } } diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index 7d0de720..0c170eb7 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -14,44 +14,16 @@ import ( ) func TestTemplateLagoonServices(t *testing.T) { - type args struct { - alertContact string - statusPageID string - projectName string - environmentName string - branch string - prNumber string - prHeadBranch string - prBaseBranch string - environmentType string - buildType string - activeEnvironment string - standbyEnvironment string - cacheNoCache string - serviceID string - secretPrefix string - ingressClass string - configMapSha string - rootlessWorkloads string - projectVars string - envVars string - lagoonVersion string - lagoonYAML string - valuesFilePath string - templatePath string - imageReferences map[string]string - } tests := []struct { name string description string - args args - args2 testdata.TestData + args testdata.TestData templatePath string want string }{ { name: "test1 basic deployment", - args2: testdata.GetSeedData( + args: testdata.GetSeedData( testdata.TestData{ ProjectName: "example-project", EnvironmentName: "main", @@ -66,7 +38,7 @@ func TestTemplateLagoonServices(t *testing.T) { }, { name: "test2a nginx-php deployment", - args2: testdata.GetSeedData( + args: testdata.GetSeedData( testdata.TestData{ ProjectName: "example-project", EnvironmentName: "main", @@ -85,7 +57,7 @@ func TestTemplateLagoonServices(t *testing.T) { }, { name: "test2b nginx-php deployment - rootless", - args2: testdata.GetSeedData( + args: testdata.GetSeedData( testdata.TestData{ ProjectName: "example-project", EnvironmentName: "main", @@ -112,7 +84,7 @@ func TestTemplateLagoonServices(t *testing.T) { { name: "test3 - funky pvcs", description: "only create pvcs of the requested persistent-name in the docker-compose file", - args2: testdata.GetSeedData( + args: testdata.GetSeedData( testdata.TestData{ ProjectName: "example-project", EnvironmentName: "main", @@ -137,7 +109,7 @@ func TestTemplateLagoonServices(t *testing.T) { { name: "test4 - basic-persistent with worker-persistent", description: "create a basic-persistent that gets a pvc and mount that volume on a worker-persistent type", - args2: testdata.GetSeedData( + args: testdata.GetSeedData( testdata.TestData{ ProjectName: "example-project", EnvironmentName: "main", @@ -163,7 +135,7 @@ func TestTemplateLagoonServices(t *testing.T) { t.Run(tt.name, func(t *testing.T) { // set the environment variables from args savedTemplates := tt.templatePath - generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args2) + generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) if err != nil { t.Errorf("%v", err) } From 52f4ee5205680fe870a4caf04e0cce3d8f41d741 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 10 Jan 2024 11:07:30 +1100 Subject: [PATCH 43/92] chore: set paths for testing from root --- cmd/identify_feature_test.go | 23 +-- cmd/identify_ingress_test.go | 99 ++++++------ cmd/identify_lagoonservices.go | 5 +- cmd/identify_lagoonservices_test.go | 15 +- cmd/identify_native_cronjobs_test.go | 15 +- cmd/template_autogen_ingress_test.go | 149 +++++++++--------- cmd/template_backups_test.go | 51 +++--- cmd/template_dbaas_test.go | 9 +- cmd/template_ingress_test.go | 141 +++++++++-------- cmd/template_lagoonservices_test.go | 33 ++-- cmd/validate_compose_test.go | 19 ++- cmd/validate_lagoonyml_test.go | 53 ++++--- internal/lagoon/compose_test.go | 44 +++--- .../basic/docker-compose.thunderhub-2.yml | 4 +- .../basic/docker-compose.thunderhub.yml | 6 +- internal/testdata/basic/docker-compose.yml | 2 +- internal/testdata/basic/docker/Dockerfile | 1 + .../testdata/basic/docker/basic.dockerfile | 1 + .../testdata/basic/lagoon.thunderhub-2.yml | 2 +- internal/testdata/basic/lagoon.thunderhub.yml | 2 +- internal/testdata/basic/lagoon.yml | 2 +- .../complex/docker-compose.complex-1.yml | 14 +- .../complex/docker-compose.small-1.yml | 8 +- .../complex/docker-compose.small-2.yml | 8 +- .../complex/docker-compose.varnish.yml | 8 +- internal/testdata/complex/docker-compose.yml | 8 +- .../complex/docker/.docker/Dockerfile.cli | 1 + .../docker/.docker/Dockerfile.nginx-drupal | 1 + .../complex/docker/.docker/Dockerfile.php | 1 + .../complex/docker/builder.dockerfile | 1 + .../testdata/complex/docker/cli.dockerfile | 1 + .../complex/docker/mariadb.dockerfile | 1 + .../testdata/complex/docker/nginx.dockerfile | 1 + .../testdata/complex/docker/php.dockerfile | 1 + .../testdata/complex/lagoon.complex-1.yml | 2 +- .../testdata/complex/lagoon.complex-2.yml | 2 +- internal/testdata/complex/lagoon.small-2.yml | 2 +- internal/testdata/complex/lagoon.small.yml | 2 +- internal/testdata/complex/lagoon.varnish.yml | 2 +- internal/testdata/complex/lagoon.yml | 2 +- .../docker-compose/test1/docker-compose.yml | 121 ++++++++++++++ .../docker-compose/test10/docker-compose.yml | 111 +++++++++++++ .../docker-compose/test11/docker-compose.yml | 20 +++ .../docker-compose/test2/docker-compose.yml | 20 +++ .../docker-compose/test3/docker-compose.yml | 126 +++++++++++++++ .../docker-compose/test4/docker-compose.yml | 146 +++++++++++++++++ .../docker-compose/test5/docker-compose.yml | 131 +++++++++++++++ .../docker-compose/test6/docker-compose.yml | 138 ++++++++++++++++ .../docker-compose/test7/docker-compose.yml | 119 ++++++++++++++ .../docker-compose/test8/docker-compose.yml | 119 ++++++++++++++ .../docker-compose/test9/docker-compose.yml | 111 +++++++++++++ .../nginxphp/docker-compose.nginx-1.yml | 4 +- .../nginxphp/docker-compose.servicename.yml | 4 +- internal/testdata/nginxphp/docker-compose.yml | 4 +- .../testdata/nginxphp/docker/nginx.dockerfile | 1 + .../testdata/nginxphp/docker/php.dockerfile | 1 + internal/testdata/nginxphp/lagoon.nginx-1.yml | 2 +- internal/testdata/nginxphp/lagoon.nginx-2.yml | 2 +- .../testdata/nginxphp/lagoon.servicename.yml | 2 +- internal/testdata/nginxphp/lagoon.yml | 2 +- .../node/docker-compose.autogen-1.yml | 2 +- .../node/docker-compose.autogen-2.yml | 2 +- .../node/docker-compose.autogen-3.yml | 2 +- .../testdata/node/docker-compose.none.yml | 2 +- internal/testdata/node/docker-compose.yml | 2 +- internal/testdata/node/docker/node.dockerfile | 1 + .../testdata/node/lagoon.activestandby.yml | 2 +- internal/testdata/node/lagoon.autogen-1.yml | 2 +- internal/testdata/node/lagoon.autogen-2.yml | 2 +- internal/testdata/node/lagoon.autogen-3.yml | 2 +- internal/testdata/node/lagoon.autogen-4.yml | 2 +- internal/testdata/node/lagoon.autogen-5.yml | 2 +- internal/testdata/node/lagoon.autogen-6.yml | 2 +- internal/testdata/node/lagoon.autogen-7.yml | 2 +- internal/testdata/node/lagoon.autogen-8.yml | 2 +- internal/testdata/node/lagoon.autogen-9.yml | 2 +- .../node/lagoon.autogen-prefixes-1.yml | 2 +- internal/testdata/node/lagoon.polysite-pr.yml | 2 +- internal/testdata/node/lagoon.polysite.yml | 2 +- internal/testdata/node/lagoon.yml | 2 +- internal/testdata/testdata.go | 10 +- .../cronjobs/lagoon-override-env.yml | 20 +++ .../cronjobs/lagoon-override.yml | 20 +++ .../validate-lagoon-yml/cronjobs/lagoon.yml | 49 ++++++ .../cronjobs/multiline-cronjobs.lagoon.yml | 53 +++++++ .../cronjobs/singleline-cronjobs.lagoon.yml | 46 ++++++ .../validate-lagoon-yml/test1/lagoon.yml | 22 +++ .../test2/lagoon-final.yml | 56 +++++++ .../test2/lagoon-override.yml | 20 +++ .../validate-lagoon-yml/test2/lagoon.yml | 41 +++++ .../test3/lagoon-final.yml | 56 +++++++ .../test3/lagoon-override.yml | 20 +++ .../validate-lagoon-yml/test3/lagoon.yml | 41 +++++ .../test4/lagoon-final.yml | 73 +++++++++ .../test4/lagoon-override-env.yml | 20 +++ .../test4/lagoon-override.yml | 20 +++ .../validate-lagoon-yml/test4/lagoon.yml | 41 +++++ .../test5/lagoon-final.yml | 35 ++++ .../test5/lagoon-override.yml | 8 + .../validate-lagoon-yml/test5/lagoon.yml | 37 +++++ .../test6/lagoon-final.yml | 35 ++++ .../test6/lagoon-override.yml | 9 ++ .../validate-lagoon-yml/test6/lagoon.yml | 37 +++++ .../test7/lagoon-final.yml | 35 ++++ .../test7/lagoon-override.yml | 9 ++ .../validate-lagoon-yml/test7/lagoon.yml | 37 +++++ internal/testing/testing.go | 18 +++ 107 files changed, 2454 insertions(+), 379 deletions(-) create mode 100644 internal/testdata/basic/docker/Dockerfile create mode 100644 internal/testdata/basic/docker/basic.dockerfile create mode 100644 internal/testdata/complex/docker/.docker/Dockerfile.cli create mode 100644 internal/testdata/complex/docker/.docker/Dockerfile.nginx-drupal create mode 100644 internal/testdata/complex/docker/.docker/Dockerfile.php create mode 100644 internal/testdata/complex/docker/builder.dockerfile create mode 100644 internal/testdata/complex/docker/cli.dockerfile create mode 100644 internal/testdata/complex/docker/mariadb.dockerfile create mode 100644 internal/testdata/complex/docker/nginx.dockerfile create mode 100644 internal/testdata/complex/docker/php.dockerfile create mode 100644 internal/testdata/docker-compose/test1/docker-compose.yml create mode 100644 internal/testdata/docker-compose/test10/docker-compose.yml create mode 100644 internal/testdata/docker-compose/test11/docker-compose.yml create mode 100644 internal/testdata/docker-compose/test2/docker-compose.yml create mode 100644 internal/testdata/docker-compose/test3/docker-compose.yml create mode 100644 internal/testdata/docker-compose/test4/docker-compose.yml create mode 100644 internal/testdata/docker-compose/test5/docker-compose.yml create mode 100644 internal/testdata/docker-compose/test6/docker-compose.yml create mode 100644 internal/testdata/docker-compose/test7/docker-compose.yml create mode 100644 internal/testdata/docker-compose/test8/docker-compose.yml create mode 100644 internal/testdata/docker-compose/test9/docker-compose.yml create mode 100644 internal/testdata/nginxphp/docker/nginx.dockerfile create mode 100644 internal/testdata/nginxphp/docker/php.dockerfile create mode 100644 internal/testdata/node/docker/node.dockerfile create mode 100644 internal/testdata/validate-lagoon-yml/cronjobs/lagoon-override-env.yml create mode 100644 internal/testdata/validate-lagoon-yml/cronjobs/lagoon-override.yml create mode 100644 internal/testdata/validate-lagoon-yml/cronjobs/lagoon.yml create mode 100644 internal/testdata/validate-lagoon-yml/cronjobs/multiline-cronjobs.lagoon.yml create mode 100644 internal/testdata/validate-lagoon-yml/cronjobs/singleline-cronjobs.lagoon.yml create mode 100644 internal/testdata/validate-lagoon-yml/test1/lagoon.yml create mode 100644 internal/testdata/validate-lagoon-yml/test2/lagoon-final.yml create mode 100644 internal/testdata/validate-lagoon-yml/test2/lagoon-override.yml create mode 100644 internal/testdata/validate-lagoon-yml/test2/lagoon.yml create mode 100644 internal/testdata/validate-lagoon-yml/test3/lagoon-final.yml create mode 100644 internal/testdata/validate-lagoon-yml/test3/lagoon-override.yml create mode 100644 internal/testdata/validate-lagoon-yml/test3/lagoon.yml create mode 100644 internal/testdata/validate-lagoon-yml/test4/lagoon-final.yml create mode 100644 internal/testdata/validate-lagoon-yml/test4/lagoon-override-env.yml create mode 100644 internal/testdata/validate-lagoon-yml/test4/lagoon-override.yml create mode 100644 internal/testdata/validate-lagoon-yml/test4/lagoon.yml create mode 100644 internal/testdata/validate-lagoon-yml/test5/lagoon-final.yml create mode 100644 internal/testdata/validate-lagoon-yml/test5/lagoon-override.yml create mode 100644 internal/testdata/validate-lagoon-yml/test5/lagoon.yml create mode 100644 internal/testdata/validate-lagoon-yml/test6/lagoon-final.yml create mode 100644 internal/testdata/validate-lagoon-yml/test6/lagoon-override.yml create mode 100644 internal/testdata/validate-lagoon-yml/test6/lagoon.yml create mode 100644 internal/testdata/validate-lagoon-yml/test7/lagoon-final.yml create mode 100644 internal/testdata/validate-lagoon-yml/test7/lagoon-override.yml create mode 100644 internal/testdata/validate-lagoon-yml/test7/lagoon.yml create mode 100644 internal/testing/testing.go diff --git a/cmd/identify_feature_test.go b/cmd/identify_feature_test.go index 6fa34f5f..1f26a422 100644 --- a/cmd/identify_feature_test.go +++ b/cmd/identify_feature_test.go @@ -7,6 +7,9 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" "github.com/uselagoon/build-deploy-tool/internal/testdata" + + // changes the testing to source from root so paths to test resources must be defined from repo root + _ "github.com/uselagoon/build-deploy-tool/internal/testing" ) func TestIdentifyFeatureFlag(t *testing.T) { @@ -51,7 +54,7 @@ func TestIdentifyFeatureFlag(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", @@ -60,7 +63,7 @@ func TestIdentifyFeatureFlag(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "enabled", }, { @@ -71,7 +74,7 @@ func TestIdentifyFeatureFlag(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", EnvVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", @@ -80,7 +83,7 @@ func TestIdentifyFeatureFlag(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "enabled", }, { @@ -91,9 +94,9 @@ func TestIdentifyFeatureFlag(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", vars: []helpers.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_FORCE_ROOTLESS_WORKLOAD", @@ -110,9 +113,9 @@ func TestIdentifyFeatureFlag(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", vars: []helpers.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_FORCE_ROOTLESS_WORKLOAD", @@ -133,7 +136,7 @@ func TestIdentifyFeatureFlag(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", @@ -162,7 +165,7 @@ func TestIdentifyFeatureFlag(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", diff --git a/cmd/identify_ingress_test.go b/cmd/identify_ingress_test.go index ba83a600..9eb7488b 100644 --- a/cmd/identify_ingress_test.go +++ b/cmd/identify_ingress_test.go @@ -7,6 +7,9 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/lagoon" "github.com/uselagoon/build-deploy-tool/internal/testdata" + + // changes the testing to source from root so paths to test resources must be defined from repo root + _ "github.com/uselagoon/build-deploy-tool/internal/testing" ) func TestIdentifyRoute(t *testing.T) { @@ -26,7 +29,7 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_IDS", @@ -35,7 +38,7 @@ func TestIdentifyRoute(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://example.com", wantRemain: []string{"https://node-example-project-main.example.com", "https://example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, @@ -48,7 +51,7 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_IDS", @@ -57,7 +60,7 @@ func TestIdentifyRoute(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://example.com", wantRemain: []string{"https://node-example-project-main.example.com", "https://example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, @@ -70,7 +73,7 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_ID", @@ -79,7 +82,7 @@ func TestIdentifyRoute(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://example.com", wantRemain: []string{"https://node-example-project-main.example.com", "https://example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, @@ -92,9 +95,9 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://example.com", wantRemain: []string{"https://node-example-project-main.example.com", "https://example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, @@ -107,9 +110,9 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "multiproject1", EnvironmentName: "multiproject", Branch: "multiproject", - LagoonYAML: "../internal/testdata/node/lagoon.polysite.yml", + LagoonYAML: "internal/testdata/node/lagoon.polysite.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://multiproject1.com", wantRemain: []string{"https://node-multiproject1-multiproject.example.com", "https://multiproject1.com"}, wantautoGen: []string{"https://node-multiproject1-multiproject.example.com"}, @@ -122,9 +125,9 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "multiproject2", EnvironmentName: "multiproject", Branch: "multiproject", - LagoonYAML: "../internal/testdata/node/lagoon.polysite.yml", + LagoonYAML: "internal/testdata/node/lagoon.polysite.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://multiproject2.com", wantRemain: []string{"https://node-multiproject2-multiproject.example.com", "https://multiproject2.com"}, wantautoGen: []string{"https://node-multiproject2-multiproject.example.com"}, @@ -137,9 +140,9 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "example-project", EnvironmentName: "tworoutes", Branch: "tworoutes", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://example.com", wantRemain: []string{"https://node-example-project-tworoutes.example.com", "https://example.com", "https://www.example.com"}, wantautoGen: []string{"https://node-example-project-tworoutes.example.com"}, @@ -152,9 +155,9 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "example-project", EnvironmentName: "branch-routes", Branch: "branch/routes", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://customdomain-will-be-main-domain.com", wantRemain: []string{"https://node-example-project-branch-routes.example.com", "https://customdomain-will-be-main-domain.com", "https://customdomain-will-be-not-be-main-domain.com"}, wantautoGen: []string{"https://node-example-project-branch-routes.example.com"}, @@ -169,9 +172,9 @@ func TestIdentifyRoute(t *testing.T) { Branch: "main", ActiveEnvironment: "main", StandbyEnvironment: "main-sb", - LagoonYAML: "../internal/testdata/node/lagoon.activestandby.yml", + LagoonYAML: "internal/testdata/node/lagoon.activestandby.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://active.example.com", wantRemain: []string{"https://node-example-project-main.example.com", "https://main.example.com", "https://active.example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, @@ -186,9 +189,9 @@ func TestIdentifyRoute(t *testing.T) { Branch: "main-sb", ActiveEnvironment: "main", StandbyEnvironment: "main-sb", - LagoonYAML: "../internal/testdata/node/lagoon.activestandby.yml", + LagoonYAML: "internal/testdata/node/lagoon.activestandby.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://standby.example.com", wantRemain: []string{"https://node-example-project-main-sb.example.com", "https://main-sb.example.com", "https://standby.example.com"}, wantautoGen: []string{"https://node-example-project-main-sb.example.com"}, @@ -201,9 +204,9 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "example-project", EnvironmentName: "no-ingress", Branch: "no-ingress", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://node-example-project-no-ingress.example.com", wantRemain: []string{"https://node-example-project-no-ingress.example.com"}, wantautoGen: []string{"https://node-example-project-no-ingress.example.com"}, @@ -216,9 +219,9 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "example-project", EnvironmentName: "no-ingress", Branch: "no-ingress", - LagoonYAML: "../internal/testdata/node/lagoon.autogen-prefixes-1.yml", + LagoonYAML: "internal/testdata/node/lagoon.autogen-prefixes-1.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://node-example-project-no-ingress.example.com", wantRemain: []string{ "https://node-example-project-no-ingress.example.com", @@ -243,9 +246,9 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.autogen-1.yml", + LagoonYAML: "internal/testdata/node/lagoon.autogen-1.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://example.com", wantRemain: []string{"https://example.com"}, wantautoGen: []string{}, @@ -258,9 +261,9 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "example-project", EnvironmentName: "notmain", Branch: "notmain", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://node-example-project-notmain.example.com", wantRemain: []string{"https://node-example-project-notmain.example.com"}, wantautoGen: []string{"https://node-example-project-notmain.example.com"}, @@ -274,7 +277,7 @@ func TestIdentifyRoute(t *testing.T) { EnvironmentName: "develop", Branch: "develop", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/complex/lagoon.small.yml", + LagoonYAML: "internal/testdata/complex/lagoon.small.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_SYSTEM_ROUTER_PATTERN", @@ -283,7 +286,7 @@ func TestIdentifyRoute(t *testing.T) { }, }, }, false), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://nginx-sales-customer-support-develop.ex1.example-web.com", wantRemain: []string{"https://nginx-sales-customer-support-develop.ex1.example-web.com"}, wantautoGen: []string{"https://nginx-sales-customer-support-develop.ex1.example-web.com"}, @@ -297,7 +300,7 @@ func TestIdentifyRoute(t *testing.T) { EnvironmentName: "feature-migration", Branch: "feature/migration", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/nginxphp/lagoon.nginx-2.yml", + LagoonYAML: "internal/testdata/nginxphp/lagoon.nginx-2.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_SYSTEM_ROUTER_PATTERN", @@ -306,7 +309,7 @@ func TestIdentifyRoute(t *testing.T) { }, }, }, false), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://nginx-php.feature-migration.content-example-com.example.com", wantRemain: []string{"https://nginx-php.feature-migration.content-example-com.example.com"}, wantautoGen: []string{"https://nginx-php.feature-migration.content-example-com.example.com"}, @@ -319,9 +322,9 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/complex/lagoon.small-2.yml", + LagoonYAML: "internal/testdata/complex/lagoon.small-2.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://nginx-example-project-main.example.com", wantRemain: []string{"https://nginx-example-project-main.example.com", "https://varnish-example-project-main.example.com"}, wantautoGen: []string{"https://nginx-example-project-main.example.com", "https://varnish-example-project-main.example.com"}, @@ -334,9 +337,9 @@ func TestIdentifyRoute(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/complex/lagoon.complex-2.yml", + LagoonYAML: "internal/testdata/complex/lagoon.complex-2.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "https://wild.example.com", wantRemain: []string{"https://nginx-example-project-main.example.com", "https://wild.example.com", "https://alt.example.com", "https://www.example.com", "https://en.example.com"}, wantautoGen: []string{"https://nginx-example-project-main.example.com"}, @@ -422,9 +425,9 @@ func TestCreatedIngressIdentification(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.autogen-1.yml", + LagoonYAML: "internal/testdata/node/lagoon.autogen-1.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", wantRemain: []string{"example.com"}, wantautoGen: []string{}, wantJSON: `{"primary":"","secondary":["example.com"],"autogenerated":[]}`, @@ -436,9 +439,9 @@ func TestCreatedIngressIdentification(t *testing.T) { ProjectName: "example-project", EnvironmentName: "notmain", Branch: "notmain", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", wantRemain: []string{}, wantautoGen: []string{"node"}, wantJSON: `{"primary":"","secondary":[],"autogenerated":["node"]}`, @@ -451,7 +454,7 @@ func TestCreatedIngressIdentification(t *testing.T) { EnvironmentName: "develop", Branch: "develop", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/complex/lagoon.small.yml", + LagoonYAML: "internal/testdata/complex/lagoon.small.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_SYSTEM_ROUTER_PATTERN", @@ -460,7 +463,7 @@ func TestCreatedIngressIdentification(t *testing.T) { }, }, }, false), - templatePath: "testdata/output", + templatePath: "test-resources/output", wantRemain: []string{}, wantautoGen: []string{"nginx"}, wantJSON: `{"primary":"","secondary":[],"autogenerated":["nginx"]}`, @@ -473,7 +476,7 @@ func TestCreatedIngressIdentification(t *testing.T) { EnvironmentName: "feature-migration", Branch: "feature/migration", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/nginxphp/lagoon.nginx-2.yml", + LagoonYAML: "internal/testdata/nginxphp/lagoon.nginx-2.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_SYSTEM_ROUTER_PATTERN", @@ -482,7 +485,7 @@ func TestCreatedIngressIdentification(t *testing.T) { }, }, }, false), - templatePath: "testdata/output", + templatePath: "test-resources/output", wantRemain: []string{}, wantautoGen: []string{"nginx-php"}, wantJSON: `{"primary":"","secondary":[],"autogenerated":["nginx-php"]}`, @@ -494,9 +497,9 @@ func TestCreatedIngressIdentification(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/complex/lagoon.small-2.yml", + LagoonYAML: "internal/testdata/complex/lagoon.small-2.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", wantRemain: []string{}, wantautoGen: []string{"nginx", "varnish"}, wantJSON: `{"primary":"","secondary":[],"autogenerated":["nginx","varnish"]}`, @@ -508,9 +511,9 @@ func TestCreatedIngressIdentification(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/complex/lagoon.complex-2.yml", + LagoonYAML: "internal/testdata/complex/lagoon.complex-2.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", wantRemain: []string{"wildcard-wild.example.com", "alt.example.com"}, wantautoGen: []string{"nginx"}, wantJSON: `{"primary":"","secondary":["wildcard-wild.example.com","alt.example.com"],"autogenerated":["nginx"]}`, diff --git a/cmd/identify_lagoonservices.go b/cmd/identify_lagoonservices.go index a8c77589..f8cd0161 100644 --- a/cmd/identify_lagoonservices.go +++ b/cmd/identify_lagoonservices.go @@ -77,7 +77,10 @@ func LagoonServiceTemplateIdentification(g generator.GeneratorInput) ([]identify for _, p := range dc.Ports { dcp = append(dcp, ports{Port: p.ContainerPort}) } - dcs = append(dcs, containers{Name: dc.Name, Ports: dcp}) + dcs = append(dcs, containers{ + Name: dc.Name, + Ports: dcp, + }) } lServices = append(lServices, identifyServices{ Name: d.Name, diff --git a/cmd/identify_lagoonservices_test.go b/cmd/identify_lagoonservices_test.go index b75a0d24..7c26bd4d 100644 --- a/cmd/identify_lagoonservices_test.go +++ b/cmd/identify_lagoonservices_test.go @@ -9,6 +9,9 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" "github.com/uselagoon/build-deploy-tool/internal/testdata" + + // changes the testing to source from root so paths to test resources must be defined from repo root + _ "github.com/uselagoon/build-deploy-tool/internal/testing" ) func TestIdentifyLagoonServices(t *testing.T) { @@ -25,7 +28,7 @@ func TestIdentifyLagoonServices(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/basic/lagoon.yml", + LagoonYAML: "internal/testdata/basic/lagoon.yml", ImageReferences: map[string]string{ "node": "harbor.example/example-project/main/node:latest", }, @@ -54,7 +57,7 @@ func TestIdentifyLagoonServices(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/complex/lagoon.varnish.yml", + LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", ImageReferences: map[string]string{ "nginx": "harbor.example/example-project/main/nginx:latest", "php": "harbor.example/example-project/main/php:latest", @@ -126,7 +129,7 @@ func TestIdentifyLagoonServices(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/complex/lagoon.varnish.yml", + LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", ImageReferences: map[string]string{ "nginx": "harbor.example/example-project/main/nginx:latest", "php": "harbor.example/example-project/main/php:latest", @@ -206,7 +209,7 @@ func TestIdentifyLagoonServices(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/basic/lagoon.thunderhub.yml", + LagoonYAML: "internal/testdata/basic/lagoon.thunderhub.yml", ImageReferences: map[string]string{ "lnd": "harbor.example/example-project/main/lnd:latest", "thunderhub": "harbor.example/example-project/main/thunderhub:latest", @@ -269,7 +272,7 @@ func TestIdentifyLagoonServices(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/basic/lagoon.thunderhub-2.yml", + LagoonYAML: "internal/testdata/basic/lagoon.thunderhub-2.yml", ImageReferences: map[string]string{ "lnd": "harbor.example/example-project/main/lnd:latest", "tor": "harbor.example/example-project/main/tor:latest", @@ -308,7 +311,7 @@ func TestIdentifyLagoonServices(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // set the environment variables from args - savedTemplates := "testdata/output" + savedTemplates := "test-resources/output" generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) if err != nil { t.Errorf("%v", err) diff --git a/cmd/identify_native_cronjobs_test.go b/cmd/identify_native_cronjobs_test.go index dce72fdd..37464457 100644 --- a/cmd/identify_native_cronjobs_test.go +++ b/cmd/identify_native_cronjobs_test.go @@ -8,6 +8,9 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" "github.com/uselagoon/build-deploy-tool/internal/testdata" + + // changes the testing to source from root so paths to test resources must be defined from repo root + _ "github.com/uselagoon/build-deploy-tool/internal/testing" ) func TestIdentifyNativeCronjobs(t *testing.T) { @@ -50,9 +53,9 @@ func TestIdentifyNativeCronjobs(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: "[]", }, { @@ -62,7 +65,7 @@ func TestIdentifyNativeCronjobs(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/complex/lagoon.yml", + LagoonYAML: "internal/testdata/complex/lagoon.yml", ImageReferences: map[string]string{ "nginx": "harbor.example/example-project/main/nginx:latest", "php": "harbor.example/example-project/main/php:latest", @@ -71,7 +74,7 @@ func TestIdentifyNativeCronjobs(t *testing.T) { "varnish": "harbor.example/example-project/main/varnish:latest", }, }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: `["cronjob-cli-drush-cron2"]`, }, { @@ -81,7 +84,7 @@ func TestIdentifyNativeCronjobs(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/complex/lagoon.yml", + LagoonYAML: "internal/testdata/complex/lagoon.yml", ImageReferences: map[string]string{ "nginx": "harbor.example/example-project/main/nginx:latest", "php": "harbor.example/example-project/main/php:latest", @@ -97,7 +100,7 @@ func TestIdentifyNativeCronjobs(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", want: `["cronjob-cli-drush-cron2"]`, }, } diff --git a/cmd/template_autogen_ingress_test.go b/cmd/template_autogen_ingress_test.go index 46356664..0bb4b2c9 100644 --- a/cmd/template_autogen_ingress_test.go +++ b/cmd/template_autogen_ingress_test.go @@ -10,6 +10,9 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" "github.com/uselagoon/build-deploy-tool/internal/testdata" + + // changes the testing to source from root so paths to test resources must be defined from repo root + _ "github.com/uselagoon/build-deploy-tool/internal/testing" ) func TestAutogeneratedIngressGeneration(t *testing.T) { @@ -28,10 +31,10 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-1", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-1", }, { name: "test2 no autogenerated routes but allow pullrequests", @@ -44,10 +47,10 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { PRHeadBranch: "main", PRBaseBranch: "main2", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/node/lagoon.autogen-1.yml", + LagoonYAML: "internal/testdata/node/lagoon.autogen-1.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-2", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-2", }, { name: "test3 autogenerated route but no pullrequests", @@ -60,9 +63,9 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { PRHeadBranch: "main", PRBaseBranch: "main2", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/node/lagoon.autogen-2.yml", + LagoonYAML: "internal/testdata/node/lagoon.autogen-2.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", emptyDir: true, want: "", }, @@ -73,7 +76,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_SYSTEM_ROUTER_PATTERN", @@ -82,8 +85,8 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, false), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-3", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-3", }, { name: "test5 autogenerated route short url", @@ -92,7 +95,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { ProjectName: "ci-features-control-k8s", EnvironmentName: "short-router-url-from-a-very-l-ebe8", Branch: "short-router-url-from-a-very-long-environment-name-like-this", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_SYSTEM_ROUTER_PATTERN", @@ -101,8 +104,8 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, false), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-4", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-4", }, { name: "test6 autogenerated routes but disabled by service label", @@ -111,9 +114,9 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.autogen-3.yml", + LagoonYAML: "internal/testdata/node/lagoon.autogen-3.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", emptyDir: true, want: "", }, @@ -124,10 +127,10 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.autogen-4.yml", + LagoonYAML: "internal/testdata/node/lagoon.autogen-4.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-5", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-5", }, { name: "test8 autogenerated routes with fastly", @@ -136,7 +139,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_ID", @@ -150,8 +153,8 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-6", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-6", }, { name: "test9 autogenerated routes with fastly specific domain", @@ -160,7 +163,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_IDS", @@ -174,8 +177,8 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-7", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-7", }, { name: "test10 autogenerated routes with fastly and specific secret", @@ -184,7 +187,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_ID", @@ -198,8 +201,8 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-8", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-8", }, { name: "test11 autogenerated route development environment", @@ -209,10 +212,10 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentName: "main", Branch: "main", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-9", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-9", }, { name: "test12 autogenerated route development environment - no insecure redirect", @@ -222,10 +225,10 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentName: "main", Branch: "main", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/node/lagoon.autogen-5.yml", + LagoonYAML: "internal/testdata/node/lagoon.autogen-5.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-10", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-10", }, { name: "test13 autogenerated route development service type override", @@ -235,7 +238,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentName: "main", Branch: "main", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_SERVICE_TYPES", @@ -244,8 +247,8 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-11", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-11", }, { name: "test14 autogenerated route development no service type override", @@ -255,9 +258,9 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentName: "main", Branch: "main", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/node/lagoon.autogen-6.yml", + LagoonYAML: "internal/testdata/node/lagoon.autogen-6.yml", }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", emptyDir: true, want: "", }, @@ -269,10 +272,10 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentName: "main", Branch: "main", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/nginxphp/lagoon.yml", + LagoonYAML: "internal/testdata/nginxphp/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/nginxphp/autogen-templates/ingress-1", + templatePath: "test-resources/output", + want: "internal/testdata/nginxphp/autogen-templates/ingress-1", }, { name: "test16 autogenerated route development service name override", @@ -282,10 +285,10 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentName: "main", Branch: "main", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/nginxphp/lagoon.servicename.yml", + LagoonYAML: "internal/testdata/nginxphp/lagoon.servicename.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/nginxphp/autogen-templates/ingress-2", + templatePath: "test-resources/output", + want: "internal/testdata/nginxphp/autogen-templates/ingress-2", }, { name: "test17 autogenerated route development service type override", @@ -295,7 +298,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentName: "drush-first", Branch: "drush-first", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/complex/lagoon.small.yml", + LagoonYAML: "internal/testdata/complex/lagoon.small.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_SYSTEM_ROUTER_PATTERN", @@ -304,8 +307,8 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, false), - templatePath: "testdata/output", - want: "../internal/testdata/complex/autogen-templates/ingress-1", + templatePath: "test-resources/output", + want: "internal/testdata/complex/autogen-templates/ingress-1", }, { name: "test18 autogenerated route tls-acme disabled", @@ -315,10 +318,10 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentName: "main", Branch: "main", EnvironmentType: "production", - LagoonYAML: "../internal/testdata/node/lagoon.autogen-7.yml", + LagoonYAML: "internal/testdata/node/lagoon.autogen-7.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-12", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-12", }, { name: "test19 autogenerated routes but tls-acme disabled by service label", @@ -328,10 +331,10 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentName: "main", Branch: "main", EnvironmentType: "production", - LagoonYAML: "../internal/testdata/node/lagoon.autogen-8.yml", + LagoonYAML: "internal/testdata/node/lagoon.autogen-8.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-13", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-13", }, { name: "test20 autogenerated routes where lagoon.name of service does not match service names", @@ -341,7 +344,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentName: "feature-migration", Branch: "feature/migration", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/complex/lagoon.yml", + LagoonYAML: "internal/testdata/complex/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_SYSTEM_ROUTER_PATTERN", @@ -350,8 +353,8 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, false), - templatePath: "testdata/output", - want: "../internal/testdata/complex/autogen-templates/ingress-2", + templatePath: "test-resources/output", + want: "internal/testdata/complex/autogen-templates/ingress-2", }, { name: "test21 autogenerated routes where docker-compose env_file has missing file references", @@ -361,7 +364,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentName: "feature", Branch: "feature", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/complex/lagoon.complex-1.yml", + LagoonYAML: "internal/testdata/complex/lagoon.complex-1.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_SYSTEM_ROUTER_PATTERN", @@ -370,8 +373,8 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, false), - templatePath: "testdata/output", - want: "../internal/testdata/complex/autogen-templates/ingress-3", + templatePath: "test-resources/output", + want: "internal/testdata/complex/autogen-templates/ingress-3", }, { name: "test22 autogenerated routes where should truncate long dns", @@ -384,7 +387,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { PRNumber: "123", PRHeadBranch: "main", PRBaseBranch: "main2", - LagoonYAML: "../internal/testdata/nginxphp/lagoon.nginx-1.yml", + LagoonYAML: "internal/testdata/nginxphp/lagoon.nginx-1.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_SYSTEM_ROUTER_PATTERN", @@ -393,8 +396,8 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, false), - templatePath: "testdata/output", - want: "../internal/testdata/nginxphp/autogen-templates/ingress-3", + templatePath: "test-resources/output", + want: "internal/testdata/nginxphp/autogen-templates/ingress-3", }, { name: "test23 autogenerated routes with fastly service, should be no fastly annotations on autogenerated route", @@ -403,7 +406,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_ID", @@ -412,8 +415,8 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-14", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-14", }, { name: "test24 autogenerated routes with 'string true enabled' with fastly service, should be no fastly annotations on autogenerated route", @@ -422,7 +425,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.autogen-9.yml", + LagoonYAML: "internal/testdata/node/lagoon.autogen-9.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_ID", @@ -431,8 +434,8 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/autogen-templates/ingress-14", + templatePath: "test-resources/output", + want: "internal/testdata/node/autogen-templates/ingress-14", }, { name: "test25 autogenerated routes enabled globally but disabled by environment", @@ -441,7 +444,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { ProjectName: "example-project", EnvironmentName: "autogendisabled", Branch: "autogendisabled", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_ID", @@ -450,7 +453,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", emptyDir: true, want: "", }, @@ -461,7 +464,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { ProjectName: "multiproject3", EnvironmentName: "autogendisabled", Branch: "autogendisabled", - LagoonYAML: "../internal/testdata/node/lagoon.polysite.yml", + LagoonYAML: "internal/testdata/node/lagoon.polysite.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_ID", @@ -470,7 +473,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", + templatePath: "test-resources/output", emptyDir: true, want: "", }, diff --git a/cmd/template_backups_test.go b/cmd/template_backups_test.go index 446b21c9..ccdc28ee 100644 --- a/cmd/template_backups_test.go +++ b/cmd/template_backups_test.go @@ -10,6 +10,9 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" "github.com/uselagoon/build-deploy-tool/internal/testdata" + + // changes the testing to source from root so paths to test resources must be defined from repo root + _ "github.com/uselagoon/build-deploy-tool/internal/testing" ) func TestBackupTemplateGeneration(t *testing.T) { @@ -27,7 +30,7 @@ func TestBackupTemplateGeneration(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/complex/lagoon.yml", + LagoonYAML: "internal/testdata/complex/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_IMAGECACHE_REGISTRY", @@ -36,8 +39,8 @@ func TestBackupTemplateGeneration(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/complex/backup-templates/backup-1", + templatePath: "test-resources/output", + want: "internal/testdata/complex/backup-templates/backup-1", }, { name: "test2 - custom dev only schedule but global config change enabled", @@ -47,7 +50,7 @@ func TestBackupTemplateGeneration(t *testing.T) { EnvironmentName: "main", Branch: "main", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG", @@ -61,8 +64,8 @@ func TestBackupTemplateGeneration(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/backup-templates/backup-1", + templatePath: "test-resources/output", + want: "internal/testdata/node/backup-templates/backup-1", }, { name: "test3 - custom dev only schedule but global config change not configured (use defaults)", @@ -72,7 +75,7 @@ func TestBackupTemplateGeneration(t *testing.T) { EnvironmentName: "main", Branch: "main", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_BACKUP_DEV_SCHEDULE", @@ -81,8 +84,8 @@ func TestBackupTemplateGeneration(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/backup-templates/backup-2", + templatePath: "test-resources/output", + want: "internal/testdata/node/backup-templates/backup-2", }, { name: "test4 - custom schedule and custom backup keys", @@ -95,7 +98,7 @@ func TestBackupTemplateGeneration(t *testing.T) { PRNumber: "123", PRHeadBranch: "main", PRBaseBranch: "main2", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG", @@ -109,8 +112,8 @@ func TestBackupTemplateGeneration(t *testing.T) { {Name: "LAGOON_BACKUP_PR_SCHEDULE", Value: "3,33 12 * * *", Scope: "build"}, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/backup-templates/backup-3", + templatePath: "test-resources/output", + want: "internal/testdata/node/backup-templates/backup-3", }, { name: "test5 - custom schedule and custom restore keys", @@ -123,7 +126,7 @@ func TestBackupTemplateGeneration(t *testing.T) { PRNumber: "123", PRHeadBranch: "main", PRBaseBranch: "main2", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG", @@ -137,8 +140,8 @@ func TestBackupTemplateGeneration(t *testing.T) { {Name: "LAGOON_BACKUP_PR_SCHEDULE", Value: "3,33 12 * * *", Scope: "build"}, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/backup-templates/backup-4", + templatePath: "test-resources/output", + want: "internal/testdata/node/backup-templates/backup-4", }, { name: "test6 - generic backup", @@ -148,10 +151,10 @@ func TestBackupTemplateGeneration(t *testing.T) { EnvironmentName: "main", Branch: "main", EnvironmentType: "production", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/backup-templates/backup-5", + templatePath: "test-resources/output", + want: "internal/testdata/node/backup-templates/backup-5", }, { name: "test7 - changed default backup schedule", @@ -162,10 +165,10 @@ func TestBackupTemplateGeneration(t *testing.T) { Branch: "main", EnvironmentType: "production", DefaultBackupSchedule: "M */6 * * *", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/backup-templates/backup-6", + templatePath: "test-resources/output", + want: "internal/testdata/node/backup-templates/backup-6", }, { name: "test8 - change the image registry used for prebackup pods k8upv2", @@ -175,7 +178,7 @@ func TestBackupTemplateGeneration(t *testing.T) { EnvironmentName: "main", Branch: "main", K8UPVersion: "v2", - LagoonYAML: "../internal/testdata/complex/lagoon.yml", + LagoonYAML: "internal/testdata/complex/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_IMAGECACHE_REGISTRY", @@ -184,8 +187,8 @@ func TestBackupTemplateGeneration(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/complex/backup-templates/backup-2", + templatePath: "test-resources/output", + want: "internal/testdata/complex/backup-templates/backup-2", }, } for _, tt := range tests { diff --git a/cmd/template_dbaas_test.go b/cmd/template_dbaas_test.go index a245787e..fd85282c 100644 --- a/cmd/template_dbaas_test.go +++ b/cmd/template_dbaas_test.go @@ -9,6 +9,9 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/testdata" + + // changes the testing to source from root so paths to test resources must be defined from repo root + _ "github.com/uselagoon/build-deploy-tool/internal/testing" ) func TestDBaaSTemplateGeneration(t *testing.T) { @@ -26,10 +29,10 @@ func TestDBaaSTemplateGeneration(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/complex/lagoon.yml", + LagoonYAML: "internal/testdata/complex/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/complex/dbaas-templates/dbaas-1", + templatePath: "test-resources/output", + want: "internal/testdata/complex/dbaas-templates/dbaas-1", }, } for _, tt := range tests { diff --git a/cmd/template_ingress_test.go b/cmd/template_ingress_test.go index 64cb341f..a7e8bcc8 100644 --- a/cmd/template_ingress_test.go +++ b/cmd/template_ingress_test.go @@ -10,6 +10,9 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" "github.com/uselagoon/build-deploy-tool/internal/testdata" + + // changes the testing to source from root so paths to test resources must be defined from repo root + _ "github.com/uselagoon/build-deploy-tool/internal/testing" ) func TestTemplateRoutes(t *testing.T) { @@ -26,7 +29,7 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_IDS", @@ -35,8 +38,8 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-1", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-1", }, { name: "test2 check LAGOON_FASTLY_SERVICE_IDS no secret and no values", @@ -45,7 +48,7 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_IDS", @@ -54,8 +57,8 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-2", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-2", }, { name: "test3 check LAGOON_FASTLY_SERVICE_ID no secret and no values", @@ -64,7 +67,7 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_ID", @@ -73,8 +76,8 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-3", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-3", }, { name: "test4 check no fastly and no values", @@ -83,10 +86,10 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-4", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-4", }, { name: "test5 multiproject1 no values", @@ -95,10 +98,10 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "multiproject1", EnvironmentName: "multiproject", Branch: "multiproject", - LagoonYAML: "../internal/testdata/node/lagoon.polysite.yml", + LagoonYAML: "internal/testdata/node/lagoon.polysite.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-5", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-5", }, { name: "test6 multiproject2 no values", @@ -107,10 +110,10 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "multiproject2", EnvironmentName: "multiproject", Branch: "multiproject", - LagoonYAML: "../internal/testdata/node/lagoon.polysite.yml", + LagoonYAML: "internal/testdata/node/lagoon.polysite.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-6", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-6", }, { name: "test7 multidomain no values", @@ -119,10 +122,10 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "example-project", EnvironmentName: "tworoutes", Branch: "tworoutes", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-7", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-7", }, { name: "test8 multidomain no values", @@ -131,10 +134,10 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "example-project", EnvironmentName: "branch-routes", Branch: "branch/routes", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-8", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-8", }, { name: "test9 active no values", @@ -145,10 +148,10 @@ func TestTemplateRoutes(t *testing.T) { Branch: "main", ActiveEnvironment: "main", StandbyEnvironment: "main-sb", - LagoonYAML: "../internal/testdata/node/lagoon.activestandby.yml", + LagoonYAML: "internal/testdata/node/lagoon.activestandby.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-9", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-9", }, { name: "test10 standby no values", @@ -159,10 +162,10 @@ func TestTemplateRoutes(t *testing.T) { Branch: "main-sb", ActiveEnvironment: "main", StandbyEnvironment: "main-sb", - LagoonYAML: "../internal/testdata/node/lagoon.activestandby.yml", + LagoonYAML: "internal/testdata/node/lagoon.activestandby.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-10", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-10", }, { name: "test11 standby no values", @@ -171,10 +174,10 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "content-example-com", EnvironmentName: "production", Branch: "production", - LagoonYAML: "../internal/testdata/complex/lagoon.yml", + LagoonYAML: "internal/testdata/complex/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/complex/ingress-templates/ingress-1", + templatePath: "test-resources/output", + want: "internal/testdata/complex/ingress-templates/ingress-1", }, { name: "test12 check LAGOON_ROUTES_JSON generates ingress", @@ -183,7 +186,7 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "example-project", EnvironmentName: "noyamlroutes", Branch: "noyamlroutes", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_IDS", @@ -197,8 +200,8 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-11", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-11", }, { name: "test13 ingress class from default flag", @@ -208,10 +211,10 @@ func TestTemplateRoutes(t *testing.T) { EnvironmentName: "main", Branch: "main", IngressClass: "nginx", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-12", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-12", }, { name: "test14 ingress class from lagoon.yml should overwrite default and featureflag variable", @@ -221,9 +224,9 @@ func TestTemplateRoutes(t *testing.T) { EnvironmentName: "ingressclass", Branch: "ingressclass", IngressClass: "nginx", - LagoonYAML: "../internal/testdata/node/lagoon.yml", - }, true), templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-13", + LagoonYAML: "internal/testdata/node/lagoon.yml", + }, true), templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-13", }, { name: "test15a ingress class from lagoon api project scope", @@ -233,7 +236,7 @@ func TestTemplateRoutes(t *testing.T) { EnvironmentName: "main", Branch: "main", IngressClass: "nginx", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_INGRESS_CLASS", @@ -242,8 +245,8 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-14", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-14", }, { name: "test15b ingress class from lagoon api environment scope", @@ -252,7 +255,7 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_INGRESS_CLASS", @@ -268,8 +271,8 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-15", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-15", }, { name: "test16 hsts basic", @@ -278,7 +281,7 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "example-project", EnvironmentName: "hsts", Branch: "hsts", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_IDS", @@ -287,8 +290,8 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-16", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-16", }, { name: "test17 hsts advanced", @@ -297,7 +300,7 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "example-project", EnvironmentName: "hsts2", Branch: "hsts2", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FASTLY_SERVICE_IDS", @@ -306,8 +309,8 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-17", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-17", }, { name: "test18 check first route has monitoring only", @@ -316,10 +319,10 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "example-project", EnvironmentName: "tworoutes", Branch: "tworoutes", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-18", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-18", }, { name: "test19 pullrequest routes", @@ -332,10 +335,10 @@ func TestTemplateRoutes(t *testing.T) { PRHeadBranch: "main", PRBaseBranch: "my-branch", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-19", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-19", }, { name: "test20 pullrequest routes polysite", @@ -348,10 +351,10 @@ func TestTemplateRoutes(t *testing.T) { PRHeadBranch: "main", PRBaseBranch: "my-branch", EnvironmentType: "development", - LagoonYAML: "../internal/testdata/node/lagoon.polysite-pr.yml", + LagoonYAML: "internal/testdata/node/lagoon.polysite-pr.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-20", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-20", }, { name: "test21 alternative names", @@ -360,10 +363,10 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "example-project", EnvironmentName: "alternativename", Branch: "alternativename", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-21", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-21", }, { name: "test22 check wildcard", @@ -372,10 +375,10 @@ func TestTemplateRoutes(t *testing.T) { ProjectName: "example-project", EnvironmentName: "wildcard", Branch: "wildcard", - LagoonYAML: "../internal/testdata/node/lagoon.yml", + LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "testdata/output", - want: "../internal/testdata/node/ingress-templates/ingress-22", + templatePath: "test-resources/output", + want: "internal/testdata/node/ingress-templates/ingress-22", }, } for _, tt := range tests { diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index 0c170eb7..fab1121c 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -11,6 +11,9 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" "github.com/uselagoon/build-deploy-tool/internal/testdata" + + // changes the testing to source from root so paths to test resources must be defined from repo root + _ "github.com/uselagoon/build-deploy-tool/internal/testing" ) func TestTemplateLagoonServices(t *testing.T) { @@ -28,13 +31,13 @@ func TestTemplateLagoonServices(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/basic/lagoon.yml", + LagoonYAML: "internal/testdata/basic/lagoon.yml", ImageReferences: map[string]string{ "node": "harbor.example/example-project/main/node:latest", }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/basic/service-templates/service1", + templatePath: "test-resources/output", + want: "internal/testdata/basic/service-templates/service1", }, { name: "test2a nginx-php deployment", @@ -43,7 +46,7 @@ func TestTemplateLagoonServices(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/complex/lagoon.varnish.yml", + LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", ImageReferences: map[string]string{ "nginx": "harbor.example/example-project/main/nginx:latest", "php": "harbor.example/example-project/main/php:latest", @@ -52,8 +55,8 @@ func TestTemplateLagoonServices(t *testing.T) { "varnish": "harbor.example/example-project/main/varnish:latest", }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/complex/service-templates/service1", + templatePath: "test-resources/output", + want: "internal/testdata/complex/service-templates/service1", }, { name: "test2b nginx-php deployment - rootless", @@ -62,7 +65,7 @@ func TestTemplateLagoonServices(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/complex/lagoon.varnish.yml", + LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", ImageReferences: map[string]string{ "nginx": "harbor.example/example-project/main/nginx:latest", "php": "harbor.example/example-project/main/php:latest", @@ -78,8 +81,8 @@ func TestTemplateLagoonServices(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/complex/service-templates/service2", + templatePath: "test-resources/output", + want: "internal/testdata/complex/service-templates/service2", }, { name: "test3 - funky pvcs", @@ -89,7 +92,7 @@ func TestTemplateLagoonServices(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/basic/lagoon.thunderhub.yml", + LagoonYAML: "internal/testdata/basic/lagoon.thunderhub.yml", ImageReferences: map[string]string{ "lnd": "harbor.example/example-project/main/lnd:latest", "thunderhub": "harbor.example/example-project/main/thunderhub:latest", @@ -103,8 +106,8 @@ func TestTemplateLagoonServices(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/basic/service-templates/service2", + templatePath: "test-resources/output", + want: "internal/testdata/basic/service-templates/service2", }, { name: "test4 - basic-persistent with worker-persistent", @@ -114,7 +117,7 @@ func TestTemplateLagoonServices(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/basic/lagoon.thunderhub-2.yml", + LagoonYAML: "internal/testdata/basic/lagoon.thunderhub-2.yml", ImageReferences: map[string]string{ "lnd": "harbor.example/example-project/main/lnd:latest", "tor": "harbor.example/example-project/main/tor:latest", @@ -127,8 +130,8 @@ func TestTemplateLagoonServices(t *testing.T) { }, }, }, true), - templatePath: "testdata/output", - want: "../internal/testdata/basic/service-templates/service3", + templatePath: "test-resources/output", + want: "internal/testdata/basic/service-templates/service3", }, } for _, tt := range tests { diff --git a/cmd/validate_compose_test.go b/cmd/validate_compose_test.go index 2f5a8688..659dffa6 100644 --- a/cmd/validate_compose_test.go +++ b/cmd/validate_compose_test.go @@ -3,6 +3,9 @@ package cmd import ( "strings" "testing" + + // changes the testing to source from root so paths to test resources must be defined from repo root + _ "github.com/uselagoon/build-deploy-tool/internal/testing" ) func TestValidateDockerCompose(t *testing.T) { @@ -20,31 +23,31 @@ func TestValidateDockerCompose(t *testing.T) { { name: "test1 complex docker-compose", args: args{ - file: "../test-resources/docker-compose/test3/docker-compose.yml", + file: "internal/testdata/docker-compose/test3/docker-compose.yml", }, }, { name: "test2 complex docker-compose", args: args{ - file: "../test-resources/docker-compose/test4/docker-compose.yml", + file: "internal/testdata/docker-compose/test4/docker-compose.yml", }, }, { name: "test3 complex docker-compose", args: args{ - file: "../test-resources/docker-compose/test5/docker-compose.yml", + file: "internal/testdata/docker-compose/test5/docker-compose.yml", }, }, { name: "test4 complex docker-compose", args: args{ - file: "../test-resources/docker-compose/test6/docker-compose.yml", + file: "internal/testdata/docker-compose/test6/docker-compose.yml", }, }, { name: "test5 check an invalid docker-compose", args: args{ - file: "../test-resources/docker-compose/test7/docker-compose.yml", + file: "internal/testdata/docker-compose/test7/docker-compose.yml", }, wantErr: true, wantErrMsg: "Non-string key in x-site-branch: ", @@ -52,14 +55,14 @@ func TestValidateDockerCompose(t *testing.T) { { name: "test6 check an invalid docker-compose (same as test5 but ignoring the errors)", args: args{ - file: "../test-resources/docker-compose/test8/docker-compose.yml", + file: "internal/testdata/docker-compose/test8/docker-compose.yml", ignoreNonStringKeyErrors: true, }, }, { name: "test7 check an valid docker-compose with missing env_files ", args: args{ - file: "../test-resources/docker-compose/test10/docker-compose.yml", + file: "internal/testdata/docker-compose/test10/docker-compose.yml", }, wantErr: true, wantErrMsg: "no such file or directory", @@ -67,7 +70,7 @@ func TestValidateDockerCompose(t *testing.T) { { name: "test8 check an valid docker-compose with missing env_files (same as test7 but ignoring the missing file errors)", args: args{ - file: "../test-resources/docker-compose/test9/docker-compose.yml", + file: "internal/testdata/docker-compose/test9/docker-compose.yml", ignoreNonStringKeyErrors: true, ignoreMissingEnvFiles: true, }, diff --git a/cmd/validate_lagoonyml_test.go b/cmd/validate_lagoonyml_test.go index 8558334c..0372345f 100644 --- a/cmd/validate_lagoonyml_test.go +++ b/cmd/validate_lagoonyml_test.go @@ -10,6 +10,9 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/lagoon" "sigs.k8s.io/yaml" + + // changes the testing to source from root so paths to test resources must be defined from repo root + _ "github.com/uselagoon/build-deploy-tool/internal/testing" ) func TestValidateLagoonYml(t *testing.T) { @@ -30,8 +33,8 @@ func TestValidateLagoonYml(t *testing.T) { { name: "test 1 - Simple .lagoon.yml - testing equality", args: args{ - lagoonYml: "../test-resources/validate-lagoon-yml/test1/lagoon.yml", - wantLagoonYml: "../test-resources/validate-lagoon-yml/test1/lagoon.yml", + lagoonYml: "internal/testdata/validate-lagoon-yml/test1/lagoon.yml", + wantLagoonYml: "internal/testdata/validate-lagoon-yml/test1/lagoon.yml", lYAML: &lagoon.YAML{}, projectName: "", debug: false, @@ -41,9 +44,9 @@ func TestValidateLagoonYml(t *testing.T) { { name: "test 2 - Merging files - no env vars", args: args{ - lagoonYml: "../test-resources/validate-lagoon-yml/test2/lagoon.yml", - lagoonOverrideYml: "../test-resources/validate-lagoon-yml/test2/lagoon-override.yml", - wantLagoonYml: "../test-resources/validate-lagoon-yml/test2/lagoon-final.yml", + lagoonYml: "internal/testdata/validate-lagoon-yml/test2/lagoon.yml", + lagoonOverrideYml: "internal/testdata/validate-lagoon-yml/test2/lagoon-override.yml", + wantLagoonYml: "internal/testdata/validate-lagoon-yml/test2/lagoon-final.yml", lYAML: &lagoon.YAML{}, projectName: "", debug: false, @@ -53,9 +56,9 @@ func TestValidateLagoonYml(t *testing.T) { { name: "test 3 - Merging env vars - no override", args: args{ - lagoonYml: "../test-resources/validate-lagoon-yml/test3/lagoon.yml", - lagoonOverrideEnvVarFile: "../test-resources/validate-lagoon-yml/test3/lagoon-override.yml", - wantLagoonYml: "../test-resources/validate-lagoon-yml/test3/lagoon-final.yml", + lagoonYml: "internal/testdata/validate-lagoon-yml/test3/lagoon.yml", + lagoonOverrideEnvVarFile: "internal/testdata/validate-lagoon-yml/test3/lagoon-override.yml", + wantLagoonYml: "internal/testdata/validate-lagoon-yml/test3/lagoon-final.yml", lYAML: &lagoon.YAML{}, projectName: "", debug: false, @@ -65,10 +68,10 @@ func TestValidateLagoonYml(t *testing.T) { { name: "test 4 - Merging env vars and override file", args: args{ - lagoonYml: "../test-resources/validate-lagoon-yml/test4/lagoon.yml", - lagoonOverrideYml: "../test-resources/validate-lagoon-yml/test4/lagoon-override.yml", - lagoonOverrideEnvVarFile: "../test-resources/validate-lagoon-yml/test4/lagoon-override-env.yml", - wantLagoonYml: "../test-resources/validate-lagoon-yml/test4/lagoon-final.yml", + lagoonYml: "internal/testdata/validate-lagoon-yml/test4/lagoon.yml", + lagoonOverrideYml: "internal/testdata/validate-lagoon-yml/test4/lagoon-override.yml", + lagoonOverrideEnvVarFile: "internal/testdata/validate-lagoon-yml/test4/lagoon-override-env.yml", + wantLagoonYml: "internal/testdata/validate-lagoon-yml/test4/lagoon-final.yml", lYAML: &lagoon.YAML{}, projectName: "", debug: false, @@ -78,9 +81,9 @@ func TestValidateLagoonYml(t *testing.T) { { name: "test 5 - Overriding named task", args: args{ - lagoonYml: "../test-resources/validate-lagoon-yml/test5/lagoon.yml", - lagoonOverrideYml: "../test-resources/validate-lagoon-yml/test5/lagoon-override.yml", - wantLagoonYml: "../test-resources/validate-lagoon-yml/test5/lagoon-final.yml", + lagoonYml: "internal/testdata/validate-lagoon-yml/test5/lagoon.yml", + lagoonOverrideYml: "internal/testdata/validate-lagoon-yml/test5/lagoon-override.yml", + wantLagoonYml: "internal/testdata/validate-lagoon-yml/test5/lagoon-final.yml", lYAML: &lagoon.YAML{}, projectName: "", debug: false, @@ -90,8 +93,8 @@ func TestValidateLagoonYml(t *testing.T) { { name: "test 6 - Invalid lagoon override should fail", args: args{ - lagoonYml: "../test-resources/validate-lagoon-yml/test6/lagoon.yml", - lagoonOverrideYml: "../test-resources/validate-lagoon-yml/test6/lagoon-override.yml", + lagoonYml: "internal/testdata/validate-lagoon-yml/test6/lagoon.yml", + lagoonOverrideYml: "internal/testdata/validate-lagoon-yml/test6/lagoon-override.yml", lYAML: &lagoon.YAML{}, projectName: "", debug: false, @@ -101,8 +104,8 @@ func TestValidateLagoonYml(t *testing.T) { { name: "test 7 - Invalid lagoon override env var should fail", args: args{ - lagoonYml: "../test-resources/validate-lagoon-yml/test6/lagoon.yml", - lagoonOverrideEnvVarFile: "../test-resources/validate-lagoon-yml/test6/lagoon-override.yml", + lagoonYml: "internal/testdata/validate-lagoon-yml/test6/lagoon.yml", + lagoonOverrideEnvVarFile: "internal/testdata/validate-lagoon-yml/test6/lagoon-override.yml", lYAML: &lagoon.YAML{}, projectName: "", debug: false, @@ -112,7 +115,7 @@ func TestValidateLagoonYml(t *testing.T) { { name: "multiline cronjobs should fail validation", args: args{ - lagoonYml: "../test-resources/validate-lagoon-yml/cronjobs/lagoon.yml", + lagoonYml: "internal/testdata/validate-lagoon-yml/cronjobs/lagoon.yml", lYAML: &lagoon.YAML{}, projectName: "", debug: false, @@ -122,9 +125,9 @@ func TestValidateLagoonYml(t *testing.T) { { name: "merged multiline cronjobs should fail validation", args: args{ - lagoonYml: "../test-resources/validate-lagoon-yml/cronjobs/lagoon.yml", - lagoonOverrideYml: "../test-resources/validate-lagoon-yml/cronjobs/lagoon-override.yml", - lagoonOverrideEnvVarFile: "../test-resources/validate-lagoon-yml/cronjobs/lagoon-override-env.yml", + lagoonYml: "internal/testdata/validate-lagoon-yml/cronjobs/lagoon.yml", + lagoonOverrideYml: "internal/testdata/validate-lagoon-yml/cronjobs/lagoon-override.yml", + lagoonOverrideEnvVarFile: "internal/testdata/validate-lagoon-yml/cronjobs/lagoon-override-env.yml", lYAML: &lagoon.YAML{}, projectName: "", debug: false, @@ -183,7 +186,7 @@ func TestValidateLagoonYml(t *testing.T) { func TestMultilineCronjobs(t *testing.T) { var l lagoon.YAML - if err := generator.LoadAndUnmarshalLagoonYml("../test-resources/validate-lagoon-yml/cronjobs/multiline-cronjobs.lagoon.yml", "", "", &l, "", false); err != nil { + if err := generator.LoadAndUnmarshalLagoonYml("internal/testdata/validate-lagoon-yml/cronjobs/multiline-cronjobs.lagoon.yml", "", "", &l, "", false); err != nil { t.Fatalf("couldn't load and unmarshal YAML: %v", err) } @@ -204,7 +207,7 @@ func TestMultilineCronjobs(t *testing.T) { func TestSinglelineCronjobs(t *testing.T) { var l lagoon.YAML - if err := generator.LoadAndUnmarshalLagoonYml("../test-resources/validate-lagoon-yml/cronjobs/singleline-cronjobs.lagoon.yml", "", "", &l, "", false); err != nil { + if err := generator.LoadAndUnmarshalLagoonYml("internal/testdata/validate-lagoon-yml/cronjobs/singleline-cronjobs.lagoon.yml", "", "", &l, "", false); err != nil { t.Fatalf("couldn't load and unmarshal YAML: %v", err) } diff --git a/internal/lagoon/compose_test.go b/internal/lagoon/compose_test.go index 636134f9..1179b910 100644 --- a/internal/lagoon/compose_test.go +++ b/internal/lagoon/compose_test.go @@ -25,7 +25,7 @@ func TestUnmarshaDockerComposeYAML(t *testing.T) { { name: "test1 docker-compose drupal example", args: args{ - file: "../../test-resources/docker-compose/test1/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test1/docker-compose.yml", }, want: `{"name":"test1","services":{"cli":{"build":{"context":".","dockerfile":"lagoon/cli.dockerfile"},"environment":{"LAGOON_ROUTE":"http://drupal9-example-advanced.docker.amazee.io"},"image":"drupal9-example-advanced-cli","labels":{"lagoon.persistent":"/app/web/sites/default/files/","lagoon.persistent.name":"nginx","lagoon.type":"cli-persistent","lando.type":"php-cli-drupal"},"networks":{"default":null},"user":"root","volumes":[{"type":"bind","source":".","target":"/app","bind":{"create_host_path":true}},{"type":"volume","source":"files","target":"/app/web/sites/default/files","volume":{}}],"volumes_from":["container:amazeeio-ssh-agent"]},"mariadb":{"environment":{"LAGOON_ROUTE":"http://drupal9-example-advanced.docker.amazee.io"},"image":"uselagoon/mariadb-10.5-drupal:latest","labels":{"lagoon.type":"mariadb","lando.type":"mariadb-drupal"},"networks":{"default":null},"ports":[{"mode":"ingress","target":3306,"protocol":"tcp"}],"user":"1000"},"nginx":{"build":{"context":".","dockerfile":"lagoon/nginx.dockerfile","args":{"CLI_IMAGE":"drupal9-example-advanced-cli"}},"depends_on":{"cli":{"condition":"service_started"}},"environment":{"LAGOON_LOCALDEV_URL":"http://drupal9-example-advanced.docker.amazee.io","LAGOON_ROUTE":"http://drupal9-example-advanced.docker.amazee.io"},"labels":{"lagoon.persistent":"/app/web/sites/default/files/","lagoon.type":"nginx-php-persistent","lando.type":"nginx-drupal"},"networks":{"amazeeio-network":null,"default":null},"user":"1000","volumes":[{"type":"bind","source":".","target":"/app","bind":{"create_host_path":true}},{"type":"volume","source":"files","target":"/app/web/sites/default/files","volume":{}}]},"php":{"build":{"context":".","dockerfile":"lagoon/php.dockerfile","args":{"CLI_IMAGE":"drupal9-example-advanced-cli"}},"depends_on":{"cli":{"condition":"service_started"}},"environment":{"LAGOON_ROUTE":"http://drupal9-example-advanced.docker.amazee.io"},"labels":{"lagoon.name":"nginx","lagoon.persistent":"/app/web/sites/default/files/","lagoon.type":"nginx-php-persistent","lando.type":"php-fpm"},"networks":{"default":null},"user":"1000","volumes":[{"type":"bind","source":".","target":"/app","bind":{"create_host_path":true}},{"type":"volume","source":"files","target":"/app/web/sites/default/files","volume":{}}]},"redis":{"environment":{"LAGOON_ROUTE":"http://drupal9-example-advanced.docker.amazee.io"},"image":"uselagoon/redis-5:latest","labels":{"lagoon.type":"redis","lando.type":"redis"},"networks":{"default":null},"ports":[{"mode":"ingress","target":6379,"protocol":"tcp"}],"user":"1000"},"solr":{"environment":{"LAGOON_ROUTE":"http://drupal9-example-advanced.docker.amazee.io"},"image":"uselagoon/solr-7.7-drupal:latest","labels":{"lagoon.type":"solr","lando.type":"solr-drupal"},"networks":{"default":null},"ports":[{"mode":"ingress","target":8983,"protocol":"tcp"}]}},"networks":{"amazeeio-network":{"name":"amazeeio-network","ipam":{},"external":true},"default":{"name":"test1_default","ipam":{},"external":false}},"volumes":{"files":{"name":"test1_files","external":false}}}`, wantOrder: []OriginalServiceOrder{ @@ -40,7 +40,7 @@ func TestUnmarshaDockerComposeYAML(t *testing.T) { { name: "test2 docker-compose node example", args: args{ - file: "../../test-resources/docker-compose/test2/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test2/docker-compose.yml", }, want: `{"name":"test2","services":{"node":{"build":{"context":".","dockerfile":"node.dockerfile"},"environment":{"LAGOON_LOCALDEV_HTTP_PORT":"3000","LAGOON_ROUTE":"http://node.docker.amazee.io"},"labels":{"lagoon.type":"node"},"networks":{"amazeeio-network":null,"default":null},"volumes":[{"type":"bind","source":".","target":"/app","bind":{"create_host_path":true}}]}},"networks":{"amazeeio-network":{"name":"amazeeio-network","ipam":{},"external":true},"default":{"name":"test2_default","ipam":{},"external":false}}}`, wantOrder: []OriginalServiceOrder{ @@ -50,7 +50,7 @@ func TestUnmarshaDockerComposeYAML(t *testing.T) { { name: "test3 docker-compose complex", args: args{ - file: "../../test-resources/docker-compose/test3/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test3/docker-compose.yml", }, want: `{"name":"test3","services":{"cli":{"build":{"context":".","dockerfile":".lagoon/cli.dockerfile","args":{"DOCKER_CLI_IMAGE_URI":"","ENVIRONMENT_TYPE_ID":""}},"container_name":"_cli","environment":{"ENVIRONMENT_TYPE_ID":"","LAGOON_ENVIRONMENT_TYPE":"","LAGOON_PROJECT":"","LAGOON_ROUTE":"http://","PHP_MEMORY_LIMIT":"768M","XDEBUG_ENABLE":""},"labels":{"lagoon.persistent":"/app/docroot/sites/default/files/","lagoon.persistent.name":"nginx","lagoon.type":"cli-persistent"},"networks":{"default":null},"user":"root","volumes":[{"type":"bind","source":"./.lagoon/scripts/bash_prompts.rc","target":"/home/.bashrc","bind":{"create_host_path":true}},{"type":"bind","source":"./.lagoon/scripts/color_grid.sh","target":"/home/color_grid.sh","bind":{"create_host_path":true}}],"volumes_from":["container:amazeeio-ssh-agent"]},"mariadb":{"container_name":"_db","environment":{"ENVIRONMENT_TYPE_ID":"","LAGOON_ENVIRONMENT_TYPE":"","LAGOON_PROJECT":"","LAGOON_ROUTE":"http://","PHP_MEMORY_LIMIT":"768M","XDEBUG_ENABLE":""},"image":"amazeeio/mariadb-drupal","labels":{"lagoon.type":"mariadb"},"networks":{"default":null},"ports":[{"mode":"ingress","target":3306,"protocol":"tcp"}],"volumes":[{"type":"volume","source":"mysql","target":"/var/lib/mysql","volume":{}}]},"nginx":{"build":{"context":".","dockerfile":".lagoon/nginx.dockerfile","args":{"CLI_IMAGE":"","DOCKER_NGINX_IMAGE_URI":"","LAGOON_GIT_BRANCH":""}},"container_name":"_nginx","depends_on":{"cli":{"condition":"service_started"}},"environment":{"ENVIRONMENT_TYPE_ID":"","LAGOON_ENVIRONMENT_TYPE":"","LAGOON_LOCALDEV_URL":"http://","LAGOON_PROJECT":"","LAGOON_ROUTE":"http://","PHP_MEMORY_LIMIT":"768M","XDEBUG_ENABLE":""},"labels":{"lagoon.name":"nginx","lagoon.persistent":"/app/docroot/sites/default/files/","lagoon.type":"nginx-php-persistent"},"networks":{"amazeeio-network":null,"default":null},"volumes":[{"type":"bind","source":"./.lagoon/nginx/nginx-http.conf","target":"/etc/nginx/conf.d/000-nginx-http.conf","bind":{"create_host_path":true}},{"type":"bind","source":"./.lagoon/nginx/app.conf","target":"/etc/nginx/conf.d/app.conf","bind":{"create_host_path":true}}]},"php":{"build":{"context":".","dockerfile":".lagoon/php.dockerfile","args":{"CLI_IMAGE":"","DOCKER_PHP_IMAGE_URI":""}},"container_name":"_php","depends_on":{"cli":{"condition":"service_started"}},"environment":{"ENVIRONMENT_TYPE_ID":"","LAGOON_ENVIRONMENT_TYPE":"","LAGOON_PROJECT":"","LAGOON_ROUTE":"http://","PHP_MEMORY_LIMIT":"768M","XDEBUG_ENABLE":""},"labels":{"lagoon.deployment.servicetype":"php","lagoon.name":"nginx","lagoon.persistent":"/app/docroot/sites/default/files","lagoon.type":"nginx-php-persistent"},"networks":{"default":null}}},"networks":{"amazeeio-network":{"name":"amazeeio-network","ipam":{},"external":true},"default":{"name":"test3_default","ipam":{},"external":false}},"volumes":{"app":{"name":"test3_app","external":false},"mysql":{"name":"test3_mysql","external":false},"solr7":{"name":"test3_solr7","external":false}}}`, wantOrder: []OriginalServiceOrder{ @@ -63,7 +63,7 @@ func TestUnmarshaDockerComposeYAML(t *testing.T) { { name: "test4 docker-compose complex", args: args{ - file: "../../test-resources/docker-compose/test4/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test4/docker-compose.yml", }, want: `{"name":"test4","services":{"chrome":{"depends_on":{"cli":{"condition":"service_started"}},"environment":{"CKEDITOR_SCAYT_CUSTOMERID":"","CKEDITOR_SCAYT_SLANG":"","DB_ALIAS":"example.prod-left","DRUPAL_HASH_SALT":"fakehashsaltfakehashsaltfakehashsalt","DRUPAL_REFRESH_SEARCHAPI":"","EXAMPLE_IMAGE_VERSION":"latest","EXAMPLE_INGRESS_ENABLED":"","EXAMPLE_INGRESS_HEADER":"","EXAMPLE_INGRESS_PSK":"","EXAMPLE_KEY":"","GITHUB_TOKEN":"","LAGOON_ENVIRONMENT_TYPE":"local","LAGOON_LOCALDEV_URL":"http://mysite.docker.amazee.io","LAGOON_PROJECT":"mysite","LAGOON_ROUTE":"http://mysite.docker.amazee.io","PHP_MEMORY_LIMIT":"1024M","REDIS_CACHE_PREFIX":"tide_"},"image":"seleniarm/standalone-chromium:101.0","labels":{"lagoon.type":"none"},"networks":{"default":null},"shm_size":"1073741824","volumes":[{"type":"bind","source":".","target":"/app","bind":{"create_host_path":true}},{"type":"bind","source":"./docroot/sites/default/files","target":"/app/docroot/sites/default/files","bind":{"create_host_path":true}}]},"clamav":{"environment":{"CKEDITOR_SCAYT_CUSTOMERID":"","CKEDITOR_SCAYT_SLANG":"","DB_ALIAS":"example.prod-left","DRUPAL_HASH_SALT":"fakehashsaltfakehashsaltfakehashsalt","DRUPAL_REFRESH_SEARCHAPI":"","EXAMPLE_IMAGE_VERSION":"latest","EXAMPLE_INGRESS_ENABLED":"","EXAMPLE_INGRESS_HEADER":"","EXAMPLE_INGRESS_PSK":"","EXAMPLE_KEY":"","GITHUB_TOKEN":"","LAGOON_ENVIRONMENT_TYPE":"local","LAGOON_LOCALDEV_URL":"http://mysite.docker.amazee.io","LAGOON_PROJECT":"mysite","LAGOON_ROUTE":"http://mysite.docker.amazee.io","PHP_MEMORY_LIMIT":"1024M","REDIS_CACHE_PREFIX":"tide_"},"image":"clamav/example-clamav:4.x","labels":{"lagoon.type":"none"},"networks":{"default":null},"ports":[{"mode":"ingress","target":3310,"protocol":"tcp"}]},"cli":{"build":{"context":".","dockerfile":".docker/Dockerfile.cli","args":{"COMPOSER":"composer.json","EXAMPLE_IMAGE_VERSION":"4.x"}},"environment":{"CKEDITOR_SCAYT_CUSTOMERID":"","CKEDITOR_SCAYT_SLANG":"","DB_ALIAS":"example.prod-left","DRUPAL_HASH_SALT":"fakehashsaltfakehashsaltfakehashsalt","DRUPAL_REFRESH_SEARCHAPI":"","EXAMPLE_IMAGE_VERSION":"latest","EXAMPLE_INGRESS_ENABLED":"","EXAMPLE_INGRESS_HEADER":"","EXAMPLE_INGRESS_PSK":"","EXAMPLE_KEY":"","GITHUB_TOKEN":"","LAGOON_ENVIRONMENT_TYPE":"local","LAGOON_LOCALDEV_URL":"http://mysite.docker.amazee.io","LAGOON_PROJECT":"mysite","LAGOON_ROUTE":"http://mysite.docker.amazee.io","PHP_MEMORY_LIMIT":"1024M","REDIS_CACHE_PREFIX":"tide_"},"image":"mysite","labels":{"lagoon.persistent":"/app/docroot/sites/default/files/","lagoon.persistent.name":"nginx-php","lagoon.persistent.size":"50Gi","lagoon.type":"cli-persistent"},"networks":{"default":null},"volumes":[{"type":"bind","source":".","target":"/app","bind":{"create_host_path":true}},{"type":"bind","source":"./docroot/sites/default/files","target":"/app/docroot/sites/default/files","bind":{"create_host_path":true}}],"volumes_from":["container:amazeeio-ssh-agent"]},"elasticsearch":{"build":{"context":".","dockerfile":".docker/Dockerfile.elasticsearch","args":{"ES_TPL":"elasticsearch.yml"}},"labels":{"lagoon.type":"none"},"networks":{"default":null}},"mariadb":{"environment":{"CKEDITOR_SCAYT_CUSTOMERID":"","CKEDITOR_SCAYT_SLANG":"","DB_ALIAS":"example.prod-left","DRUPAL_HASH_SALT":"fakehashsaltfakehashsaltfakehashsalt","DRUPAL_REFRESH_SEARCHAPI":"","EXAMPLE_IMAGE_VERSION":"latest","EXAMPLE_INGRESS_ENABLED":"","EXAMPLE_INGRESS_HEADER":"","EXAMPLE_INGRESS_PSK":"","EXAMPLE_KEY":"","GITHUB_TOKEN":"","LAGOON_ENVIRONMENT_TYPE":"local","LAGOON_LOCALDEV_URL":"http://mysite.docker.amazee.io","LAGOON_PROJECT":"mysite","LAGOON_ROUTE":"http://mysite.docker.amazee.io","PHP_MEMORY_LIMIT":"1024M","REDIS_CACHE_PREFIX":"tide_"},"image":"uselagoon/mariadb-10.4-drupal:latest","labels":{"lagoon.type":"mariadb-shared"},"networks":{"default":null},"ports":[{"mode":"ingress","target":3306,"protocol":"tcp"}]},"nginx":{"build":{"context":".","dockerfile":".docker/Dockerfile.nginx-drupal","args":{"CLI_IMAGE":"mysite","EXAMPLE_IMAGE_VERSION":"4.x"}},"depends_on":{"cli":{"condition":"service_started"}},"environment":{"CKEDITOR_SCAYT_CUSTOMERID":"","CKEDITOR_SCAYT_SLANG":"","DB_ALIAS":"example.prod-left","DRUPAL_HASH_SALT":"fakehashsaltfakehashsaltfakehashsalt","DRUPAL_REFRESH_SEARCHAPI":"","EXAMPLE_IMAGE_VERSION":"latest","EXAMPLE_INGRESS_ENABLED":"","EXAMPLE_INGRESS_HEADER":"","EXAMPLE_INGRESS_PSK":"","EXAMPLE_KEY":"","GITHUB_TOKEN":"","LAGOON_ENVIRONMENT_TYPE":"local","LAGOON_LOCALDEV_URL":"http://mysite.docker.amazee.io","LAGOON_PROJECT":"mysite","LAGOON_ROUTE":"http://mysite.docker.amazee.io","PHP_MEMORY_LIMIT":"1024M","REDIS_CACHE_PREFIX":"tide_"},"expose":["8080"],"labels":{"lagoon.name":"nginx-php","lagoon.persistent":"/app/docroot/sites/default/files/","lagoon.persistent.size":"50Gi","lagoon.type":"nginx-php-persistent"},"networks":{"amazeeio-network":null,"default":null},"volumes":[{"type":"bind","source":".","target":"/app","bind":{"create_host_path":true}},{"type":"bind","source":"./docroot/sites/default/files","target":"/app/docroot/sites/default/files","bind":{"create_host_path":true}}]},"php":{"build":{"context":".","dockerfile":".docker/Dockerfile.php","args":{"CLI_IMAGE":"mysite","EXAMPLE_IMAGE_VERSION":"4.x"}},"depends_on":{"cli":{"condition":"service_started"}},"environment":{"CKEDITOR_SCAYT_CUSTOMERID":"","CKEDITOR_SCAYT_SLANG":"","DB_ALIAS":"example.prod-left","DRUPAL_HASH_SALT":"fakehashsaltfakehashsaltfakehashsalt","DRUPAL_REFRESH_SEARCHAPI":"","EXAMPLE_IMAGE_VERSION":"latest","EXAMPLE_INGRESS_ENABLED":"","EXAMPLE_INGRESS_HEADER":"","EXAMPLE_INGRESS_PSK":"","EXAMPLE_KEY":"","GITHUB_TOKEN":"","LAGOON_ENVIRONMENT_TYPE":"local","LAGOON_LOCALDEV_URL":"http://mysite.docker.amazee.io","LAGOON_PROJECT":"mysite","LAGOON_ROUTE":"http://mysite.docker.amazee.io","PHP_MEMORY_LIMIT":"1024M","REDIS_CACHE_PREFIX":"tide_"},"labels":{"lagoon.name":"nginx-php","lagoon.persistent":"/app/docroot/sites/default/files/","lagoon.persistent.size":"50Gi","lagoon.type":"nginx-php-persistent"},"networks":{"default":null},"volumes":[{"type":"bind","source":".","target":"/app","bind":{"create_host_path":true}},{"type":"bind","source":"./docroot/sites/default/files","target":"/app/docroot/sites/default/files","bind":{"create_host_path":true}}]},"redis":{"image":"uselagoon/redis-5:latest","labels":{"lagoon.type":"redis"},"networks":{"default":null}}},"networks":{"amazeeio-network":{"name":"amazeeio-network","ipam":{},"external":true},"default":{"name":"test4_default","ipam":{},"external":false}},"volumes":{"app":{"name":"test4_app","external":false},"files":{"name":"test4_files","external":false}}}`, wantOrder: []OriginalServiceOrder{ @@ -80,7 +80,7 @@ func TestUnmarshaDockerComposeYAML(t *testing.T) { { name: "test5 docker-compose complex", args: args{ - file: "../../test-resources/docker-compose/test5/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test5/docker-compose.yml", }, want: `{"name":"test5","services":{"chrome":{"depends_on":{"cli":{"condition":"service_started"}},"environment":{"CI":"","DOCKERHOST":"host.docker.internal","LAGOON_ENVIRONMENT_TYPE":"local","LAGOON_LOCALDEV_URL":"example-project.docker.amazee.io","LAGOON_PROJECT":"example-project","LAGOON_ROUTE":"example-project.docker.amazee.io","PHP_APC_SHM_SIZE":"256M","PHP_MAX_EXECUTION_TIME":"-1","PHP_MAX_INPUT_VARS":"4000","PHP_MEMORY_LIMIT":"2G","XDEBUG_ENABLE":""},"image":"selenium/standalone-chrome:3.141.59-oxygen","labels":{"lagoon.type":"none"},"networks":{"default":null},"shm_size":"1073741824","volumes":[{"type":"bind","source":".","target":"/app","bind":{"create_host_path":true}}]},"cli":{"build":{"context":".","dockerfile":".docker/Dockerfile.cli"},"environment":{"CI":"","DOCKERHOST":"host.docker.internal","LAGOON_ENVIRONMENT_TYPE":"local","LAGOON_LOCALDEV_URL":"example-project.docker.amazee.io","LAGOON_PROJECT":"example-project","LAGOON_ROUTE":"example-project.docker.amazee.io","PHP_APC_SHM_SIZE":"256M","PHP_MAX_EXECUTION_TIME":"-1","PHP_MAX_INPUT_VARS":"4000","PHP_MEMORY_LIMIT":"2G","XDEBUG_ENABLE":""},"image":"example-project","labels":{"lagoon.persistent":"/app/docroot/sites/default/files/","lagoon.persistent.name":"nginx-php","lagoon.type":"cli-persistent"},"networks":{"default":null},"ports":[{"mode":"ingress","target":35729,"protocol":"tcp"}],"user":"root","volumes":[{"type":"bind","source":".","target":"/app","bind":{"create_host_path":true}}],"volumes_from":["container:amazeeio-ssh-agent"]},"mariadb":{"build":{"context":".","dockerfile":".docker/Dockerfile.mariadb","args":{"IMAGE":"amazeeio/mariadb-drupal:21.7.0"}},"environment":{"CI":"","DOCKERHOST":"host.docker.internal","LAGOON_ENVIRONMENT_TYPE":"local","LAGOON_LOCALDEV_URL":"example-project.docker.amazee.io","LAGOON_PROJECT":"example-project","LAGOON_ROUTE":"example-project.docker.amazee.io","PHP_APC_SHM_SIZE":"256M","PHP_MAX_EXECUTION_TIME":"-1","PHP_MAX_INPUT_VARS":"4000","PHP_MEMORY_LIMIT":"2G","XDEBUG_ENABLE":""},"labels":{"lagoon.type":"mariadb"},"networks":{"default":null},"ports":[{"mode":"ingress","target":3306,"protocol":"tcp"}]},"nginx":{"build":{"context":".","dockerfile":".docker/Dockerfile.nginx-drupal","args":{"CLI_IMAGE":"example-project"}},"depends_on":{"cli":{"condition":"service_started"}},"environment":{"CI":"","DOCKERHOST":"host.docker.internal","LAGOON_ENVIRONMENT_TYPE":"local","LAGOON_LOCALDEV_URL":"example-project.docker.amazee.io","LAGOON_PROJECT":"example-project","LAGOON_ROUTE":"example-project.docker.amazee.io","PHP_APC_SHM_SIZE":"256M","PHP_MAX_EXECUTION_TIME":"-1","PHP_MAX_INPUT_VARS":"4000","PHP_MEMORY_LIMIT":"2G","XDEBUG_ENABLE":""},"labels":{"lagoon.name":"nginx-php","lagoon.persistent":"/app/docroot/sites/default/files/","lagoon.persistent.class":"slow","lagoon.type":"nginx-php-persistent"},"networks":{"amazeeio-network":null,"default":null},"user":"1000","volumes":[{"type":"bind","source":".","target":"/app","bind":{"create_host_path":true}}]},"php":{"build":{"context":".","dockerfile":".docker/Dockerfile.php","args":{"CLI_IMAGE":"example-project"}},"depends_on":{"cli":{"condition":"service_started"}},"environment":{"CI":"","DOCKERHOST":"host.docker.internal","LAGOON_ENVIRONMENT_TYPE":"local","LAGOON_LOCALDEV_URL":"example-project.docker.amazee.io","LAGOON_PROJECT":"example-project","LAGOON_ROUTE":"example-project.docker.amazee.io","PHP_APC_SHM_SIZE":"256M","PHP_MAX_EXECUTION_TIME":"-1","PHP_MAX_INPUT_VARS":"4000","PHP_MEMORY_LIMIT":"2G","XDEBUG_ENABLE":""},"labels":{"lagoon.name":"nginx-php","lagoon.persistent":"/app/docroot/sites/default/files/","lagoon.persistent.class":"slow","lagoon.type":"nginx-php-persistent"},"networks":{"default":null},"user":"1000","volumes":[{"type":"bind","source":".","target":"/app","bind":{"create_host_path":true}}]},"redis":{"environment":{"CI":"","DOCKERHOST":"host.docker.internal","LAGOON_ENVIRONMENT_TYPE":"local","LAGOON_LOCALDEV_URL":"example-project.docker.amazee.io","LAGOON_PROJECT":"example-project","LAGOON_ROUTE":"example-project.docker.amazee.io","PHP_APC_SHM_SIZE":"256M","PHP_MAX_EXECUTION_TIME":"-1","PHP_MAX_INPUT_VARS":"4000","PHP_MEMORY_LIMIT":"2G","XDEBUG_ENABLE":""},"image":"amazeeio/redis:6-21.11.0","labels":{"lagoon.type":"redis"},"networks":{"default":null}},"wait_dependencies":{"command":["mariadb:3306"],"depends_on":{"cli":{"condition":"service_started"},"mariadb":{"condition":"service_started"}},"image":"dadarek/wait-for-dependencies","labels":{"lagoon.type":"none"},"networks":{"default":null}}},"networks":{"amazeeio-network":{"name":"amazeeio-network","ipam":{},"external":true},"default":{"name":"test5_default","ipam":{},"external":false}},"volumes":{"app":{"name":"test5_app","external":false}}}`, wantOrder: []OriginalServiceOrder{ @@ -96,7 +96,7 @@ func TestUnmarshaDockerComposeYAML(t *testing.T) { { name: "test6 docker-compose complex", args: args{ - file: "../../test-resources/docker-compose/test6/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test6/docker-compose.yml", }, want: `{"name":"test6","services":{"chrome":{"depends_on":{"test":{"condition":"service_started"}},"image":"selenium/standalone-chrome","labels":{"lagoon.type":"none"},"networks":{"default":null},"shm_size":"1073741824","volumes":[{"type":"bind","source":"./themes","target":"/app/web/themes/custom","bind":{"create_host_path":true}},{"type":"bind","source":"./files","target":"/app/web/sites/default/files","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/behat/features","target":"/app/tests/behat/features","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/behat/screenshots","target":"/app/tests/behat/screenshots","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/phpunit/tests","target":"/app/tests/phpunit/tests","bind":{"create_host_path":true}},{"type":"bind","source":"./config","target":"/app/config","bind":{"create_host_path":true}}]},"cli":{"build":{"context":".","dockerfile":".docker/Dockerfile.cli","args":{"EXAMPLE_IMAGE_VERSION":"9.x-latest","LAGOON_SAFE_PROJECT":"ca-learning2"}},"environment":{"DEV_MODE":"false","DOCKERHOST":"host.docker.internal","DRUPAL_SHIELD_PASS":"","DRUPAL_SHIELD_USER":"","EXAMPLE_DEPLOY_WORKFLOW_CONFIG":"import","EXAMPLE_IMAGE_VERSION":"9.x-latest","EXAMPLE_PREPARE_XML_SCRIPT":"/app/vendor/bin/example-prepare-xml","LAGOON_ENVIRONMENT_TYPE":"","LAGOON_PROJECT":"ca-learning2","LAGOON_ROUTE":"http://ca-learning2.docker.amazee.io","STAGE_FILE_PROXY_URL":"","XDEBUG_ENABLE":"","X_FRAME_OPTIONS":"SameOrigin"},"image":"ca-learning2","labels":{"lagoon.persistent":"/app/web/sites/default/files/","lagoon.persistent.name":"nginx","lagoon.type":"cli-persistent"},"networks":{"default":null},"volumes":[{"type":"bind","source":"./themes","target":"/app/web/themes/custom","bind":{"create_host_path":true}},{"type":"bind","source":"./files","target":"/app/web/sites/default/files","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/behat/features","target":"/app/tests/behat/features","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/behat/screenshots","target":"/app/tests/behat/screenshots","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/phpunit/tests","target":"/app/tests/phpunit/tests","bind":{"create_host_path":true}},{"type":"bind","source":"./config","target":"/app/config","bind":{"create_host_path":true}}],"volumes_from":["container:amazeeio-ssh-agent"]},"mariadb":{"environment":{"DEV_MODE":"false","DOCKERHOST":"host.docker.internal","DRUPAL_SHIELD_PASS":"","DRUPAL_SHIELD_USER":"","EXAMPLE_DEPLOY_WORKFLOW_CONFIG":"import","EXAMPLE_IMAGE_VERSION":"9.x-latest","EXAMPLE_PREPARE_XML_SCRIPT":"/app/vendor/bin/example-prepare-xml","LAGOON_ENVIRONMENT_TYPE":"","LAGOON_PROJECT":"ca-learning2","LAGOON_ROUTE":"http://ca-learning2.docker.amazee.io","STAGE_FILE_PROXY_URL":"","XDEBUG_ENABLE":"","X_FRAME_OPTIONS":"SameOrigin"},"image":"example/mariadb-drupal:9.x-latest","labels":{"lagoon.image":"example/mariadb-drupal:9.x-latest","lagoon.type":"mariadb"},"networks":{"default":null},"ports":[{"mode":"ingress","target":3306,"protocol":"tcp"}]},"nginx":{"build":{"context":".","dockerfile":".docker/Dockerfile.nginx-drupal","args":{"CLI_IMAGE":"ca-learning2","EXAMPLE_IMAGE_VERSION":"9.x-latest"}},"depends_on":{"cli":{"condition":"service_started"}},"environment":{"DEV_MODE":"false","DOCKERHOST":"host.docker.internal","DRUPAL_SHIELD_PASS":"","DRUPAL_SHIELD_USER":"","EXAMPLE_DEPLOY_WORKFLOW_CONFIG":"import","EXAMPLE_IMAGE_VERSION":"9.x-latest","EXAMPLE_PREPARE_XML_SCRIPT":"/app/vendor/bin/example-prepare-xml","LAGOON_ENVIRONMENT_TYPE":"","LAGOON_LOCALDEV_URL":"http://ca-learning2.docker.amazee.io","LAGOON_PROJECT":"ca-learning2","LAGOON_ROUTE":"http://ca-learning2.docker.amazee.io","STAGE_FILE_PROXY_URL":"","XDEBUG_ENABLE":"","X_FRAME_OPTIONS":"SameOrigin"},"labels":{"lagoon.persistent":"/app/web/sites/default/files/","lagoon.type":"nginx-php-persistent"},"networks":{"amazeeio-network":null,"default":null},"volumes":[{"type":"bind","source":"./themes","target":"/app/web/themes/custom","bind":{"create_host_path":true}},{"type":"bind","source":"./files","target":"/app/web/sites/default/files","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/behat/features","target":"/app/tests/behat/features","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/behat/screenshots","target":"/app/tests/behat/screenshots","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/phpunit/tests","target":"/app/tests/phpunit/tests","bind":{"create_host_path":true}},{"type":"bind","source":"./config","target":"/app/config","bind":{"create_host_path":true}}]},"php":{"build":{"context":".","dockerfile":".docker/Dockerfile.php","args":{"CLI_IMAGE":"ca-learning2","EXAMPLE_IMAGE_VERSION":"9.x-latest"}},"depends_on":{"cli":{"condition":"service_started"}},"environment":{"DEV_MODE":"false","DOCKERHOST":"host.docker.internal","DRUPAL_SHIELD_PASS":"","DRUPAL_SHIELD_USER":"","EXAMPLE_DEPLOY_WORKFLOW_CONFIG":"import","EXAMPLE_IMAGE_VERSION":"9.x-latest","EXAMPLE_PREPARE_XML_SCRIPT":"/app/vendor/bin/example-prepare-xml","LAGOON_ENVIRONMENT_TYPE":"","LAGOON_PROJECT":"ca-learning2","LAGOON_ROUTE":"http://ca-learning2.docker.amazee.io","STAGE_FILE_PROXY_URL":"","XDEBUG_ENABLE":"","X_FRAME_OPTIONS":"SameOrigin"},"labels":{"lagoon.name":"nginx","lagoon.persistent":"/app/web/sites/default/files/","lagoon.type":"nginx-php-persistent"},"networks":{"default":null},"volumes":[{"type":"bind","source":"./themes","target":"/app/web/themes/custom","bind":{"create_host_path":true}},{"type":"bind","source":"./files","target":"/app/web/sites/default/files","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/behat/features","target":"/app/tests/behat/features","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/behat/screenshots","target":"/app/tests/behat/screenshots","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/phpunit/tests","target":"/app/tests/phpunit/tests","bind":{"create_host_path":true}},{"type":"bind","source":"./config","target":"/app/config","bind":{"create_host_path":true}}]},"test":{"build":{"context":".","dockerfile":".docker/Dockerfile.test","args":{"CLI_IMAGE":"ca-learning2","EXAMPLE_IMAGE_VERSION":"9.x-latest","SITE_AUDIT_VERSION":"7.x-3.x"}},"depends_on":{"cli":{"condition":"service_started"}},"environment":{"DEV_MODE":"false","DOCKERHOST":"host.docker.internal","DRUPAL_SHIELD_PASS":"","DRUPAL_SHIELD_USER":"","EXAMPLE_DEPLOY_WORKFLOW_CONFIG":"import","EXAMPLE_IMAGE_VERSION":"9.x-latest","EXAMPLE_PREPARE_XML_SCRIPT":"/app/vendor/bin/example-prepare-xml","LAGOON_ENVIRONMENT_TYPE":"","LAGOON_PROJECT":"ca-learning2","LAGOON_ROUTE":"http://ca-learning2.docker.amazee.io","STAGE_FILE_PROXY_URL":"","XDEBUG_ENABLE":"","X_FRAME_OPTIONS":"SameOrigin"},"labels":{"lagoon.type":"none"},"networks":{"default":null},"volumes":[{"type":"bind","source":"./themes","target":"/app/web/themes/custom","bind":{"create_host_path":true}},{"type":"bind","source":"./files","target":"/app/web/sites/default/files","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/behat/features","target":"/app/tests/behat/features","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/behat/screenshots","target":"/app/tests/behat/screenshots","bind":{"create_host_path":true}},{"type":"bind","source":"./tests/phpunit/tests","target":"/app/tests/phpunit/tests","bind":{"create_host_path":true}},{"type":"bind","source":"./config","target":"/app/config","bind":{"create_host_path":true}}]}},"networks":{"amazeeio-network":{"name":"amazeeio-network","ipam":{},"external":true},"default":{"name":"test6_default","ipam":{},"external":false}}}`, wantOrder: []OriginalServiceOrder{ @@ -111,7 +111,7 @@ func TestUnmarshaDockerComposeYAML(t *testing.T) { { name: "test7 check an invalid docker-compose with ignoring non-string key errors", args: args{ - file: "../../test-resources/docker-compose/test7/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test7/docker-compose.yml", ignoreNonStringKeyErrors: true, }, want: `{"name":"test7","services":{"cli":{"build":{"context":".","dockerfile":".lagoon/cli.dockerfile","args":{"DOCKER_CLI_IMAGE_URI":"","ENVIRONMENT_TYPE_ID":""}},"container_name":"_cli","environment":{"ENVIRONMENT_TYPE_ID":"","LAGOON_ENVIRONMENT_TYPE":"","LAGOON_PROJECT":"","LAGOON_ROUTE":"http://","PHP_MEMORY_LIMIT":"768M","XDEBUG_ENABLE":""},"labels":{"lagoon.persistent":"/app/docroot/sites/default/files/","lagoon.persistent.name":"nginx","lagoon.type":"cli-persistent"},"networks":{"default":null},"user":"root","volumes":[{"type":"bind","source":"./.lagoon/scripts/bash_prompts.rc","target":"/home/.bashrc","bind":{"create_host_path":true}},{"type":"bind","source":"./.lagoon/scripts/color_grid.sh","target":"/home/color_grid.sh","bind":{"create_host_path":true}}],"volumes_from":["container:amazeeio-ssh-agent"]},"mariadb":{"container_name":"_db","environment":{"ENVIRONMENT_TYPE_ID":"","LAGOON_ENVIRONMENT_TYPE":"","LAGOON_PROJECT":"","LAGOON_ROUTE":"http://","PHP_MEMORY_LIMIT":"768M","XDEBUG_ENABLE":""},"image":"amazeeio/mariadb-drupal","labels":{"lagoon.type":"mariadb"},"networks":{"default":null},"ports":[{"mode":"ingress","target":3306,"protocol":"tcp"}],"volumes":[{"type":"volume","source":"mysql","target":"/var/lib/mysql","volume":{}}]},"nginx":{"build":{"context":".","dockerfile":".lagoon/nginx.dockerfile","args":{"CLI_IMAGE":"","DOCKER_NGINX_IMAGE_URI":"","LAGOON_GIT_BRANCH":null}},"container_name":"_nginx","depends_on":{"cli":{"condition":"service_started"}},"environment":{"ENVIRONMENT_TYPE_ID":"","LAGOON_ENVIRONMENT_TYPE":"","LAGOON_LOCALDEV_URL":"http://","LAGOON_PROJECT":"","LAGOON_ROUTE":"http://","PHP_MEMORY_LIMIT":"768M","XDEBUG_ENABLE":""},"labels":{"lagoon.name":"nginx","lagoon.persistent":"/app/docroot/sites/default/files/","lagoon.type":"nginx-php-persistent"},"networks":{"amazeeio-network":null,"default":null},"volumes":[{"type":"bind","source":"./.lagoon/nginx/nginx-http.conf","target":"/etc/nginx/conf.d/000-nginx-http.conf","bind":{"create_host_path":true}},{"type":"bind","source":"./.lagoon/nginx/app.conf","target":"/etc/nginx/conf.d/app.conf","bind":{"create_host_path":true}}]},"php":{"build":{"context":".","dockerfile":".lagoon/php.dockerfile","args":{"CLI_IMAGE":"","DOCKER_PHP_IMAGE_URI":""}},"container_name":"_php","depends_on":{"cli":{"condition":"service_started"}},"environment":{"ENVIRONMENT_TYPE_ID":"","LAGOON_ENVIRONMENT_TYPE":"","LAGOON_PROJECT":"","LAGOON_ROUTE":"http://","PHP_MEMORY_LIMIT":"768M","XDEBUG_ENABLE":""},"labels":{"lagoon.deployment.servicetype":"php","lagoon.name":"nginx","lagoon.persistent":"/app/docroot/sites/default/files","lagoon.type":"nginx-php-persistent"},"networks":{"default":null}}},"networks":{"amazeeio-network":{"name":"amazeeio-network","ipam":{},"external":true},"default":{"name":"test7_default","ipam":{},"external":false}},"volumes":{"app":{"name":"test7_app","external":false},"mysql":{"name":"test7_mysql","external":false},"solr7":{"name":"test7_solr7","external":false}}}`, @@ -125,7 +125,7 @@ func TestUnmarshaDockerComposeYAML(t *testing.T) { { name: "test8 check an invalid docker-compose (same as test7 but not ignoring the errors)", args: args{ - file: "../../test-resources/docker-compose/test8/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test8/docker-compose.yml", }, wantErr: true, wantErrMsg: "Non-string key in x-site-branch: ", @@ -133,7 +133,7 @@ func TestUnmarshaDockerComposeYAML(t *testing.T) { { name: "test9 check an valid docker-compose with missing env_files", args: args{ - file: "../../test-resources/docker-compose/test9/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test9/docker-compose.yml", ignoreNonStringKeyErrors: true, ignoreMissingEnvFiles: true, }, @@ -149,7 +149,7 @@ func TestUnmarshaDockerComposeYAML(t *testing.T) { { name: "test10 check an valid docker-compose with missing env_files (same as test9 but not ignoring the errors)", args: args{ - file: "../../test-resources/docker-compose/test10/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test10/docker-compose.yml", }, wantErr: true, wantErrMsg: "no such file or directory", @@ -157,7 +157,7 @@ func TestUnmarshaDockerComposeYAML(t *testing.T) { { name: "test11 docker-compose service name with '.'", args: args{ - file: "../../test-resources/docker-compose/test11/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test11/docker-compose.yml", }, wantErr: true, wantErrMsg: "Service name is invalid. Please refer to the documentation regarding service naming requirements", @@ -231,7 +231,7 @@ func TestUnmarshalLagoonDockerComposeYAML(t *testing.T) { { name: "test1 docker-compose drupal example", args: args{ - file: "../../test-resources/docker-compose/test1/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test1/docker-compose.yml", }, wantErr: true, wantErrMsg: `line 59: mapping key "<<" already defined at line 58`, @@ -239,25 +239,25 @@ func TestUnmarshalLagoonDockerComposeYAML(t *testing.T) { { name: "test2 docker-compose node example", args: args{ - file: "../../test-resources/docker-compose/test2/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test2/docker-compose.yml", }, }, { name: "test3 docker-compose complex", args: args{ - file: "../../test-resources/docker-compose/test3/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test3/docker-compose.yml", }, }, { name: "test4 docker-compose complex", args: args{ - file: "../../test-resources/docker-compose/test4/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test4/docker-compose.yml", }, }, { name: "test5 docker-compose complex", args: args{ - file: "../../test-resources/docker-compose/test5/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test5/docker-compose.yml", }, wantErr: true, wantErrMsg: `line 57: mapping key "<<" already defined at line 56`, @@ -265,38 +265,38 @@ func TestUnmarshalLagoonDockerComposeYAML(t *testing.T) { { name: "test6 docker-compose complex", args: args{ - file: "../../test-resources/docker-compose/test6/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test6/docker-compose.yml", }, }, // these tests are specific to docker-compose validations, but will pass yaml validations { name: "test7 check an invalid docker-compose with ignoring non-string key errors (valid yaml)", args: args{ - file: "../../test-resources/docker-compose/test7/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test7/docker-compose.yml", }, }, { name: "test8 check an invalid docker-compose (same as test7 but not ignoring the errors)", args: args{ - file: "../../test-resources/docker-compose/test8/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test8/docker-compose.yml", }, }, { name: "test9 check an valid docker-compose with missing env_files", args: args{ - file: "../../test-resources/docker-compose/test9/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test9/docker-compose.yml", }, }, { name: "test10 check an valid docker-compose with missing env_files (same as test9 but not ignoring the errors)", args: args{ - file: "../../test-resources/docker-compose/test10/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test10/docker-compose.yml", }, }, { name: "test11 docker-compose service name with '.'", args: args{ - file: "../../test-resources/docker-compose/test11/docker-compose.yml", + file: "../../internal/testdata/docker-compose/test11/docker-compose.yml", }, }, // ^^ these tests are specific to docker-compose validations, but will pass yaml validations diff --git a/internal/testdata/basic/docker-compose.thunderhub-2.yml b/internal/testdata/basic/docker-compose.thunderhub-2.yml index d8e39aaa..93e3cee3 100644 --- a/internal/testdata/basic/docker-compose.thunderhub-2.yml +++ b/internal/testdata/basic/docker-compose.thunderhub-2.yml @@ -5,7 +5,7 @@ services: - amazeeio-network - default build: - context: . + context: internal/testdata/basic/docker dockerfile: Dockerfile user: '10000' labels: @@ -28,7 +28,7 @@ services: - amazeeio-network - default build: - context: tor + context: internal/testdata/basic/docker dockerfile: Dockerfile user: '10000' labels: diff --git a/internal/testdata/basic/docker-compose.thunderhub.yml b/internal/testdata/basic/docker-compose.thunderhub.yml index 04115bee..a6c3bdea 100644 --- a/internal/testdata/basic/docker-compose.thunderhub.yml +++ b/internal/testdata/basic/docker-compose.thunderhub.yml @@ -5,7 +5,7 @@ services: - amazeeio-network - default build: - context: . + context: internal/testdata/basic/docker dockerfile: Dockerfile user: '10000' labels: @@ -28,7 +28,7 @@ services: - amazeeio-network - default build: - context: thunderhub + context: internal/testdata/basic/docker dockerfile: Dockerfile user: '10000' environment: @@ -52,7 +52,7 @@ services: - amazeeio-network - default build: - context: tor + context: internal/testdata/basic/docker dockerfile: Dockerfile user: '10000' labels: diff --git a/internal/testdata/basic/docker-compose.yml b/internal/testdata/basic/docker-compose.yml index 66b9415e..9d4b1f6f 100644 --- a/internal/testdata/basic/docker-compose.yml +++ b/internal/testdata/basic/docker-compose.yml @@ -5,7 +5,7 @@ services: - amazeeio-network - default build: - context: . + context: internal/testdata/basic/docker dockerfile: basic.dockerfile labels: lagoon.type: basic diff --git a/internal/testdata/basic/docker/Dockerfile b/internal/testdata/basic/docker/Dockerfile new file mode 100644 index 00000000..2db7fd80 --- /dev/null +++ b/internal/testdata/basic/docker/Dockerfile @@ -0,0 +1 @@ +FROM uselagoon/fake-basic:latest diff --git a/internal/testdata/basic/docker/basic.dockerfile b/internal/testdata/basic/docker/basic.dockerfile new file mode 100644 index 00000000..2db7fd80 --- /dev/null +++ b/internal/testdata/basic/docker/basic.dockerfile @@ -0,0 +1 @@ +FROM uselagoon/fake-basic:latest diff --git a/internal/testdata/basic/lagoon.thunderhub-2.yml b/internal/testdata/basic/lagoon.thunderhub-2.yml index c2287dba..c276e5a9 100644 --- a/internal/testdata/basic/lagoon.thunderhub-2.yml +++ b/internal/testdata/basic/lagoon.thunderhub-2.yml @@ -1 +1 @@ -docker-compose-yaml: ../internal/testdata/basic/docker-compose.thunderhub-2.yml \ No newline at end of file +docker-compose-yaml: internal/testdata/basic/docker-compose.thunderhub-2.yml \ No newline at end of file diff --git a/internal/testdata/basic/lagoon.thunderhub.yml b/internal/testdata/basic/lagoon.thunderhub.yml index ffcac6e7..ae3eb0da 100644 --- a/internal/testdata/basic/lagoon.thunderhub.yml +++ b/internal/testdata/basic/lagoon.thunderhub.yml @@ -1 +1 @@ -docker-compose-yaml: ../internal/testdata/basic/docker-compose.thunderhub.yml \ No newline at end of file +docker-compose-yaml: internal/testdata/basic/docker-compose.thunderhub.yml \ No newline at end of file diff --git a/internal/testdata/basic/lagoon.yml b/internal/testdata/basic/lagoon.yml index d7a785a8..5ea54bdb 100644 --- a/internal/testdata/basic/lagoon.yml +++ b/internal/testdata/basic/lagoon.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/basic/docker-compose.yml +docker-compose-yaml: internal/testdata/basic/docker-compose.yml environment_variables: git_sha: "true" diff --git a/internal/testdata/complex/docker-compose.complex-1.yml b/internal/testdata/complex/docker-compose.complex-1.yml index c58a678e..67c99edf 100644 --- a/internal/testdata/complex/docker-compose.complex-1.yml +++ b/internal/testdata/complex/docker-compose.complex-1.yml @@ -16,8 +16,8 @@ services: cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) container_name: "${COMPOSE_PROJECT_NAME}-cli" build: - context: . - dockerfile: lagoon/cli.dockerfile + context: internal/testdata/complex/docker + dockerfile: cli.dockerfile image: *lagoon-project # this image will be reused as `CLI_IMAGE` in subsequent Docker builds labels: # Lagoon Labels @@ -38,8 +38,8 @@ services: nginx: container_name: "${COMPOSE_PROJECT_NAME}-nginx" build: - context: . - dockerfile: lagoon/nginx.dockerfile + context: internal/testdata/complex/docker + dockerfile: nginx.dockerfile args: CLI_IMAGE: *lagoon-project # Inject the name of the cli image labels: @@ -59,8 +59,8 @@ services: php: container_name: "${COMPOSE_PROJECT_NAME}-php" build: - context: . - dockerfile: lagoon/php.dockerfile + context: internal/testdata/complex/docker + dockerfile: php.dockerfile args: CLI_IMAGE: *lagoon-project labels: @@ -78,7 +78,7 @@ services: mariadb: container_name: "${COMPOSE_PROJECT_NAME}-db" - image: uselagoon/mariadb-drupal:latest + image: usemariadb-drupal:latest labels: lagoon.type: mariadb ports: diff --git a/internal/testdata/complex/docker-compose.small-1.yml b/internal/testdata/complex/docker-compose.small-1.yml index a0427540..6dfded12 100644 --- a/internal/testdata/complex/docker-compose.small-1.yml +++ b/internal/testdata/complex/docker-compose.small-1.yml @@ -2,7 +2,7 @@ version: '2' services: cli: build: - context: . + context: internal/testdata/complex/docker dockerfile: builder.dockerfile image: builder labels: @@ -19,7 +19,7 @@ services: - amazeeio-network - default build: - context: . + context: internal/testdata/complex/docker dockerfile: nginx.dockerfile labels: lagoon.type: nginx-php-persistent @@ -37,7 +37,7 @@ services: LAGOON_LOCALDEV_URL: drupal9-mariadb.docker.amazee.io php: build: - context: . + context: internal/testdata/complex/docker dockerfile: php.dockerfile labels: lagoon.type: nginx-php-persistent @@ -50,7 +50,7 @@ services: - cli mariadb: build: - context: . + context: internal/testdata/complex/docker dockerfile: mariadb.dockerfile labels: lagoon.type: mariadb-single diff --git a/internal/testdata/complex/docker-compose.small-2.yml b/internal/testdata/complex/docker-compose.small-2.yml index 03b85222..f725df20 100644 --- a/internal/testdata/complex/docker-compose.small-2.yml +++ b/internal/testdata/complex/docker-compose.small-2.yml @@ -2,7 +2,7 @@ version: '2' services: cli: build: - context: . + context: internal/testdata/complex/docker dockerfile: builder.dockerfile image: builder labels: @@ -19,7 +19,7 @@ services: - amazeeio-network - default build: - context: . + context: internal/testdata/complex/docker dockerfile: nginx.dockerfile labels: lagoon.type: nginx-php-persistent @@ -37,7 +37,7 @@ services: LAGOON_LOCALDEV_URL: drupal9-mariadb.docker.amazee.io php: build: - context: . + context: internal/testdata/complex/docker dockerfile: php.dockerfile labels: lagoon.type: nginx-php-persistent @@ -61,7 +61,7 @@ services: mariadb: build: - context: . + context: internal/testdata/complex/docker dockerfile: mariadb.dockerfile labels: lagoon.type: mariadb-single diff --git a/internal/testdata/complex/docker-compose.varnish.yml b/internal/testdata/complex/docker-compose.varnish.yml index 5efe6c55..a03f9926 100644 --- a/internal/testdata/complex/docker-compose.varnish.yml +++ b/internal/testdata/complex/docker-compose.varnish.yml @@ -34,7 +34,7 @@ services: cli: build: - context: . + context: internal/testdata/complex/docker dockerfile: .docker/Dockerfile.cli args: COMPOSER: ${COMPOSER:-composer.json} @@ -53,7 +53,7 @@ services: nginx: build: - context: . + context: internal/testdata/complex/docker dockerfile: .docker/Dockerfile.nginx-drupal args: CLI_IMAGE: *project @@ -75,7 +75,7 @@ services: - "8080" php: build: - context: . + context: internal/testdata/complex/docker dockerfile: .docker/Dockerfile.php args: CLI_IMAGE: *project @@ -107,7 +107,7 @@ services: elasticsearch: build: - context: . + context: internal/testdata/complex/docker dockerfile: .docker/Dockerfile.elasticsearch args: - ES_TPL=${ES_TPL:-elasticsearch.yml} diff --git a/internal/testdata/complex/docker-compose.yml b/internal/testdata/complex/docker-compose.yml index 9ed4b99b..6df990eb 100644 --- a/internal/testdata/complex/docker-compose.yml +++ b/internal/testdata/complex/docker-compose.yml @@ -29,7 +29,7 @@ services: cli: build: - context: . + context: internal/testdata/complex/docker dockerfile: .docker/Dockerfile.cli args: COMPOSER: ${COMPOSER:-composer.json} @@ -49,7 +49,7 @@ services: nginx: build: - context: . + context: internal/testdata/complex/docker dockerfile: .docker/Dockerfile.nginx-drupal args: CLI_IMAGE: *project @@ -71,7 +71,7 @@ services: - "8080" php: build: - context: . + context: internal/testdata/complex/docker dockerfile: .docker/Dockerfile.php args: CLI_IMAGE: *project @@ -103,7 +103,7 @@ services: elasticsearch: build: - context: . + context: internal/testdata/complex/docker dockerfile: .docker/Dockerfile.elasticsearch args: - ES_TPL=${ES_TPL:-elasticsearch.yml} diff --git a/internal/testdata/complex/docker/.docker/Dockerfile.cli b/internal/testdata/complex/docker/.docker/Dockerfile.cli new file mode 100644 index 00000000..94f3893c --- /dev/null +++ b/internal/testdata/complex/docker/.docker/Dockerfile.cli @@ -0,0 +1 @@ +FROM uselagoon/fake-cli:latest diff --git a/internal/testdata/complex/docker/.docker/Dockerfile.nginx-drupal b/internal/testdata/complex/docker/.docker/Dockerfile.nginx-drupal new file mode 100644 index 00000000..aff3c474 --- /dev/null +++ b/internal/testdata/complex/docker/.docker/Dockerfile.nginx-drupal @@ -0,0 +1 @@ +FROM uselagoon/fake-nginx:latest diff --git a/internal/testdata/complex/docker/.docker/Dockerfile.php b/internal/testdata/complex/docker/.docker/Dockerfile.php new file mode 100644 index 00000000..8141f2cd --- /dev/null +++ b/internal/testdata/complex/docker/.docker/Dockerfile.php @@ -0,0 +1 @@ +FROM uselagoon/fake-php:latest diff --git a/internal/testdata/complex/docker/builder.dockerfile b/internal/testdata/complex/docker/builder.dockerfile new file mode 100644 index 00000000..68b71a5e --- /dev/null +++ b/internal/testdata/complex/docker/builder.dockerfile @@ -0,0 +1 @@ +FROM uselagoon/fake-builder:latest \ No newline at end of file diff --git a/internal/testdata/complex/docker/cli.dockerfile b/internal/testdata/complex/docker/cli.dockerfile new file mode 100644 index 00000000..94f3893c --- /dev/null +++ b/internal/testdata/complex/docker/cli.dockerfile @@ -0,0 +1 @@ +FROM uselagoon/fake-cli:latest diff --git a/internal/testdata/complex/docker/mariadb.dockerfile b/internal/testdata/complex/docker/mariadb.dockerfile new file mode 100644 index 00000000..950e48f9 --- /dev/null +++ b/internal/testdata/complex/docker/mariadb.dockerfile @@ -0,0 +1 @@ +FROM uselagoon/fake-mariadb:latest \ No newline at end of file diff --git a/internal/testdata/complex/docker/nginx.dockerfile b/internal/testdata/complex/docker/nginx.dockerfile new file mode 100644 index 00000000..aff3c474 --- /dev/null +++ b/internal/testdata/complex/docker/nginx.dockerfile @@ -0,0 +1 @@ +FROM uselagoon/fake-nginx:latest diff --git a/internal/testdata/complex/docker/php.dockerfile b/internal/testdata/complex/docker/php.dockerfile new file mode 100644 index 00000000..8141f2cd --- /dev/null +++ b/internal/testdata/complex/docker/php.dockerfile @@ -0,0 +1 @@ +FROM uselagoon/fake-php:latest diff --git a/internal/testdata/complex/lagoon.complex-1.yml b/internal/testdata/complex/lagoon.complex-1.yml index 56c60cfc..a1dec4e8 100644 --- a/internal/testdata/complex/lagoon.complex-1.yml +++ b/internal/testdata/complex/lagoon.complex-1.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/complex/docker-compose.complex-1.yml +docker-compose-yaml: internal/testdata/complex/docker-compose.complex-1.yml tasks: diff --git a/internal/testdata/complex/lagoon.complex-2.yml b/internal/testdata/complex/lagoon.complex-2.yml index 4b6d3d74..6fe26237 100644 --- a/internal/testdata/complex/lagoon.complex-2.yml +++ b/internal/testdata/complex/lagoon.complex-2.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/complex/docker-compose.complex-1.yml +docker-compose-yaml: internal/testdata/complex/docker-compose.complex-1.yml environments: main: diff --git a/internal/testdata/complex/lagoon.small-2.yml b/internal/testdata/complex/lagoon.small-2.yml index 9c03e6da..2ef7f832 100644 --- a/internal/testdata/complex/lagoon.small-2.yml +++ b/internal/testdata/complex/lagoon.small-2.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/complex/docker-compose.small-2.yml +docker-compose-yaml: internal/testdata/complex/docker-compose.small-2.yml ssh: lagoon-core-ssh.lagoon.svc:2020 api: http://lagoon-core-api.lagoon.svc:80/graphql diff --git a/internal/testdata/complex/lagoon.small.yml b/internal/testdata/complex/lagoon.small.yml index 6aa5e31e..85070428 100644 --- a/internal/testdata/complex/lagoon.small.yml +++ b/internal/testdata/complex/lagoon.small.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/complex/docker-compose.small-1.yml +docker-compose-yaml: internal/testdata/complex/docker-compose.small-1.yml ssh: lagoon-core-ssh.lagoon.svc:2020 api: http://lagoon-core-api.lagoon.svc:80/graphql diff --git a/internal/testdata/complex/lagoon.varnish.yml b/internal/testdata/complex/lagoon.varnish.yml index 6e00aeff..a845c6a0 100644 --- a/internal/testdata/complex/lagoon.varnish.yml +++ b/internal/testdata/complex/lagoon.varnish.yml @@ -1,5 +1,5 @@ --- -docker-compose-yaml: ../internal/testdata/complex/docker-compose.varnish.yml +docker-compose-yaml: internal/testdata/complex/docker-compose.varnish.yml project: example-com diff --git a/internal/testdata/complex/lagoon.yml b/internal/testdata/complex/lagoon.yml index 474b28ca..1b467da7 100644 --- a/internal/testdata/complex/lagoon.yml +++ b/internal/testdata/complex/lagoon.yml @@ -1,5 +1,5 @@ --- -docker-compose-yaml: ../internal/testdata/complex/docker-compose.yml +docker-compose-yaml: internal/testdata/complex/docker-compose.yml project: content-example-com diff --git a/internal/testdata/docker-compose/test1/docker-compose.yml b/internal/testdata/docker-compose/test1/docker-compose.yml new file mode 100644 index 00000000..51ec1413 --- /dev/null +++ b/internal/testdata/docker-compose/test1/docker-compose.yml @@ -0,0 +1,121 @@ +version: '2.3' + +x-volumes: + &default-volumes + # Define all volumes you would like to have real-time mounted into the docker containers + volumes: + - .:/app:delegated ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. + - files:/app/web/sites/default/files + +x-environment: + &default-environment + # Route that should be used locally, if you are using pygmy, this route *must* end with .docker.amazee.io + LAGOON_ROUTE: &default-url http://${COMPOSE_PROJECT_NAME:-drupal9-example-advanced}.docker.amazee.io + # Uncomment if you like to have the system behave like in production + #LAGOON_ENVIRONMENT_TYPE: production + # Uncomment to enable xdebug and then restart via `docker-compose up -d` + #XDEBUG_ENABLE: "true" + +x-user: + &default-user + # The default user under which the containers should run. Change this if you are on linux and run with another user than id `1000` + user: '1000' + +volumes: + files: + {} + +services: + + cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) + build: + context: . + dockerfile: lagoon/cli.dockerfile + image: &cli-image ${COMPOSE_PROJECT_NAME:-drupal9-example-advanced}-cli # this image will be reused as `CLI_IMAGE` in subsequent Docker builds + labels: + # Lagoon Labels + lagoon.type: cli-persistent + lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container + lagoon.persistent: /app/web/sites/default/files/ # location where the persistent storage should be mounted + lando.type: php-cli-drupal + << : *default-volumes # loads the defined volumes from the top + user: root + volumes_from: ### mount the ssh-agent from the pygmy or cachalot ssh-agent. Automatically removed in CI. + - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. + environment: + << : *default-environment # loads the defined environment variables from the top + + nginx: + build: + context: . + dockerfile: lagoon/nginx.dockerfile + args: + CLI_IMAGE: *cli-image # Inject the name of the cli image + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/web/sites/default/files/ # define where the persistent storage should be mounted too + lando.type: nginx-drupal + << : *default-volumes # loads the defined volumes from the top + << : *default-user # uses the defined user from top + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + LAGOON_LOCALDEV_URL: *default-url + networks: + - amazeeio-network + - default + + php: + build: + context: . + dockerfile: lagoon/php.dockerfile + args: + CLI_IMAGE: *cli-image + labels: + lagoon.type: nginx-php-persistent + lagoon.name: nginx # we want this service be part of the nginx pod in Lagoon + lagoon.persistent: /app/web/sites/default/files/ # define where the persistent storage should be mounted too + lando.type: php-fpm + << : *default-volumes # loads the defined volumes from the top + << : *default-user # uses the defined user from top + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + + mariadb: + image: uselagoon/mariadb-10.5-drupal:latest + labels: + lagoon.type: mariadb + lando.type: mariadb-drupal + ports: + - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` + << : *default-user # uses the defined user from top + environment: + << : *default-environment + + redis: + image: uselagoon/redis-5:latest + labels: + lagoon.type: redis + lando.type: redis + ports: + - "6379" # exposes the port 6379 with a random local port, find it with `docker-compose port redis 6379` + << : *default-user # uses the defined user from top + environment: + << : *default-environment + + solr: + image: uselagoon/solr-7.7-drupal:latest + labels: + lagoon.type: solr + lando.type: solr-drupal + ports: + - "8983" # exposes the port 8983 with a random local port, find it with `docker-compose port solr 8983` + environment: + << : *default-environment + +networks: + amazeeio-network: + external: true \ No newline at end of file diff --git a/internal/testdata/docker-compose/test10/docker-compose.yml b/internal/testdata/docker-compose/test10/docker-compose.yml new file mode 100644 index 00000000..c58a678e --- /dev/null +++ b/internal/testdata/docker-compose/test10/docker-compose.yml @@ -0,0 +1,111 @@ +version: '2.3' + +x-lagoon-project: + # Lagoon project name (leave `&lagoon-project` when you edit this) + &lagoon-project "${COMPOSE_PROJECT_NAME}" + +x-environment: + &default-environment + LAGOON_PROJECT: *lagoon-project + # Route that should be used locally + LAGOON_ROUTE: "https://${DRUPAL_HOSTNAME}" + SSMTP_MAILHUB: "host.docker.internal:1025" + +services: + + cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) + container_name: "${COMPOSE_PROJECT_NAME}-cli" + build: + context: . + dockerfile: lagoon/cli.dockerfile + image: *lagoon-project # this image will be reused as `CLI_IMAGE` in subsequent Docker builds + labels: + # Lagoon Labels + lagoon.type: cli-persistent + lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container + lagoon.persistent: "/app/public/sites/default/files/" # location where the persistent storage should be mounted + volumes: + - .:/app:delegated + - ssh:/tmp/amazeeio_ssh-agent + environment: + << : *default-environment # loads the defined environment variables from the top + SIMPLETEST_BASE_URL: "http://nginx:8080" + SIMPLETEST_DB: "mysql://drupal:drupal@mariadb:3306/drupal" + DRUSH_OPTIONS_URI: "https://${DRUPAL_HOSTNAME}" + env_file: + - .env.local + + nginx: + container_name: "${COMPOSE_PROJECT_NAME}-nginx" + build: + context: . + dockerfile: lagoon/nginx.dockerfile + args: + CLI_IMAGE: *lagoon-project # Inject the name of the cli image + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: "/app/public/sites/default/files/" # define where the persistent file storage should be mounted too + volumes: + - .:/app:delegated + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + LAGOON_LOCALDEV_URL: "${DRUPAL_HOSTNAME}" # generate another route for nginx, by default we go to varnish + networks: + - stonehenge-network + - default + + php: + container_name: "${COMPOSE_PROJECT_NAME}-php" + build: + context: . + dockerfile: lagoon/php.dockerfile + args: + CLI_IMAGE: *lagoon-project + labels: + lagoon.type: nginx-php-persistent + lagoon.name: nginx # we want this service be part of the nginx pod in Lagoon + lagoon.persistent: /app/public/sites/default/files/ # define where the persistent storage should be mounted too + volumes: + - .:/app:delegated + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + env_file: + - .env.local + + mariadb: + container_name: "${COMPOSE_PROJECT_NAME}-db" + image: uselagoon/mariadb-drupal:latest + labels: + lagoon.type: mariadb + ports: + - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` + environment: + << : *default-environment + + pma: + image: phpmyadmin/phpmyadmin + container_name: "${COMPOSE_PROJECT_NAME}-pma" + environment: + PMA_HOST: mariadb + PMA_USER: drupal + PMA_PASSWORD: drupal + UPLOAD_LIMIT: 1G + labels: + lagoon.type: none + networks: + - default + - stonehenge-network + +networks: + stonehenge-network: + external: true + +volumes: + es_data: + ssh: + name: stonehenge-ssh + external: true \ No newline at end of file diff --git a/internal/testdata/docker-compose/test11/docker-compose.yml b/internal/testdata/docker-compose/test11/docker-compose.yml new file mode 100644 index 00000000..e65e3dc1 --- /dev/null +++ b/internal/testdata/docker-compose/test11/docker-compose.yml @@ -0,0 +1,20 @@ +version: '2' +services: + node.test: + networks: + - amazeeio-network + - default + build: + context: . + dockerfile: node.dockerfile + labels: + lagoon.type: node + volumes: + - .:/app:delegated + environment: + - LAGOON_LOCALDEV_HTTP_PORT=3000 + - LAGOON_ROUTE=http://node.docker.amazee.io + +networks: + amazeeio-network: + external: true \ No newline at end of file diff --git a/internal/testdata/docker-compose/test2/docker-compose.yml b/internal/testdata/docker-compose/test2/docker-compose.yml new file mode 100644 index 00000000..85386270 --- /dev/null +++ b/internal/testdata/docker-compose/test2/docker-compose.yml @@ -0,0 +1,20 @@ +version: '2' +services: + node: + networks: + - amazeeio-network + - default + build: + context: . + dockerfile: node.dockerfile + labels: + lagoon.type: node + volumes: + - .:/app:delegated + environment: + - LAGOON_LOCALDEV_HTTP_PORT=3000 + - LAGOON_ROUTE=http://node.docker.amazee.io + +networks: + amazeeio-network: + external: true \ No newline at end of file diff --git a/internal/testdata/docker-compose/test3/docker-compose.yml b/internal/testdata/docker-compose/test3/docker-compose.yml new file mode 100644 index 00000000..022393cb --- /dev/null +++ b/internal/testdata/docker-compose/test3/docker-compose.yml @@ -0,0 +1,126 @@ +version: '2.3' + +x-lagoon-project: + # Lagoon project name (leave `&lagoon-project` when you edit this) + &lagoon-project $PROJECT_NAME + +x-environment: + &default-environment + # Environment ID + ENVIRONMENT_TYPE_ID: $ENVIRONMENT_TYPE_ID + # Machine name of the lagoon project. + LAGOON_PROJECT: *lagoon-project + # Route that should be used locally, if you are using pygmy, this route *must* end with .docker.amazee.io + LAGOON_ROUTE: &default-url http://$LAGOON_ROUTE + # Uncomment if you like to have the system behave like in production + LAGOON_ENVIRONMENT_TYPE: $LAGOON_ENVIRONMENT_TYPE + # The current Git branch of the Lagoon environment. + # LAGOON_GIT_BRANCH: $LAGOON_GIT_BRANCH + # Enable Xdebug within the .env file, then `make down` to reload the env. + XDEBUG_ENABLE: $XDEBUG_ENABLE + # The entrypoint script attempts to autodetect the DOCKERHOST for xdebug. + # If it fails to detect your host, the following override is available: + # DOCKERHOST: host.docker.internal + # Increase PHP memory limit. + PHP_MEMORY_LIMIT: 768M + +x-site-branch: + &site-branch $LAGOON_GIT_BRANCH + +x-user: + &default-user + user: $DEFAULT_USER_ID + +services: + + cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) + build: + context: . + dockerfile: .lagoon/cli.dockerfile + args: + ENVIRONMENT_TYPE_ID: ${ENVIRONMENT_TYPE_ID} + DOCKER_CLI_IMAGE_URI: ${DOCKER_CLI_IMAGE_URI} + image: *lagoon-project # this image will be reused as `CLI_IMAGE` in subsequent Docker builds + container_name: ${PROJECT_NAME}_cli + labels: + # Lagoon Labels + lagoon.type: cli-persistent + lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container + lagoon.persistent: /app/docroot/sites/default/files/ # location where the persistent storage should be mounted + user: root + environment: + << : *default-environment # loads the defined environment variables from the top + volumes: + - ./.lagoon/scripts/bash_prompts.rc:/home/.bashrc + - ./.lagoon/scripts/color_grid.sh:/home/color_grid.sh + volumes_from: + - container:amazeeio-ssh-agent + + nginx: + build: + context: . + dockerfile: .lagoon/nginx.dockerfile + args: + CLI_IMAGE: *lagoon-project + DOCKER_NGINX_IMAGE_URI: ${DOCKER_NGINX_IMAGE_URI} + LAGOON_GIT_BRANCH: *site-branch + container_name: ${PROJECT_NAME}_nginx + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.name: nginx + << : *default-user # uses the defined user from top + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + # LAGOON_LOCALDEV_URL: nginx-${LAGOON_ROUTE} + LAGOON_LOCALDEV_URL: *default-url + networks: + - amazeeio-network + - default + volumes: + - ./.lagoon/nginx/nginx-http.conf:/etc/nginx/conf.d/000-nginx-http.conf + - ./.lagoon/nginx/app.conf:/etc/nginx/conf.d/app.conf + + php: + build: + context: . + dockerfile: .lagoon/php.dockerfile + args: + CLI_IMAGE: *lagoon-project + DOCKER_PHP_IMAGE_URI: ${DOCKER_PHP_IMAGE_URI} + container_name: ${PROJECT_NAME}_php + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/docroot/sites/default/files + lagoon.name: nginx + lagoon.deployment.servicetype: php + << : *default-user # uses the defined user from top + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + + mariadb: + image: amazeeio/mariadb-drupal + container_name: ${PROJECT_NAME}_db + labels: + lagoon.type: mariadb + ports: + - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` + << : *default-user # uses the defined user from top + environment: + << : *default-environment + volumes: + - mysql:/var/lib/mysql + +networks: + amazeeio-network: + external: true + +volumes: + app: + # Add a volume for the DB so it persists between shutdowns. + mysql: + solr7: \ No newline at end of file diff --git a/internal/testdata/docker-compose/test4/docker-compose.yml b/internal/testdata/docker-compose/test4/docker-compose.yml new file mode 100644 index 00000000..9c21b5f8 --- /dev/null +++ b/internal/testdata/docker-compose/test4/docker-compose.yml @@ -0,0 +1,146 @@ +version: '2.3' + +x-example-image-version: + &example-image-version ${EXAMPLE_IMAGE_VERSION:-4.x} + +x-project: + &project ${PROJECT_NAME:-mysite} + +x-volumes: + &default-volumes + volumes: + - .:/app:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. + - ./docroot/sites/default/files:/app/docroot/sites/default/files:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. + +x-environment: + &default-environment + LAGOON_PROJECT: *project + DRUPAL_HASH_SALT: fakehashsaltfakehashsaltfakehashsalt + # Local dev URL populated from the environment. Do not override here. Instead, + # specify the value in .env file. + LAGOON_LOCALDEV_URL: ${LOCALDEV_URL:-http://mysite.docker.amazee.io} + LAGOON_ROUTE: ${LOCALDEV_URL:-http://mysite.docker.amazee.io} + GITHUB_TOKEN: ${GITHUB_TOKEN:-} + EXAMPLE_KEY: ${EXAMPLE_KEY:-} + EXAMPLE_IMAGE_VERSION: ${EXAMPLE_IMAGE_VERSION:-latest} + LAGOON_ENVIRONMENT_TYPE: ${LAGOON_ENVIRONMENT_TYPE:-local} + DRUPAL_REFRESH_SEARCHAPI: ${DRUPAL_REFRESH_SEARCHAPI:-} + EXAMPLE_INGRESS_PSK: ${EXAMPLE_INGRESS_PSK:-} + EXAMPLE_INGRESS_HEADER: ${EXAMPLE_INGRESS_HEADER:-} + EXAMPLE_INGRESS_ENABLED: ${EXAMPLE_INGRESS_ENABLED:-} + REDIS_CACHE_PREFIX: "tide_" + DB_ALIAS: ${DB_ALIAS:-example.prod-left} + CKEDITOR_SCAYT_CUSTOMERID: ${CKEDITOR_SCAYT_CUSTOMERID:-} + CKEDITOR_SCAYT_SLANG: ${CKEDITOR_SCAYT_SLANG:-} + PHP_MEMORY_LIMIT: ${PHP_MEMORY_LIMIT:-1024M} + +services: + cli: + build: + context: . + dockerfile: .docker/Dockerfile.cli + args: + COMPOSER: ${COMPOSER:-composer.json} + EXAMPLE_IMAGE_VERSION: *example-image-version + image: *project + environment: + << : *default-environment + << : *default-volumes + volumes_from: ### Local overrides to mount host SSH keys. Automatically removed in CI. + - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. + labels: + lagoon.type: cli-persistent + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.persistent.name: nginx-php + lagoon.persistent.size: 50Gi + + nginx: + build: + context: . + dockerfile: .docker/Dockerfile.nginx-drupal + args: + CLI_IMAGE: *project + EXAMPLE_IMAGE_VERSION: *example-image-version + << : *default-volumes + environment: + << : *default-environment + depends_on: + - cli + networks: + - amazeeio-network + - default + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.persistent.size: 50Gi + lagoon.name: nginx-php + expose: + - "8080" + php: + build: + context: . + dockerfile: .docker/Dockerfile.php + args: + CLI_IMAGE: *project + EXAMPLE_IMAGE_VERSION: *example-image-version + environment: + << : *default-environment + << : *default-volumes + depends_on: + - cli + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.persistent.size: 50Gi + lagoon.name: nginx-php + + mariadb: + image: uselagoon/mariadb-10.4-drupal:latest + environment: + << : *default-environment + ports: + - "3306" # Find port on host with `ahoy info` or `docker-compose port mariadb 3306` + labels: + lagoon.type: mariadb-shared + + redis: + image: uselagoon/redis-5:latest + labels: + lagoon.type: redis + + elasticsearch: + build: + context: . + dockerfile: .docker/Dockerfile.elasticsearch + args: + - ES_TPL=${ES_TPL:-elasticsearch.yml} + labels: + lagoon.type: none + + chrome: + image: seleniarm/standalone-chromium:101.0 + shm_size: '1gb' + environment: + << : *default-environment + << : *default-volumes + depends_on: + - cli + labels: + lagoon.type: none + + clamav: + image: clamav/example-clamav:${EXAMPLE_IMAGE_VERSION:-4.x} + environment: + << : *default-environment + ports: + - "3310" + labels: + lagoon.type: none + +networks: + amazeeio-network: + external: true + +volumes: + app: {} + files: {} \ No newline at end of file diff --git a/internal/testdata/docker-compose/test5/docker-compose.yml b/internal/testdata/docker-compose/test5/docker-compose.yml new file mode 100644 index 00000000..992a85ca --- /dev/null +++ b/internal/testdata/docker-compose/test5/docker-compose.yml @@ -0,0 +1,131 @@ +version: '2.3' + +x-project: + &project ${PROJECT:-example-project} + +x-volumes: + &default-volumes + volumes: + + - .:/app:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. +x-user: + &default-user + user: '1000' + +x-environment: + &default-environment + LAGOON_LOCALDEV_URL: &default-url ${LOCALDEV_URL:-example-project.docker.amazee.io} + LAGOON_ROUTE: *default-url + XDEBUG_ENABLE: ${XDEBUG_ENABLE:-} + CI: ${CI:-} + DOCKERHOST: ${DOCKERHOST:-host.docker.internal} + PHP_MEMORY_LIMIT: "2G" + PHP_APC_SHM_SIZE: "256M" + PHP_MAX_EXECUTION_TIME: -1 + PHP_MAX_INPUT_VARS: 4000 + + LAGOON_PROJECT: *project + + LAGOON_ENVIRONMENT_TYPE: ${LAGOON_ENVIRONMENT_TYPE:-local} + +services: + + cli: + build: + context: . + dockerfile: .docker/Dockerfile.cli + image: *project + <<: *default-volumes + user: root + environment: + <<: *default-environment + volumes_from: ### Local overrides to mount host SSH keys. Automatically removed in CI. + - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. + ports: + - "35729" + labels: + lagoon.type: cli-persistent + lagoon.persistent.name: nginx-php + lagoon.persistent: /app/docroot/sites/default/files/ + nginx: + build: + context: . + dockerfile: .docker/Dockerfile.nginx-drupal + args: + CLI_IMAGE: *project + <<: *default-volumes + <<: *default-user + environment: + <<: *default-environment + depends_on: + - cli + networks: + - amazeeio-network + - default + labels: + lagoon.type: nginx-php-persistent + lagoon.name: nginx-php + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.persistent.class: slow + + php: + build: + context: . + dockerfile: .docker/Dockerfile.php + args: + CLI_IMAGE: *project + <<: *default-volumes + <<: *default-user + environment: + <<: *default-environment + depends_on: + - cli + labels: + lagoon.type: nginx-php-persistent + lagoon.name: nginx-php + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.persistent.class: slow + + mariadb: + build: + context: . + dockerfile: .docker/Dockerfile.mariadb + args: + IMAGE: "${DATABASE_IMAGE:-amazeeio/mariadb-drupal:21.7.0}" + environment: + <<: *default-environment + ports: + - "3306" + labels: + lagoon.type: mariadb + redis: + image: amazeeio/redis:6-21.11.0 + labels: + lagoon.type: redis + environment: + << : *default-environment + + chrome: + image: selenium/standalone-chrome:3.141.59-oxygen + shm_size: '1gb' + <<: *default-volumes + environment: + <<: *default-environment + depends_on: + - cli + labels: + lagoon.type: none + + wait_dependencies: + image: dadarek/wait-for-dependencies + depends_on: + - cli + - mariadb + command: mariadb:3306 + labels: + lagoon.type: none +networks: + amazeeio-network: + external: true +volumes: + app: {} \ No newline at end of file diff --git a/internal/testdata/docker-compose/test6/docker-compose.yml b/internal/testdata/docker-compose/test6/docker-compose.yml new file mode 100644 index 00000000..a3056e0f --- /dev/null +++ b/internal/testdata/docker-compose/test6/docker-compose.yml @@ -0,0 +1,138 @@ +version: '2.3' + +# This value intentionally matches the project name on Lagoon. +# It is used to name the CLI_IMAGE to use as a build arg locally. +x-lagoon-project: &lagoon-project + ca-learning2 + +x-lagoon-local-dev-url: &lagoon-local-dev-url + http://ca-learning2.docker.amazee.io + +x-example-image-version: &example-image-version + ${EXAMPLE_IMAGE_VERSION:-9.x-latest} + +x-volumes: &default-volumes + volumes: + - ./themes:/app/web/themes/custom:${VOLUME_FLAGS:-delegated} + - ./files:/app/web/sites/default/files:delegated + - ./tests/behat/features:/app/tests/behat/features:${VOLUME_FLAGS:-delegated} + - ./tests/behat/screenshots:/app/tests/behat/screenshots:${VOLUME_FLAGS:-delegated} + - ./tests/phpunit/tests:/app/tests/phpunit/tests:${VOLUME_FLAGS:-delegated} + - ./config:/app/config + +x-volumes-paas: &paas-volumes + volumes: + - .:/app:delegated + +x-environment: &default-environment + STAGE_FILE_PROXY_URL: ${STAGE_FILE_PROXY_URL:-} + LAGOON_ENVIRONMENT_TYPE: ${LAGOON_ENVIRONMENT_TYPE:-} + LAGOON_PROJECT: *lagoon-project + LAGOON_ROUTE: &default-url ${LOCALDEV_URL:-http://ca-learning2.docker.amazee.io} + EXAMPLE_IMAGE_VERSION: ${EXAMPLE_IMAGE_VERSION:-9.x-latest} + DEV_MODE: "${DEV_MODE:-false}" + XDEBUG_ENABLE: ${XDEBUG_ENABLE:-} + DOCKERHOST: ${DOCKERHOST:-host.docker.internal} + X_FRAME_OPTIONS: ${X_FRAME_OPTIONS:-SameOrigin} + DRUPAL_SHIELD_USER: ${DRUPAL_SHIELD_USER:-} + DRUPAL_SHIELD_PASS: ${DRUPAL_SHIELD_PASS:-} + EXAMPLE_DEPLOY_WORKFLOW_CONFIG: ${EXAMPLE_DEPLOY_WORKFLOW_CONFIG:-import} + EXAMPLE_PREPARE_XML_SCRIPT: /app/vendor/bin/example-prepare-xml + +services: + + cli: + build: + context: . + dockerfile: .docker/Dockerfile.cli + args: + LAGOON_SAFE_PROJECT: *lagoon-project + EXAMPLE_IMAGE_VERSION: *example-image-version + image: *lagoon-project + labels: + lagoon.type: cli-persistent + lagoon.persistent.name: nginx + lagoon.persistent: /app/web/sites/default/files/ + << : *default-volumes + environment: + << : *default-environment + # Mount volumes from Pygmy to inject host SSH key into container. + # https://pygmy.readthedocs.io/en/master/ssh_agent/ + volumes_from: ### Local overrides to mount host SSH keys. Automatically removed in CI. + - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. + + test: + build: + context: . + dockerfile: .docker/Dockerfile.test + args: + CLI_IMAGE: *lagoon-project + EXAMPLE_IMAGE_VERSION: *example-image-version + SITE_AUDIT_VERSION: ${SITE_AUDIT_VERSION:-7.x-3.x} + labels: + lagoon.type: none + << : *default-volumes + depends_on: + - cli + environment: + << : *default-environment + + nginx: + build: + context: . + dockerfile: .docker/Dockerfile.nginx-drupal + args: + CLI_IMAGE: *lagoon-project + EXAMPLE_IMAGE_VERSION: *example-image-version + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/web/sites/default/files/ + << : *default-volumes + depends_on: + - cli + environment: + << : *default-environment + LAGOON_LOCALDEV_URL: *default-url + networks: + - amazeeio-network + - default + + php: + build: + context: . + dockerfile: .docker/Dockerfile.php + args: + CLI_IMAGE: *lagoon-project + EXAMPLE_IMAGE_VERSION: *example-image-version + labels: + lagoon.type: nginx-php-persistent + lagoon.name: nginx + lagoon.persistent: /app/web/sites/default/files/ + << : *default-volumes + depends_on: + - cli + environment: + << : *default-environment + + mariadb: + image: ${MARIADB_DATA_IMAGE:-example/mariadb-drupal:9.x-latest} + labels: + lagoon.type: mariadb + lagoon.image: example/mariadb-drupal:9.x-latest + ports: + - "3306" # Find port on host with `docker-compose port mariadb 3306` + environment: + << : *default-environment + + chrome: + image: selenium/standalone-chrome + shm_size: '1gb' + depends_on: + - test + labels: + lagoon.type: none + << : *default-volumes + +networks: + amazeeio-network: + external: true \ No newline at end of file diff --git a/internal/testdata/docker-compose/test7/docker-compose.yml b/internal/testdata/docker-compose/test7/docker-compose.yml new file mode 100644 index 00000000..0bbf7416 --- /dev/null +++ b/internal/testdata/docker-compose/test7/docker-compose.yml @@ -0,0 +1,119 @@ +version: '2.3' + +x-lagoon-project: + &lagoon-project $PROJECT_NAME + +x-environment: + &default-environment + ENVIRONMENT_TYPE_ID: $ENVIRONMENT_TYPE_ID + LAGOON_PROJECT: *lagoon-project + LAGOON_ROUTE: &default-url http://$LAGOON_ROUTE + LAGOON_ENVIRONMENT_TYPE: $LAGOON_ENVIRONMENT_TYPE + XDEBUG_ENABLE: $XDEBUG_ENABLE + PHP_MEMORY_LIMIT: 768M + +### this block is invalid and returns a `Non-string key in x-site-branch: ` +x-site-branch: + &site-branch: $LAGOON_GIT_BRANCH +### this is how it should be, noting the missing `:` after `&site-branch` +# x-site-branch: +# &site-branch $LAGOON_GIT_BRANCH + +x-user: + &default-user + user: $DEFAULT_USER_ID + +services: + + cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) + build: + context: . + dockerfile: .lagoon/cli.dockerfile + args: + ENVIRONMENT_TYPE_ID: ${ENVIRONMENT_TYPE_ID} + DOCKER_CLI_IMAGE_URI: ${DOCKER_CLI_IMAGE_URI} + image: *lagoon-project # this image will be reused as `CLI_IMAGE` in subsequent Docker builds + container_name: ${PROJECT_NAME}_cli + labels: + # Lagoon Labels + lagoon.type: cli-persistent + lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container + lagoon.persistent: /app/docroot/sites/default/files/ # location where the persistent storage should be mounted + user: root + environment: + << : *default-environment # loads the defined environment variables from the top + volumes: + - ./.lagoon/scripts/bash_prompts.rc:/home/.bashrc + - ./.lagoon/scripts/color_grid.sh:/home/color_grid.sh + volumes_from: + - container:amazeeio-ssh-agent + + nginx: + build: + context: . + dockerfile: .lagoon/nginx.dockerfile + args: + CLI_IMAGE: *lagoon-project + DOCKER_NGINX_IMAGE_URI: ${DOCKER_NGINX_IMAGE_URI} + LAGOON_GIT_BRANCH: *site-branch + container_name: ${PROJECT_NAME}_nginx + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.name: nginx + << : *default-user # uses the defined user from top + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + # LAGOON_LOCALDEV_URL: nginx-${LAGOON_ROUTE} + LAGOON_LOCALDEV_URL: *default-url + networks: + - amazeeio-network + - default + volumes: + - ./.lagoon/nginx/nginx-http.conf:/etc/nginx/conf.d/000-nginx-http.conf + - ./.lagoon/nginx/app.conf:/etc/nginx/conf.d/app.conf + + php: + build: + context: . + dockerfile: .lagoon/php.dockerfile + args: + CLI_IMAGE: *lagoon-project + DOCKER_PHP_IMAGE_URI: ${DOCKER_PHP_IMAGE_URI} + container_name: ${PROJECT_NAME}_php + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/docroot/sites/default/files + lagoon.name: nginx + lagoon.deployment.servicetype: php + << : *default-user # uses the defined user from top + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + + mariadb: + image: amazeeio/mariadb-drupal + container_name: ${PROJECT_NAME}_db + labels: + lagoon.type: mariadb + ports: + - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` + << : *default-user # uses the defined user from top + environment: + << : *default-environment + volumes: + - mysql:/var/lib/mysql + + +networks: + amazeeio-network: + external: true + +volumes: + app: + # Add a volume for the DB so it persists between shutdowns. + mysql: + solr7: \ No newline at end of file diff --git a/internal/testdata/docker-compose/test8/docker-compose.yml b/internal/testdata/docker-compose/test8/docker-compose.yml new file mode 100644 index 00000000..0bbf7416 --- /dev/null +++ b/internal/testdata/docker-compose/test8/docker-compose.yml @@ -0,0 +1,119 @@ +version: '2.3' + +x-lagoon-project: + &lagoon-project $PROJECT_NAME + +x-environment: + &default-environment + ENVIRONMENT_TYPE_ID: $ENVIRONMENT_TYPE_ID + LAGOON_PROJECT: *lagoon-project + LAGOON_ROUTE: &default-url http://$LAGOON_ROUTE + LAGOON_ENVIRONMENT_TYPE: $LAGOON_ENVIRONMENT_TYPE + XDEBUG_ENABLE: $XDEBUG_ENABLE + PHP_MEMORY_LIMIT: 768M + +### this block is invalid and returns a `Non-string key in x-site-branch: ` +x-site-branch: + &site-branch: $LAGOON_GIT_BRANCH +### this is how it should be, noting the missing `:` after `&site-branch` +# x-site-branch: +# &site-branch $LAGOON_GIT_BRANCH + +x-user: + &default-user + user: $DEFAULT_USER_ID + +services: + + cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) + build: + context: . + dockerfile: .lagoon/cli.dockerfile + args: + ENVIRONMENT_TYPE_ID: ${ENVIRONMENT_TYPE_ID} + DOCKER_CLI_IMAGE_URI: ${DOCKER_CLI_IMAGE_URI} + image: *lagoon-project # this image will be reused as `CLI_IMAGE` in subsequent Docker builds + container_name: ${PROJECT_NAME}_cli + labels: + # Lagoon Labels + lagoon.type: cli-persistent + lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container + lagoon.persistent: /app/docroot/sites/default/files/ # location where the persistent storage should be mounted + user: root + environment: + << : *default-environment # loads the defined environment variables from the top + volumes: + - ./.lagoon/scripts/bash_prompts.rc:/home/.bashrc + - ./.lagoon/scripts/color_grid.sh:/home/color_grid.sh + volumes_from: + - container:amazeeio-ssh-agent + + nginx: + build: + context: . + dockerfile: .lagoon/nginx.dockerfile + args: + CLI_IMAGE: *lagoon-project + DOCKER_NGINX_IMAGE_URI: ${DOCKER_NGINX_IMAGE_URI} + LAGOON_GIT_BRANCH: *site-branch + container_name: ${PROJECT_NAME}_nginx + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.name: nginx + << : *default-user # uses the defined user from top + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + # LAGOON_LOCALDEV_URL: nginx-${LAGOON_ROUTE} + LAGOON_LOCALDEV_URL: *default-url + networks: + - amazeeio-network + - default + volumes: + - ./.lagoon/nginx/nginx-http.conf:/etc/nginx/conf.d/000-nginx-http.conf + - ./.lagoon/nginx/app.conf:/etc/nginx/conf.d/app.conf + + php: + build: + context: . + dockerfile: .lagoon/php.dockerfile + args: + CLI_IMAGE: *lagoon-project + DOCKER_PHP_IMAGE_URI: ${DOCKER_PHP_IMAGE_URI} + container_name: ${PROJECT_NAME}_php + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/docroot/sites/default/files + lagoon.name: nginx + lagoon.deployment.servicetype: php + << : *default-user # uses the defined user from top + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + + mariadb: + image: amazeeio/mariadb-drupal + container_name: ${PROJECT_NAME}_db + labels: + lagoon.type: mariadb + ports: + - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` + << : *default-user # uses the defined user from top + environment: + << : *default-environment + volumes: + - mysql:/var/lib/mysql + + +networks: + amazeeio-network: + external: true + +volumes: + app: + # Add a volume for the DB so it persists between shutdowns. + mysql: + solr7: \ No newline at end of file diff --git a/internal/testdata/docker-compose/test9/docker-compose.yml b/internal/testdata/docker-compose/test9/docker-compose.yml new file mode 100644 index 00000000..c58a678e --- /dev/null +++ b/internal/testdata/docker-compose/test9/docker-compose.yml @@ -0,0 +1,111 @@ +version: '2.3' + +x-lagoon-project: + # Lagoon project name (leave `&lagoon-project` when you edit this) + &lagoon-project "${COMPOSE_PROJECT_NAME}" + +x-environment: + &default-environment + LAGOON_PROJECT: *lagoon-project + # Route that should be used locally + LAGOON_ROUTE: "https://${DRUPAL_HOSTNAME}" + SSMTP_MAILHUB: "host.docker.internal:1025" + +services: + + cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) + container_name: "${COMPOSE_PROJECT_NAME}-cli" + build: + context: . + dockerfile: lagoon/cli.dockerfile + image: *lagoon-project # this image will be reused as `CLI_IMAGE` in subsequent Docker builds + labels: + # Lagoon Labels + lagoon.type: cli-persistent + lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container + lagoon.persistent: "/app/public/sites/default/files/" # location where the persistent storage should be mounted + volumes: + - .:/app:delegated + - ssh:/tmp/amazeeio_ssh-agent + environment: + << : *default-environment # loads the defined environment variables from the top + SIMPLETEST_BASE_URL: "http://nginx:8080" + SIMPLETEST_DB: "mysql://drupal:drupal@mariadb:3306/drupal" + DRUSH_OPTIONS_URI: "https://${DRUPAL_HOSTNAME}" + env_file: + - .env.local + + nginx: + container_name: "${COMPOSE_PROJECT_NAME}-nginx" + build: + context: . + dockerfile: lagoon/nginx.dockerfile + args: + CLI_IMAGE: *lagoon-project # Inject the name of the cli image + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: "/app/public/sites/default/files/" # define where the persistent file storage should be mounted too + volumes: + - .:/app:delegated + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + LAGOON_LOCALDEV_URL: "${DRUPAL_HOSTNAME}" # generate another route for nginx, by default we go to varnish + networks: + - stonehenge-network + - default + + php: + container_name: "${COMPOSE_PROJECT_NAME}-php" + build: + context: . + dockerfile: lagoon/php.dockerfile + args: + CLI_IMAGE: *lagoon-project + labels: + lagoon.type: nginx-php-persistent + lagoon.name: nginx # we want this service be part of the nginx pod in Lagoon + lagoon.persistent: /app/public/sites/default/files/ # define where the persistent storage should be mounted too + volumes: + - .:/app:delegated + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + env_file: + - .env.local + + mariadb: + container_name: "${COMPOSE_PROJECT_NAME}-db" + image: uselagoon/mariadb-drupal:latest + labels: + lagoon.type: mariadb + ports: + - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` + environment: + << : *default-environment + + pma: + image: phpmyadmin/phpmyadmin + container_name: "${COMPOSE_PROJECT_NAME}-pma" + environment: + PMA_HOST: mariadb + PMA_USER: drupal + PMA_PASSWORD: drupal + UPLOAD_LIMIT: 1G + labels: + lagoon.type: none + networks: + - default + - stonehenge-network + +networks: + stonehenge-network: + external: true + +volumes: + es_data: + ssh: + name: stonehenge-ssh + external: true \ No newline at end of file diff --git a/internal/testdata/nginxphp/docker-compose.nginx-1.yml b/internal/testdata/nginxphp/docker-compose.nginx-1.yml index caaf0425..c8082e81 100644 --- a/internal/testdata/nginxphp/docker-compose.nginx-1.yml +++ b/internal/testdata/nginxphp/docker-compose.nginx-1.yml @@ -5,7 +5,7 @@ services: - amazeeio-network - default build: - context: . + context: internal/testdata/nginxphp/docker dockerfile: nginx.dockerfile labels: lagoon.type: nginx-php @@ -18,7 +18,7 @@ services: php: build: - context: . + context: internal/testdata/nginxphp/docker dockerfile: php.dockerfile depends_on: - cli diff --git a/internal/testdata/nginxphp/docker-compose.servicename.yml b/internal/testdata/nginxphp/docker-compose.servicename.yml index 060a5168..34b14fc4 100644 --- a/internal/testdata/nginxphp/docker-compose.servicename.yml +++ b/internal/testdata/nginxphp/docker-compose.servicename.yml @@ -2,7 +2,7 @@ version: '2' services: nginx: build: - context: . + context: internal/testdata/nginxphp/docker dockerfile: nginx.dockerfile labels: lagoon.type: nginx-php-persistent @@ -11,7 +11,7 @@ services: php: build: - context: . + context: internal/testdata/nginxphp/docker dockerfile: php.dockerfile labels: lagoon.type: nginx-php-persistent diff --git a/internal/testdata/nginxphp/docker-compose.yml b/internal/testdata/nginxphp/docker-compose.yml index 0fbd183e..eccca5f9 100644 --- a/internal/testdata/nginxphp/docker-compose.yml +++ b/internal/testdata/nginxphp/docker-compose.yml @@ -2,7 +2,7 @@ version: '2' services: nginx: build: - context: . + context: internal/testdata/nginxphp/docker dockerfile: nginx.dockerfile labels: lagoon.type: nginx-php-persistent @@ -10,7 +10,7 @@ services: php: build: - context: . + context: internal/testdata/nginxphp/docker dockerfile: php.dockerfile labels: lagoon.type: nginx-php-persistent diff --git a/internal/testdata/nginxphp/docker/nginx.dockerfile b/internal/testdata/nginxphp/docker/nginx.dockerfile new file mode 100644 index 00000000..aff3c474 --- /dev/null +++ b/internal/testdata/nginxphp/docker/nginx.dockerfile @@ -0,0 +1 @@ +FROM uselagoon/fake-nginx:latest diff --git a/internal/testdata/nginxphp/docker/php.dockerfile b/internal/testdata/nginxphp/docker/php.dockerfile new file mode 100644 index 00000000..8141f2cd --- /dev/null +++ b/internal/testdata/nginxphp/docker/php.dockerfile @@ -0,0 +1 @@ +FROM uselagoon/fake-php:latest diff --git a/internal/testdata/nginxphp/lagoon.nginx-1.yml b/internal/testdata/nginxphp/lagoon.nginx-1.yml index 26364829..4212e188 100644 --- a/internal/testdata/nginxphp/lagoon.nginx-1.yml +++ b/internal/testdata/nginxphp/lagoon.nginx-1.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/nginxphp/docker-compose.nginx-1.yml +docker-compose-yaml: internal/testdata/nginxphp/docker-compose.nginx-1.yml routes: autogenerate: diff --git a/internal/testdata/nginxphp/lagoon.nginx-2.yml b/internal/testdata/nginxphp/lagoon.nginx-2.yml index e6b20a46..3f676c05 100644 --- a/internal/testdata/nginxphp/lagoon.nginx-2.yml +++ b/internal/testdata/nginxphp/lagoon.nginx-2.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/nginxphp/docker-compose.nginx-1.yml +docker-compose-yaml: internal/testdata/nginxphp/docker-compose.nginx-1.yml environment_variables: git_sha: "true" diff --git a/internal/testdata/nginxphp/lagoon.servicename.yml b/internal/testdata/nginxphp/lagoon.servicename.yml index a9a9fb75..fa08e84b 100644 --- a/internal/testdata/nginxphp/lagoon.servicename.yml +++ b/internal/testdata/nginxphp/lagoon.servicename.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/nginxphp/docker-compose.servicename.yml +docker-compose-yaml: internal/testdata/nginxphp/docker-compose.servicename.yml routes: autogenerate: diff --git a/internal/testdata/nginxphp/lagoon.yml b/internal/testdata/nginxphp/lagoon.yml index a2006fe2..8b2abb3a 100644 --- a/internal/testdata/nginxphp/lagoon.yml +++ b/internal/testdata/nginxphp/lagoon.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/nginxphp/docker-compose.yml +docker-compose-yaml: internal/testdata/nginxphp/docker-compose.yml routes: autogenerate: diff --git a/internal/testdata/node/docker-compose.autogen-1.yml b/internal/testdata/node/docker-compose.autogen-1.yml index 1d1311eb..dfeddddb 100644 --- a/internal/testdata/node/docker-compose.autogen-1.yml +++ b/internal/testdata/node/docker-compose.autogen-1.yml @@ -5,7 +5,7 @@ services: - amazeeio-network - default build: - context: . + context: internal/testdata/node/docker dockerfile: node.dockerfile labels: lagoon.type: node diff --git a/internal/testdata/node/docker-compose.autogen-2.yml b/internal/testdata/node/docker-compose.autogen-2.yml index 4d4abe45..7663632d 100644 --- a/internal/testdata/node/docker-compose.autogen-2.yml +++ b/internal/testdata/node/docker-compose.autogen-2.yml @@ -5,7 +5,7 @@ services: - amazeeio-network - default build: - context: . + context: internal/testdata/node/docker dockerfile: node.dockerfile labels: lagoon.type: node diff --git a/internal/testdata/node/docker-compose.autogen-3.yml b/internal/testdata/node/docker-compose.autogen-3.yml index d7ff82f7..c5564f7f 100644 --- a/internal/testdata/node/docker-compose.autogen-3.yml +++ b/internal/testdata/node/docker-compose.autogen-3.yml @@ -5,7 +5,7 @@ services: - amazeeio-network - default build: - context: . + context: internal/testdata/node/docker dockerfile: node.dockerfile labels: lagoon.type: node diff --git a/internal/testdata/node/docker-compose.none.yml b/internal/testdata/node/docker-compose.none.yml index edaf9cd4..0f16891f 100644 --- a/internal/testdata/node/docker-compose.none.yml +++ b/internal/testdata/node/docker-compose.none.yml @@ -5,7 +5,7 @@ services: - amazeeio-network - default build: - context: . + context: internal/testdata/node/docker dockerfile: node.dockerfile labels: lagoon.type: none diff --git a/internal/testdata/node/docker-compose.yml b/internal/testdata/node/docker-compose.yml index 85386270..67655b61 100644 --- a/internal/testdata/node/docker-compose.yml +++ b/internal/testdata/node/docker-compose.yml @@ -5,7 +5,7 @@ services: - amazeeio-network - default build: - context: . + context: internal/testdata/node/docker dockerfile: node.dockerfile labels: lagoon.type: node diff --git a/internal/testdata/node/docker/node.dockerfile b/internal/testdata/node/docker/node.dockerfile new file mode 100644 index 00000000..ad1290a7 --- /dev/null +++ b/internal/testdata/node/docker/node.dockerfile @@ -0,0 +1 @@ +FROM uselagoon/fake-node:latest \ No newline at end of file diff --git a/internal/testdata/node/lagoon.activestandby.yml b/internal/testdata/node/lagoon.activestandby.yml index 989a014e..c138fc5c 100644 --- a/internal/testdata/node/lagoon.activestandby.yml +++ b/internal/testdata/node/lagoon.activestandby.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.yml +docker-compose-yaml: internal/testdata/node/docker-compose.yml environment_variables: git_sha: "true" diff --git a/internal/testdata/node/lagoon.autogen-1.yml b/internal/testdata/node/lagoon.autogen-1.yml index 59e41789..b06ebc9e 100644 --- a/internal/testdata/node/lagoon.autogen-1.yml +++ b/internal/testdata/node/lagoon.autogen-1.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.yml +docker-compose-yaml: internal/testdata/node/docker-compose.yml routes: autogenerate: diff --git a/internal/testdata/node/lagoon.autogen-2.yml b/internal/testdata/node/lagoon.autogen-2.yml index 373e85f4..5edace3b 100644 --- a/internal/testdata/node/lagoon.autogen-2.yml +++ b/internal/testdata/node/lagoon.autogen-2.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.yml +docker-compose-yaml: internal/testdata/node/docker-compose.yml routes: autogenerate: diff --git a/internal/testdata/node/lagoon.autogen-3.yml b/internal/testdata/node/lagoon.autogen-3.yml index d57c4d1b..d1c64af9 100644 --- a/internal/testdata/node/lagoon.autogen-3.yml +++ b/internal/testdata/node/lagoon.autogen-3.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.autogen-1.yml +docker-compose-yaml: internal/testdata/node/docker-compose.autogen-1.yml routes: autogenerate: diff --git a/internal/testdata/node/lagoon.autogen-4.yml b/internal/testdata/node/lagoon.autogen-4.yml index 4a17f112..b949a192 100644 --- a/internal/testdata/node/lagoon.autogen-4.yml +++ b/internal/testdata/node/lagoon.autogen-4.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.autogen-2.yml +docker-compose-yaml: internal/testdata/node/docker-compose.autogen-2.yml routes: autogenerate: diff --git a/internal/testdata/node/lagoon.autogen-5.yml b/internal/testdata/node/lagoon.autogen-5.yml index a2d65bec..ac0754c8 100644 --- a/internal/testdata/node/lagoon.autogen-5.yml +++ b/internal/testdata/node/lagoon.autogen-5.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.yml +docker-compose-yaml: internal/testdata/node/docker-compose.yml routes: autogenerate: diff --git a/internal/testdata/node/lagoon.autogen-6.yml b/internal/testdata/node/lagoon.autogen-6.yml index 874130b3..6364feb1 100644 --- a/internal/testdata/node/lagoon.autogen-6.yml +++ b/internal/testdata/node/lagoon.autogen-6.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.none.yml +docker-compose-yaml: internal/testdata/node/docker-compose.none.yml routes: autogenerate: diff --git a/internal/testdata/node/lagoon.autogen-7.yml b/internal/testdata/node/lagoon.autogen-7.yml index 0da39080..c2196f3d 100644 --- a/internal/testdata/node/lagoon.autogen-7.yml +++ b/internal/testdata/node/lagoon.autogen-7.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.yml +docker-compose-yaml: internal/testdata/node/docker-compose.yml routes: autogenerate: diff --git a/internal/testdata/node/lagoon.autogen-8.yml b/internal/testdata/node/lagoon.autogen-8.yml index e03471a0..6e70dce9 100644 --- a/internal/testdata/node/lagoon.autogen-8.yml +++ b/internal/testdata/node/lagoon.autogen-8.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.autogen-3.yml +docker-compose-yaml: internal/testdata/node/docker-compose.autogen-3.yml routes: autogenerate: diff --git a/internal/testdata/node/lagoon.autogen-9.yml b/internal/testdata/node/lagoon.autogen-9.yml index 0fe4f520..38d9ab54 100644 --- a/internal/testdata/node/lagoon.autogen-9.yml +++ b/internal/testdata/node/lagoon.autogen-9.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.yml +docker-compose-yaml: internal/testdata/node/docker-compose.yml routes: autogenerate: diff --git a/internal/testdata/node/lagoon.autogen-prefixes-1.yml b/internal/testdata/node/lagoon.autogen-prefixes-1.yml index 1acdb5e3..4e30cb7d 100644 --- a/internal/testdata/node/lagoon.autogen-prefixes-1.yml +++ b/internal/testdata/node/lagoon.autogen-prefixes-1.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.yml +docker-compose-yaml: internal/testdata/node/docker-compose.yml routes: autogenerate: diff --git a/internal/testdata/node/lagoon.polysite-pr.yml b/internal/testdata/node/lagoon.polysite-pr.yml index f1689a8f..c324dbef 100644 --- a/internal/testdata/node/lagoon.polysite-pr.yml +++ b/internal/testdata/node/lagoon.polysite-pr.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.yml +docker-compose-yaml: internal/testdata/node/docker-compose.yml environment_variables: git_sha: 'true' diff --git a/internal/testdata/node/lagoon.polysite.yml b/internal/testdata/node/lagoon.polysite.yml index de37de5e..9527fab1 100644 --- a/internal/testdata/node/lagoon.polysite.yml +++ b/internal/testdata/node/lagoon.polysite.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.yml +docker-compose-yaml: internal/testdata/node/docker-compose.yml environment_variables: git_sha: "true" diff --git a/internal/testdata/node/lagoon.yml b/internal/testdata/node/lagoon.yml index 8acb00ed..97a55e2a 100644 --- a/internal/testdata/node/lagoon.yml +++ b/internal/testdata/node/lagoon.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.yml +docker-compose-yaml: internal/testdata/node/docker-compose.yml routes: autogenerate: diff --git a/internal/testdata/testdata.go b/internal/testdata/testdata.go index c2d7ff93..1664f868 100644 --- a/internal/testdata/testdata.go +++ b/internal/testdata/testdata.go @@ -44,6 +44,7 @@ type TestData struct { Namespace string ImageReferences map[string]string ConfigMapSha string + ImageRegistry string } // helper function to set up all the environment variables from provided testdata @@ -130,6 +131,10 @@ func SetupEnvironment(rootCmd cobra.Command, templatePath string, t TestData) (g if err != nil { return generator.GeneratorInput{}, err } + err = os.Setenv("REGISTRY", t.ImageRegistry) + if err != nil { + return generator.GeneratorInput{}, err + } generator, err := generator.GenerateInput(rootCmd, false) if err != nil { @@ -169,8 +174,9 @@ func GetSeedData(t TestData, defaultProjectVariables bool) TestData { Scope: "internal_system", }, }, - K8UPVersion: "v1", - ConfigMapSha: "abcdefg1234567890", + K8UPVersion: "v1", + ConfigMapSha: "abcdefg1234567890", + ImageRegistry: "harbor.example", } if t.ProjectName != "" { rt.ProjectName = t.ProjectName diff --git a/internal/testdata/validate-lagoon-yml/cronjobs/lagoon-override-env.yml b/internal/testdata/validate-lagoon-yml/cronjobs/lagoon-override-env.yml new file mode 100644 index 00000000..47149945 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/cronjobs/lagoon-override-env.yml @@ -0,0 +1,20 @@ +tasks: + pre-rollout: + - run: + name: envvar pre-rollout task1 + command: echo "task 1" + service: cli + weight: -1 + post-rollout: + - run: + name: envvar post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + weight: -1 + - run: + name: envvar post-rollout task2 + command: echo "task 2" + service: cli + shell: bash + weight: 1 \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/cronjobs/lagoon-override.yml b/internal/testdata/validate-lagoon-yml/cronjobs/lagoon-override.yml new file mode 100644 index 00000000..b7a2e400 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/cronjobs/lagoon-override.yml @@ -0,0 +1,20 @@ +tasks: + pre-rollout: + - run: + name: file pre-rollout task1 + command: echo "task 1" + service: cli + weight: -1 + post-rollout: + - run: + name: file post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + weight: -1 + - run: + name: file post-rollout task2 + command: echo "task 2" + service: cli + shell: bash + weight: 1 \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/cronjobs/lagoon.yml b/internal/testdata/validate-lagoon-yml/cronjobs/lagoon.yml new file mode 100644 index 00000000..a9d4ae17 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/cronjobs/lagoon.yml @@ -0,0 +1,49 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + cronjobs: + - name: block scalar literal stripped + command: |- + multiline + command + + - name: flow scalar plain 2 + command: singleline command + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect + + +tasks: + pre-rollout: + - run: + name: lagoon.yml pre-rollout task1 + command: echo "task 1" + service: cli + post-rollout: + - run: + name: lagoon.yml post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + - run: + name: lagoon.yml post-rollout task2 + command: echo "task 2" + service: cli + shell: bash diff --git a/internal/testdata/validate-lagoon-yml/cronjobs/multiline-cronjobs.lagoon.yml b/internal/testdata/validate-lagoon-yml/cronjobs/multiline-cronjobs.lagoon.yml new file mode 100644 index 00000000..7b743990 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/cronjobs/multiline-cronjobs.lagoon.yml @@ -0,0 +1,53 @@ +# All the possible YAML incantations for introducing a newline into a string. +# https://yaml-multiline.info/ +environments: + main: + cronjobs: + - name: flow scalar plain + command: multiline + + command + - name: flow scalar single quoted + command: 'multiline + + command' + - name: flow scalar double quoted newline + command: "multiline + + command" + - name: flow scalar double quoted escaped + command: "multiline\ncommand" + - name: multiline block literal clipped + command: | + multiline + command + + - name: block scalar literal stripped + command: |- + multiline + command + + - name: block scalar literal keep + command: |+ + multiline + command + + - name: block scalar folded clipped + command: > + multiline + + command + + - name: block scalar folded stripped + command: >- + multiline + + command + + - name: block scalar folded keep + command: >+ + multiline + + command + +# dummy comment to keep previous newline diff --git a/internal/testdata/validate-lagoon-yml/cronjobs/singleline-cronjobs.lagoon.yml b/internal/testdata/validate-lagoon-yml/cronjobs/singleline-cronjobs.lagoon.yml new file mode 100644 index 00000000..4a3c5b7e --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/cronjobs/singleline-cronjobs.lagoon.yml @@ -0,0 +1,46 @@ +# Strings that may appear to have newlines but don't. +environments: + main: + cronjobs: + - name: flow scalar plain 1 + command: singleline + command + - name: flow scalar plain 2 + command: singleline command + - name: flow scalar plain 3 + command: singleline\ncommand + - name: flow scalar single quoted 1 + command: 'singleline + command' + - name: flow scalar single quoted 2 + command: 'singleline command' + - name: flow scalar single quoted 3 + command: 'singleline\ncommand' + - name: flow scalar double quoted 1 + command: "singleline + command" + - name: flow scalar double quoted 2 + command: "singleline command" + - name: flow scalar double quoted 3 + command: "singleline\ + command" + - name: block scalar literal stripped + command: |- + singleline command + + - name: block scalar folded clipped 1 + command: > + singleline + command + - name: block scalar folded clipped 2 + command: > + singleline command + - name: block scalar folded stripped 1 + command: >- + singleline + command + - name: block scalar folded stripped 2 + command: >- + singleline command + +# dummy comment to keep previous newline diff --git a/internal/testdata/validate-lagoon-yml/test1/lagoon.yml b/internal/testdata/validate-lagoon-yml/test1/lagoon.yml new file mode 100644 index 00000000..71ae5215 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test1/lagoon.yml @@ -0,0 +1,22 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect diff --git a/internal/testdata/validate-lagoon-yml/test2/lagoon-final.yml b/internal/testdata/validate-lagoon-yml/test2/lagoon-final.yml new file mode 100644 index 00000000..bbbfb406 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test2/lagoon-final.yml @@ -0,0 +1,56 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect +tasks: + pre-rollout: + - run: + name: file pre-rollout task1 + command: echo "task 1" + service: cli + weight: -1 + - run: + name: lagoon.yml pre-rollout task1 + command: echo "task 1" + service: cli + post-rollout: + - run: + name: file post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + weight: -1 + - run: + name: lagoon.yml post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + - run: + name: lagoon.yml post-rollout task2 + command: echo "task 2" + service: cli + shell: bash + - run: + name: file post-rollout task2 + command: echo "task 2" + service: cli + shell: bash + weight: 1 \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test2/lagoon-override.yml b/internal/testdata/validate-lagoon-yml/test2/lagoon-override.yml new file mode 100644 index 00000000..b7a2e400 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test2/lagoon-override.yml @@ -0,0 +1,20 @@ +tasks: + pre-rollout: + - run: + name: file pre-rollout task1 + command: echo "task 1" + service: cli + weight: -1 + post-rollout: + - run: + name: file post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + weight: -1 + - run: + name: file post-rollout task2 + command: echo "task 2" + service: cli + shell: bash + weight: 1 \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test2/lagoon.yml b/internal/testdata/validate-lagoon-yml/test2/lagoon.yml new file mode 100644 index 00000000..73e22746 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test2/lagoon.yml @@ -0,0 +1,41 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect + + +tasks: + pre-rollout: + - run: + name: lagoon.yml pre-rollout task1 + command: echo "task 1" + service: cli + post-rollout: + - run: + name: lagoon.yml post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + - run: + name: lagoon.yml post-rollout task2 + command: echo "task 2" + service: cli + shell: bash \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test3/lagoon-final.yml b/internal/testdata/validate-lagoon-yml/test3/lagoon-final.yml new file mode 100644 index 00000000..484caaa6 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test3/lagoon-final.yml @@ -0,0 +1,56 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect +tasks: + pre-rollout: + - run: + name: envvar pre-rollout task1 + command: echo "task 1" + service: cli + weight: -1 + - run: + name: lagoon.yml pre-rollout task1 + command: echo "task 1" + service: cli + post-rollout: + - run: + name: envvar post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + weight: -1 + - run: + name: lagoon.yml post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + - run: + name: lagoon.yml post-rollout task2 + command: echo "task 2" + service: cli + shell: bash + - run: + name: envvar post-rollout task2 + command: echo "task 2" + service: cli + shell: bash + weight: 1 \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test3/lagoon-override.yml b/internal/testdata/validate-lagoon-yml/test3/lagoon-override.yml new file mode 100644 index 00000000..47149945 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test3/lagoon-override.yml @@ -0,0 +1,20 @@ +tasks: + pre-rollout: + - run: + name: envvar pre-rollout task1 + command: echo "task 1" + service: cli + weight: -1 + post-rollout: + - run: + name: envvar post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + weight: -1 + - run: + name: envvar post-rollout task2 + command: echo "task 2" + service: cli + shell: bash + weight: 1 \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test3/lagoon.yml b/internal/testdata/validate-lagoon-yml/test3/lagoon.yml new file mode 100644 index 00000000..73e22746 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test3/lagoon.yml @@ -0,0 +1,41 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect + + +tasks: + pre-rollout: + - run: + name: lagoon.yml pre-rollout task1 + command: echo "task 1" + service: cli + post-rollout: + - run: + name: lagoon.yml post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + - run: + name: lagoon.yml post-rollout task2 + command: echo "task 2" + service: cli + shell: bash \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test4/lagoon-final.yml b/internal/testdata/validate-lagoon-yml/test4/lagoon-final.yml new file mode 100644 index 00000000..19a29bd0 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test4/lagoon-final.yml @@ -0,0 +1,73 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect +tasks: + pre-rollout: + - run: + name: envvar pre-rollout task1 + command: echo "task 1" + service: cli + weight: -1 + - run: + name: lagoon.yml pre-rollout task1 + command: echo "task 1" + service: cli + - run: + name: file pre-rollout task1 + command: echo "task 1" + service: cli + weight: 1 + post-rollout: + - run: + name: file post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + weight: -2 + - run: + name: envvar post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + weight: -1 + - run: + name: lagoon.yml post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + - run: + name: lagoon.yml post-rollout task2 + command: echo "task 2" + service: cli + shell: bash + - run: + name: envvar post-rollout task2 + command: echo "task 2" + service: cli + shell: bash + weight: 1 + - run: + name: file post-rollout task2 + command: echo "task 2" + service: cli + shell: bash + weight: 2 \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test4/lagoon-override-env.yml b/internal/testdata/validate-lagoon-yml/test4/lagoon-override-env.yml new file mode 100644 index 00000000..47149945 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test4/lagoon-override-env.yml @@ -0,0 +1,20 @@ +tasks: + pre-rollout: + - run: + name: envvar pre-rollout task1 + command: echo "task 1" + service: cli + weight: -1 + post-rollout: + - run: + name: envvar post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + weight: -1 + - run: + name: envvar post-rollout task2 + command: echo "task 2" + service: cli + shell: bash + weight: 1 \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test4/lagoon-override.yml b/internal/testdata/validate-lagoon-yml/test4/lagoon-override.yml new file mode 100644 index 00000000..1f23d5b9 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test4/lagoon-override.yml @@ -0,0 +1,20 @@ +tasks: + pre-rollout: + - run: + name: file pre-rollout task1 + command: echo "task 1" + service: cli + weight: 1 + post-rollout: + - run: + name: file post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + weight: -2 + - run: + name: file post-rollout task2 + command: echo "task 2" + service: cli + shell: bash + weight: 2 \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test4/lagoon.yml b/internal/testdata/validate-lagoon-yml/test4/lagoon.yml new file mode 100644 index 00000000..73e22746 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test4/lagoon.yml @@ -0,0 +1,41 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect + + +tasks: + pre-rollout: + - run: + name: lagoon.yml pre-rollout task1 + command: echo "task 1" + service: cli + post-rollout: + - run: + name: lagoon.yml post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + - run: + name: lagoon.yml post-rollout task2 + command: echo "task 2" + service: cli + shell: bash \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test5/lagoon-final.yml b/internal/testdata/validate-lagoon-yml/test5/lagoon-final.yml new file mode 100644 index 00000000..6a482eae --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test5/lagoon-final.yml @@ -0,0 +1,35 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect +tasks: + pre-rollout: + post-rollout: + - run: + name: lagoon.yml post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + - run: + name: override me + command: echo "overridden" + service: cli + shell: bash diff --git a/internal/testdata/validate-lagoon-yml/test5/lagoon-override.yml b/internal/testdata/validate-lagoon-yml/test5/lagoon-override.yml new file mode 100644 index 00000000..0e576cb0 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test5/lagoon-override.yml @@ -0,0 +1,8 @@ +tasks: + pre-rollout: + post-rollout: + - run: + name: override me + command: echo "overridden" + service: cli + shell: bash \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test5/lagoon.yml b/internal/testdata/validate-lagoon-yml/test5/lagoon.yml new file mode 100644 index 00000000..9d1e1f28 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test5/lagoon.yml @@ -0,0 +1,37 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect + + +tasks: + pre-rollout: + post-rollout: + - run: + name: lagoon.yml post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + - run: + name: override me + command: echo "should be overridden" + service: cli + shell: bash \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test6/lagoon-final.yml b/internal/testdata/validate-lagoon-yml/test6/lagoon-final.yml new file mode 100644 index 00000000..6a482eae --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test6/lagoon-final.yml @@ -0,0 +1,35 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect +tasks: + pre-rollout: + post-rollout: + - run: + name: lagoon.yml post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + - run: + name: override me + command: echo "overridden" + service: cli + shell: bash diff --git a/internal/testdata/validate-lagoon-yml/test6/lagoon-override.yml b/internal/testdata/validate-lagoon-yml/test6/lagoon-override.yml new file mode 100644 index 00000000..b251a1b4 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test6/lagoon-override.yml @@ -0,0 +1,9 @@ +{error {error}} +tasks: + pre-rollout: + post-rollout: + - run: + name: override me + command: echo "overridden" + service: cli + shell: bash \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test6/lagoon.yml b/internal/testdata/validate-lagoon-yml/test6/lagoon.yml new file mode 100644 index 00000000..9d1e1f28 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test6/lagoon.yml @@ -0,0 +1,37 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect + + +tasks: + pre-rollout: + post-rollout: + - run: + name: lagoon.yml post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + - run: + name: override me + command: echo "should be overridden" + service: cli + shell: bash \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test7/lagoon-final.yml b/internal/testdata/validate-lagoon-yml/test7/lagoon-final.yml new file mode 100644 index 00000000..6a482eae --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test7/lagoon-final.yml @@ -0,0 +1,35 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect +tasks: + pre-rollout: + post-rollout: + - run: + name: lagoon.yml post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + - run: + name: override me + command: echo "overridden" + service: cli + shell: bash diff --git a/internal/testdata/validate-lagoon-yml/test7/lagoon-override.yml b/internal/testdata/validate-lagoon-yml/test7/lagoon-override.yml new file mode 100644 index 00000000..b251a1b4 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test7/lagoon-override.yml @@ -0,0 +1,9 @@ +{error {error}} +tasks: + pre-rollout: + post-rollout: + - run: + name: override me + command: echo "overridden" + service: cli + shell: bash \ No newline at end of file diff --git a/internal/testdata/validate-lagoon-yml/test7/lagoon.yml b/internal/testdata/validate-lagoon-yml/test7/lagoon.yml new file mode 100644 index 00000000..9d1e1f28 --- /dev/null +++ b/internal/testdata/validate-lagoon-yml/test7/lagoon.yml @@ -0,0 +1,37 @@ +docker-compose-yaml: docker-compose.yml +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: "true" + - b.example.com + - c.example.com +production_routes: + active: + routes: + - nginx: + - "active.example.com": + tls-acme: "true" + insecure: Redirect + standby: + routes: + - nginx: + - "standby.example.com": + tls-acme: "false" + insecure: Redirect + + +tasks: + pre-rollout: + post-rollout: + - run: + name: lagoon.yml post-rollout task1 + command: echo "task 1" + service: cli + shell: bash + - run: + name: override me + command: echo "should be overridden" + service: cli + shell: bash \ No newline at end of file diff --git a/internal/testing/testing.go b/internal/testing/testing.go new file mode 100644 index 00000000..6c99f729 --- /dev/null +++ b/internal/testing/testing.go @@ -0,0 +1,18 @@ +package testing + +import ( + "os" + "path" + "runtime" +) + +// simple testing helper that changes the directory to the root of the repository +// this allows all files used in test suites to be defined relative to the repository root +func init() { + _, filename, _, _ := runtime.Caller(0) + dir := path.Join(path.Dir(filename), "../..") + err := os.Chdir(dir) + if err != nil { + panic(err) + } +} From e5448e5bf55da46a2c8f50bc00f472a28c4c8dde Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 10 Jan 2024 11:07:56 +1100 Subject: [PATCH 44/92] chore: set paths for testing from root --- .../docker-compose/test1/docker-compose.yml | 121 --------------- .../docker-compose/test10/docker-compose.yml | 111 ------------- .../docker-compose/test11/docker-compose.yml | 20 --- .../docker-compose/test2/docker-compose.yml | 20 --- .../docker-compose/test3/docker-compose.yml | 126 --------------- .../docker-compose/test4/docker-compose.yml | 146 ------------------ .../docker-compose/test5/docker-compose.yml | 131 ---------------- .../docker-compose/test6/docker-compose.yml | 138 ----------------- .../docker-compose/test7/docker-compose.yml | 119 -------------- .../docker-compose/test8/docker-compose.yml | 119 -------------- .../docker-compose/test9/docker-compose.yml | 111 ------------- .../cronjobs/lagoon-override-env.yml | 20 --- .../cronjobs/lagoon-override.yml | 20 --- .../validate-lagoon-yml/cronjobs/lagoon.yml | 49 ------ .../cronjobs/multiline-cronjobs.lagoon.yml | 53 ------- .../cronjobs/singleline-cronjobs.lagoon.yml | 46 ------ .../validate-lagoon-yml/test1/lagoon.yml | 22 --- .../test2/lagoon-final.yml | 56 ------- .../test2/lagoon-override.yml | 20 --- .../validate-lagoon-yml/test2/lagoon.yml | 41 ----- .../test3/lagoon-final.yml | 56 ------- .../test3/lagoon-override.yml | 20 --- .../validate-lagoon-yml/test3/lagoon.yml | 41 ----- .../test4/lagoon-final.yml | 73 --------- .../test4/lagoon-override-env.yml | 20 --- .../test4/lagoon-override.yml | 20 --- .../validate-lagoon-yml/test4/lagoon.yml | 41 ----- .../test5/lagoon-final.yml | 35 ----- .../test5/lagoon-override.yml | 8 - .../validate-lagoon-yml/test5/lagoon.yml | 37 ----- .../test6/lagoon-final.yml | 35 ----- .../test6/lagoon-override.yml | 9 -- .../validate-lagoon-yml/test6/lagoon.yml | 37 ----- .../test7/lagoon-final.yml | 35 ----- .../test7/lagoon-override.yml | 9 -- .../validate-lagoon-yml/test7/lagoon.yml | 37 ----- 36 files changed, 2002 deletions(-) delete mode 100644 test-resources/docker-compose/test1/docker-compose.yml delete mode 100644 test-resources/docker-compose/test10/docker-compose.yml delete mode 100644 test-resources/docker-compose/test11/docker-compose.yml delete mode 100644 test-resources/docker-compose/test2/docker-compose.yml delete mode 100644 test-resources/docker-compose/test3/docker-compose.yml delete mode 100644 test-resources/docker-compose/test4/docker-compose.yml delete mode 100644 test-resources/docker-compose/test5/docker-compose.yml delete mode 100644 test-resources/docker-compose/test6/docker-compose.yml delete mode 100644 test-resources/docker-compose/test7/docker-compose.yml delete mode 100644 test-resources/docker-compose/test8/docker-compose.yml delete mode 100644 test-resources/docker-compose/test9/docker-compose.yml delete mode 100644 test-resources/validate-lagoon-yml/cronjobs/lagoon-override-env.yml delete mode 100644 test-resources/validate-lagoon-yml/cronjobs/lagoon-override.yml delete mode 100644 test-resources/validate-lagoon-yml/cronjobs/lagoon.yml delete mode 100644 test-resources/validate-lagoon-yml/cronjobs/multiline-cronjobs.lagoon.yml delete mode 100644 test-resources/validate-lagoon-yml/cronjobs/singleline-cronjobs.lagoon.yml delete mode 100644 test-resources/validate-lagoon-yml/test1/lagoon.yml delete mode 100644 test-resources/validate-lagoon-yml/test2/lagoon-final.yml delete mode 100644 test-resources/validate-lagoon-yml/test2/lagoon-override.yml delete mode 100644 test-resources/validate-lagoon-yml/test2/lagoon.yml delete mode 100644 test-resources/validate-lagoon-yml/test3/lagoon-final.yml delete mode 100644 test-resources/validate-lagoon-yml/test3/lagoon-override.yml delete mode 100644 test-resources/validate-lagoon-yml/test3/lagoon.yml delete mode 100644 test-resources/validate-lagoon-yml/test4/lagoon-final.yml delete mode 100644 test-resources/validate-lagoon-yml/test4/lagoon-override-env.yml delete mode 100644 test-resources/validate-lagoon-yml/test4/lagoon-override.yml delete mode 100644 test-resources/validate-lagoon-yml/test4/lagoon.yml delete mode 100644 test-resources/validate-lagoon-yml/test5/lagoon-final.yml delete mode 100644 test-resources/validate-lagoon-yml/test5/lagoon-override.yml delete mode 100644 test-resources/validate-lagoon-yml/test5/lagoon.yml delete mode 100644 test-resources/validate-lagoon-yml/test6/lagoon-final.yml delete mode 100644 test-resources/validate-lagoon-yml/test6/lagoon-override.yml delete mode 100644 test-resources/validate-lagoon-yml/test6/lagoon.yml delete mode 100644 test-resources/validate-lagoon-yml/test7/lagoon-final.yml delete mode 100644 test-resources/validate-lagoon-yml/test7/lagoon-override.yml delete mode 100644 test-resources/validate-lagoon-yml/test7/lagoon.yml diff --git a/test-resources/docker-compose/test1/docker-compose.yml b/test-resources/docker-compose/test1/docker-compose.yml deleted file mode 100644 index 51ec1413..00000000 --- a/test-resources/docker-compose/test1/docker-compose.yml +++ /dev/null @@ -1,121 +0,0 @@ -version: '2.3' - -x-volumes: - &default-volumes - # Define all volumes you would like to have real-time mounted into the docker containers - volumes: - - .:/app:delegated ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. - - files:/app/web/sites/default/files - -x-environment: - &default-environment - # Route that should be used locally, if you are using pygmy, this route *must* end with .docker.amazee.io - LAGOON_ROUTE: &default-url http://${COMPOSE_PROJECT_NAME:-drupal9-example-advanced}.docker.amazee.io - # Uncomment if you like to have the system behave like in production - #LAGOON_ENVIRONMENT_TYPE: production - # Uncomment to enable xdebug and then restart via `docker-compose up -d` - #XDEBUG_ENABLE: "true" - -x-user: - &default-user - # The default user under which the containers should run. Change this if you are on linux and run with another user than id `1000` - user: '1000' - -volumes: - files: - {} - -services: - - cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) - build: - context: . - dockerfile: lagoon/cli.dockerfile - image: &cli-image ${COMPOSE_PROJECT_NAME:-drupal9-example-advanced}-cli # this image will be reused as `CLI_IMAGE` in subsequent Docker builds - labels: - # Lagoon Labels - lagoon.type: cli-persistent - lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container - lagoon.persistent: /app/web/sites/default/files/ # location where the persistent storage should be mounted - lando.type: php-cli-drupal - << : *default-volumes # loads the defined volumes from the top - user: root - volumes_from: ### mount the ssh-agent from the pygmy or cachalot ssh-agent. Automatically removed in CI. - - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. - environment: - << : *default-environment # loads the defined environment variables from the top - - nginx: - build: - context: . - dockerfile: lagoon/nginx.dockerfile - args: - CLI_IMAGE: *cli-image # Inject the name of the cli image - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: /app/web/sites/default/files/ # define where the persistent storage should be mounted too - lando.type: nginx-drupal - << : *default-volumes # loads the defined volumes from the top - << : *default-user # uses the defined user from top - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - LAGOON_LOCALDEV_URL: *default-url - networks: - - amazeeio-network - - default - - php: - build: - context: . - dockerfile: lagoon/php.dockerfile - args: - CLI_IMAGE: *cli-image - labels: - lagoon.type: nginx-php-persistent - lagoon.name: nginx # we want this service be part of the nginx pod in Lagoon - lagoon.persistent: /app/web/sites/default/files/ # define where the persistent storage should be mounted too - lando.type: php-fpm - << : *default-volumes # loads the defined volumes from the top - << : *default-user # uses the defined user from top - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - - mariadb: - image: uselagoon/mariadb-10.5-drupal:latest - labels: - lagoon.type: mariadb - lando.type: mariadb-drupal - ports: - - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` - << : *default-user # uses the defined user from top - environment: - << : *default-environment - - redis: - image: uselagoon/redis-5:latest - labels: - lagoon.type: redis - lando.type: redis - ports: - - "6379" # exposes the port 6379 with a random local port, find it with `docker-compose port redis 6379` - << : *default-user # uses the defined user from top - environment: - << : *default-environment - - solr: - image: uselagoon/solr-7.7-drupal:latest - labels: - lagoon.type: solr - lando.type: solr-drupal - ports: - - "8983" # exposes the port 8983 with a random local port, find it with `docker-compose port solr 8983` - environment: - << : *default-environment - -networks: - amazeeio-network: - external: true \ No newline at end of file diff --git a/test-resources/docker-compose/test10/docker-compose.yml b/test-resources/docker-compose/test10/docker-compose.yml deleted file mode 100644 index c58a678e..00000000 --- a/test-resources/docker-compose/test10/docker-compose.yml +++ /dev/null @@ -1,111 +0,0 @@ -version: '2.3' - -x-lagoon-project: - # Lagoon project name (leave `&lagoon-project` when you edit this) - &lagoon-project "${COMPOSE_PROJECT_NAME}" - -x-environment: - &default-environment - LAGOON_PROJECT: *lagoon-project - # Route that should be used locally - LAGOON_ROUTE: "https://${DRUPAL_HOSTNAME}" - SSMTP_MAILHUB: "host.docker.internal:1025" - -services: - - cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) - container_name: "${COMPOSE_PROJECT_NAME}-cli" - build: - context: . - dockerfile: lagoon/cli.dockerfile - image: *lagoon-project # this image will be reused as `CLI_IMAGE` in subsequent Docker builds - labels: - # Lagoon Labels - lagoon.type: cli-persistent - lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container - lagoon.persistent: "/app/public/sites/default/files/" # location where the persistent storage should be mounted - volumes: - - .:/app:delegated - - ssh:/tmp/amazeeio_ssh-agent - environment: - << : *default-environment # loads the defined environment variables from the top - SIMPLETEST_BASE_URL: "http://nginx:8080" - SIMPLETEST_DB: "mysql://drupal:drupal@mariadb:3306/drupal" - DRUSH_OPTIONS_URI: "https://${DRUPAL_HOSTNAME}" - env_file: - - .env.local - - nginx: - container_name: "${COMPOSE_PROJECT_NAME}-nginx" - build: - context: . - dockerfile: lagoon/nginx.dockerfile - args: - CLI_IMAGE: *lagoon-project # Inject the name of the cli image - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: "/app/public/sites/default/files/" # define where the persistent file storage should be mounted too - volumes: - - .:/app:delegated - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - LAGOON_LOCALDEV_URL: "${DRUPAL_HOSTNAME}" # generate another route for nginx, by default we go to varnish - networks: - - stonehenge-network - - default - - php: - container_name: "${COMPOSE_PROJECT_NAME}-php" - build: - context: . - dockerfile: lagoon/php.dockerfile - args: - CLI_IMAGE: *lagoon-project - labels: - lagoon.type: nginx-php-persistent - lagoon.name: nginx # we want this service be part of the nginx pod in Lagoon - lagoon.persistent: /app/public/sites/default/files/ # define where the persistent storage should be mounted too - volumes: - - .:/app:delegated - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - env_file: - - .env.local - - mariadb: - container_name: "${COMPOSE_PROJECT_NAME}-db" - image: uselagoon/mariadb-drupal:latest - labels: - lagoon.type: mariadb - ports: - - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` - environment: - << : *default-environment - - pma: - image: phpmyadmin/phpmyadmin - container_name: "${COMPOSE_PROJECT_NAME}-pma" - environment: - PMA_HOST: mariadb - PMA_USER: drupal - PMA_PASSWORD: drupal - UPLOAD_LIMIT: 1G - labels: - lagoon.type: none - networks: - - default - - stonehenge-network - -networks: - stonehenge-network: - external: true - -volumes: - es_data: - ssh: - name: stonehenge-ssh - external: true \ No newline at end of file diff --git a/test-resources/docker-compose/test11/docker-compose.yml b/test-resources/docker-compose/test11/docker-compose.yml deleted file mode 100644 index e65e3dc1..00000000 --- a/test-resources/docker-compose/test11/docker-compose.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: '2' -services: - node.test: - networks: - - amazeeio-network - - default - build: - context: . - dockerfile: node.dockerfile - labels: - lagoon.type: node - volumes: - - .:/app:delegated - environment: - - LAGOON_LOCALDEV_HTTP_PORT=3000 - - LAGOON_ROUTE=http://node.docker.amazee.io - -networks: - amazeeio-network: - external: true \ No newline at end of file diff --git a/test-resources/docker-compose/test2/docker-compose.yml b/test-resources/docker-compose/test2/docker-compose.yml deleted file mode 100644 index 85386270..00000000 --- a/test-resources/docker-compose/test2/docker-compose.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: '2' -services: - node: - networks: - - amazeeio-network - - default - build: - context: . - dockerfile: node.dockerfile - labels: - lagoon.type: node - volumes: - - .:/app:delegated - environment: - - LAGOON_LOCALDEV_HTTP_PORT=3000 - - LAGOON_ROUTE=http://node.docker.amazee.io - -networks: - amazeeio-network: - external: true \ No newline at end of file diff --git a/test-resources/docker-compose/test3/docker-compose.yml b/test-resources/docker-compose/test3/docker-compose.yml deleted file mode 100644 index 022393cb..00000000 --- a/test-resources/docker-compose/test3/docker-compose.yml +++ /dev/null @@ -1,126 +0,0 @@ -version: '2.3' - -x-lagoon-project: - # Lagoon project name (leave `&lagoon-project` when you edit this) - &lagoon-project $PROJECT_NAME - -x-environment: - &default-environment - # Environment ID - ENVIRONMENT_TYPE_ID: $ENVIRONMENT_TYPE_ID - # Machine name of the lagoon project. - LAGOON_PROJECT: *lagoon-project - # Route that should be used locally, if you are using pygmy, this route *must* end with .docker.amazee.io - LAGOON_ROUTE: &default-url http://$LAGOON_ROUTE - # Uncomment if you like to have the system behave like in production - LAGOON_ENVIRONMENT_TYPE: $LAGOON_ENVIRONMENT_TYPE - # The current Git branch of the Lagoon environment. - # LAGOON_GIT_BRANCH: $LAGOON_GIT_BRANCH - # Enable Xdebug within the .env file, then `make down` to reload the env. - XDEBUG_ENABLE: $XDEBUG_ENABLE - # The entrypoint script attempts to autodetect the DOCKERHOST for xdebug. - # If it fails to detect your host, the following override is available: - # DOCKERHOST: host.docker.internal - # Increase PHP memory limit. - PHP_MEMORY_LIMIT: 768M - -x-site-branch: - &site-branch $LAGOON_GIT_BRANCH - -x-user: - &default-user - user: $DEFAULT_USER_ID - -services: - - cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) - build: - context: . - dockerfile: .lagoon/cli.dockerfile - args: - ENVIRONMENT_TYPE_ID: ${ENVIRONMENT_TYPE_ID} - DOCKER_CLI_IMAGE_URI: ${DOCKER_CLI_IMAGE_URI} - image: *lagoon-project # this image will be reused as `CLI_IMAGE` in subsequent Docker builds - container_name: ${PROJECT_NAME}_cli - labels: - # Lagoon Labels - lagoon.type: cli-persistent - lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container - lagoon.persistent: /app/docroot/sites/default/files/ # location where the persistent storage should be mounted - user: root - environment: - << : *default-environment # loads the defined environment variables from the top - volumes: - - ./.lagoon/scripts/bash_prompts.rc:/home/.bashrc - - ./.lagoon/scripts/color_grid.sh:/home/color_grid.sh - volumes_from: - - container:amazeeio-ssh-agent - - nginx: - build: - context: . - dockerfile: .lagoon/nginx.dockerfile - args: - CLI_IMAGE: *lagoon-project - DOCKER_NGINX_IMAGE_URI: ${DOCKER_NGINX_IMAGE_URI} - LAGOON_GIT_BRANCH: *site-branch - container_name: ${PROJECT_NAME}_nginx - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: /app/docroot/sites/default/files/ - lagoon.name: nginx - << : *default-user # uses the defined user from top - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - # LAGOON_LOCALDEV_URL: nginx-${LAGOON_ROUTE} - LAGOON_LOCALDEV_URL: *default-url - networks: - - amazeeio-network - - default - volumes: - - ./.lagoon/nginx/nginx-http.conf:/etc/nginx/conf.d/000-nginx-http.conf - - ./.lagoon/nginx/app.conf:/etc/nginx/conf.d/app.conf - - php: - build: - context: . - dockerfile: .lagoon/php.dockerfile - args: - CLI_IMAGE: *lagoon-project - DOCKER_PHP_IMAGE_URI: ${DOCKER_PHP_IMAGE_URI} - container_name: ${PROJECT_NAME}_php - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: /app/docroot/sites/default/files - lagoon.name: nginx - lagoon.deployment.servicetype: php - << : *default-user # uses the defined user from top - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - - mariadb: - image: amazeeio/mariadb-drupal - container_name: ${PROJECT_NAME}_db - labels: - lagoon.type: mariadb - ports: - - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` - << : *default-user # uses the defined user from top - environment: - << : *default-environment - volumes: - - mysql:/var/lib/mysql - -networks: - amazeeio-network: - external: true - -volumes: - app: - # Add a volume for the DB so it persists between shutdowns. - mysql: - solr7: \ No newline at end of file diff --git a/test-resources/docker-compose/test4/docker-compose.yml b/test-resources/docker-compose/test4/docker-compose.yml deleted file mode 100644 index 9c21b5f8..00000000 --- a/test-resources/docker-compose/test4/docker-compose.yml +++ /dev/null @@ -1,146 +0,0 @@ -version: '2.3' - -x-example-image-version: - &example-image-version ${EXAMPLE_IMAGE_VERSION:-4.x} - -x-project: - &project ${PROJECT_NAME:-mysite} - -x-volumes: - &default-volumes - volumes: - - .:/app:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. - - ./docroot/sites/default/files:/app/docroot/sites/default/files:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. - -x-environment: - &default-environment - LAGOON_PROJECT: *project - DRUPAL_HASH_SALT: fakehashsaltfakehashsaltfakehashsalt - # Local dev URL populated from the environment. Do not override here. Instead, - # specify the value in .env file. - LAGOON_LOCALDEV_URL: ${LOCALDEV_URL:-http://mysite.docker.amazee.io} - LAGOON_ROUTE: ${LOCALDEV_URL:-http://mysite.docker.amazee.io} - GITHUB_TOKEN: ${GITHUB_TOKEN:-} - EXAMPLE_KEY: ${EXAMPLE_KEY:-} - EXAMPLE_IMAGE_VERSION: ${EXAMPLE_IMAGE_VERSION:-latest} - LAGOON_ENVIRONMENT_TYPE: ${LAGOON_ENVIRONMENT_TYPE:-local} - DRUPAL_REFRESH_SEARCHAPI: ${DRUPAL_REFRESH_SEARCHAPI:-} - EXAMPLE_INGRESS_PSK: ${EXAMPLE_INGRESS_PSK:-} - EXAMPLE_INGRESS_HEADER: ${EXAMPLE_INGRESS_HEADER:-} - EXAMPLE_INGRESS_ENABLED: ${EXAMPLE_INGRESS_ENABLED:-} - REDIS_CACHE_PREFIX: "tide_" - DB_ALIAS: ${DB_ALIAS:-example.prod-left} - CKEDITOR_SCAYT_CUSTOMERID: ${CKEDITOR_SCAYT_CUSTOMERID:-} - CKEDITOR_SCAYT_SLANG: ${CKEDITOR_SCAYT_SLANG:-} - PHP_MEMORY_LIMIT: ${PHP_MEMORY_LIMIT:-1024M} - -services: - cli: - build: - context: . - dockerfile: .docker/Dockerfile.cli - args: - COMPOSER: ${COMPOSER:-composer.json} - EXAMPLE_IMAGE_VERSION: *example-image-version - image: *project - environment: - << : *default-environment - << : *default-volumes - volumes_from: ### Local overrides to mount host SSH keys. Automatically removed in CI. - - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. - labels: - lagoon.type: cli-persistent - lagoon.persistent: /app/docroot/sites/default/files/ - lagoon.persistent.name: nginx-php - lagoon.persistent.size: 50Gi - - nginx: - build: - context: . - dockerfile: .docker/Dockerfile.nginx-drupal - args: - CLI_IMAGE: *project - EXAMPLE_IMAGE_VERSION: *example-image-version - << : *default-volumes - environment: - << : *default-environment - depends_on: - - cli - networks: - - amazeeio-network - - default - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: /app/docroot/sites/default/files/ - lagoon.persistent.size: 50Gi - lagoon.name: nginx-php - expose: - - "8080" - php: - build: - context: . - dockerfile: .docker/Dockerfile.php - args: - CLI_IMAGE: *project - EXAMPLE_IMAGE_VERSION: *example-image-version - environment: - << : *default-environment - << : *default-volumes - depends_on: - - cli - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: /app/docroot/sites/default/files/ - lagoon.persistent.size: 50Gi - lagoon.name: nginx-php - - mariadb: - image: uselagoon/mariadb-10.4-drupal:latest - environment: - << : *default-environment - ports: - - "3306" # Find port on host with `ahoy info` or `docker-compose port mariadb 3306` - labels: - lagoon.type: mariadb-shared - - redis: - image: uselagoon/redis-5:latest - labels: - lagoon.type: redis - - elasticsearch: - build: - context: . - dockerfile: .docker/Dockerfile.elasticsearch - args: - - ES_TPL=${ES_TPL:-elasticsearch.yml} - labels: - lagoon.type: none - - chrome: - image: seleniarm/standalone-chromium:101.0 - shm_size: '1gb' - environment: - << : *default-environment - << : *default-volumes - depends_on: - - cli - labels: - lagoon.type: none - - clamav: - image: clamav/example-clamav:${EXAMPLE_IMAGE_VERSION:-4.x} - environment: - << : *default-environment - ports: - - "3310" - labels: - lagoon.type: none - -networks: - amazeeio-network: - external: true - -volumes: - app: {} - files: {} \ No newline at end of file diff --git a/test-resources/docker-compose/test5/docker-compose.yml b/test-resources/docker-compose/test5/docker-compose.yml deleted file mode 100644 index 992a85ca..00000000 --- a/test-resources/docker-compose/test5/docker-compose.yml +++ /dev/null @@ -1,131 +0,0 @@ -version: '2.3' - -x-project: - &project ${PROJECT:-example-project} - -x-volumes: - &default-volumes - volumes: - - - .:/app:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. -x-user: - &default-user - user: '1000' - -x-environment: - &default-environment - LAGOON_LOCALDEV_URL: &default-url ${LOCALDEV_URL:-example-project.docker.amazee.io} - LAGOON_ROUTE: *default-url - XDEBUG_ENABLE: ${XDEBUG_ENABLE:-} - CI: ${CI:-} - DOCKERHOST: ${DOCKERHOST:-host.docker.internal} - PHP_MEMORY_LIMIT: "2G" - PHP_APC_SHM_SIZE: "256M" - PHP_MAX_EXECUTION_TIME: -1 - PHP_MAX_INPUT_VARS: 4000 - - LAGOON_PROJECT: *project - - LAGOON_ENVIRONMENT_TYPE: ${LAGOON_ENVIRONMENT_TYPE:-local} - -services: - - cli: - build: - context: . - dockerfile: .docker/Dockerfile.cli - image: *project - <<: *default-volumes - user: root - environment: - <<: *default-environment - volumes_from: ### Local overrides to mount host SSH keys. Automatically removed in CI. - - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. - ports: - - "35729" - labels: - lagoon.type: cli-persistent - lagoon.persistent.name: nginx-php - lagoon.persistent: /app/docroot/sites/default/files/ - nginx: - build: - context: . - dockerfile: .docker/Dockerfile.nginx-drupal - args: - CLI_IMAGE: *project - <<: *default-volumes - <<: *default-user - environment: - <<: *default-environment - depends_on: - - cli - networks: - - amazeeio-network - - default - labels: - lagoon.type: nginx-php-persistent - lagoon.name: nginx-php - lagoon.persistent: /app/docroot/sites/default/files/ - lagoon.persistent.class: slow - - php: - build: - context: . - dockerfile: .docker/Dockerfile.php - args: - CLI_IMAGE: *project - <<: *default-volumes - <<: *default-user - environment: - <<: *default-environment - depends_on: - - cli - labels: - lagoon.type: nginx-php-persistent - lagoon.name: nginx-php - lagoon.persistent: /app/docroot/sites/default/files/ - lagoon.persistent.class: slow - - mariadb: - build: - context: . - dockerfile: .docker/Dockerfile.mariadb - args: - IMAGE: "${DATABASE_IMAGE:-amazeeio/mariadb-drupal:21.7.0}" - environment: - <<: *default-environment - ports: - - "3306" - labels: - lagoon.type: mariadb - redis: - image: amazeeio/redis:6-21.11.0 - labels: - lagoon.type: redis - environment: - << : *default-environment - - chrome: - image: selenium/standalone-chrome:3.141.59-oxygen - shm_size: '1gb' - <<: *default-volumes - environment: - <<: *default-environment - depends_on: - - cli - labels: - lagoon.type: none - - wait_dependencies: - image: dadarek/wait-for-dependencies - depends_on: - - cli - - mariadb - command: mariadb:3306 - labels: - lagoon.type: none -networks: - amazeeio-network: - external: true -volumes: - app: {} \ No newline at end of file diff --git a/test-resources/docker-compose/test6/docker-compose.yml b/test-resources/docker-compose/test6/docker-compose.yml deleted file mode 100644 index a3056e0f..00000000 --- a/test-resources/docker-compose/test6/docker-compose.yml +++ /dev/null @@ -1,138 +0,0 @@ -version: '2.3' - -# This value intentionally matches the project name on Lagoon. -# It is used to name the CLI_IMAGE to use as a build arg locally. -x-lagoon-project: &lagoon-project - ca-learning2 - -x-lagoon-local-dev-url: &lagoon-local-dev-url - http://ca-learning2.docker.amazee.io - -x-example-image-version: &example-image-version - ${EXAMPLE_IMAGE_VERSION:-9.x-latest} - -x-volumes: &default-volumes - volumes: - - ./themes:/app/web/themes/custom:${VOLUME_FLAGS:-delegated} - - ./files:/app/web/sites/default/files:delegated - - ./tests/behat/features:/app/tests/behat/features:${VOLUME_FLAGS:-delegated} - - ./tests/behat/screenshots:/app/tests/behat/screenshots:${VOLUME_FLAGS:-delegated} - - ./tests/phpunit/tests:/app/tests/phpunit/tests:${VOLUME_FLAGS:-delegated} - - ./config:/app/config - -x-volumes-paas: &paas-volumes - volumes: - - .:/app:delegated - -x-environment: &default-environment - STAGE_FILE_PROXY_URL: ${STAGE_FILE_PROXY_URL:-} - LAGOON_ENVIRONMENT_TYPE: ${LAGOON_ENVIRONMENT_TYPE:-} - LAGOON_PROJECT: *lagoon-project - LAGOON_ROUTE: &default-url ${LOCALDEV_URL:-http://ca-learning2.docker.amazee.io} - EXAMPLE_IMAGE_VERSION: ${EXAMPLE_IMAGE_VERSION:-9.x-latest} - DEV_MODE: "${DEV_MODE:-false}" - XDEBUG_ENABLE: ${XDEBUG_ENABLE:-} - DOCKERHOST: ${DOCKERHOST:-host.docker.internal} - X_FRAME_OPTIONS: ${X_FRAME_OPTIONS:-SameOrigin} - DRUPAL_SHIELD_USER: ${DRUPAL_SHIELD_USER:-} - DRUPAL_SHIELD_PASS: ${DRUPAL_SHIELD_PASS:-} - EXAMPLE_DEPLOY_WORKFLOW_CONFIG: ${EXAMPLE_DEPLOY_WORKFLOW_CONFIG:-import} - EXAMPLE_PREPARE_XML_SCRIPT: /app/vendor/bin/example-prepare-xml - -services: - - cli: - build: - context: . - dockerfile: .docker/Dockerfile.cli - args: - LAGOON_SAFE_PROJECT: *lagoon-project - EXAMPLE_IMAGE_VERSION: *example-image-version - image: *lagoon-project - labels: - lagoon.type: cli-persistent - lagoon.persistent.name: nginx - lagoon.persistent: /app/web/sites/default/files/ - << : *default-volumes - environment: - << : *default-environment - # Mount volumes from Pygmy to inject host SSH key into container. - # https://pygmy.readthedocs.io/en/master/ssh_agent/ - volumes_from: ### Local overrides to mount host SSH keys. Automatically removed in CI. - - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. - - test: - build: - context: . - dockerfile: .docker/Dockerfile.test - args: - CLI_IMAGE: *lagoon-project - EXAMPLE_IMAGE_VERSION: *example-image-version - SITE_AUDIT_VERSION: ${SITE_AUDIT_VERSION:-7.x-3.x} - labels: - lagoon.type: none - << : *default-volumes - depends_on: - - cli - environment: - << : *default-environment - - nginx: - build: - context: . - dockerfile: .docker/Dockerfile.nginx-drupal - args: - CLI_IMAGE: *lagoon-project - EXAMPLE_IMAGE_VERSION: *example-image-version - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: /app/web/sites/default/files/ - << : *default-volumes - depends_on: - - cli - environment: - << : *default-environment - LAGOON_LOCALDEV_URL: *default-url - networks: - - amazeeio-network - - default - - php: - build: - context: . - dockerfile: .docker/Dockerfile.php - args: - CLI_IMAGE: *lagoon-project - EXAMPLE_IMAGE_VERSION: *example-image-version - labels: - lagoon.type: nginx-php-persistent - lagoon.name: nginx - lagoon.persistent: /app/web/sites/default/files/ - << : *default-volumes - depends_on: - - cli - environment: - << : *default-environment - - mariadb: - image: ${MARIADB_DATA_IMAGE:-example/mariadb-drupal:9.x-latest} - labels: - lagoon.type: mariadb - lagoon.image: example/mariadb-drupal:9.x-latest - ports: - - "3306" # Find port on host with `docker-compose port mariadb 3306` - environment: - << : *default-environment - - chrome: - image: selenium/standalone-chrome - shm_size: '1gb' - depends_on: - - test - labels: - lagoon.type: none - << : *default-volumes - -networks: - amazeeio-network: - external: true \ No newline at end of file diff --git a/test-resources/docker-compose/test7/docker-compose.yml b/test-resources/docker-compose/test7/docker-compose.yml deleted file mode 100644 index 0bbf7416..00000000 --- a/test-resources/docker-compose/test7/docker-compose.yml +++ /dev/null @@ -1,119 +0,0 @@ -version: '2.3' - -x-lagoon-project: - &lagoon-project $PROJECT_NAME - -x-environment: - &default-environment - ENVIRONMENT_TYPE_ID: $ENVIRONMENT_TYPE_ID - LAGOON_PROJECT: *lagoon-project - LAGOON_ROUTE: &default-url http://$LAGOON_ROUTE - LAGOON_ENVIRONMENT_TYPE: $LAGOON_ENVIRONMENT_TYPE - XDEBUG_ENABLE: $XDEBUG_ENABLE - PHP_MEMORY_LIMIT: 768M - -### this block is invalid and returns a `Non-string key in x-site-branch: ` -x-site-branch: - &site-branch: $LAGOON_GIT_BRANCH -### this is how it should be, noting the missing `:` after `&site-branch` -# x-site-branch: -# &site-branch $LAGOON_GIT_BRANCH - -x-user: - &default-user - user: $DEFAULT_USER_ID - -services: - - cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) - build: - context: . - dockerfile: .lagoon/cli.dockerfile - args: - ENVIRONMENT_TYPE_ID: ${ENVIRONMENT_TYPE_ID} - DOCKER_CLI_IMAGE_URI: ${DOCKER_CLI_IMAGE_URI} - image: *lagoon-project # this image will be reused as `CLI_IMAGE` in subsequent Docker builds - container_name: ${PROJECT_NAME}_cli - labels: - # Lagoon Labels - lagoon.type: cli-persistent - lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container - lagoon.persistent: /app/docroot/sites/default/files/ # location where the persistent storage should be mounted - user: root - environment: - << : *default-environment # loads the defined environment variables from the top - volumes: - - ./.lagoon/scripts/bash_prompts.rc:/home/.bashrc - - ./.lagoon/scripts/color_grid.sh:/home/color_grid.sh - volumes_from: - - container:amazeeio-ssh-agent - - nginx: - build: - context: . - dockerfile: .lagoon/nginx.dockerfile - args: - CLI_IMAGE: *lagoon-project - DOCKER_NGINX_IMAGE_URI: ${DOCKER_NGINX_IMAGE_URI} - LAGOON_GIT_BRANCH: *site-branch - container_name: ${PROJECT_NAME}_nginx - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: /app/docroot/sites/default/files/ - lagoon.name: nginx - << : *default-user # uses the defined user from top - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - # LAGOON_LOCALDEV_URL: nginx-${LAGOON_ROUTE} - LAGOON_LOCALDEV_URL: *default-url - networks: - - amazeeio-network - - default - volumes: - - ./.lagoon/nginx/nginx-http.conf:/etc/nginx/conf.d/000-nginx-http.conf - - ./.lagoon/nginx/app.conf:/etc/nginx/conf.d/app.conf - - php: - build: - context: . - dockerfile: .lagoon/php.dockerfile - args: - CLI_IMAGE: *lagoon-project - DOCKER_PHP_IMAGE_URI: ${DOCKER_PHP_IMAGE_URI} - container_name: ${PROJECT_NAME}_php - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: /app/docroot/sites/default/files - lagoon.name: nginx - lagoon.deployment.servicetype: php - << : *default-user # uses the defined user from top - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - - mariadb: - image: amazeeio/mariadb-drupal - container_name: ${PROJECT_NAME}_db - labels: - lagoon.type: mariadb - ports: - - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` - << : *default-user # uses the defined user from top - environment: - << : *default-environment - volumes: - - mysql:/var/lib/mysql - - -networks: - amazeeio-network: - external: true - -volumes: - app: - # Add a volume for the DB so it persists between shutdowns. - mysql: - solr7: \ No newline at end of file diff --git a/test-resources/docker-compose/test8/docker-compose.yml b/test-resources/docker-compose/test8/docker-compose.yml deleted file mode 100644 index 0bbf7416..00000000 --- a/test-resources/docker-compose/test8/docker-compose.yml +++ /dev/null @@ -1,119 +0,0 @@ -version: '2.3' - -x-lagoon-project: - &lagoon-project $PROJECT_NAME - -x-environment: - &default-environment - ENVIRONMENT_TYPE_ID: $ENVIRONMENT_TYPE_ID - LAGOON_PROJECT: *lagoon-project - LAGOON_ROUTE: &default-url http://$LAGOON_ROUTE - LAGOON_ENVIRONMENT_TYPE: $LAGOON_ENVIRONMENT_TYPE - XDEBUG_ENABLE: $XDEBUG_ENABLE - PHP_MEMORY_LIMIT: 768M - -### this block is invalid and returns a `Non-string key in x-site-branch: ` -x-site-branch: - &site-branch: $LAGOON_GIT_BRANCH -### this is how it should be, noting the missing `:` after `&site-branch` -# x-site-branch: -# &site-branch $LAGOON_GIT_BRANCH - -x-user: - &default-user - user: $DEFAULT_USER_ID - -services: - - cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) - build: - context: . - dockerfile: .lagoon/cli.dockerfile - args: - ENVIRONMENT_TYPE_ID: ${ENVIRONMENT_TYPE_ID} - DOCKER_CLI_IMAGE_URI: ${DOCKER_CLI_IMAGE_URI} - image: *lagoon-project # this image will be reused as `CLI_IMAGE` in subsequent Docker builds - container_name: ${PROJECT_NAME}_cli - labels: - # Lagoon Labels - lagoon.type: cli-persistent - lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container - lagoon.persistent: /app/docroot/sites/default/files/ # location where the persistent storage should be mounted - user: root - environment: - << : *default-environment # loads the defined environment variables from the top - volumes: - - ./.lagoon/scripts/bash_prompts.rc:/home/.bashrc - - ./.lagoon/scripts/color_grid.sh:/home/color_grid.sh - volumes_from: - - container:amazeeio-ssh-agent - - nginx: - build: - context: . - dockerfile: .lagoon/nginx.dockerfile - args: - CLI_IMAGE: *lagoon-project - DOCKER_NGINX_IMAGE_URI: ${DOCKER_NGINX_IMAGE_URI} - LAGOON_GIT_BRANCH: *site-branch - container_name: ${PROJECT_NAME}_nginx - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: /app/docroot/sites/default/files/ - lagoon.name: nginx - << : *default-user # uses the defined user from top - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - # LAGOON_LOCALDEV_URL: nginx-${LAGOON_ROUTE} - LAGOON_LOCALDEV_URL: *default-url - networks: - - amazeeio-network - - default - volumes: - - ./.lagoon/nginx/nginx-http.conf:/etc/nginx/conf.d/000-nginx-http.conf - - ./.lagoon/nginx/app.conf:/etc/nginx/conf.d/app.conf - - php: - build: - context: . - dockerfile: .lagoon/php.dockerfile - args: - CLI_IMAGE: *lagoon-project - DOCKER_PHP_IMAGE_URI: ${DOCKER_PHP_IMAGE_URI} - container_name: ${PROJECT_NAME}_php - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: /app/docroot/sites/default/files - lagoon.name: nginx - lagoon.deployment.servicetype: php - << : *default-user # uses the defined user from top - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - - mariadb: - image: amazeeio/mariadb-drupal - container_name: ${PROJECT_NAME}_db - labels: - lagoon.type: mariadb - ports: - - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` - << : *default-user # uses the defined user from top - environment: - << : *default-environment - volumes: - - mysql:/var/lib/mysql - - -networks: - amazeeio-network: - external: true - -volumes: - app: - # Add a volume for the DB so it persists between shutdowns. - mysql: - solr7: \ No newline at end of file diff --git a/test-resources/docker-compose/test9/docker-compose.yml b/test-resources/docker-compose/test9/docker-compose.yml deleted file mode 100644 index c58a678e..00000000 --- a/test-resources/docker-compose/test9/docker-compose.yml +++ /dev/null @@ -1,111 +0,0 @@ -version: '2.3' - -x-lagoon-project: - # Lagoon project name (leave `&lagoon-project` when you edit this) - &lagoon-project "${COMPOSE_PROJECT_NAME}" - -x-environment: - &default-environment - LAGOON_PROJECT: *lagoon-project - # Route that should be used locally - LAGOON_ROUTE: "https://${DRUPAL_HOSTNAME}" - SSMTP_MAILHUB: "host.docker.internal:1025" - -services: - - cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) - container_name: "${COMPOSE_PROJECT_NAME}-cli" - build: - context: . - dockerfile: lagoon/cli.dockerfile - image: *lagoon-project # this image will be reused as `CLI_IMAGE` in subsequent Docker builds - labels: - # Lagoon Labels - lagoon.type: cli-persistent - lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container - lagoon.persistent: "/app/public/sites/default/files/" # location where the persistent storage should be mounted - volumes: - - .:/app:delegated - - ssh:/tmp/amazeeio_ssh-agent - environment: - << : *default-environment # loads the defined environment variables from the top - SIMPLETEST_BASE_URL: "http://nginx:8080" - SIMPLETEST_DB: "mysql://drupal:drupal@mariadb:3306/drupal" - DRUSH_OPTIONS_URI: "https://${DRUPAL_HOSTNAME}" - env_file: - - .env.local - - nginx: - container_name: "${COMPOSE_PROJECT_NAME}-nginx" - build: - context: . - dockerfile: lagoon/nginx.dockerfile - args: - CLI_IMAGE: *lagoon-project # Inject the name of the cli image - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: "/app/public/sites/default/files/" # define where the persistent file storage should be mounted too - volumes: - - .:/app:delegated - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - LAGOON_LOCALDEV_URL: "${DRUPAL_HOSTNAME}" # generate another route for nginx, by default we go to varnish - networks: - - stonehenge-network - - default - - php: - container_name: "${COMPOSE_PROJECT_NAME}-php" - build: - context: . - dockerfile: lagoon/php.dockerfile - args: - CLI_IMAGE: *lagoon-project - labels: - lagoon.type: nginx-php-persistent - lagoon.name: nginx # we want this service be part of the nginx pod in Lagoon - lagoon.persistent: /app/public/sites/default/files/ # define where the persistent storage should be mounted too - volumes: - - .:/app:delegated - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - env_file: - - .env.local - - mariadb: - container_name: "${COMPOSE_PROJECT_NAME}-db" - image: uselagoon/mariadb-drupal:latest - labels: - lagoon.type: mariadb - ports: - - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` - environment: - << : *default-environment - - pma: - image: phpmyadmin/phpmyadmin - container_name: "${COMPOSE_PROJECT_NAME}-pma" - environment: - PMA_HOST: mariadb - PMA_USER: drupal - PMA_PASSWORD: drupal - UPLOAD_LIMIT: 1G - labels: - lagoon.type: none - networks: - - default - - stonehenge-network - -networks: - stonehenge-network: - external: true - -volumes: - es_data: - ssh: - name: stonehenge-ssh - external: true \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/cronjobs/lagoon-override-env.yml b/test-resources/validate-lagoon-yml/cronjobs/lagoon-override-env.yml deleted file mode 100644 index 47149945..00000000 --- a/test-resources/validate-lagoon-yml/cronjobs/lagoon-override-env.yml +++ /dev/null @@ -1,20 +0,0 @@ -tasks: - pre-rollout: - - run: - name: envvar pre-rollout task1 - command: echo "task 1" - service: cli - weight: -1 - post-rollout: - - run: - name: envvar post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - weight: -1 - - run: - name: envvar post-rollout task2 - command: echo "task 2" - service: cli - shell: bash - weight: 1 \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/cronjobs/lagoon-override.yml b/test-resources/validate-lagoon-yml/cronjobs/lagoon-override.yml deleted file mode 100644 index b7a2e400..00000000 --- a/test-resources/validate-lagoon-yml/cronjobs/lagoon-override.yml +++ /dev/null @@ -1,20 +0,0 @@ -tasks: - pre-rollout: - - run: - name: file pre-rollout task1 - command: echo "task 1" - service: cli - weight: -1 - post-rollout: - - run: - name: file post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - weight: -1 - - run: - name: file post-rollout task2 - command: echo "task 2" - service: cli - shell: bash - weight: 1 \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/cronjobs/lagoon.yml b/test-resources/validate-lagoon-yml/cronjobs/lagoon.yml deleted file mode 100644 index a9d4ae17..00000000 --- a/test-resources/validate-lagoon-yml/cronjobs/lagoon.yml +++ /dev/null @@ -1,49 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - cronjobs: - - name: block scalar literal stripped - command: |- - multiline - command - - - name: flow scalar plain 2 - command: singleline command - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect - - -tasks: - pre-rollout: - - run: - name: lagoon.yml pre-rollout task1 - command: echo "task 1" - service: cli - post-rollout: - - run: - name: lagoon.yml post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - - run: - name: lagoon.yml post-rollout task2 - command: echo "task 2" - service: cli - shell: bash diff --git a/test-resources/validate-lagoon-yml/cronjobs/multiline-cronjobs.lagoon.yml b/test-resources/validate-lagoon-yml/cronjobs/multiline-cronjobs.lagoon.yml deleted file mode 100644 index 7b743990..00000000 --- a/test-resources/validate-lagoon-yml/cronjobs/multiline-cronjobs.lagoon.yml +++ /dev/null @@ -1,53 +0,0 @@ -# All the possible YAML incantations for introducing a newline into a string. -# https://yaml-multiline.info/ -environments: - main: - cronjobs: - - name: flow scalar plain - command: multiline - - command - - name: flow scalar single quoted - command: 'multiline - - command' - - name: flow scalar double quoted newline - command: "multiline - - command" - - name: flow scalar double quoted escaped - command: "multiline\ncommand" - - name: multiline block literal clipped - command: | - multiline - command - - - name: block scalar literal stripped - command: |- - multiline - command - - - name: block scalar literal keep - command: |+ - multiline - command - - - name: block scalar folded clipped - command: > - multiline - - command - - - name: block scalar folded stripped - command: >- - multiline - - command - - - name: block scalar folded keep - command: >+ - multiline - - command - -# dummy comment to keep previous newline diff --git a/test-resources/validate-lagoon-yml/cronjobs/singleline-cronjobs.lagoon.yml b/test-resources/validate-lagoon-yml/cronjobs/singleline-cronjobs.lagoon.yml deleted file mode 100644 index 4a3c5b7e..00000000 --- a/test-resources/validate-lagoon-yml/cronjobs/singleline-cronjobs.lagoon.yml +++ /dev/null @@ -1,46 +0,0 @@ -# Strings that may appear to have newlines but don't. -environments: - main: - cronjobs: - - name: flow scalar plain 1 - command: singleline - command - - name: flow scalar plain 2 - command: singleline command - - name: flow scalar plain 3 - command: singleline\ncommand - - name: flow scalar single quoted 1 - command: 'singleline - command' - - name: flow scalar single quoted 2 - command: 'singleline command' - - name: flow scalar single quoted 3 - command: 'singleline\ncommand' - - name: flow scalar double quoted 1 - command: "singleline - command" - - name: flow scalar double quoted 2 - command: "singleline command" - - name: flow scalar double quoted 3 - command: "singleline\ - command" - - name: block scalar literal stripped - command: |- - singleline command - - - name: block scalar folded clipped 1 - command: > - singleline - command - - name: block scalar folded clipped 2 - command: > - singleline command - - name: block scalar folded stripped 1 - command: >- - singleline - command - - name: block scalar folded stripped 2 - command: >- - singleline command - -# dummy comment to keep previous newline diff --git a/test-resources/validate-lagoon-yml/test1/lagoon.yml b/test-resources/validate-lagoon-yml/test1/lagoon.yml deleted file mode 100644 index 71ae5215..00000000 --- a/test-resources/validate-lagoon-yml/test1/lagoon.yml +++ /dev/null @@ -1,22 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect diff --git a/test-resources/validate-lagoon-yml/test2/lagoon-final.yml b/test-resources/validate-lagoon-yml/test2/lagoon-final.yml deleted file mode 100644 index bbbfb406..00000000 --- a/test-resources/validate-lagoon-yml/test2/lagoon-final.yml +++ /dev/null @@ -1,56 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect -tasks: - pre-rollout: - - run: - name: file pre-rollout task1 - command: echo "task 1" - service: cli - weight: -1 - - run: - name: lagoon.yml pre-rollout task1 - command: echo "task 1" - service: cli - post-rollout: - - run: - name: file post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - weight: -1 - - run: - name: lagoon.yml post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - - run: - name: lagoon.yml post-rollout task2 - command: echo "task 2" - service: cli - shell: bash - - run: - name: file post-rollout task2 - command: echo "task 2" - service: cli - shell: bash - weight: 1 \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test2/lagoon-override.yml b/test-resources/validate-lagoon-yml/test2/lagoon-override.yml deleted file mode 100644 index b7a2e400..00000000 --- a/test-resources/validate-lagoon-yml/test2/lagoon-override.yml +++ /dev/null @@ -1,20 +0,0 @@ -tasks: - pre-rollout: - - run: - name: file pre-rollout task1 - command: echo "task 1" - service: cli - weight: -1 - post-rollout: - - run: - name: file post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - weight: -1 - - run: - name: file post-rollout task2 - command: echo "task 2" - service: cli - shell: bash - weight: 1 \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test2/lagoon.yml b/test-resources/validate-lagoon-yml/test2/lagoon.yml deleted file mode 100644 index 73e22746..00000000 --- a/test-resources/validate-lagoon-yml/test2/lagoon.yml +++ /dev/null @@ -1,41 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect - - -tasks: - pre-rollout: - - run: - name: lagoon.yml pre-rollout task1 - command: echo "task 1" - service: cli - post-rollout: - - run: - name: lagoon.yml post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - - run: - name: lagoon.yml post-rollout task2 - command: echo "task 2" - service: cli - shell: bash \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test3/lagoon-final.yml b/test-resources/validate-lagoon-yml/test3/lagoon-final.yml deleted file mode 100644 index 484caaa6..00000000 --- a/test-resources/validate-lagoon-yml/test3/lagoon-final.yml +++ /dev/null @@ -1,56 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect -tasks: - pre-rollout: - - run: - name: envvar pre-rollout task1 - command: echo "task 1" - service: cli - weight: -1 - - run: - name: lagoon.yml pre-rollout task1 - command: echo "task 1" - service: cli - post-rollout: - - run: - name: envvar post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - weight: -1 - - run: - name: lagoon.yml post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - - run: - name: lagoon.yml post-rollout task2 - command: echo "task 2" - service: cli - shell: bash - - run: - name: envvar post-rollout task2 - command: echo "task 2" - service: cli - shell: bash - weight: 1 \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test3/lagoon-override.yml b/test-resources/validate-lagoon-yml/test3/lagoon-override.yml deleted file mode 100644 index 47149945..00000000 --- a/test-resources/validate-lagoon-yml/test3/lagoon-override.yml +++ /dev/null @@ -1,20 +0,0 @@ -tasks: - pre-rollout: - - run: - name: envvar pre-rollout task1 - command: echo "task 1" - service: cli - weight: -1 - post-rollout: - - run: - name: envvar post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - weight: -1 - - run: - name: envvar post-rollout task2 - command: echo "task 2" - service: cli - shell: bash - weight: 1 \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test3/lagoon.yml b/test-resources/validate-lagoon-yml/test3/lagoon.yml deleted file mode 100644 index 73e22746..00000000 --- a/test-resources/validate-lagoon-yml/test3/lagoon.yml +++ /dev/null @@ -1,41 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect - - -tasks: - pre-rollout: - - run: - name: lagoon.yml pre-rollout task1 - command: echo "task 1" - service: cli - post-rollout: - - run: - name: lagoon.yml post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - - run: - name: lagoon.yml post-rollout task2 - command: echo "task 2" - service: cli - shell: bash \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test4/lagoon-final.yml b/test-resources/validate-lagoon-yml/test4/lagoon-final.yml deleted file mode 100644 index 19a29bd0..00000000 --- a/test-resources/validate-lagoon-yml/test4/lagoon-final.yml +++ /dev/null @@ -1,73 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect -tasks: - pre-rollout: - - run: - name: envvar pre-rollout task1 - command: echo "task 1" - service: cli - weight: -1 - - run: - name: lagoon.yml pre-rollout task1 - command: echo "task 1" - service: cli - - run: - name: file pre-rollout task1 - command: echo "task 1" - service: cli - weight: 1 - post-rollout: - - run: - name: file post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - weight: -2 - - run: - name: envvar post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - weight: -1 - - run: - name: lagoon.yml post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - - run: - name: lagoon.yml post-rollout task2 - command: echo "task 2" - service: cli - shell: bash - - run: - name: envvar post-rollout task2 - command: echo "task 2" - service: cli - shell: bash - weight: 1 - - run: - name: file post-rollout task2 - command: echo "task 2" - service: cli - shell: bash - weight: 2 \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test4/lagoon-override-env.yml b/test-resources/validate-lagoon-yml/test4/lagoon-override-env.yml deleted file mode 100644 index 47149945..00000000 --- a/test-resources/validate-lagoon-yml/test4/lagoon-override-env.yml +++ /dev/null @@ -1,20 +0,0 @@ -tasks: - pre-rollout: - - run: - name: envvar pre-rollout task1 - command: echo "task 1" - service: cli - weight: -1 - post-rollout: - - run: - name: envvar post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - weight: -1 - - run: - name: envvar post-rollout task2 - command: echo "task 2" - service: cli - shell: bash - weight: 1 \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test4/lagoon-override.yml b/test-resources/validate-lagoon-yml/test4/lagoon-override.yml deleted file mode 100644 index 1f23d5b9..00000000 --- a/test-resources/validate-lagoon-yml/test4/lagoon-override.yml +++ /dev/null @@ -1,20 +0,0 @@ -tasks: - pre-rollout: - - run: - name: file pre-rollout task1 - command: echo "task 1" - service: cli - weight: 1 - post-rollout: - - run: - name: file post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - weight: -2 - - run: - name: file post-rollout task2 - command: echo "task 2" - service: cli - shell: bash - weight: 2 \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test4/lagoon.yml b/test-resources/validate-lagoon-yml/test4/lagoon.yml deleted file mode 100644 index 73e22746..00000000 --- a/test-resources/validate-lagoon-yml/test4/lagoon.yml +++ /dev/null @@ -1,41 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect - - -tasks: - pre-rollout: - - run: - name: lagoon.yml pre-rollout task1 - command: echo "task 1" - service: cli - post-rollout: - - run: - name: lagoon.yml post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - - run: - name: lagoon.yml post-rollout task2 - command: echo "task 2" - service: cli - shell: bash \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test5/lagoon-final.yml b/test-resources/validate-lagoon-yml/test5/lagoon-final.yml deleted file mode 100644 index 6a482eae..00000000 --- a/test-resources/validate-lagoon-yml/test5/lagoon-final.yml +++ /dev/null @@ -1,35 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect -tasks: - pre-rollout: - post-rollout: - - run: - name: lagoon.yml post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - - run: - name: override me - command: echo "overridden" - service: cli - shell: bash diff --git a/test-resources/validate-lagoon-yml/test5/lagoon-override.yml b/test-resources/validate-lagoon-yml/test5/lagoon-override.yml deleted file mode 100644 index 0e576cb0..00000000 --- a/test-resources/validate-lagoon-yml/test5/lagoon-override.yml +++ /dev/null @@ -1,8 +0,0 @@ -tasks: - pre-rollout: - post-rollout: - - run: - name: override me - command: echo "overridden" - service: cli - shell: bash \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test5/lagoon.yml b/test-resources/validate-lagoon-yml/test5/lagoon.yml deleted file mode 100644 index 9d1e1f28..00000000 --- a/test-resources/validate-lagoon-yml/test5/lagoon.yml +++ /dev/null @@ -1,37 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect - - -tasks: - pre-rollout: - post-rollout: - - run: - name: lagoon.yml post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - - run: - name: override me - command: echo "should be overridden" - service: cli - shell: bash \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test6/lagoon-final.yml b/test-resources/validate-lagoon-yml/test6/lagoon-final.yml deleted file mode 100644 index 6a482eae..00000000 --- a/test-resources/validate-lagoon-yml/test6/lagoon-final.yml +++ /dev/null @@ -1,35 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect -tasks: - pre-rollout: - post-rollout: - - run: - name: lagoon.yml post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - - run: - name: override me - command: echo "overridden" - service: cli - shell: bash diff --git a/test-resources/validate-lagoon-yml/test6/lagoon-override.yml b/test-resources/validate-lagoon-yml/test6/lagoon-override.yml deleted file mode 100644 index b251a1b4..00000000 --- a/test-resources/validate-lagoon-yml/test6/lagoon-override.yml +++ /dev/null @@ -1,9 +0,0 @@ -{error {error}} -tasks: - pre-rollout: - post-rollout: - - run: - name: override me - command: echo "overridden" - service: cli - shell: bash \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test6/lagoon.yml b/test-resources/validate-lagoon-yml/test6/lagoon.yml deleted file mode 100644 index 9d1e1f28..00000000 --- a/test-resources/validate-lagoon-yml/test6/lagoon.yml +++ /dev/null @@ -1,37 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect - - -tasks: - pre-rollout: - post-rollout: - - run: - name: lagoon.yml post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - - run: - name: override me - command: echo "should be overridden" - service: cli - shell: bash \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test7/lagoon-final.yml b/test-resources/validate-lagoon-yml/test7/lagoon-final.yml deleted file mode 100644 index 6a482eae..00000000 --- a/test-resources/validate-lagoon-yml/test7/lagoon-final.yml +++ /dev/null @@ -1,35 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect -tasks: - pre-rollout: - post-rollout: - - run: - name: lagoon.yml post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - - run: - name: override me - command: echo "overridden" - service: cli - shell: bash diff --git a/test-resources/validate-lagoon-yml/test7/lagoon-override.yml b/test-resources/validate-lagoon-yml/test7/lagoon-override.yml deleted file mode 100644 index b251a1b4..00000000 --- a/test-resources/validate-lagoon-yml/test7/lagoon-override.yml +++ /dev/null @@ -1,9 +0,0 @@ -{error {error}} -tasks: - pre-rollout: - post-rollout: - - run: - name: override me - command: echo "overridden" - service: cli - shell: bash \ No newline at end of file diff --git a/test-resources/validate-lagoon-yml/test7/lagoon.yml b/test-resources/validate-lagoon-yml/test7/lagoon.yml deleted file mode 100644 index 9d1e1f28..00000000 --- a/test-resources/validate-lagoon-yml/test7/lagoon.yml +++ /dev/null @@ -1,37 +0,0 @@ -docker-compose-yaml: docker-compose.yml -environments: - main: - routes: - - nginx: - - a.example.com: - tls-acme: "true" - - b.example.com - - c.example.com -production_routes: - active: - routes: - - nginx: - - "active.example.com": - tls-acme: "true" - insecure: Redirect - standby: - routes: - - nginx: - - "standby.example.com": - tls-acme: "false" - insecure: Redirect - - -tasks: - pre-rollout: - post-rollout: - - run: - name: lagoon.yml post-rollout task1 - command: echo "task 1" - service: cli - shell: bash - - run: - name: override me - command: echo "should be overridden" - service: cli - shell: bash \ No newline at end of file From 8e9c5b548d5f85c91a2676dffcdbdac2528fd574 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 12 Jan 2024 11:59:47 +1100 Subject: [PATCH 45/92] chore: delete scripts due to merging in main bash --- legacy/scripts/exec-build.sh | 13 ------------- legacy/scripts/exec-kubernetes-copy-to-registry.sh | 2 -- legacy/scripts/exec-kubernetes-promote.sh | 2 -- legacy/scripts/exec-push-parallel.sh | 6 ------ 4 files changed, 23 deletions(-) delete mode 100755 legacy/scripts/exec-build.sh delete mode 100644 legacy/scripts/exec-kubernetes-copy-to-registry.sh delete mode 100644 legacy/scripts/exec-kubernetes-promote.sh delete mode 100755 legacy/scripts/exec-push-parallel.sh diff --git a/legacy/scripts/exec-build.sh b/legacy/scripts/exec-build.sh deleted file mode 100755 index a4f0d03f..00000000 --- a/legacy/scripts/exec-build.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# try to pull the last pushed image so we can use it for --cache-from during the build -set +x - -if [ $BUILD_TARGET == "false" ]; then - echo "Building ${BUILD_CONTEXT}/${DOCKERFILE}" - DOCKER_BUILDKIT=$DOCKER_BUILDKIT docker build --network=host "${BUILD_ARGS[@]}" -t $TEMPORARY_IMAGE_NAME -f $BUILD_CONTEXT/$DOCKERFILE $BUILD_CONTEXT -else - echo "Building target ${BUILD_TARGET} for ${BUILD_CONTEXT}/${DOCKERFILE}" - DOCKER_BUILDKIT=$DOCKER_BUILDKIT docker build --network=host "${BUILD_ARGS[@]}" -t $TEMPORARY_IMAGE_NAME -f $BUILD_CONTEXT/$DOCKERFILE --target $BUILD_TARGET $BUILD_CONTEXT -fi -set -x diff --git a/legacy/scripts/exec-kubernetes-copy-to-registry.sh b/legacy/scripts/exec-kubernetes-copy-to-registry.sh deleted file mode 100644 index 034b5248..00000000 --- a/legacy/scripts/exec-kubernetes-copy-to-registry.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -skopeo copy --retry-times 5 --dest-tls-verify=false docker://${IMAGECACHE_REGISTRY}${PULL_IMAGE} docker://${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG:-latest} diff --git a/legacy/scripts/exec-kubernetes-promote.sh b/legacy/scripts/exec-kubernetes-promote.sh deleted file mode 100644 index 675b222b..00000000 --- a/legacy/scripts/exec-kubernetes-promote.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -skopeo copy --retry-times 5 --src-tls-verify=false --dest-tls-verify=false docker://${REGISTRY}/${PROJECT}/${PROMOTION_SOURCE_ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG:-latest} docker://${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG:-latest} diff --git a/legacy/scripts/exec-push-parallel.sh b/legacy/scripts/exec-push-parallel.sh deleted file mode 100755 index 6c9241cd..00000000 --- a/legacy/scripts/exec-push-parallel.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -docker tag ${TEMPORARY_IMAGE_NAME} ${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG:-latest} - -echo "docker push ${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG:-latest}" >> /kubectl-build-deploy/lagoon/push - From 8e38c5ab484efdb4b8e794b9b4bf5e909b95b18d Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 12 Jan 2024 12:00:37 +1100 Subject: [PATCH 46/92] refactor: extend testdata for missing values --- internal/testdata/testdata.go | 116 ++++++++++++++++++++++++---------- 1 file changed, 82 insertions(+), 34 deletions(-) diff --git a/internal/testdata/testdata.go b/internal/testdata/testdata.go index 1664f868..e0e3fa88 100644 --- a/internal/testdata/testdata.go +++ b/internal/testdata/testdata.go @@ -14,37 +14,44 @@ import ( // basic data structure for test data using the generator type TestData struct { - AlertContact string - StatusPageID string - ProjectName string - EnvironmentName string - Branch string - PRNumber string - PRHeadBranch string - PRBaseBranch string - EnvironmentType string - BuildType string - ActiveEnvironment string - StandbyEnvironment string - CacheNoCache string - ServiceID string - SecretPrefix string - IngressClass string - ProjectVars string - EnvVars string - ProjectVariables []lagoon.EnvironmentVariable - EnvVariables []lagoon.EnvironmentVariable - LagoonVersion string - LagoonYAML string - ValuesFilePath string - K8UPVersion string - DefaultBackupSchedule string - ControllerDevSchedule string - ControllerPRSchedule string - Namespace string - ImageReferences map[string]string - ConfigMapSha string - ImageRegistry string + AlertContact string + StatusPageID string + BuildName string + SourceRepository string + Kubernetes string + ProjectName string + EnvironmentName string + Branch string + GitSHA string + PRNumber string + PRHeadBranch string + PRBaseBranch string + PRHeadSHA string + PRBaseSHA string + EnvironmentType string + BuildType string + ActiveEnvironment string + StandbyEnvironment string + CacheNoCache string + ServiceID string + SecretPrefix string + IngressClass string + ProjectVars string + EnvVars string + ProjectVariables []lagoon.EnvironmentVariable + EnvVariables []lagoon.EnvironmentVariable + LagoonVersion string + LagoonYAML string + ValuesFilePath string + K8UPVersion string + DefaultBackupSchedule string + ControllerDevSchedule string + ControllerPRSchedule string + Namespace string + ImageReferences map[string]string + ConfigMapSha string + ImageRegistry string + PromotionSourceEnvironment string } // helper function to set up all the environment variables from provided testdata @@ -135,6 +142,34 @@ func SetupEnvironment(rootCmd cobra.Command, templatePath string, t TestData) (g if err != nil { return generator.GeneratorInput{}, err } + err = os.Setenv("SOURCE_REPOSITORY", t.SourceRepository) + if err != nil { + return generator.GeneratorInput{}, err + } + err = os.Setenv("LAGOON_BUILD_NAME", t.BuildName) + if err != nil { + return generator.GeneratorInput{}, err + } + err = os.Setenv("KUBERNETES", t.Kubernetes) + if err != nil { + return generator.GeneratorInput{}, err + } + err = os.Setenv("PR_HEAD_SHA", t.PRHeadSHA) + if err != nil { + return generator.GeneratorInput{}, err + } + err = os.Setenv("PR_BASE_SHA", t.PRBaseSHA) + if err != nil { + return generator.GeneratorInput{}, err + } + err = os.Setenv("LAGOON_GIT_SHA", t.GitSHA) + if err != nil { + return generator.GeneratorInput{}, err + } + err = os.Setenv("PROMOTION_SOURCE_ENVIRONMENT", t.PromotionSourceEnvironment) + if err != nil { + return generator.GeneratorInput{}, err + } generator, err := generator.GenerateInput(rootCmd, false) if err != nil { @@ -174,9 +209,13 @@ func GetSeedData(t TestData, defaultProjectVariables bool) TestData { Scope: "internal_system", }, }, - K8UPVersion: "v1", - ConfigMapSha: "abcdefg1234567890", - ImageRegistry: "harbor.example", + K8UPVersion: "v1", + ConfigMapSha: "abcdefg1234567890", + ImageRegistry: "harbor.example", + BuildName: "lagoon-build-abcdefg", + SourceRepository: "ssh://git@example.com/lagoon-demo.git", + Kubernetes: "remote-cluster1", + GitSHA: "abcdefg123456", } if t.ProjectName != "" { rt.ProjectName = t.ProjectName @@ -193,6 +232,9 @@ func GetSeedData(t TestData, defaultProjectVariables bool) TestData { if t.BuildType != "" { rt.BuildType = t.BuildType } + if rt.BuildType == "promote" { + rt.PromotionSourceEnvironment = "promote-main" + } if t.PRNumber != "" { rt.PRNumber = t.PRNumber } @@ -202,6 +244,12 @@ func GetSeedData(t TestData, defaultProjectVariables bool) TestData { if t.PRBaseBranch != "" { rt.PRBaseBranch = t.PRBaseBranch } + if t.PRHeadSHA != "" { + rt.PRHeadSHA = t.PRHeadSHA + } + if t.PRBaseSHA != "" { + rt.PRBaseSHA = t.PRBaseSHA + } if t.LagoonVersion != "" { rt.LagoonVersion = t.LagoonVersion } From 64fa812b1f4cec9ea475f6ebb07c7c47d6a3e59b Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 12 Jan 2024 12:01:40 +1100 Subject: [PATCH 47/92] refactor: generator, add missing values and create image build data --- internal/generator/backups.go | 22 +- internal/generator/backups_test.go | 66 ++- internal/generator/buildvalues.go | 118 +++-- internal/generator/generator.go | 211 +++++--- internal/generator/ingress.go | 39 +- internal/generator/ingress_test.go | 336 ++++++------ internal/generator/services.go | 237 +++++++-- internal/generator/services_test.go | 783 ++++++++++++++++++++-------- 8 files changed, 1190 insertions(+), 622 deletions(-) diff --git a/internal/generator/backups.go b/internal/generator/backups.go index 077ba7df..f687372e 100644 --- a/internal/generator/backups.go +++ b/internal/generator/backups.go @@ -21,7 +21,6 @@ const ( func generateBackupValues( buildValues *BuildValues, - lYAML *lagoon.YAML, mergedVariables []lagoon.EnvironmentVariable, debug bool, ) error { @@ -136,20 +135,21 @@ func generateBackupValues( } // :end - if lYAML.BackupRetention.Production.Hourly != nil && buildValues.EnvironmentType == "production" { - buildValues.Backup.PruneRetention.Hourly = *lYAML.BackupRetention.Production.Hourly + if buildValues.LagoonYAML.BackupRetention.Production.Hourly != nil && buildValues.EnvironmentType == "production" { + fmt.Println(*buildValues.LagoonYAML.BackupRetention.Production.Hourly) + buildValues.Backup.PruneRetention.Hourly = *buildValues.LagoonYAML.BackupRetention.Production.Hourly } - if lYAML.BackupRetention.Production.Daily != nil && buildValues.EnvironmentType == "production" { - buildValues.Backup.PruneRetention.Daily = *lYAML.BackupRetention.Production.Daily + if buildValues.LagoonYAML.BackupRetention.Production.Daily != nil && buildValues.EnvironmentType == "production" { + buildValues.Backup.PruneRetention.Daily = *buildValues.LagoonYAML.BackupRetention.Production.Daily } - if lYAML.BackupRetention.Production.Weekly != nil && buildValues.EnvironmentType == "production" { - buildValues.Backup.PruneRetention.Weekly = *lYAML.BackupRetention.Production.Weekly + if buildValues.LagoonYAML.BackupRetention.Production.Weekly != nil && buildValues.EnvironmentType == "production" { + buildValues.Backup.PruneRetention.Weekly = *buildValues.LagoonYAML.BackupRetention.Production.Weekly } - if lYAML.BackupRetention.Production.Monthly != nil && buildValues.EnvironmentType == "production" { - buildValues.Backup.PruneRetention.Monthly = *lYAML.BackupRetention.Production.Monthly + if buildValues.LagoonYAML.BackupRetention.Production.Monthly != nil && buildValues.EnvironmentType == "production" { + buildValues.Backup.PruneRetention.Monthly = *buildValues.LagoonYAML.BackupRetention.Production.Monthly } - if lYAML.BackupSchedule.Production != "" && buildValues.EnvironmentType == "production" { - buildValues.Backup.BackupSchedule, err = helpers.ConvertCrontab(buildValues.Namespace, lYAML.BackupSchedule.Production) + if buildValues.LagoonYAML.BackupSchedule.Production != "" && buildValues.EnvironmentType == "production" { + buildValues.Backup.BackupSchedule, err = helpers.ConvertCrontab(buildValues.Namespace, buildValues.LagoonYAML.BackupSchedule.Production) if err != nil { return fmt.Errorf("Unable to convert crontab for default backup schedule from .lagoon.yml: %v", err) } diff --git a/internal/generator/backups_test.go b/internal/generator/backups_test.go index 956b993d..a0852545 100644 --- a/internal/generator/backups_test.go +++ b/internal/generator/backups_test.go @@ -13,7 +13,6 @@ import ( func Test_generateBackupValues(t *testing.T) { type args struct { buildValues *BuildValues - lYAML *lagoon.YAML mergedVariables []lagoon.EnvironmentVariable debug bool } @@ -33,8 +32,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{}, }, want: &BuildValues{ @@ -66,8 +65,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{ {Name: "LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG", Value: "enabled", Scope: "global"}, {Name: "LAGOON_BACKUP_DEV_SCHEDULE", Value: "M/15 23 * * 0-5", Scope: "build"}, @@ -102,8 +101,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{ {Name: "LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG", Value: "enabled", Scope: "global"}, }, @@ -140,8 +139,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{ {Name: "LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG", Value: "enabled", Scope: "global"}, {Name: "LAGOON_BACKUP_PR_SCHEDULE", Value: "M/15 23 * * 0-5", Scope: "build"}, @@ -176,8 +175,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{ {Name: "LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG", Value: "enabled", Scope: "global"}, }, @@ -214,8 +213,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{ {Name: "LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG", Value: "enabled", Scope: "global"}, {Name: "LAGOON_BACKUP_DEV_SCHEDULE", Value: "M/15 23 * * 0-5", Scope: "build"}, @@ -250,8 +249,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{ {Name: "LAGOON_FEATURE_FLAG_CUSTOM_BACKUP_CONFIG", Value: "enabled", Scope: "global"}, }, @@ -288,8 +287,29 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{ + BackupRetention: lagoon.BackupRetention{ + Production: lagoon.Retention{ + Hourly: helpers.IntPtr(10), + Daily: helpers.IntPtr(10), + Weekly: helpers.IntPtr(10), + Monthly: helpers.IntPtr(10), + }, + }, + BackupSchedule: lagoon.BackupSchedule{ + Production: "*/15 0-23 1-31 1-12 0-6", + }, + }, }, - lYAML: &lagoon.YAML{ + mergedVariables: []lagoon.EnvironmentVariable{}, + }, + want: &BuildValues{ + BuildType: "branch", + EnvironmentType: "production", + Project: "example-project", + Namespace: "example-com-main", + DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{ BackupRetention: lagoon.BackupRetention{ Production: lagoon.Retention{ Hourly: helpers.IntPtr(10), @@ -302,14 +322,6 @@ func Test_generateBackupValues(t *testing.T) { Production: "*/15 0-23 1-31 1-12 0-6", }, }, - mergedVariables: []lagoon.EnvironmentVariable{}, - }, - want: &BuildValues{ - BuildType: "branch", - EnvironmentType: "production", - Project: "example-project", - Namespace: "example-com-main", - DefaultBackupSchedule: "M H(22-2) * * *", Backup: BackupConfiguration{ BackupSchedule: "1,16,31,46 0-23 1-31 1-12 0-6", CheckSchedule: "31 6 * * 1", @@ -333,8 +345,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{ {Name: "LAGOON_BAAS_CUSTOM_BACKUP_ACCESS_KEY", Value: "abcdefg", Scope: "build"}, {Name: "LAGOON_BAAS_CUSTOM_BACKUP_SECRET_KEY", Value: "a1b2c3d4e5f6g7h8i9", Scope: "build"}, @@ -374,8 +386,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{ {Name: "LAGOON_BAAS_CUSTOM_BACKUP_ACCESS_KEY", Value: "abcdefg", Scope: "build"}, {Name: "LAGOON_BAAS_CUSTOM_BACKUP_SECRET_KEY", Value: "a1b2c3d4e5f6g7h8i9", Scope: "build"}, @@ -418,8 +430,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{ {Name: "LAGOON_BAAS_CUSTOM_RESTORE_ACCESS_KEY", Value: "abcdefg", Scope: "build"}, {Name: "LAGOON_BAAS_CUSTOM_RESTORE_SECRET_KEY", Value: "a1b2c3d4e5f6g7h8i9", Scope: "build"}, @@ -458,8 +470,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{ {Name: "LAGOON_BAAS_CUSTOM_BACKUP_ACCESS_KEY", Value: "abcdefg", Scope: "build"}, {Name: "LAGOON_BAAS_CUSTOM_BACKUP_SECRET_KEY", Value: "a1b2c3d4e5f6g7h8i9", Scope: "build"}, @@ -506,8 +518,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{}, }, vars: []helpers.EnvironmentVariable{ @@ -542,8 +554,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{}, }, vars: []helpers.EnvironmentVariable{ @@ -578,8 +590,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_BAAS_BUCKET_NAME", @@ -617,8 +629,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_BAAS_BUCKET_NAME", @@ -661,8 +673,8 @@ func Test_generateBackupValues(t *testing.T) { Project: "example-project", Namespace: "example-com-main", DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, }, - lYAML: &lagoon.YAML{}, mergedVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_SYSTEM_PROJECT_SHARED_BUCKET", @@ -700,7 +712,7 @@ func Test_generateBackupValues(t *testing.T) { t.Errorf("%v", err) } } - if err := generateBackupValues(tt.args.buildValues, tt.args.lYAML, tt.args.mergedVariables, tt.args.debug); (err != nil) != tt.wantErr { + if err := generateBackupValues(tt.args.buildValues, tt.args.mergedVariables, tt.args.debug); (err != nil) != tt.wantErr { t.Errorf("generateBackupValues() error = %v, wantErr %v", err, tt.wantErr) } lValues, _ := json.Marshal(tt.args.buildValues) diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index f7f44324..2de25e84 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -9,54 +9,64 @@ import ( // BuildValues is the values file data generated by the lagoon build type BuildValues struct { - Project string `json:"project"` - Environment string `json:"environment"` - EnvironmentType string `json:"environmentType"` - Namespace string `json:"namespace"` - GitSha string `json:"gitSha"` - BuildType string `json:"buildType"` - Kubernetes string `json:"kubernetes"` - LagoonVersion string `json:"lagoonVersion"` - ActiveEnvironment string `json:"activeEnvironment"` - StandbyEnvironment string `json:"standbyEnvironment"` - IsActiveEnvironment bool `json:"isActiveEnvironment"` - IsStandbyEnvironment bool `json:"isStandbyEnvironment"` - PodSecurityContext PodSecurityContext `json:"podSecurityContext"` - ImagePullSecrets []ImagePullSecrets `json:"imagePullSecrets"` - Branch string `json:"branch"` - PRNumber string `json:"prNumber"` - PRTitle string `json:"prTitle"` - PRHeadBranch string `json:"prHeadBranch"` - PRBaseBranch string `json:"prBaseBranch"` - PrivateRegistryURLS []string `json:"privateRegistryURLS"` - Fastly Fastly `json:"fastly"` - FastlyCacheNoCache string `json:"fastlyCacheNoCahce"` - FastlyAPISecretPrefix string `json:"fastlyAPISecretPrefix"` - ConfigMapSha string `json:"configMapSha"` - Route string `json:"route"` - Routes []string `json:"routes"` - AutogeneratedRoutes []string `json:"autogeneratedRoutes"` - RoutesAutogeneratePrefixes []string `json:"routesAutogeneratePrefixes"` - AutogeneratedRoutesFastly bool `json:"autogeneratedRoutesFastly"` - Services []ServiceValues `json:"services"` - Backup BackupConfiguration `json:"backup"` - Monitoring MonitoringConfig `json:"monitoring"` - DBaaSOperatorEndpoint string `json:"dbaasOperatorEndpoint"` - ServiceTypeOverrides *lagoon.EnvironmentVariable `json:"serviceTypeOverrides"` - DBaaSEnvironmentTypeOverrides *lagoon.EnvironmentVariable `json:"dbaasEnvironmentTypeOverrides"` - DBaaSFallbackSingle bool `json:"dbaasFallbackSingle"` - IngressClass string `json:"ingressClass"` - TaskScaleMaxIterations int `json:"taskScaleMaxIterations"` - TaskScaleWaitTime int `json:"taskScaleWaitTime"` - DynamicSecretMounts []DynamicSecretMounts `json:"dynamicSecretMounts"` - DynamicSecretVolumes []DynamicSecretVolumes `json:"dynamicSecretVolumes"` - ImageCache string `json:"imageCache"` - DefaultBackupSchedule string `json:"defaultBackupSchedule"` - DBaaSClient *dbaasclient.Client `json:"-"` - ImageReferences map[string]string `json:"imageReferences"` - Resources Resources `json:"resources"` - CronjobsDisabled bool `json:"cronjobsDisabled"` - FeatureFlags map[string]bool `json:"-"` + SourceRepository string `json:"sourceRepository"` + BuildName string `json:"buildName"` + Project string `json:"project"` + Environment string `json:"environment"` + EnvironmentType string `json:"environmentType"` + Namespace string `json:"namespace"` + GitSHA string `json:"gitSha"` + BuildType string `json:"buildType"` + Kubernetes string `json:"kubernetes"` + LagoonVersion string `json:"lagoonVersion"` + ActiveEnvironment string `json:"activeEnvironment"` + StandbyEnvironment string `json:"standbyEnvironment"` + IsActiveEnvironment bool `json:"isActiveEnvironment"` + IsStandbyEnvironment bool `json:"isStandbyEnvironment"` + PodSecurityContext PodSecurityContext `json:"podSecurityContext"` + ImagePullSecrets []ImagePullSecrets `json:"imagePullSecrets"` + Branch string `json:"branch"` + PRNumber string `json:"prNumber"` + PRTitle string `json:"prTitle"` + PRHeadBranch string `json:"prHeadBranch"` + PRBaseBranch string `json:"prBaseBranch"` + PRHeadSHA string `json:"prHeadSHA"` + PRBaseSHA string `json:"prBaseSHA"` + PrivateRegistryURLS []string `json:"privateRegistryURLS"` + Fastly Fastly `json:"fastly"` + FastlyCacheNoCache string `json:"fastlyCacheNoCahce"` + FastlyAPISecretPrefix string `json:"fastlyAPISecretPrefix"` + ConfigMapSha string `json:"configMapSha"` + Route string `json:"route"` + Routes []string `json:"routes"` + AutogeneratedRoutes []string `json:"autogeneratedRoutes"` + RoutesAutogeneratePrefixes []string `json:"routesAutogeneratePrefixes"` + AutogeneratedRoutesFastly bool `json:"autogeneratedRoutesFastly"` + Services []ServiceValues `json:"services"` + Backup BackupConfiguration `json:"backup"` + Monitoring MonitoringConfig `json:"monitoring"` + DBaaSOperatorEndpoint string `json:"dbaasOperatorEndpoint"` + ServiceTypeOverrides *lagoon.EnvironmentVariable `json:"serviceTypeOverrides"` + DBaaSEnvironmentTypeOverrides *lagoon.EnvironmentVariable `json:"dbaasEnvironmentTypeOverrides"` + DBaaSFallbackSingle bool `json:"dbaasFallbackSingle"` + IngressClass string `json:"ingressClass"` + TaskScaleMaxIterations int `json:"taskScaleMaxIterations"` + TaskScaleWaitTime int `json:"taskScaleWaitTime"` + DynamicSecretMounts []DynamicSecretMounts `json:"dynamicSecretMounts"` + DynamicSecretVolumes []DynamicSecretVolumes `json:"dynamicSecretVolumes"` + ImageCache string `json:"imageCache"` + DefaultBackupSchedule string `json:"defaultBackupSchedule"` + DBaaSClient *dbaasclient.Client `json:"-"` + ImageReferences map[string]string `json:"imageReferences"` + Resources Resources `json:"resources"` + CronjobsDisabled bool `json:"cronjobsDisabled"` + FeatureFlags map[string]bool `json:"-"` + ImageRegistry string `json:"imageRegistry"` + DockerBuildKit bool `json:"dockerBuildKit"` + ImageBuildArguments map[string]string `json:"imageBuildArguments"` + EnvironmentVariables []lagoon.EnvironmentVariable `json:"environmentVariables"` + LagoonYAML lagoon.YAML `json:"lagoonYAML"` + PromotionSourceEnvironment string `json:"promotionSourceEnvironment"` } type Resources struct { @@ -124,7 +134,6 @@ type ServiceValues struct { DBaaSEnvironment string `json:"dbaasEnvironment"` NativeCronjobs []lagoon.Cronjob `json:"nativeCronjobs"` InPodCronjobs []lagoon.Cronjob `json:"inPodCronjobs"` - ImageName string `json:"imageName"` DeploymentServiceType string `json:"deploymentServiceType"` ServicePort int32 `json:"servicePort,omitempty"` PersistentVolumePath string `json:"persistentVolumePath,omitempty"` @@ -145,6 +154,17 @@ type ServiceValues struct { CronjobTolerations *[]corev1.Toleration `json:"cronjobTolerations"` CronjobAffinity *corev1.Affinity `json:"cronjobAffinity"` DBaasReadReplica bool `json:"dBaasReadReplica"` + ImageBuild *ImageBuild `json:"docker,omitempty"` +} + +type ImageBuild struct { + DockerFile string `json:"dockerFile,omitempty"` + Target string `json:"target,omitempty"` + Context string `json:"context,omitempty"` + PullImage string `json:"pullImage,omitempty"` + PromoteImage string `json:"promoteImage,omitempty"` + BuildImage string `json:"buildImage,omitempty"` + TemporaryImage string `json:"temporaryImage,omitempty"` } type AdditionalServicePort struct { diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 1ad0f939..417313bb 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "os" + "strconv" "strings" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" @@ -16,48 +17,55 @@ import ( ) type Generator struct { - LagoonYAML *lagoon.YAML - BuildValues *BuildValues - LagoonEnvironmentVariables *[]lagoon.EnvironmentVariable - ActiveEnvironment *bool - StandbyEnvironment *bool - AutogeneratedRoutes *lagoon.RoutesV2 - MainRoutes *lagoon.RoutesV2 - ActiveStandbyRoutes *lagoon.RoutesV2 + LagoonYAML *lagoon.YAML + BuildValues *BuildValues + ActiveEnvironment *bool + StandbyEnvironment *bool + AutogeneratedRoutes *lagoon.RoutesV2 + MainRoutes *lagoon.RoutesV2 + ActiveStandbyRoutes *lagoon.RoutesV2 } type GeneratorInput struct { - LagoonYAML string - LagoonYAMLOverride string - LagoonVersion string - ProjectName string - EnvironmentName string - EnvironmentType string - ActiveEnvironment string - StandbyEnvironment string - ProjectVariables string - EnvironmentVariables string - BuildType string - Branch string - PRNumber string - PRTitle string - PRHeadBranch string - PRBaseBranch string - MonitoringContact string - MonitoringStatusPageID string - FastlyCacheNoCahce string - FastlyAPISecretPrefix string - SavedTemplatesPath string - ConfigMapSha string - BackupConfiguration BackupConfiguration - IgnoreNonStringKeyErrors bool - IgnoreMissingEnvFiles bool - Debug bool - DBaaSClient *dbaasclient.Client - ImageReferences map[string]string - ImagePullSecret string - Namespace string - DefaultBackupSchedule string + LagoonYAML string + LagoonYAMLOverride string + LagoonVersion string + BuildName string + SourceRepository string + ProjectName string + EnvironmentName string + EnvironmentType string + ActiveEnvironment string + StandbyEnvironment string + ProjectVariables string + EnvironmentVariables string + BuildType string + Branch string + GitSHA string + PRNumber string + PRTitle string + PRHeadBranch string + PRBaseBranch string + PRHeadSHA string + PRBaseSHA string + PromotionSourceEnvironment string + MonitoringContact string + MonitoringStatusPageID string + FastlyCacheNoCahce string + FastlyAPISecretPrefix string + SavedTemplatesPath string + ConfigMapSha string + BackupConfiguration BackupConfiguration + IgnoreNonStringKeyErrors bool + IgnoreMissingEnvFiles bool + Debug bool + DBaaSClient *dbaasclient.Client + ImageReferences map[string]string + ImagePullSecret string + Namespace string + DefaultBackupSchedule string + ImageRegistry string + Kubernetes string } func NewGenerator( @@ -68,7 +76,6 @@ func NewGenerator( buildValues := BuildValues{} buildValues.FeatureFlags = map[string]bool{} lYAML := &lagoon.YAML{} - lagoonEnvVars := []lagoon.EnvironmentVariable{} autogenRoutes := &lagoon.RoutesV2{} mainRoutes := &lagoon.RoutesV2{} activeStandbyRoutes := &lagoon.RoutesV2{} @@ -93,8 +100,22 @@ func NewGenerator( fastlyAPISecretPrefix := helpers.GetEnv("ROUTE_FASTLY_SERVICE_ID", generator.FastlyAPISecretPrefix, generator.Debug) lagoonVersion := helpers.GetEnv("LAGOON_VERSION", generator.LagoonVersion, generator.Debug) configMapSha := helpers.GetEnv("CONFIG_MAP_SHA", generator.ConfigMapSha, generator.Debug) + imageRegistry := helpers.GetEnv("REGISTRY", generator.ImageRegistry, generator.Debug) + kubernetes := helpers.GetEnv("KUBERNETES", generator.Kubernetes, generator.Debug) + buildName := helpers.GetEnv("LAGOON_BUILD_NAME", generator.BuildName, generator.Debug) + sourceRepository := helpers.GetEnv("SOURCE_REPOSITORY", generator.SourceRepository, generator.Debug) + promotionSourceEnvironment := helpers.GetEnv("PROMOTION_SOURCE_ENVIRONMENT", generator.PromotionSourceEnvironment, generator.Debug) + gitSHA := helpers.GetEnv("LAGOON_GIT_SHA", generator.SourceRepository, generator.Debug) + prHeadSHA := helpers.GetEnv("PR_HEAD_SHA", generator.PRHeadSHA, generator.Debug) + prBaseSHA := helpers.GetEnv("PR_BASE_SHA", generator.PRBaseSHA, generator.Debug) buildValues.ConfigMapSha = configMapSha + buildValues.BuildName = buildName + buildValues.Kubernetes = kubernetes + buildValues.GitSHA = gitSHA + buildValues.ImageRegistry = imageRegistry + buildValues.SourceRepository = sourceRepository + buildValues.PromotionSourceEnvironment = promotionSourceEnvironment // get the image references values from the build images output buildValues.ImageReferences = generator.ImageReferences // add standard lagoon imagepull secret name @@ -124,6 +145,7 @@ func NewGenerator( if err := LoadAndUnmarshalLagoonYml(generator.LagoonYAML, generator.LagoonYAMLOverride, "LAGOON_YAML_OVERRIDE", lYAML, projectName, generator.Debug); err != nil { return nil, err } + buildValues.LagoonYAML = *lYAML //add the dbaas client to build values too buildValues.DBaaSClient = generator.DBaaSClient @@ -155,6 +177,8 @@ func NewGenerator( buildValues.PRTitle = prTitle buildValues.PRHeadBranch = prHeadBranch buildValues.PRBaseBranch = prBaseBranch + buildValues.PRHeadSHA = prHeadSHA + buildValues.PRBaseSHA = prBaseSHA // since pullrequests don't have a branch // we should set the branch to be `pr-PRNUMBER` so that it can be used for matching elsewhere where matching for `branch` // using buildvalues is done @@ -205,9 +229,9 @@ func NewGenerator( configVars := collectBuildVariables(buildValues) // add the calculated build runtime variables into the existing variable slice // this will later be used to add `runtime|global` scope into the `lagoon-env` configmap - lagoonEnvVars = lagoon.MergeVariables(mergedVariables, configVars) + buildValues.EnvironmentVariables = lagoon.MergeVariables(mergedVariables, configVars) - imageCache := CheckFeatureFlag("IMAGECACHE_REGISTRY", lagoonEnvVars, generator.Debug) + imageCache := CheckFeatureFlag("IMAGECACHE_REGISTRY", buildValues.EnvironmentVariables, generator.Debug) if imageCache != "" { if imageCache[len(imageCache)-1:] != "/" { imageCache = fmt.Sprintf("%s/", imageCache) @@ -216,11 +240,11 @@ func NewGenerator( buildValues.ImageCache = imageCache // check the environment for INGRESS_CLASS flag, will be "" if there are none found - ingressClass := CheckFeatureFlag("INGRESS_CLASS", lagoonEnvVars, generator.Debug) + ingressClass := CheckFeatureFlag("INGRESS_CLASS", buildValues.EnvironmentVariables, generator.Debug) buildValues.IngressClass = ingressClass // check for rootless workloads - rootlessWorkloads := CheckFeatureFlag("ROOTLESS_WORKLOAD", lagoonEnvVars, generator.Debug) + rootlessWorkloads := CheckFeatureFlag("ROOTLESS_WORKLOAD", buildValues.EnvironmentVariables, generator.Debug) if rootlessWorkloads == "enabled" { buildValues.FeatureFlags["rootlessworkloads"] = true buildValues.PodSecurityContext = PodSecurityContext{ @@ -230,7 +254,7 @@ func NewGenerator( } } - fsOnRootMismatch := CheckFeatureFlag("FS_ON_ROOT_MISMATCH", lagoonEnvVars, generator.Debug) + fsOnRootMismatch := CheckFeatureFlag("FS_ON_ROOT_MISMATCH", buildValues.EnvironmentVariables, generator.Debug) if fsOnRootMismatch == "enabled" { buildValues.PodSecurityContext.OnRootMismatch = true } @@ -259,22 +283,32 @@ func NewGenerator( } } - // get any variables from the API here - lagoonServiceTypes, _ := lagoon.GetLagoonVariable("LAGOON_SERVICE_TYPES", nil, lagoonEnvVars) + // get any variables from the API here that could be used to influence a build or services within the environment + // collect docker buildkit value + dockerBuildKit, _ := lagoon.GetLagoonVariable("DOCKER_BUILDKIT", []string{"build"}, buildValues.EnvironmentVariables) + if dockerBuildKit != nil { + buildValues.DockerBuildKit, _ = strconv.ParseBool(dockerBuildKit.Value) + } + + // get any lagoon service type overrides + lagoonServiceTypes, _ := lagoon.GetLagoonVariable("LAGOON_SERVICE_TYPES", nil, buildValues.EnvironmentVariables) buildValues.ServiceTypeOverrides = lagoonServiceTypes - lagoonDBaaSEnvironmentTypes, _ := lagoon.GetLagoonVariable("LAGOON_DBAAS_ENVIRONMENT_TYPES", nil, lagoonEnvVars) + // get any dbaas environment type overrides + lagoonDBaaSEnvironmentTypes, _ := lagoon.GetLagoonVariable("LAGOON_DBAAS_ENVIRONMENT_TYPES", nil, buildValues.EnvironmentVariables) buildValues.DBaaSEnvironmentTypeOverrides = lagoonDBaaSEnvironmentTypes // check autogenerated routes for fastly `LAGOON_FEATURE_FLAG(_FORCE|_DEFAULT)_FASTLY_AUTOGENERATED` using feature flags - autogeneratedRoutesFastly := CheckFeatureFlag("FASTLY_AUTOGENERATED", lagoonEnvVars, generator.Debug) + // @TODO: eventually deprecate fastly functionality in favour of a more generic implementation + autogeneratedRoutesFastly := CheckFeatureFlag("FASTLY_AUTOGENERATED", buildValues.EnvironmentVariables, generator.Debug) if autogeneratedRoutesFastly == "enabled" { buildValues.AutogeneratedRoutesFastly = true } else { buildValues.AutogeneratedRoutesFastly = false } // check legacy variable in envvars - lagoonAutogeneratedFastly, _ := lagoon.GetLagoonVariable("LAGOON_FASTLY_AUTOGENERATED", nil, lagoonEnvVars) + // @TODO: eventually deprecate fastly functionality in favour of a more generic implementation + lagoonAutogeneratedFastly, _ := lagoon.GetLagoonVariable("LAGOON_FASTLY_AUTOGENERATED", nil, buildValues.EnvironmentVariables) if lagoonAutogeneratedFastly != nil { if lagoonAutogeneratedFastly.Value == "enabled" { buildValues.AutogeneratedRoutesFastly = true @@ -283,7 +317,7 @@ func NewGenerator( } } // check legacy variable in envvars - cronjobsDisabled, _ := lagoon.GetLagoonVariable("LAGOON_CRONJOBS_DISABLED", nil, lagoonEnvVars) + cronjobsDisabled, _ := lagoon.GetLagoonVariable("LAGOON_CRONJOBS_DISABLED", nil, buildValues.EnvironmentVariables) if cronjobsDisabled != nil { if cronjobsDisabled.Value == "true" { buildValues.CronjobsDisabled = true @@ -293,30 +327,34 @@ func NewGenerator( } // @TODO: eventually fail builds if this is not set https://github.com/uselagoon/build-deploy-tool/issues/56 - // lagoonDBaaSFallbackSingle, _ := lagoon.GetLagoonVariable("LAGOON_FEATURE_FLAG_DBAAS_FALLBACK_SINGLE", nil, lagoonEnvVars) + // lagoonDBaaSFallbackSingle, _ := lagoon.GetLagoonVariable("LAGOON_FEATURE_FLAG_DBAAS_FALLBACK_SINGLE", nil, buildValues.EnvironmentVariables) // buildValues.DBaaSFallbackSingle = helpers.StrToBool(lagoonDBaaSFallbackSingle.Value) /* start backups configuration */ - err = generateBackupValues(&buildValues, lYAML, lagoonEnvVars, generator.Debug) + err = generateBackupValues(&buildValues, buildValues.EnvironmentVariables, generator.Debug) if err != nil { return nil, err } /* end backups configuration */ - /* start compose->service configuration */ - err = generateServicesFromDockerCompose(&buildValues, lYAML, lagoonEnvVars, generator.IgnoreNonStringKeyErrors, generator.IgnoreMissingEnvFiles, generator.Debug) + /* + start compose->service configuration + !! IMPORTANT !! + build values should be calculated as much as possible before being passed to the generate services function + */ + err = generateServicesFromDockerCompose(&buildValues, generator.IgnoreNonStringKeyErrors, generator.IgnoreMissingEnvFiles, generator.Debug) if err != nil { return nil, err } + buildValues.ImageBuildArguments = collectImageBuildArguments(buildValues) /* end compose->service configuration */ /* start route generation */ // create all the routes for this environment and store the primary and secondary routes into values // populate the autogenRoutes, mainRoutes and activeStandbyRoutes here and load them buildValues.Route, buildValues.Routes, buildValues.AutogeneratedRoutes, err = generateRoutes( - lagoonEnvVars, + buildValues.EnvironmentVariables, buildValues, - *lYAML, autogenRoutes, mainRoutes, activeStandbyRoutes, @@ -329,14 +367,12 @@ func NewGenerator( // finally return the generator values return &Generator{ - BuildValues: &buildValues, - LagoonYAML: lYAML, - LagoonEnvironmentVariables: &lagoonEnvVars, - ActiveEnvironment: &buildValues.IsActiveEnvironment, - StandbyEnvironment: &buildValues.IsStandbyEnvironment, - AutogeneratedRoutes: autogenRoutes, - MainRoutes: mainRoutes, - ActiveStandbyRoutes: activeStandbyRoutes, + BuildValues: &buildValues, + ActiveEnvironment: &buildValues.IsActiveEnvironment, + StandbyEnvironment: &buildValues.IsStandbyEnvironment, + AutogeneratedRoutes: autogenRoutes, + MainRoutes: mainRoutes, + ActiveStandbyRoutes: activeStandbyRoutes, }, nil } @@ -396,7 +432,7 @@ func collectBuildVariables(buildValues BuildValues) []lagoon.EnvironmentVariable vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_PROJECT", Value: buildValues.Project, Scope: "runtime"}) vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ENVIRONMENT", Value: buildValues.Environment, Scope: "runtime"}) vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ENVIRONMENT_TYPE", Value: buildValues.EnvironmentType, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_SHA", Value: buildValues.GitSha, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_SHA", Value: buildValues.GitSHA, Scope: "runtime"}) vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_KUBERNETES", Value: buildValues.Kubernetes, Scope: "runtime"}) vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_SAFE_BRANCH", Value: buildValues.Environment, Scope: "runtime"}) //deprecated??? (https://github.com/uselagoon/lagoon/blob/1053965321495213591f4c9110f90a9d9dcfc946/images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh#L748) if buildValues.BuildType == "branch" { @@ -420,6 +456,49 @@ func collectBuildVariables(buildValues BuildValues) []lagoon.EnvironmentVariable return vars } +// this creates all the build arguments that an image build can consume +func collectImageBuildArguments(buildValues BuildValues) map[string]string { + buildArgs := map[string]string{} + // source any from the environment variables in the project/environment that are `global` or `build` scoped + for _, envvar := range buildValues.EnvironmentVariables { + if helpers.Contains([]string{"global", "build"}, envvar.Scope) { + buildArgs[envvar.Name] = envvar.Value + } + } + // set the standard ones + buildArgs["LAGOON_PROJECT"] = buildValues.Project + buildArgs["LAGOON_ENVIRONMENT"] = buildValues.Environment + buildArgs["LAGOON_ENVIRONMENT_TYPE"] = buildValues.EnvironmentType + buildArgs["LAGOON_BUILD_TYPE"] = buildValues.BuildType + buildArgs["LAGOON_GIT_SOURCE_REPOSITORY"] = buildValues.SourceRepository + buildArgs["LAGOON_KUBERNETES"] = buildValues.Kubernetes + // set any specific build type overrides + if buildValues.BuildType == "branch" { + buildArgs["LAGOON_GIT_SHA"] = buildValues.GitSHA + buildArgs["LAGOON_GIT_BRANCH"] = buildValues.Branch + } + if buildValues.BuildType == "pullrequest" { + buildArgs["LAGOON_GIT_SHA"] = buildValues.GitSHA + buildArgs["LAGOON_PR_HEAD_BRANCH"] = buildValues.PRHeadBranch + buildArgs["LAGOON_PR_HEAD_SHA"] = buildValues.PRHeadSHA + buildArgs["LAGOON_PR_BASE_BRANCH"] = buildValues.PRBaseBranch + buildArgs["LAGOON_PR_BASE_SHA"] = buildValues.PRBaseSHA + buildArgs["LAGOON_PR_TITLE"] = buildValues.PRTitle + buildArgs["LAGOON_PR_NUMBER"] = buildValues.PRNumber + } + // Add in random data as per https://github.com/uselagoon/lagoon/issues/2246 + buildArgs["LAGOON_BUILD_NAME"] = buildValues.BuildName + // and now that we know the temporary image names upfront, they can be passed to all image build steps without + // needing to wait for the other images to be built + for _, service := range buildValues.Services { + if service.ImageBuild != nil && service.ImageBuild.TemporaryImage != "" { + // add the temporary image name to the payload + buildArgs[fmt.Sprintf("%s_IMAGE", strings.ToUpper(service.Name))] = service.ImageBuild.TemporaryImage + } + } + return buildArgs +} + // checks the provided environment variables looking for feature flag based variables func CheckFeatureFlag(key string, envVariables []lagoon.EnvironmentVariable, debug bool) string { // check for force value diff --git a/internal/generator/ingress.go b/internal/generator/ingress.go index 82247882..9f452761 100644 --- a/internal/generator/ingress.go +++ b/internal/generator/ingress.go @@ -13,7 +13,6 @@ import ( func generateRoutes( lagoonEnvVars []lagoon.EnvironmentVariable, buildValues BuildValues, - lYAML lagoon.YAML, autogenRoutes *lagoon.RoutesV2, mainRoutes *lagoon.RoutesV2, activeStanbyRoutes *lagoon.RoutesV2, @@ -26,7 +25,7 @@ func generateRoutes( prefix := "https://" // generate the autogenerated routes - err = generateAutogenRoutes(lagoonEnvVars, &lYAML, &buildValues, autogenRoutes) + err = generateAutogenRoutes(lagoonEnvVars, &buildValues, autogenRoutes) if err != nil { return "", []string{}, []string{}, fmt.Errorf("couldn't unmarshal routes from Lagoon API, is it actually JSON that has been base64 encoded?: %v", err) } @@ -48,7 +47,7 @@ func generateRoutes( } // handle routes from the .lagoon.yml and the API specifically - err = generateIngress(lagoonEnvVars, buildValues, lYAML, mainRoutes, debug) + err = generateIngress(lagoonEnvVars, buildValues, mainRoutes, debug) if err != nil { return "", []string{}, []string{}, fmt.Errorf("couldn't generate and merge routes: %v", err) } @@ -76,7 +75,7 @@ func generateRoutes( // generate the templates for these independently of any previously generated routes, // this WILL overwrite previously created templates ensuring that anything defined in the `production_routes` // section are created correctly ensuring active/standby will work - *activeStanbyRoutes, err = generateActiveStandbyRoutes(lagoonEnvVars, lYAML, buildValues) + *activeStanbyRoutes, err = generateActiveStandbyRoutes(lagoonEnvVars, buildValues) if err != nil { return "", []string{}, []string{}, fmt.Errorf("couldn't generate and merge routes: %v", err) } @@ -106,7 +105,6 @@ func generateRoutes( func generateIngress( envVars []lagoon.EnvironmentVariable, values BuildValues, - lYAML lagoon.YAML, mainRoutes *lagoon.RoutesV2, debug bool, ) error { @@ -117,7 +115,7 @@ func generateIngress( } // handle routes from the .lagoon.yml and the API specifically - *mainRoutes, err = generateAndMerge(*apiRoutes, envVars, lYAML, values) + *mainRoutes, err = generateAndMerge(*apiRoutes, envVars, values) if err != nil { return fmt.Errorf("couldn't generate and merge routes: %v", err) } @@ -126,7 +124,6 @@ func generateIngress( func generateAutogenRoutes( envVars []lagoon.EnvironmentVariable, - lagoonYAML *lagoon.YAML, buildValues *BuildValues, autogenRoutes *lagoon.RoutesV2, ) error { @@ -150,7 +147,7 @@ func generateAutogenRoutes( buildValues.Services[idx].ShortAutogeneratedRouteDomain = shortDomain // alternativeNames are `prefixes` for autogenerated routes - autgenPrefixes := lagoonYAML.Routes.Autogenerate.Prefixes + autgenPrefixes := buildValues.LagoonYAML.Routes.Autogenerate.Prefixes alternativeNames := []string{} for _, altName := range autgenPrefixes { // add the prefix to the domain into a new slice of alternative domains @@ -164,12 +161,12 @@ func generateAutogenRoutes( } } insecure := "Allow" - if lagoonYAML.Routes.Autogenerate.Insecure != "" { - insecure = lagoonYAML.Routes.Autogenerate.Insecure + if buildValues.LagoonYAML.Routes.Autogenerate.Insecure != "" { + insecure = buildValues.LagoonYAML.Routes.Autogenerate.Insecure } ingressClass := buildValues.IngressClass - if lagoonYAML.Routes.Autogenerate.IngressClass != "" { - ingressClass = lagoonYAML.Routes.Autogenerate.IngressClass + if buildValues.LagoonYAML.Routes.Autogenerate.IngressClass != "" { + ingressClass = buildValues.LagoonYAML.Routes.Autogenerate.IngressClass } autogenRoute := lagoon.RouteV2{ Domain: domain, @@ -246,15 +243,14 @@ func autogeneratedDomainFromPattern(pattern, service, projectName, environmentNa // create the activestandby routes from lagoon yaml func generateActiveStandbyRoutes( envVars []lagoon.EnvironmentVariable, - lagoonYAML lagoon.YAML, buildValues BuildValues, ) (lagoon.RoutesV2, error) { activeStanbyRoutes := &lagoon.RoutesV2{} - if lagoonYAML.ProductionRoutes != nil { + if buildValues.LagoonYAML.ProductionRoutes != nil { if buildValues.IsActiveEnvironment == true { - if lagoonYAML.ProductionRoutes.Active != nil { - if lagoonYAML.ProductionRoutes.Active.Routes != nil { - for _, routeMap := range lagoonYAML.ProductionRoutes.Active.Routes { + if buildValues.LagoonYAML.ProductionRoutes.Active != nil { + if buildValues.LagoonYAML.ProductionRoutes.Active.Routes != nil { + for _, routeMap := range buildValues.LagoonYAML.ProductionRoutes.Active.Routes { err := lagoon.GenerateRoutesV2(activeStanbyRoutes, routeMap, envVars, buildValues.IngressClass, buildValues.FastlyAPISecretPrefix, true) if err != nil { return *activeStanbyRoutes, err @@ -264,9 +260,9 @@ func generateActiveStandbyRoutes( } } if buildValues.IsStandbyEnvironment == true { - if lagoonYAML.ProductionRoutes.Standby != nil { - if lagoonYAML.ProductionRoutes.Standby.Routes != nil { - for _, routeMap := range lagoonYAML.ProductionRoutes.Standby.Routes { + if buildValues.LagoonYAML.ProductionRoutes.Standby != nil { + if buildValues.LagoonYAML.ProductionRoutes.Standby.Routes != nil { + for _, routeMap := range buildValues.LagoonYAML.ProductionRoutes.Standby.Routes { err := lagoon.GenerateRoutesV2(activeStanbyRoutes, routeMap, envVars, buildValues.IngressClass, buildValues.FastlyAPISecretPrefix, true) if err != nil { return *activeStanbyRoutes, err @@ -308,13 +304,12 @@ func getRoutesFromAPIEnvVar( func generateAndMerge( api lagoon.RoutesV2, envVars []lagoon.EnvironmentVariable, - lagoonYAML lagoon.YAML, buildValues BuildValues, ) (lagoon.RoutesV2, error) { n := &lagoon.RoutesV2{} // placeholder for generated routes // otherwise it just uses the default environment name - for _, routeMap := range lagoonYAML.Environments[buildValues.Branch].Routes { + for _, routeMap := range buildValues.LagoonYAML.Environments[buildValues.Branch].Routes { err := lagoon.GenerateRoutesV2(n, routeMap, envVars, buildValues.IngressClass, buildValues.FastlyAPISecretPrefix, false) if err != nil { return *n, err diff --git a/internal/generator/ingress_test.go b/internal/generator/ingress_test.go index a43b2b2f..e2e8e8d6 100644 --- a/internal/generator/ingress_test.go +++ b/internal/generator/ingress_test.go @@ -102,7 +102,6 @@ func Test_generateAndMerge(t *testing.T) { type args struct { api lagoon.RoutesV2 envVars []lagoon.EnvironmentVariable - lagoonYAML lagoon.YAML buildValues BuildValues } tests := []struct { @@ -116,25 +115,25 @@ func Test_generateAndMerge(t *testing.T) { args: args{ buildValues: BuildValues{ Branch: "main", - }, - lagoonYAML: lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - Routes: []map[string][]lagoon.Route{ - { - "nginx": { - { - Ingresses: map[string]lagoon.Ingress{ - "a.example.com": { - TLSAcme: helpers.BoolPtr(true), + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Routes: []map[string][]lagoon.Route{ + { + "nginx": { + { + Ingresses: map[string]lagoon.Ingress{ + "a.example.com": { + TLSAcme: helpers.BoolPtr(true), + }, }, }, - }, - { - Name: "b.example.com", - }, - { - Name: "c.example.com", + { + Name: "b.example.com", + }, + { + Name: "c.example.com", + }, }, }, }, @@ -208,9 +207,9 @@ func Test_generateAndMerge(t *testing.T) { name: "test2 - don't generate routes from lagoon yaml and only merge ones from api onto them", args: args{ buildValues: BuildValues{ - Branch: "main", + Branch: "main", + LagoonYAML: lagoon.YAML{}, }, - lagoonYAML: lagoon.YAML{}, api: lagoon.RoutesV2{ Routes: []lagoon.RouteV2{ { @@ -259,25 +258,25 @@ func Test_generateAndMerge(t *testing.T) { buildValues: BuildValues{ Branch: "main", IngressClass: "nginx", - }, - lagoonYAML: lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - Routes: []map[string][]lagoon.Route{ - { - "nginx": { - { - Ingresses: map[string]lagoon.Ingress{ - "a.example.com": { - TLSAcme: helpers.BoolPtr(true), + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Routes: []map[string][]lagoon.Route{ + { + "nginx": { + { + Ingresses: map[string]lagoon.Ingress{ + "a.example.com": { + TLSAcme: helpers.BoolPtr(true), + }, }, }, - }, - { - Name: "b.example.com", - }, - { - Name: "c.example.com", + { + Name: "b.example.com", + }, + { + Name: "c.example.com", + }, }, }, }, @@ -357,17 +356,17 @@ func Test_generateAndMerge(t *testing.T) { buildValues: BuildValues{ Branch: "main", IngressClass: "nginx", - }, - lagoonYAML: lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - Routes: []map[string][]lagoon.Route{ - { - "nginx": { - { - Ingresses: map[string]lagoon.Ingress{ - "a.example.com": { - TLSAcme: helpers.BoolPtr(true), + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Routes: []map[string][]lagoon.Route{ + { + "nginx": { + { + Ingresses: map[string]lagoon.Ingress{ + "a.example.com": { + TLSAcme: helpers.BoolPtr(true), + }, }, }, }, @@ -414,18 +413,18 @@ func Test_generateAndMerge(t *testing.T) { buildValues: BuildValues{ Branch: "main", IngressClass: "nginx", - }, - lagoonYAML: lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - Routes: []map[string][]lagoon.Route{ - { - "nginx": { - { - Ingresses: map[string]lagoon.Ingress{ - "a.example.com": { - TLSAcme: helpers.BoolPtr(false), - Wildcard: helpers.BoolPtr(true), + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Routes: []map[string][]lagoon.Route{ + { + "nginx": { + { + Ingresses: map[string]lagoon.Ingress{ + "a.example.com": { + TLSAcme: helpers.BoolPtr(false), + Wildcard: helpers.BoolPtr(true), + }, }, }, }, @@ -459,18 +458,18 @@ func Test_generateAndMerge(t *testing.T) { buildValues: BuildValues{ Branch: "main", IngressClass: "nginx", - }, - lagoonYAML: lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - Routes: []map[string][]lagoon.Route{ - { - "nginx": { - { - Ingresses: map[string]lagoon.Ingress{ - "a.example.com": { - TLSAcme: helpers.BoolPtr(true), - Wildcard: helpers.BoolPtr(true), + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Routes: []map[string][]lagoon.Route{ + { + "nginx": { + { + Ingresses: map[string]lagoon.Ingress{ + "a.example.com": { + TLSAcme: helpers.BoolPtr(true), + Wildcard: helpers.BoolPtr(true), + }, }, }, }, @@ -489,7 +488,7 @@ func Test_generateAndMerge(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := generateAndMerge(tt.args.api, tt.args.envVars, tt.args.lagoonYAML, tt.args.buildValues) + got, err := generateAndMerge(tt.args.api, tt.args.envVars, tt.args.buildValues) if (err != nil) != tt.wantErr { t.Errorf("generateAndMerge() error = %v, wantErr %v", err, tt.wantErr) return @@ -506,7 +505,6 @@ func Test_generateAndMerge(t *testing.T) { func Test_generateActiveStandbyRoutes(t *testing.T) { type args struct { envVars []lagoon.EnvironmentVariable - lagoonYAML lagoon.YAML buildValues BuildValues } tests := []struct { @@ -520,15 +518,15 @@ func Test_generateActiveStandbyRoutes(t *testing.T) { args: args{ buildValues: BuildValues{ IsActiveEnvironment: true, - }, - lagoonYAML: lagoon.YAML{ - ProductionRoutes: &lagoon.ProductionRoutes{ - Active: &lagoon.Environment{ - Routes: []map[string][]lagoon.Route{ - { - "nginx": { - { - Name: "active.example.com", + LagoonYAML: lagoon.YAML{ + ProductionRoutes: &lagoon.ProductionRoutes{ + Active: &lagoon.Environment{ + Routes: []map[string][]lagoon.Route{ + { + "nginx": { + { + Name: "active.example.com", + }, }, }, }, @@ -560,17 +558,17 @@ func Test_generateActiveStandbyRoutes(t *testing.T) { buildValues: BuildValues{ IsActiveEnvironment: true, IngressClass: "nginx", - }, - lagoonYAML: lagoon.YAML{ - ProductionRoutes: &lagoon.ProductionRoutes{ - Active: &lagoon.Environment{ - Routes: []map[string][]lagoon.Route{ - { - "nginx": { - { - Ingresses: map[string]lagoon.Ingress{ - "active.example.com": { - TLSAcme: helpers.BoolPtr(true), + LagoonYAML: lagoon.YAML{ + ProductionRoutes: &lagoon.ProductionRoutes{ + Active: &lagoon.Environment{ + Routes: []map[string][]lagoon.Route{ + { + "nginx": { + { + Ingresses: map[string]lagoon.Ingress{ + "active.example.com": { + TLSAcme: helpers.BoolPtr(true), + }, }, }, }, @@ -605,18 +603,18 @@ func Test_generateActiveStandbyRoutes(t *testing.T) { buildValues: BuildValues{ IsActiveEnvironment: true, IngressClass: "nginx", - }, - lagoonYAML: lagoon.YAML{ - ProductionRoutes: &lagoon.ProductionRoutes{ - Active: &lagoon.Environment{ - Routes: []map[string][]lagoon.Route{ - { - "nginx": { - { - Ingresses: map[string]lagoon.Ingress{ - "active.example.com": { - TLSAcme: helpers.BoolPtr(true), - IngressClass: "custom-nginx", + LagoonYAML: lagoon.YAML{ + ProductionRoutes: &lagoon.ProductionRoutes{ + Active: &lagoon.Environment{ + Routes: []map[string][]lagoon.Route{ + { + "nginx": { + { + Ingresses: map[string]lagoon.Ingress{ + "active.example.com": { + TLSAcme: helpers.BoolPtr(true), + IngressClass: "custom-nginx", + }, }, }, }, @@ -651,18 +649,18 @@ func Test_generateActiveStandbyRoutes(t *testing.T) { buildValues: BuildValues{ IngressClass: "nginx", IsActiveEnvironment: true, - }, - lagoonYAML: lagoon.YAML{ - ProductionRoutes: &lagoon.ProductionRoutes{ - Active: &lagoon.Environment{ - Routes: []map[string][]lagoon.Route{ - { - "nginx": { - { - Ingresses: map[string]lagoon.Ingress{ - "active.example.com": { - TLSAcme: helpers.BoolPtr(true), - Wildcard: helpers.BoolPtr(true), + LagoonYAML: lagoon.YAML{ + ProductionRoutes: &lagoon.ProductionRoutes{ + Active: &lagoon.Environment{ + Routes: []map[string][]lagoon.Route{ + { + "nginx": { + { + Ingresses: map[string]lagoon.Ingress{ + "active.example.com": { + TLSAcme: helpers.BoolPtr(true), + Wildcard: helpers.BoolPtr(true), + }, }, }, }, @@ -685,18 +683,18 @@ func Test_generateActiveStandbyRoutes(t *testing.T) { buildValues: BuildValues{ IngressClass: "nginx", IsActiveEnvironment: true, - }, - lagoonYAML: lagoon.YAML{ - ProductionRoutes: &lagoon.ProductionRoutes{ - Active: &lagoon.Environment{ - Routes: []map[string][]lagoon.Route{ - { - "nginx": { - { - Ingresses: map[string]lagoon.Ingress{ - "active.example.com": { - TLSAcme: helpers.BoolPtr(false), - Wildcard: helpers.BoolPtr(true), + LagoonYAML: lagoon.YAML{ + ProductionRoutes: &lagoon.ProductionRoutes{ + Active: &lagoon.Environment{ + Routes: []map[string][]lagoon.Route{ + { + "nginx": { + { + Ingresses: map[string]lagoon.Ingress{ + "active.example.com": { + TLSAcme: helpers.BoolPtr(false), + Wildcard: helpers.BoolPtr(true), + }, }, }, }, @@ -729,7 +727,7 @@ func Test_generateActiveStandbyRoutes(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := generateActiveStandbyRoutes(tt.args.envVars, tt.args.lagoonYAML, tt.args.buildValues) + got, err := generateActiveStandbyRoutes(tt.args.envVars, tt.args.buildValues) if (err != nil) != tt.wantErr { t.Errorf("generateAndMerge() error = %v, wantErr %v", err, tt.wantErr) return @@ -795,7 +793,6 @@ func Test_autogeneratedDomainFromPattern(t *testing.T) { func Test_generateAutogenRoutes(t *testing.T) { type args struct { envVars []lagoon.EnvironmentVariable - lagoonYAML *lagoon.YAML buildValues *BuildValues autogenRoutes *lagoon.RoutesV2 } @@ -815,7 +812,6 @@ func Test_generateAutogenRoutes(t *testing.T) { Scope: "internal_system", }, }, - lagoonYAML: &lagoon.YAML{}, buildValues: &BuildValues{ Project: "example-com", BuildType: "branch", @@ -830,6 +826,7 @@ func Test_generateAutogenRoutes(t *testing.T) { AutogeneratedRoutesTLSAcme: true, }, }, + LagoonYAML: lagoon.YAML{}, }, autogenRoutes: &lagoon.RoutesV2{}, }, @@ -866,7 +863,6 @@ func Test_generateAutogenRoutes(t *testing.T) { Scope: "internal_system", }, }, - lagoonYAML: &lagoon.YAML{}, buildValues: &BuildValues{ Project: "example-com", BuildType: "branch", @@ -882,6 +878,7 @@ func Test_generateAutogenRoutes(t *testing.T) { }, }, IngressClass: "nginx", + LagoonYAML: lagoon.YAML{}, }, autogenRoutes: &lagoon.RoutesV2{}, }, @@ -919,13 +916,6 @@ func Test_generateAutogenRoutes(t *testing.T) { Scope: "internal_system", }, }, - lagoonYAML: &lagoon.YAML{ - Routes: lagoon.Routes{ - Autogenerate: lagoon.Autogenerate{ - IngressClass: "custom-nginx", - }, - }, - }, buildValues: &BuildValues{ Project: "example-com", BuildType: "branch", @@ -941,6 +931,13 @@ func Test_generateAutogenRoutes(t *testing.T) { }, }, IngressClass: "nginx", + LagoonYAML: lagoon.YAML{ + Routes: lagoon.Routes{ + Autogenerate: lagoon.Autogenerate{ + IngressClass: "custom-nginx", + }, + }, + }, }, autogenRoutes: &lagoon.RoutesV2{}, }, @@ -971,7 +968,7 @@ func Test_generateAutogenRoutes(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := generateAutogenRoutes(tt.args.envVars, tt.args.lagoonYAML, tt.args.buildValues, tt.args.autogenRoutes); (err != nil) != tt.wantErr { + if err := generateAutogenRoutes(tt.args.envVars, tt.args.buildValues, tt.args.autogenRoutes); (err != nil) != tt.wantErr { t.Errorf("generateAutogenRoutes() error = %v, wantErr %v", err, tt.wantErr) } lValues, _ := json.Marshal(tt.args.autogenRoutes) @@ -987,7 +984,6 @@ func Test_generateRoutes(t *testing.T) { type args struct { envVars []lagoon.EnvironmentVariable buildValues BuildValues - lagoonYAML lagoon.YAML autogenRoutes *lagoon.RoutesV2 mainRoutes *lagoon.RoutesV2 activeStanbyRoutes *lagoon.RoutesV2 @@ -1011,7 +1007,6 @@ func Test_generateRoutes(t *testing.T) { Scope: "internal_system", }, }, - lagoonYAML: lagoon.YAML{}, buildValues: BuildValues{ Project: "example-com", BuildType: "branch", @@ -1026,6 +1021,7 @@ func Test_generateRoutes(t *testing.T) { AutogeneratedRoutesTLSAcme: true, }, }, + LagoonYAML: lagoon.YAML{}, }, autogenRoutes: &lagoon.RoutesV2{}, mainRoutes: &lagoon.RoutesV2{}, @@ -1045,31 +1041,6 @@ func Test_generateRoutes(t *testing.T) { Scope: "internal_system", }, }, - lagoonYAML: lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - Routes: []map[string][]lagoon.Route{ - { - "nginx": { - { - Ingresses: map[string]lagoon.Ingress{ - "a.example.com": { - TLSAcme: helpers.BoolPtr(true), - }, - }, - }, - { - Name: "b.example.com", - }, - { - Name: "c.example.com", - }, - }, - }, - }, - }, - }, - }, buildValues: BuildValues{ Project: "example-com", BuildType: "branch", @@ -1085,6 +1056,31 @@ func Test_generateRoutes(t *testing.T) { AutogeneratedRoutesTLSAcme: true, }, }, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Routes: []map[string][]lagoon.Route{ + { + "nginx": { + { + Ingresses: map[string]lagoon.Ingress{ + "a.example.com": { + TLSAcme: helpers.BoolPtr(true), + }, + }, + }, + { + Name: "b.example.com", + }, + { + Name: "c.example.com", + }, + }, + }, + }, + }, + }, + }, }, autogenRoutes: &lagoon.RoutesV2{}, mainRoutes: &lagoon.RoutesV2{}, @@ -1097,7 +1093,7 @@ func Test_generateRoutes(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, got1, got2, err := generateRoutes(tt.args.envVars, tt.args.buildValues, tt.args.lagoonYAML, tt.args.autogenRoutes, tt.args.mainRoutes, tt.args.activeStanbyRoutes, tt.args.debug) + got, got1, got2, err := generateRoutes(tt.args.envVars, tt.args.buildValues, tt.args.autogenRoutes, tt.args.mainRoutes, tt.args.activeStanbyRoutes, tt.args.debug) if (err != nil) != tt.wantErr { t.Errorf("generateRoutes() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/internal/generator/services.go b/internal/generator/services.go index b57fcf36..487ef95b 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -2,13 +2,16 @@ package generator import ( "encoding/json" + "errors" "fmt" + "os" "reflect" "regexp" "strconv" "strings" composetypes "github.com/compose-spec/compose-go/types" + "github.com/drone/envsubst" "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" "github.com/uselagoon/build-deploy-tool/internal/servicetypes" @@ -38,16 +41,21 @@ var supportedAutogeneratedTypes = []string{ "python", } +// these service types don't have images +var ignoredImageTypes = []string{ + "mariadb-dbaas", + "postgres-dbaas", + "mongodb-dbaas", +} + // generateServicesFromDockerCompose unmarshals the docker-compose file and processes the services using composeToServiceValues func generateServicesFromDockerCompose( buildValues *BuildValues, - lYAML *lagoon.YAML, - lagoonEnvVars []lagoon.EnvironmentVariable, ignoreNonStringKeyErrors, ignoreMissingEnvFiles, debug bool, ) error { // take lagoon envvars and create new map for being unmarshalled against the docker-compose file composeVars := make(map[string]string) - for _, envvar := range lagoonEnvVars { + for _, envvar := range buildValues.EnvironmentVariables { composeVars[envvar.Name] = envvar.Value } @@ -55,7 +63,7 @@ func generateServicesFromDockerCompose( buildValues.Services = []ServiceValues{} // unmarshal the docker-compose.yml file - lCompose, lComposeOrder, err := lagoon.UnmarshaDockerComposeYAML(lYAML.DockerComposeYAML, ignoreNonStringKeyErrors, ignoreMissingEnvFiles, composeVars) + lCompose, lComposeOrder, err := lagoon.UnmarshaDockerComposeYAML(buildValues.LagoonYAML.DockerComposeYAML, ignoreNonStringKeyErrors, ignoreMissingEnvFiles, composeVars) if err != nil { return err } @@ -65,7 +73,7 @@ func generateServicesFromDockerCompose( for _, service := range lComposeOrder { for _, composeServiceValues := range lCompose.Services { if service.Name == composeServiceValues.Name { - cService, err := composeToServiceValues(buildValues, lagoonEnvVars, lYAML, composeServiceValues.Name, composeServiceValues, debug) + cService, err := composeToServiceValues(buildValues, composeServiceValues.Name, composeServiceValues, debug) if err != nil { return err } @@ -81,8 +89,6 @@ func generateServicesFromDockerCompose( // this is the "known state" of that service, and all subsequent steps to create templates will use this data unmodified func composeToServiceValues( buildValues *BuildValues, - lagoonEnvVars []lagoon.EnvironmentVariable, - lYAML *lagoon.YAML, composeService string, composeServiceValues composetypes.ServiceConfig, debug bool, @@ -100,35 +106,35 @@ func composeToServiceValues( autogenEnabled := true autogenTLSAcmeEnabled := true // check if autogenerated routes are disabled - if lYAML.Routes.Autogenerate.Enabled != nil { - if *lYAML.Routes.Autogenerate.Enabled == false { + if buildValues.LagoonYAML.Routes.Autogenerate.Enabled != nil { + if *buildValues.LagoonYAML.Routes.Autogenerate.Enabled == false { autogenEnabled = false } } // check if pullrequests autogenerated routes are disabled - if buildValues.BuildType == "pullrequest" && lYAML.Routes.Autogenerate.AllowPullRequests != nil { - if *lYAML.Routes.Autogenerate.AllowPullRequests == false { + if buildValues.BuildType == "pullrequest" && buildValues.LagoonYAML.Routes.Autogenerate.AllowPullRequests != nil { + if *buildValues.LagoonYAML.Routes.Autogenerate.AllowPullRequests == false { autogenEnabled = false } else { autogenEnabled = true } } // check if this environment has autogenerated routes disabled - if lYAML.Environments[buildValues.Branch].AutogenerateRoutes != nil { - if *lYAML.Environments[buildValues.Branch].AutogenerateRoutes == false { + if buildValues.LagoonYAML.Environments[buildValues.Branch].AutogenerateRoutes != nil { + if *buildValues.LagoonYAML.Environments[buildValues.Branch].AutogenerateRoutes == false { autogenEnabled = false } else { autogenEnabled = true } } // check if autogenerated routes tls-acme disabled - if lYAML.Routes.Autogenerate.TLSAcme != nil { - if *lYAML.Routes.Autogenerate.TLSAcme == false { + if buildValues.LagoonYAML.Routes.Autogenerate.TLSAcme != nil { + if *buildValues.LagoonYAML.Routes.Autogenerate.TLSAcme == false { autogenTLSAcmeEnabled = false } } // check lagoon yaml for an override for this service - if value, ok := lYAML.Environments[buildValues.Environment].Types[composeService]; ok { + if value, ok := buildValues.LagoonYAML.Environments[buildValues.Environment].Types[composeService]; ok { lagoonType = value } // check if the service has a specific override @@ -195,37 +201,6 @@ func composeToServiceValues( } } - // work out cronjobs for this service - inpodcronjobs := []lagoon.Cronjob{} - nativecronjobs := []lagoon.Cronjob{} - // check if there are any duplicate named cronjobs - if err := checkDuplicateCronjobs(lYAML.Environments[buildValues.Branch].Cronjobs); err != nil { - return ServiceValues{}, err - } - if !buildValues.CronjobsDisabled { - for _, cronjob := range lYAML.Environments[buildValues.Branch].Cronjobs { - // if this cronjob is meant for this service, add it - if cronjob.Service == composeService { - var err error - inpod, err := helpers.IsInPodCronjob(cronjob.Schedule) - if err != nil { - return ServiceValues{}, fmt.Errorf("Unable to validate crontab for cronjob %s: %v", cronjob.Name, err) - } - cronjob.Schedule, err = helpers.ConvertCrontab(buildValues.Namespace, cronjob.Schedule) - if err != nil { - return ServiceValues{}, fmt.Errorf("Unable to convert crontab for cronjob %s: %v", cronjob.Name, err) - } - if inpod { - inpodcronjobs = append(inpodcronjobs, cronjob) - } else { - // make the cronjob name kubernetes compliant - cronjob.Name = regexp.MustCompile(`[^a-zA-Z0-9]+`).ReplaceAllString(fmt.Sprintf("cronjob-%s-%s", lagoonOverrideName, strings.ToLower(cronjob.Name)), "-") - nativecronjobs = append(nativecronjobs, cronjob) - } - } - } - } - // if there are overrides defined in the lagoon API `LAGOON_SERVICE_TYPES` // handle those here if buildValues.ServiceTypeOverrides != nil { @@ -248,6 +223,7 @@ func composeToServiceValues( if lagoonType == "none" { return ServiceValues{}, nil } + // anything after this point is where heavy processing is done as the service type has now been determined by this stage // handle dbaas operator checks here dbaasEnvironment := buildValues.EnvironmentType @@ -274,7 +250,7 @@ func composeToServiceValues( } // @TODO: maybe phase this out? - // if value, ok := lYAML.Environments[buildValues.Environment].Overrides[composeService][mariadb][mariadb-dbaas].Environment; ok { + // if value, ok := buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService][mariadb][mariadb-dbaas].Environment; ok { // this isn't documented in the lagoon.yml, and it looks like a failover from days past. // lagoonType = value // } @@ -317,17 +293,17 @@ func composeToServiceValues( // these services can support multiple replicas in production // @TODO this should probably be an admin only feature flag though spotReplicaTypes := "nginx,nginx-persistent,nginx-php,nginx-php-persistent" - // spotReplicaTypes := CheckAdminFeatureFlag("SPOT_REPLICAS_PRODUCTION", lagoonEnvVars, debug) // doesn't exist yet + // spotReplicaTypes := CheckAdminFeatureFlag("SPOT_REPLICAS_PRODUCTION", buildValues.EnvironmentVariables, debug) // doesn't exist yet - productionSpot := CheckFeatureFlag("SPOT_INSTANCE_PRODUCTION", lagoonEnvVars, debug) - developmentSpot := CheckFeatureFlag("SPOT_INSTANCE_DEVELOPMENT", lagoonEnvVars, debug) + productionSpot := CheckFeatureFlag("SPOT_INSTANCE_PRODUCTION", buildValues.EnvironmentVariables, debug) + developmentSpot := CheckFeatureFlag("SPOT_INSTANCE_DEVELOPMENT", buildValues.EnvironmentVariables, debug) if productionSpot == "enabled" && buildValues.EnvironmentType == "production" { - spotTypes = CheckFeatureFlag("SPOT_INSTANCE_PRODUCTION_TYPES", lagoonEnvVars, debug) - cronjobSpotTypes = CheckFeatureFlag("SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES", lagoonEnvVars, debug) + spotTypes = CheckFeatureFlag("SPOT_INSTANCE_PRODUCTION_TYPES", buildValues.EnvironmentVariables, debug) + cronjobSpotTypes = CheckFeatureFlag("SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES", buildValues.EnvironmentVariables, debug) } if developmentSpot == "enabled" && buildValues.EnvironmentType == "development" { - spotTypes = CheckFeatureFlag("SPOT_INSTANCE_DEVELOPMENT_TYPES", lagoonEnvVars, debug) - cronjobSpotTypes = CheckFeatureFlag("SPOT_INSTANCE_DEVELOPMENT_CRONJOB_TYPES", lagoonEnvVars, debug) + spotTypes = CheckFeatureFlag("SPOT_INSTANCE_DEVELOPMENT_TYPES", buildValues.EnvironmentVariables, debug) + cronjobSpotTypes = CheckFeatureFlag("SPOT_INSTANCE_DEVELOPMENT_CRONJOB_TYPES", buildValues.EnvironmentVariables, debug) } // check if the provided spot instance types against the current lagoonType for _, t := range strings.Split(spotTypes, ",") { @@ -363,6 +339,42 @@ func composeToServiceValues( } // end spot instance handling + // work out cronjobs for this service + inpodcronjobs := []lagoon.Cronjob{} + nativecronjobs := []lagoon.Cronjob{} + // check if there are any duplicate named cronjobs + if err := checkDuplicateCronjobs(buildValues.LagoonYAML.Environments[buildValues.Branch].Cronjobs); err != nil { + return ServiceValues{}, err + } + if !buildValues.CronjobsDisabled { + for _, cronjob := range buildValues.LagoonYAML.Environments[buildValues.Branch].Cronjobs { + // if this cronjob is meant for this service, add it + if cronjob.Service == composeService { + var err error + inpod, err := helpers.IsInPodCronjob(cronjob.Schedule) + if err != nil { + return ServiceValues{}, fmt.Errorf("Unable to validate crontab for cronjob %s: %v", cronjob.Name, err) + } + cronjob.Schedule, err = helpers.ConvertCrontab(buildValues.Namespace, cronjob.Schedule) + if err != nil { + return ServiceValues{}, fmt.Errorf("Unable to convert crontab for cronjob %s: %v", cronjob.Name, err) + } + if inpod { + inpodcronjobs = append(inpodcronjobs, cronjob) + } else { + // make the cronjob name kubernetes compliant + cronjob.Name = regexp.MustCompile(`[^a-zA-Z0-9]+`).ReplaceAllString(fmt.Sprintf("cronjob-%s-%s", lagoonOverrideName, strings.ToLower(cronjob.Name)), "-") + if len(cronjob.Name) > 52 { + // if the cronjob name is longer than 52 characters + // truncate it and add a hash of the name to it + cronjob.Name = fmt.Sprintf("%s-%s", cronjob.Name[:45], helpers.GetBase32EncodedLowercase(helpers.GetSha256Hash(cronjob.Name))[:6]) + } + nativecronjobs = append(nativecronjobs, cronjob) + } + } + } + } + // check if this service is one that supports autogenerated routes if !helpers.Contains(supportedAutogeneratedTypes, lagoonType) { autogenEnabled = false @@ -390,8 +402,119 @@ func composeToServiceValues( PodSecurityContext: buildValues.PodSecurityContext, } - // handle extracting the built image name from the provided image references - cService.ImageName = buildValues.ImageReferences[composeService] + // work out the images here and the associated dockerfile and contexts + // if the type is in the ignored image types, then there is no image to build or pull for this service (eg, its a dbaas service) + if !helpers.Contains(ignoredImageTypes, lagoonType) { + // create a holder for all the docker related information, if this is a pull through image or a build image + imageBuild := ImageBuild{} + // handle extracting the built image name from the provided image references + if composeServiceValues.Build != nil { + // if a build spec is defined, consume it + // set the dockerfile + imageBuild.DockerFile = composeServiceValues.Build.Dockerfile + // set the context if found, otherwise set '.' + imageBuild.Context = func(s string) string { + if s == "" { + return "." + } + return s + }(composeServiceValues.Build.Context) + // if there is a build target defined, set that here too + imageBuild.Target = composeServiceValues.Build.Target + } + // if there is a dockerfile defined in the + if buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Build.Dockerfile != "" { + imageBuild.DockerFile = buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Build.Dockerfile + if imageBuild.Context == "" { + // if we get here, it means that a dockerfile override was defined in the .lagoon.yml file + // but there was no `build` spec defined in the docker-compose file, so this just sets the context to the default `.` + // in the same way the legacy script used to do it + imageBuild.Context = "." + } + } + if imageBuild.DockerFile == "" { + // no dockerfile determined, this must be a pull through image + if composeServiceValues.Image == "" { + return ServiceValues{}, fmt.Errorf( + "defined Dockerfile or Image for service %s defined", composeService, + ) + } + // check docker-compose override image + pullImage := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.image") + // check lagoon.yml override image + if buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Image != "" { + pullImage = buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Image + } + if pullImage != "" { + // if an override image is provided, envsubst it + // not really sure why we do this, but legacy bash says `expand environment variables from ${OVERRIDE_IMAGE}` + // so there may be some undocumented functionality that allows people to use envvars in their image overrides? + evalImage, err := envsubst.EvalEnv(pullImage) + if err != nil { + return ServiceValues{}, fmt.Errorf( + "error evaluating override image %s with envsubst", pullImage, + ) + } + // set the evalled image now + pullImage = evalImage + } else { + // else set the pullimage to whatever is defined in the docker-compose file otherwise + pullImage = composeServiceValues.Image + } + // if the image just is an image name (like "alpine") we prefix it with `libary/` as the imagecache does not understand + // the magic `alpine` image + if !strings.Contains(pullImage, "/") { + imageBuild.PullImage = fmt.Sprintf("library/%s", pullImage) + } else { + imageBuild.PullImage = pullImage + } + } else { + // otherwise this must be an image build + // set temporary image to prevent clashes?? not sure this is even required, the temporary name is just as unique as the final image name eventually is + // so clashing would occur in both situations + imageBuild.TemporaryImage = fmt.Sprintf("%s-%s", buildValues.Namespace, composeService) //@TODO maybe get rid of this + if buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Build.Context != "" { + imageBuild.Context = buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Build.Context + } + // check the dockerfile exists + if _, err := os.Stat(fmt.Sprintf("%s/%s", imageBuild.Context, imageBuild.DockerFile)); errors.Is(err, os.ErrNotExist) { + return ServiceValues{}, fmt.Errorf( + "defined Dockerfile %s for service %s not found", + fmt.Sprintf("%s/%s", imageBuild.Context, imageBuild.DockerFile), composeService, + ) + } + } + // since we know what the final build image will be, we can set it here, this is what all images will be built as during the build + // for `pullimages` they will get retagged as this imagename and pushed to the registry + imageBuild.BuildImage = fmt.Sprintf("%s/%s/%s/%s:%s", buildValues.ImageRegistry, buildValues.Project, buildValues.Environment, composeService, "latest") + if buildValues.BuildType == "promote" { + imageBuild.PromoteImage = fmt.Sprintf("%s/%s/%s/%s:%s", buildValues.ImageRegistry, buildValues.Project, buildValues.PromotionSourceEnvironment, composeService, "latest") + } + // populate the docker derived information here, this information will be used by the build and pushing scripts + cService.ImageBuild = &imageBuild + + // // // cService.ImageName = buildValues.ImageReferences[composeService] + // unfortunately, this uses a specific hash which is computed "AFTER" the image builds take place, so this + // `ImageName` is an unreliable field in respect to consuming data from generator during phases of a build + // it would be great if there was a way to precalculate this, but there are other issues that could pop up + // using the buildname as the tag could be one way, but this could result in container restarts even if the image hash does not change :( + // for now `ImageName` is disabled, and ImageReferences must be provided whenever templating occurs that needs an image reference + // luckily the templating engine will reproduce identical data when it is run as to when the image build data is populated as above + // so when the templating is done in a later step, at least it can be informed of the resulting image references by way of the + // images flag that is passed to it + /* + // example in code + ImageReferences: map[string]string{ + "myservice": "harbor.example.com/example-project/environment-name/myservice@sha256:abcdefg", + }, + + // in bash, the images are provided from yaml as base64 encoded data to retain formatting + // the command `lagoon-services` decodes and unmarshals it + build-deploy-tool template lagoon-services \ + --saved-templates-path ${LAGOON_SERVICES_YAML_FOLDER} \ + --images $(yq3 r -j /kubectl-build-deploy/images.yaml | jq -M -c | base64 -w0) + */ + } // check if the service has a service port override (this only applies to basic(-persistent)) servicePortOverride := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.service.port") diff --git a/internal/generator/services_test.go b/internal/generator/services_test.go index c787a137..8430b612 100644 --- a/internal/generator/services_test.go +++ b/internal/generator/services_test.go @@ -14,7 +14,6 @@ import ( func Test_composeToServiceValues(t *testing.T) { type args struct { - lYAML *lagoon.YAML buildValues *BuildValues composeService string composeServiceValues composetypes.ServiceConfig @@ -29,22 +28,29 @@ func Test_composeToServiceValues(t *testing.T) { { name: "test1", args: args{ - lYAML: &lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{}, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", Branch: "main", BuildType: "branch", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{}, + }, + }, }, composeService: "nginx", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ "lagoon.type": "nginx", }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{ @@ -55,21 +61,30 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesTLSAcme: true, InPodCronjobs: []lagoon.Cronjob{}, NativeCronjobs: []lagoon.Cronjob{}, + ImageBuild: &ImageBuild{ + TemporaryImage: "example-project-main-nginx", + Context: ".", + DockerFile: "../testdata/basic/docker/basic.dockerfile", + BuildImage: "harbor.example/example-project/main/nginx:latest", + }, }, }, { name: "test2 - override name", args: args{ - lYAML: &lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{}, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", Branch: "main", BuildType: "branch", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{}, + }, + }, }, composeService: "nginx", composeServiceValues: composetypes.ServiceConfig{ @@ -77,6 +92,10 @@ func Test_composeToServiceValues(t *testing.T) { "lagoon.type": "nginx", "lagoon.name": "nginx-php", }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{ @@ -87,31 +106,44 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesTLSAcme: true, InPodCronjobs: []lagoon.Cronjob{}, NativeCronjobs: []lagoon.Cronjob{}, + ImageBuild: &ImageBuild{ + TemporaryImage: "example-project-main-nginx", + Context: ".", + DockerFile: "../testdata/basic/docker/basic.dockerfile", + BuildImage: "harbor.example/example-project/main/nginx:latest", + }, }, }, { name: "test3 - lagoon.yml type override", args: args{ - lYAML: &lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - Types: map[string]string{ - "nginx": "nginx-php-persistent", - }, - }, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", Branch: "main", BuildType: "branch", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Types: map[string]string{ + "nginx": "nginx-php-persistent", + }, + }, + }, + }, }, composeService: "nginx", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ "lagoon.type": "nginx-php", }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{ @@ -123,30 +155,43 @@ func Test_composeToServiceValues(t *testing.T) { InPodCronjobs: []lagoon.Cronjob{}, NativeCronjobs: []lagoon.Cronjob{}, PersistentVolumeSize: "5Gi", + ImageBuild: &ImageBuild{ + TemporaryImage: "example-project-main-nginx", + Context: ".", + DockerFile: "../testdata/basic/docker/basic.dockerfile", + BuildImage: "harbor.example/example-project/main/nginx:latest", + }, }, }, { name: "test4 - variable servicetypes type override", args: args{ - lYAML: &lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{}, - }, - }, buildValues: &BuildValues{ - Environment: "main", - Branch: "main", - BuildType: "branch", + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", + Environment: "main", + Branch: "main", + BuildType: "branch", ServiceTypeOverrides: &lagoon.EnvironmentVariable{ Name: "LAGOON_SERVICE_TYPES", Value: "nginx:nginx-php-persistent,mariadb:mariadb-dbaas", }, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{}, + }, + }, }, composeService: "nginx", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ "lagoon.type": "nginx-php", }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{ @@ -157,21 +202,30 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesTLSAcme: true, InPodCronjobs: []lagoon.Cronjob{}, NativeCronjobs: []lagoon.Cronjob{}, + ImageBuild: &ImageBuild{ + TemporaryImage: "example-project-main-nginx", + Context: ".", + DockerFile: "../testdata/basic/docker/basic.dockerfile", + BuildImage: "harbor.example/example-project/main/nginx:latest", + }, }, }, { name: "test5 - additional labels", args: args{ - lYAML: &lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{}, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", Branch: "main", BuildType: "branch", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{}, + }, + }, }, composeService: "nginx", composeServiceValues: composetypes.ServiceConfig{ @@ -180,6 +234,10 @@ func Test_composeToServiceValues(t *testing.T) { "lagoon.autogeneratedroute": "false", "lagoon.autogeneratedroute.tls-acme": "false", }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{ @@ -190,34 +248,47 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesTLSAcme: false, InPodCronjobs: []lagoon.Cronjob{}, NativeCronjobs: []lagoon.Cronjob{}, + ImageBuild: &ImageBuild{ + TemporaryImage: "example-project-main-nginx", + Context: ".", + DockerFile: "../testdata/basic/docker/basic.dockerfile", + BuildImage: "harbor.example/example-project/main/nginx:latest", + }, }, }, { name: "test6 - lagoon.yml additional fields", args: args{ - lYAML: &lagoon.YAML{ - Routes: lagoon.Routes{ - Autogenerate: lagoon.Autogenerate{ - Enabled: helpers.BoolPtr(false), - }, - }, - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - AutogenerateRoutes: helpers.BoolPtr(true), - }, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", Branch: "main", BuildType: "branch", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Routes: lagoon.Routes{ + Autogenerate: lagoon.Autogenerate{ + Enabled: helpers.BoolPtr(false), + }, + }, + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + AutogenerateRoutes: helpers.BoolPtr(true), + }, + }, + }, }, composeService: "nginx", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ "lagoon.type": "nginx-php", }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{ @@ -228,35 +299,48 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesTLSAcme: true, InPodCronjobs: []lagoon.Cronjob{}, NativeCronjobs: []lagoon.Cronjob{}, + ImageBuild: &ImageBuild{ + TemporaryImage: "example-project-main-nginx", + Context: ".", + DockerFile: "../testdata/basic/docker/basic.dockerfile", + BuildImage: "harbor.example/example-project/main/nginx:latest", + }, }, }, { name: "test7 - lagoon.yml additional fields pullrequest", args: args{ - lYAML: &lagoon.YAML{ - Routes: lagoon.Routes{ - Autogenerate: lagoon.Autogenerate{ - Enabled: helpers.BoolPtr(true), - AllowPullRequests: helpers.BoolPtr(false), - }, - }, - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - AutogenerateRoutes: helpers.BoolPtr(true), - }, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-pr-123", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "pr-123", Branch: "pr-123", BuildType: "pullrequest", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Routes: lagoon.Routes{ + Autogenerate: lagoon.Autogenerate{ + Enabled: helpers.BoolPtr(true), + AllowPullRequests: helpers.BoolPtr(false), + }, + }, + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + AutogenerateRoutes: helpers.BoolPtr(true), + }, + }, + }, }, composeService: "nginx", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ "lagoon.type": "nginx-php", }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{ @@ -267,29 +351,38 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesTLSAcme: true, InPodCronjobs: []lagoon.Cronjob{}, NativeCronjobs: []lagoon.Cronjob{}, + ImageBuild: &ImageBuild{ + TemporaryImage: "example-project-pr-123-nginx", + Context: ".", + DockerFile: "../testdata/basic/docker/basic.dockerfile", + BuildImage: "harbor.example/example-project/pr-123/nginx:latest", + }, }, }, { name: "test8 - no labels, no service", args: args{ - lYAML: &lagoon.YAML{ - Routes: lagoon.Routes{ - Autogenerate: lagoon.Autogenerate{ - Enabled: helpers.BoolPtr(true), - AllowPullRequests: helpers.BoolPtr(false), - }, - }, - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - AutogenerateRoutes: helpers.BoolPtr(true), - }, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-pr-123", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "pr-123", Branch: "pr-123", BuildType: "pullrequest", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Routes: lagoon.Routes{ + Autogenerate: lagoon.Autogenerate{ + Enabled: helpers.BoolPtr(true), + AllowPullRequests: helpers.BoolPtr(false), + }, + }, + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + AutogenerateRoutes: helpers.BoolPtr(true), + }, + }, + }, }, composeService: "nginx", composeServiceValues: composetypes.ServiceConfig{}, @@ -300,30 +393,37 @@ func Test_composeToServiceValues(t *testing.T) { { name: "test9 - type none, no service", args: args{ - lYAML: &lagoon.YAML{ - Routes: lagoon.Routes{ - Autogenerate: lagoon.Autogenerate{ - Enabled: helpers.BoolPtr(true), - AllowPullRequests: helpers.BoolPtr(false), - }, - }, - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - AutogenerateRoutes: helpers.BoolPtr(true), - }, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-pr-123", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "pr-123", Branch: "pr-123", BuildType: "pullrequest", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Routes: lagoon.Routes{ + Autogenerate: lagoon.Autogenerate{ + Enabled: helpers.BoolPtr(true), + AllowPullRequests: helpers.BoolPtr(false), + }, + }, + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + AutogenerateRoutes: helpers.BoolPtr(true), + }, + }, + }, }, composeService: "nginx", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ "lagoon.type": "none", }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{}, @@ -331,31 +431,36 @@ func Test_composeToServiceValues(t *testing.T) { { name: "test10 - mariadb to mariadb-dbaas", args: args{ - lYAML: &lagoon.YAML{ - Routes: lagoon.Routes{ - Autogenerate: lagoon.Autogenerate{ - Enabled: helpers.BoolPtr(true), - AllowPullRequests: helpers.BoolPtr(false), - }, - }, - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - AutogenerateRoutes: helpers.BoolPtr(true), - }, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", Branch: "main", BuildType: "branch", EnvironmentType: "development", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Routes: lagoon.Routes{ + Autogenerate: lagoon.Autogenerate{ + Enabled: helpers.BoolPtr(true), + AllowPullRequests: helpers.BoolPtr(false), + }, + }, + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + AutogenerateRoutes: helpers.BoolPtr(true), + }, + }, + }, }, composeService: "mariadb", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ "lagoon.type": "mariadb", - }}, + }, + Image: "uselagoon/fake-mariadb:latest", + }, }, want: ServiceValues{ Name: "mariadb", @@ -372,20 +477,10 @@ func Test_composeToServiceValues(t *testing.T) { //@TODO: this should FAIL in the future https://github.com/uselagoon/build-deploy-tool/issues/56 name: "test11 - mariadb to mariadb-single via environment override with no patching db provider", args: args{ - lYAML: &lagoon.YAML{ - Routes: lagoon.Routes{ - Autogenerate: lagoon.Autogenerate{ - Enabled: helpers.BoolPtr(true), - AllowPullRequests: helpers.BoolPtr(false), - }, - }, - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - AutogenerateRoutes: helpers.BoolPtr(true), - }, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", Branch: "main", BuildType: "branch", @@ -395,12 +490,27 @@ func Test_composeToServiceValues(t *testing.T) { Name: "LAGOON_DBAAS_ENVIRONMENT_TYPES", Value: "mariadb:development2,postgres:postgres-single", }, + LagoonYAML: lagoon.YAML{ + Routes: lagoon.Routes{ + Autogenerate: lagoon.Autogenerate{ + Enabled: helpers.BoolPtr(true), + AllowPullRequests: helpers.BoolPtr(false), + }, + }, + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + AutogenerateRoutes: helpers.BoolPtr(true), + }, + }, + }, }, composeService: "mariadb", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ "lagoon.type": "mariadb", - }}, + }, + Image: "uselagoon/fake-mariadb:latest", + }, }, want: ServiceValues{ Name: "mariadb", @@ -411,36 +521,45 @@ func Test_composeToServiceValues(t *testing.T) { DBaaSEnvironment: "development2", InPodCronjobs: []lagoon.Cronjob{}, NativeCronjobs: []lagoon.Cronjob{}, + ImageBuild: &ImageBuild{ + PullImage: "uselagoon/fake-mariadb:latest", + BuildImage: "harbor.example/example-project/main/mariadb:latest", + }, }, }, { name: "test12 - postgres to postgres-dbaas", args: args{ - lYAML: &lagoon.YAML{ - Routes: lagoon.Routes{ - Autogenerate: lagoon.Autogenerate{ - Enabled: helpers.BoolPtr(true), - AllowPullRequests: helpers.BoolPtr(false), - }, - }, - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - AutogenerateRoutes: helpers.BoolPtr(true), - }, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", Branch: "main", BuildType: "branch", EnvironmentType: "development", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Routes: lagoon.Routes{ + Autogenerate: lagoon.Autogenerate{ + Enabled: helpers.BoolPtr(true), + AllowPullRequests: helpers.BoolPtr(false), + }, + }, + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + AutogenerateRoutes: helpers.BoolPtr(true), + }, + }, + }, }, composeService: "postgres", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ "lagoon.type": "postgres", - }}, + }, + Image: "uselagoon/fake-postgres:latest", + }, }, want: ServiceValues{ Name: "postgres", @@ -456,22 +575,29 @@ func Test_composeToServiceValues(t *testing.T) { { name: "test13 - ckandatapusher should be python", args: args{ - lYAML: &lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{}, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", Branch: "main", BuildType: "branch", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{}, + }, + }, }, composeService: "python-ckan", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ "lagoon.type": "python-ckandatapusher", }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{ @@ -482,36 +608,49 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesTLSAcme: true, InPodCronjobs: []lagoon.Cronjob{}, NativeCronjobs: []lagoon.Cronjob{}, + ImageBuild: &ImageBuild{ + TemporaryImage: "example-project-main-python-ckan", + Context: ".", + DockerFile: "../testdata/basic/docker/basic.dockerfile", + BuildImage: "harbor.example/example-project/main/python-ckan:latest", + }, }, }, { name: "test14 - spot instances", args: args{ - lYAML: &lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{}, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", EnvironmentType: "production", Branch: "main", BuildType: "branch", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + EnvironmentVariables: []lagoon.EnvironmentVariable{ + {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION", Value: "enabled", Scope: "global"}, + {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT", Value: "enabled", Scope: "global"}, + {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_TYPES", Value: "nginx:force,nginx-php-persistent,basic", Scope: "global"}, + {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"}, + {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES", Value: "nginx:force,nginx-php-persistent,basic", Scope: "global"}, + {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT_CRONJOB_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"}, + }, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{}, + }, + }, }, composeService: "nginx", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ "lagoon.type": "nginx", }, - }, - lagoonEnvVars: []lagoon.EnvironmentVariable{ - {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION", Value: "enabled", Scope: "global"}, - {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT", Value: "enabled", Scope: "global"}, - {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_TYPES", Value: "nginx:force,nginx-php-persistent,basic", Scope: "global"}, - {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"}, - {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_PRODUCTION_CRONJOB_TYPES", Value: "nginx:force,nginx-php-persistent,basic", Scope: "global"}, - {Name: "LAGOON_FEATURE_FLAG_SPOT_INSTANCE_DEVELOPMENT_CRONJOB_TYPES", Value: "nginx,nginx-php-persistent,basic", Scope: "global"}, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{ @@ -528,22 +667,31 @@ func Test_composeToServiceValues(t *testing.T) { InPodCronjobs: []lagoon.Cronjob{}, NativeCronjobs: []lagoon.Cronjob{}, Replicas: 2, + ImageBuild: &ImageBuild{ + TemporaryImage: "example-project-main-nginx", + Context: ".", + DockerFile: "../testdata/basic/docker/basic.dockerfile", + BuildImage: "harbor.example/example-project/main/nginx:latest", + }, }, }, { name: "test15 - multiple service ports", args: args{ - lYAML: &lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{}, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", EnvironmentType: "production", Branch: "main", BuildType: "branch", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{}, + }, + }, }, composeService: "service-a", composeServiceValues: composetypes.ServiceConfig{ @@ -557,6 +705,10 @@ func Test_composeToServiceValues(t *testing.T) { Protocol: "tcp", }, }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{ @@ -577,42 +729,61 @@ func Test_composeToServiceValues(t *testing.T) { ServiceName: "service-a-8181", }, }, + ImageBuild: &ImageBuild{ + TemporaryImage: "example-project-main-service-a", + Context: ".", + DockerFile: "../testdata/basic/docker/basic.dockerfile", + BuildImage: "harbor.example/example-project/main/service-a:latest", + }, }, }, { name: "test16 - cronjobs", args: args{ - lYAML: &lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - Cronjobs: []lagoon.Cronjob{ - { - Name: "My Cronjob", - Command: "env", - Service: "cli", - Schedule: "5 2 * * *", - }, - { - Name: "My Cronjob2", - Command: "drush cron", - Service: "cli", - Schedule: "*/5 * * * *", - }, - }, - }, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", Branch: "main", BuildType: "branch", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Cronjobs: []lagoon.Cronjob{ + { + Name: "My Cronjob", + Command: "env", + Service: "cli", + Schedule: "5 2 * * *", + }, + { + Name: "My Cronjob2", + Command: "drush cron", + Service: "cli", + Schedule: "*/5 * * * *", + }, + { + Name: "My Cronjob that has a very very very long name", + Command: "drush cron", + Service: "cli", + Schedule: "5 2 * * *", + }, + }, + }, + }, + }, }, composeService: "cli", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ "lagoon.type": "cli", }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{ @@ -625,7 +796,7 @@ func Test_composeToServiceValues(t *testing.T) { { Name: "My Cronjob2", Service: "cli", - Schedule: "0,5,10,15,20,25,30,35,40,45,50,55 * * * *", + Schedule: "3,8,13,18,23,28,33,38,43,48,53,58 * * * *", Command: "drush cron", }, }, @@ -635,44 +806,64 @@ func Test_composeToServiceValues(t *testing.T) { Service: "cli", Schedule: "5 2 * * *", Command: "env", - }}, + }, + { + Name: "cronjob-cli-my-cronjob-that-has-a-very-very-v-znwv36", + Service: "cli", + Schedule: "5 2 * * *", + Command: "drush cron", + }, + }, + ImageBuild: &ImageBuild{ + TemporaryImage: "example-project-main-cli", + Context: ".", + DockerFile: "../testdata/basic/docker/basic.dockerfile", + BuildImage: "harbor.example/example-project/main/cli:latest", + }, }, }, { name: "test17 - cronjobs disabled", args: args{ - lYAML: &lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - Cronjobs: []lagoon.Cronjob{ - { - Name: "My Cronjob", - Command: "env", - Service: "cli", - Schedule: "5 2 * * *", - }, - { - Name: "My Cronjob2", - Command: "drush cron", - Service: "cli", - Schedule: "*/5 * * * *", - }, - }, - }, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", Branch: "main", BuildType: "branch", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, CronjobsDisabled: true, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Cronjobs: []lagoon.Cronjob{ + { + Name: "My Cronjob", + Command: "env", + Service: "cli", + Schedule: "5 2 * * *", + }, + { + Name: "My Cronjob2", + Command: "drush cron", + Service: "cli", + Schedule: "*/5 * * * *", + }, + }, + }, + }, + }, }, composeService: "cli", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ "lagoon.type": "cli", }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{ @@ -683,21 +874,30 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesTLSAcme: false, InPodCronjobs: []lagoon.Cronjob{}, NativeCronjobs: []lagoon.Cronjob{}, + ImageBuild: &ImageBuild{ + TemporaryImage: "example-project-main-cli", + Context: ".", + DockerFile: "../testdata/basic/docker/basic.dockerfile", + BuildImage: "harbor.example/example-project/main/cli:latest", + }, }, }, { name: "test18 - invalid service port", args: args{ - lYAML: &lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{}, - }, - }, buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", Branch: "main", BuildType: "branch", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{}, + }, + }, }, composeService: "basic", composeServiceValues: composetypes.ServiceConfig{ @@ -705,6 +905,10 @@ func Test_composeToServiceValues(t *testing.T) { "lagoon.type": "basic", "lagoon.service.port": "32a12", }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, }, }, want: ServiceValues{}, @@ -713,46 +917,185 @@ func Test_composeToServiceValues(t *testing.T) { { name: "test19 - duplicate cronjobs", args: args{ - lYAML: &lagoon.YAML{ - Environments: lagoon.Environments{ - "main": lagoon.Environment{ - Cronjobs: []lagoon.Cronjob{ - { - Name: "My Cronjob", - Command: "env", - Service: "cli", - Schedule: "5 2 * * *", - }, - { - Name: "My Cronjob2", - Command: "drush cron", - Service: "cli", - Schedule: "*/5 * * * *", + buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", + Environment: "main", + Branch: "main", + BuildType: "branch", + ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Cronjobs: []lagoon.Cronjob{ + { + Name: "My Cronjob", + Command: "env", + Service: "cli", + Schedule: "5 2 * * *", + }, + { + Name: "My Cronjob2", + Command: "drush cron", + Service: "cli", + Schedule: "*/5 * * * *", + }, + { + Name: "My Cronjob", + Command: "env", + Service: "cli", + Schedule: "15 5 4 * 0", + }, }, - { - Name: "My Cronjob", - Command: "env", - Service: "cli", - Schedule: "15 5 4 * 0", + }, + }, + }, + }, + composeService: "cli", + composeServiceValues: composetypes.ServiceConfig{ + Labels: composetypes.Labels{ + "lagoon.type": "cli", + }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, + }, + }, + wantErr: true, + }, + { + name: "test20 - dockerfile build items", + args: args{ + buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", + Environment: "main", + Branch: "main", + BuildType: "branch", + ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{}, + }, + }, + }, + composeService: "redis", + composeServiceValues: composetypes.ServiceConfig{ + Labels: composetypes.Labels{ + "lagoon.type": "redis", + }, + Image: "uselagoon/fake-redis:latest", + }, + }, + want: ServiceValues{ + Name: "redis", + OverrideName: "redis", + Type: "redis", + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, + ImageBuild: &ImageBuild{ + PullImage: "uselagoon/fake-redis:latest", + BuildImage: "harbor.example/example-project/main/redis:latest", + }, + }, + }, + { + name: "test21 - dockerfile build override from lagoon.yml", + args: args{ + buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", + Environment: "main", + Branch: "main", + BuildType: "branch", + ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Overrides: map[string]lagoon.Override{ + "nginx": { + Build: lagoon.Build{ + Dockerfile: "../testdata/basic/docker/basic.dockerfile", + }, + }, }, }, }, }, }, + composeService: "nginx", + composeServiceValues: composetypes.ServiceConfig{ + Labels: composetypes.Labels{ + "lagoon.type": "nginx", + }, + Build: &composetypes.BuildConfig{ + Context: ".", + Dockerfile: "../testdata/basic/docker/basic.dockerfile", //intentionally wrong, override by lagoon.yml + }, + }, + }, + want: ServiceValues{ + Name: "nginx", + OverrideName: "nginx", + Type: "nginx", + AutogeneratedRoutesEnabled: true, + AutogeneratedRoutesTLSAcme: true, + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, + ImageBuild: &ImageBuild{ + TemporaryImage: "example-project-main-nginx", + Context: ".", + DockerFile: "../testdata/basic/docker/basic.dockerfile", + BuildImage: "harbor.example/example-project/main/nginx:latest", + }, + }, + }, + { + name: "test22 - dockerfile image override from lagoon.yml", + args: args{ buildValues: &BuildValues{ + Namespace: "example-project-main", + Project: "example-project", + ImageRegistry: "harbor.example", Environment: "main", Branch: "main", BuildType: "branch", ServiceTypeOverrides: &lagoon.EnvironmentVariable{}, + LagoonYAML: lagoon.YAML{ + Environments: lagoon.Environments{ + "main": lagoon.Environment{ + Overrides: map[string]lagoon.Override{ + "redis": { + Image: "uselagoon/fake-redis:7", + }, + }, + }, + }, + }, }, - composeService: "cli", + composeService: "redis", composeServiceValues: composetypes.ServiceConfig{ Labels: composetypes.Labels{ - "lagoon.type": "cli", + "lagoon.type": "redis", }, + Image: "uselagoon/fake-redis:latest", //intentionally wrong, override by lagoon.yml + }, + }, + want: ServiceValues{ + Name: "redis", + OverrideName: "redis", + Type: "redis", + InPodCronjobs: []lagoon.Cronjob{}, + NativeCronjobs: []lagoon.Cronjob{}, + ImageBuild: &ImageBuild{ + PullImage: "uselagoon/fake-redis:7", + BuildImage: "harbor.example/example-project/main/redis:latest", }, }, - wantErr: true, }, } for _, tt := range tests { @@ -765,7 +1108,7 @@ func Test_composeToServiceValues(t *testing.T) { RetryWaitMin: time.Duration(10) * time.Millisecond, RetryWaitMax: time.Duration(50) * time.Millisecond, }) - got, err := composeToServiceValues(tt.args.buildValues, tt.args.lagoonEnvVars, tt.args.lYAML, tt.args.composeService, tt.args.composeServiceValues, false) + got, err := composeToServiceValues(tt.args.buildValues, tt.args.composeService, tt.args.composeServiceValues, false) if (err != nil) != tt.wantErr { t.Errorf("composeToServiceValues() error = %v, wantErr %v", err, tt.wantErr) return From 9e30a6805fbbff82f9a72c7901c940356ab302f5 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 12 Jan 2024 12:05:12 +1100 Subject: [PATCH 48/92] refactor: support additional lagoonyaml values --- internal/lagoon/lagoon.go | 58 ++++++++++++++++--- internal/lagoon/lagoon_test.go | 37 ++++++++++++ .../lagoon-yaml/test7/lagoon.yml | 14 +++++ 3 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 internal/lagoon/test-resources/lagoon-yaml/test7/lagoon.yml diff --git a/internal/lagoon/lagoon.go b/internal/lagoon/lagoon.go index 9d149279..f0ddf0b7 100644 --- a/internal/lagoon/lagoon.go +++ b/internal/lagoon/lagoon.go @@ -24,6 +24,7 @@ type Environment struct { Types map[string]string `json:"types"` Routes []map[string][]Route `json:"routes"` Cronjobs []Cronjob `json:"cronjobs"` + Overrides map[string]Override `json:"overrides,omitempty"` } // Cronjob represents a Lagoon cronjob. @@ -34,6 +35,16 @@ type Cronjob struct { Command string `json:"command"` } +type Override struct { + Build Build `json:"build,omitempty"` + Image string `json:"image,omitempty"` +} + +type Build struct { + Dockerfile string `json:"dockerfile,omitempty"` + Context string `json:"context,omitempty"` +} + // Environments . type Environments map[string]Environment @@ -50,13 +61,18 @@ type Tasks struct { // YAML represents the .lagoon.yml file. type YAML struct { - DockerComposeYAML string `json:"docker-compose-yaml"` - Environments Environments `json:"environments"` - ProductionRoutes *ProductionRoutes `json:"production_routes"` - Tasks Tasks `json:"tasks"` - Routes Routes `json:"routes"` - BackupRetention BackupRetention `json:"backup-retention"` - BackupSchedule BackupSchedule `json:"backup-schedule"` + DockerComposeYAML string `json:"docker-compose-yaml"` + Environments Environments `json:"environments"` + ProductionRoutes *ProductionRoutes `json:"production_routes"` + Tasks Tasks `json:"tasks"` + Routes Routes `json:"routes"` + BackupRetention BackupRetention `json:"backup-retention"` + BackupSchedule BackupSchedule `json:"backup-schedule"` + EnvironmentVariables EnvironmentVariables `json:"environment_variables,omitempty"` +} + +type EnvironmentVariables struct { + GitSHA *bool `json:"git_sha"` } type BackupRetention struct { @@ -101,6 +117,8 @@ func (a *Routes) UnmarshalJSON(data []byte) error { if reflect.TypeOf(value.(map[string]interface{})["tls-acme"]).Kind() == reflect.String { vBool, err := strconv.ParseBool(value.(map[string]interface{})["tls-acme"].(string)) if err == nil { + // @TODO: add warning functionality here to inform that users should fix their yaml to be boolean not string + // this could warn in a yaml validation step at the start of builds value.(map[string]interface{})["tls-acme"] = vBool } } @@ -109,6 +127,8 @@ func (a *Routes) UnmarshalJSON(data []byte) error { if reflect.TypeOf(value.(map[string]interface{})["enabled"]).Kind() == reflect.String { vBool, err := strconv.ParseBool(value.(map[string]interface{})["enabled"].(string)) if err == nil { + // @TODO: add warning functionality here to inform that users should fix their yaml to be boolean not string + // this could warn in a yaml validation step at the start of builds value.(map[string]interface{})["enabled"] = vBool } } @@ -117,6 +137,8 @@ func (a *Routes) UnmarshalJSON(data []byte) error { if reflect.TypeOf(value.(map[string]interface{})["allowPullRequests"]).Kind() == reflect.String { vBool, err := strconv.ParseBool(value.(map[string]interface{})["allowPullRequests"].(string)) if err == nil { + // @TODO: add warning functionality here to inform that users should fix their yaml to be boolean not string + // this could warn in a yaml validation step at the start of builds value.(map[string]interface{})["allowPullRequests"] = vBool } } @@ -127,6 +149,28 @@ func (a *Routes) UnmarshalJSON(data []byte) error { return nil } +func (a *EnvironmentVariables) UnmarshalJSON(data []byte) error { + tmpMap := map[string]interface{}{} + json.Unmarshal(data, &tmpMap) + if value, ok := tmpMap["git_sha"]; ok { + // @TODO: eventually lagoon should be more strict, but in lagoonyaml version 2 we could do this + // some things in .lagoon.yml can be defined as a bool or string and lagoon builds don't care + // but types are more strict, so this unmarshaler attempts to change between the two types + // that can be bool or string + if reflect.TypeOf(value).Kind() == reflect.String { + vBool, err := strconv.ParseBool(value.(string)) + if err == nil { + // @TODO: add warning functionality here to inform that users should fix their yaml to be boolean not string + // this could warn in a yaml validation step at the start of builds + value = vBool + } + } + newData, _ := json.Marshal(value) + return json.Unmarshal(newData, &a.GitSHA) + } + return nil +} + // UnmarshalLagoonYAML unmarshal the lagoon.yml file into a YAML and map for consumption. func UnmarshalLagoonYAML(file string, l *YAML, project string) error { rawYAML, err := os.ReadFile(file) diff --git a/internal/lagoon/lagoon_test.go b/internal/lagoon/lagoon_test.go index e6ee7c7d..92634a33 100644 --- a/internal/lagoon/lagoon_test.go +++ b/internal/lagoon/lagoon_test.go @@ -317,6 +317,43 @@ func TestUnmarshalLagoonYAML(t *testing.T) { }, }, }, + { + name: "test overrides", + args: args{ + file: "test-resources/lagoon-yaml/test7/lagoon.yml", + l: &YAML{}, + }, + want: &YAML{ + DockerComposeYAML: "docker-compose.yml", + EnvironmentVariables: EnvironmentVariables{ + GitSHA: helpers.BoolPtr(true), + }, + Environments: Environments{ + "main": Environment{ + Routes: []map[string][]Route{ + { + "nginx": { + { + Ingresses: map[string]Ingress{ + "a.example.com": { + TLSAcme: helpers.BoolPtr(true), + }, + }, + }, + }, + }, + }, + Overrides: map[string]Override{ + "nginx": { + Build: Build{ + Dockerfile: "test-resources/dockerfile.nginx", + }, + }, + }, + }, + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/lagoon/test-resources/lagoon-yaml/test7/lagoon.yml b/internal/lagoon/test-resources/lagoon-yaml/test7/lagoon.yml new file mode 100644 index 00000000..ea324033 --- /dev/null +++ b/internal/lagoon/test-resources/lagoon-yaml/test7/lagoon.yml @@ -0,0 +1,14 @@ +docker-compose-yaml: docker-compose.yml +environment_variables: + git_sha: 'true' + +environments: + main: + overrides: + nginx: + build: + dockerfile: test-resources/dockerfile.nginx + routes: + - nginx: + - a.example.com: + tls-acme: true \ No newline at end of file From ff23a15cb3cc5481d9f9d915e2808a450f575368 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 12 Jan 2024 12:06:01 +1100 Subject: [PATCH 49/92] chore: update test results with latest fixes --- .../service1/deployment-node.yaml | 3 +- .../service2/deployment-lnd.yaml | 3 +- .../service2/deployment-thunderhub.yaml | 3 +- .../service2/deployment-tor.yaml | 3 +- .../service3/deployment-lnd.yaml | 3 +- .../service3/deployment-tor.yaml | 3 +- .../service4/deployment-node.yaml | 83 +++++++++++++++++ .../service4/service-node.yaml | 38 ++++++++ .../service5/deployment-node.yaml | 89 +++++++++++++++++++ .../service5/service-node.yaml | 41 +++++++++ .../cronjob-cronjob-cli-drush-cron2.yaml | 3 +- .../service1/deployment-cli.yaml | 3 +- .../service1/deployment-nginx-php.yaml | 6 +- .../service1/deployment-redis.yaml | 3 +- .../service1/deployment-varnish.yaml | 3 +- .../cronjob-cronjob-cli-drush-cron2.yaml | 3 +- .../service2/deployment-cli.yaml | 3 +- .../service2/deployment-nginx-php.yaml | 6 +- .../service2/deployment-redis.yaml | 3 +- .../service2/deployment-varnish.yaml | 3 +- 20 files changed, 287 insertions(+), 18 deletions(-) create mode 100644 internal/testdata/basic/service-templates/service4/deployment-node.yaml create mode 100644 internal/testdata/basic/service-templates/service4/service-node.yaml create mode 100644 internal/testdata/basic/service-templates/service5/deployment-node.yaml create mode 100644 internal/testdata/basic/service-templates/service5/service-node.yaml diff --git a/internal/testdata/basic/service-templates/service1/deployment-node.yaml b/internal/testdata/basic/service-templates/service1/deployment-node.yaml index 1a0d8667..1f637b42 100644 --- a/internal/testdata/basic/service-templates/service1/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service1/deployment-node.yaml @@ -47,11 +47,12 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/node:latest + image: harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml index fe94c93d..53aa050e 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml @@ -47,11 +47,12 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/lnd:latest + image: harbor.example/example-project/main/lnd@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml index 71cc158e..7d7e148c 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml @@ -47,11 +47,12 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/thunderhub:latest + image: harbor.example/example-project/main/thunderhub@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/basic/service-templates/service2/deployment-tor.yaml b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml index ef0c864f..c1a22ed5 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-tor.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml @@ -47,11 +47,12 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/tor:latest + image: harbor.example/example-project/main/tor@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml index fe94c93d..53aa050e 100644 --- a/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml +++ b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml @@ -47,11 +47,12 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/lnd:latest + image: harbor.example/example-project/main/lnd@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/basic/service-templates/service3/deployment-tor.yaml b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml index 97762e89..eb1387fa 100644 --- a/internal/testdata/basic/service-templates/service3/deployment-tor.yaml +++ b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml @@ -47,11 +47,12 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/tor:latest + image: harbor.example/example-project/main/tor@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 name: worker readinessProbe: exec: diff --git a/internal/testdata/basic/service-templates/service4/deployment-node.yaml b/internal/testdata/basic/service-templates/service4/deployment-node.yaml new file mode 100644 index 00000000..68e8ad2e --- /dev/null +++ b/internal/testdata/basic/service-templates/service4/deployment-node.yaml @@ -0,0 +1,83 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + 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: promote + 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/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: promote + 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 + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + 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: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production +status: {} diff --git a/internal/testdata/basic/service-templates/service4/service-node.yaml b/internal/testdata/basic/service-templates/service4/service-node.yaml new file mode 100644 index 00000000..bf27295a --- /dev/null +++ b/internal/testdata/basic/service-templates/service4/service-node.yaml @@ -0,0 +1,38 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + 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: promote + 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: {} diff --git a/internal/testdata/basic/service-templates/service5/deployment-node.yaml b/internal/testdata/basic/service-templates/service5/deployment-node.yaml new file mode 100644 index 00000000..d1e65d6a --- /dev/null +++ b/internal/testdata/basic/service-templates/service5/deployment-node.yaml @@ -0,0 +1,89 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/prBaseBranch: pr-base + lagoon.sh/prHeadBranch: pr-head + lagoon.sh/prNumber: "123" + 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: pullrequest + lagoon.sh/environment: pr-123 + 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/configMapSha: abcdefg1234567890 + lagoon.sh/prBaseBranch: pr-base + lagoon.sh/prHeadBranch: pr-head + lagoon.sh/prNumber: "123" + 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: pullrequest + lagoon.sh/environment: pr-123 + 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 + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/pr-123/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + 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: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production +status: {} diff --git a/internal/testdata/basic/service-templates/service5/service-node.yaml b/internal/testdata/basic/service-templates/service5/service-node.yaml new file mode 100644 index 00000000..36448c38 --- /dev/null +++ b/internal/testdata/basic/service-templates/service5/service-node.yaml @@ -0,0 +1,41 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/prBaseBranch: pr-base + lagoon.sh/prHeadBranch: pr-head + lagoon.sh/prNumber: "123" + 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: pullrequest + lagoon.sh/environment: pr-123 + 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: {} diff --git a/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml b/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml index 23ac5968..bdb1e0ed 100644 --- a/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml +++ b/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml @@ -50,12 +50,13 @@ spec: - drush cron env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: SERVICE_NAME value: cli envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/cli:latest + image: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 name: cronjob-cli-drush-cron2 resources: requests: diff --git a/internal/testdata/complex/service-templates/service1/deployment-cli.yaml b/internal/testdata/complex/service-templates/service1/deployment-cli.yaml index b8400b7a..98dab57b 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-cli.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-cli.yaml @@ -47,13 +47,14 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS value: | 3,18,33,48 * * * * drush cron envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/cli:latest + image: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 name: cli readinessProbe: exec: diff --git a/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml index 586bcbfb..243621b9 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml @@ -49,11 +49,12 @@ spec: - name: NGINX_FASTCGI_PASS value: 127.0.0.1 - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/nginx:latest + image: harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 livenessProbe: failureThreshold: 5 httpGet: @@ -83,10 +84,11 @@ spec: - name: NGINX_FASTCGI_PASS value: 127.0.0.1 - name: LAGOON_GIT_SHA + value: abcdefg123456 envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/php:latest + image: harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 livenessProbe: initialDelaySeconds: 60 periodSeconds: 10 diff --git a/internal/testdata/complex/service-templates/service1/deployment-redis.yaml b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml index 48822935..410e91a8 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-redis.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml @@ -47,11 +47,12 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/redis:latest + image: harbor.example/example-project/main/redis@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 livenessProbe: initialDelaySeconds: 120 tcpSocket: diff --git a/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml index 01c0bf35..db6c14c5 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml @@ -47,11 +47,12 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/varnish:latest + image: harbor.example/example-project/main/varnish@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml b/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml index 82f11316..758aa012 100644 --- a/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml +++ b/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml @@ -50,12 +50,13 @@ spec: - drush cron env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: SERVICE_NAME value: cli envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/cli:latest + image: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 name: cronjob-cli-drush-cron2 resources: requests: diff --git a/internal/testdata/complex/service-templates/service2/deployment-cli.yaml b/internal/testdata/complex/service-templates/service2/deployment-cli.yaml index d09af656..6e7848e8 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-cli.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-cli.yaml @@ -47,13 +47,14 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS value: | 3,18,33,48 * * * * drush cron envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/cli:latest + image: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 name: cli readinessProbe: exec: diff --git a/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml index 817dd923..8a65c258 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml @@ -49,11 +49,12 @@ spec: - name: NGINX_FASTCGI_PASS value: 127.0.0.1 - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/nginx:latest + image: harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 livenessProbe: failureThreshold: 5 httpGet: @@ -83,10 +84,11 @@ spec: - name: NGINX_FASTCGI_PASS value: 127.0.0.1 - name: LAGOON_GIT_SHA + value: abcdefg123456 envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/php:latest + image: harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 livenessProbe: initialDelaySeconds: 60 periodSeconds: 10 diff --git a/internal/testdata/complex/service-templates/service2/deployment-redis.yaml b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml index d4cc970e..4c3c07ea 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-redis.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml @@ -47,11 +47,12 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/redis:latest + image: harbor.example/example-project/main/redis@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 livenessProbe: initialDelaySeconds: 120 tcpSocket: diff --git a/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml index dd142ca5..b73ed33d 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml @@ -47,11 +47,12 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: abcdefg123456 - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env - image: harbor.example/example-project/main/varnish:latest + image: harbor.example/example-project/main/varnish@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 livenessProbe: initialDelaySeconds: 60 tcpSocket: From 364238e03f5a79128e073ca0c01101ba85fe5f49 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 12 Jan 2024 12:49:19 +1100 Subject: [PATCH 50/92] chore: update test results with latest fixes --- .../templating/services/templates_cronjob.go | 8 +- .../services/templates_cronjob_test.go | 8 +- .../services/templates_deployment.go | 17 ++- .../services/templates_deployment_test.go | 127 ++++++++++++------ .../deployment/result-basic-1.yaml | 15 ++- .../deployment/result-cli-1.yaml | 2 +- .../deployment/result-elasticsearch-1.yaml | 12 +- .../deployment/result-opensearch-1.yaml | 12 +- .../deployment/result-postgres-single-1.yaml | 4 +- .../deployment/result-solr-1.yaml | 4 +- 10 files changed, 146 insertions(+), 63 deletions(-) diff --git a/internal/templating/services/templates_cronjob.go b/internal/templating/services/templates_cronjob.go index b43b99ec..6181948b 100644 --- a/internal/templating/services/templates_cronjob.go +++ b/internal/templating/services/templates_cronjob.go @@ -290,7 +290,11 @@ func GenerateCronjobTemplate( // handle setting the rest of the containers specs with values from the service or build values container.Container.Name = nCronjob.Name - container.Container.Image = serviceValues.ImageName + if val, ok := buildValues.ImageReferences[serviceValues.Name]; ok { + container.Container.Image = val + } else { + return nil, fmt.Errorf("no image reference was found for primary container of service %s", serviceValues.Name) + } // set up cronjobs if required cronjobs := "" @@ -300,7 +304,7 @@ func GenerateCronjobTemplate( envvars := []corev1.EnvVar{ { Name: "LAGOON_GIT_SHA", - Value: buildValues.GitSha, + Value: buildValues.GitSHA, }, { Name: "SERVICE_NAME", diff --git a/internal/templating/services/templates_cronjob_test.go b/internal/templating/services/templates_cronjob_test.go index 8be07cad..a5226518 100644 --- a/internal/templating/services/templates_cronjob_test.go +++ b/internal/templating/services/templates_cronjob_test.go @@ -38,7 +38,11 @@ func TestGenerateCronjobTemplate(t *testing.T) { Name: "lagoon-internal-registry-secret", }, }, - GitSha: "0", + ImageReferences: map[string]string{ + "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", + "myservice-persist": "harbor.example.com/example-project/environment-name/myservice-persistent@latest", + }, + GitSHA: "0", ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", Services: []generator.ServiceValues{ { @@ -46,7 +50,6 @@ func TestGenerateCronjobTemplate(t *testing.T) { OverrideName: "myservice", Type: "cli", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/myservice@latest", NativeCronjobs: []lagoon.Cronjob{ { Name: "cronjob-myservice-my-cronjobbb", @@ -67,7 +70,6 @@ func TestGenerateCronjobTemplate(t *testing.T) { OverrideName: "myservice-persist", Type: "cli-persistent", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/myservice-persistent@latest", PersistentVolumePath: "/storage/data", PersistentVolumeName: "nginx-php", NativeCronjobs: []lagoon.Cronjob{ diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index a2dd5a3c..70d8e5ca 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -364,8 +364,11 @@ func GenerateDeploymentTemplate( // handle setting the rest of the containers specs with values from the service or build values container.Container.Name = container.Name - container.Container.Image = serviceValues.ImageName - + if val, ok := buildValues.ImageReferences[serviceValues.Name]; ok { + container.Container.Image = val + } else { + return nil, fmt.Errorf("no image reference was found for primary container of service %s", serviceValues.Name) + } // set up cronjobs if required cronjobs := "" for _, cronjob := range serviceValues.InPodCronjobs { @@ -374,7 +377,7 @@ func GenerateDeploymentTemplate( envvars := []corev1.EnvVar{ { Name: "LAGOON_GIT_SHA", - Value: buildValues.GitSha, + Value: buildValues.GitSHA, }, { Name: "CRONJOBS", @@ -475,12 +478,16 @@ func GenerateDeploymentTemplate( // handle setting the rest of the containers specs with values from the service or build values linkedContainer.Container.Name = linkedContainer.Name - linkedContainer.Container.Image = serviceValues.LinkedService.ImageName + if val, ok := buildValues.ImageReferences[serviceValues.LinkedService.Name]; ok { + linkedContainer.Container.Image = val + } else { + return nil, fmt.Errorf("no image reference was found for secondary container %s of service %s", serviceValues.LinkedService.Name, serviceValues.Name) + } envvars := []corev1.EnvVar{ { Name: "LAGOON_GIT_SHA", - Value: buildValues.GitSha, + Value: buildValues.GitSHA, }, } for _, envvar := range envvars { diff --git a/internal/templating/services/templates_deployment_test.go b/internal/templating/services/templates_deployment_test.go index 4b21f480..4a352efe 100644 --- a/internal/templating/services/templates_deployment_test.go +++ b/internal/templating/services/templates_deployment_test.go @@ -40,15 +40,21 @@ func TestGenerateDeploymentTemplate(t *testing.T) { Name: "lagoon-internal-registry-secret", }, }, - GitSha: "0", + GitSHA: "0", ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", + "myservice-po": "harbor.example.com/example-project/environment-name/myservice-po@latest", + "myservice-persist": "harbor.example.com/example-project/environment-name/myservice-persist@latest", + "myservice-persist-po": "harbor.example.com/example-project/environment-name/myservice-persist-po@latest", + "myservice-persist-posize": "harbor.example.com/example-project/environment-name/myservice-persist-posize@latest", + }, Services: []generator.ServiceValues{ { Name: "myservice", OverrideName: "myservice", Type: "basic", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/myservice@latest", InPodCronjobs: []lagoon.Cronjob{ { Name: "cron - inpod", @@ -77,7 +83,6 @@ func TestGenerateDeploymentTemplate(t *testing.T) { OverrideName: "myservice-po", Type: "basic", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/myservice-po@latest", ServicePort: 8080, // template should have port changed to 8080 from 3000 UseSpotInstances: true, // template should have spot instance label and toleration/selector/affinity Replicas: 2, @@ -100,8 +105,8 @@ func TestGenerateDeploymentTemplate(t *testing.T) { PersistentVolumeName: "basic", }, { - Name: "myservice-persist-po", - OverrideName: "myservice-persist-po", + Name: "myservice-persist-posize", + OverrideName: "myservice-persist-posize", Type: "basic-persistent", DBaaSEnvironment: "production", ServicePort: 8080, @@ -139,29 +144,32 @@ func TestGenerateDeploymentTemplate(t *testing.T) { RunAsUser: 10000, FsGroup: 10001, }, - GitSha: "0", + GitSHA: "0", ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "nginx": "harbor.example.com/example-project/environment-name/nginx@latest", + "php": "harbor.example.com/example-project/environment-name/php@latest", + "nginx2": "harbor.example.com/example-project/environment-name/nginx2@latest", + "php2": "harbor.example.com/example-project/environment-name/php2@latest", + }, Services: []generator.ServiceValues{ { Name: "nginx", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", }, { Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, { Name: "nginx2", OverrideName: "nginx-2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/nginx2@latest", PersistentVolumePath: "/storage/data", PersistentVolumeName: "nginx2", }, @@ -170,7 +178,6 @@ func TestGenerateDeploymentTemplate(t *testing.T) { OverrideName: "nginx-2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/php2@latest", PersistentVolumeSize: "10Gi", PersistentVolumePath: "/storage/data", PersistentVolumeName: "nginx2", @@ -197,22 +204,24 @@ func TestGenerateDeploymentTemplate(t *testing.T) { Name: "lagoon-internal-registry-secret", }, }, - GitSha: "0", + GitSHA: "0", ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", + "myservice-persist": "harbor.example.com/example-project/environment-name/myservice-persist@latest", + }, Services: []generator.ServiceValues{ { Name: "myservice", OverrideName: "myservice", Type: "cli", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/myservice@latest", }, { Name: "myservice-persist", OverrideName: "myservice-persist", Type: "cli-persistent", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/myservice-persistent@latest", PersistentVolumePath: "/storage/data", PersistentVolumeName: "nginx-php", }, @@ -238,6 +247,11 @@ func TestGenerateDeploymentTemplate(t *testing.T) { Name: "lagoon-internal-registry-secret", }, }, + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", + }, Services: []generator.ServiceValues{ { Name: "myservice", @@ -262,6 +276,17 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", + "myservice-size": "harbor.example.com/example-project/environment-name/myservice-size@latest", + }, Services: []generator.ServiceValues{ { Name: "myservice", @@ -294,6 +319,17 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", + "myservice-size": "harbor.example.com/example-project/environment-name/myservice-size@latest", + }, Services: []generator.ServiceValues{ { Name: "myservice", @@ -331,15 +367,17 @@ func TestGenerateDeploymentTemplate(t *testing.T) { Name: "lagoon-internal-registry-secret", }, }, - GitSha: "0", + GitSHA: "0", ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "myservice-po": "harbor.example.com/example-project/environment-name/myservice-po@latest", + }, Services: []generator.ServiceValues{ { Name: "myservice-po", OverrideName: "myservice-po", Type: "basic", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/myservice-po@latest", AdditionalServicePorts: []generator.AdditionalServicePort{ { ServiceName: "myservice-po-8191", @@ -381,6 +419,11 @@ func TestGenerateDeploymentTemplate(t *testing.T) { Name: "lagoon-internal-registry-secret", }, }, + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "solr": "harbor.example.com/example-project/environment-name/solr@latest", + }, Services: []generator.ServiceValues{ { Name: "solr", @@ -419,15 +462,17 @@ func TestGenerateDeploymentTemplate(t *testing.T) { EphemeralStorage: "1Gi", }, }, - GitSha: "0", + GitSHA: "0", ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "myservice-po": "harbor.example.com/example-project/environment-name/myservice-po@latest", + }, Services: []generator.ServiceValues{ { Name: "myservice-po", OverrideName: "myservice-po", Type: "basic", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/myservice-po@latest", AdditionalServicePorts: []generator.AdditionalServicePort{ { ServiceName: "myservice-po-8191", @@ -479,29 +524,32 @@ func TestGenerateDeploymentTemplate(t *testing.T) { FsGroup: 10001, OnRootMismatch: true, }, - GitSha: "0", + GitSHA: "0", ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "nginx": "harbor.example.com/example-project/environment-name/nginx@latest", + "php": "harbor.example.com/example-project/environment-name/php@latest", + "nginx2": "harbor.example.com/example-project/environment-name/nginx2@latest", + "php2": "harbor.example.com/example-project/environment-name/php2@latest", + }, Services: []generator.ServiceValues{ { Name: "nginx", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", }, { Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, { Name: "nginx2", OverrideName: "nginx-2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/nginx2@latest", PersistentVolumePath: "/storage/data", PersistentVolumeName: "nginx2", }, @@ -510,7 +558,6 @@ func TestGenerateDeploymentTemplate(t *testing.T) { OverrideName: "nginx-2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/php2@latest", PersistentVolumeSize: "10Gi", PersistentVolumePath: "/storage/data", PersistentVolumeName: "nginx2", @@ -567,14 +614,14 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + // ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", }, { Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/php@latest", + // ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, }, }, @@ -584,13 +631,13 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + // ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", LinkedService: &generator.ServiceValues{ Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/php@latest", + // ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, }, }, @@ -604,28 +651,28 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + // ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", }, { Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/php@latest", + // ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, { Name: "nginx2", OverrideName: "nginx2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/nginx2@latest", + // ImageName: "harbor.example.com/example-project/environment-name/nginx2@latest", }, { Name: "php2", OverrideName: "nginx2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/php2@latest", + // ImageName: "harbor.example.com/example-project/environment-name/php2@latest", }, }, }, @@ -635,13 +682,13 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + // ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", LinkedService: &generator.ServiceValues{ Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/php@latest", + // ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, }, { @@ -649,13 +696,13 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "nginx2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/nginx2@latest", + // ImageName: "harbor.example.com/example-project/environment-name/nginx2@latest", LinkedService: &generator.ServiceValues{ Name: "php2", OverrideName: "nginx2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/php2@latest", + // ImageName: "harbor.example.com/example-project/environment-name/php2@latest", }, }, }, @@ -669,21 +716,21 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + // ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", }, { Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/php@latest", + // ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, { Name: "normalnginx", OverrideName: "normalnginx", Type: "nginx", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/normalnginx@latest", + // ImageName: "harbor.example.com/example-project/environment-name/normalnginx@latest", }, }, }, @@ -693,20 +740,20 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "normalnginx", Type: "nginx", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/normalnginx@latest", + // ImageName: "harbor.example.com/example-project/environment-name/normalnginx@latest", }, { Name: "nginx", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", + // ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", LinkedService: &generator.ServiceValues{ Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - ImageName: "harbor.example.com/example-project/environment-name/php@latest", + // ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, }, }, diff --git a/internal/templating/services/test-resources/deployment/result-basic-1.yaml b/internal/templating/services/test-resources/deployment/result-basic-1.yaml index c0979386..a77b868b 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-1.yaml @@ -230,6 +230,7 @@ spec: envFrom: - configMapRef: name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice-persist@latest livenessProbe: initialDelaySeconds: 60 tcpSocket: @@ -315,6 +316,7 @@ spec: envFrom: - configMapRef: name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice-persist-po@latest livenessProbe: initialDelaySeconds: 60 tcpSocket: @@ -355,22 +357,22 @@ metadata: lagoon.sh/version: v2.x.x creationTimestamp: null labels: - app.kubernetes.io/instance: myservice-persist-po + app.kubernetes.io/instance: myservice-persist-posize app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: basic-persistent lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project - lagoon.sh/service: myservice-persist-po + lagoon.sh/service: myservice-persist-posize lagoon.sh/service-type: basic-persistent lagoon.sh/template: basic-persistent-0.1.0 - name: myservice-persist-po + name: myservice-persist-posize spec: replicas: 1 selector: matchLabels: - app.kubernetes.io/instance: myservice-persist-po + app.kubernetes.io/instance: myservice-persist-posize app.kubernetes.io/name: basic-persistent strategy: {} template: @@ -381,14 +383,14 @@ spec: lagoon.sh/version: v2.x.x creationTimestamp: null labels: - app.kubernetes.io/instance: myservice-persist-po + app.kubernetes.io/instance: myservice-persist-posize app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: basic-persistent lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project - lagoon.sh/service: myservice-persist-po + lagoon.sh/service: myservice-persist-posize lagoon.sh/service-type: basic-persistent lagoon.sh/template: basic-persistent-0.1.0 spec: @@ -400,6 +402,7 @@ spec: envFrom: - configMapRef: name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice-persist-posize@latest livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/templating/services/test-resources/deployment/result-cli-1.yaml b/internal/templating/services/test-resources/deployment/result-cli-1.yaml index cbb22958..44a9f20a 100644 --- a/internal/templating/services/test-resources/deployment/result-cli-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-cli-1.yaml @@ -136,7 +136,7 @@ spec: envFrom: - configMapRef: name: lagoon-env - image: harbor.example.com/example-project/environment-name/myservice-persistent@latest + image: harbor.example.com/example-project/environment-name/myservice-persist@latest name: cli readinessProbe: exec: diff --git a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml index d9240d02..61688784 100644 --- a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml @@ -32,7 +32,7 @@ spec: ." k8up.syn.tools/file-extension: .myservice.tar lagoon.sh/branch: environment-name - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -50,16 +50,20 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: "0" - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice@latest name: elasticsearch resources: {} volumeMounts: - mountPath: /usr/share/elasticsearch/data name: myservice enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret initContainers: - command: - sh @@ -118,7 +122,7 @@ spec: ." k8up.syn.tools/file-extension: .myservice-size.tar lagoon.sh/branch: environment-name - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -136,16 +140,20 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: "0" - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice-size@latest name: elasticsearch resources: {} volumeMounts: - mountPath: /usr/share/elasticsearch/data name: myservice-size enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret initContainers: - command: - sh diff --git a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml index b0cebda0..e417e1bd 100644 --- a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml @@ -32,7 +32,7 @@ spec: ." k8up.syn.tools/file-extension: .myservice.tar lagoon.sh/branch: environment-name - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -50,16 +50,20 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: "0" - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice@latest name: opensearch resources: {} volumeMounts: - mountPath: /usr/share/opensearch/data name: myservice enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret initContainers: - command: - sh @@ -118,7 +122,7 @@ spec: ." k8up.syn.tools/file-extension: .myservice-size.tar lagoon.sh/branch: environment-name - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -136,16 +140,20 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: "0" - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice-size@latest name: opensearch resources: {} volumeMounts: - mountPath: /usr/share/opensearch/data name: myservice-size enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret initContainers: - command: - sh diff --git a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml index b7701094..ece1e969 100644 --- a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml @@ -34,7 +34,7 @@ spec: --format=t -w" k8up.syn.tools/file-extension: .myservice.tar lagoon.sh/branch: environment-name - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -52,10 +52,12 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: "0" - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env + image: harbor.example.com/example-project/environment-name/myservice@latest livenessProbe: initialDelaySeconds: 120 periodSeconds: 5 diff --git a/internal/templating/services/test-resources/deployment/result-solr-1.yaml b/internal/templating/services/test-resources/deployment/result-solr-1.yaml index 6fb57ab1..457cdc34 100644 --- a/internal/templating/services/test-resources/deployment/result-solr-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-solr-1.yaml @@ -32,7 +32,7 @@ spec: . || [ $? -eq 1 ]' k8up.syn.tools/file-extension: .solr.tar lagoon.sh/branch: environment-name - lagoon.sh/configMapSha: "" + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x creationTimestamp: null labels: @@ -50,10 +50,12 @@ spec: containers: - env: - name: LAGOON_GIT_SHA + value: "0" - name: CRONJOBS envFrom: - configMapRef: name: lagoon-env + image: harbor.example.com/example-project/environment-name/solr@latest livenessProbe: failureThreshold: 5 initialDelaySeconds: 90 From 5070fac7474743b6210a9139b5db3b516e4cdf9b Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 12 Jan 2024 12:50:17 +1100 Subject: [PATCH 51/92] refactor: main commands to use refactoring done with generator --- .gitignore | 2 +- cmd/identify_feature.go | 2 +- cmd/identify_feature_test.go | 8 +- cmd/identify_imagebuild.go | 71 +++++ cmd/identify_imagebuild_test.go | 458 +++++++++++++++++++++++++++ cmd/identify_ingress_test.go | 48 +-- cmd/identify_lagoonservices.go | 15 +- cmd/identify_lagoonservices_test.go | 34 +- cmd/identify_native_cronjobs_test.go | 20 +- cmd/tasks_run.go | 4 +- cmd/template_autogen_ingress_test.go | 58 ++-- cmd/template_backups_test.go | 20 +- cmd/template_dbaas_test.go | 2 +- cmd/template_ingress_test.go | 50 +-- cmd/template_lagoonservices.go | 9 +- cmd/template_lagoonservices_test.go | 78 +++-- docs/buildrequirements.md | 2 +- go.mod | 1 + go.sum | 2 + 19 files changed, 732 insertions(+), 152 deletions(-) create mode 100644 cmd/identify_imagebuild.go create mode 100644 cmd/identify_imagebuild_test.go diff --git a/.gitignore b/.gitignore index 403d6213..572906cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .idea -test-resources/output +testoutput diff --git a/cmd/identify_feature.go b/cmd/identify_feature.go index f3d17261..c04ff2fa 100644 --- a/cmd/identify_feature.go +++ b/cmd/identify_feature.go @@ -40,7 +40,7 @@ func IdentifyFeatureFlag(g generator.GeneratorInput, name string) (string, error if forceFlagVar != "" { return forceFlagVar, nil } - featureFlagVar, _ := lagoon.GetLagoonVariable(fmt.Sprintf("%s%s", "LAGOON_FEATURE_FLAG_", name), []string{"build", "global"}, *lagoonBuild.LagoonEnvironmentVariables) + featureFlagVar, _ := lagoon.GetLagoonVariable(fmt.Sprintf("%s%s", "LAGOON_FEATURE_FLAG_", name), []string{"build", "global"}, lagoonBuild.BuildValues.EnvironmentVariables) if featureFlagVar != nil { return featureFlagVar.Value, nil } diff --git a/cmd/identify_feature_test.go b/cmd/identify_feature_test.go index 1f26a422..54d4791e 100644 --- a/cmd/identify_feature_test.go +++ b/cmd/identify_feature_test.go @@ -63,7 +63,7 @@ func TestIdentifyFeatureFlag(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "enabled", }, { @@ -83,7 +83,7 @@ func TestIdentifyFeatureFlag(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "enabled", }, { @@ -96,7 +96,7 @@ func TestIdentifyFeatureFlag(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", vars: []helpers.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_FORCE_ROOTLESS_WORKLOAD", @@ -115,7 +115,7 @@ func TestIdentifyFeatureFlag(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", vars: []helpers.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_FORCE_ROOTLESS_WORKLOAD", diff --git a/cmd/identify_imagebuild.go b/cmd/identify_imagebuild.go new file mode 100644 index 00000000..057b2615 --- /dev/null +++ b/cmd/identify_imagebuild.go @@ -0,0 +1,71 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + generator "github.com/uselagoon/build-deploy-tool/internal/generator" +) + +var imageBuildIdentify = &cobra.Command{ + Use: "image-build", + Aliases: []string{"ib"}, + Short: "Identify the configuration for building images for a Lagoon build", + RunE: func(cmd *cobra.Command, args []string) error { + gen, err := generator.GenerateInput(*rootCmd, true) + if err != nil { + return err + } + out, err := ImageBuildConfigurationIdentification(gen) + if err != nil { + return err + } + fmt.Println(out) + return nil + }, +} + +type imageBuild struct { + BuildKit bool `json:"buildKit"` + Images []imageBuilds `json:"images"` + BuildArguments map[string]string `json:"buildArguments"` +} + +type imageBuilds struct { + Name string `json:"name"` + ImageBuild generator.ImageBuild `json:"imageBuild"` +} + +// ImageBuildConfigurationIdentification takes the output of the generator and turns it into a JSON payload +// that can be used by the legacy bash to build container images. This payload contains the buildkit flag if it was as part of the build +// but it also provides all the container contexts and dockerfile paths that can be passed to the build command +// this includes the: +// * temporary image name (namespace-service) +// * the push image name (registry/project/environment/service:latest) +// * the pull through image, if there is no dockerfile +// * eventually other information like build args etc +func ImageBuildConfigurationIdentification(g generator.GeneratorInput) (imageBuild, error) { + + lServices := imageBuild{} + lagoonBuild, err := generator.NewGenerator( + g, + ) + if err != nil { + return lServices, err + } + lServices.BuildKit = lagoonBuild.BuildValues.DockerBuildKit + lServices.BuildArguments = lagoonBuild.BuildValues.ImageBuildArguments + for _, service := range lagoonBuild.BuildValues.Services { + if service.ImageBuild != nil { + lServices.Images = append(lServices.Images, imageBuilds{ + Name: service.Name, + ImageBuild: *service.ImageBuild, + }) + } + } + return lServices, nil +} + +func init() { + identifyCmd.AddCommand(imageBuildIdentify) +} diff --git a/cmd/identify_imagebuild_test.go b/cmd/identify_imagebuild_test.go new file mode 100644 index 00000000..57be5a76 --- /dev/null +++ b/cmd/identify_imagebuild_test.go @@ -0,0 +1,458 @@ +package cmd + +import ( + "encoding/json" + "os" + "testing" + + "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" + "github.com/uselagoon/build-deploy-tool/internal/generator" + "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/lagoon" + "github.com/uselagoon/build-deploy-tool/internal/testdata" + + // changes the testing to source from root so paths to test resources must be defined from repo root + _ "github.com/uselagoon/build-deploy-tool/internal/testing" +) + +func TestImageBuildConfigurationIdentification(t *testing.T) { + tests := []struct { + name string + description string + args testdata.TestData + want imageBuild + }{ + { + name: "test1 basic deployment", + args: testdata.GetSeedData( + testdata.TestData{ + Namespace: "example-project-main", + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "internal/testdata/basic/lagoon.yml", + }, true), + want: imageBuild{ + BuildKit: false, + BuildArguments: map[string]string{ + "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", + "LAGOON_PROJECT": "example-project", + "LAGOON_ENVIRONMENT": "main", + "LAGOON_ENVIRONMENT_TYPE": "production", + "LAGOON_BUILD_TYPE": "branch", + "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", + "LAGOON_KUBERNETES": "remote-cluster1", + "LAGOON_GIT_SHA": "abcdefg123456", + "LAGOON_GIT_BRANCH": "main", + "NODE_IMAGE": "example-project-main-node", + }, + Images: []imageBuilds{ + { + Name: "node", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/node:latest", + Context: "internal/testdata/basic/docker", + DockerFile: "basic.dockerfile", + TemporaryImage: "example-project-main-node", + }, + }, + }, + }, + }, + { + name: "test2a nginx-php deployment", + args: testdata.GetSeedData( + testdata.TestData{ + Namespace: "example-project-main", + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", + }, true), + want: imageBuild{ + BuildKit: false, + BuildArguments: map[string]string{ + "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", + "LAGOON_PROJECT": "example-project", + "LAGOON_ENVIRONMENT": "main", + "LAGOON_ENVIRONMENT_TYPE": "production", + "LAGOON_BUILD_TYPE": "branch", + "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", + "LAGOON_KUBERNETES": "remote-cluster1", + "LAGOON_GIT_SHA": "abcdefg123456", + "LAGOON_GIT_BRANCH": "main", + "CLI_IMAGE": "example-project-main-cli", + "NGINX_IMAGE": "example-project-main-nginx", + "PHP_IMAGE": "example-project-main-php", + }, + Images: []imageBuilds{ + { + Name: "cli", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/cli:latest", + Context: "internal/testdata/complex/docker", + DockerFile: ".docker/Dockerfile.cli", + TemporaryImage: "example-project-main-cli", + }, + }, { + Name: "nginx", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/nginx:latest", + Context: "internal/testdata/complex/docker", + DockerFile: ".docker/Dockerfile.nginx-drupal", + TemporaryImage: "example-project-main-nginx", + }, + }, { + Name: "php", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/php:latest", + Context: "internal/testdata/complex/docker", + DockerFile: ".docker/Dockerfile.php", + TemporaryImage: "example-project-main-php", + }, + }, { + Name: "redis", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/redis:latest", + PullImage: "amazeeio/redis", + }, + }, { + Name: "varnish", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/varnish:latest", + PullImage: "uselagoon/varnish-5-drupal:latest", + }, + }, + }, + }, + }, + { + name: "test2b nginx-php deployment - rootless", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", + ImageReferences: map[string]string{ + "nginx": "harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "php": "harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "cli": "harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "redis": "harbor.example/example-project/main/redis@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "varnish": "harbor.example/example-project/main/varnish@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + }, + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", + Value: "enabled", + Scope: "build", + }, + }, + }, true), + want: imageBuild{ + BuildKit: false, + BuildArguments: map[string]string{ + "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD": "enabled", + "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", + "LAGOON_PROJECT": "example-project", + "LAGOON_ENVIRONMENT": "main", + "LAGOON_ENVIRONMENT_TYPE": "production", + "LAGOON_BUILD_TYPE": "branch", + "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", + "LAGOON_KUBERNETES": "remote-cluster1", + "LAGOON_GIT_SHA": "abcdefg123456", + "LAGOON_GIT_BRANCH": "main", + "CLI_IMAGE": "example-project-main-cli", + "NGINX_IMAGE": "example-project-main-nginx", + "PHP_IMAGE": "example-project-main-php", + }, + Images: []imageBuilds{ + { + Name: "cli", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/cli:latest", + Context: "internal/testdata/complex/docker", + DockerFile: ".docker/Dockerfile.cli", + TemporaryImage: "example-project-main-cli", + }, + }, { + Name: "nginx", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/nginx:latest", + Context: "internal/testdata/complex/docker", + DockerFile: ".docker/Dockerfile.nginx-drupal", + TemporaryImage: "example-project-main-nginx", + }, + }, { + Name: "php", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/php:latest", + Context: "internal/testdata/complex/docker", + DockerFile: ".docker/Dockerfile.php", + TemporaryImage: "example-project-main-php", + }, + }, { + Name: "redis", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/redis:latest", + PullImage: "amazeeio/redis", + }, + }, { + Name: "varnish", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/varnish:latest", + PullImage: "uselagoon/varnish-5-drupal:latest", + }, + }, + }, + }, + }, + { + name: "test3 - funky pvcs", + description: "only create pvcs of the requested persistent-name in the docker-compose file", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "internal/testdata/basic/lagoon.thunderhub.yml", + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", + Value: "enabled", + Scope: "build", + }, + }, + }, true), + want: imageBuild{ + BuildKit: false, + BuildArguments: map[string]string{ + "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD": "enabled", + "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", + "LAGOON_PROJECT": "example-project", + "LAGOON_ENVIRONMENT": "main", + "LAGOON_ENVIRONMENT_TYPE": "production", + "LAGOON_BUILD_TYPE": "branch", + "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", + "LAGOON_KUBERNETES": "remote-cluster1", + "LAGOON_GIT_SHA": "abcdefg123456", + "LAGOON_GIT_BRANCH": "main", + "LND_IMAGE": "example-project-main-lnd", + "THUNDERHUB_IMAGE": "example-project-main-thunderhub", + "TOR_IMAGE": "example-project-main-tor", + }, + Images: []imageBuilds{ + { + Name: "lnd", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/lnd:latest", + Context: "internal/testdata/basic/docker", + DockerFile: "Dockerfile", + TemporaryImage: "example-project-main-lnd", + }, + }, { + Name: "thunderhub", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/thunderhub:latest", + Context: "internal/testdata/basic/docker", + DockerFile: "Dockerfile", + TemporaryImage: "example-project-main-thunderhub", + }, + }, { + Name: "tor", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/tor:latest", + Context: "internal/testdata/basic/docker", + DockerFile: "Dockerfile", + TemporaryImage: "example-project-main-tor", + }, + }, + }, + }, + }, + { + name: "test4 - basic-persistent with worker-persistent with buildkit", + description: "create a basic-persistent that gets a pvc and mount that volume on a worker-persistent type", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "internal/testdata/basic/lagoon.thunderhub-2.yml", + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", + Value: "enabled", + Scope: "build", + }, + { + Name: "DOCKER_BUILDKIT", + Value: "true", + Scope: "build", + }, + }, + }, true), + want: imageBuild{ + BuildKit: true, + BuildArguments: map[string]string{ + "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD": "enabled", + "DOCKER_BUILDKIT": "true", + "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", + "LAGOON_PROJECT": "example-project", + "LAGOON_ENVIRONMENT": "main", + "LAGOON_ENVIRONMENT_TYPE": "production", + "LAGOON_BUILD_TYPE": "branch", + "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", + "LAGOON_KUBERNETES": "remote-cluster1", + "LAGOON_GIT_SHA": "abcdefg123456", + "LAGOON_GIT_BRANCH": "main", + "LND_IMAGE": "example-project-main-lnd", + "TOR_IMAGE": "example-project-main-tor", + }, + Images: []imageBuilds{ + { + Name: "lnd", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/lnd:latest", + Context: "internal/testdata/basic/docker", + DockerFile: "Dockerfile", + TemporaryImage: "example-project-main-lnd", + }, + }, { + Name: "tor", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/tor:latest", + Context: "internal/testdata/basic/docker", + DockerFile: "Dockerfile", + TemporaryImage: "example-project-main-tor", + }, + }, + }, + }, + }, + { + name: "test5 basic deployment promote", + args: testdata.GetSeedData( + testdata.TestData{ + Namespace: "example-project-main", + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + BuildType: "promote", + LagoonYAML: "internal/testdata/basic/lagoon.yml", + }, true), + want: imageBuild{ + BuildKit: false, + BuildArguments: map[string]string{ + "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", + "LAGOON_PROJECT": "example-project", + "LAGOON_ENVIRONMENT": "main", + "LAGOON_ENVIRONMENT_TYPE": "production", + "LAGOON_BUILD_TYPE": "promote", + "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", + "LAGOON_KUBERNETES": "remote-cluster1", + "NODE_IMAGE": "example-project-main-node", + }, + Images: []imageBuilds{ + { + Name: "node", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/node:latest", + PromoteImage: "harbor.example/example-project/promote-main/node:latest", + Context: "internal/testdata/basic/docker", + DockerFile: "basic.dockerfile", + TemporaryImage: "example-project-main-node", + }, + }, + }, + }, + }, + { + name: "test6 basic deployment pr", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "pr-123", + BuildType: "pullrequest", + PRNumber: "123", + PRHeadBranch: "pr-head", + PRBaseBranch: "pr-base", + PRHeadSHA: "123456", + PRBaseSHA: "abcdef", + LagoonYAML: "internal/testdata/basic/lagoon.yml", + ImageReferences: map[string]string{ + "node": "harbor.example/example-project/pr-123/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + }, + }, true), + want: imageBuild{ + BuildKit: false, + BuildArguments: map[string]string{ + "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", + "LAGOON_PROJECT": "example-project", + "LAGOON_ENVIRONMENT": "pr-123", + "LAGOON_ENVIRONMENT_TYPE": "production", + "LAGOON_BUILD_TYPE": "pullrequest", + "LAGOON_PR_BASE_BRANCH": "pr-base", + "LAGOON_PR_BASE_SHA": "abcdef", + "LAGOON_PR_HEAD_BRANCH": "pr-head", + "LAGOON_PR_HEAD_SHA": "123456", + "LAGOON_PR_NUMBER": "123", + "LAGOON_PR_TITLE": "123", + "LAGOON_GIT_SHA": "abcdefg123456", + "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", + "LAGOON_KUBERNETES": "remote-cluster1", + "NODE_IMAGE": "example-project-pr-123-node", + }, + Images: []imageBuilds{ + { + Name: "node", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/pr-123/node:latest", + Context: "internal/testdata/basic/docker", + DockerFile: "basic.dockerfile", + TemporaryImage: "example-project-pr-123-node", + }, + }, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // set the environment variables from args + savedTemplates := "testoutput" + generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) + if err != nil { + t.Errorf("%v", err) + } + + err = os.MkdirAll(savedTemplates, 0755) + if err != nil { + t.Errorf("couldn't create directory %v: %v", savedTemplates, err) + } + + defer os.RemoveAll(savedTemplates) + + ts := dbaasclient.TestDBaaSHTTPServer() + defer ts.Close() + err = os.Setenv("DBAAS_OPERATOR_HTTP", ts.URL) + if err != nil { + t.Errorf("%v", err) + } + + out, err := ImageBuildConfigurationIdentification(generator) + if err != nil { + t.Errorf("%v", err) + } + + oJ, _ := json.Marshal(out) + wJ, _ := json.Marshal(tt.want) + if string(oJ) != string(wJ) { + t.Errorf("returned output %v doesn't match want %v", string(oJ), string(wJ)) + } + t.Cleanup(func() { + helpers.UnsetEnvVars(nil) + }) + }) + } +} diff --git a/cmd/identify_ingress_test.go b/cmd/identify_ingress_test.go index 9eb7488b..907ebd58 100644 --- a/cmd/identify_ingress_test.go +++ b/cmd/identify_ingress_test.go @@ -38,7 +38,7 @@ func TestIdentifyRoute(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://example.com", wantRemain: []string{"https://node-example-project-main.example.com", "https://example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, @@ -60,7 +60,7 @@ func TestIdentifyRoute(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://example.com", wantRemain: []string{"https://node-example-project-main.example.com", "https://example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, @@ -82,7 +82,7 @@ func TestIdentifyRoute(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://example.com", wantRemain: []string{"https://node-example-project-main.example.com", "https://example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, @@ -97,7 +97,7 @@ func TestIdentifyRoute(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://example.com", wantRemain: []string{"https://node-example-project-main.example.com", "https://example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, @@ -112,7 +112,7 @@ func TestIdentifyRoute(t *testing.T) { Branch: "multiproject", LagoonYAML: "internal/testdata/node/lagoon.polysite.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://multiproject1.com", wantRemain: []string{"https://node-multiproject1-multiproject.example.com", "https://multiproject1.com"}, wantautoGen: []string{"https://node-multiproject1-multiproject.example.com"}, @@ -127,7 +127,7 @@ func TestIdentifyRoute(t *testing.T) { Branch: "multiproject", LagoonYAML: "internal/testdata/node/lagoon.polysite.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://multiproject2.com", wantRemain: []string{"https://node-multiproject2-multiproject.example.com", "https://multiproject2.com"}, wantautoGen: []string{"https://node-multiproject2-multiproject.example.com"}, @@ -142,7 +142,7 @@ func TestIdentifyRoute(t *testing.T) { Branch: "tworoutes", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://example.com", wantRemain: []string{"https://node-example-project-tworoutes.example.com", "https://example.com", "https://www.example.com"}, wantautoGen: []string{"https://node-example-project-tworoutes.example.com"}, @@ -157,7 +157,7 @@ func TestIdentifyRoute(t *testing.T) { Branch: "branch/routes", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://customdomain-will-be-main-domain.com", wantRemain: []string{"https://node-example-project-branch-routes.example.com", "https://customdomain-will-be-main-domain.com", "https://customdomain-will-be-not-be-main-domain.com"}, wantautoGen: []string{"https://node-example-project-branch-routes.example.com"}, @@ -174,7 +174,7 @@ func TestIdentifyRoute(t *testing.T) { StandbyEnvironment: "main-sb", LagoonYAML: "internal/testdata/node/lagoon.activestandby.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://active.example.com", wantRemain: []string{"https://node-example-project-main.example.com", "https://main.example.com", "https://active.example.com"}, wantautoGen: []string{"https://node-example-project-main.example.com"}, @@ -191,7 +191,7 @@ func TestIdentifyRoute(t *testing.T) { StandbyEnvironment: "main-sb", LagoonYAML: "internal/testdata/node/lagoon.activestandby.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://standby.example.com", wantRemain: []string{"https://node-example-project-main-sb.example.com", "https://main-sb.example.com", "https://standby.example.com"}, wantautoGen: []string{"https://node-example-project-main-sb.example.com"}, @@ -206,7 +206,7 @@ func TestIdentifyRoute(t *testing.T) { Branch: "no-ingress", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://node-example-project-no-ingress.example.com", wantRemain: []string{"https://node-example-project-no-ingress.example.com"}, wantautoGen: []string{"https://node-example-project-no-ingress.example.com"}, @@ -221,7 +221,7 @@ func TestIdentifyRoute(t *testing.T) { Branch: "no-ingress", LagoonYAML: "internal/testdata/node/lagoon.autogen-prefixes-1.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://node-example-project-no-ingress.example.com", wantRemain: []string{ "https://node-example-project-no-ingress.example.com", @@ -248,7 +248,7 @@ func TestIdentifyRoute(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/node/lagoon.autogen-1.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://example.com", wantRemain: []string{"https://example.com"}, wantautoGen: []string{}, @@ -263,7 +263,7 @@ func TestIdentifyRoute(t *testing.T) { Branch: "notmain", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://node-example-project-notmain.example.com", wantRemain: []string{"https://node-example-project-notmain.example.com"}, wantautoGen: []string{"https://node-example-project-notmain.example.com"}, @@ -286,7 +286,7 @@ func TestIdentifyRoute(t *testing.T) { }, }, }, false), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://nginx-sales-customer-support-develop.ex1.example-web.com", wantRemain: []string{"https://nginx-sales-customer-support-develop.ex1.example-web.com"}, wantautoGen: []string{"https://nginx-sales-customer-support-develop.ex1.example-web.com"}, @@ -309,7 +309,7 @@ func TestIdentifyRoute(t *testing.T) { }, }, }, false), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://nginx-php.feature-migration.content-example-com.example.com", wantRemain: []string{"https://nginx-php.feature-migration.content-example-com.example.com"}, wantautoGen: []string{"https://nginx-php.feature-migration.content-example-com.example.com"}, @@ -324,7 +324,7 @@ func TestIdentifyRoute(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/complex/lagoon.small-2.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://nginx-example-project-main.example.com", wantRemain: []string{"https://nginx-example-project-main.example.com", "https://varnish-example-project-main.example.com"}, wantautoGen: []string{"https://nginx-example-project-main.example.com", "https://varnish-example-project-main.example.com"}, @@ -339,7 +339,7 @@ func TestIdentifyRoute(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/complex/lagoon.complex-2.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "https://wild.example.com", wantRemain: []string{"https://nginx-example-project-main.example.com", "https://wild.example.com", "https://alt.example.com", "https://www.example.com", "https://en.example.com"}, wantautoGen: []string{"https://nginx-example-project-main.example.com"}, @@ -427,7 +427,7 @@ func TestCreatedIngressIdentification(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/node/lagoon.autogen-1.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", wantRemain: []string{"example.com"}, wantautoGen: []string{}, wantJSON: `{"primary":"","secondary":["example.com"],"autogenerated":[]}`, @@ -441,7 +441,7 @@ func TestCreatedIngressIdentification(t *testing.T) { Branch: "notmain", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", wantRemain: []string{}, wantautoGen: []string{"node"}, wantJSON: `{"primary":"","secondary":[],"autogenerated":["node"]}`, @@ -463,7 +463,7 @@ func TestCreatedIngressIdentification(t *testing.T) { }, }, }, false), - templatePath: "test-resources/output", + templatePath: "testoutput", wantRemain: []string{}, wantautoGen: []string{"nginx"}, wantJSON: `{"primary":"","secondary":[],"autogenerated":["nginx"]}`, @@ -485,7 +485,7 @@ func TestCreatedIngressIdentification(t *testing.T) { }, }, }, false), - templatePath: "test-resources/output", + templatePath: "testoutput", wantRemain: []string{}, wantautoGen: []string{"nginx-php"}, wantJSON: `{"primary":"","secondary":[],"autogenerated":["nginx-php"]}`, @@ -499,7 +499,7 @@ func TestCreatedIngressIdentification(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/complex/lagoon.small-2.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", wantRemain: []string{}, wantautoGen: []string{"nginx", "varnish"}, wantJSON: `{"primary":"","secondary":[],"autogenerated":["nginx","varnish"]}`, @@ -513,7 +513,7 @@ func TestCreatedIngressIdentification(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/complex/lagoon.complex-2.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", wantRemain: []string{"wildcard-wild.example.com", "alt.example.com"}, wantautoGen: []string{"nginx"}, wantJSON: `{"primary":"","secondary":["wildcard-wild.example.com","alt.example.com"],"autogenerated":["nginx"]}`, diff --git a/cmd/identify_lagoonservices.go b/cmd/identify_lagoonservices.go index f8cd0161..b88ff617 100644 --- a/cmd/identify_lagoonservices.go +++ b/cmd/identify_lagoonservices.go @@ -41,8 +41,13 @@ var lagoonServiceIdentify = &cobra.Command{ var imageRefs struct { Images map[string]string `json:"images"` } - imagesStr, _ := base64.StdEncoding.DecodeString(images) - json.Unmarshal(imagesStr, &imageRefs) + imagesStr, err := base64.StdEncoding.DecodeString(images) + if err != nil { + return fmt.Errorf("error decoding images payload: %v", err) + } + if err := json.Unmarshal(imagesStr, &imageRefs); err != nil { + return fmt.Errorf("error unmarshalling images payload: %v", err) + } gen.ImageReferences = imageRefs.Images out, err := LagoonServiceTemplateIdentification(gen) if err != nil { @@ -53,7 +58,10 @@ var lagoonServiceIdentify = &cobra.Command{ }, } -// LagoonServiceTemplateIdentification . +// LagoonServiceTemplateIdentification takes the output of the generator and returns a JSON payload that contains information +// about the services that lagoon will be deploying (this will be kubernetes `kind: deployment`, but lagoon calls them services ¯\_(ツ)_/¯) +// this command can be used to identify services that are deployed by the build, so that services that may remain in the environment can be identified +// and eventually removed func LagoonServiceTemplateIdentification(g generator.GeneratorInput) ([]identifyServices, error) { lServices := []identifyServices{} @@ -64,7 +72,6 @@ func LagoonServiceTemplateIdentification(g generator.GeneratorInput) ([]identify return nil, err } - // generate the templates deployments, err := servicestemplates.GenerateDeploymentTemplate(*lagoonBuild.BuildValues) if err != nil { return nil, fmt.Errorf("couldn't generate template: %v", err) diff --git a/cmd/identify_lagoonservices_test.go b/cmd/identify_lagoonservices_test.go index 7c26bd4d..20e6e6fe 100644 --- a/cmd/identify_lagoonservices_test.go +++ b/cmd/identify_lagoonservices_test.go @@ -30,7 +30,7 @@ func TestIdentifyLagoonServices(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/basic/lagoon.yml", ImageReferences: map[string]string{ - "node": "harbor.example/example-project/main/node:latest", + "node": "harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, }, true), want: []identifyServices{ @@ -59,11 +59,11 @@ func TestIdentifyLagoonServices(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", ImageReferences: map[string]string{ - "nginx": "harbor.example/example-project/main/nginx:latest", - "php": "harbor.example/example-project/main/php:latest", - "cli": "harbor.example/example-project/main/cli:latest", - "redis": "harbor.example/example-project/main/redis:latest", - "varnish": "harbor.example/example-project/main/varnish:latest", + "nginx": "harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "php": "harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "cli": "harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "redis": "harbor.example/example-project/main/redis@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "varnish": "harbor.example/example-project/main/varnish@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, }, true), want: []identifyServices{ @@ -131,11 +131,11 @@ func TestIdentifyLagoonServices(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", ImageReferences: map[string]string{ - "nginx": "harbor.example/example-project/main/nginx:latest", - "php": "harbor.example/example-project/main/php:latest", - "cli": "harbor.example/example-project/main/cli:latest", - "redis": "harbor.example/example-project/main/redis:latest", - "varnish": "harbor.example/example-project/main/varnish:latest", + "nginx": "harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "php": "harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "cli": "harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "redis": "harbor.example/example-project/main/redis@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "varnish": "harbor.example/example-project/main/varnish@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, ProjectVariables: []lagoon.EnvironmentVariable{ { @@ -211,9 +211,9 @@ func TestIdentifyLagoonServices(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/basic/lagoon.thunderhub.yml", ImageReferences: map[string]string{ - "lnd": "harbor.example/example-project/main/lnd:latest", - "thunderhub": "harbor.example/example-project/main/thunderhub:latest", - "tor": "harbor.example/example-project/main/tor:latest", + "lnd": "harbor.example/example-project/main/lnd@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "thunderhub": "harbor.example/example-project/main/thunderhub@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "tor": "harbor.example/example-project/main/tor@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, ProjectVariables: []lagoon.EnvironmentVariable{ { @@ -274,8 +274,8 @@ func TestIdentifyLagoonServices(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/basic/lagoon.thunderhub-2.yml", ImageReferences: map[string]string{ - "lnd": "harbor.example/example-project/main/lnd:latest", - "tor": "harbor.example/example-project/main/tor:latest", + "lnd": "harbor.example/example-project/main/lnd@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "tor": "harbor.example/example-project/main/tor@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, ProjectVariables: []lagoon.EnvironmentVariable{ { @@ -311,7 +311,7 @@ func TestIdentifyLagoonServices(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // set the environment variables from args - savedTemplates := "test-resources/output" + savedTemplates := "testoutput" generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) if err != nil { t.Errorf("%v", err) diff --git a/cmd/identify_native_cronjobs_test.go b/cmd/identify_native_cronjobs_test.go index 37464457..2d1970bc 100644 --- a/cmd/identify_native_cronjobs_test.go +++ b/cmd/identify_native_cronjobs_test.go @@ -55,7 +55,7 @@ func TestIdentifyNativeCronjobs(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "[]", }, { @@ -66,15 +66,8 @@ func TestIdentifyNativeCronjobs(t *testing.T) { EnvironmentName: "main", Branch: "main", LagoonYAML: "internal/testdata/complex/lagoon.yml", - ImageReferences: map[string]string{ - "nginx": "harbor.example/example-project/main/nginx:latest", - "php": "harbor.example/example-project/main/php:latest", - "cli": "harbor.example/example-project/main/cli:latest", - "redis": "harbor.example/example-project/main/redis:latest", - "varnish": "harbor.example/example-project/main/varnish:latest", - }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: `["cronjob-cli-drush-cron2"]`, }, { @@ -85,13 +78,6 @@ func TestIdentifyNativeCronjobs(t *testing.T) { EnvironmentName: "main", Branch: "main", LagoonYAML: "internal/testdata/complex/lagoon.yml", - ImageReferences: map[string]string{ - "nginx": "harbor.example/example-project/main/nginx:latest", - "php": "harbor.example/example-project/main/php:latest", - "cli": "harbor.example/example-project/main/cli:latest", - "redis": "harbor.example/example-project/main/redis:latest", - "varnish": "harbor.example/example-project/main/varnish:latest", - }, ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", @@ -100,7 +86,7 @@ func TestIdentifyNativeCronjobs(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: `["cronjob-cli-drush-cron2"]`, }, } diff --git a/cmd/tasks_run.go b/cmd/tasks_run.go index fd970d42..8708db8d 100644 --- a/cmd/tasks_run.go +++ b/cmd/tasks_run.go @@ -120,8 +120,8 @@ func getEnvironmentInfo(g generator.GeneratorInput) (lagoon.YAML, tasklib.TaskEn } lagoonConditionalEvaluationEnvironment := tasklib.TaskEnvironment{} - if len(*lagoonBuild.LagoonEnvironmentVariables) > 0 { - for _, envVar := range *lagoonBuild.LagoonEnvironmentVariables { + if len(lagoonBuild.BuildValues.EnvironmentVariables) > 0 { + for _, envVar := range lagoonBuild.BuildValues.EnvironmentVariables { lagoonConditionalEvaluationEnvironment[envVar.Name] = envVar.Value } } diff --git a/cmd/template_autogen_ingress_test.go b/cmd/template_autogen_ingress_test.go index 0bb4b2c9..35f64304 100644 --- a/cmd/template_autogen_ingress_test.go +++ b/cmd/template_autogen_ingress_test.go @@ -33,7 +33,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-1", }, { @@ -46,10 +46,12 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { PRNumber: "123", PRHeadBranch: "main", PRBaseBranch: "main2", + PRHeadSHA: "a1b2c3", + PRBaseSHA: "1a2b3c", EnvironmentType: "development", LagoonYAML: "internal/testdata/node/lagoon.autogen-1.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-2", }, { @@ -62,10 +64,12 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { PRNumber: "123", PRHeadBranch: "main", PRBaseBranch: "main2", + PRHeadSHA: "a1b2c3", + PRBaseSHA: "1a2b3c", EnvironmentType: "development", LagoonYAML: "internal/testdata/node/lagoon.autogen-2.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", emptyDir: true, want: "", }, @@ -85,7 +89,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, false), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-3", }, { @@ -104,7 +108,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, false), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-4", }, { @@ -116,7 +120,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/node/lagoon.autogen-3.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", emptyDir: true, want: "", }, @@ -129,7 +133,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/node/lagoon.autogen-4.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-5", }, { @@ -153,7 +157,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-6", }, { @@ -177,7 +181,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-7", }, { @@ -201,7 +205,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-8", }, { @@ -214,7 +218,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentType: "development", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-9", }, { @@ -227,7 +231,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentType: "development", LagoonYAML: "internal/testdata/node/lagoon.autogen-5.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-10", }, { @@ -247,7 +251,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-11", }, { @@ -260,7 +264,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentType: "development", LagoonYAML: "internal/testdata/node/lagoon.autogen-6.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", emptyDir: true, want: "", }, @@ -274,7 +278,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentType: "development", LagoonYAML: "internal/testdata/nginxphp/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/nginxphp/autogen-templates/ingress-1", }, { @@ -287,7 +291,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentType: "development", LagoonYAML: "internal/testdata/nginxphp/lagoon.servicename.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/nginxphp/autogen-templates/ingress-2", }, { @@ -307,7 +311,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, false), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/complex/autogen-templates/ingress-1", }, { @@ -320,7 +324,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentType: "production", LagoonYAML: "internal/testdata/node/lagoon.autogen-7.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-12", }, { @@ -333,7 +337,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { EnvironmentType: "production", LagoonYAML: "internal/testdata/node/lagoon.autogen-8.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-13", }, { @@ -353,7 +357,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, false), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/complex/autogen-templates/ingress-2", }, { @@ -373,7 +377,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, false), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/complex/autogen-templates/ingress-3", }, { @@ -387,6 +391,8 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { PRNumber: "123", PRHeadBranch: "main", PRBaseBranch: "main2", + PRHeadSHA: "a1b2c3", + PRBaseSHA: "1a2b3c", LagoonYAML: "internal/testdata/nginxphp/lagoon.nginx-1.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { @@ -396,7 +402,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, false), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/nginxphp/autogen-templates/ingress-3", }, { @@ -415,7 +421,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-14", }, { @@ -434,7 +440,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/autogen-templates/ingress-14", }, { @@ -453,7 +459,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", emptyDir: true, want: "", }, @@ -473,7 +479,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", emptyDir: true, want: "", }, diff --git a/cmd/template_backups_test.go b/cmd/template_backups_test.go index ccdc28ee..1bf4cb18 100644 --- a/cmd/template_backups_test.go +++ b/cmd/template_backups_test.go @@ -39,7 +39,7 @@ func TestBackupTemplateGeneration(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/complex/backup-templates/backup-1", }, { @@ -64,7 +64,7 @@ func TestBackupTemplateGeneration(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/backup-templates/backup-1", }, { @@ -84,7 +84,7 @@ func TestBackupTemplateGeneration(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/backup-templates/backup-2", }, { @@ -98,6 +98,8 @@ func TestBackupTemplateGeneration(t *testing.T) { PRNumber: "123", PRHeadBranch: "main", PRBaseBranch: "main2", + PRHeadSHA: "a1b2c3", + PRBaseSHA: "1a2b3c", LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { @@ -112,7 +114,7 @@ func TestBackupTemplateGeneration(t *testing.T) { {Name: "LAGOON_BACKUP_PR_SCHEDULE", Value: "3,33 12 * * *", Scope: "build"}, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/backup-templates/backup-3", }, { @@ -126,6 +128,8 @@ func TestBackupTemplateGeneration(t *testing.T) { PRNumber: "123", PRHeadBranch: "main", PRBaseBranch: "main2", + PRHeadSHA: "a1b2c3", + PRBaseSHA: "1a2b3c", LagoonYAML: "internal/testdata/node/lagoon.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { @@ -140,7 +144,7 @@ func TestBackupTemplateGeneration(t *testing.T) { {Name: "LAGOON_BACKUP_PR_SCHEDULE", Value: "3,33 12 * * *", Scope: "build"}, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/backup-templates/backup-4", }, { @@ -153,7 +157,7 @@ func TestBackupTemplateGeneration(t *testing.T) { EnvironmentType: "production", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/backup-templates/backup-5", }, { @@ -167,7 +171,7 @@ func TestBackupTemplateGeneration(t *testing.T) { DefaultBackupSchedule: "M */6 * * *", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/backup-templates/backup-6", }, { @@ -187,7 +191,7 @@ func TestBackupTemplateGeneration(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/complex/backup-templates/backup-2", }, } diff --git a/cmd/template_dbaas_test.go b/cmd/template_dbaas_test.go index fd85282c..a07e75fb 100644 --- a/cmd/template_dbaas_test.go +++ b/cmd/template_dbaas_test.go @@ -31,7 +31,7 @@ func TestDBaaSTemplateGeneration(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/complex/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/complex/dbaas-templates/dbaas-1", }, } diff --git a/cmd/template_ingress_test.go b/cmd/template_ingress_test.go index a7e8bcc8..acac2191 100644 --- a/cmd/template_ingress_test.go +++ b/cmd/template_ingress_test.go @@ -38,7 +38,7 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-1", }, { @@ -57,7 +57,7 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-2", }, { @@ -76,7 +76,7 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-3", }, { @@ -88,7 +88,7 @@ func TestTemplateRoutes(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-4", }, { @@ -100,7 +100,7 @@ func TestTemplateRoutes(t *testing.T) { Branch: "multiproject", LagoonYAML: "internal/testdata/node/lagoon.polysite.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-5", }, { @@ -112,7 +112,7 @@ func TestTemplateRoutes(t *testing.T) { Branch: "multiproject", LagoonYAML: "internal/testdata/node/lagoon.polysite.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-6", }, { @@ -124,7 +124,7 @@ func TestTemplateRoutes(t *testing.T) { Branch: "tworoutes", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-7", }, { @@ -136,7 +136,7 @@ func TestTemplateRoutes(t *testing.T) { Branch: "branch/routes", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-8", }, { @@ -150,7 +150,7 @@ func TestTemplateRoutes(t *testing.T) { StandbyEnvironment: "main-sb", LagoonYAML: "internal/testdata/node/lagoon.activestandby.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-9", }, { @@ -164,7 +164,7 @@ func TestTemplateRoutes(t *testing.T) { StandbyEnvironment: "main-sb", LagoonYAML: "internal/testdata/node/lagoon.activestandby.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-10", }, { @@ -176,7 +176,7 @@ func TestTemplateRoutes(t *testing.T) { Branch: "production", LagoonYAML: "internal/testdata/complex/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/complex/ingress-templates/ingress-1", }, { @@ -200,7 +200,7 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-11", }, { @@ -213,7 +213,7 @@ func TestTemplateRoutes(t *testing.T) { IngressClass: "nginx", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-12", }, { @@ -225,7 +225,7 @@ func TestTemplateRoutes(t *testing.T) { Branch: "ingressclass", IngressClass: "nginx", LagoonYAML: "internal/testdata/node/lagoon.yml", - }, true), templatePath: "test-resources/output", + }, true), templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-13", }, { @@ -245,7 +245,7 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-14", }, { @@ -271,7 +271,7 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-15", }, { @@ -290,7 +290,7 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-16", }, { @@ -309,7 +309,7 @@ func TestTemplateRoutes(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-17", }, { @@ -321,7 +321,7 @@ func TestTemplateRoutes(t *testing.T) { Branch: "tworoutes", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-18", }, { @@ -334,10 +334,12 @@ func TestTemplateRoutes(t *testing.T) { PRNumber: "4841", PRHeadBranch: "main", PRBaseBranch: "my-branch", + PRHeadSHA: "a1b2c3", + PRBaseSHA: "1a2b3c", EnvironmentType: "development", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-19", }, { @@ -350,10 +352,12 @@ func TestTemplateRoutes(t *testing.T) { PRNumber: "4841", PRHeadBranch: "main", PRBaseBranch: "my-branch", + PRHeadSHA: "a1b2c3", + PRBaseSHA: "1a2b3c", EnvironmentType: "development", LagoonYAML: "internal/testdata/node/lagoon.polysite-pr.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-20", }, { @@ -365,7 +369,7 @@ func TestTemplateRoutes(t *testing.T) { Branch: "alternativename", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-21", }, { @@ -377,7 +381,7 @@ func TestTemplateRoutes(t *testing.T) { Branch: "wildcard", LagoonYAML: "internal/testdata/node/lagoon.yml", }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/node/ingress-templates/ingress-22", }, } diff --git a/cmd/template_lagoonservices.go b/cmd/template_lagoonservices.go index fc00c55b..d2d9b92b 100644 --- a/cmd/template_lagoonservices.go +++ b/cmd/template_lagoonservices.go @@ -28,8 +28,13 @@ var lagoonServiceGeneration = &cobra.Command{ var imageRefs struct { Images map[string]string `json:"images"` } - imagesStr, _ := base64.StdEncoding.DecodeString(images) - json.Unmarshal(imagesStr, &imageRefs) + imagesStr, err := base64.StdEncoding.DecodeString(images) + if err != nil { + return fmt.Errorf("error decoding images payload: %v", err) + } + if err := json.Unmarshal(imagesStr, &imageRefs); err != nil { + return fmt.Errorf("error unmarshalling images payload: %v", err) + } gen.ImageReferences = imageRefs.Images return LagoonServiceTemplateGeneration(gen) }, diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index fab1121c..29fd5929 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -33,10 +33,10 @@ func TestTemplateLagoonServices(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/basic/lagoon.yml", ImageReferences: map[string]string{ - "node": "harbor.example/example-project/main/node:latest", + "node": "harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/basic/service-templates/service1", }, { @@ -48,14 +48,14 @@ func TestTemplateLagoonServices(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", ImageReferences: map[string]string{ - "nginx": "harbor.example/example-project/main/nginx:latest", - "php": "harbor.example/example-project/main/php:latest", - "cli": "harbor.example/example-project/main/cli:latest", - "redis": "harbor.example/example-project/main/redis:latest", - "varnish": "harbor.example/example-project/main/varnish:latest", + "nginx": "harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "php": "harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "cli": "harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "redis": "harbor.example/example-project/main/redis@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "varnish": "harbor.example/example-project/main/varnish@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/complex/service-templates/service1", }, { @@ -67,11 +67,11 @@ func TestTemplateLagoonServices(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", ImageReferences: map[string]string{ - "nginx": "harbor.example/example-project/main/nginx:latest", - "php": "harbor.example/example-project/main/php:latest", - "cli": "harbor.example/example-project/main/cli:latest", - "redis": "harbor.example/example-project/main/redis:latest", - "varnish": "harbor.example/example-project/main/varnish:latest", + "nginx": "harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "php": "harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "cli": "harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "redis": "harbor.example/example-project/main/redis@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "varnish": "harbor.example/example-project/main/varnish@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, ProjectVariables: []lagoon.EnvironmentVariable{ { @@ -81,7 +81,7 @@ func TestTemplateLagoonServices(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/complex/service-templates/service2", }, { @@ -94,9 +94,9 @@ func TestTemplateLagoonServices(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/basic/lagoon.thunderhub.yml", ImageReferences: map[string]string{ - "lnd": "harbor.example/example-project/main/lnd:latest", - "thunderhub": "harbor.example/example-project/main/thunderhub:latest", - "tor": "harbor.example/example-project/main/tor:latest", + "lnd": "harbor.example/example-project/main/lnd@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "thunderhub": "harbor.example/example-project/main/thunderhub@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "tor": "harbor.example/example-project/main/tor@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, ProjectVariables: []lagoon.EnvironmentVariable{ { @@ -106,7 +106,7 @@ func TestTemplateLagoonServices(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/basic/service-templates/service2", }, { @@ -119,8 +119,8 @@ func TestTemplateLagoonServices(t *testing.T) { Branch: "main", LagoonYAML: "internal/testdata/basic/lagoon.thunderhub-2.yml", ImageReferences: map[string]string{ - "lnd": "harbor.example/example-project/main/lnd:latest", - "tor": "harbor.example/example-project/main/tor:latest", + "lnd": "harbor.example/example-project/main/lnd@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "tor": "harbor.example/example-project/main/tor@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, ProjectVariables: []lagoon.EnvironmentVariable{ { @@ -130,9 +130,45 @@ func TestTemplateLagoonServices(t *testing.T) { }, }, }, true), - templatePath: "test-resources/output", + templatePath: "testoutput", want: "internal/testdata/basic/service-templates/service3", }, + { + name: "test5 basic deployment promote", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + BuildType: "promote", + LagoonYAML: "internal/testdata/basic/lagoon.yml", + ImageReferences: map[string]string{ + "node": "harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + }, + }, true), + templatePath: "testoutput", + want: "internal/testdata/basic/service-templates/service4", + }, + { + name: "test6 basic deployment pr", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "pr-123", + BuildType: "pullrequest", + PRNumber: "123", + PRHeadBranch: "pr-head", + PRBaseBranch: "pr-base", + PRHeadSHA: "123456", + PRBaseSHA: "abcdef", + LagoonYAML: "internal/testdata/basic/lagoon.yml", + ImageReferences: map[string]string{ + "node": "harbor.example/example-project/pr-123/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + }, + }, true), + templatePath: "testoutput", + want: "internal/testdata/basic/service-templates/service5", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/docs/buildrequirements.md b/docs/buildrequirements.md index cb248834..fbc88cc5 100644 --- a/docs/buildrequirements.md +++ b/docs/buildrequirements.md @@ -36,7 +36,7 @@ These are variables that are injected into a build pod by `remote-controller`, s * `PR_BASE_SHA` #### Promotion Variables -* `PROMOTION_SOURCE_ENVIRONMENT` +* `PROMOTION_SOURCE_ENVIRONMENT` contains the source environment name if this is a promotion type build #### Environment Variables * `LAGOON_PROJECT_VARIABLES` contains any project specific environment variables diff --git a/go.mod b/go.mod index 2087b91f..cf905d0e 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 github.com/compose-spec/compose-go v1.2.7 github.com/cxmcc/unixsums v0.0.0-20131125091133-89564297d82f + github.com/drone/envsubst v1.0.3 github.com/google/go-cmp v0.5.9 github.com/hashicorp/go-retryablehttp v0.7.5 github.com/k8up-io/k8up/v2 v2.7.2 diff --git a/go.sum b/go.sum index 64328eb1..1eb2a909 100644 --- a/go.sum +++ b/go.sum @@ -162,6 +162,8 @@ github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE= github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= +github.com/drone/envsubst v1.0.3 h1:PCIBwNDYjs50AsLZPYdfhSATKaRg/FJmDc2D6+C2x8g= +github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustmop/soup v1.1.2-0.20190516214245-38228baa104e/go.mod h1:CgNC6SGbT+Xb8wGGvzilttZL1mc5sQ/5KkcxsZttMIk= From c25ea64314c97098922d2ded979b563b5ede9ce5 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 12 Jan 2024 20:22:56 +1100 Subject: [PATCH 52/92] chore: remove legacy helmcharts --- .../helmcharts/basic-persistent/.helmignore | 22 --- legacy/helmcharts/basic-persistent/Chart.yaml | 17 -- .../basic-persistent/templates/_helpers.tpl | 123 -------------- .../basic-persistent/templates/cronjob.yaml | 94 ----------- .../helmcharts/basic-persistent/values.yaml | 72 --------- legacy/helmcharts/basic/.helmignore | 22 --- legacy/helmcharts/basic/Chart.yaml | 17 -- .../helmcharts/basic/templates/_helpers.tpl | 114 ------------- .../helmcharts/basic/templates/cronjob.yaml | 87 ---------- legacy/helmcharts/basic/values.yaml | 70 -------- legacy/helmcharts/cli-persistent/.helmignore | 22 --- legacy/helmcharts/cli-persistent/Chart.yaml | 17 -- .../cli-persistent/templates/_helpers.tpl | 98 ------------ .../cli-persistent/templates/cronjob.yaml | 101 ------------ legacy/helmcharts/cli-persistent/values.yaml | 64 -------- legacy/helmcharts/cli/.helmignore | 22 --- legacy/helmcharts/cli/Chart.yaml | 17 -- legacy/helmcharts/cli/templates/_helpers.tpl | 84 ---------- legacy/helmcharts/cli/templates/cronjob.yaml | 96 ----------- legacy/helmcharts/cli/values.yaml | 63 -------- legacy/helmcharts/elasticsearch/.helmignore | 22 --- legacy/helmcharts/elasticsearch/Chart.yaml | 17 -- .../elasticsearch/templates/_helpers.tpl | 99 ------------ .../elasticsearch/templates/cronjob.yaml | 87 ---------- .../elasticsearch/templates/deployment.yaml | 97 ----------- .../elasticsearch/templates/pvc.yaml | 15 -- .../elasticsearch/templates/service.yaml | 17 -- legacy/helmcharts/elasticsearch/values.yaml | 68 -------- .../isolation-network-policy/.helmignore | 23 --- .../isolation-network-policy/Chart.yaml | 18 --- .../templates/_helpers.tpl | 66 -------- .../templates/networkpolicy.yaml | 22 --- .../isolation-network-policy/values.yaml | 1 - legacy/helmcharts/kibana/Chart.yaml | 17 -- .../helmcharts/kibana/templates/_helpers.tpl | 83 ---------- .../helmcharts/kibana/templates/cronjob.yaml | 100 ------------ .../kibana/templates/deployment.yaml | 83 ---------- .../helmcharts/kibana/templates/ingress.yaml | 49 ------ .../helmcharts/kibana/templates/service.yaml | 17 -- legacy/helmcharts/kibana/values.yaml | 93 ----------- legacy/helmcharts/logstash/.helmignore | 22 --- legacy/helmcharts/logstash/Chart.yaml | 21 --- .../logstash/templates/_helpers.tpl | 82 ---------- .../logstash/templates/cronjob.yaml | 87 ---------- .../logstash/templates/deployment.yaml | 85 ---------- .../logstash/templates/service.yaml | 17 -- legacy/helmcharts/logstash/values.yaml | 83 ---------- legacy/helmcharts/mariadb-single/.helmignore | 22 --- legacy/helmcharts/mariadb-single/Chart.yaml | 21 --- .../mariadb-single/templates/_helpers.tpl | 91 ----------- .../mariadb-single/templates/cronjob.yaml | 94 ----------- .../mariadb-single/templates/deployment.yaml | 91 ----------- .../mariadb-single/templates/pvc.yaml | 15 -- .../mariadb-single/templates/service.yaml | 17 -- legacy/helmcharts/mariadb-single/values.yaml | 91 ----------- legacy/helmcharts/mongodb-single/.helmignore | 22 --- legacy/helmcharts/mongodb-single/Chart.yaml | 21 --- .../mongodb-single/templates/_helpers.tpl | 91 ----------- .../mongodb-single/templates/cronjob.yaml | 94 ----------- .../mongodb-single/templates/deployment.yaml | 86 ---------- .../mongodb-single/templates/pvc.yaml | 16 -- .../mongodb-single/templates/service.yaml | 17 -- legacy/helmcharts/mongodb-single/values.yaml | 91 ----------- .../nginx-php-persistent/.helmignore | 22 --- .../nginx-php-persistent/Chart.yaml | 17 -- .../templates/_helpers.tpl | 150 ------------------ .../templates/cronjob.yaml | 101 ------------ .../nginx-php-persistent/values.yaml | 85 ---------- legacy/helmcharts/nginx-php/.helmignore | 22 --- legacy/helmcharts/nginx-php/Chart.yaml | 17 -- .../nginx-php/templates/_helpers.tpl | 128 --------------- .../nginx-php/templates/cronjob.yaml | 96 ----------- legacy/helmcharts/nginx-php/values.yaml | 82 ---------- legacy/helmcharts/nginx/.helmignore | 22 --- legacy/helmcharts/nginx/Chart.yaml | 17 -- .../helmcharts/nginx/templates/_helpers.tpl | 115 -------------- .../helmcharts/nginx/templates/cronjob.yaml | 96 ----------- legacy/helmcharts/nginx/values.yaml | 93 ----------- legacy/helmcharts/node-persistent/.helmignore | 22 --- legacy/helmcharts/node-persistent/Chart.yaml | 17 -- .../node-persistent/templates/_helpers.tpl | 123 -------------- .../node-persistent/templates/cronjob.yaml | 101 ------------ .../node-persistent/templates/deployment.yaml | 91 ----------- .../node-persistent/templates/pvc.yaml | 16 -- .../node-persistent/templates/service.yaml | 17 -- legacy/helmcharts/node-persistent/values.yaml | 72 --------- legacy/helmcharts/node/.helmignore | 22 --- legacy/helmcharts/node/Chart.yaml | 17 -- legacy/helmcharts/node/templates/_helpers.tpl | 114 ------------- legacy/helmcharts/node/templates/cronjob.yaml | 87 ---------- .../helmcharts/node/templates/deployment.yaml | 88 ---------- legacy/helmcharts/node/templates/service.yaml | 17 -- legacy/helmcharts/node/values.yaml | 70 -------- legacy/helmcharts/opensearch/.helmignore | 22 --- legacy/helmcharts/opensearch/Chart.yaml | 17 -- .../opensearch/templates/_helpers.tpl | 99 ------------ .../opensearch/templates/cronjob.yaml | 87 ---------- .../opensearch/templates/deployment.yaml | 99 ------------ .../helmcharts/opensearch/templates/pvc.yaml | 15 -- .../opensearch/templates/service.yaml | 17 -- legacy/helmcharts/opensearch/values.yaml | 68 -------- legacy/helmcharts/postgres-single/.helmignore | 22 --- legacy/helmcharts/postgres-single/Chart.yaml | 21 --- .../postgres-single/templates/_helpers.tpl | 91 ----------- .../postgres-single/templates/cronjob.yaml | 94 ----------- legacy/helmcharts/postgres-single/values.yaml | 91 ----------- .../helmcharts/python-persistent/.helmignore | 22 --- .../helmcharts/python-persistent/Chart.yaml | 17 -- .../python-persistent/templates/_helpers.tpl | 115 -------------- .../python-persistent/templates/cronjob.yaml | 101 ------------ .../templates/deployment.yaml | 92 ----------- .../python-persistent/templates/pvc.yaml | 16 -- .../python-persistent/templates/service.yaml | 17 -- .../helmcharts/python-persistent/values.yaml | 72 --------- legacy/helmcharts/python/.helmignore | 22 --- legacy/helmcharts/python/Chart.yaml | 17 -- .../helmcharts/python/templates/_helpers.tpl | 106 ------------- .../helmcharts/python/templates/cronjob.yaml | 88 ---------- .../python/templates/deployment.yaml | 87 ---------- .../helmcharts/python/templates/service.yaml | 17 -- legacy/helmcharts/python/values.yaml | 70 -------- legacy/helmcharts/rabbitmq/.helmignore | 22 --- legacy/helmcharts/rabbitmq/Chart.yaml | 17 -- .../rabbitmq/templates/_helpers.tpl | 99 ------------ .../rabbitmq/templates/cronjob.yaml | 87 ---------- .../rabbitmq/templates/deployment.yaml | 83 ---------- legacy/helmcharts/rabbitmq/templates/pvc.yaml | 15 -- .../rabbitmq/templates/service.yaml | 21 --- legacy/helmcharts/rabbitmq/values.yaml | 67 -------- .../helmcharts/redis-persistent/.helmignore | 22 --- legacy/helmcharts/redis-persistent/Chart.yaml | 17 -- .../redis-persistent/templates/_helpers.tpl | 99 ------------ .../redis-persistent/templates/cronjob.yaml | 94 ----------- .../helmcharts/redis-persistent/values.yaml | 88 ---------- legacy/helmcharts/redis/.helmignore | 22 --- legacy/helmcharts/redis/Chart.yaml | 17 -- .../helmcharts/redis/templates/_helpers.tpl | 91 ----------- .../helmcharts/redis/templates/cronjob.yaml | 87 ---------- legacy/helmcharts/redis/values.yaml | 84 ---------- legacy/helmcharts/solr/.helmignore | 22 --- legacy/helmcharts/solr/Chart.yaml | 17 -- legacy/helmcharts/solr/templates/_helpers.tpl | 99 ------------ legacy/helmcharts/solr/templates/cronjob.yaml | 87 ---------- legacy/helmcharts/solr/values.yaml | 67 -------- .../helmcharts/varnish-persistent/.helmignore | 22 --- .../helmcharts/varnish-persistent/Chart.yaml | 17 -- .../varnish-persistent/templates/_helpers.tpl | 123 -------------- .../varnish-persistent/templates/cronjob.yaml | 94 ----------- .../helmcharts/varnish-persistent/values.yaml | 92 ----------- legacy/helmcharts/varnish/.helmignore | 22 --- legacy/helmcharts/varnish/Chart.yaml | 17 -- .../helmcharts/varnish/templates/_helpers.tpl | 115 -------------- .../helmcharts/varnish/templates/cronjob.yaml | 87 ---------- legacy/helmcharts/varnish/values.yaml | 88 ---------- .../helmcharts/worker-persistent/.helmignore | 22 --- .../helmcharts/worker-persistent/Chart.yaml | 17 -- .../worker-persistent/templates/_helpers.tpl | 98 ------------ .../worker-persistent/templates/cronjob.yaml | 101 ------------ .../helmcharts/worker-persistent/values.yaml | 64 -------- legacy/helmcharts/worker/.helmignore | 22 --- legacy/helmcharts/worker/Chart.yaml | 17 -- .../helmcharts/worker/templates/_helpers.tpl | 84 ---------- .../helmcharts/worker/templates/cronjob.yaml | 96 ----------- legacy/helmcharts/worker/values.yaml | 63 -------- 164 files changed, 9617 deletions(-) delete mode 100644 legacy/helmcharts/basic-persistent/.helmignore delete mode 100644 legacy/helmcharts/basic-persistent/Chart.yaml delete mode 100644 legacy/helmcharts/basic-persistent/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/basic-persistent/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/basic-persistent/values.yaml delete mode 100644 legacy/helmcharts/basic/.helmignore delete mode 100644 legacy/helmcharts/basic/Chart.yaml delete mode 100644 legacy/helmcharts/basic/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/basic/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/basic/values.yaml delete mode 100644 legacy/helmcharts/cli-persistent/.helmignore delete mode 100644 legacy/helmcharts/cli-persistent/Chart.yaml delete mode 100644 legacy/helmcharts/cli-persistent/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/cli-persistent/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/cli-persistent/values.yaml delete mode 100644 legacy/helmcharts/cli/.helmignore delete mode 100644 legacy/helmcharts/cli/Chart.yaml delete mode 100644 legacy/helmcharts/cli/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/cli/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/cli/values.yaml delete mode 100644 legacy/helmcharts/elasticsearch/.helmignore delete mode 100644 legacy/helmcharts/elasticsearch/Chart.yaml delete mode 100644 legacy/helmcharts/elasticsearch/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/elasticsearch/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/elasticsearch/templates/deployment.yaml delete mode 100644 legacy/helmcharts/elasticsearch/templates/pvc.yaml delete mode 100644 legacy/helmcharts/elasticsearch/templates/service.yaml delete mode 100644 legacy/helmcharts/elasticsearch/values.yaml delete mode 100644 legacy/helmcharts/isolation-network-policy/.helmignore delete mode 100644 legacy/helmcharts/isolation-network-policy/Chart.yaml delete mode 100644 legacy/helmcharts/isolation-network-policy/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/isolation-network-policy/templates/networkpolicy.yaml delete mode 100644 legacy/helmcharts/isolation-network-policy/values.yaml delete mode 100644 legacy/helmcharts/kibana/Chart.yaml delete mode 100644 legacy/helmcharts/kibana/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/kibana/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/kibana/templates/deployment.yaml delete mode 100644 legacy/helmcharts/kibana/templates/ingress.yaml delete mode 100644 legacy/helmcharts/kibana/templates/service.yaml delete mode 100644 legacy/helmcharts/kibana/values.yaml delete mode 100644 legacy/helmcharts/logstash/.helmignore delete mode 100644 legacy/helmcharts/logstash/Chart.yaml delete mode 100644 legacy/helmcharts/logstash/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/logstash/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/logstash/templates/deployment.yaml delete mode 100644 legacy/helmcharts/logstash/templates/service.yaml delete mode 100644 legacy/helmcharts/logstash/values.yaml delete mode 100644 legacy/helmcharts/mariadb-single/.helmignore delete mode 100644 legacy/helmcharts/mariadb-single/Chart.yaml delete mode 100644 legacy/helmcharts/mariadb-single/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/mariadb-single/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/mariadb-single/templates/deployment.yaml delete mode 100644 legacy/helmcharts/mariadb-single/templates/pvc.yaml delete mode 100644 legacy/helmcharts/mariadb-single/templates/service.yaml delete mode 100644 legacy/helmcharts/mariadb-single/values.yaml delete mode 100644 legacy/helmcharts/mongodb-single/.helmignore delete mode 100644 legacy/helmcharts/mongodb-single/Chart.yaml delete mode 100644 legacy/helmcharts/mongodb-single/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/mongodb-single/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/mongodb-single/templates/deployment.yaml delete mode 100644 legacy/helmcharts/mongodb-single/templates/pvc.yaml delete mode 100644 legacy/helmcharts/mongodb-single/templates/service.yaml delete mode 100644 legacy/helmcharts/mongodb-single/values.yaml delete mode 100644 legacy/helmcharts/nginx-php-persistent/.helmignore delete mode 100644 legacy/helmcharts/nginx-php-persistent/Chart.yaml delete mode 100644 legacy/helmcharts/nginx-php-persistent/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/nginx-php-persistent/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/nginx-php-persistent/values.yaml delete mode 100644 legacy/helmcharts/nginx-php/.helmignore delete mode 100644 legacy/helmcharts/nginx-php/Chart.yaml delete mode 100644 legacy/helmcharts/nginx-php/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/nginx-php/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/nginx-php/values.yaml delete mode 100644 legacy/helmcharts/nginx/.helmignore delete mode 100644 legacy/helmcharts/nginx/Chart.yaml delete mode 100644 legacy/helmcharts/nginx/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/nginx/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/nginx/values.yaml delete mode 100644 legacy/helmcharts/node-persistent/.helmignore delete mode 100644 legacy/helmcharts/node-persistent/Chart.yaml delete mode 100644 legacy/helmcharts/node-persistent/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/node-persistent/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/node-persistent/templates/deployment.yaml delete mode 100644 legacy/helmcharts/node-persistent/templates/pvc.yaml delete mode 100644 legacy/helmcharts/node-persistent/templates/service.yaml delete mode 100644 legacy/helmcharts/node-persistent/values.yaml delete mode 100644 legacy/helmcharts/node/.helmignore delete mode 100644 legacy/helmcharts/node/Chart.yaml delete mode 100644 legacy/helmcharts/node/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/node/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/node/templates/deployment.yaml delete mode 100644 legacy/helmcharts/node/templates/service.yaml delete mode 100644 legacy/helmcharts/node/values.yaml delete mode 100644 legacy/helmcharts/opensearch/.helmignore delete mode 100644 legacy/helmcharts/opensearch/Chart.yaml delete mode 100644 legacy/helmcharts/opensearch/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/opensearch/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/opensearch/templates/deployment.yaml delete mode 100644 legacy/helmcharts/opensearch/templates/pvc.yaml delete mode 100644 legacy/helmcharts/opensearch/templates/service.yaml delete mode 100644 legacy/helmcharts/opensearch/values.yaml delete mode 100644 legacy/helmcharts/postgres-single/.helmignore delete mode 100644 legacy/helmcharts/postgres-single/Chart.yaml delete mode 100644 legacy/helmcharts/postgres-single/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/postgres-single/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/postgres-single/values.yaml delete mode 100644 legacy/helmcharts/python-persistent/.helmignore delete mode 100644 legacy/helmcharts/python-persistent/Chart.yaml delete mode 100644 legacy/helmcharts/python-persistent/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/python-persistent/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/python-persistent/templates/deployment.yaml delete mode 100644 legacy/helmcharts/python-persistent/templates/pvc.yaml delete mode 100644 legacy/helmcharts/python-persistent/templates/service.yaml delete mode 100644 legacy/helmcharts/python-persistent/values.yaml delete mode 100644 legacy/helmcharts/python/.helmignore delete mode 100644 legacy/helmcharts/python/Chart.yaml delete mode 100644 legacy/helmcharts/python/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/python/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/python/templates/deployment.yaml delete mode 100644 legacy/helmcharts/python/templates/service.yaml delete mode 100644 legacy/helmcharts/python/values.yaml delete mode 100644 legacy/helmcharts/rabbitmq/.helmignore delete mode 100644 legacy/helmcharts/rabbitmq/Chart.yaml delete mode 100644 legacy/helmcharts/rabbitmq/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/rabbitmq/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/rabbitmq/templates/deployment.yaml delete mode 100644 legacy/helmcharts/rabbitmq/templates/pvc.yaml delete mode 100644 legacy/helmcharts/rabbitmq/templates/service.yaml delete mode 100644 legacy/helmcharts/rabbitmq/values.yaml delete mode 100644 legacy/helmcharts/redis-persistent/.helmignore delete mode 100644 legacy/helmcharts/redis-persistent/Chart.yaml delete mode 100644 legacy/helmcharts/redis-persistent/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/redis-persistent/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/redis-persistent/values.yaml delete mode 100644 legacy/helmcharts/redis/.helmignore delete mode 100644 legacy/helmcharts/redis/Chart.yaml delete mode 100644 legacy/helmcharts/redis/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/redis/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/redis/values.yaml delete mode 100644 legacy/helmcharts/solr/.helmignore delete mode 100644 legacy/helmcharts/solr/Chart.yaml delete mode 100644 legacy/helmcharts/solr/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/solr/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/solr/values.yaml delete mode 100644 legacy/helmcharts/varnish-persistent/.helmignore delete mode 100644 legacy/helmcharts/varnish-persistent/Chart.yaml delete mode 100644 legacy/helmcharts/varnish-persistent/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/varnish-persistent/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/varnish-persistent/values.yaml delete mode 100644 legacy/helmcharts/varnish/.helmignore delete mode 100644 legacy/helmcharts/varnish/Chart.yaml delete mode 100644 legacy/helmcharts/varnish/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/varnish/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/varnish/values.yaml delete mode 100644 legacy/helmcharts/worker-persistent/.helmignore delete mode 100644 legacy/helmcharts/worker-persistent/Chart.yaml delete mode 100644 legacy/helmcharts/worker-persistent/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/worker-persistent/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/worker-persistent/values.yaml delete mode 100644 legacy/helmcharts/worker/.helmignore delete mode 100644 legacy/helmcharts/worker/Chart.yaml delete mode 100644 legacy/helmcharts/worker/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/worker/templates/cronjob.yaml delete mode 100644 legacy/helmcharts/worker/values.yaml diff --git a/legacy/helmcharts/basic-persistent/.helmignore b/legacy/helmcharts/basic-persistent/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/basic-persistent/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/basic-persistent/Chart.yaml b/legacy/helmcharts/basic-persistent/Chart.yaml deleted file mode 100644 index 15a1defc..00000000 --- a/legacy/helmcharts/basic-persistent/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: basic-persistent -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/basic-persistent/templates/_helpers.tpl b/legacy/helmcharts/basic-persistent/templates/_helpers.tpl deleted file mode 100644 index d8418aca..00000000 --- a/legacy/helmcharts/basic-persistent/templates/_helpers.tpl +++ /dev/null @@ -1,123 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "basic-persistent.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "basic-persistent.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "basic-persistent.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "basic-persistent.autogeneratedHost" -}} -{{- if .root.Values.autogeneratedRouteDomain -}} -{{ if not .prefix }} -{{- printf "%s" .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s" .prefix .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- end -}} -{{- else -}} -{{ if not .prefix }} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s.%s" .prefix .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create short hostname for autogenerated hosts. -This is used to work around problems with long CN fields in certificates. -*/}} -{{- define "basic-persistent.autogeneratedShortHost" -}} -{{- if .root.Values.shortAutogeneratedRouteDomain -}} -{{- printf "%s" .root.Values.shortAutogeneratedRouteDomain }} -{{- else -}} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateShortSuffix }} -{{- end -}} -{{- end }} - -{{/* -Generate name of Persistent Storage -Uses the Release Name (Lagoon Service Name) unless it's overwritten via .Values.persistentStorage.name -*/}} -{{- define "basic-persistent.persistentStorageName" -}} -{{- default .Release.Name .Values.persistentStorage.name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "basic-persistent.labels" -}} -helm.sh/chart: {{ include "basic-persistent.chart" . }} -{{ include "basic-persistent.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "basic-persistent.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "basic-persistent.selectorLabels" -}} -app.kubernetes.io/name: {{ include "basic-persistent.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "basic-persistent.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "basic-persistent.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "basic-persistent.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "basic-persistent.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/basic-persistent/templates/cronjob.yaml b/legacy/helmcharts/basic-persistent/templates/cronjob.yaml deleted file mode 100644 index 811dc851..00000000 --- a/legacy/helmcharts/basic-persistent/templates/cronjob.yaml +++ /dev/null @@ -1,94 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "basic-persistent.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "basic-persistent.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "basic-persistent.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "basic-persistent.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "basic-persistent.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "basic-persistent.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "basic-persistent.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: {{ $.Values.persistentStorage.name }} - persistentVolumeClaim: - claimName: {{ $.Values.persistentStorage.name }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - name: {{ $.Values.persistentStorage.name }} - mountPath: {{ $.Values.persistentStorage.path | quote }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/basic-persistent/values.yaml b/legacy/helmcharts/basic-persistent/values.yaml deleted file mode 100644 index b8a3ff16..00000000 --- a/legacy/helmcharts/basic-persistent/values.yaml +++ /dev/null @@ -1,72 +0,0 @@ -# Default values for basic-persistent. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production - -persistentStorage: - size: 5Gi - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: {} - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 3000 - -## example fastly block -fastly: - watch: false -# serviceId: '' -# apiSecretName: '' - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/basic/.helmignore b/legacy/helmcharts/basic/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/basic/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/basic/Chart.yaml b/legacy/helmcharts/basic/Chart.yaml deleted file mode 100644 index cf84a1eb..00000000 --- a/legacy/helmcharts/basic/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: basic -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/basic/templates/_helpers.tpl b/legacy/helmcharts/basic/templates/_helpers.tpl deleted file mode 100644 index e26fa410..00000000 --- a/legacy/helmcharts/basic/templates/_helpers.tpl +++ /dev/null @@ -1,114 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "basic.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "basic.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "basic.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "basic.autogeneratedHost" -}} -{{- if .root.Values.autogeneratedRouteDomain -}} -{{ if not .prefix }} -{{- printf "%s" .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s" .prefix .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- end -}} -{{- else -}} -{{ if not .prefix }} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s.%s" .prefix .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create short hostname for autogenerated hosts. -This is used to work around problems with long CN fields in certificates. -*/}} -{{- define "basic.autogeneratedShortHost" -}} -{{- if .root.Values.shortAutogeneratedRouteDomain -}} -{{- printf "%s" .root.Values.shortAutogeneratedRouteDomain }} -{{- else -}} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateShortSuffix }} -{{- end -}} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "basic.labels" -}} -helm.sh/chart: {{ include "basic.chart" . }} -{{ include "basic.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "basic.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "basic.selectorLabels" -}} -app.kubernetes.io/name: {{ include "basic.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "basic.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "basic.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "basic.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} -{{/* -Annotations -*/}} -{{- define "basic.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/basic/templates/cronjob.yaml b/legacy/helmcharts/basic/templates/cronjob.yaml deleted file mode 100644 index 4f46343f..00000000 --- a/legacy/helmcharts/basic/templates/cronjob.yaml +++ /dev/null @@ -1,87 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "basic.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "basic.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "basic.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "basic.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "basic.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "basic.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "basic.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/basic/values.yaml b/legacy/helmcharts/basic/values.yaml deleted file mode 100644 index e8cf2cf1..00000000 --- a/legacy/helmcharts/basic/values.yaml +++ /dev/null @@ -1,70 +0,0 @@ -# Default values for basic. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 3000 - -## example fastly block -fastly: - watch: false -# serviceId: '' -# apiSecretName: '' - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/cli-persistent/.helmignore b/legacy/helmcharts/cli-persistent/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/cli-persistent/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/cli-persistent/Chart.yaml b/legacy/helmcharts/cli-persistent/Chart.yaml deleted file mode 100644 index 372a749b..00000000 --- a/legacy/helmcharts/cli-persistent/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: cli-persistent -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 \ No newline at end of file diff --git a/legacy/helmcharts/cli-persistent/templates/_helpers.tpl b/legacy/helmcharts/cli-persistent/templates/_helpers.tpl deleted file mode 100644 index ddb0f7c5..00000000 --- a/legacy/helmcharts/cli-persistent/templates/_helpers.tpl +++ /dev/null @@ -1,98 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "cli-persistent.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "cli-persistent.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "cli-persistent.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "cli-persistent.labels" -}} -helm.sh/chart: {{ include "cli-persistent.chart" . }} -{{ include "cli-persistent.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "cli-persistent.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "cli-persistent.selectorLabels" -}} -app.kubernetes.io/name: {{ include "cli-persistent.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "cli-persistent.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "cli-persistent.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "cli-persistent.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "cli-persistent.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} - -{{/* -Generate name for twig storage emptyDir -*/}} -{{- define "cli-persistent.twig-storage.name" -}} -{{- printf "%s-twig" .Values.persistentStorage.name }} -{{- end -}} - -{{/* -Generate path for twig storage emptyDir -*/}} -{{- define "cli-persistent.twig-storage.path" -}} -{{- printf "%s/php" .Values.persistentStorage.path }} -{{- end -}} diff --git a/legacy/helmcharts/cli-persistent/templates/cronjob.yaml b/legacy/helmcharts/cli-persistent/templates/cronjob.yaml deleted file mode 100644 index ae2e8397..00000000 --- a/legacy/helmcharts/cli-persistent/templates/cronjob.yaml +++ /dev/null @@ -1,101 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "cli-persistent.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "cli-persistent.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "cli-persistent.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "cli-persistent.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "cli-persistent.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "cli-persistent.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "cli-persistent.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - - name: {{ $.Values.persistentStorage.name }} - persistentVolumeClaim: - claimName: {{ $.Values.persistentStorage.name }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - name: {{ $.Values.persistentStorage.name }} - mountPath: {{ $.Values.persistentStorage.path | quote }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/cli-persistent/values.yaml b/legacy/helmcharts/cli-persistent/values.yaml deleted file mode 100644 index 4f736c5c..00000000 --- a/legacy/helmcharts/cli-persistent/values.yaml +++ /dev/null @@ -1,64 +0,0 @@ -# Default values for cli-persistent. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -environmentType: production - -gitSha: "" - -image: "" - -persistentStorage: - name: "" - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: {} - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -resources: - limits: - cpu: 2 - memory: 8Gi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/cli/.helmignore b/legacy/helmcharts/cli/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/cli/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/cli/Chart.yaml b/legacy/helmcharts/cli/Chart.yaml deleted file mode 100644 index 770a3141..00000000 --- a/legacy/helmcharts/cli/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: cli -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 \ No newline at end of file diff --git a/legacy/helmcharts/cli/templates/_helpers.tpl b/legacy/helmcharts/cli/templates/_helpers.tpl deleted file mode 100644 index cf8658cb..00000000 --- a/legacy/helmcharts/cli/templates/_helpers.tpl +++ /dev/null @@ -1,84 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "cli.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "cli.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "cli.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "cli.labels" -}} -helm.sh/chart: {{ include "cli.chart" . }} -{{ include "cli.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "cli.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "cli.selectorLabels" -}} -app.kubernetes.io/name: {{ include "cli.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "cli.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "cli.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "cli.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "cli.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/cli/templates/cronjob.yaml b/legacy/helmcharts/cli/templates/cronjob.yaml deleted file mode 100644 index a26e88fa..00000000 --- a/legacy/helmcharts/cli/templates/cronjob.yaml +++ /dev/null @@ -1,96 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "cli.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "cli.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "cli.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "cli.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "cli.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "cli.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "cli.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/cli/values.yaml b/legacy/helmcharts/cli/values.yaml deleted file mode 100644 index 554ae4ab..00000000 --- a/legacy/helmcharts/cli/values.yaml +++ /dev/null @@ -1,63 +0,0 @@ -# Default values for cli. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -environmentType: production - -gitSha: "" - -image: "" - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -resources: - limits: - cpu: 2 - memory: 8Gi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/elasticsearch/.helmignore b/legacy/helmcharts/elasticsearch/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/elasticsearch/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/elasticsearch/Chart.yaml b/legacy/helmcharts/elasticsearch/Chart.yaml deleted file mode 100644 index 5763d9a8..00000000 --- a/legacy/helmcharts/elasticsearch/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: elasticsearch-persistent -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/elasticsearch/templates/_helpers.tpl b/legacy/helmcharts/elasticsearch/templates/_helpers.tpl deleted file mode 100644 index b1b31478..00000000 --- a/legacy/helmcharts/elasticsearch/templates/_helpers.tpl +++ /dev/null @@ -1,99 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "elasticsearch.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "elasticsearch.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "elasticsearch.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "elasticsearch.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{/* -Generate name of Persistent Storage -Uses the Release Name (Lagoon Service Name) unless it's overwritten via .Values.persistentStorage.name -*/}} -{{- define "elasticsearch.persistentStorageName" -}} -{{- default .Release.Name .Values.persistentStorage.name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "elasticsearch.labels" -}} -helm.sh/chart: {{ include "elasticsearch.chart" . }} -{{ include "elasticsearch.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "elasticsearch.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "elasticsearch.selectorLabels" -}} -app.kubernetes.io/name: {{ include "elasticsearch.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "elasticsearch.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "elasticsearch.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "elasticsearch.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "elasticsearch.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/elasticsearch/templates/cronjob.yaml b/legacy/helmcharts/elasticsearch/templates/cronjob.yaml deleted file mode 100644 index 9fe221b1..00000000 --- a/legacy/helmcharts/elasticsearch/templates/cronjob.yaml +++ /dev/null @@ -1,87 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "elasticsearch.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "elasticsearch.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "elasticsearch.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "elasticsearch.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "elasticsearch.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "elasticsearch.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "elasticsearch.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/elasticsearch/templates/deployment.yaml b/legacy/helmcharts/elasticsearch/templates/deployment.yaml deleted file mode 100644 index 0ab2d092..00000000 --- a/legacy/helmcharts/elasticsearch/templates/deployment.yaml +++ /dev/null @@ -1,97 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "elasticsearch.fullname" . }} - labels: - {{- include "elasticsearch.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "elasticsearch.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: Recreate - selector: - matchLabels: - {{- include "elasticsearch.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "elasticsearch.labels" . | nindent 8 }} - {{- include "elasticsearch.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "elasticsearch.annotations" . | nindent 8 }} - k8up.syn.tools/backupcommand: /bin/sh -c "tar -cf - -C {{ .Values.persistentStorage.path }} ." - k8up.syn.tools/file-extension: .{{ include "elasticsearch.fullname" . }}.tar - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ include "elasticsearch.persistentStorageName" . }} - persistentVolumeClaim: - claimName: {{ include "elasticsearch.persistentStorageName" . }} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - priorityClassName: {{ include "elasticsearch.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - initContainers: - # This init container sets the appropriate limits for mmap counts on the hosting node. - # https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html - - name: set-max-map-count - image: {{ .Values.imageCache }}library/busybox:latest - imagePullPolicy: {{ .Values.imagePullPolicy }} - securityContext: - privileged: true - runAsUser: 0 - command: - - sh - - '-c' - - | - set -xe - DESIRED="262144" - CURRENT=$(sysctl -n vm.max_map_count) - if [ "$DESIRED" -gt "$CURRENT" ]; then - sysctl -w vm.max_map_count=$DESIRED - fi - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - containerPort: 9200 - protocol: TCP - readinessProbe: - httpGet: - path: /_cluster/health?local=true - port: 9200 - initialDelaySeconds: 20 - livenessProbe: - httpGet: - path: /_cluster/health?local=true - port: 9200 - initialDelaySeconds: 120 - envFrom: - - configMapRef: - name: lagoon-env - env: - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - volumeMounts: - - name: {{ include "elasticsearch.persistentStorageName" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} diff --git a/legacy/helmcharts/elasticsearch/templates/pvc.yaml b/legacy/helmcharts/elasticsearch/templates/pvc.yaml deleted file mode 100644 index bfeab781..00000000 --- a/legacy/helmcharts/elasticsearch/templates/pvc.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "elasticsearch.persistentStorageName" . }} - labels: - {{- include "elasticsearch.labels" . | nindent 4 }} - annotations: - k8up.syn.tools/backup: "false" - {{- include "elasticsearch.annotations" . | nindent 4 }} -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.persistentStorage.size | quote }} diff --git a/legacy/helmcharts/elasticsearch/templates/service.yaml b/legacy/helmcharts/elasticsearch/templates/service.yaml deleted file mode 100644 index f5d37ba3..00000000 --- a/legacy/helmcharts/elasticsearch/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "elasticsearch.fullname" . }} - labels: - {{- include "elasticsearch.labels" . | nindent 4 }} - annotations: - {{- include "elasticsearch.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: 9200 - protocol: TCP - name: 9200-tcp - selector: - {{- include "elasticsearch.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/elasticsearch/values.yaml b/legacy/helmcharts/elasticsearch/values.yaml deleted file mode 100644 index 374fcb2c..00000000 --- a/legacy/helmcharts/elasticsearch/values.yaml +++ /dev/null @@ -1,68 +0,0 @@ -# Default values for elasticsearch. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -imageCache: "" -image: "" - -environmentType: production -persistentStorage: - size: 5Gi - path: '/usr/share/elasticsearch/data' - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: - fsGroup: 0 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 9200 - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/isolation-network-policy/.helmignore b/legacy/helmcharts/isolation-network-policy/.helmignore deleted file mode 100644 index 0e8a0eb3..00000000 --- a/legacy/helmcharts/isolation-network-policy/.helmignore +++ /dev/null @@ -1,23 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*.orig -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/isolation-network-policy/Chart.yaml b/legacy/helmcharts/isolation-network-policy/Chart.yaml deleted file mode 100644 index 24e59d20..00000000 --- a/legacy/helmcharts/isolation-network-policy/Chart.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: v2 -name: isolation-network-policy -description: A Helm chart for Kubernetes creating a namespace isolation network policy. - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -# Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.0 diff --git a/legacy/helmcharts/isolation-network-policy/templates/_helpers.tpl b/legacy/helmcharts/isolation-network-policy/templates/_helpers.tpl deleted file mode 100644 index 0d2782f7..00000000 --- a/legacy/helmcharts/isolation-network-policy/templates/_helpers.tpl +++ /dev/null @@ -1,66 +0,0 @@ -{{/* -Expand the name of the chart. -*/}} -{{- define "isolation-network-policy.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "isolation-network-policy.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "isolation-network-policy.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "isolation-network-policy.labels" -}} -helm.sh/chart: {{ include "isolation-network-policy.chart" . }} -{{ include "isolation-network-policy.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "isolation-network-policy.lagoonLabels" . }} -{{- end }} - -{{/* -Selector labels -*/}} -{{- define "isolation-network-policy.selectorLabels" -}} -app.kubernetes.io/name: {{ include "isolation-network-policy.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - -{{/* -Lagoon Labels -*/}} -{{- define "isolation-network-policy.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end }} - -{{/* -Lagoon Annotations -*/}} -{{- define "isolation-network-policy.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end }} diff --git a/legacy/helmcharts/isolation-network-policy/templates/networkpolicy.yaml b/legacy/helmcharts/isolation-network-policy/templates/networkpolicy.yaml deleted file mode 100644 index 17fdbcb9..00000000 --- a/legacy/helmcharts/isolation-network-policy/templates/networkpolicy.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: networking.k8s.io/v1 -kind: NetworkPolicy -metadata: - name: {{ include "isolation-network-policy.fullname" . }} - labels: - {{- include "isolation-network-policy.labels" . | nindent 4 }} - annotations: - {{- include "isolation-network-policy.annotations" . | nindent 4 }} -spec: - # empty podSelector applies this policy to _all_ pods in the current - # namespace. - podSelector: {} - ingress: - - from: - # empty ingress podSelector means traffic from _all_ pods in the current - # namespace are allowed ingress. - - podSelector: {} - # allow network traffic from cluster services - - namespaceSelector: - matchExpressions: - - key: lagoon.sh/environment - operator: DoesNotExist diff --git a/legacy/helmcharts/isolation-network-policy/values.yaml b/legacy/helmcharts/isolation-network-policy/values.yaml deleted file mode 100644 index 419dfa75..00000000 --- a/legacy/helmcharts/isolation-network-policy/values.yaml +++ /dev/null @@ -1 +0,0 @@ -nameOverride: "" diff --git a/legacy/helmcharts/kibana/Chart.yaml b/legacy/helmcharts/kibana/Chart.yaml deleted file mode 100644 index f52d5148..00000000 --- a/legacy/helmcharts/kibana/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: kibana -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/kibana/templates/_helpers.tpl b/legacy/helmcharts/kibana/templates/_helpers.tpl deleted file mode 100644 index a4e3a933..00000000 --- a/legacy/helmcharts/kibana/templates/_helpers.tpl +++ /dev/null @@ -1,83 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "kibana.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "kibana.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "kibana.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "kibana.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "kibana.labels" -}} -helm.sh/chart: {{ include "kibana.chart" . }} -{{ include "kibana.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "kibana.lagoonLabels" . }} - -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "kibana.selectorLabels" -}} -app.kubernetes.io/name: {{ include "kibana.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "kibana.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "kibana.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "kibana.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} \ No newline at end of file diff --git a/legacy/helmcharts/kibana/templates/cronjob.yaml b/legacy/helmcharts/kibana/templates/cronjob.yaml deleted file mode 100644 index 51027ee5..00000000 --- a/legacy/helmcharts/kibana/templates/cronjob.yaml +++ /dev/null @@ -1,100 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "kibana.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "kibana.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "kibana.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "kibana.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "kibana.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "kibana.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "kibana.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command | quote }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - tolerations: - - effect: NoSchedule - key: lagoon/build - operator: Exists - - effect: NoSchedule - key: lagoon.sh/build - operator: Exists - {{- toYaml $.Values.cronjobTolerations | nindent 12 }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/kibana/templates/deployment.yaml b/legacy/helmcharts/kibana/templates/deployment.yaml deleted file mode 100644 index 89262c55..00000000 --- a/legacy/helmcharts/kibana/templates/deployment.yaml +++ /dev/null @@ -1,83 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "kibana.fullname" . }} - labels: - {{- include "kibana.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "kibana.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "kibana.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "kibana.labels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "kibana.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- if .Values.dynamicSecretVolumes }} - volumes: - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - env: - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - envFrom: - - configMapRef: - name: lagoon-env - ports: - - name: 5601-tcp - containerPort: 5601 - protocol: TCP - readinessProbe: - tcpSocket: - port: 5601 - initialDelaySeconds: 20 - timeoutSeconds: 1 - livenessProbe: - tcpSocket: - port: 5601 - initialDelaySeconds: 120 - periodSeconds: 10 - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- if .Values.dynamicSecretMounts }} - volumeMounts: - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/kibana/templates/ingress.yaml b/legacy/helmcharts/kibana/templates/ingress.yaml deleted file mode 100644 index 7fdffd31..00000000 --- a/legacy/helmcharts/kibana/templates/ingress.yaml +++ /dev/null @@ -1,49 +0,0 @@ -{{- if .Values.routesAutogenerateEnabled -}} -{{- $fullName := include "kibana.fullname" . -}} -{{- $host := include "kibana.autogeneratedHost" . -}} -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: {{ $fullName }} - labels: - lagoon.sh/autogenerated: "true" - {{- include "kibana.labels" . | nindent 4 }} - annotations: - {{- if eq .Values.routesAutogenerateInsecure "Allow"}} - kibana.ingress.kubernetes.io/ssl-redirect: "false" - ingress.kubernetes.io/ssl-redirect: "false" - {{- else if eq .Values.routesAutogenerateInsecure "Redirect"}} - kibana.ingress.kubernetes.io/ssl-redirect: "true" - ingress.kubernetes.io/ssl-redirect: "true" - {{- else if eq .Values.routesAutogenerateInsecure "None"}} - kibana.ingress.kubernetes.io/ssl-redirect: "true" - ingress.kubernetes.io/ssl-redirect: "true" - {{- end }} - kubernetes.io/tls-acme: "true" - # use a specific fastly service - {{- if .Values.fastly.serviceId }} - fastly.amazee.io/service-id: "{{ .Values.fastly.serviceId }}" - {{- end }} - fastly.amazee.io/watch: "{{ .Values.fastly.watch }}" - # use a custom secret for this ingress (customer supplied fastly integration) - {{- if .Values.fastly.apiSecretName }} - fastly.amazee.io/api-secret-name: "{{ .Values.fastly.apiSecretName }}" - {{- end }} - {{- include "kibana.annotations" . | nindent 4 }} -spec: - tls: - - hosts: - - {{ $host | quote }} - secretName: {{ $fullName }}-tls - rules: - - host: {{ $host | quote }} - http: - paths: - - path: "/" - pathType: Prefix - backend: - service: - name: {{ $fullName }} - port: - number: {{ .Values.service.port }} -{{- end }} diff --git a/legacy/helmcharts/kibana/templates/service.yaml b/legacy/helmcharts/kibana/templates/service.yaml deleted file mode 100644 index 59bed683..00000000 --- a/legacy/helmcharts/kibana/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "kibana.fullname" . }} - labels: - {{- include "kibana.labels" . | nindent 4 }} - annotations: - {{- include "kibana.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: 5601 - protocol: TCP - name: 5601-tcp - selector: - {{- include "kibana.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/kibana/values.yaml b/legacy/helmcharts/kibana/values.yaml deleted file mode 100644 index 06cafd90..00000000 --- a/legacy/helmcharts/kibana/values.yaml +++ /dev/null @@ -1,93 +0,0 @@ -# Default values for kibana. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -serviceAccount: - # Specifies whether a service account should be created - create: true - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 5601 - -## example fastly block -fastly: - watch: false -# serviceId: '' -# apiSecretName: '' - -ingress: - enabled: false - annotations: {} - # kubernetes.io/ingress.class: kibana - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: [] - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -tls_acme: false -routesAutogenerateInsecure: Allow - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/logstash/.helmignore b/legacy/helmcharts/logstash/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/logstash/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/logstash/Chart.yaml b/legacy/helmcharts/logstash/Chart.yaml deleted file mode 100644 index 70af7d0a..00000000 --- a/legacy/helmcharts/logstash/Chart.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: v2 -name: logstash -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 - -# This is the version number of the application being deployed. This version number should be -# incremented each time you make changes to the application. -appVersion: 1.16.0 diff --git a/legacy/helmcharts/logstash/templates/_helpers.tpl b/legacy/helmcharts/logstash/templates/_helpers.tpl deleted file mode 100644 index 8e47c541..00000000 --- a/legacy/helmcharts/logstash/templates/_helpers.tpl +++ /dev/null @@ -1,82 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "logstash.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "logstash.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "logstash.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "logstash.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "logstash.labels" -}} -helm.sh/chart: {{ include "logstash.chart" . }} -{{ include "logstash.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "logstash.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "logstash.selectorLabels" -}} -app.kubernetes.io/name: {{ include "logstash.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "logstash.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "logstash.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "logstash.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/logstash/templates/cronjob.yaml b/legacy/helmcharts/logstash/templates/cronjob.yaml deleted file mode 100644 index bd78665d..00000000 --- a/legacy/helmcharts/logstash/templates/cronjob.yaml +++ /dev/null @@ -1,87 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "logstash.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "logstash.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "logstash.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "logstash.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "logstash.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "logstash.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "logstash.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/logstash/templates/deployment.yaml b/legacy/helmcharts/logstash/templates/deployment.yaml deleted file mode 100644 index 231815ea..00000000 --- a/legacy/helmcharts/logstash/templates/deployment.yaml +++ /dev/null @@ -1,85 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "logstash.fullname" . }} - labels: - {{- include "logstash.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "logstash.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "logstash.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "logstash.labels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "logstash.annotations" . | nindent 4 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- if .Values.dynamicSecretVolumes }} - volumes: - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - containers: - - name: {{ .Chart.Name | quote }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - image: {{ .Values.image | quote }} - imagePullPolicy: {{ .Values.imagePullPolicy | quote }} - env: - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ .Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - ports: - - name: 9600-tcp - containerPort: 9600 - protocol: TCP - readinessProbe: - tcpSocket: - port: 9600 - initialDelaySeconds: 10 - timeoutSeconds: 1 - periodSeconds: 10 - livenessProbe: - tcpSocket: - port: 9600 - initialDelaySeconds: 120 - timeoutSeconds: 1 - periodSeconds: 10 - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- if .Values.dynamicSecretMounts }} - volumeMounts: - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/logstash/templates/service.yaml b/legacy/helmcharts/logstash/templates/service.yaml deleted file mode 100644 index 52704a00..00000000 --- a/legacy/helmcharts/logstash/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "logstash.fullname" . }} - labels: - {{- include "logstash.labels" . | nindent 4 }} - annotations: - {{- include "logstash.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: 9600 - protocol: TCP - name: 9600-tcp - selector: - {{- include "logstash.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/logstash/values.yaml b/legacy/helmcharts/logstash/values.yaml deleted file mode 100644 index d19a2c55..00000000 --- a/legacy/helmcharts/logstash/values.yaml +++ /dev/null @@ -1,83 +0,0 @@ -# Default values for logstash. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" -environmentType: production - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -serviceAccount: - # Specifies whether a service account should be created - create: true - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 9600 - -ingress: - enabled: false - annotations: {} - # kubernetes.io/ingress.class: logstash - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: [] - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/mariadb-single/.helmignore b/legacy/helmcharts/mariadb-single/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/mariadb-single/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/mariadb-single/Chart.yaml b/legacy/helmcharts/mariadb-single/Chart.yaml deleted file mode 100644 index 9fa32fbb..00000000 --- a/legacy/helmcharts/mariadb-single/Chart.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: v2 -name: mariadb-single -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 - -# This is the version number of the application being deployed. This version number should be -# incremented each time you make changes to the application. -appVersion: 1.16.0 diff --git a/legacy/helmcharts/mariadb-single/templates/_helpers.tpl b/legacy/helmcharts/mariadb-single/templates/_helpers.tpl deleted file mode 100644 index 9e1332d1..00000000 --- a/legacy/helmcharts/mariadb-single/templates/_helpers.tpl +++ /dev/null @@ -1,91 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "mariadb-single.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "mariadb-single.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "mariadb-single.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "mariadb-single.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "mariadb-single.labels" -}} -helm.sh/chart: {{ include "mariadb-single.chart" . }} -{{ include "mariadb-single.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "mariadb-single.lagoonLabels" . }} -{{- end -}} - -{{/* -Add annotations -*/}} -{{- define "mariadb-single.annotations" -}} -{{ if .Values.annotations }} -{{- toYaml .Values.annotations }} -{{- end }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "mariadb-single.selectorLabels" -}} -app.kubernetes.io/name: {{ include "mariadb-single.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "mariadb-single.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "mariadb-single.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "mariadb-single" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} \ No newline at end of file diff --git a/legacy/helmcharts/mariadb-single/templates/cronjob.yaml b/legacy/helmcharts/mariadb-single/templates/cronjob.yaml deleted file mode 100644 index 19f60dd9..00000000 --- a/legacy/helmcharts/mariadb-single/templates/cronjob.yaml +++ /dev/null @@ -1,94 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "mariadb-single.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "mariadb-single.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "mariadb-single.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "mariadb-single.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "mariadb-single.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "mariadb-single.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "mariadb-single.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: {{ include "mariadb-single.fullname" $ }} - persistentVolumeClaim: - claimName: {{ include "mariadb-single.fullname" $ }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - name: {{ include "mariadb-single.fullname" $ }} - mountPath: {{ $.Values.persistentStorage.path | quote }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/mariadb-single/templates/deployment.yaml b/legacy/helmcharts/mariadb-single/templates/deployment.yaml deleted file mode 100644 index 02e6b9ac..00000000 --- a/legacy/helmcharts/mariadb-single/templates/deployment.yaml +++ /dev/null @@ -1,91 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "mariadb-single.fullname" . }} - labels: - {{- include "mariadb-single.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "mariadb-single.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: Recreate - selector: - matchLabels: - {{- include "mariadb-single.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "mariadb-single.labels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "mariadb-single.annotations" . | nindent 8 }} - k8up.syn.tools/backupcommand: /bin/sh -c 'mysqldump --max-allowed-packet=500M --events --routines --quick --add-locks --no-autocommit --single-transaction --all-databases' - k8up.syn.tools/file-extension: .{{ include "mariadb-single.fullname" . }}.sql - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ include "mariadb-single.fullname" . }} - persistentVolumeClaim: - claimName: {{ include "mariadb-single.fullname" . }} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image }}" - imagePullPolicy: {{ .Values.imagePullPolicy }} - env: - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - envFrom: - - configMapRef: - name: lagoon-env - ports: - - containerPort: 3306 - protocol: TCP - readinessProbe: - tcpSocket: - port: 3306 - initialDelaySeconds: 1 - timeoutSeconds: 1 - livenessProbe: - tcpSocket: - port: 3306 - initialDelaySeconds: 120 - periodSeconds: 5 - volumeMounts: - - name: {{ include "mariadb-single.fullname" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/mariadb-single/templates/pvc.yaml b/legacy/helmcharts/mariadb-single/templates/pvc.yaml deleted file mode 100644 index d0de3fdd..00000000 --- a/legacy/helmcharts/mariadb-single/templates/pvc.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: "{{ include "mariadb-single.fullname" . }}" - labels: - {{- include "mariadb-single.labels" . | nindent 4 }} - annotations: - {{- include "mariadb-single.annotations" . | nindent 4 }} - k8up.syn.tools/backup: "false" -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.persistentStorage.size | quote }} diff --git a/legacy/helmcharts/mariadb-single/templates/service.yaml b/legacy/helmcharts/mariadb-single/templates/service.yaml deleted file mode 100644 index 58c18c13..00000000 --- a/legacy/helmcharts/mariadb-single/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "mariadb-single.fullname" . }} - labels: - {{- include "mariadb-single.labels" . | nindent 4 }} - annotations: - {{- include "mariadb-single.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: 3306 - protocol: TCP - name: 3306-tcp - selector: - {{- include "mariadb-single.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/mariadb-single/values.yaml b/legacy/helmcharts/mariadb-single/values.yaml deleted file mode 100644 index e5fa05a8..00000000 --- a/legacy/helmcharts/mariadb-single/values.yaml +++ /dev/null @@ -1,91 +0,0 @@ -# Default values for mariadb-single. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" -environmentType: production -persistentStorage: - size: 5Gi - path: "/var/lib/mysql" - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -serviceAccount: - # Specifies whether a service account should be created - create: true - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: - -podSecurityContext: - fsGroup: 0 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 3306 - -ingress: - enabled: false - annotations: {} - # kubernetes.io/ingress.class: mariadb-single - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: [] - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -annotations: {} - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -tls_acme: false -routesAutogenerateInsecure: Allow - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/mongodb-single/.helmignore b/legacy/helmcharts/mongodb-single/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/mongodb-single/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/mongodb-single/Chart.yaml b/legacy/helmcharts/mongodb-single/Chart.yaml deleted file mode 100644 index 2b2cce92..00000000 --- a/legacy/helmcharts/mongodb-single/Chart.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: v2 -name: mongodb-single -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 - -# This is the version number of the application being deployed. This version number should be -# incremented each time you make changes to the application. -appVersion: 1.16.0 diff --git a/legacy/helmcharts/mongodb-single/templates/_helpers.tpl b/legacy/helmcharts/mongodb-single/templates/_helpers.tpl deleted file mode 100644 index b52874eb..00000000 --- a/legacy/helmcharts/mongodb-single/templates/_helpers.tpl +++ /dev/null @@ -1,91 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "mongodb-single.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "mongodb-single.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "mongodb-single.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "mongodb-single.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "mongodb-single.labels" -}} -helm.sh/chart: {{ include "mongodb-single.chart" . }} -{{ include "mongodb-single.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "mongodb-single.lagoonLabels" . }} -{{- end -}} - -{{/* -Add annotations -*/}} -{{- define "mongodb-single.annotations" -}} -{{ if .Values.annotations }} -{{- toYaml .Values.annotations }} -{{- end }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "mongodb-single.selectorLabels" -}} -app.kubernetes.io/name: {{ include "mongodb-single.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "mongodb-single.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "mongodb-single.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "mongodb-single" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/mongodb-single/templates/cronjob.yaml b/legacy/helmcharts/mongodb-single/templates/cronjob.yaml deleted file mode 100644 index 58f04950..00000000 --- a/legacy/helmcharts/mongodb-single/templates/cronjob.yaml +++ /dev/null @@ -1,94 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "mongodb-single.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "mongodb-single.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "mongodb-single.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "mongodb-single.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "mongodb-single.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "mongodb-single.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "mongodb-single.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: {{ include "mongodb-single.fullname" $ }} - persistentVolumeClaim: - claimName: {{ include "mongodb-single.fullname" $ }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - name: {{ include "mongodb-single.fullname" $ }} - mountPath: {{ $.Values.persistentStorage.path | quote }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/mongodb-single/templates/deployment.yaml b/legacy/helmcharts/mongodb-single/templates/deployment.yaml deleted file mode 100644 index 62f5b511..00000000 --- a/legacy/helmcharts/mongodb-single/templates/deployment.yaml +++ /dev/null @@ -1,86 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "mongodb-single.fullname" . }} - labels: - {{- include "mongodb-single.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "mongodb-single.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: Recreate - selector: - matchLabels: - {{- include "mongodb-single.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "mongodb-single.labels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "mongodb-single.annotations" . | nindent 8 }} - k8up.syn.tools/backupcommand: /bin/sh -c 'tar -cf - -C {{ .Values.persistentStorage.path | quote }} --exclude="lost\+found" . || [ $? -eq 1 ]' - k8up.syn.tools/file-extension: .{{ include "mongodb-single.fullname" . }}.tar - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ include "mongodb-single.fullname" . }} - persistentVolumeClaim: - claimName: {{ include "mongodb-single.fullname" . }} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image }}" - imagePullPolicy: {{ .Values.imagePullPolicy }} - env: - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - envFrom: - - configMapRef: - name: lagoon-env - ports: - - containerPort: 27017 - protocol: TCP - readinessProbe: - tcpSocket: - port: 27017 - initialDelaySeconds: 1 - timeoutSeconds: 1 - volumeMounts: - - name: {{ include "mongodb-single.fullname" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/mongodb-single/templates/pvc.yaml b/legacy/helmcharts/mongodb-single/templates/pvc.yaml deleted file mode 100644 index f918b19a..00000000 --- a/legacy/helmcharts/mongodb-single/templates/pvc.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: "{{ include "mongodb-single.fullname" . }}" - labels: - {{- include "mongodb-single.labels" . | nindent 4 }} - annotations: - {{- include "mongodb-single.annotations" . | nindent 4 }} - annotations: - k8up.syn.tools/backup: "false" -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.persistentStorage.size | quote }} diff --git a/legacy/helmcharts/mongodb-single/templates/service.yaml b/legacy/helmcharts/mongodb-single/templates/service.yaml deleted file mode 100644 index e0f8d76d..00000000 --- a/legacy/helmcharts/mongodb-single/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "mongodb-single.fullname" . }} - labels: - {{- include "mongodb-single.labels" . | nindent 4 }} - annotations: - {{- include "mongodb-single.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: 27017 - protocol: TCP - name: 27017-tcp - selector: - {{- include "mongodb-single.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/mongodb-single/values.yaml b/legacy/helmcharts/mongodb-single/values.yaml deleted file mode 100644 index eac54d35..00000000 --- a/legacy/helmcharts/mongodb-single/values.yaml +++ /dev/null @@ -1,91 +0,0 @@ -# Default values for mongodb-single. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" -environmentType: production -persistentStorage: - size: 5Gi - path: "/data/db" - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -serviceAccount: - # Specifies whether a service account should be created - create: true - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: - -podSecurityContext: - fsGroup: 0 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 27017 - -ingress: - enabled: false - annotations: {} - # kubernetes.io/ingress.class: mongodb-single - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: [] - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -annotations: {} - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -tls_acme: false -routesAutogenerateInsecure: Allow - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/nginx-php-persistent/.helmignore b/legacy/helmcharts/nginx-php-persistent/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/nginx-php-persistent/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/nginx-php-persistent/Chart.yaml b/legacy/helmcharts/nginx-php-persistent/Chart.yaml deleted file mode 100644 index 39116b1b..00000000 --- a/legacy/helmcharts/nginx-php-persistent/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: nginx-php-persistent -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/nginx-php-persistent/templates/_helpers.tpl b/legacy/helmcharts/nginx-php-persistent/templates/_helpers.tpl deleted file mode 100644 index 57d5420e..00000000 --- a/legacy/helmcharts/nginx-php-persistent/templates/_helpers.tpl +++ /dev/null @@ -1,150 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "nginx-php-persistent.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "nginx-php-persistent.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "nginx-php-persistent.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "nginx-php-persistent.autogeneratedHost" -}} -{{- if .root.Values.autogeneratedRouteDomain -}} -{{ if not .prefix }} -{{- printf "%s" .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s" .prefix .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- end -}} -{{- else -}} -{{ if not .prefix }} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s.%s" .prefix .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create short hostname for autogenerated hosts. -This is used to work around problems with long CN fields in certificates. -*/}} -{{- define "nginx-php-persistent.autogeneratedShortHost" -}} -{{- if .root.Values.shortAutogeneratedRouteDomain -}} -{{- printf "%s" .root.Values.shortAutogeneratedRouteDomain }} -{{- else -}} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateShortSuffix }} -{{- end -}} -{{- end }} - -{{/* -Generate name of Persistent Storage -Uses the Release Name (Lagoon Service Name) unless it's overwritten via .Values.persistentStorage.name -*/}} -{{- define "nginx-php-persistent.persistentStorageName" -}} -{{- default .Release.Name .Values.persistentStorage.name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "nginx-php-persistent.labels" -}} -helm.sh/chart: {{ include "nginx-php-persistent.chart" . }} -{{ include "nginx-php-persistent.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "nginx-php-persistent.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "nginx-php-persistent.selectorLabels" -}} -app.kubernetes.io/name: {{ include "nginx-php-persistent.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "nginx-php-persistent.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "nginx-php-persistent.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "nginx-php-persistent.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "nginx-php-persistent.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} - -{{/* -Generate name for twig storage emptyDir -*/}} -{{- define "nginx-php-persistent.twig-storage.name" -}} -{{- printf "%s-twig" (include "nginx-php-persistent.persistentStorageName" .) }} -{{- end -}} - -{{/* -Generate path for twig storage emptyDir -*/}} -{{- define "nginx-php-persistent.twig-storage.path" -}} -{{- printf "%s/php" .Values.persistentStorage.path }} -{{- end -}} - -{{/* -Merge resources from global over resources defined in the values -*/}} -{{- define "resources" -}} -{{- $value := dict -}} -{{- range (rest .) -}} - {{- $value = merge $value . -}} -{{- end -}} -{{- if $value -}} -{{- toYaml $value }} -{{- end }} -{{- end -}} \ No newline at end of file diff --git a/legacy/helmcharts/nginx-php-persistent/templates/cronjob.yaml b/legacy/helmcharts/nginx-php-persistent/templates/cronjob.yaml deleted file mode 100644 index 7a262edb..00000000 --- a/legacy/helmcharts/nginx-php-persistent/templates/cronjob.yaml +++ /dev/null @@ -1,101 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "nginx-php-persistent.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "nginx-php-persistent.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "nginx-php-persistent.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "nginx-php-persistent.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "nginx-php-persistent.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "nginx-php-persistent.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "nginx-php-persistent.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - - name: {{ $.Values.persistentStorage.name }} - persistentVolumeClaim: - claimName: {{ $.Values.persistentStorage.name }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - name: {{ $.Values.persistentStorage.name }} - mountPath: {{ $.Values.persistentStorage.path | quote }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/nginx-php-persistent/values.yaml b/legacy/helmcharts/nginx-php-persistent/values.yaml deleted file mode 100644 index 98f1ee06..00000000 --- a/legacy/helmcharts/nginx-php-persistent/values.yaml +++ /dev/null @@ -1,85 +0,0 @@ -# Default values for nginx. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -imageCache: "" -images: - nginx: "" - php: "" - -environmentType: production - -persistentStorage: - size: 5Gi - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: {} - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 8080 - -## example fastly block -fastly: - watch: false -# serviceId: '' -# apiSecretName: '' - -containerResources: - nginx: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - php: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 100Mi - -resources: {} - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/nginx-php/.helmignore b/legacy/helmcharts/nginx-php/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/nginx-php/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/nginx-php/Chart.yaml b/legacy/helmcharts/nginx-php/Chart.yaml deleted file mode 100644 index 6c7119b2..00000000 --- a/legacy/helmcharts/nginx-php/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: nginx-php -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/nginx-php/templates/_helpers.tpl b/legacy/helmcharts/nginx-php/templates/_helpers.tpl deleted file mode 100644 index 99605844..00000000 --- a/legacy/helmcharts/nginx-php/templates/_helpers.tpl +++ /dev/null @@ -1,128 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "nginx-php.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "nginx-php.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "nginx-php.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "nginx-php.autogeneratedHost" -}} -{{- if .root.Values.autogeneratedRouteDomain -}} -{{ if not .prefix }} -{{- printf "%s" .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s" .prefix .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- end -}} -{{- else -}} -{{ if not .prefix }} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s.%s" .prefix .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create short hostname for autogenerated hosts. -This is used to work around problems with long CN fields in certificates. -*/}} -{{- define "nginx-php.autogeneratedShortHost" -}} -{{- if .root.Values.shortAutogeneratedRouteDomain -}} -{{- printf "%s" .root.Values.shortAutogeneratedRouteDomain }} -{{- else -}} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateShortSuffix }} -{{- end -}} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "nginx-php.labels" -}} -helm.sh/chart: {{ include "nginx-php.chart" . }} -{{ include "nginx-php.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "nginx-php.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "nginx-php.selectorLabels" -}} -app.kubernetes.io/name: {{ include "nginx-php.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "nginx-php.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "nginx-php.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "nginx-php.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "nginx-php.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} - -{{/* -Merge resources from global over resources defined in the values -*/}} -{{- define "resources" -}} -{{- $value := dict -}} -{{- range (rest .) -}} - {{- $value = merge $value . -}} -{{- end -}} -{{- if $value -}} -{{- toYaml $value }} -{{- end }} -{{- end -}} \ No newline at end of file diff --git a/legacy/helmcharts/nginx-php/templates/cronjob.yaml b/legacy/helmcharts/nginx-php/templates/cronjob.yaml deleted file mode 100644 index 4d84a01d..00000000 --- a/legacy/helmcharts/nginx-php/templates/cronjob.yaml +++ /dev/null @@ -1,96 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "nginx-php.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "nginx-php.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "nginx-php.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "nginx-php.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "nginx-php.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "nginx-php.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "nginx-php.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/nginx-php/values.yaml b/legacy/helmcharts/nginx-php/values.yaml deleted file mode 100644 index b23fa64f..00000000 --- a/legacy/helmcharts/nginx-php/values.yaml +++ /dev/null @@ -1,82 +0,0 @@ -# Default values for nginx. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -images: - nginx: "" - php: "" - -environmentType: production - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 8080 - -## example fastly block -fastly: - watch: false -# serviceId: '' -# apiSecretName: '' - -containerResources: - nginx: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - php: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 100Mi - -resources: {} - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/nginx/.helmignore b/legacy/helmcharts/nginx/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/nginx/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/nginx/Chart.yaml b/legacy/helmcharts/nginx/Chart.yaml deleted file mode 100644 index 9c40f7a2..00000000 --- a/legacy/helmcharts/nginx/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: nginx -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/nginx/templates/_helpers.tpl b/legacy/helmcharts/nginx/templates/_helpers.tpl deleted file mode 100644 index c9b422e8..00000000 --- a/legacy/helmcharts/nginx/templates/_helpers.tpl +++ /dev/null @@ -1,115 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "nginx.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "nginx.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "nginx.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "nginx.autogeneratedHost" -}} -{{- if .root.Values.autogeneratedRouteDomain -}} -{{ if not .prefix }} -{{- printf "%s" .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s" .prefix .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- end -}} -{{- else -}} -{{ if not .prefix }} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s.%s" .prefix .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create short hostname for autogenerated hosts. -This is used to work around problems with long CN fields in certificates. -*/}} -{{- define "nginx.autogeneratedShortHost" -}} -{{- if .root.Values.shortAutogeneratedRouteDomain -}} -{{- printf "%s" .root.Values.shortAutogeneratedRouteDomain }} -{{- else -}} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateShortSuffix }} -{{- end -}} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "nginx.labels" -}} -helm.sh/chart: {{ include "nginx.chart" . }} -{{ include "nginx.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "nginx.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "nginx.selectorLabels" -}} -app.kubernetes.io/name: {{ include "nginx.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "nginx.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "nginx.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "nginx.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "nginx.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/nginx/templates/cronjob.yaml b/legacy/helmcharts/nginx/templates/cronjob.yaml deleted file mode 100644 index 2a9d8fb1..00000000 --- a/legacy/helmcharts/nginx/templates/cronjob.yaml +++ /dev/null @@ -1,96 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "nginx.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "nginx.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "nginx.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "nginx.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "nginx.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "nginx.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "nginx.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/nginx/values.yaml b/legacy/helmcharts/nginx/values.yaml deleted file mode 100644 index 33f3063d..00000000 --- a/legacy/helmcharts/nginx/values.yaml +++ /dev/null @@ -1,93 +0,0 @@ -# Default values for nginx. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -serviceAccount: - # Specifies whether a service account should be created - create: true - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 8080 - -## example fastly block -fastly: - watch: false -# serviceId: '' -# apiSecretName: '' - -ingress: - enabled: false - annotations: {} - # kubernetes.io/ingress.class: nginx - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: [] - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -tls_acme: false -routesAutogenerateInsecure: Allow - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/node-persistent/.helmignore b/legacy/helmcharts/node-persistent/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/node-persistent/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/node-persistent/Chart.yaml b/legacy/helmcharts/node-persistent/Chart.yaml deleted file mode 100644 index 372fa013..00000000 --- a/legacy/helmcharts/node-persistent/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: node-persistent -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/node-persistent/templates/_helpers.tpl b/legacy/helmcharts/node-persistent/templates/_helpers.tpl deleted file mode 100644 index 482b8b5b..00000000 --- a/legacy/helmcharts/node-persistent/templates/_helpers.tpl +++ /dev/null @@ -1,123 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "node-persistent.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "node-persistent.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "node-persistent.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "node-persistent.autogeneratedHost" -}} -{{- if .root.Values.autogeneratedRouteDomain -}} -{{ if not .prefix }} -{{- printf "%s" .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s" .prefix .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- end -}} -{{- else -}} -{{ if not .prefix }} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s.%s" .prefix .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create short hostname for autogenerated hosts. -This is used to work around problems with long CN fields in certificates. -*/}} -{{- define "node-persistent.autogeneratedShortHost" -}} -{{- if .root.Values.shortAutogeneratedRouteDomain -}} -{{- printf "%s" .root.Values.shortAutogeneratedRouteDomain }} -{{- else -}} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateShortSuffix }} -{{- end -}} -{{- end }} - -{{/* -Generate name of Persistent Storage -Uses the Release Name (Lagoon Service Name) unless it's overwritten via .Values.persistentStorage.name -*/}} -{{- define "node-persistent.persistentStorageName" -}} -{{- default .Release.Name .Values.persistentStorage.name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "node-persistent.labels" -}} -helm.sh/chart: {{ include "node-persistent.chart" . }} -{{ include "node-persistent.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "node-persistent.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "node-persistent.selectorLabels" -}} -app.kubernetes.io/name: {{ include "node-persistent.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "node-persistent.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "node-persistent.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "node-persistent.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "node-persistent.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/node-persistent/templates/cronjob.yaml b/legacy/helmcharts/node-persistent/templates/cronjob.yaml deleted file mode 100644 index b441913b..00000000 --- a/legacy/helmcharts/node-persistent/templates/cronjob.yaml +++ /dev/null @@ -1,101 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "node-persistent.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "node-persistent.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "node-persistent.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "node-persistent.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "node-persistent.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "node-persistent.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "node-persistent.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - - name: {{ $.Values.persistentStorage.name }} - persistentVolumeClaim: - claimName: {{ $.Values.persistentStorage.name }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - name: {{ $.Values.persistentStorage.name }} - mountPath: {{ $.Values.persistentStorage.path | quote }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/node-persistent/templates/deployment.yaml b/legacy/helmcharts/node-persistent/templates/deployment.yaml deleted file mode 100644 index d7bab4ab..00000000 --- a/legacy/helmcharts/node-persistent/templates/deployment.yaml +++ /dev/null @@ -1,91 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "node-persistent.fullname" . }} - labels: - {{- include "node-persistent.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "node-persistent.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "node-persistent.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "node-persistent.labels" . | nindent 8 }} - {{- include "node-persistent.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "node-persistent.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ include "node-persistent.persistentStorageName" . }} - persistentVolumeClaim: - claimName: {{ include "node-persistent.persistentStorageName" . }} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - priorityClassName: {{ include "node-persistent.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - name: http - containerPort: 3000 - protocol: TCP - readinessProbe: - tcpSocket: - port: 3000 - initialDelaySeconds: 1 - timeoutSeconds: 1 - livenessProbe: - tcpSocket: - port: 3000 - initialDelaySeconds: 60 - periodSeconds: 10 - env: - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - envFrom: - - configMapRef: - name: lagoon-env - volumeMounts: - - name: {{ include "node-persistent.persistentStorageName" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/node-persistent/templates/pvc.yaml b/legacy/helmcharts/node-persistent/templates/pvc.yaml deleted file mode 100644 index beea490c..00000000 --- a/legacy/helmcharts/node-persistent/templates/pvc.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "node-persistent.persistentStorageName" . }} - labels: - {{- include "node-persistent.labels" . | nindent 4 }} - annotations: - k8up.syn.tools/backup: "true" - {{- include "node-persistent.annotations" . | nindent 4 }} -spec: - accessModes: - - ReadWriteMany - storageClassName: bulk - resources: - requests: - storage: {{ .Values.persistentStorage.size | quote }} diff --git a/legacy/helmcharts/node-persistent/templates/service.yaml b/legacy/helmcharts/node-persistent/templates/service.yaml deleted file mode 100644 index b1b1f976..00000000 --- a/legacy/helmcharts/node-persistent/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "node-persistent.fullname" . }} - labels: - {{- include "node-persistent.labels" . | nindent 4 }} - annotations: - {{- include "node-persistent.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "node-persistent.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/node-persistent/values.yaml b/legacy/helmcharts/node-persistent/values.yaml deleted file mode 100644 index 0ce6dfef..00000000 --- a/legacy/helmcharts/node-persistent/values.yaml +++ /dev/null @@ -1,72 +0,0 @@ -# Default values for node-persistent. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production - -persistentStorage: - size: 5Gi - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: {} - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 3000 - -## example fastly block -fastly: - watch: false -# serviceId: '' -# apiSecretName: '' - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 100Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/node/.helmignore b/legacy/helmcharts/node/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/node/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/node/Chart.yaml b/legacy/helmcharts/node/Chart.yaml deleted file mode 100644 index 007a2732..00000000 --- a/legacy/helmcharts/node/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: node -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/node/templates/_helpers.tpl b/legacy/helmcharts/node/templates/_helpers.tpl deleted file mode 100644 index b4dbf3cd..00000000 --- a/legacy/helmcharts/node/templates/_helpers.tpl +++ /dev/null @@ -1,114 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "node.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "node.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "node.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "node.autogeneratedHost" -}} -{{- if .root.Values.autogeneratedRouteDomain -}} -{{ if not .prefix }} -{{- printf "%s" .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s" .prefix .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- end -}} -{{- else -}} -{{ if not .prefix }} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s.%s" .prefix .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create short hostname for autogenerated hosts. -This is used to work around problems with long CN fields in certificates. -*/}} -{{- define "node.autogeneratedShortHost" -}} -{{- if .root.Values.shortAutogeneratedRouteDomain -}} -{{- printf "%s" .root.Values.shortAutogeneratedRouteDomain }} -{{- else -}} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateShortSuffix }} -{{- end -}} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "node.labels" -}} -helm.sh/chart: {{ include "node.chart" . }} -{{ include "node.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "node.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "node.selectorLabels" -}} -app.kubernetes.io/name: {{ include "node.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "node.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "node.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "node.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} -{{/* -Annotations -*/}} -{{- define "node.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/node/templates/cronjob.yaml b/legacy/helmcharts/node/templates/cronjob.yaml deleted file mode 100644 index ec020437..00000000 --- a/legacy/helmcharts/node/templates/cronjob.yaml +++ /dev/null @@ -1,87 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "node.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "node.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "node.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "node.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "node.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "node.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "node.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/node/templates/deployment.yaml b/legacy/helmcharts/node/templates/deployment.yaml deleted file mode 100644 index 58572310..00000000 --- a/legacy/helmcharts/node/templates/deployment.yaml +++ /dev/null @@ -1,88 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "node.fullname" . }} - labels: - {{- include "node.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "node.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "node.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "node.labels" . | nindent 8 }} - {{- include "node.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "node.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - priorityClassName: {{ include "node.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- if .Values.dynamicSecretVolumes }} - volumes: - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - name: http - containerPort: 3000 - protocol: TCP - readinessProbe: - tcpSocket: - port: 3000 - initialDelaySeconds: 1 - timeoutSeconds: 1 - livenessProbe: - tcpSocket: - port: 3000 - initialDelaySeconds: 60 - periodSeconds: 10 - env: - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- if .Values.dynamicSecretMounts }} - volumeMounts: - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/node/templates/service.yaml b/legacy/helmcharts/node/templates/service.yaml deleted file mode 100644 index f29fd663..00000000 --- a/legacy/helmcharts/node/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "node.fullname" . }} - labels: - {{- include "node.labels" . | nindent 4 }} - annotations: - {{- include "node.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "node.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/node/values.yaml b/legacy/helmcharts/node/values.yaml deleted file mode 100644 index 8de3da33..00000000 --- a/legacy/helmcharts/node/values.yaml +++ /dev/null @@ -1,70 +0,0 @@ -# Default values for node. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 3000 - -## example fastly block -fastly: - watch: false -# serviceId: '' -# apiSecretName: '' - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 100Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/opensearch/.helmignore b/legacy/helmcharts/opensearch/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/opensearch/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/opensearch/Chart.yaml b/legacy/helmcharts/opensearch/Chart.yaml deleted file mode 100644 index 189bc1b8..00000000 --- a/legacy/helmcharts/opensearch/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: opensearch-persistent -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/opensearch/templates/_helpers.tpl b/legacy/helmcharts/opensearch/templates/_helpers.tpl deleted file mode 100644 index 61b63f61..00000000 --- a/legacy/helmcharts/opensearch/templates/_helpers.tpl +++ /dev/null @@ -1,99 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "opensearch.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "opensearch.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "opensearch.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "opensearch.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{/* -Generate name of Persistent Storage -Uses the Release Name (Lagoon Service Name) unless it's overwritten via .Values.persistentStorage.name -*/}} -{{- define "opensearch.persistentStorageName" -}} -{{- default .Release.Name .Values.persistentStorage.name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "opensearch.labels" -}} -helm.sh/chart: {{ include "opensearch.chart" . }} -{{ include "opensearch.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "opensearch.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "opensearch.selectorLabels" -}} -app.kubernetes.io/name: {{ include "opensearch.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "opensearch.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "opensearch.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "opensearch.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "opensearch.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/opensearch/templates/cronjob.yaml b/legacy/helmcharts/opensearch/templates/cronjob.yaml deleted file mode 100644 index c21b9188..00000000 --- a/legacy/helmcharts/opensearch/templates/cronjob.yaml +++ /dev/null @@ -1,87 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "opensearch.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "opensearch.annotations" . | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "opensearch.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "opensearch.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "opensearch.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "opensearch.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "opensearch.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/opensearch/templates/deployment.yaml b/legacy/helmcharts/opensearch/templates/deployment.yaml deleted file mode 100644 index 7acb586d..00000000 --- a/legacy/helmcharts/opensearch/templates/deployment.yaml +++ /dev/null @@ -1,99 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "opensearch.fullname" . }} - labels: - {{- include "opensearch.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "opensearch.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: Recreate - selector: - matchLabels: - {{- include "opensearch.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "opensearch.labels" . | nindent 8 }} - {{- include "opensearch.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "opensearch.annotations" . | nindent 8 }} - k8up.syn.tools/backupcommand: /bin/sh -c "tar -cf - -C {{ .Values.persistentStorage.path }} ." - k8up.syn.tools/file-extension: .{{ include "opensearch.fullname" . }}.tar - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ include "opensearch.persistentStorageName" . }} - persistentVolumeClaim: - claimName: {{ include "opensearch.persistentStorageName" . }} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - priorityClassName: {{ include "opensearch.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - initContainers: - # This init container sets the appropriate limits for mmap counts on the hosting node. - # https://opensearch.org/docs/latest/opensearch/install/important-settings/ - - name: set-max-map-count - image: {{ .Values.imageCache }}library/busybox:latest - imagePullPolicy: {{ .Values.imagePullPolicy }} - securityContext: - privileged: true - runAsUser: 0 - command: - - sh - - '-c' - - | - set -xe - DESIRED="262144" - CURRENT=$(sysctl -n vm.max_map_count) - if [ "$DESIRED" -gt "$CURRENT" ]; then - sysctl -w vm.max_map_count=$DESIRED - fi - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - ports: - - containerPort: 9200 - protocol: TCP - readinessProbe: - httpGet: - path: /_cluster/health?local=true - port: 9200 - initialDelaySeconds: 20 - livenessProbe: - httpGet: - path: /_cluster/health?local=true - port: 9200 - initialDelaySeconds: 120 - envFrom: - - configMapRef: - name: lagoon-env - env: - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - volumeMounts: - - name: {{ include "opensearch.persistentStorageName" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} diff --git a/legacy/helmcharts/opensearch/templates/pvc.yaml b/legacy/helmcharts/opensearch/templates/pvc.yaml deleted file mode 100644 index db2db2f0..00000000 --- a/legacy/helmcharts/opensearch/templates/pvc.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "opensearch.persistentStorageName" . }} - labels: - {{- include "opensearch.labels" . | nindent 4 }} - annotations: - k8up.syn.tools/backup: "false" - {{- include "opensearch.annotations" . | nindent 4 }} -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.persistentStorage.size | quote }} diff --git a/legacy/helmcharts/opensearch/templates/service.yaml b/legacy/helmcharts/opensearch/templates/service.yaml deleted file mode 100644 index 246c600a..00000000 --- a/legacy/helmcharts/opensearch/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "opensearch.fullname" . }} - labels: - {{- include "opensearch.labels" . | nindent 4 }} - annotations: - {{- include "opensearch.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: 9200 - protocol: TCP - name: 9200-tcp - selector: - {{- include "opensearch.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/opensearch/values.yaml b/legacy/helmcharts/opensearch/values.yaml deleted file mode 100644 index a8842b35..00000000 --- a/legacy/helmcharts/opensearch/values.yaml +++ /dev/null @@ -1,68 +0,0 @@ -# Default values for opensearch. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -imageCache: "" -image: "" - -environmentType: production -persistentStorage: - size: 5Gi - path: '/usr/share/opensearch/data' - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: - fsGroup: 0 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 9200 - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/postgres-single/.helmignore b/legacy/helmcharts/postgres-single/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/postgres-single/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/postgres-single/Chart.yaml b/legacy/helmcharts/postgres-single/Chart.yaml deleted file mode 100644 index 3d92547a..00000000 --- a/legacy/helmcharts/postgres-single/Chart.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: v2 -name: postgres-single -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 - -# This is the version number of the application being deployed. This version number should be -# incremented each time you make changes to the application. -appVersion: 1.16.0 diff --git a/legacy/helmcharts/postgres-single/templates/_helpers.tpl b/legacy/helmcharts/postgres-single/templates/_helpers.tpl deleted file mode 100644 index 06529fe3..00000000 --- a/legacy/helmcharts/postgres-single/templates/_helpers.tpl +++ /dev/null @@ -1,91 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "postgres-single.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "postgres-single.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "postgres-single.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "postgres-single.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "postgres-single.labels" -}} -helm.sh/chart: {{ include "postgres-single.chart" . }} -{{ include "postgres-single.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "postgres-single.lagoonLabels" . }} -{{- end -}} - -{{/* -Add annotations -*/}} -{{- define "postgres-single.annotations" -}} -{{ if .Values.annotations }} -{{- toYaml .Values.annotations }} -{{- end }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "postgres-single.selectorLabels" -}} -app.kubernetes.io/name: {{ include "postgres-single.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "postgres-single.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "postgres-single.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "postgres-single" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/postgres-single/templates/cronjob.yaml b/legacy/helmcharts/postgres-single/templates/cronjob.yaml deleted file mode 100644 index 58444cac..00000000 --- a/legacy/helmcharts/postgres-single/templates/cronjob.yaml +++ /dev/null @@ -1,94 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "postgres-single.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "postgres-single.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "postgres-single.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "postgres-single.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "postgres-single.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "postgres-single.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "postgres-single.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: {{ include "postgres-single.fullname" $ }} - persistentVolumeClaim: - claimName: {{ include "postgres-single.fullname" $ }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - name: {{ include "postgres-single.fullname" $ }} - mountPath: {{ $.Values.persistentStorage.path | quote }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/postgres-single/values.yaml b/legacy/helmcharts/postgres-single/values.yaml deleted file mode 100644 index 9b6dd22e..00000000 --- a/legacy/helmcharts/postgres-single/values.yaml +++ /dev/null @@ -1,91 +0,0 @@ -# Default values for postgres-single. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" -environmentType: production -persistentStorage: - size: 5Gi - path: "/var/lib/postgresql/data" - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -serviceAccount: - # Specifies whether a service account should be created - create: true - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: - -podSecurityContext: - fsGroup: 0 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 5432 - -ingress: - enabled: false - annotations: {} - # kubernetes.io/ingress.class: postgres-single - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: [] - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -annotations: {} - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -tls_acme: false -routesAutogenerateInsecure: Allow - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/python-persistent/.helmignore b/legacy/helmcharts/python-persistent/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/python-persistent/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/python-persistent/Chart.yaml b/legacy/helmcharts/python-persistent/Chart.yaml deleted file mode 100644 index 0f55f86f..00000000 --- a/legacy/helmcharts/python-persistent/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: python-persistent -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/python-persistent/templates/_helpers.tpl b/legacy/helmcharts/python-persistent/templates/_helpers.tpl deleted file mode 100644 index 84963b31..00000000 --- a/legacy/helmcharts/python-persistent/templates/_helpers.tpl +++ /dev/null @@ -1,115 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "python-persistent.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "python-persistent.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "python-persistent.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "python-persistent.autogeneratedHost" -}} -{{- if .root.Values.autogeneratedRouteDomain -}} -{{ if not .prefix }} -{{- printf "%s" .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s" .prefix .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- end -}} -{{- else -}} -{{ if not .prefix }} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s.%s" .prefix .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create short hostname for autogenerated hosts. -This is used to work around problems with long CN fields in certificates. -*/}} -{{- define "python-persistent.autogeneratedShortHost" -}} -{{- if .root.Values.shortAutogeneratedRouteDomain -}} -{{- printf "%s" .root.Values.shortAutogeneratedRouteDomain }} -{{- else -}} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateShortSuffix }} -{{- end -}} -{{- end }} - -{{/* -Generate name of Persistent Storage -Uses the Release Name (Lagoon Service Name) unless it's overwritten via .Values.persistentStorage.name -*/}} -{{- define "python-persistent.persistentStorageName" -}} -{{- default .Release.Name .Values.persistentStorage.name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - - -{{/* -Common labels -*/}} -{{- define "python-persistent.labels" -}} -helm.sh/chart: {{ include "python-persistent.chart" . }} -{{ include "python-persistent.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "python-persistent.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "python-persistent.selectorLabels" -}} -app.kubernetes.io/name: {{ include "python-persistent.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "python-persistent.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "python-persistent.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "python-persistent.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/python-persistent/templates/cronjob.yaml b/legacy/helmcharts/python-persistent/templates/cronjob.yaml deleted file mode 100644 index dbd0e71a..00000000 --- a/legacy/helmcharts/python-persistent/templates/cronjob.yaml +++ /dev/null @@ -1,101 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "python-persistent.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "python-persistent.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "python-persistent.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "python-persistent.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "python-persistent.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "python-persistent.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "python-persistent.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - - name: {{ $.Values.persistentStorage.name }} - persistentVolumeClaim: - claimName: {{ $.Values.persistentStorage.name }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - name: {{ $.Values.persistentStorage.name }} - mountPath: {{ $.Values.persistentStorage.path | quote }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/python-persistent/templates/deployment.yaml b/legacy/helmcharts/python-persistent/templates/deployment.yaml deleted file mode 100644 index 3b12923e..00000000 --- a/legacy/helmcharts/python-persistent/templates/deployment.yaml +++ /dev/null @@ -1,92 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "python-persistent.fullname" . }} - labels: - {{- include "python-persistent.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "python-persistent.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "python-persistent.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "python-persistent.labels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "python-persistent.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ include "python-persistent.persistentStorageName" . }} - persistentVolumeClaim: - claimName: {{ include "python-persistent.persistentStorageName" . }} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - priorityClassName: {{ include "python-persistent.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - name: http - containerPort: 8800 - protocol: TCP - readinessProbe: - tcpSocket: - port: 8800 - initialDelaySeconds: 15 - timeoutSeconds: 1 - livenessProbe: - tcpSocket: - port: 8800 - initialDelaySeconds: 60 - periodSeconds: 5 - env: - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - envFrom: - - configMapRef: - name: lagoon-env - volumeMounts: - - name: {{ include "python-persistent.persistentStorageName" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/python-persistent/templates/pvc.yaml b/legacy/helmcharts/python-persistent/templates/pvc.yaml deleted file mode 100644 index e8d620a6..00000000 --- a/legacy/helmcharts/python-persistent/templates/pvc.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "python-persistent.persistentStorageName" . }} - labels: - {{- include "python-persistent.labels" . | nindent 4 }} - annotations: - k8up.syn.tools/backup: "true" - {{- include "python-persistent.annotations" . | nindent 4 }} -spec: - accessModes: - - ReadWriteMany - storageClassName: bulk - resources: - requests: - storage: {{ .Values.persistentStorage.size | quote }} diff --git a/legacy/helmcharts/python-persistent/templates/service.yaml b/legacy/helmcharts/python-persistent/templates/service.yaml deleted file mode 100644 index 3caff428..00000000 --- a/legacy/helmcharts/python-persistent/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "python-persistent.fullname" . }} - labels: - {{- include "python-persistent.labels" . | nindent 4 }} - annotations: - {{- include "python-persistent.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "python-persistent.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/python-persistent/values.yaml b/legacy/helmcharts/python-persistent/values.yaml deleted file mode 100644 index 8bbdf7c4..00000000 --- a/legacy/helmcharts/python-persistent/values.yaml +++ /dev/null @@ -1,72 +0,0 @@ -# Default values for python-persistent. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production - -persistentStorage: - size: 5Gi - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: {} - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 8800 - -## example fastly block -fastly: - watch: false -# serviceId: '' -# apiSecretName: '' - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/python/.helmignore b/legacy/helmcharts/python/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/python/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/python/Chart.yaml b/legacy/helmcharts/python/Chart.yaml deleted file mode 100644 index f444d947..00000000 --- a/legacy/helmcharts/python/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: python -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/python/templates/_helpers.tpl b/legacy/helmcharts/python/templates/_helpers.tpl deleted file mode 100644 index 30ca3a4d..00000000 --- a/legacy/helmcharts/python/templates/_helpers.tpl +++ /dev/null @@ -1,106 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "python.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "python.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "python.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "python.autogeneratedHost" -}} -{{- if .root.Values.autogeneratedRouteDomain -}} -{{ if not .prefix }} -{{- printf "%s" .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s" .prefix .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- end -}} -{{- else -}} -{{ if not .prefix }} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s.%s" .prefix .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create short hostname for autogenerated hosts. -This is used to work around problems with long CN fields in certificates. -*/}} -{{- define "python.autogeneratedShortHost" -}} -{{- if .root.Values.shortAutogeneratedRouteDomain -}} -{{- printf "%s" .root.Values.shortAutogeneratedRouteDomain }} -{{- else -}} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateShortSuffix }} -{{- end -}} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "python.labels" -}} -helm.sh/chart: {{ include "python.chart" . }} -{{ include "python.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "python.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "python.selectorLabels" -}} -app.kubernetes.io/name: {{ include "python.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "python.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "python.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "python.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/python/templates/cronjob.yaml b/legacy/helmcharts/python/templates/cronjob.yaml deleted file mode 100644 index c417594f..00000000 --- a/legacy/helmcharts/python/templates/cronjob.yaml +++ /dev/null @@ -1,88 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "python.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "python.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "python.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "python.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "python.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "python.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: - {{- include "python.lagoonPriority" $ | nindent 12 }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/python/templates/deployment.yaml b/legacy/helmcharts/python/templates/deployment.yaml deleted file mode 100644 index e8a5b8db..00000000 --- a/legacy/helmcharts/python/templates/deployment.yaml +++ /dev/null @@ -1,87 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "python.fullname" . }} - labels: - {{- include "python.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "python.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - {{- include "python.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "python.labels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "python.annotations" . | nindent 8 }} - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - priorityClassName: {{ include "python.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- if .Values.dynamicSecretVolumes }} - volumes: - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - name: http - containerPort: 8800 - protocol: TCP - readinessProbe: - tcpSocket: - port: 8800 - initialDelaySeconds: 15 - timeoutSeconds: 1 - livenessProbe: - tcpSocket: - port: 8800 - initialDelaySeconds: 60 - periodSeconds: 5 - env: - ## LAGOON_GIT_SHA is injected directly and not loaded via `lagoon-env` config - ## This will cause the pod to redeploy on every deployment, even the files have not changed - - name: LAGOON_GIT_SHA - value: {{ .Values.gitSha | quote }} - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- if .Values.dynamicSecretMounts }} - volumeMounts: - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/legacy/helmcharts/python/templates/service.yaml b/legacy/helmcharts/python/templates/service.yaml deleted file mode 100644 index 86073d5d..00000000 --- a/legacy/helmcharts/python/templates/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "python.fullname" . }} - labels: - {{- include "python.labels" . | nindent 4 }} - annotations: - {{- include "python.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "python.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/python/values.yaml b/legacy/helmcharts/python/values.yaml deleted file mode 100644 index 7080bf0a..00000000 --- a/legacy/helmcharts/python/values.yaml +++ /dev/null @@ -1,70 +0,0 @@ -# Default values for python. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 8800 - -## example fastly block -fastly: - watch: false -# serviceId: '' -# apiSecretName: '' - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/rabbitmq/.helmignore b/legacy/helmcharts/rabbitmq/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/rabbitmq/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/rabbitmq/Chart.yaml b/legacy/helmcharts/rabbitmq/Chart.yaml deleted file mode 100644 index 5a449e4f..00000000 --- a/legacy/helmcharts/rabbitmq/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: rabbitmq -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/rabbitmq/templates/_helpers.tpl b/legacy/helmcharts/rabbitmq/templates/_helpers.tpl deleted file mode 100644 index 2332e3ca..00000000 --- a/legacy/helmcharts/rabbitmq/templates/_helpers.tpl +++ /dev/null @@ -1,99 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "rabbitmq.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "rabbitmq.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "rabbitmq.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "rabbitmq.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{/* -Generate name of Persistent Storage -Uses the Release Name (Lagoon Service Name) unless it's overwritten via .Values.persistentStorage.name -*/}} -{{- define "rabbitmq.persistentStorageName" -}} -{{- default .Release.Name .Values.persistentStorage.name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "rabbitmq.labels" -}} -helm.sh/chart: {{ include "rabbitmq.chart" . }} -{{ include "rabbitmq.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "rabbitmq.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "rabbitmq.selectorLabels" -}} -app.kubernetes.io/name: {{ include "rabbitmq.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "rabbitmq.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "rabbitmq.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "rabbitmq.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "rabbitmq.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/rabbitmq/templates/cronjob.yaml b/legacy/helmcharts/rabbitmq/templates/cronjob.yaml deleted file mode 100644 index f2abe773..00000000 --- a/legacy/helmcharts/rabbitmq/templates/cronjob.yaml +++ /dev/null @@ -1,87 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "rabbitmq.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "rabbitmq.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "rabbitmq.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "rabbitmq.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "rabbitmq.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "rabbitmq.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "rabbitmq.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/rabbitmq/templates/deployment.yaml b/legacy/helmcharts/rabbitmq/templates/deployment.yaml deleted file mode 100644 index 299e159d..00000000 --- a/legacy/helmcharts/rabbitmq/templates/deployment.yaml +++ /dev/null @@ -1,83 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "rabbitmq.fullname" . }} - labels: - {{- include "rabbitmq.labels" . | nindent 4 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "rabbitmq.annotations" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: Recreate - selector: - matchLabels: - {{- include "rabbitmq.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "rabbitmq.labels" . | nindent 8 }} - {{- include "rabbitmq.datadogLabels" . | nindent 8 }} - {{- if .Values.useSpot }} - lagoon.sh/spot: {{ .Values.useSpot | quote }} - {{- end }} - annotations: - {{- include "rabbitmq.annotations" . | nindent 8 }} - k8up.syn.tools/backupcommand: /bin/sh -c 'tar -cf - -C {{ .Values.persistentStorage.path | quote }} --exclude="lost\+found" . || [ $? -eq 1 ]' - k8up.syn.tools/file-extension: .{{ include "rabbitmq.fullname" . }}.tar - lagoon.sh/configMapSha: {{ .Values.configMapSha | quote }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - volumes: - - name: {{ include "rabbitmq.persistentStorageName" . }} - persistentVolumeClaim: - claimName: {{ include "rabbitmq.persistentStorageName" . }} - {{- if .Values.dynamicSecretVolumes }} - {{- toYaml .Values.dynamicSecretVolumes | nindent 8 }} - {{- end }} - priorityClassName: {{ include "rabbitmq.lagoonPriority" . }} - enableServiceLinks: false - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - image: {{ .Values.image | quote }} - name: {{ .Chart.Name }} - imagePullPolicy: {{ .Values.imagePullPolicy }} - ports: - - containerPort: 5672 - protocol: TCP - - containerPort: 15672 - protocol: TCP - readinessProbe: - tcpSocket: - port: 5672 - initialDelaySeconds: 1 - periodSeconds: 3 - livenessProbe: - tcpSocket: - port: 5672 - initialDelaySeconds: 90 - timeoutSeconds: 3 - failureThreshold: 5 - envFrom: - - configMapRef: - name: lagoon-env - env: - - name: CRONJOBS - value: {{ .Values.inPodCronjobs | toYaml | indent 14 | trim }} - - name: RABBITMQ_NODENAME - value: rabbitmq@localhost - volumeMounts: - - name: {{ include "rabbitmq.persistentStorageName" . }} - mountPath: {{ .Values.persistentStorage.path | quote }} - {{- if .Values.dynamicSecretMounts }} - {{- toYaml .Values.dynamicSecretMounts | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} diff --git a/legacy/helmcharts/rabbitmq/templates/pvc.yaml b/legacy/helmcharts/rabbitmq/templates/pvc.yaml deleted file mode 100644 index 6911adc5..00000000 --- a/legacy/helmcharts/rabbitmq/templates/pvc.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "rabbitmq.persistentStorageName" . }} - labels: - {{- include "rabbitmq.labels" . | nindent 4 }} - annotations: - k8up.syn.tools/backup: "false" - {{- include "rabbitmq.annotations" . | nindent 4 }} -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .Values.persistentStorage.size | quote }} diff --git a/legacy/helmcharts/rabbitmq/templates/service.yaml b/legacy/helmcharts/rabbitmq/templates/service.yaml deleted file mode 100644 index 7923e418..00000000 --- a/legacy/helmcharts/rabbitmq/templates/service.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "rabbitmq.fullname" . }} - labels: - {{- include "rabbitmq.labels" . | nindent 4 }} - annotations: - {{- include "rabbitmq.annotations" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: 5672 - protocol: TCP - name: tcp-5672 - - port: 15672 - targetPort: 15672 - protocol: TCP - name: tcp-15672 - selector: - {{- include "rabbitmq.selectorLabels" . | nindent 4 }} diff --git a/legacy/helmcharts/rabbitmq/values.yaml b/legacy/helmcharts/rabbitmq/values.yaml deleted file mode 100644 index a6ea8352..00000000 --- a/legacy/helmcharts/rabbitmq/values.yaml +++ /dev/null @@ -1,67 +0,0 @@ -# Default values for rabbitmq. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production -persistentStorage: - size: 5Gi - path: '/var/lib/rabbitmq' - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: - fsGroup: 0 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 5672 - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/redis-persistent/.helmignore b/legacy/helmcharts/redis-persistent/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/redis-persistent/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/redis-persistent/Chart.yaml b/legacy/helmcharts/redis-persistent/Chart.yaml deleted file mode 100644 index fccef181..00000000 --- a/legacy/helmcharts/redis-persistent/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: redis-persistent -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/redis-persistent/templates/_helpers.tpl b/legacy/helmcharts/redis-persistent/templates/_helpers.tpl deleted file mode 100644 index 84d0f03a..00000000 --- a/legacy/helmcharts/redis-persistent/templates/_helpers.tpl +++ /dev/null @@ -1,99 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "redis-persistent.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "redis-persistent.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "redis-persistent.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "redis-persistent.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{/* -Generate name of Persistent Storage -Uses the Release Name (Lagoon Service Name) unless it's overwritten via .Values.persistentStorage.name -*/}} -{{- define "redis-persistent.persistentStorageName" -}} -{{- default .Release.Name .Values.persistentStorage.name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "redis-persistent.labels" -}} -helm.sh/chart: {{ include "redis-persistent.chart" . }} -{{ include "redis-persistent.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "redis-persistent.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "redis-persistent.selectorLabels" -}} -app.kubernetes.io/name: {{ include "redis-persistent.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "redis-persistent.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "redis-persistent.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "redis-persistent.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "redis-persistent.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/redis-persistent/templates/cronjob.yaml b/legacy/helmcharts/redis-persistent/templates/cronjob.yaml deleted file mode 100644 index 37cfc4b4..00000000 --- a/legacy/helmcharts/redis-persistent/templates/cronjob.yaml +++ /dev/null @@ -1,94 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "redis-persistent.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "redis-persistent.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "redis-persistent.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "redis-persistent.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "redis-persistent.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "redis-persistent.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "redis-persistent.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: {{ $.Values.persistentStorage.name }} - persistentVolumeClaim: - claimName: {{ $.Values.persistentStorage.name }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - name: {{ $.Values.persistentStorage.name }} - mountPath: {{ $.Values.persistentStorage.path | quote }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/redis-persistent/values.yaml b/legacy/helmcharts/redis-persistent/values.yaml deleted file mode 100644 index dc8cf8ec..00000000 --- a/legacy/helmcharts/redis-persistent/values.yaml +++ /dev/null @@ -1,88 +0,0 @@ -# Default values for redis-persistent. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production - -persistentStorage: - size: 5Gi - path: "/data" - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -serviceAccount: - # Specifies whether a service account should be created - create: true - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 6379 - -ingress: - enabled: false - annotations: {} - # kubernetes.io/ingress.class: redis-persistent - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: [] - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/redis/.helmignore b/legacy/helmcharts/redis/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/redis/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/redis/Chart.yaml b/legacy/helmcharts/redis/Chart.yaml deleted file mode 100644 index aac566f7..00000000 --- a/legacy/helmcharts/redis/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: redis -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/redis/templates/_helpers.tpl b/legacy/helmcharts/redis/templates/_helpers.tpl deleted file mode 100644 index c029f115..00000000 --- a/legacy/helmcharts/redis/templates/_helpers.tpl +++ /dev/null @@ -1,91 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "redis.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "redis.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "redis.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "redis.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "redis.labels" -}} -helm.sh/chart: {{ include "redis.chart" . }} -{{ include "redis.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "redis.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "redis.selectorLabels" -}} -app.kubernetes.io/name: {{ include "redis.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "redis.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "redis.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "redis.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "redis.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/redis/templates/cronjob.yaml b/legacy/helmcharts/redis/templates/cronjob.yaml deleted file mode 100644 index 33ce28c5..00000000 --- a/legacy/helmcharts/redis/templates/cronjob.yaml +++ /dev/null @@ -1,87 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "redis.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "redis.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "redis.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "redis.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "redis.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "redis.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "redis.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/redis/values.yaml b/legacy/helmcharts/redis/values.yaml deleted file mode 100644 index a5159d1f..00000000 --- a/legacy/helmcharts/redis/values.yaml +++ /dev/null @@ -1,84 +0,0 @@ -# Default values for redis. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -serviceAccount: - # Specifies whether a service account should be created - create: true - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 6379 - -ingress: - enabled: false - annotations: {} - # kubernetes.io/ingress.class: redis - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: [] - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/solr/.helmignore b/legacy/helmcharts/solr/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/solr/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/solr/Chart.yaml b/legacy/helmcharts/solr/Chart.yaml deleted file mode 100644 index af9ab613..00000000 --- a/legacy/helmcharts/solr/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: solr-php-persistent -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/solr/templates/_helpers.tpl b/legacy/helmcharts/solr/templates/_helpers.tpl deleted file mode 100644 index 31002bbb..00000000 --- a/legacy/helmcharts/solr/templates/_helpers.tpl +++ /dev/null @@ -1,99 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "solr.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "solr.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "solr.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "solr.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{/* -Generate name of Persistent Storage -Uses the Release Name (Lagoon Service Name) unless it's overwritten via .Values.persistentStorage.name -*/}} -{{- define "solr.persistentStorageName" -}} -{{- default .Release.Name .Values.persistentStorage.name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "solr.labels" -}} -helm.sh/chart: {{ include "solr.chart" . }} -{{ include "solr.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "solr.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "solr.selectorLabels" -}} -app.kubernetes.io/name: {{ include "solr.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "solr.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "solr.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "solr.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "solr.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/solr/templates/cronjob.yaml b/legacy/helmcharts/solr/templates/cronjob.yaml deleted file mode 100644 index 77ea09a3..00000000 --- a/legacy/helmcharts/solr/templates/cronjob.yaml +++ /dev/null @@ -1,87 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "solr.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "solr.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "solr.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "solr.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "solr.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "solr.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "solr.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/solr/values.yaml b/legacy/helmcharts/solr/values.yaml deleted file mode 100644 index aafd7121..00000000 --- a/legacy/helmcharts/solr/values.yaml +++ /dev/null @@ -1,67 +0,0 @@ -# Default values for solr. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production -persistentStorage: - size: 5Gi - path: '/var/solr' - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: - fsGroup: 0 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 8983 - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/varnish-persistent/.helmignore b/legacy/helmcharts/varnish-persistent/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/varnish-persistent/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/varnish-persistent/Chart.yaml b/legacy/helmcharts/varnish-persistent/Chart.yaml deleted file mode 100644 index a7696342..00000000 --- a/legacy/helmcharts/varnish-persistent/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: varnish-persistent -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/varnish-persistent/templates/_helpers.tpl b/legacy/helmcharts/varnish-persistent/templates/_helpers.tpl deleted file mode 100644 index 5332275f..00000000 --- a/legacy/helmcharts/varnish-persistent/templates/_helpers.tpl +++ /dev/null @@ -1,123 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "varnish-persistent.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "varnish-persistent.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "varnish-persistent.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "varnish-persistent.autogeneratedHost" -}} -{{- if .root.Values.autogeneratedRouteDomain -}} -{{ if not .prefix }} -{{- printf "%s" .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s" .prefix .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- end -}} -{{- else -}} -{{ if not .prefix }} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s.%s" .prefix .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create short hostname for autogenerated hosts. -This is used to work around problems with long CN fields in certificates. -*/}} -{{- define "varnish-persistent.autogeneratedShortHost" -}} -{{- if .root.Values.shortAutogeneratedRouteDomain -}} -{{- printf "%s" .root.Values.shortAutogeneratedRouteDomain }} -{{- else -}} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateShortSuffix }} -{{- end -}} -{{- end }} - -{{/* -Generate name of Persistent Storage -Uses the Release Name (Lagoon Service Name) unless it's overwritten via .Values.persistentStorage.name -*/}} -{{- define "varnish-persistent.persistentStorageName" -}} -{{- default .Release.Name .Values.persistentStorage.name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "varnish-persistent.labels" -}} -helm.sh/chart: {{ include "varnish-persistent.chart" . }} -{{ include "varnish-persistent.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "varnish-persistent.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "varnish-persistent.selectorLabels" -}} -app.kubernetes.io/name: {{ include "varnish-persistent.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "varnish-persistent.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "varnish-persistent.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "varnish-persistent.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "varnish-persistent.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/varnish-persistent/templates/cronjob.yaml b/legacy/helmcharts/varnish-persistent/templates/cronjob.yaml deleted file mode 100644 index 882950c0..00000000 --- a/legacy/helmcharts/varnish-persistent/templates/cronjob.yaml +++ /dev/null @@ -1,94 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "varnish-persistent.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "varnish-persistent.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "varnish-persistent.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "varnish-persistent.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "varnish-persistent.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "varnish-persistent.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "varnish-persistent.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: {{ $.Values.persistentStorage.name }} - persistentVolumeClaim: - claimName: {{ $.Values.persistentStorage.name }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - name: {{ $.Values.persistentStorage.name }} - mountPath: {{ $.Values.persistentStorage.path | quote }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/varnish-persistent/values.yaml b/legacy/helmcharts/varnish-persistent/values.yaml deleted file mode 100644 index c5cce418..00000000 --- a/legacy/helmcharts/varnish-persistent/values.yaml +++ /dev/null @@ -1,92 +0,0 @@ -# Default values for varnish-persistent. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production - -persistentStorage: - size: 5Gi - path: "/var/cache/varnish" - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -serviceAccount: - # Specifies whether a service account should be created - create: true - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 8080 - -## example fastly block -fastly: - watch: false -# serviceId: '' -# apiSecretName: '' - -ingress: - enabled: false - annotations: {} - # kubernetes.io/ingress.class: varnish-persistent - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: [] - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/varnish/.helmignore b/legacy/helmcharts/varnish/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/varnish/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/varnish/Chart.yaml b/legacy/helmcharts/varnish/Chart.yaml deleted file mode 100644 index d8eb0355..00000000 --- a/legacy/helmcharts/varnish/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: varnish -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 diff --git a/legacy/helmcharts/varnish/templates/_helpers.tpl b/legacy/helmcharts/varnish/templates/_helpers.tpl deleted file mode 100644 index acf1e7a7..00000000 --- a/legacy/helmcharts/varnish/templates/_helpers.tpl +++ /dev/null @@ -1,115 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "varnish.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "varnish.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "varnish.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "varnish.autogeneratedHost" -}} -{{- if .root.Values.autogeneratedRouteDomain -}} -{{ if not .prefix }} -{{- printf "%s" .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s" .prefix .root.Values.autogeneratedRouteDomain | trimSuffix "-" -}} -{{- end -}} -{{- else -}} -{{ if not .prefix }} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s.%s.%s" .prefix .root.Release.Name .root.Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create short hostname for autogenerated hosts. -This is used to work around problems with long CN fields in certificates. -*/}} -{{- define "varnish.autogeneratedShortHost" -}} -{{- if .root.Values.shortAutogeneratedRouteDomain -}} -{{- printf "%s" .root.Values.shortAutogeneratedRouteDomain }} -{{- else -}} -{{- printf "%s.%s" .root.Release.Name .root.Values.routesAutogenerateShortSuffix }} -{{- end -}} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "varnish.labels" -}} -helm.sh/chart: {{ include "varnish.chart" . }} -{{ include "varnish.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "varnish.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "varnish.selectorLabels" -}} -app.kubernetes.io/name: {{ include "varnish.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "varnish.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "varnish.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "varnish.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "varnish.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/varnish/templates/cronjob.yaml b/legacy/helmcharts/varnish/templates/cronjob.yaml deleted file mode 100644 index eff2a006..00000000 --- a/legacy/helmcharts/varnish/templates/cronjob.yaml +++ /dev/null @@ -1,87 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "varnish.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "varnish.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "varnish.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "varnish.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "varnish.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "varnish.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "varnish.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/varnish/values.yaml b/legacy/helmcharts/varnish/values.yaml deleted file mode 100644 index 06f5094e..00000000 --- a/legacy/helmcharts/varnish/values.yaml +++ /dev/null @@ -1,88 +0,0 @@ -# Default values for varnish. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: "" - -environmentType: production - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -serviceAccount: - # Specifies whether a service account should be created - create: true - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 8080 - -## example fastly block -fastly: - watch: false -# serviceId: '' -# apiSecretName: '' - -ingress: - enabled: false - annotations: {} - # kubernetes.io/ingress.class: varnish - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: [] - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -resources: - # limits: - # cpu: 100m - # memory: 128Mi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/worker-persistent/.helmignore b/legacy/helmcharts/worker-persistent/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/worker-persistent/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/worker-persistent/Chart.yaml b/legacy/helmcharts/worker-persistent/Chart.yaml deleted file mode 100644 index 6ff73a6a..00000000 --- a/legacy/helmcharts/worker-persistent/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: worker-persistent -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 \ No newline at end of file diff --git a/legacy/helmcharts/worker-persistent/templates/_helpers.tpl b/legacy/helmcharts/worker-persistent/templates/_helpers.tpl deleted file mode 100644 index 9917de32..00000000 --- a/legacy/helmcharts/worker-persistent/templates/_helpers.tpl +++ /dev/null @@ -1,98 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "worker-persistent.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "worker-persistent.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "worker-persistent.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "worker-persistent.labels" -}} -helm.sh/chart: {{ include "worker-persistent.chart" . }} -{{ include "worker-persistent.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "worker-persistent.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "worker-persistent.selectorLabels" -}} -app.kubernetes.io/name: {{ include "worker-persistent.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "worker-persistent.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "worker-persistent.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "worker-persistent.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "worker-persistent.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} - -{{/* -Generate name for twig storage emptyDir -*/}} -{{- define "worker-persistent.twig-storage.name" -}} -{{- printf "%s-twig" .Values.persistentStorage.name }} -{{- end -}} - -{{/* -Generate path for twig storage emptyDir -*/}} -{{- define "worker-persistent.twig-storage.path" -}} -{{- printf "%s/php" .Values.persistentStorage.path }} -{{- end -}} diff --git a/legacy/helmcharts/worker-persistent/templates/cronjob.yaml b/legacy/helmcharts/worker-persistent/templates/cronjob.yaml deleted file mode 100644 index 643a414a..00000000 --- a/legacy/helmcharts/worker-persistent/templates/cronjob.yaml +++ /dev/null @@ -1,101 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "worker-persistent.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "worker-persistent.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "worker-persistent.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "worker-persistent.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "worker-persistent.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "worker-persistent.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "worker-persistent.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - - name: {{ $.Values.persistentStorage.name }} - persistentVolumeClaim: - claimName: {{ $.Values.persistentStorage.name }} - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - - name: {{ $.Values.persistentStorage.name }} - mountPath: {{ $.Values.persistentStorage.path | quote }} - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/worker-persistent/values.yaml b/legacy/helmcharts/worker-persistent/values.yaml deleted file mode 100644 index a0bfa83a..00000000 --- a/legacy/helmcharts/worker-persistent/values.yaml +++ /dev/null @@ -1,64 +0,0 @@ -# Default values for worker-persistent. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -environmentType: production - -gitSha: "" - -image: "" - -persistentStorage: - name: "" - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -podSecurityContext: {} - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -resources: - limits: - cpu: 2 - memory: 8Gi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] diff --git a/legacy/helmcharts/worker/.helmignore b/legacy/helmcharts/worker/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/worker/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/worker/Chart.yaml b/legacy/helmcharts/worker/Chart.yaml deleted file mode 100644 index b0b25c0d..00000000 --- a/legacy/helmcharts/worker/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: worker -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 \ No newline at end of file diff --git a/legacy/helmcharts/worker/templates/_helpers.tpl b/legacy/helmcharts/worker/templates/_helpers.tpl deleted file mode 100644 index 6103c370..00000000 --- a/legacy/helmcharts/worker/templates/_helpers.tpl +++ /dev/null @@ -1,84 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "worker.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "worker.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "worker.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "worker.labels" -}} -helm.sh/chart: {{ include "worker.chart" . }} -{{ include "worker.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "worker.lagoonLabels" . }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "worker.selectorLabels" -}} -app.kubernetes.io/name: {{ include "worker.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create a PriorityClassName. -(this is based on the Lagoon Environment Type)). -*/}} -{{- define "worker.lagoonPriority" -}} -{{- printf "lagoon-priority-%s" .Values.environmentType }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "worker.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Datadog Admission Controller label -*/}} -{{- define "worker.datadogLabels" -}} -{{- if eq .Values.environmentType "production" -}} -admission.datadoghq.com/enabled: "true" -{{- end -}} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "worker.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/worker/templates/cronjob.yaml b/legacy/helmcharts/worker/templates/cronjob.yaml deleted file mode 100644 index 54193c64..00000000 --- a/legacy/helmcharts/worker/templates/cronjob.yaml +++ /dev/null @@ -1,96 +0,0 @@ -{{- range $cronjobName, $cronjobConfig := .Values.nativeCronjobs }} ---- -apiVersion: batch/v1 -kind: CronJob -metadata: - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - labels: - {{- include "worker.labels" $ | nindent 4 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "worker.annotations" $ | nindent 4 }} -spec: - schedule: {{ $cronjobConfig.schedule | quote }} - concurrencyPolicy: Forbid - successfulJobsHistoryLimit: 0 - failedJobsHistoryLimit: 1 - startingDeadlineSeconds: 240 - jobTemplate: - metadata: - labels: - {{- include "worker.labels" $ | nindent 8 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "worker.annotations" $ | nindent 8 }} - spec: - backoffLimit: 0 - template: - metadata: - labels: - {{- include "worker.labels" $ | nindent 12 }} - {{- if $.Values.cronjobUseSpot }} - lagoon.sh/spot: {{ $.Values.cronjobUseSpot | quote }} - {{- end }} - annotations: - {{- include "worker.annotations" $ | nindent 12 }} - spec: - {{- with $.Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 12 }} - {{- end }} - priorityClassName: {{ include "worker.lagoonPriority" $ }} - enableServiceLinks: false - securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 12 }} - volumes: - - name: lagoon-sshkey - secret: - defaultMode: 420 - secretName: lagoon-sshkey - containers: - - image: {{ $.Values.image | quote }} - name: cronjob-{{ $.Release.Name }}-{{ $cronjobName }} - securityContext: - {{- toYaml $.Values.securityContext | nindent 16 }} - imagePullPolicy: {{ $.Values.imagePullPolicy }} - command: - - /lagoon/cronjob.sh - - {{ $cronjobConfig.command }} - env: - - name: LAGOON_GIT_SHA - value: {{ $.Values.gitSha | quote }} - - name: SERVICE_NAME - value: {{ $.Release.Name | quote }} - envFrom: - - configMapRef: - name: lagoon-env - resources: - {{- toYaml $.Values.resources | nindent 16 }} - volumeMounts: - - mountPath: /var/run/secrets/lagoon/sshkey/ - name: lagoon-sshkey - readOnly: true - restartPolicy: Never - {{- with $.Values.cronjobNodeSelector }} - nodeSelector: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobAffinity }} - affinity: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with $.Values.cronjobTolerations }} - tolerations: - {{- toYaml . | nindent 12 }} - {{- end }} - dnsConfig: - options: - - name: timeout - value: "60" - - name: attempts - value: "10" -{{- end }} diff --git a/legacy/helmcharts/worker/values.yaml b/legacy/helmcharts/worker/values.yaml deleted file mode 100644 index 4740a315..00000000 --- a/legacy/helmcharts/worker/values.yaml +++ /dev/null @@ -1,63 +0,0 @@ -# Default values for worker. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -environmentType: production - -gitSha: "" - -image: "" - -imagePullPolicy: Always - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -resources: - limits: - cpu: 2 - memory: 8Gi - requests: - cpu: 10m - memory: 10Mi - -nodeSelector: {} - -cronjobNodeSelector: {} - -tolerations: [] - -cronjobTolerations: [] - -affinity: {} - -cronjobAffinity: {} - -inPodCronjobs: "" - -nativeCronjobs: {} - -configMapSha: "" - -useSpot: false - -cronjobUseSpot: false - -dynamicSecretMounts: [] - -dynamicSecretVolumes: [] From 76199ebf54357ace332978c8c5affffec9c5ba49 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 12 Jan 2024 20:26:50 +1100 Subject: [PATCH 53/92] refactor: additional refactoring to support additional features from bash --- cmd/identify_imagebuild_test.go | 200 ++++++++-- cmd/template_lagoonservices.go | 18 + cmd/template_lagoonservices_test.go | 22 +- internal/generator/backups.go | 1 - internal/generator/buildvalues.go | 120 +++--- internal/generator/generator.go | 66 +++- internal/generator/services.go | 146 +++---- internal/helpers/helpers.go | 13 + internal/helpers/helpers_test.go | 42 ++ internal/lagoon/lagoon_test.go | 2 - internal/servicetypes/cli.go | 6 +- internal/servicetypes/elasticsearch.go | 4 +- internal/servicetypes/nginx.go | 10 +- internal/servicetypes/opensearch.go | 4 +- internal/servicetypes/postgres.go | 4 +- internal/servicetypes/rabbitmq.go | 105 +++++ internal/servicetypes/solr.go | 4 +- internal/servicetypes/types.go | 1 + .../networkpolicy/template_networkpolicy.go | 67 ++++ .../template_networkpolicy_test.go | 144 +++++++ .../test-resources/result-np-1.yaml | 24 ++ .../templating/services/templates_cronjob.go | 19 +- .../services/templates_deployment.go | 21 +- .../services/templates_deployment_test.go | 360 +++++++++++++++++- internal/templating/services/templates_pvc.go | 6 + .../templating/services/templates_pvc_test.go | 25 ++ .../deployment/result-mariadb-1.yaml | 78 ++++ .../deployment/result-mongodb-1.yaml | 77 ++++ .../deployment/result-node-1.yaml | 175 +++++++++ .../deployment/result-postgres-1.yaml | 96 +++++ .../deployment/result-python-1.yaml | 175 +++++++++ .../deployment/result-rabbitmq-1.yaml | 98 +++++ .../deployment/result-redis-1.yaml | 161 ++++++++ .../deployment/result-varnish-1.yaml | 164 ++++++++ .../deployment/result-worker-1.yaml | 168 ++++++++ .../test-resources/pvc/result-basic-2.yaml | 30 ++ .../test-resources/pvc/result-basic-3.yaml | 30 ++ .../service1/deployment-node.yaml | 1 + .../service2/deployment-lnd.yaml | 2 +- .../service2/deployment-thunderhub.yaml | 2 +- .../service2/deployment-tor.yaml | 2 +- .../service3/deployment-lnd.yaml | 2 +- .../service3/deployment-tor.yaml | 2 +- .../service5/isolation-network-policy.yaml | 26 ++ .../complex/docker-compose.varnish2.yml | 160 ++++++++ internal/testdata/complex/lagoon.varnish2.yml | 19 + .../cronjob-cronjob-cli-drush-cron2.yaml | 2 +- .../service1/deployment-cli.yaml | 2 +- .../service1/deployment-nginx-php.yaml | 4 +- .../service1/deployment-redis.yaml | 2 +- .../service1/deployment-varnish.yaml | 2 +- .../cronjob-cronjob-cli-drush-cron2.yaml | 2 +- .../service2/deployment-cli.yaml | 2 +- .../service2/deployment-nginx-php.yaml | 4 +- .../service2/deployment-redis.yaml | 2 +- .../service2/deployment-varnish.yaml | 2 +- internal/testdata/testdata.go | 4 + 57 files changed, 2706 insertions(+), 224 deletions(-) create mode 100644 internal/servicetypes/rabbitmq.go create mode 100644 internal/templating/networkpolicy/template_networkpolicy.go create mode 100644 internal/templating/networkpolicy/template_networkpolicy_test.go create mode 100644 internal/templating/networkpolicy/test-resources/result-np-1.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-mariadb-1.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-mongodb-1.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-node-1.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-postgres-1.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-python-1.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-redis-1.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-varnish-1.yaml create mode 100644 internal/templating/services/test-resources/deployment/result-worker-1.yaml create mode 100644 internal/templating/services/test-resources/pvc/result-basic-2.yaml create mode 100644 internal/templating/services/test-resources/pvc/result-basic-3.yaml create mode 100644 internal/testdata/basic/service-templates/service5/isolation-network-policy.yaml create mode 100644 internal/testdata/complex/docker-compose.varnish2.yml create mode 100644 internal/testdata/complex/lagoon.varnish2.yml diff --git a/cmd/identify_imagebuild_test.go b/cmd/identify_imagebuild_test.go index 57be5a76..e106abae 100644 --- a/cmd/identify_imagebuild_test.go +++ b/cmd/identify_imagebuild_test.go @@ -21,6 +21,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { description string args testdata.TestData want imageBuild + vars []helpers.EnvironmentVariable }{ { name: "test1 basic deployment", @@ -79,7 +80,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { "LAGOON_BUILD_TYPE": "branch", "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", "LAGOON_KUBERNETES": "remote-cluster1", - "LAGOON_GIT_SHA": "abcdefg123456", + "LAGOON_GIT_SHA": "0000000000000000000000000000000000000000", "LAGOON_GIT_BRANCH": "main", "CLI_IMAGE": "example-project-main-cli", "NGINX_IMAGE": "example-project-main-nginx", @@ -147,24 +148,30 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { Value: "enabled", Scope: "build", }, + { + Name: "LAGOON_FEATURE_FLAG_IMAGECACHE_REGISTRY", + Value: "imagecache.example.com", + Scope: "build", + }, }, }, true), want: imageBuild{ BuildKit: false, BuildArguments: map[string]string{ - "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD": "enabled", - "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", - "LAGOON_PROJECT": "example-project", - "LAGOON_ENVIRONMENT": "main", - "LAGOON_ENVIRONMENT_TYPE": "production", - "LAGOON_BUILD_TYPE": "branch", - "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", - "LAGOON_KUBERNETES": "remote-cluster1", - "LAGOON_GIT_SHA": "abcdefg123456", - "LAGOON_GIT_BRANCH": "main", - "CLI_IMAGE": "example-project-main-cli", - "NGINX_IMAGE": "example-project-main-nginx", - "PHP_IMAGE": "example-project-main-php", + "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD": "enabled", + "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", + "LAGOON_PROJECT": "example-project", + "LAGOON_ENVIRONMENT": "main", + "LAGOON_ENVIRONMENT_TYPE": "production", + "LAGOON_BUILD_TYPE": "branch", + "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", + "LAGOON_KUBERNETES": "remote-cluster1", + "LAGOON_GIT_SHA": "0000000000000000000000000000000000000000", + "LAGOON_GIT_BRANCH": "main", + "CLI_IMAGE": "example-project-main-cli", + "NGINX_IMAGE": "example-project-main-nginx", + "PHP_IMAGE": "example-project-main-php", + "LAGOON_FEATURE_FLAG_IMAGECACHE_REGISTRY": "imagecache.example.com", }, Images: []imageBuilds{ { @@ -195,13 +202,13 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { Name: "redis", ImageBuild: generator.ImageBuild{ BuildImage: "harbor.example/example-project/main/redis:latest", - PullImage: "amazeeio/redis", + PullImage: "imagecache.example.com/amazeeio/redis", }, }, { Name: "varnish", ImageBuild: generator.ImageBuild{ BuildImage: "harbor.example/example-project/main/varnish:latest", - PullImage: "uselagoon/varnish-5-drupal:latest", + PullImage: "imagecache.example.com/uselagoon/varnish-5-drupal:latest", }, }, }, @@ -235,7 +242,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { "LAGOON_BUILD_TYPE": "branch", "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", "LAGOON_KUBERNETES": "remote-cluster1", - "LAGOON_GIT_SHA": "abcdefg123456", + "LAGOON_GIT_SHA": "0000000000000000000000000000000000000000", "LAGOON_GIT_BRANCH": "main", "LND_IMAGE": "example-project-main-lnd", "THUNDERHUB_IMAGE": "example-project-main-thunderhub", @@ -304,7 +311,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { "LAGOON_BUILD_TYPE": "branch", "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", "LAGOON_KUBERNETES": "remote-cluster1", - "LAGOON_GIT_SHA": "abcdefg123456", + "LAGOON_GIT_SHA": "0000000000000000000000000000000000000000", "LAGOON_GIT_BRANCH": "main", "LND_IMAGE": "example-project-main-lnd", "TOR_IMAGE": "example-project-main-tor", @@ -351,17 +358,13 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { "LAGOON_BUILD_TYPE": "promote", "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", "LAGOON_KUBERNETES": "remote-cluster1", - "NODE_IMAGE": "example-project-main-node", }, Images: []imageBuilds{ { Name: "node", ImageBuild: generator.ImageBuild{ - BuildImage: "harbor.example/example-project/main/node:latest", - PromoteImage: "harbor.example/example-project/promote-main/node:latest", - Context: "internal/testdata/basic/docker", - DockerFile: "basic.dockerfile", - TemporaryImage: "example-project-main-node", + BuildImage: "harbor.example/example-project/main/node:latest", + PromoteImage: "harbor.example/example-project/promote-main/node:latest", }, }, }, @@ -416,9 +419,156 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { }, }, }, + { + name: "test7 nginx-php deployment promote", + args: testdata.GetSeedData( + testdata.TestData{ + Namespace: "example-project-main", + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + BuildType: "promote", + LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", + }, true), + want: imageBuild{ + BuildKit: false, + BuildArguments: map[string]string{ + "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", + "LAGOON_PROJECT": "example-project", + "LAGOON_ENVIRONMENT": "main", + "LAGOON_ENVIRONMENT_TYPE": "production", + "LAGOON_BUILD_TYPE": "promote", + "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", + "LAGOON_KUBERNETES": "remote-cluster1", + }, + Images: []imageBuilds{ + { + Name: "cli", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/cli:latest", + PromoteImage: "harbor.example/example-project/promote-main/cli:latest", + }, + }, { + Name: "nginx", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/nginx:latest", + PromoteImage: "harbor.example/example-project/promote-main/nginx:latest", + }, + }, { + Name: "php", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/php:latest", + PromoteImage: "harbor.example/example-project/promote-main/php:latest", + }, + }, { + Name: "redis", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/redis:latest", + PromoteImage: "harbor.example/example-project/promote-main/redis:latest", + }, + }, { + Name: "varnish", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/varnish:latest", + PromoteImage: "harbor.example/example-project/promote-main/varnish:latest", + }, + }, + }, + }, + }, + { + name: "test8 nginx-php external pull images", + vars: []helpers.EnvironmentVariable{ + { + Name: "EXTERNAL_REGISTRY_URLS", + Value: "registry1.example.com", + }, + }, + args: testdata.GetSeedData( + testdata.TestData{ + Namespace: "example-project-main", + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "internal/testdata/complex/lagoon.varnish2.yml", + // PrivateRegistryURLS: []string{ + // "registry1.example.com", + // }, + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_IMAGECACHE_REGISTRY", + Value: "imagecache.example.com", + Scope: "build", + }, + }, + }, true), + want: imageBuild{ + BuildKit: false, + BuildArguments: map[string]string{ + "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", + "LAGOON_PROJECT": "example-project", + "LAGOON_ENVIRONMENT": "main", + "LAGOON_ENVIRONMENT_TYPE": "production", + "LAGOON_BUILD_TYPE": "branch", + "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", + "LAGOON_KUBERNETES": "remote-cluster1", + "LAGOON_GIT_SHA": "0000000000000000000000000000000000000000", + "LAGOON_GIT_BRANCH": "main", + "CLI_IMAGE": "example-project-main-cli", + "NGINX_IMAGE": "example-project-main-nginx", + "PHP_IMAGE": "example-project-main-php", + "LAGOON_FEATURE_FLAG_IMAGECACHE_REGISTRY": "imagecache.example.com", + }, + Images: []imageBuilds{ + { + Name: "cli", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/cli:latest", + Context: "internal/testdata/complex/docker", + DockerFile: ".docker/Dockerfile.cli", + TemporaryImage: "example-project-main-cli", + }, + }, { + Name: "nginx", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/nginx:latest", + Context: "internal/testdata/complex/docker", + DockerFile: ".docker/Dockerfile.nginx-drupal", + TemporaryImage: "example-project-main-nginx", + }, + }, { + Name: "php", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/php:latest", + Context: "internal/testdata/complex/docker", + DockerFile: ".docker/Dockerfile.php", + TemporaryImage: "example-project-main-php", + }, + }, { + Name: "redis", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/redis:latest", + PullImage: "registry1.example.com/amazeeio/redis", + }, + }, { + Name: "varnish", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/varnish:latest", + PullImage: "imagecache.example.com/uselagoon/varnish-5-drupal:latest", + }, + }, + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + for _, envVar := range tt.vars { + err := os.Setenv(envVar.Name, envVar.Value) + if err != nil { + t.Errorf("%v", err) + } + } // set the environment variables from args savedTemplates := "testoutput" generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) @@ -451,7 +601,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { t.Errorf("returned output %v doesn't match want %v", string(oJ), string(wJ)) } t.Cleanup(func() { - helpers.UnsetEnvVars(nil) + helpers.UnsetEnvVars(tt.vars) }) }) } diff --git a/cmd/template_lagoonservices.go b/cmd/template_lagoonservices.go index d2d9b92b..4d4ac296 100644 --- a/cmd/template_lagoonservices.go +++ b/cmd/template_lagoonservices.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/cobra" generator "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/templating/networkpolicy" servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating/services" "sigs.k8s.io/yaml" ) @@ -123,6 +124,23 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { helpers.WriteTemplateFile(fmt.Sprintf("%s/cronjob-%s.yaml", savedTemplates, d.Name), restoreResult) } } + if lagoonBuild.BuildValues.IsolationNetworkPolicy { + // if isolation network policies are enabled, template that here + np, err := networkpolicy.GenerateNetworkPolicy(*lagoonBuild.BuildValues) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + npBytes, err := yaml.Marshal(np) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + separator := []byte("---\n") + restoreResult := append(separator[:], npBytes[:]...) + if g.Debug { + fmt.Println(fmt.Sprintf("Templating networkpolicy manifest %s", fmt.Sprintf("%s/isolation-network-policy.yaml", savedTemplates))) + } + helpers.WriteTemplateFile(fmt.Sprintf("%s/isolation-network-policy.yaml", savedTemplates), restoreResult) + } return nil } diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index 29fd5929..96e1023e 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -23,9 +23,16 @@ func TestTemplateLagoonServices(t *testing.T) { args testdata.TestData templatePath string want string + vars []helpers.EnvironmentVariable }{ { name: "test1 basic deployment", + vars: []helpers.EnvironmentVariable{ + { + Name: "EXTERNAL_REGISTRY_SECRETS", + Value: "lagoon-private-registry-custom-secret", + }, + }, args: testdata.GetSeedData( testdata.TestData{ ProjectName: "example-project", @@ -165,6 +172,13 @@ func TestTemplateLagoonServices(t *testing.T) { ImageReferences: map[string]string{ "node": "harbor.example/example-project/pr-123/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_ISOLATION_NETWORK_POLICY", + Value: "enabled", + Scope: "build", + }, + }, }, true), templatePath: "testoutput", want: "internal/testdata/basic/service-templates/service5", @@ -172,6 +186,12 @@ func TestTemplateLagoonServices(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + for _, envVar := range tt.vars { + err := os.Setenv(envVar.Name, envVar.Value) + if err != nil { + t.Errorf("%v", err) + } + } // set the environment variables from args savedTemplates := tt.templatePath generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) @@ -246,7 +266,7 @@ func TestTemplateLagoonServices(t *testing.T) { t.Errorf("resulting templates do not match") } t.Cleanup(func() { - helpers.UnsetEnvVars(nil) + helpers.UnsetEnvVars(tt.vars) }) }) } diff --git a/internal/generator/backups.go b/internal/generator/backups.go index f687372e..98627ca0 100644 --- a/internal/generator/backups.go +++ b/internal/generator/backups.go @@ -136,7 +136,6 @@ func generateBackupValues( // :end if buildValues.LagoonYAML.BackupRetention.Production.Hourly != nil && buildValues.EnvironmentType == "production" { - fmt.Println(*buildValues.LagoonYAML.BackupRetention.Production.Hourly) buildValues.Backup.PruneRetention.Hourly = *buildValues.LagoonYAML.BackupRetention.Production.Hourly } if buildValues.LagoonYAML.BackupRetention.Production.Daily != nil && buildValues.EnvironmentType == "production" { diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index 2de25e84..d79991cc 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -9,64 +9,66 @@ import ( // BuildValues is the values file data generated by the lagoon build type BuildValues struct { - SourceRepository string `json:"sourceRepository"` - BuildName string `json:"buildName"` - Project string `json:"project"` - Environment string `json:"environment"` - EnvironmentType string `json:"environmentType"` - Namespace string `json:"namespace"` - GitSHA string `json:"gitSha"` - BuildType string `json:"buildType"` - Kubernetes string `json:"kubernetes"` - LagoonVersion string `json:"lagoonVersion"` - ActiveEnvironment string `json:"activeEnvironment"` - StandbyEnvironment string `json:"standbyEnvironment"` - IsActiveEnvironment bool `json:"isActiveEnvironment"` - IsStandbyEnvironment bool `json:"isStandbyEnvironment"` - PodSecurityContext PodSecurityContext `json:"podSecurityContext"` - ImagePullSecrets []ImagePullSecrets `json:"imagePullSecrets"` - Branch string `json:"branch"` - PRNumber string `json:"prNumber"` - PRTitle string `json:"prTitle"` - PRHeadBranch string `json:"prHeadBranch"` - PRBaseBranch string `json:"prBaseBranch"` - PRHeadSHA string `json:"prHeadSHA"` - PRBaseSHA string `json:"prBaseSHA"` - PrivateRegistryURLS []string `json:"privateRegistryURLS"` - Fastly Fastly `json:"fastly"` - FastlyCacheNoCache string `json:"fastlyCacheNoCahce"` - FastlyAPISecretPrefix string `json:"fastlyAPISecretPrefix"` - ConfigMapSha string `json:"configMapSha"` - Route string `json:"route"` - Routes []string `json:"routes"` - AutogeneratedRoutes []string `json:"autogeneratedRoutes"` - RoutesAutogeneratePrefixes []string `json:"routesAutogeneratePrefixes"` - AutogeneratedRoutesFastly bool `json:"autogeneratedRoutesFastly"` - Services []ServiceValues `json:"services"` - Backup BackupConfiguration `json:"backup"` - Monitoring MonitoringConfig `json:"monitoring"` - DBaaSOperatorEndpoint string `json:"dbaasOperatorEndpoint"` - ServiceTypeOverrides *lagoon.EnvironmentVariable `json:"serviceTypeOverrides"` - DBaaSEnvironmentTypeOverrides *lagoon.EnvironmentVariable `json:"dbaasEnvironmentTypeOverrides"` - DBaaSFallbackSingle bool `json:"dbaasFallbackSingle"` - IngressClass string `json:"ingressClass"` - TaskScaleMaxIterations int `json:"taskScaleMaxIterations"` - TaskScaleWaitTime int `json:"taskScaleWaitTime"` - DynamicSecretMounts []DynamicSecretMounts `json:"dynamicSecretMounts"` - DynamicSecretVolumes []DynamicSecretVolumes `json:"dynamicSecretVolumes"` - ImageCache string `json:"imageCache"` - DefaultBackupSchedule string `json:"defaultBackupSchedule"` - DBaaSClient *dbaasclient.Client `json:"-"` - ImageReferences map[string]string `json:"imageReferences"` - Resources Resources `json:"resources"` - CronjobsDisabled bool `json:"cronjobsDisabled"` - FeatureFlags map[string]bool `json:"-"` - ImageRegistry string `json:"imageRegistry"` - DockerBuildKit bool `json:"dockerBuildKit"` - ImageBuildArguments map[string]string `json:"imageBuildArguments"` - EnvironmentVariables []lagoon.EnvironmentVariable `json:"environmentVariables"` - LagoonYAML lagoon.YAML `json:"lagoonYAML"` - PromotionSourceEnvironment string `json:"promotionSourceEnvironment"` + SourceRepository string `json:"sourceRepository" description:"the source repository for the project"` + BuildName string `json:"buildName" description:"the name of the build"` + Project string `json:"project" description:"the name of the project"` + Environment string `json:"environment" description:"the name of the environment, this is the safe version and may differ from the branch name"` + EnvironmentType string `json:"environmentType" description:"the type of the environment, production or development"` + Namespace string `json:"namespace" description:"the kubernetes namespace that this environment is built in"` + GitSHA string `json:"gitSha" description:"the git sha of this particular build"` + BuildType string `json:"buildType" description:"the type of build this is, branch, pullrequest, or promote"` + Kubernetes string `json:"kubernetes" description:"the name of the cluster that this hosts this environment"` + LagoonVersion string `json:"lagoonVersion" description:"the version of lagoon that started this build"` + ActiveEnvironment string `json:"activeEnvironment" activestandby:"true" description:"the current active environment"` + StandbyEnvironment string `json:"standbyEnvironment" activestandby:"true" description:"the current standby environment"` + IsActiveEnvironment bool `json:"isActiveEnvironment" activestandby:"true" description:"flag to determine if this environment is currently an active environment"` + IsStandbyEnvironment bool `json:"isStandbyEnvironment" activestandby:"true" description:"flag to determine if this environment is currently a standby environment"` + PodSecurityContext PodSecurityContext `json:"podSecurityContext" description:"stores the podsecuritycontext overrides"` + ImagePullSecrets []ImagePullSecrets `json:"imagePullSecrets" description:"stores any image pull secrets that the deployments in this environment need to know about"` + Branch string `json:"branch" buildtype:"branch" description:"the branch used for this environment"` + PRNumber string `json:"prNumber" buildtype:"pullrequest" description:"pullrequest number"` + PRTitle string `json:"prTitle" buildtype:"pullrequest" description:"title of the pullrequest"` + PRHeadBranch string `json:"prHeadBranch" buildtype:"pullrequest" description:"head branch of the pullrequest"` + PRBaseBranch string `json:"prBaseBranch" buildtype:"pullrequest" description:"base branch of the pullrequest"` + PRHeadSHA string `json:"prHeadSHA" buildtype:"pullrequest" description:"head sha of the pullrequest"` + PRBaseSHA string `json:"prBaseSHA" buildtype:"pullrequest" description:"base sha of the pullrequest"` + PrivateRegistryURLS []string `json:"privateRegistryURLS" description:"this stores all the private registry urls used by this environment"` + Fastly Fastly `json:"fastly" deprecated:"true" description:"this is the configuration of fastly for this environment"` + FastlyCacheNoCache string `json:"fastlyCacheNoCahce" deprecated:"true" description:"this is the service id of a fastly cache-no-cache service"` + FastlyAPISecretPrefix string `json:"fastlyAPISecretPrefix" deprecated:"true" description:"this is the fastly-api-secret prefix to use"` + ConfigMapSha string `json:"configMapSha" description:"this is the computed sha of the lagoon-env configmap, it is used to determine if changes are required to deployments"` + Route string `json:"route" description:"this stores the primary determiend route after all have been calculated"` + Routes []string `json:"routes" description:"this stores all routes after they are calculated"` + AutogeneratedRoutes []string `json:"autogeneratedRoutes" description:"this stores autogenerated routes after they are calculated"` + AutogeneratedRoutesFastly bool `json:"autogeneratedRoutesFastly" deprecated:"true" description:"the flag to determine if autogenerated routes should receive fastly annotations"` + Services []ServiceValues `json:"services" description:"stores all the computed values for all docker-compose services for this environment"` + Backup BackupConfiguration `json:"backup" description:"stores backup configuration"` + Monitoring MonitoringConfig `json:"monitoring" deprecated:"true" description:"stores monitoring configuration"` + DBaaSOperatorEndpoint string `json:"dbaasOperatorEndpoint" description:"the dbaas operator to use for provisioning a consumer"` + ServiceTypeOverrides *lagoon.EnvironmentVariable `json:"serviceTypeOverrides" description:"stores any service type overrides"` + DBaaSEnvironmentTypeOverrides *lagoon.EnvironmentVariable `json:"dbaasEnvironmentTypeOverrides" description:"stores any dbaas type overrides"` + DBaaSFallbackSingle bool `json:"dbaasFallbackSingle" description:"the fallback flag to define if a single pod should be used if no provider is found"` + IngressClass string `json:"ingressClass" description:"the ingress class used for this environment"` + TaskScaleMaxIterations int `json:"taskScaleMaxIterations" description:"the number of attempts to wait for pods to scale for pre and post rollout tasks"` + TaskScaleWaitTime int `json:"taskScaleWaitTime" description:"the time to wait for pods to scale for pre and post rollout tasks"` + DynamicSecretMounts []DynamicSecretMounts `json:"dynamicSecretMounts" description:"stores any dynamic secret mount definitions"` + DynamicSecretVolumes []DynamicSecretVolumes `json:"dynamicSecretVolumes" description:"stores any dynamic secret volume definitions"` + ImageCache string `json:"imageCache" description:"if an imagecache has been provided for images outside of the imageregistry"` + DefaultBackupSchedule string `json:"defaultBackupSchedule" description:"the default backup scheduled"` + DBaaSClient *dbaasclient.Client `json:"-" description:"used to store connection information for the dbaas operator endpoint"` + ImageReferences map[string]string `json:"imageReferences" description:"the post image build phase storage location of images for this build"` + Resources Resources `json:"resources" description:"this stores resource overrides for this environment"` + CronjobsDisabled bool `json:"cronjobsDisabled" description:"this controls whether cronjobs are enabled for this environment or not"` + FeatureFlags map[string]bool `json:"-" description:"these are used by templating systems to turn on or off certain functionality based on if feature flags are defined"` + ImageRegistry string `json:"imageRegistry" description:"the image registry in use for this environment, usually harbor"` + DockerBuildKit bool `json:"dockerBuildKit" description:"the flag to determine if docker buildkit is used"` + ImageBuildArguments map[string]string `json:"imageBuildArguments" description:"where the calculated image build arguments are stored"` + EnvironmentVariables []lagoon.EnvironmentVariable `json:"environmentVariables" description:"the merged project and environment variables for this environment"` + LagoonYAML lagoon.YAML `json:"lagoonYAML" description:"the unmarshalled lagoon yaml file"` + PromotionSourceEnvironment string `json:"promotionSourceEnvironment" buildtype:"promote" description:"the promotion source environment to pull images from"` + IsCI bool `json:"isCI" description:"this controls aspects of the environment or build depending on if a CI job"` + RWX2RWO bool `json:"RWX2RWO" description:"this controls whether the ReadWriteMany to ReadWriteOnce override should be used"` + IsolationNetworkPolicy bool `json:"isolationNetworkPolicy" description:"this controls whether isolation network policies should be enabled"` } type Resources struct { @@ -124,7 +126,7 @@ type DynamicSecret struct { // ServiceValues is the values for a specific service used by a lagoon build type ServiceValues struct { - Name string `json:"name"` // this is the actual compose service name + Name string `json:"name"` // the actual compose service name OverrideName string `json:"overrideName"` // if an override name is provided, use it Type string `json:"type"` AutogeneratedRoutesEnabled bool `json:"autogeneratedRoutesEnabled"` diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 417313bb..d3226b6c 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "net/url" "os" "strconv" "strings" @@ -61,11 +62,13 @@ type GeneratorInput struct { Debug bool DBaaSClient *dbaasclient.Client ImageReferences map[string]string - ImagePullSecret string + ImagePullSecrets []string Namespace string DefaultBackupSchedule string ImageRegistry string Kubernetes string + CI bool + PrivateRegistryURLS []string } func NewGenerator( @@ -108,6 +111,40 @@ func NewGenerator( gitSHA := helpers.GetEnv("LAGOON_GIT_SHA", generator.SourceRepository, generator.Debug) prHeadSHA := helpers.GetEnv("PR_HEAD_SHA", generator.PRHeadSHA, generator.Debug) prBaseSHA := helpers.GetEnv("PR_BASE_SHA", generator.PRBaseSHA, generator.Debug) + // get any external registry urls that this build has so we can update any pullthrough images accordingly + gExternalRegistryURLS := "" + if generator.PrivateRegistryURLS != nil { + gExternalRegistryURLS = strings.Join(generator.PrivateRegistryURLS, ",") + } + sExternalRegistryURLs := helpers.GetEnv("EXTERNAL_REGISTRY_URLS", gExternalRegistryURLS, generator.Debug) + if sExternalRegistryURLs != "" { + externalRegistryURLs := strings.Split(sExternalRegistryURLs, ",") + for _, eru := range externalRegistryURLs { + // strip the scheme, only provide the host + u, _ := url.Parse(eru) + if u.Host == "" { + eru = fmt.Sprintf("%s/", eru) + buildValues.PrivateRegistryURLS = append(buildValues.PrivateRegistryURLS, eru) + } else { + eru = fmt.Sprintf("%s/", u.Host) + buildValues.PrivateRegistryURLS = append(buildValues.PrivateRegistryURLS, eru) + } + } + } + // get any external registry secrets from the environment + gExternalRegistrySecrets := "" + if generator.PrivateRegistryURLS != nil { + gExternalRegistrySecrets = strings.Join(generator.ImagePullSecrets, ",") + } + sExternalRegistrySecrets := helpers.GetEnv("EXTERNAL_REGISTRY_SECRETS", gExternalRegistrySecrets, generator.Debug) + if sExternalRegistrySecrets != "" { + externalRegistrySecrets := strings.Split(sExternalRegistrySecrets, ",") + for _, ers := range externalRegistrySecrets { + buildValues.ImagePullSecrets = append(buildValues.ImagePullSecrets, ImagePullSecrets{Name: ers}) + } + } + // this is used by CI systems to influence builds, it is rarely used and should probably be abandoned + buildValues.IsCI = helpers.GetEnvBool("CI", generator.CI, generator.Debug) buildValues.ConfigMapSha = configMapSha buildValues.BuildName = buildName @@ -146,6 +183,9 @@ func NewGenerator( return nil, err } buildValues.LagoonYAML = *lYAML + if buildValues.LagoonYAML.EnvironmentVariables.GitSHA == nil || !*buildValues.LagoonYAML.EnvironmentVariables.GitSHA { + buildValues.GitSHA = "0000000000000000000000000000000000000000" + } //add the dbaas client to build values too buildValues.DBaaSClient = generator.DBaaSClient @@ -231,13 +271,30 @@ func NewGenerator( // this will later be used to add `runtime|global` scope into the `lagoon-env` configmap buildValues.EnvironmentVariables = lagoon.MergeVariables(mergedVariables, configVars) + // check for readwritemany to readwriteonce flag, disabled by default + rwx2rwo := CheckFeatureFlag("RWX_TO_RWO", buildValues.EnvironmentVariables, generator.Debug) + if rwx2rwo == "enabled" { + buildValues.RWX2RWO = true + } + + // check for isolation network policy, disabled by default + isolationNetworkPolicy := CheckFeatureFlag("ISOLATION_NETWORK_POLICY", buildValues.EnvironmentVariables, generator.Debug) + if isolationNetworkPolicy == "enabled" { + buildValues.IsolationNetworkPolicy = true + } + + // check for imagecache override, disabled by default imageCache := CheckFeatureFlag("IMAGECACHE_REGISTRY", buildValues.EnvironmentVariables, generator.Debug) if imageCache != "" { - if imageCache[len(imageCache)-1:] != "/" { + // strip the scheme, only provide the host + u, _ := url.Parse(imageCache) + if u.Host == "" { imageCache = fmt.Sprintf("%s/", imageCache) + } else { + imageCache = fmt.Sprintf("%s/", u.Host) } + buildValues.ImageCache = imageCache } - buildValues.ImageCache = imageCache // check the environment for INGRESS_CLASS flag, will be "" if there are none found ingressClass := CheckFeatureFlag("INGRESS_CLASS", buildValues.EnvironmentVariables, generator.Debug) @@ -466,6 +523,9 @@ func collectImageBuildArguments(buildValues BuildValues) map[string]string { } } // set the standard ones + if buildValues.IsCI { + buildArgs["IMAGE_REPO"] = "172.17.0.1:5000/lagoon" + } buildArgs["LAGOON_PROJECT"] = buildValues.Project buildArgs["LAGOON_ENVIRONMENT"] = buildValues.Environment buildArgs["LAGOON_ENVIRONMENT_TYPE"] = buildValues.EnvironmentType diff --git a/internal/generator/services.go b/internal/generator/services.go index 487ef95b..8e91f255 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -407,81 +407,89 @@ func composeToServiceValues( if !helpers.Contains(ignoredImageTypes, lagoonType) { // create a holder for all the docker related information, if this is a pull through image or a build image imageBuild := ImageBuild{} - // handle extracting the built image name from the provided image references - if composeServiceValues.Build != nil { - // if a build spec is defined, consume it - // set the dockerfile - imageBuild.DockerFile = composeServiceValues.Build.Dockerfile - // set the context if found, otherwise set '.' - imageBuild.Context = func(s string) string { - if s == "" { - return "." - } - return s - }(composeServiceValues.Build.Context) - // if there is a build target defined, set that here too - imageBuild.Target = composeServiceValues.Build.Target - } - // if there is a dockerfile defined in the - if buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Build.Dockerfile != "" { - imageBuild.DockerFile = buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Build.Dockerfile - if imageBuild.Context == "" { - // if we get here, it means that a dockerfile override was defined in the .lagoon.yml file - // but there was no `build` spec defined in the docker-compose file, so this just sets the context to the default `.` - // in the same way the legacy script used to do it - imageBuild.Context = "." - } - } - if imageBuild.DockerFile == "" { - // no dockerfile determined, this must be a pull through image - if composeServiceValues.Image == "" { - return ServiceValues{}, fmt.Errorf( - "defined Dockerfile or Image for service %s defined", composeService, - ) + // if this is not a promote environment, then attempt to work out the image build information that is required for the builder + if buildValues.BuildType != "promote" { + // handle extracting the built image name from the provided image references + if composeServiceValues.Build != nil { + // if a build spec is defined, consume it + // set the dockerfile + imageBuild.DockerFile = composeServiceValues.Build.Dockerfile + // set the context if found, otherwise set '.' + imageBuild.Context = func(s string) string { + if s == "" { + return "." + } + return s + }(composeServiceValues.Build.Context) + // if there is a build target defined, set that here too + imageBuild.Target = composeServiceValues.Build.Target } - // check docker-compose override image - pullImage := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.image") - // check lagoon.yml override image - if buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Image != "" { - pullImage = buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Image + // if there is a dockerfile defined in the + if buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Build.Dockerfile != "" { + imageBuild.DockerFile = buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Build.Dockerfile + if imageBuild.Context == "" { + // if we get here, it means that a dockerfile override was defined in the .lagoon.yml file + // but there was no `build` spec defined in the docker-compose file, so this just sets the context to the default `.` + // in the same way the legacy script used to do it + imageBuild.Context = "." + } } - if pullImage != "" { - // if an override image is provided, envsubst it - // not really sure why we do this, but legacy bash says `expand environment variables from ${OVERRIDE_IMAGE}` - // so there may be some undocumented functionality that allows people to use envvars in their image overrides? - evalImage, err := envsubst.EvalEnv(pullImage) - if err != nil { + if imageBuild.DockerFile == "" { + // no dockerfile determined, this must be a pull through image + if composeServiceValues.Image == "" { return ServiceValues{}, fmt.Errorf( - "error evaluating override image %s with envsubst", pullImage, + "defined Dockerfile or Image for service %s defined", composeService, ) } - // set the evalled image now - pullImage = evalImage - } else { - // else set the pullimage to whatever is defined in the docker-compose file otherwise - pullImage = composeServiceValues.Image - } - // if the image just is an image name (like "alpine") we prefix it with `libary/` as the imagecache does not understand - // the magic `alpine` image - if !strings.Contains(pullImage, "/") { - imageBuild.PullImage = fmt.Sprintf("library/%s", pullImage) + // check docker-compose override image + pullImage := lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.image") + // check lagoon.yml override image + if buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Image != "" { + pullImage = buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Image + } + if pullImage != "" { + // if an override image is provided, envsubst it + // not really sure why we do this, but legacy bash says `expand environment variables from ${OVERRIDE_IMAGE}` + // so there may be some undocumented functionality that allows people to use envvars in their image overrides? + evalImage, err := envsubst.EvalEnv(pullImage) + if err != nil { + return ServiceValues{}, fmt.Errorf( + "error evaluating override image %s with envsubst", pullImage, + ) + } + // set the evalled image now + pullImage = evalImage + } else { + // else set the pullimage to whatever is defined in the docker-compose file otherwise + pullImage = composeServiceValues.Image + } + // if the image just is an image name (like "alpine") we prefix it with `libary/` as the imagecache does not understand + // the magic `alpine` image + if !strings.Contains(pullImage, "/") { + imageBuild.PullImage = fmt.Sprintf("library/%s", pullImage) + } else { + imageBuild.PullImage = pullImage + } + if !helpers.ContainsR(buildValues.PrivateRegistryURLS, pullImage) { + if buildValues.ImageCache != "" { + imageBuild.PullImage = fmt.Sprintf("%s%s", buildValues.ImageCache, imageBuild.PullImage) + } + } } else { - imageBuild.PullImage = pullImage - } - } else { - // otherwise this must be an image build - // set temporary image to prevent clashes?? not sure this is even required, the temporary name is just as unique as the final image name eventually is - // so clashing would occur in both situations - imageBuild.TemporaryImage = fmt.Sprintf("%s-%s", buildValues.Namespace, composeService) //@TODO maybe get rid of this - if buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Build.Context != "" { - imageBuild.Context = buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Build.Context - } - // check the dockerfile exists - if _, err := os.Stat(fmt.Sprintf("%s/%s", imageBuild.Context, imageBuild.DockerFile)); errors.Is(err, os.ErrNotExist) { - return ServiceValues{}, fmt.Errorf( - "defined Dockerfile %s for service %s not found", - fmt.Sprintf("%s/%s", imageBuild.Context, imageBuild.DockerFile), composeService, - ) + // otherwise this must be an image build + // set temporary image to prevent clashes?? not sure this is even required, the temporary name is just as unique as the final image name eventually is + // so clashing would occur in both situations + imageBuild.TemporaryImage = fmt.Sprintf("%s-%s", buildValues.Namespace, composeService) //@TODO maybe get rid of this + if buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Build.Context != "" { + imageBuild.Context = buildValues.LagoonYAML.Environments[buildValues.Environment].Overrides[composeService].Build.Context + } + // check the dockerfile exists + if _, err := os.Stat(fmt.Sprintf("%s/%s", imageBuild.Context, imageBuild.DockerFile)); errors.Is(err, os.ErrNotExist) { + return ServiceValues{}, fmt.Errorf( + "defined Dockerfile %s for service %s not found", + fmt.Sprintf("%s/%s", imageBuild.Context, imageBuild.DockerFile), composeService, + ) + } } } // since we know what the final build image will be, we can set it here, this is what all images will be built as during the build diff --git a/internal/helpers/helpers.go b/internal/helpers/helpers.go index 3f5bc8a6..05e652c8 100644 --- a/internal/helpers/helpers.go +++ b/internal/helpers/helpers.go @@ -10,6 +10,7 @@ import ( "fmt" "html/template" "os" + "regexp" "strconv" "strings" @@ -165,6 +166,17 @@ func Contains(s []string, str string) bool { return false } +// ContainsR checks if a string slice contains a specific string regex match. +func ContainsR(regex []string, match string) bool { + for _, v := range regex { + m, _ := regexp.MatchString(v, match) + if m { + return true + } + } + return false +} + // WriteTemplateFile writes the template to a file. func WriteTemplateFile(templateOutputFile string, data []byte) { err := os.WriteFile(templateOutputFile, data, 0644) @@ -221,6 +233,7 @@ func UnsetEnvVars(localVars []EnvironmentVariable) { "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD", "DBAAS_OPERATOR_HTTP", "CONFIG_MAP_SHA", + "LAGOON_FEATURE_FLAG_IMAGECACHE_REGISTRY", } for _, varName := range varNames { os.Unsetenv(varName) diff --git a/internal/helpers/helpers_test.go b/internal/helpers/helpers_test.go index adc294ce..d7ec3d87 100644 --- a/internal/helpers/helpers_test.go +++ b/internal/helpers/helpers_test.go @@ -615,3 +615,45 @@ func TestGetNamespace(t *testing.T) { }) } } + +func TestContainsR(t *testing.T) { + type args struct { + s []string + match string + } + tests := []struct { + name string + args args + want bool + }{ + { + name: "test1", + args: args{ + s: []string{ + "registry1.example.com", + "registry2.example.com", + }, + match: "registry2.example.com/image/name/cli:latest", + }, + want: true, + }, + { + name: "test2", + args: args{ + s: []string{ + "registry1.example.com", + "registry2.example.com", + }, + match: "image/name/cli:latest", + }, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := ContainsR(tt.args.s, tt.args.match); got != tt.want { + t.Errorf("ContainsR() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/lagoon/lagoon_test.go b/internal/lagoon/lagoon_test.go index 92634a33..ba423ec5 100644 --- a/internal/lagoon/lagoon_test.go +++ b/internal/lagoon/lagoon_test.go @@ -463,8 +463,6 @@ func TestMergeLagoonYAMLs(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - //fmt.Println(tt.args.left) - //fmt.Println(tt.args.right) err := MergeLagoonYAMLs(tt.args.left, tt.args.right) got := tt.args.left if (err != nil) != tt.wantErr { diff --git a/internal/servicetypes/cli.go b/internal/servicetypes/cli.go index ba96f07d..ad3bd8df 100644 --- a/internal/servicetypes/cli.go +++ b/internal/servicetypes/cli.go @@ -63,14 +63,14 @@ var cliPersistent = ServiceType{ ImagePullPolicy: cli.PrimaryContainer.ImagePullPolicy, Container: cli.PrimaryContainer.Container, Volumes: append(cli.PrimaryContainer.Volumes, corev1.Volume{ - Name: "{{ .PersistentVolumeName }}-twig", + Name: "{{ .ServiceValues.PersistentVolumeName }}-twig", VolumeSource: corev1.VolumeSource{ EmptyDir: &corev1.EmptyDirVolumeSource{}, }, }), VolumeMounts: append(cli.PrimaryContainer.VolumeMounts, corev1.VolumeMount{ - Name: "{{ .PersistentVolumeName }}-twig", - MountPath: "{{ .PersistentVolumePath }}/php", + Name: "{{ .ServiceValues.PersistentVolumeName }}-twig", + MountPath: "{{ .ServiceValues.PersistentVolumePath }}/php", }), }, } diff --git a/internal/servicetypes/elasticsearch.go b/internal/servicetypes/elasticsearch.go index 5b1f7f2b..f38b646d 100644 --- a/internal/servicetypes/elasticsearch.go +++ b/internal/servicetypes/elasticsearch.go @@ -56,8 +56,8 @@ fi`, PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/usr/share/elasticsearch/data", BackupConfiguration: BackupConfiguration{ - Command: `/bin/sh -c "tar -cf - -C /usr/share/elasticsearch/data ."`, - FileExtension: ".{{ .OverrideName }}.tar", + Command: `/bin/sh -c "tar -cf - -C {{ if .ServiceValues.PersistentVolumePath }}{{.ServiceValues.PersistentVolumePath}}{{else}}{{.ServiceTypeValues.Volumes.PersistentVolumePath}}{{end}} ."`, + FileExtension: ".{{ .ServiceValues.OverrideName }}.tar", }, }, } diff --git a/internal/servicetypes/nginx.go b/internal/servicetypes/nginx.go index 326932cf..48cd6d3a 100644 --- a/internal/servicetypes/nginx.go +++ b/internal/servicetypes/nginx.go @@ -198,7 +198,7 @@ var nginxPHPPersistent = ServiceType{ `set -e SENTINEL="/storage/.lagoon-rootless-migration-complete" if ! [ -f "$SENTINEL" ]; then - find /storage -exec chown {{ .PodSecurityContext.RunAsUser}}:0 {} + + find /storage -exec chown {{ .ServiceValues.PodSecurityContext.RunAsUser}}:0 {} + find /storage -exec chmod a+r,u+w {} + find /storage -type d -exec chmod a+x {} + touch "$SENTINEL" @@ -214,7 +214,7 @@ fi`, }, VolumeMounts: []corev1.VolumeMount{ { - Name: "{{ .PersistentVolumeName }}", + Name: "{{ .ServiceValues.PersistentVolumeName }}", MountPath: "/storage", }, }, @@ -230,7 +230,7 @@ fi`, Container: nginxPHP.SecondaryContainer.Container, Volumes: []corev1.Volume{ { - Name: "{{ .PersistentVolumeName }}-twig", + Name: "{{ .ServiceValues.PersistentVolumeName }}-twig", VolumeSource: corev1.VolumeSource{ EmptyDir: &corev1.EmptyDirVolumeSource{}, }, @@ -238,8 +238,8 @@ fi`, }, VolumeMounts: []corev1.VolumeMount{ { - Name: "{{ .PersistentVolumeName }}-twig", - MountPath: "{{ .PersistentVolumePath }}/php", + Name: "{{ .ServiceValues.PersistentVolumeName }}-twig", + MountPath: "{{ .ServiceValues.PersistentVolumePath }}/php", }, }, }, diff --git a/internal/servicetypes/opensearch.go b/internal/servicetypes/opensearch.go index b70a508c..fbc449b0 100644 --- a/internal/servicetypes/opensearch.go +++ b/internal/servicetypes/opensearch.go @@ -60,8 +60,8 @@ fi`, PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/usr/share/opensearch/data", BackupConfiguration: BackupConfiguration{ - Command: `/bin/sh -c "tar -cf - -C /usr/share/opensearch/data ."`, - FileExtension: ".{{ .OverrideName }}.tar", + Command: `/bin/sh -c "tar -cf - -C {{ if .ServiceValues.PersistentVolumePath }}{{.ServiceValues.PersistentVolumePath}}{{else}}{{.ServiceTypeValues.Volumes.PersistentVolumePath}}{{end}} ."`, + FileExtension: ".{{ .ServiceValues.OverrideName }}.tar", }, }, } diff --git a/internal/servicetypes/postgres.go b/internal/servicetypes/postgres.go index f4657bbd..1e327a40 100644 --- a/internal/servicetypes/postgres.go +++ b/internal/servicetypes/postgres.go @@ -81,8 +81,8 @@ var postgresSingle = ServiceType{ PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/var/lib/postgresql/data", BackupConfiguration: BackupConfiguration{ - Command: `/bin/sh -c "PGPASSWORD=${{ .OverrideName | FixServiceName }}_PASSWORD pg_dump --host=localhost --port=${{ .OverrideName | FixServiceName }}_SERVICE_PORT --dbname=${{ .OverrideName | FixServiceName }}_DB --username=${{ .OverrideName | FixServiceName }}_USER --format=t -w"`, - FileExtension: ".{{ .OverrideName }}.tar", + Command: `/bin/sh -c "PGPASSWORD=${{ .ServiceValues.OverrideName | FixServiceName }}_PASSWORD pg_dump --host=localhost --port=${{ .ServiceValues.OverrideName | FixServiceName }}_SERVICE_PORT --dbname=${{ .ServiceValues.OverrideName | FixServiceName }}_DB --username=${{ .ServiceValues.OverrideName | FixServiceName }}_USER --format=t -w"`, + FileExtension: ".{{ .ServiceValues.OverrideName }}.tar", }, }, } diff --git a/internal/servicetypes/rabbitmq.go b/internal/servicetypes/rabbitmq.go new file mode 100644 index 00000000..a411b08a --- /dev/null +++ b/internal/servicetypes/rabbitmq.go @@ -0,0 +1,105 @@ +package servicetypes + +import ( + "fmt" + + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/apimachinery/pkg/util/intstr" +) + +var defaultRabbitMQPort int32 = 5672 +var defaultRabbitMQWebPort int32 = 15672 + +var rabbitmq = ServiceType{ + Name: "rabbitmq", + Ports: ServicePorts{ + Ports: []corev1.ServicePort{ + { + Port: defaultRabbitMQPort, + TargetPort: intstr.IntOrString{ + Type: intstr.Int, + IntVal: defaultRabbitMQPort, + }, + Protocol: corev1.ProtocolTCP, + Name: fmt.Sprintf("%d-tcp", defaultRabbitMQPort), + }, + { + Port: defaultRabbitMQWebPort, + TargetPort: intstr.IntOrString{ + Type: intstr.Int, + IntVal: defaultRabbitMQWebPort, + }, + Protocol: corev1.ProtocolTCP, + Name: fmt.Sprintf("%d-tcp", defaultRabbitMQWebPort), + }, + }, + }, + PrimaryContainer: ServiceContainer{ + Name: "rabbitmq", + ImagePullPolicy: corev1.PullAlways, + Container: corev1.Container{ + Ports: []corev1.ContainerPort{ + { + Name: fmt.Sprintf("%d-tcp", defaultRabbitMQPort), + ContainerPort: defaultRabbitMQPort, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: defaultRabbitMQPort, + }, + }, + }, + InitialDelaySeconds: 1, + PeriodSeconds: 3, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: defaultRabbitMQPort, + }, + }, + }, + InitialDelaySeconds: 90, + TimeoutSeconds: 3, + FailureThreshold: 5, + }, + Env: []corev1.EnvVar{ + { + Name: "RABBITMQ_NODENAME", + Value: "rabbitmq@localhost", + }, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("100M"), + }, + }, + }, + }, + PodSecurityContext: ServicePodSecurityContext{ + HasDefault: true, + FSGroup: 0, + }, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RecreateDeploymentStrategyType, + }, + Volumes: ServiceVolume{ + PersistentVolumeSize: "5Gi", + PersistentVolumeType: corev1.ReadWriteOnce, + PersistentVolumePath: "/var/lib/rabbitmq", + BackupConfiguration: BackupConfiguration{ + Command: `/bin/sh -c 'tar -cf - -C "{{ if .ServiceValues.PersistentVolumePath }}{{.ServiceValues.PersistentVolumePath}}{{else}}{{.ServiceTypeValues.Volumes.PersistentVolumePath}}{{end}}" --exclude="lost\+found" . || [ $? -eq 1 ]'`, + FileExtension: ".{{ .ServiceValues.OverrideName }}.tar", + }, + }, +} diff --git a/internal/servicetypes/solr.go b/internal/servicetypes/solr.go index 93d87fe0..9b35f21b 100644 --- a/internal/servicetypes/solr.go +++ b/internal/servicetypes/solr.go @@ -74,8 +74,8 @@ var solr = ServiceType{ PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/var/solr", BackupConfiguration: BackupConfiguration{ - Command: `/bin/sh -c 'tar -cf - -C "/var/solr" --exclude="lost\+found" . || [ $? -eq 1 ]'`, - FileExtension: ".{{ .OverrideName }}.tar", + Command: `/bin/sh -c 'tar -cf - -C "{{ if .ServiceValues.PersistentVolumePath }}{{.ServiceValues.PersistentVolumePath}}{{else}}{{.ServiceTypeValues.Volumes.PersistentVolumePath}}{{end}}" --exclude="lost\+found" . || [ $? -eq 1 ]'`, + FileExtension: ".{{ .ServiceValues.OverrideName }}.tar", }, }, } diff --git a/internal/servicetypes/types.go b/internal/servicetypes/types.go index 946f7cd9..57d55745 100644 --- a/internal/servicetypes/types.go +++ b/internal/servicetypes/types.go @@ -76,4 +76,5 @@ var ServiceTypes = map[string]ServiceType{ "solr": solr, "worker": worker, "worker-persistent": workerPersistent, + "rabbitmq": rabbitmq, } diff --git a/internal/templating/networkpolicy/template_networkpolicy.go b/internal/templating/networkpolicy/template_networkpolicy.go new file mode 100644 index 00000000..60f5011e --- /dev/null +++ b/internal/templating/networkpolicy/template_networkpolicy.go @@ -0,0 +1,67 @@ +package networkpolicy + +import ( + "github.com/uselagoon/build-deploy-tool/internal/generator" + networkv1 "k8s.io/api/networking/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// GenerateNetworkPolicy generates the lagoon template to apply. +func GenerateNetworkPolicy( + buildValues generator.BuildValues, +) (networkv1.NetworkPolicy, error) { + // add the default labels + labels := map[string]string{ + "app.kubernetes.io/managed-by": "build-deploy-tool", + "lagoon.sh/project": buildValues.Project, + "lagoon.sh/environment": buildValues.Environment, + "lagoon.sh/environmentType": buildValues.EnvironmentType, + "lagoon.sh/buildType": buildValues.BuildType, + } + + // add the default annotations + annotations := map[string]string{ + "lagoon.sh/version": buildValues.LagoonVersion, + } + + // add any additional labels + if buildValues.BuildType == "branch" { + annotations["lagoon.sh/branch"] = buildValues.Branch + } else if buildValues.BuildType == "pullrequest" { + annotations["lagoon.sh/prNumber"] = buildValues.PRNumber + annotations["lagoon.sh/prHeadBranch"] = buildValues.PRHeadBranch + annotations["lagoon.sh/prBaseBranch"] = buildValues.PRBaseBranch + } + np := networkv1.NetworkPolicy{ + TypeMeta: metav1.TypeMeta{ + Kind: "NetworkPolicy", + APIVersion: "networking.k8s.io/v1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "isolation-network-policy", + Labels: labels, + Annotations: annotations, + }, + Spec: networkv1.NetworkPolicySpec{ + PodSelector: metav1.LabelSelector{}, + Ingress: []networkv1.NetworkPolicyIngressRule{ + { + From: []networkv1.NetworkPolicyPeer{ + { + PodSelector: &metav1.LabelSelector{}, + NamespaceSelector: &metav1.LabelSelector{ + MatchExpressions: []metav1.LabelSelectorRequirement{ + { + Key: "lagoon.sh/environment", + Operator: metav1.LabelSelectorOpDoesNotExist, + }, + }, + }, + }, + }, + }, + }, + }, + } + return np, nil +} diff --git a/internal/templating/networkpolicy/template_networkpolicy_test.go b/internal/templating/networkpolicy/template_networkpolicy_test.go new file mode 100644 index 00000000..583640a3 --- /dev/null +++ b/internal/templating/networkpolicy/template_networkpolicy_test.go @@ -0,0 +1,144 @@ +package networkpolicy + +import ( + "os" + "reflect" + "testing" + + "github.com/andreyvit/diff" + "github.com/uselagoon/build-deploy-tool/internal/generator" + "github.com/uselagoon/build-deploy-tool/internal/lagoon" + "sigs.k8s.io/yaml" +) + +func TestGenerateNetworkPolicy(t *testing.T) { + type args struct { + buildValues generator.BuildValues + } + tests := []struct { + name string + args args + want string + wantErr bool + }{{ + name: "test1 - basic", + 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", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", + "myservice-po": "harbor.example.com/example-project/environment-name/myservice-po@latest", + "myservice-persist": "harbor.example.com/example-project/environment-name/myservice-persist@latest", + "myservice-persist-po": "harbor.example.com/example-project/environment-name/myservice-persist-po@latest", + "myservice-persist-posize": "harbor.example.com/example-project/environment-name/myservice-persist-posize@latest", + }, + Services: []generator.ServiceValues{ + { + Name: "myservice", + OverrideName: "myservice", + Type: "basic", + DBaaSEnvironment: "production", + InPodCronjobs: []lagoon.Cronjob{ + { + Name: "cron - inpod", + Schedule: "M/5 * * * *", + Command: "drush cron", + Service: "basic", + }, + { + Name: "cron2 - inpod", + Schedule: "M/15 * * * *", + Command: "other cronjob", + Service: "basic", + }, + }, + NativeCronjobs: []lagoon.Cronjob{ + { + Name: "cron3 - native", + Schedule: "35 * * * *", + Command: "drush cron", + Service: "basic", + }, + }, + }, + { + Name: "myservice-po", + OverrideName: "myservice-po", + Type: "basic", + DBaaSEnvironment: "production", + ServicePort: 8080, // template should have port changed to 8080 from 3000 + UseSpotInstances: true, // template should have spot instance label and toleration/selector/affinity + Replicas: 2, + }, + { + Name: "myservice-persist", + OverrideName: "myservice-persist", + Type: "basic-persistent", + DBaaSEnvironment: "production", + PersistentVolumePath: "/storage/data", + PersistentVolumeName: "basic", + }, + { + Name: "myservice-persist-po", + OverrideName: "myservice-persist-po", + Type: "basic-persistent", + DBaaSEnvironment: "production", + ServicePort: 8080, + PersistentVolumePath: "/storage/data", + PersistentVolumeName: "basic", + }, + { + Name: "myservice-persist-posize", + OverrideName: "myservice-persist-posize", + Type: "basic-persistent", + DBaaSEnvironment: "production", + ServicePort: 8080, + PersistentVolumeSize: "100Gi", + PersistentVolumePath: "/storage/data", + PersistentVolumeName: "basic", + }, + }, + }, + }, + want: "test-resources/result-np-1.yaml", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GenerateNetworkPolicy(tt.args.buildValues) + if (err != nil) != tt.wantErr { + t.Errorf("GenerateNetworkPolicy() error = %v, wantErr %v", err, tt.wantErr) + return + } + r1, err := os.ReadFile(tt.want) + if err != nil { + t.Errorf("couldn't read file %v: %v", tt.want, err) + } + separator := []byte("---\n") + var result []byte + deploymentBytes, err := yaml.Marshal(got) + if err != nil { + t.Errorf("couldn't generate template %v", err) + } + restoreResult := append(separator[:], deploymentBytes[:]...) + result = append(result, restoreResult[:]...) + if !reflect.DeepEqual(string(result), string(r1)) { + t.Errorf("GenerateDeploymentTemplate() = \n%v", diff.LineDiff(string(r1), string(result))) + } + }) + } +} diff --git a/internal/templating/networkpolicy/test-resources/result-np-1.yaml b/internal/templating/networkpolicy/test-resources/result-np-1.yaml new file mode 100644 index 00000000..4495a11c --- /dev/null +++ b/internal/templating/networkpolicy/test-resources/result-np-1.yaml @@ -0,0 +1,24 @@ +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + annotations: + lagoon.sh/branch: environment-name + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/managed-by: build-deploy-tool + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + name: isolation-network-policy +spec: + ingress: + - from: + - namespaceSelector: + matchExpressions: + - key: lagoon.sh/environment + operator: DoesNotExist + podSelector: {} + podSelector: {} diff --git a/internal/templating/services/templates_cronjob.go b/internal/templating/services/templates_cronjob.go index 6181948b..b37d597b 100644 --- a/internal/templating/services/templates_cronjob.go +++ b/internal/templating/services/templates_cronjob.go @@ -63,9 +63,16 @@ func GenerateCronjobTemplate( templateAnnotations := make(map[string]string) templateAnnotations["lagoon.sh/configMapSha"] = buildValues.ConfigMapSha + tpld := struct { + ServiceValues interface{} + ServiceTypeValues interface{} + }{ + serviceValues, + serviceTypeValues, + } if serviceTypeValues.Volumes.BackupConfiguration.Command != "" { bc := servicetypes.BackupConfiguration{} - helpers.TemplateThings(serviceValues, serviceTypeValues.Volumes.BackupConfiguration, &bc) + helpers.TemplateThings(tpld, serviceTypeValues.Volumes.BackupConfiguration, &bc) templateAnnotations["k8up.syn.tools/backupcommand"] = bc.Command templateAnnotations["k8up.syn.tools/file-extension"] = bc.FileExtension } @@ -233,12 +240,12 @@ func GenerateCronjobTemplate( // if there are any specific container volume overrides provided, handle those here for _, pcv := range serviceTypeValues.PrimaryContainer.Volumes { volume := corev1.Volume{} - helpers.TemplateThings(serviceValues, pcv, &volume) + helpers.TemplateThings(tpld, pcv, &volume) cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes = append(cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes, volume) } for _, scv := range serviceTypeValues.SecondaryContainer.Volumes { volume := corev1.Volume{} - helpers.TemplateThings(serviceValues, scv, &volume) + helpers.TemplateThings(tpld, scv, &volume) cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes = append(cronjob.Spec.JobTemplate.Spec.Template.Spec.Volumes, volume) } @@ -271,13 +278,13 @@ func GenerateCronjobTemplate( if enableInit || init.FeatureFlags == nil { for _, svm := range serviceTypeValues.InitContainer.VolumeMounts { volumeMount := corev1.VolumeMount{} - helpers.TemplateThings(serviceValues, svm, &volumeMount) + helpers.TemplateThings(tpld, svm, &volumeMount) init.Container.VolumeMounts = append(init.Container.VolumeMounts, volumeMount) } cmd := []string{} for _, c := range init.Command { var c2 string - helpers.TemplateThings(serviceValues, c, &c2) + helpers.TemplateThings(tpld, c, &c2) cmd = append(cmd, c2) } init.Container.Command = cmd @@ -347,7 +354,7 @@ func GenerateCronjobTemplate( } for _, svm := range serviceTypeValues.PrimaryContainer.VolumeMounts { volumeMount := corev1.VolumeMount{} - helpers.TemplateThings(serviceValues, svm, &volumeMount) + helpers.TemplateThings(tpld, svm, &volumeMount) container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) } if serviceValues.PersistentVolumeName != "" && serviceValues.PersistentVolumePath != "" && serviceTypeValues.Volumes.PersistentVolumeSize == "" { diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index 70d8e5ca..b4997b1e 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -64,9 +64,16 @@ func GenerateDeploymentTemplate( templateAnnotations := make(map[string]string) templateAnnotations["lagoon.sh/configMapSha"] = buildValues.ConfigMapSha + tpld := struct { + ServiceValues interface{} + ServiceTypeValues interface{} + }{ + serviceValues, + serviceTypeValues, + } if serviceTypeValues.Volumes.BackupConfiguration.Command != "" { bc := servicetypes.BackupConfiguration{} - helpers.TemplateThings(serviceValues, serviceTypeValues.Volumes.BackupConfiguration, &bc) + helpers.TemplateThings(tpld, serviceTypeValues.Volumes.BackupConfiguration, &bc) templateAnnotations["k8up.syn.tools/backupcommand"] = bc.Command templateAnnotations["k8up.syn.tools/file-extension"] = bc.FileExtension } @@ -238,12 +245,12 @@ func GenerateDeploymentTemplate( // if there are any specific container volume overrides provided, handle those here for _, pcv := range serviceTypeValues.PrimaryContainer.Volumes { volume := corev1.Volume{} - helpers.TemplateThings(serviceValues, pcv, &volume) + helpers.TemplateThings(tpld, pcv, &volume) deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, volume) } for _, scv := range serviceTypeValues.SecondaryContainer.Volumes { volume := corev1.Volume{} - helpers.TemplateThings(serviceValues, scv, &volume) + helpers.TemplateThings(tpld, scv, &volume) deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, volume) } @@ -277,13 +284,13 @@ func GenerateDeploymentTemplate( // add any volume mounts to the init container as required for _, svm := range serviceTypeValues.InitContainer.VolumeMounts { volumeMount := corev1.VolumeMount{} - helpers.TemplateThings(serviceValues, svm, &volumeMount) + helpers.TemplateThings(tpld, svm, &volumeMount) init.Container.VolumeMounts = append(init.Container.VolumeMounts, volumeMount) } cmd := []string{} for _, c := range init.Command { var c2 string - helpers.TemplateThings(serviceValues, c, &c2) + helpers.TemplateThings(tpld, c, &c2) cmd = append(cmd, c2) } init.Container.Command = cmd @@ -424,7 +431,7 @@ func GenerateDeploymentTemplate( // create the container volume mounts for _, svm := range serviceTypeValues.PrimaryContainer.VolumeMounts { volumeMount := corev1.VolumeMount{} - helpers.TemplateThings(serviceValues, svm, &volumeMount) + helpers.TemplateThings(tpld, svm, &volumeMount) container.Container.VolumeMounts = append(container.Container.VolumeMounts, volumeMount) } // mount the default storage volume if one exists @@ -520,7 +527,7 @@ func GenerateDeploymentTemplate( for _, svm := range serviceTypeValues.SecondaryContainer.VolumeMounts { volumeMount := corev1.VolumeMount{} - helpers.TemplateThings(serviceValues, svm, &volumeMount) + helpers.TemplateThings(tpld, svm, &volumeMount) linkedContainer.Container.VolumeMounts = append(linkedContainer.Container.VolumeMounts, volumeMount) } deployment.Spec.Template.Spec.Containers = append(deployment.Spec.Template.Spec.Containers, linkedContainer.Container) diff --git a/internal/templating/services/templates_deployment_test.go b/internal/templating/services/templates_deployment_test.go index 4a352efe..f348a0c6 100644 --- a/internal/templating/services/templates_deployment_test.go +++ b/internal/templating/services/templates_deployment_test.go @@ -567,6 +567,348 @@ func TestGenerateDeploymentTemplate(t *testing.T) { }, want: "test-resources/deployment/result-nginx-2.yaml", }, + { + name: "test12 - worker", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-name", + EnvironmentType: "production", + Namespace: "example-project-environment-name", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-name", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + PodSecurityContext: generator.PodSecurityContext{ + RunAsGroup: 0, + RunAsUser: 10000, + FsGroup: 10001, + OnRootMismatch: true, + }, + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "worker": "harbor.example.com/example-project/environment-name/worker@latest", + "worker-persist": "harbor.example.com/example-project/environment-name/worker-persist@latest", + }, + Services: []generator.ServiceValues{ + { + Name: "worker", + OverrideName: "worker", + Type: "worker", + }, + { + Name: "worker-persist", + OverrideName: "worker-persist", + Type: "worker-persistent", + }, + }, + }, + }, + want: "test-resources/deployment/result-worker-1.yaml", + }, + { + name: "test13 - python", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-name", + EnvironmentType: "production", + Namespace: "example-project-environment-name", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-name", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + PodSecurityContext: generator.PodSecurityContext{ + RunAsGroup: 0, + RunAsUser: 10000, + FsGroup: 10001, + OnRootMismatch: true, + }, + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "python": "harbor.example.com/example-project/environment-name/python@latest", + "python-persist": "harbor.example.com/example-project/environment-name/python-persist@latest", + }, + Services: []generator.ServiceValues{ + { + Name: "python", + OverrideName: "python", + Type: "python", + }, + { + Name: "python-persist", + OverrideName: "python-persist", + Type: "python-persistent", + }, + }, + }, + }, + want: "test-resources/deployment/result-python-1.yaml", + }, + { + name: "test14 - node", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-name", + EnvironmentType: "production", + Namespace: "example-project-environment-name", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-name", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + PodSecurityContext: generator.PodSecurityContext{ + RunAsGroup: 0, + RunAsUser: 10000, + FsGroup: 10001, + OnRootMismatch: true, + }, + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "node": "harbor.example.com/example-project/environment-name/node@latest", + "node-persist": "harbor.example.com/example-project/environment-name/node-persist@latest", + }, + Services: []generator.ServiceValues{ + { + Name: "node", + OverrideName: "node", + Type: "node", + }, + { + Name: "node-persist", + OverrideName: "node-persist", + Type: "node-persistent", + }, + }, + }, + }, + want: "test-resources/deployment/result-node-1.yaml", + }, + { + name: "test15 - varnish", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-name", + EnvironmentType: "production", + Namespace: "example-project-environment-name", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-name", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + PodSecurityContext: generator.PodSecurityContext{ + RunAsGroup: 0, + RunAsUser: 10000, + FsGroup: 10001, + OnRootMismatch: true, + }, + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "varnish": "harbor.example.com/example-project/environment-name/varnish@latest", + "varnish-persist": "harbor.example.com/example-project/environment-name/varnish-persist@latest", + }, + Services: []generator.ServiceValues{ + { + Name: "varnish", + OverrideName: "varnish", + Type: "varnish", + }, + { + Name: "varnish-persist", + OverrideName: "varnish-persist", + Type: "varnish-persistent", + }, + }, + }, + }, + want: "test-resources/deployment/result-varnish-1.yaml", + }, + { + name: "test16 - redis", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-name", + EnvironmentType: "production", + Namespace: "example-project-environment-name", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-name", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + PodSecurityContext: generator.PodSecurityContext{ + RunAsGroup: 0, + RunAsUser: 10000, + FsGroup: 10001, + OnRootMismatch: true, + }, + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "redis": "harbor.example.com/example-project/environment-name/redis@latest", + "redis-persist": "harbor.example.com/example-project/environment-name/redis-persist@latest", + }, + Services: []generator.ServiceValues{ + { + Name: "redis", + OverrideName: "redis", + Type: "redis", + }, + { + Name: "redis-persist", + OverrideName: "redis-persist", + Type: "redis-persistent", + }, + }, + }, + }, + want: "test-resources/deployment/result-redis-1.yaml", + }, + { + name: "test17 - mariadb", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-name", + EnvironmentType: "production", + Namespace: "example-project-environment-name", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-name", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + PodSecurityContext: generator.PodSecurityContext{ + RunAsGroup: 0, + RunAsUser: 10000, + FsGroup: 10001, + OnRootMismatch: true, + }, + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "mariadb": "harbor.example.com/example-project/environment-name/mariadb@latest", + }, + Services: []generator.ServiceValues{ + { + Name: "mariadb", + OverrideName: "mariadb", + Type: "mariadb-single", + }, + }, + }, + }, + want: "test-resources/deployment/result-mariadb-1.yaml", + }, + { + name: "test18 - mongodb", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-name", + EnvironmentType: "production", + Namespace: "example-project-environment-name", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-name", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + PodSecurityContext: generator.PodSecurityContext{ + RunAsGroup: 0, + RunAsUser: 10000, + FsGroup: 10001, + OnRootMismatch: true, + }, + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "mongodb": "harbor.example.com/example-project/environment-name/mongodb@latest", + }, + Services: []generator.ServiceValues{ + { + Name: "mongodb", + OverrideName: "mongodb", + Type: "mongodb-single", + }, + }, + }, + }, + want: "test-resources/deployment/result-mongodb-1.yaml", + }, + { + name: "test19 - postgres", + args: args{ + buildValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-name", + EnvironmentType: "production", + Namespace: "example-project-environment-name", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-name", + ImagePullSecrets: []generator.ImagePullSecrets{ + { + Name: "lagoon-internal-registry-secret", + }, + }, + PodSecurityContext: generator.PodSecurityContext{ + RunAsGroup: 0, + RunAsUser: 10000, + FsGroup: 10001, + OnRootMismatch: true, + }, + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + ImageReferences: map[string]string{ + "postgres": "harbor.example.com/example-project/environment-name/postgres@latest", + }, + Services: []generator.ServiceValues{ + { + Name: "postgres", + OverrideName: "postgres", + Type: "postgres-single", + }, + }, + }, + }, + want: "test-resources/deployment/result-postgres-1.yaml", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -614,14 +956,12 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", }, { Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, }, }, @@ -631,13 +971,11 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", LinkedService: &generator.ServiceValues{ Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, }, }, @@ -651,28 +989,24 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", }, { Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, { Name: "nginx2", OverrideName: "nginx2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/nginx2@latest", }, { Name: "php2", OverrideName: "nginx2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/php2@latest", }, }, }, @@ -682,13 +1016,11 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", LinkedService: &generator.ServiceValues{ Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, }, { @@ -696,13 +1028,11 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "nginx2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/nginx2@latest", LinkedService: &generator.ServiceValues{ Name: "php2", OverrideName: "nginx2", Type: "nginx-php-persistent", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/php2@latest", }, }, }, @@ -716,21 +1046,18 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", }, { Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, { Name: "normalnginx", OverrideName: "normalnginx", Type: "nginx", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/normalnginx@latest", }, }, }, @@ -740,20 +1067,17 @@ func TestLinkedServiceCalculator(t *testing.T) { OverrideName: "normalnginx", Type: "nginx", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/normalnginx@latest", }, { Name: "nginx", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/nginx@latest", LinkedService: &generator.ServiceValues{ Name: "php", OverrideName: "nginx", Type: "nginx-php", DBaaSEnvironment: "production", - // ImageName: "harbor.example.com/example-project/environment-name/php@latest", }, }, }, diff --git a/internal/templating/services/templates_pvc.go b/internal/templating/services/templates_pvc.go index 7eb5c51e..601c6152 100644 --- a/internal/templating/services/templates_pvc.go +++ b/internal/templating/services/templates_pvc.go @@ -141,6 +141,12 @@ func GeneratePVCTemplate( if serviceTypeValues.Volumes.PersistentVolumeType == corev1.ReadWriteMany { pvc.Spec.StorageClassName = helpers.StrPtr("bulk") } + if buildValues.RWX2RWO || buildValues.IsCI { + // this should be a rwo volume in CI and if the rwx2rwo flag is enabled + pvc.Spec.AccessModes = []corev1.PersistentVolumeAccessMode{ + corev1.ReadWriteOnce, + } + } // end PVC template result = append(result, *pvc) } diff --git a/internal/templating/services/templates_pvc_test.go b/internal/templating/services/templates_pvc_test.go index 1ed01abc..e92731e4 100644 --- a/internal/templating/services/templates_pvc_test.go +++ b/internal/templating/services/templates_pvc_test.go @@ -188,6 +188,31 @@ func TestGeneratePVCTemplate(t *testing.T) { }, want: "test-resources/pvc/result-postgres-single-1.yaml", }, + { + name: "test7 - basic rwx2rwo", + 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-persist", + OverrideName: "myservice-persist", + Type: "basic-persistent", + DBaaSEnvironment: "development", + }, + }, + }, + }, + want: "test-resources/pvc/result-basic-3.yaml", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml b/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml new file mode 100644 index 00000000..e72e05c4 --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml @@ -0,0 +1,78 @@ +--- +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: mariadb + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + name: mariadb +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: mariadb + app.kubernetes.io/name: mariadb-single + strategy: {} + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c 'mysqldump --max-allowed-packet=500M + --events --routines --quick --add-locks --no-autocommit --single-transaction + --all-databases' + k8up.syn.tools/file-extension: . + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mariadb + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/mariadb@latest + name: "" + resources: {} + volumeMounts: + - mountPath: /var/lib/mysql + name: mariadb + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: mariadb + persistentVolumeClaim: + claimName: mariadb +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml b/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml new file mode 100644 index 00000000..161bad76 --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml @@ -0,0 +1,77 @@ +--- +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: mongodb + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mongodb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mongodb + lagoon.sh/service-type: mongodb-single + lagoon.sh/template: mongodb-single-0.1.0 + name: mongodb +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: mongodb + app.kubernetes.io/name: mongodb-single + strategy: {} + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c 'tar -cf - -C "/data/db" --exclude="lost\+found" + . || [ $? -eq 1 ]' + k8up.syn.tools/file-extension: . + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mongodb + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mongodb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mongodb + lagoon.sh/service-type: mongodb-single + lagoon.sh/template: mongodb-single-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/mongodb@latest + name: "" + resources: {} + volumeMounts: + - mountPath: /data/db + name: mongodb + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: mongodb + persistentVolumeClaim: + claimName: mongodb +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-node-1.yaml b/internal/templating/services/test-resources/deployment/result-node-1.yaml new file mode 100644 index 00000000..9adea579 --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-node-1.yaml @@ -0,0 +1,175 @@ +--- +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: node + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: node + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: node + lagoon.sh/service-type: node + lagoon.sh/template: node-0.1.0 + name: node +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: node + app.kubernetes.io/name: node + strategy: {} + 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: node + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: node + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: node + lagoon.sh/service-type: node + lagoon.sh/template: node-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/node@latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 3000 + timeoutSeconds: 10 + name: node + ports: + - containerPort: 3000 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 3000 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 +status: {} +--- +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: node-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: node-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: node-persist + lagoon.sh/service-type: node-persistent + lagoon.sh/template: node-persistent-0.1.0 + name: node-persist +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: node-persist + app.kubernetes.io/name: node-persistent + strategy: {} + 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: node-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: node-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: node-persist + lagoon.sh/service-type: node-persistent + lagoon.sh/template: node-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/node-persist@latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 3000 + timeoutSeconds: 10 + name: node + ports: + - containerPort: 3000 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 3000 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: "" + name: node-persist + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: node-persist + persistentVolumeClaim: + claimName: node-persist +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-postgres-1.yaml b/internal/templating/services/test-resources/deployment/result-postgres-1.yaml new file mode 100644 index 00000000..a0314753 --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-postgres-1.yaml @@ -0,0 +1,96 @@ +--- +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: postgres + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + name: postgres +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: postgres + app.kubernetes.io/name: postgres-single + strategy: + type: Recreate + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c "PGPASSWORD=$POSTGRES_PASSWORD pg_dump + --host=localhost --port=$POSTGRES_SERVICE_PORT --dbname=$POSTGRES_DB --username=$POSTGRES_USER + --format=t -w" + k8up.syn.tools/file-extension: .postgres.tar + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: postgres + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/postgres@latest + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 5432 + name: postgres + ports: + - containerPort: 5432 + name: 5432-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 5432 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: postgres + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: postgres + persistentVolumeClaim: + claimName: postgres +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-python-1.yaml b/internal/templating/services/test-resources/deployment/result-python-1.yaml new file mode 100644 index 00000000..04c7674d --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-python-1.yaml @@ -0,0 +1,175 @@ +--- +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: python + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: python + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: python + lagoon.sh/service-type: python + lagoon.sh/template: python-0.1.0 + name: python +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: python + app.kubernetes.io/name: python + strategy: {} + 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: python + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: python + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: python + lagoon.sh/service-type: python + lagoon.sh/template: python-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/python@latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8800 + timeoutSeconds: 10 + name: python + ports: + - containerPort: 8800 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8800 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 +status: {} +--- +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: python-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: python-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: python-persist + lagoon.sh/service-type: python-persistent + lagoon.sh/template: python-persistent-0.1.0 + name: python-persist +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: python-persist + app.kubernetes.io/name: python-persistent + strategy: {} + 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: python-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: python-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: python-persist + lagoon.sh/service-type: python-persistent + lagoon.sh/template: python-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/python-persist@latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8800 + timeoutSeconds: 10 + name: python + ports: + - containerPort: 8800 + name: http + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8800 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: "" + name: python-persist + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: python-persist + persistentVolumeClaim: + claimName: python-persist +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml b/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml new file mode 100644 index 00000000..4529b4b4 --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml @@ -0,0 +1,98 @@ +--- +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: rabbitmq + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: rabbitmq + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: rabbitmq + lagoon.sh/service-type: rabbitmq + lagoon.sh/template: rabbitmq-0.1.0 + name: rabbitmq +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: rabbitmq + app.kubernetes.io/name: rabbitmq + strategy: + type: Recreate + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c 'tar -cf - -C "/var/lib/rabbitmq" + --exclude="lost\+found" . || [ $? -eq 1 ]' + k8up.syn.tools/file-extension: .rabbitmq.tar + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: rabbitmq + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: rabbitmq + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: rabbitmq + lagoon.sh/service-type: rabbitmq + lagoon.sh/template: rabbitmq-0.1.0 + spec: + containers: + - env: + - name: RABBITMQ_NODENAME + value: rabbitmq@localhost + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/rabbitmq@latest + livenessProbe: + failureThreshold: 5 + initialDelaySeconds: 90 + tcpSocket: + port: 5672 + timeoutSeconds: 3 + name: rabbitmq + ports: + - containerPort: 5672 + name: 5672-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + periodSeconds: 3 + tcpSocket: + port: 5672 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/lib/rabbitmq + name: rabbitmq + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: rabbitmq + persistentVolumeClaim: + claimName: rabbitmq +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-redis-1.yaml b/internal/templating/services/test-resources/deployment/result-redis-1.yaml new file mode 100644 index 00000000..95232b37 --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-redis-1.yaml @@ -0,0 +1,161 @@ +--- +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: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + name: redis +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: redis + app.kubernetes.io/name: redis + strategy: {} + 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: redis + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/redis@latest + livenessProbe: + initialDelaySeconds: 120 + tcpSocket: + port: 6379 + timeoutSeconds: 10 + name: redis + ports: + - containerPort: 6379 + name: 6379-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 6379 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 +status: {} +--- +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: redis-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis-persist + lagoon.sh/service-type: redis-persistent + lagoon.sh/template: redis-persistent-0.1.0 + name: redis-persist +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: redis-persist + app.kubernetes.io/name: redis-persistent + strategy: {} + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c "/bin/busybox tar -cf - -C /data + ." + k8up.syn.tools/file-extension: . + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis-persist + lagoon.sh/service-type: redis-persistent + lagoon.sh/template: redis-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/redis-persist@latest + name: "" + resources: {} + volumeMounts: + - mountPath: /data + name: redis-persist + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: redis-persist + persistentVolumeClaim: + claimName: redis-persist +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-varnish-1.yaml b/internal/templating/services/test-resources/deployment/result-varnish-1.yaml new file mode 100644 index 00000000..5cf321e8 --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-varnish-1.yaml @@ -0,0 +1,164 @@ +--- +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: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + name: varnish +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: varnish + app.kubernetes.io/name: varnish + strategy: {} + 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: varnish + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish + lagoon.sh/service-type: varnish + lagoon.sh/template: varnish-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/varnish@latest + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8080 + timeoutSeconds: 10 + name: varnish + ports: + - containerPort: 8080 + name: http + protocol: TCP + - containerPort: 6082 + name: controlport + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8080 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 +status: {} +--- +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: varnish-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish-persist + lagoon.sh/service-type: varnish-persistent + lagoon.sh/template: varnish-persistent-0.1.0 + name: varnish-persist +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: varnish-persist + app.kubernetes.io/name: varnish-persistent + strategy: {} + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c "/bin/busybox tar -cf - -C /var/cache/varnish + ." + k8up.syn.tools/file-extension: . + lagoon.sh/branch: environment-name + lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: varnish-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: varnish-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: varnish-persist + lagoon.sh/service-type: varnish-persistent + lagoon.sh/template: varnish-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/varnish-persist@latest + name: "" + resources: {} + volumeMounts: + - mountPath: /var/cache/varnish + name: varnish-persist + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 + volumes: + - name: varnish-persist + persistentVolumeClaim: + claimName: varnish-persist +status: {} diff --git a/internal/templating/services/test-resources/deployment/result-worker-1.yaml b/internal/templating/services/test-resources/deployment/result-worker-1.yaml new file mode 100644 index 00000000..7bdaa272 --- /dev/null +++ b/internal/templating/services/test-resources/deployment/result-worker-1.yaml @@ -0,0 +1,168 @@ +--- +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: worker + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: worker + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: worker + lagoon.sh/service-type: worker + lagoon.sh/template: worker-0.1.0 + name: worker +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: worker + app.kubernetes.io/name: worker + strategy: {} + 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: worker + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: worker + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: worker + lagoon.sh/service-type: worker + lagoon.sh/template: worker-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/worker@latest + name: worker + readinessProbe: + exec: + command: + - /bin/sh + - -c + - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; + fi + failureThreshold: 3 + initialDelaySeconds: 5 + periodSeconds: 2 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 +status: {} +--- +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: worker-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: worker-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: worker-persist + lagoon.sh/service-type: worker-persistent + lagoon.sh/template: worker-persistent-0.1.0 + name: worker-persist +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: worker-persist + app.kubernetes.io/name: worker-persistent + strategy: {} + 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: worker-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: worker-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: worker-persist + lagoon.sh/service-type: worker-persistent + lagoon.sh/template: worker-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: "0" + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example.com/example-project/environment-name/worker-persist@latest + name: worker + readinessProbe: + exec: + command: + - /bin/sh + - -c + - if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness; + fi + failureThreshold: 3 + initialDelaySeconds: 5 + periodSeconds: 2 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/sshkey/ + name: lagoon-sshkey + readOnly: true + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + securityContext: + fsGroup: 10001 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 0 + runAsUser: 10000 +status: {} diff --git a/internal/templating/services/test-resources/pvc/result-basic-2.yaml b/internal/templating/services/test-resources/pvc/result-basic-2.yaml new file mode 100644 index 00000000..5eebe966 --- /dev/null +++ b/internal/templating/services/test-resources/pvc/result-basic-2.yaml @@ -0,0 +1,30 @@ +--- +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-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: myservice-persist +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi + storageClassName: bulk +status: {} diff --git a/internal/templating/services/test-resources/pvc/result-basic-3.yaml b/internal/templating/services/test-resources/pvc/result-basic-3.yaml new file mode 100644 index 00000000..5eebe966 --- /dev/null +++ b/internal/templating/services/test-resources/pvc/result-basic-3.yaml @@ -0,0 +1,30 @@ +--- +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-persist + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: myservice-persist + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: myservice-persist +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi + storageClassName: bulk +status: {} diff --git a/internal/testdata/basic/service-templates/service1/deployment-node.yaml b/internal/testdata/basic/service-templates/service1/deployment-node.yaml index 1f637b42..ac5f3224 100644 --- a/internal/testdata/basic/service-templates/service1/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service1/deployment-node.yaml @@ -80,6 +80,7 @@ spec: memory: 100M enableServiceLinks: false imagePullSecrets: + - name: lagoon-private-registry-custom-secret - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production status: {} diff --git a/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml index 53aa050e..79a6fa9e 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml @@ -47,7 +47,7 @@ spec: containers: - env: - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: CRONJOBS envFrom: - configMapRef: diff --git a/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml index 7d7e148c..15c8455a 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml @@ -47,7 +47,7 @@ spec: containers: - env: - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: CRONJOBS envFrom: - configMapRef: diff --git a/internal/testdata/basic/service-templates/service2/deployment-tor.yaml b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml index c1a22ed5..f05a2939 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-tor.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml @@ -47,7 +47,7 @@ spec: containers: - env: - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: CRONJOBS envFrom: - configMapRef: diff --git a/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml index 53aa050e..79a6fa9e 100644 --- a/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml +++ b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml @@ -47,7 +47,7 @@ spec: containers: - env: - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: CRONJOBS envFrom: - configMapRef: diff --git a/internal/testdata/basic/service-templates/service3/deployment-tor.yaml b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml index eb1387fa..d425fd8a 100644 --- a/internal/testdata/basic/service-templates/service3/deployment-tor.yaml +++ b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml @@ -47,7 +47,7 @@ spec: containers: - env: - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: CRONJOBS envFrom: - configMapRef: diff --git a/internal/testdata/basic/service-templates/service5/isolation-network-policy.yaml b/internal/testdata/basic/service-templates/service5/isolation-network-policy.yaml new file mode 100644 index 00000000..d93bc282 --- /dev/null +++ b/internal/testdata/basic/service-templates/service5/isolation-network-policy.yaml @@ -0,0 +1,26 @@ +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + annotations: + lagoon.sh/prBaseBranch: pr-base + lagoon.sh/prHeadBranch: pr-head + lagoon.sh/prNumber: "123" + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/managed-by: build-deploy-tool + lagoon.sh/buildType: pullrequest + lagoon.sh/environment: pr-123 + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + name: isolation-network-policy +spec: + ingress: + - from: + - namespaceSelector: + matchExpressions: + - key: lagoon.sh/environment + operator: DoesNotExist + podSelector: {} + podSelector: {} diff --git a/internal/testdata/complex/docker-compose.varnish2.yml b/internal/testdata/complex/docker-compose.varnish2.yml new file mode 100644 index 00000000..021dfebc --- /dev/null +++ b/internal/testdata/complex/docker-compose.varnish2.yml @@ -0,0 +1,160 @@ +version: '2.3' + +x-example-image-version: + &example-image-version ${EXAMPLE_IMAGE_VERSION:-4.x} + +x-project: + &project ${PROJECT_NAME:-mysite} + +x-volumes: + &default-volumes + volumes: + - .:/app:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. + - ./docroot/sites/default/files:/app/docroot/sites/default/files:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. + +x-environment: + &default-environment + LAGOON_PROJECT: *project + DRUPAL_HASH_SALT: fakehashsaltfakehashsaltfakehashsalt + LAGOON_LOCALDEV_URL: ${LOCALDEV_URL:-http://mysite.docker.amazee.io} + LAGOON_ROUTE: ${LOCALDEV_URL:-http://mysite.docker.amazee.io} + GITHUB_TOKEN: ${GITHUB_TOKEN:-} + EXAMPLE_KEY: ${EXAMPLE_KEY:-} + EXAMPLE_IMAGE_VERSION: ${EXAMPLE_IMAGE_VERSION:-latest} + LAGOON_ENVIRONMENT_TYPE: ${LAGOON_ENVIRONMENT_TYPE:-local} + DRUPAL_REFRESH_SEARCHAPI: ${DRUPAL_REFRESH_SEARCHAPI:-} + EXAMPLE_INGRESS_PSK: ${EXAMPLE_INGRESS_PSK:-} + EXAMPLE_INGRESS_HEADER: ${EXAMPLE_INGRESS_HEADER:-} + EXAMPLE_INGRESS_ENABLED: ${EXAMPLE_INGRESS_ENABLED:-} + REDIS_CACHE_PREFIX: "tide_" + DB_ALIAS: ${DB_ALIAS:-bay.production} + + +services: + + cli: + build: + context: internal/testdata/complex/docker + dockerfile: .docker/Dockerfile.cli + args: + COMPOSER: ${COMPOSER:-composer.json} + EXAMPLE_IMAGE_VERSION: *example-image-version + image: *project + environment: + << : *default-environment + << : *default-volumes + volumes_from: ### Local overrides to mount host SSH keys. Automatically removed in CI. + - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. + labels: + lagoon.type: cli-persistent + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.persistent.name: nginx-php + lagoon.persistent.size: 5Gi + + nginx: + build: + context: internal/testdata/complex/docker + dockerfile: .docker/Dockerfile.nginx-drupal + args: + CLI_IMAGE: *project + EXAMPLE_IMAGE_VERSION: *example-image-version + << : *default-volumes + environment: + << : *default-environment + depends_on: + - cli + networks: + - amazeeio-network + - default + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.persistent.size: 5Gi + lagoon.name: nginx-php + expose: + - "8080" + php: + build: + context: internal/testdata/complex/docker + dockerfile: .docker/Dockerfile.php + args: + CLI_IMAGE: *project + EXAMPLE_IMAGE_VERSION: *example-image-version + environment: + << : *default-environment + << : *default-volumes + depends_on: + - cli + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/docroot/sites/default/files/ + lagoon.persistent.size: 5Gi + lagoon.name: nginx-php + + mariadb: + image: amazeeio/mariadb-drupal + environment: + << : *default-environment + ports: + - "3306" # Find port on host with `ahoy info` or `docker-compose port mariadb 3306` + labels: + lagoon.type: mariadb + + redis: + image: registry1.example.com/amazeeio/redis + labels: + lagoon.type: redis + + elasticsearch: + build: + context: internal/testdata/complex/docker + dockerfile: .docker/Dockerfile.elasticsearch + args: + - ES_TPL=${ES_TPL:-elasticsearch.yml} + environment: + - discovery.type=single-node + labels: + lagoon.type: none + + chrome: + image: selenium/standalone-chrome:3.141.59-oxygen + shm_size: '1gb' + environment: + << : *default-environment + << : *default-volumes + depends_on: + - cli + labels: + lagoon.type: none + + clamav: + image: clamav/clamav:${EXAMPLE_IMAGE_VERSION:-4.x} + environment: + << : *default-environment + ports: + - "3310" + labels: + lagoon.type: none + + varnish: + image: uselagoon/varnish-5-drupal:latest + labels: + lagoon.type: varnish + lando.type: varnish-drupal + links: + - nginx # links varnish to the nginx in this docker-compose project, or it would try to connect to any nginx running in docker + environment: + << : *default-environment + VARNISH_BYPASS: "true" # by default we bypass varnish, change to 'false' or remove in order to tell varnish to cache if possible + networks: + - amazeeio-network + - default + + +networks: + amazeeio-network: + external: true + +volumes: + app: {} + files: {} \ No newline at end of file diff --git a/internal/testdata/complex/lagoon.varnish2.yml b/internal/testdata/complex/lagoon.varnish2.yml new file mode 100644 index 00000000..77fa431a --- /dev/null +++ b/internal/testdata/complex/lagoon.varnish2.yml @@ -0,0 +1,19 @@ +--- +docker-compose-yaml: internal/testdata/complex/docker-compose.varnish2.yml + +project: example-com + +environments: + main: + routes: + - nginx: + - example.com + cronjobs: + - name: drush cron + schedule: "*/15 * * * *" + command: drush cron + service: cli + - name: drush cron2 + schedule: "*/30 * * * *" + command: drush cron + service: cli \ No newline at end of file diff --git a/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml b/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml index bdb1e0ed..e6dd7311 100644 --- a/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml +++ b/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml @@ -50,7 +50,7 @@ spec: - drush cron env: - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: SERVICE_NAME value: cli envFrom: diff --git a/internal/testdata/complex/service-templates/service1/deployment-cli.yaml b/internal/testdata/complex/service-templates/service1/deployment-cli.yaml index 98dab57b..1bcf72e1 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-cli.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-cli.yaml @@ -47,7 +47,7 @@ spec: containers: - env: - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: CRONJOBS value: | 3,18,33,48 * * * * drush cron diff --git a/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml index 243621b9..65d854be 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml @@ -49,7 +49,7 @@ spec: - name: NGINX_FASTCGI_PASS value: 127.0.0.1 - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: CRONJOBS envFrom: - configMapRef: @@ -84,7 +84,7 @@ spec: - name: NGINX_FASTCGI_PASS value: 127.0.0.1 - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service1/deployment-redis.yaml b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml index 410e91a8..7f2ec91e 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-redis.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml @@ -47,7 +47,7 @@ spec: containers: - env: - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: CRONJOBS envFrom: - configMapRef: diff --git a/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml index db6c14c5..92ff10cc 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml @@ -47,7 +47,7 @@ spec: containers: - env: - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: CRONJOBS envFrom: - configMapRef: diff --git a/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml b/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml index 758aa012..a2785c23 100644 --- a/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml +++ b/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml @@ -50,7 +50,7 @@ spec: - drush cron env: - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: SERVICE_NAME value: cli envFrom: diff --git a/internal/testdata/complex/service-templates/service2/deployment-cli.yaml b/internal/testdata/complex/service-templates/service2/deployment-cli.yaml index 6e7848e8..f023e948 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-cli.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-cli.yaml @@ -47,7 +47,7 @@ spec: containers: - env: - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: CRONJOBS value: | 3,18,33,48 * * * * drush cron diff --git a/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml index 8a65c258..37facd80 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml @@ -49,7 +49,7 @@ spec: - name: NGINX_FASTCGI_PASS value: 127.0.0.1 - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: CRONJOBS envFrom: - configMapRef: @@ -84,7 +84,7 @@ spec: - name: NGINX_FASTCGI_PASS value: 127.0.0.1 - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service2/deployment-redis.yaml b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml index 4c3c07ea..72bd8927 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-redis.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml @@ -47,7 +47,7 @@ spec: containers: - env: - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: CRONJOBS envFrom: - configMapRef: diff --git a/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml index b73ed33d..08f1d9df 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml @@ -47,7 +47,7 @@ spec: containers: - env: - name: LAGOON_GIT_SHA - value: abcdefg123456 + value: "0000000000000000000000000000000000000000" - name: CRONJOBS envFrom: - configMapRef: diff --git a/internal/testdata/testdata.go b/internal/testdata/testdata.go index e0e3fa88..35ebf470 100644 --- a/internal/testdata/testdata.go +++ b/internal/testdata/testdata.go @@ -52,6 +52,7 @@ type TestData struct { ConfigMapSha string ImageRegistry string PromotionSourceEnvironment string + PrivateRegistryURLS []string } // helper function to set up all the environment variables from provided testdata @@ -298,5 +299,8 @@ func GetSeedData(t TestData, defaultProjectVariables bool) TestData { if t.StatusPageID != "" { rt.StatusPageID = t.StatusPageID } + if t.PrivateRegistryURLS != nil { + rt.PrivateRegistryURLS = t.PrivateRegistryURLS + } return rt } From 6ba6533dfd24d35745b1fc0ea76e3701e5f61497 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 12 Jan 2024 20:45:50 +1100 Subject: [PATCH 54/92] refactor: use build-deploy-tool for image build calculation and service templating --- legacy/build-deploy-docker-compose.sh | 330 +++++++------------------- legacy/build-deploy.sh | 31 ++- 2 files changed, 107 insertions(+), 254 deletions(-) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 95a90970..d0b3f857 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -350,8 +350,15 @@ declare -A MAP_SERVICE_NAME_TO_IMAGENAME declare -A MAP_SERVICE_NAME_TO_SERVICEBROKER_CLASS declare -A MAP_SERVICE_NAME_TO_SERVICEBROKER_PLAN declare -A MAP_SERVICE_NAME_TO_DBAAS_ENVIRONMENT +# this array stores the images that will need to be pulled from an external registry (private, dockerhub) declare -A IMAGES_PULL +# this array stores the built images declare -A IMAGES_BUILD +# this array stores the image names that will be pushed (registry/project/environment/service:tag) +declare -A IMAGES_PUSH +# this array stores the images from the source environment that will be pulled from +declare -A IMAGES_PROMOTE +# this array stores the hashes of the built images declare -A IMAGE_HASHES set +x @@ -613,7 +620,7 @@ do [[ "$SERVICE_TYPE" != "postgres-dbaas" ]] && [[ "$SERVICE_TYPE" != "mongodb-dbaas" ]] && [[ "$SERVICE_TYPE" != "mongodb-shared" ]]; then - # Generate List of Images to build + # Generate list of images to build IMAGES+=("${IMAGE_NAME}") fi @@ -676,174 +683,75 @@ set +x # reduce noise in build logs fi set -x -# we only need to build images for pullrequests and branches -if [[ "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ]]; then - - BUILD_ARGS=() - - set +x # reduce noise in build logs - # Add environment variables from lagoon API as build args - if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then - echo "LAGOON_PROJECT_VARIABLES are available from the API" - # multiline/spaced variables seem to break when being added from the API. - # this changes the way it works to create the variable in a similar way to how they are injected below - LAGOON_ENV_VARS=$(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "build" or .scope == "global") | "\(.name)"') - for LAGOON_ENV_VAR in $LAGOON_ENV_VARS - do - BUILD_ARGS+=(--build-arg $(echo $LAGOON_ENV_VAR)="$(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "build" or .scope == "global") | select(.name == "'$LAGOON_ENV_VAR'") | "\(.value)"')") - done - fi - if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then - echo "LAGOON_ENVIRONMENT_VARIABLES are available from the API" - # multiline/spaced variables seem to break when being added from the API. - # this changes the way it works to create the variable in a similar way to how they are injected below - LAGOON_ENV_VARS=$(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.scope == "build" or .scope == "global") | "\(.name)"') - for LAGOON_ENV_VAR in $LAGOON_ENV_VARS - do - BUILD_ARGS+=(--build-arg $(echo $LAGOON_ENV_VAR)="$(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.scope == "build" or .scope == "global") | select(.name == "'$LAGOON_ENV_VAR'") | "\(.value)"')") - done +# seed all the push images for use later on, push images relate to images that may not be built by this build +# but are required from somewhere else like a promote environment or from another registry +ENVIRONMENT_IMAGE_BUILD_DATA=$(build-deploy-tool identify image-builds | jq -r) +for IMAGE_BUILD_DATA in $(echo $ENVIRONMENT_IMAGE_BUILD_DATA | jq -r '.images[]') +do + # add the image name to the array of images to push. this is consumed later in the build process + IMAGES_PUSH["${SERVICE_NAME}"]="$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.buildImage')" + if [ "$BUILD_TYPE" == "promote" ]; then + # add the image name to the array of images to promote from. this is consumed later in the build process + IMAGES_PROMOTE["${SERVICE_NAME}"]="$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.promoteImage')" fi - set -x - - BUILD_ARGS+=(--build-arg IMAGE_REPO="${CI_OVERRIDE_IMAGE_REPO}") - BUILD_ARGS+=(--build-arg LAGOON_PROJECT="${PROJECT}") - BUILD_ARGS+=(--build-arg LAGOON_ENVIRONMENT="${ENVIRONMENT}") - BUILD_ARGS+=(--build-arg LAGOON_ENVIRONMENT_TYPE="${ENVIRONMENT_TYPE}") - BUILD_ARGS+=(--build-arg LAGOON_BUILD_TYPE="${BUILD_TYPE}") - BUILD_ARGS+=(--build-arg LAGOON_GIT_SOURCE_REPOSITORY="${SOURCE_REPOSITORY}") - BUILD_ARGS+=(--build-arg LAGOON_KUBERNETES="${KUBERNETES}") +done - # Add in the cache args - for value in "${LAGOON_CACHE_BUILD_ARGS[@]}" - do - BUILD_ARGS+=(--build-arg $value) +# we only need to build images for pullrequests and branches +if [[ "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ]]; then + # use the build-deploy-tool to seed the image build information + BUILD_ARGS=() # build args are now calculated in the build-deploy tool in the generator step + # this loop extracts the build arguments from the response from the build deploy tools previous identify image-builds call + for IMAGE_BUILD_ARGUMENTS in $(echo "$ENVIRONMENT_IMAGE_BUILD_DATA" | jq -r '.buildArguments | to_entries[] | @base64'); do + BUILD_ARGS+=('--build-arg '$(echo "$IMAGE_BUILD_ARGUMENTS" | jq -Rr '@base64d | fromjson | .key')'="'$(echo "$IMAGE_BUILD_ARGUMENTS" | jq -Rr '@base64d | fromjson | .value')'"') done - set +x - BUILD_ARGS+=(--build-arg LAGOON_SSH_PRIVATE_KEY="${SSH_PRIVATE_KEY}") - set -x - - if [ "$BUILD_TYPE" == "branch" ]; then - BUILD_ARGS+=(--build-arg LAGOON_GIT_SHA="${LAGOON_GIT_SHA}") - BUILD_ARGS+=(--build-arg LAGOON_GIT_BRANCH="${BRANCH}") - fi - - if [ "$BUILD_TYPE" == "pullrequest" ]; then - BUILD_ARGS+=(--build-arg LAGOON_GIT_SHA="${LAGOON_GIT_SHA}") - BUILD_ARGS+=(--build-arg LAGOON_PR_HEAD_BRANCH="${PR_HEAD_BRANCH}") - BUILD_ARGS+=(--build-arg LAGOON_PR_HEAD_SHA="${PR_HEAD_SHA}") - BUILD_ARGS+=(--build-arg LAGOON_PR_BASE_BRANCH="${PR_BASE_BRANCH}") - BUILD_ARGS+=(--build-arg LAGOON_PR_BASE_SHA="${PR_BASE_SHA}") - BUILD_ARGS+=(--build-arg LAGOON_PR_TITLE="${PR_TITLE}") - BUILD_ARGS+=(--build-arg LAGOON_PR_NUMBER="${PR_NUMBER}") - fi - - # Add in random data as per https://github.com/uselagoon/lagoon/issues/2246 - BUILD_ARGS+=(--build-arg LAGOON_BUILD_NAME="${LAGOON_BUILD_NAME}") - - for IMAGE_NAME in "${IMAGES[@]}" + # now we loop through the images in the build data and determine if they need to be pulled or build + for IMAGE_BUILD_DATA in $(echo $ENVIRONMENT_IMAGE_BUILD_DATA | jq -r '.images[]') do - - DOCKERFILE=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$IMAGE_NAME.build.dockerfile false) - - # allow to overwrite build dockerfile for this environment and service - ENVIRONMENT_DOCKERFILE_OVERRIDE=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH//./\\.}.overrides.$IMAGE_NAME.build.dockerfile false) - if [ ! $ENVIRONMENT_DOCKERFILE_OVERRIDE == "false" ]; then - DOCKERFILE=$ENVIRONMENT_DOCKERFILE_OVERRIDE - fi - + SERVICE_NAME=$(echo "$IMAGE_BUILD_DATA" | jq -r '.name' // false) + DOCKERFILE=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.dockerFile' // false) + # if there is no dockerfile, then this image needs to be pulled from somewhere else if [ $DOCKERFILE == "false" ]; then - # No Dockerfile defined, assuming to download the Image directly - - PULL_IMAGE=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$IMAGE_NAME.image false) - if [ $PULL_IMAGE == "false" ]; then - echo "No Dockerfile or Image for service ${IMAGE_NAME} defined"; exit 1; - fi - - # allow to overwrite image that we pull - OVERRIDE_IMAGE=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$IMAGE_NAME.labels.lagoon\\.image false) - - # allow to overwrite image that we pull for this environment and service - ENVIRONMENT_IMAGE_OVERRIDE=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH//./\\.}.overrides.$IMAGE_NAME.image false) - if [ ! $ENVIRONMENT_IMAGE_OVERRIDE == "false" ]; then - OVERRIDE_IMAGE=$ENVIRONMENT_IMAGE_OVERRIDE + PULL_IMAGE=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.pullImage' // false) + if [ "$PULL_IMAGE" != "false" ]; then + IMAGES_PULL["${SERVICE_NAME}"]="${PULL_IMAGE}" fi - - if [ ! $OVERRIDE_IMAGE == "false" ]; then - # expand environment variables from ${OVERRIDE_IMAGE} - PULL_IMAGE=$(echo "${OVERRIDE_IMAGE}" | envsubst) - fi - - # if the image just is an image name (like "alpine") we prefix it with `libary/` as the imagecache does not understand - # the magic `alpine` images - if [[ ! "$PULL_IMAGE" =~ "/" ]]; then - PULL_IMAGE="library/$PULL_IMAGE" - fi - - # Add the images we should pull to the IMAGES_PULL array, they will later be tagged from dockerhub - IMAGES_PULL["${IMAGE_NAME}"]="${PULL_IMAGE}" - else - # Dockerfile defined, load the context and build it - - # We need the Image Name uppercase sometimes, so we create that here - IMAGE_NAME_UPPERCASE=$(echo "$IMAGE_NAME" | tr '[:lower:]' '[:upper:]') - - - # To prevent clashes of ImageNames during parallel builds, we give all Images a Temporary name - TEMPORARY_IMAGE_NAME="${NAMESPACE}-${IMAGE_NAME}" - - BUILD_CONTEXT=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$IMAGE_NAME.build.context .) - - # Check to see if this service uses a build target - BUILD_TARGET=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$IMAGE_NAME.build.target false) - - # allow to overwrite build context for this environment and service - ENVIRONMENT_BUILD_CONTEXT_OVERRIDE=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH//./\\.}.overrides.$IMAGE_NAME.build.context false) - if [ ! $ENVIRONMENT_BUILD_CONTEXT_OVERRIDE == "false" ]; then - BUILD_CONTEXT=$ENVIRONMENT_BUILD_CONTEXT_OVERRIDE - fi - - if [ ! -f $BUILD_CONTEXT/$DOCKERFILE ]; then - echo "defined Dockerfile $DOCKERFILE for service $IMAGE_NAME not found"; exit 1; - fi - + # otherwise extract build information from the image build data payload + # this is a temporary image name to use for the build, it is based on the namespace and service, this can probably be deprecated and the images could just be + # built with the name they are meant to be. only 1 build can run at a time within a namespace + # the temporary name would clash here as well if there were multiple builds (it could use the `imageBuild.buildImage` value) + TEMPORARY_IMAGE_NAME=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.temporaryImage' // false) + # the context for this image build, the original source for this value is from the `docker-compose file` + BUILD_CONTEXT=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.context' // "") + # the build target for this image build, the original source for this value is from the `docker-compose file` + BUILD_TARGET=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.target' // false) set +x # reduce noise in build logs - # Decide whether to use BuildKit for Docker builds - disabled by default. + # determine if buildkit should be used for this build DOCKER_BUILDKIT=0 - - if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then - DOCKER_BUILDKIT=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "DOCKER_BUILDKIT") | "\(.value)"')) - fi - if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then - TEMP_DOCKER_BUILDKIT=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "DOCKER_BUILDKIT") | "\(.value)"')) - if [ ! -z $TEMP_DOCKER_BUILDKIT ]; then - DOCKER_BUILDKIT=$TEMP_DOCKER_BUILDKIT - fi - fi - - case "$DOCKER_BUILDKIT" in - 1|t|T|true|TRUE|True) + if [ "$(echo ${ENVIRONMENT_IMAGE_BUILD_DATA} | jq -r '.buildKit' // false)" == "true" ]; then DOCKER_BUILDKIT=1 echo "Using BuildKit for $DOCKERFILE"; - ;; - *) - DOCKER_BUILDKIT=0 - ;; - esac - set -x + fi + done - . /kubectl-build-deploy/scripts/exec-build.sh + # now do the actual image build + if [ $BUILD_TARGET == "false" ]; then + echo "Building ${BUILD_CONTEXT}/${DOCKERFILE}" + DOCKER_BUILDKIT=$DOCKER_BUILDKIT docker build --network=host "${BUILD_ARGS[@]}" -t $TEMPORARY_IMAGE_NAME -f $BUILD_CONTEXT/$DOCKERFILE $BUILD_CONTEXT + else + echo "Building target ${BUILD_TARGET} for ${BUILD_CONTEXT}/${DOCKERFILE}" + DOCKER_BUILDKIT=$DOCKER_BUILDKIT docker build --network=host "${BUILD_ARGS[@]}" -t $TEMPORARY_IMAGE_NAME -f $BUILD_CONTEXT/$DOCKERFILE --target $BUILD_TARGET $BUILD_CONTEXT + fi + set -x - # Keep a list of the images we have built, as we need to push them to the OpenShift Registry later - IMAGES_BUILD["${IMAGE_NAME}"]="${TEMPORARY_IMAGE_NAME}" + # Keep a list of the images we have built, as we need to push them to the registry later + IMAGES_BUILD["${SERVICE_NAME}"]="${TEMPORARY_IMAGE_NAME}" # adding the build image to the list of arguments passed into the next image builds - BUILD_ARGS+=(--build-arg ${IMAGE_NAME_UPPERCASE}_IMAGE=${TEMPORARY_IMAGE_NAME}) + SERVICE_NAME_UPPERCASE=$(echo "$SERVICE_NAME" | tr '[:lower:]' '[:upper:]') fi - done - fi set +x @@ -917,24 +825,9 @@ yq3 write -i -- /kubectl-build-deploy/values.yaml 'gitSha' $LAGOON_GIT_SHA yq3 write -i -- /kubectl-build-deploy/values.yaml 'buildType' $BUILD_TYPE yq3 write -i -- /kubectl-build-deploy/values.yaml 'kubernetes' $KUBERNETES yq3 write -i -- /kubectl-build-deploy/values.yaml 'lagoonVersion' $LAGOON_VERSION -if [ "$ADMIN_LAGOON_FEATURE_FLAG_CONTAINER_MEMORY_LIMIT" ]; then - yq3 write -i -- /kubectl-build-deploy/values.yaml 'resources.limits.memory' "$ADMIN_LAGOON_FEATURE_FLAG_CONTAINER_MEMORY_LIMIT" -fi -if [ "$ADMIN_LAGOON_FEATURE_FLAG_EPHEMERAL_STORAGE_REQUESTS" ]; then - yq3 write -i -- /kubectl-build-deploy/values.yaml 'resources.requests.ephemeral-storage' "$ADMIN_LAGOON_FEATURE_FLAG_EPHEMERAL_STORAGE_REQUESTS" -fi -if [ "$ADMIN_LAGOON_FEATURE_FLAG_EPHEMERAL_STORAGE_LIMIT" ]; then - yq3 write -i -- /kubectl-build-deploy/values.yaml 'resources.limits.ephemeral-storage' "$ADMIN_LAGOON_FEATURE_FLAG_EPHEMERAL_STORAGE_LIMIT" -fi # check for ROOTLESS_WORKLOAD feature flag, disabled by default set +x -if [ "$(featureFlag ROOTLESS_WORKLOAD)" = enabled ]; then - yq3 merge -ix -- /kubectl-build-deploy/values.yaml /kubectl-build-deploy/rootless.values.yaml -fi -if [ "$(featureFlag FS_ON_ROOT_MISMATCH)" = enabled ]; then - yq3 write -i -- /kubectl-build-deploy/values.yaml 'podSecurityContext.fsGroupChangePolicy' "OnRootMismatch" -fi if [ "${SCC_CHECK}" != "false" ]; then # openshift permissions are different, this is to set the fsgroup to the supplemental group from the openshift annotations # this applies it to all deployments in this environment because we don't isolate by service type its applied to all @@ -944,18 +837,6 @@ if [ "${SCC_CHECK}" != "false" ]; then fi set -x - -echo -e "\ -imagePullSecrets:\n\ -" >> /kubectl-build-deploy/values.yaml - -for REGISTRY_SECRET in "${REGISTRY_SECRETS[@]}" -do - echo -e "\ - - name: "${REGISTRY_SECRET}"\n\ -" >> /kubectl-build-deploy/values.yaml -done - echo -e "\ LAGOON_PROJECT=${PROJECT}\n\ LAGOON_ENVIRONMENT=${ENVIRONMENT}\n\ @@ -1441,85 +1322,65 @@ export CONFIG_MAP_SHA yq3 write -i -- /kubectl-build-deploy/values.yaml 'configMapSha' $CONFIG_MAP_SHA ############################################## -### PUSH IMAGES TO OPENSHIFT REGISTRY +### PUSH IMAGES TO REGISTRY ############################################## +# pullrequest/branch start if [ "$BUILD_TYPE" == "pullrequest" ] || [ "$BUILD_TYPE" == "branch" ]; then # All images that should be pulled are copied to the harbor registry for IMAGE_NAME in "${!IMAGES_PULL[@]}" do - PULL_IMAGE="${IMAGES_PULL[${IMAGE_NAME}]}" + PULL_IMAGE="${IMAGES_PULL[${IMAGE_NAME}]}" #extract the pull image name from the images to pull list + PUSH_IMAGE="${IMAGES_PUSH[${IMAGE_NAME}]}" #extract the push image name from the images to push list # Try to handle private registries first - if [ $PRIVATE_REGISTRY_COUNTER -gt 0 ]; then - if [ $PRIVATE_EXTERNAL_REGISTRY ]; then - EXTERNAL_REGISTRY=0 - for EXTERNAL_REGISTRY_URL in "${PRIVATE_REGISTRY_URLS[@]}" - do - # strip off "http://" or "https://" from registry url if present - bare_url="${EXTERNAL_REGISTRY_URL#http://}" - bare_url="${EXTERNAL_REGISTRY_URL#https://}" - - # Test registry to see if image is from an external registry or just private docker hub - case $bare_url in - "$PULL_IMAGE"*) - EXTERNAL_REGISTRY=1 - ;; - esac - done - - # If this image is hosted in an external registry, pull it from there - if [ $EXTERNAL_REGISTRY -eq 1 ]; then - skopeo copy --retry-times 5 --dest-tls-verify=false docker://${PULL_IMAGE} docker://${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG:-latest} - # If this image is not from an external registry, but docker hub creds were supplied, pull it straight from Docker Hub - elif [ $PRIVATE_DOCKER_HUB_REGISTRY -eq 1 ]; then - skopeo copy --retry-times 5 --dest-tls-verify=false docker://${PULL_IMAGE} docker://${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG:-latest} - # If image not from an external registry and no docker hub creds were supplied, pull image from the imagecache - else - skopeo copy --retry-times 5 --dest-tls-verify=false docker://${IMAGECACHE_REGISTRY}${PULL_IMAGE} docker://${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG:-latest} - fi - # If the private registry counter is 1 and no external registry was listed, we know a private docker hub was specified - else - skopeo copy --retry-times 5 --dest-tls-verify=false docker://${PULL_IMAGE} docker://${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG:-latest} - fi - # If no private registries, use the imagecache - else - skopeo copy --retry-times 5 --dest-tls-verify=false docker://${IMAGECACHE_REGISTRY}${PULL_IMAGE} docker://${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG:-latest} - fi - IMAGE_HASHES[${IMAGE_NAME}]=$(skopeo inspect --retry-times 5 docker://${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG:-latest} --tls-verify=false | jq ".Name + \"@\" + .Digest" -r) + # the external pull image name is all calculated in the build-deploy tool now, it knows how to calculate it + # from being a promote image, or an image from an imagecache or from some other registry entirely + skopeo copy --retry-times 5 --dest-tls-verify=false docker://${PULL_IMAGE} docker://${PUSH_IMAGE} + + # store the resulting image hash + IMAGE_HASHES[${IMAGE_NAME}]=$(skopeo inspect --retry-times 5 docker://${PUSH_IMAGE} --tls-verify=false | jq ".Name + \"@\" + .Digest" -r) done for IMAGE_NAME in "${!IMAGES_BUILD[@]}" do + PUSH_IMAGE="${IMAGES_PUSH[${IMAGE_NAME}]}" #extract the push image name from the images to push list # Before the push the temporary name is resolved to the future tag with the registry in the image name TEMPORARY_IMAGE_NAME="${IMAGES_BUILD[${IMAGE_NAME}]}" # This will actually not push any images and instead just add them to the file /kubectl-build-deploy/lagoon/push - . /kubectl-build-deploy/scripts/exec-push-parallel.sh + # this file is used to perform parallel image pushes next + docker tag ${TEMPORARY_IMAGE_NAME} ${PUSH_IMAGE} + echo "docker push ${PUSH_IMAGE}" >> /kubectl-build-deploy/lagoon/push done - # If we have Images to Push to the OpenRegistry, let's do so + # If we have images to push to the registry, let's do so if [ -f /kubectl-build-deploy/lagoon/push ]; then parallel --retries 4 < /kubectl-build-deploy/lagoon/push fi - # load the image hashes for just pushed Images + # load the image hashes for just pushed images for IMAGE_NAME in "${!IMAGES_BUILD[@]}" do JQ_QUERY=(jq -r ".[]|select(test(\"${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}@\"))") - IMAGE_HASHES[${IMAGE_NAME}]=$(docker inspect ${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG:-latest} --format '{{json .RepoDigests}}' | "${JQ_QUERY[@]}") + IMAGE_HASHES[${IMAGE_NAME}]=$(docker inspect ${PUSH_IMAGE} --format '{{json .RepoDigests}}' | "${JQ_QUERY[@]}") done +# pullrequest/branch end +# promote start elif [ "$BUILD_TYPE" == "promote" ]; then for IMAGE_NAME in "${IMAGES[@]}" do - . /kubectl-build-deploy/scripts/exec-kubernetes-promote.sh - IMAGE_HASHES[${IMAGE_NAME}]=$(skopeo inspect --retry-times 5 docker://${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG:-latest} --tls-verify=false | jq ".Name + \"@\" + .Digest" -r) - done + PUSH_IMAGE="${IMAGES_PUSH[${IMAGE_NAME}]}" #extract the push image name from the images to push list + PROMOTE_IMAGE="${IMAGES_PROMOTE[${IMAGE_NAME}]}" #extract the push image name from the images to push list + skopeo copy --retry-times 5 --src-tls-verify=false --dest-tls-verify=false docker://${PROMOTE_IMAGE} docker://${PUSH_IMAGE} + IMAGE_HASHES[${IMAGE_NAME}]=$(skopeo inspect --retry-times 5 docker://${PUSH_IMAGE} --tls-verify=false | jq ".Name + \"@\" + .Digest" -r) + done +# promote end fi set +x @@ -1578,14 +1439,6 @@ if [ ! "$BACKUPS_DISABLED" == true ]; then else echo ">> Backup configurations disabled for this build" fi - -# check for ISOLATION_NETWORK_POLICY feature flag, disabled by default -if [ "$(featureFlag ISOLATION_NETWORK_POLICY)" = enabled ]; then - # add namespace isolation network policy to deployment - helm template isolation-network-policy /kubectl-build-deploy/helmcharts/isolation-network-policy \ - -f /kubectl-build-deploy/values.yaml \ - > $YAML_FOLDER/isolation-network-policy.yaml -fi set -x if [ "$(ls -A $YAML_FOLDER/)" ]; then @@ -1631,17 +1484,6 @@ set -x set +x if [ "$(ls -A $LAGOON_SERVICES_YAML_FOLDER/)" ]; then - if [ "$CI" == "true" ]; then - # During CI tests of Lagoon itself we only have a single compute node, so we change podAntiAffinity to podAffinity - find $LAGOON_SERVICES_YAML_FOLDER -type f -print0 | xargs -0 sed -i s/podAntiAffinity/podAffinity/g - # During CI tests of Lagoon itself we only have a single compute node, so we change ReadWriteMany to ReadWriteOnce - find $LAGOON_SERVICES_YAML_FOLDER -type f -print0 | xargs -0 sed -i s/ReadWriteMany/ReadWriteOnce/g - fi - if [ "$(featureFlag RWX_TO_RWO)" = enabled ]; then - # If there is only a single compute node, this can be used to change RWX to RWO - find $LAGOON_SERVICES_YAML_FOLDER -type f -print0 | xargs -0 sed -i s/ReadWriteMany/ReadWriteOnce/g - fi - echo "=== deployment templates for services ===" ls -A $LAGOON_SERVICES_YAML_FOLDER @@ -1804,9 +1646,7 @@ if [ "$(featureFlag INSIGHTS)" = enabled ]; then for IMAGE_NAME in "${!IMAGES_BUILD[@]}" do - - IMAGE_TAG="${IMAGE_TAG:-latest}" - IMAGE_FULL="${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG}" + IMAGE_FULL="${IMAGES_PUSH[${IMAGE_NAME}]}" #extract the push image name from the images to push list . /kubectl-build-deploy/scripts/exec-generate-insights-configmap.sh done diff --git a/legacy/build-deploy.sh b/legacy/build-deploy.sh index f852c9cc..2138a134 100755 --- a/legacy/build-deploy.sh +++ b/legacy/build-deploy.sh @@ -12,7 +12,6 @@ set -x REGISTRY=$REGISTRY NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace) -REGISTRY_REPOSITORY=$NAMESPACE LAGOON_VERSION=$(cat /lagoon/version) set +x # reduce noise in build logs @@ -23,12 +22,6 @@ if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then fi set -x -if [ "$CI" == "true" ]; then - CI_OVERRIDE_IMAGE_REPO=172.17.0.1:5000/lagoon -else - CI_OVERRIDE_IMAGE_REPO="" -fi - echo -e "##############################################\nBEGIN Checkout Repository\n##############################################" if [ "$BUILD_TYPE" == "pullrequest" ]; then /kubectl-build-deploy/scripts/git-checkout-pull-merge.sh "$SOURCE_REPOSITORY" "$PR_HEAD_SHA" "$PR_BASE_SHA" @@ -44,13 +37,25 @@ if [ ! -f .lagoon.yml ]; then echo "no .lagoon.yml file found"; exit 1; fi +################## +# build deploy-tool can collect this value now from the lagoon.yml file +# this means further use of `LAGOON_GIT_SHA` can eventually be +# completely handled with build-deploy-tool wherever this value could be consumed +# this logic can then just be replaced entirely with a single export so that the build-deploy-tool +# will know what the value is, and performs the switch based on what the lagoon.yml provides +# this is retained for now until the remaining functionality that uses it is moved to the build-deploy-tool +# +# export LAGOON_GIT_SHA=`git rev-parse HEAD` +# INJECT_GIT_SHA=$(cat .lagoon.yml | shyaml get-value environment_variables.git_sha false) if [ "$INJECT_GIT_SHA" == "true" ] then - LAGOON_GIT_SHA=`git rev-parse HEAD` + # export this so the build-deploy-tool can read it + export LAGOON_GIT_SHA=`git rev-parse HEAD` else - LAGOON_GIT_SHA="0000000000000000000000000000000000000000" + export LAGOON_GIT_SHA="0000000000000000000000000000000000000000" fi +################## echo -e "##############################################\nBEGIN Kubernetes and Container Registry Setup\n##############################################" sleep 0.5s @@ -220,6 +225,14 @@ do fi done if [ ! -z $PRIVATE_CONTAINER_REGISTRIES ]; then + if [ $PRIVATE_REGISTRY_COUNTER -gt 0 ]; then + if [ $PRIVATE_EXTERNAL_REGISTRY ]; then + # export the external registry urls so that the build-deploy-tool can consume it later on + export EXTERNAL_REGISTRY_URLS=$(echo ${PRIVATE_REGISTRY_URLS[*]} | tr ' ' ,) + # export all the external registry secret names so that the build-deploy-tool can consume it later on + export EXTERNAL_REGISTRY_SECRETS=$(echo ${REGISTRY_SECRETS[*]} | tr ' ' ,) + fi + fi echo -e "##############################################\nEND Custom Container Registries Setup\n##############################################" sleep 0.5s fi From 7644928f4768d954bacc0675b394e826e0a4d9bd Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 12 Jan 2024 20:47:11 +1100 Subject: [PATCH 55/92] test: fix test name --- cmd/template_lagoonservices_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index 96e1023e..1483f61b 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -157,7 +157,7 @@ func TestTemplateLagoonServices(t *testing.T) { want: "internal/testdata/basic/service-templates/service4", }, { - name: "test6 basic deployment pr", + name: "test6 basic deployment pr with isolation network policy", args: testdata.GetSeedData( testdata.TestData{ ProjectName: "example-project", From 47ee6f816d3e0aeaf86df2aa64e95dbda69a2f09 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 15 Jan 2024 11:13:20 +1100 Subject: [PATCH 56/92] test: github actions sets CI variable, this needs to be disabled in tests --- cmd/config_fastly_test.go | 1 + cmd/identify_feature_test.go | 1 + cmd/identify_imagebuild_test.go | 1 + cmd/identify_ingress_test.go | 2 ++ cmd/identify_lagoonservices_test.go | 1 + cmd/identify_native_cronjobs_test.go | 1 + cmd/template_autogen_ingress_test.go | 1 + cmd/template_backups_test.go | 1 + cmd/template_dbaas_test.go | 1 + cmd/template_ingress_test.go | 1 + cmd/template_lagoonservices_test.go | 1 + internal/helpers/helpers.go | 1 + 12 files changed, 13 insertions(+) diff --git a/cmd/config_fastly_test.go b/cmd/config_fastly_test.go index add15c5f..a3eccc03 100644 --- a/cmd/config_fastly_test.go +++ b/cmd/config_fastly_test.go @@ -120,6 +120,7 @@ func TestGenerateFastlyConfig(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + helpers.UnsetEnvVars(nil) //unset variables before running tests // set the environment variables from args err := os.Setenv("LAGOON_FASTLY_NOCACHE_SERVICE_ID", tt.args.cacheNoCache) if err != nil { diff --git a/cmd/identify_feature_test.go b/cmd/identify_feature_test.go index 54d4791e..b1468c73 100644 --- a/cmd/identify_feature_test.go +++ b/cmd/identify_feature_test.go @@ -185,6 +185,7 @@ func TestIdentifyFeatureFlag(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + helpers.UnsetEnvVars(tt.vars) //unset variables before running tests // set the environment variables from args savedTemplates := tt.templatePath generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) diff --git a/cmd/identify_imagebuild_test.go b/cmd/identify_imagebuild_test.go index e106abae..7be84b3d 100644 --- a/cmd/identify_imagebuild_test.go +++ b/cmd/identify_imagebuild_test.go @@ -563,6 +563,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + helpers.UnsetEnvVars(tt.vars) //unset variables before running tests for _, envVar := range tt.vars { err := os.Setenv(envVar.Name, envVar.Value) if err != nil { diff --git a/cmd/identify_ingress_test.go b/cmd/identify_ingress_test.go index 907ebd58..7b05a5bd 100644 --- a/cmd/identify_ingress_test.go +++ b/cmd/identify_ingress_test.go @@ -5,6 +5,7 @@ import ( "reflect" "testing" + "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" "github.com/uselagoon/build-deploy-tool/internal/testdata" @@ -348,6 +349,7 @@ func TestIdentifyRoute(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + helpers.UnsetEnvVars(nil) //unset variables before running tests // set the environment variables from args savedTemplates := tt.templatePath generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) diff --git a/cmd/identify_lagoonservices_test.go b/cmd/identify_lagoonservices_test.go index 20e6e6fe..cc6e9f87 100644 --- a/cmd/identify_lagoonservices_test.go +++ b/cmd/identify_lagoonservices_test.go @@ -310,6 +310,7 @@ func TestIdentifyLagoonServices(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + helpers.UnsetEnvVars(nil) //unset variables before running tests // set the environment variables from args savedTemplates := "testoutput" generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) diff --git a/cmd/identify_native_cronjobs_test.go b/cmd/identify_native_cronjobs_test.go index 2d1970bc..54e85f38 100644 --- a/cmd/identify_native_cronjobs_test.go +++ b/cmd/identify_native_cronjobs_test.go @@ -92,6 +92,7 @@ func TestIdentifyNativeCronjobs(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + helpers.UnsetEnvVars(nil) //unset variables before running tests // set the environment variables from args savedTemplates := tt.templatePath generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) diff --git a/cmd/template_autogen_ingress_test.go b/cmd/template_autogen_ingress_test.go index 35f64304..9a300e41 100644 --- a/cmd/template_autogen_ingress_test.go +++ b/cmd/template_autogen_ingress_test.go @@ -486,6 +486,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + helpers.UnsetEnvVars(nil) //unset variables before running tests // set the environment variables from args savedTemplates := tt.templatePath generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) diff --git a/cmd/template_backups_test.go b/cmd/template_backups_test.go index 1bf4cb18..26807fc7 100644 --- a/cmd/template_backups_test.go +++ b/cmd/template_backups_test.go @@ -197,6 +197,7 @@ func TestBackupTemplateGeneration(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + helpers.UnsetEnvVars(nil) //unset variables before running tests // set the environment variables from args savedTemplates := tt.templatePath generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) diff --git a/cmd/template_dbaas_test.go b/cmd/template_dbaas_test.go index a07e75fb..2a0c6368 100644 --- a/cmd/template_dbaas_test.go +++ b/cmd/template_dbaas_test.go @@ -37,6 +37,7 @@ func TestDBaaSTemplateGeneration(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + helpers.UnsetEnvVars(nil) //unset variables before running tests // set the environment variables from args savedTemplates := tt.templatePath generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) diff --git a/cmd/template_ingress_test.go b/cmd/template_ingress_test.go index acac2191..e8f68bc9 100644 --- a/cmd/template_ingress_test.go +++ b/cmd/template_ingress_test.go @@ -387,6 +387,7 @@ func TestTemplateRoutes(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + helpers.UnsetEnvVars(nil) //unset variables before running tests // set the environment variables from args savedTemplates := tt.templatePath generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index 1483f61b..afbaa948 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -186,6 +186,7 @@ func TestTemplateLagoonServices(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + helpers.UnsetEnvVars(tt.vars) //unset variables before running tests for _, envVar := range tt.vars { err := os.Setenv(envVar.Name, envVar.Value) if err != nil { diff --git a/internal/helpers/helpers.go b/internal/helpers/helpers.go index 05e652c8..8a01db88 100644 --- a/internal/helpers/helpers.go +++ b/internal/helpers/helpers.go @@ -234,6 +234,7 @@ func UnsetEnvVars(localVars []EnvironmentVariable) { "DBAAS_OPERATOR_HTTP", "CONFIG_MAP_SHA", "LAGOON_FEATURE_FLAG_IMAGECACHE_REGISTRY", + "CI", } for _, varName := range varNames { os.Unsetenv(varName) From 59329ee73a9aef7dac088f5b7154fb4083ee41aa Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 29 Jan 2024 18:10:34 +1100 Subject: [PATCH 57/92] fix: add missing container information for other templates --- internal/servicetypes/basic.go | 9 +-- internal/servicetypes/cli.go | 5 +- internal/servicetypes/elasticsearch.go | 48 +++++++++++- internal/servicetypes/mariadb.go | 54 +++++++++++++- internal/servicetypes/mongodb.go | 54 +++++++++++++- internal/servicetypes/nginx.go | 22 +++--- internal/servicetypes/node.go | 9 +-- internal/servicetypes/opensearch.go | 50 ++++++++++++- internal/servicetypes/postgres.go | 4 +- internal/servicetypes/python.go | 9 +-- internal/servicetypes/rabbitmq.go | 4 +- internal/servicetypes/redis.go | 12 ++- internal/servicetypes/solr.go | 4 +- internal/servicetypes/varnish.go | 12 ++- internal/servicetypes/worker.go | 9 +-- .../deployment/result-basic-1.yaml | 5 ++ .../deployment/result-basic-2.yaml | 1 + .../deployment/result-basic-3.yaml | 1 + .../deployment/result-elasticsearch-1.yaml | 46 +++++++++++- .../deployment/result-mariadb-1.yaml | 27 ++++++- .../deployment/result-mongodb-1.yaml | 27 ++++++- .../deployment/result-nginx-1.yaml | 4 + .../deployment/result-nginx-2.yaml | 4 + .../deployment/result-node-1.yaml | 2 + .../deployment/result-opensearch-1.yaml | 74 ++++++++++++++----- .../deployment/result-postgres-1.yaml | 1 + .../deployment/result-postgres-single-1.yaml | 1 + .../deployment/result-python-1.yaml | 2 + .../deployment/result-rabbitmq-1.yaml | 1 + .../deployment/result-redis-1.yaml | 25 ++++++- .../deployment/result-solr-1.yaml | 1 + .../deployment/result-varnish-1.yaml | 28 ++++++- .../deployment/result-worker-1.yaml | 2 + .../pvc/result-opensearch-1.yaml | 12 +-- .../service/result-opensearch-1.yaml | 16 ++-- .../service1/deployment-node.yaml | 1 + .../service2/deployment-lnd.yaml | 1 + .../service2/deployment-thunderhub.yaml | 1 + .../service2/deployment-tor.yaml | 1 + .../service3/deployment-lnd.yaml | 1 + .../service3/deployment-tor.yaml | 1 + .../service4/deployment-node.yaml | 1 + .../service5/deployment-node.yaml | 1 + .../service1/deployment-nginx-php.yaml | 2 + .../service1/deployment-redis.yaml | 1 + .../service1/deployment-varnish.yaml | 1 + .../service2/deployment-nginx-php.yaml | 2 + .../service2/deployment-redis.yaml | 1 + .../service2/deployment-varnish.yaml | 1 + 49 files changed, 495 insertions(+), 106 deletions(-) diff --git a/internal/servicetypes/basic.go b/internal/servicetypes/basic.go index 149cac96..f85dc07b 100644 --- a/internal/servicetypes/basic.go +++ b/internal/servicetypes/basic.go @@ -26,9 +26,9 @@ var basic = ServiceType{ }, }, PrimaryContainer: ServiceContainer{ - Name: "basic", - ImagePullPolicy: corev1.PullAlways, + Name: "basic", Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{ { Name: "basic", @@ -75,9 +75,8 @@ var basicPersistent = ServiceType{ Name: "basic-persistent", Ports: basic.Ports, PrimaryContainer: ServiceContainer{ - Name: basic.PrimaryContainer.Name, - ImagePullPolicy: basic.PrimaryContainer.ImagePullPolicy, - Container: basic.PrimaryContainer.Container, + Name: basic.PrimaryContainer.Name, + Container: basic.PrimaryContainer.Container, }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", diff --git a/internal/servicetypes/cli.go b/internal/servicetypes/cli.go index ad3bd8df..bcbde51c 100644 --- a/internal/servicetypes/cli.go +++ b/internal/servicetypes/cli.go @@ -59,9 +59,8 @@ var cli = ServiceType{ var cliPersistent = ServiceType{ Name: "cli-persistent", PrimaryContainer: ServiceContainer{ - Name: cli.PrimaryContainer.Name, - ImagePullPolicy: cli.PrimaryContainer.ImagePullPolicy, - Container: cli.PrimaryContainer.Container, + Name: cli.PrimaryContainer.Name, + Container: cli.PrimaryContainer.Container, Volumes: append(cli.PrimaryContainer.Volumes, corev1.Volume{ Name: "{{ .ServiceValues.PersistentVolumeName }}-twig", VolumeSource: corev1.VolumeSource{ diff --git a/internal/servicetypes/elasticsearch.go b/internal/servicetypes/elasticsearch.go index f38b646d..14a73f00 100644 --- a/internal/servicetypes/elasticsearch.go +++ b/internal/servicetypes/elasticsearch.go @@ -4,7 +4,9 @@ import ( "fmt" "github.com/uselagoon/build-deploy-tool/internal/helpers" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -26,8 +28,47 @@ var elasticsearch = ServiceType{ }, }, PrimaryContainer: ServiceContainer{ - Name: "elasticsearch", - ImagePullPolicy: corev1.PullAlways, + Name: "elasticsearch", + Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, + Ports: []corev1.ContainerPort{ + { + Name: fmt.Sprintf("%d-tcp", defaultElasticsearchPort), + ContainerPort: defaultElasticsearchPort, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: defaultElasticsearchPort, + }, + }, + }, + InitialDelaySeconds: 1, + TimeoutSeconds: 1, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: defaultElasticsearchPort, + }, + }, + }, + InitialDelaySeconds: 120, + PeriodSeconds: 5, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("10Mi"), + }, + }, + }, }, InitContainer: ServiceContainer{ Name: "set-max-map-count", @@ -51,6 +92,9 @@ fi`, }, }, }, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RecreateDeploymentStrategyType, + }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, diff --git a/internal/servicetypes/mariadb.go b/internal/servicetypes/mariadb.go index 6f2b933d..25430cd2 100644 --- a/internal/servicetypes/mariadb.go +++ b/internal/servicetypes/mariadb.go @@ -3,7 +3,9 @@ package servicetypes import ( "fmt" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -24,13 +26,63 @@ var mariadbSingle = ServiceType{ }, }, }, + PrimaryContainer: ServiceContainer{ + Name: "mariadb-single", + Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, + Ports: []corev1.ContainerPort{ + { + Name: fmt.Sprintf("%d-tcp", defaultMariaDBPort), + ContainerPort: defaultMariaDBPort, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: defaultMariaDBPort, + }, + }, + }, + InitialDelaySeconds: 1, + TimeoutSeconds: 1, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: defaultMariaDBPort, + }, + }, + }, + InitialDelaySeconds: 120, + PeriodSeconds: 5, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("10Mi"), + }, + }, + }, + }, + PodSecurityContext: ServicePodSecurityContext{ + HasDefault: true, + FSGroup: 0, + }, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RecreateDeploymentStrategyType, + }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/var/lib/mysql", BackupConfiguration: BackupConfiguration{ Command: `/bin/sh -c 'mysqldump --max-allowed-packet=500M --events --routines --quick --add-locks --no-autocommit --single-transaction --all-databases'`, - FileExtension: ".{{ .OverrideName }}.sql", + FileExtension: ".{{ .ServiceValues.OverrideName }}.sql", }, }, } diff --git a/internal/servicetypes/mongodb.go b/internal/servicetypes/mongodb.go index f1392a2a..f9c2caf3 100644 --- a/internal/servicetypes/mongodb.go +++ b/internal/servicetypes/mongodb.go @@ -3,7 +3,9 @@ package servicetypes import ( "fmt" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -24,13 +26,63 @@ var mongodbSingle = ServiceType{ }, }, }, + PrimaryContainer: ServiceContainer{ + Name: "mongodb-single", + Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, + Ports: []corev1.ContainerPort{ + { + Name: fmt.Sprintf("%d-tcp", defaultMongoDBPort), + ContainerPort: defaultMongoDBPort, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: defaultMongoDBPort, + }, + }, + }, + InitialDelaySeconds: 1, + TimeoutSeconds: 1, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: defaultMongoDBPort, + }, + }, + }, + InitialDelaySeconds: 120, + PeriodSeconds: 5, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("10Mi"), + }, + }, + }, + }, + PodSecurityContext: ServicePodSecurityContext{ + HasDefault: true, + FSGroup: 0, + }, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RecreateDeploymentStrategyType, + }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/data/db", BackupConfiguration: BackupConfiguration{ Command: `/bin/sh -c 'tar -cf - -C "/data/db" --exclude="lost\+found" . || [ $? -eq 1 ]'`, - FileExtension: ".{{ .OverrideName }}.tar", + FileExtension: ".{{ .ServiceValues.OverrideName }}.tar", }, }, } diff --git a/internal/servicetypes/nginx.go b/internal/servicetypes/nginx.go index 48cd6d3a..98d27434 100644 --- a/internal/servicetypes/nginx.go +++ b/internal/servicetypes/nginx.go @@ -26,9 +26,9 @@ var nginx = ServiceType{ }, }, PrimaryContainer: ServiceContainer{ - Name: "nginx", - ImagePullPolicy: corev1.PullAlways, + Name: "nginx", Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{ { Name: "http", @@ -77,9 +77,9 @@ var nginxPHP = ServiceType{ Name: "nginx-php", Ports: nginx.Ports, PrimaryContainer: ServiceContainer{ - Name: "nginx", - ImagePullPolicy: corev1.PullAlways, + Name: "nginx", Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{ { Name: "http", @@ -129,9 +129,9 @@ var nginxPHP = ServiceType{ }, }, SecondaryContainer: ServiceContainer{ - Name: "php", - ImagePullPolicy: corev1.PullAlways, + Name: "php", Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{ { Name: "http", @@ -220,14 +220,12 @@ fi`, }, }, PrimaryContainer: ServiceContainer{ - Name: nginxPHP.PrimaryContainer.Name, - ImagePullPolicy: nginxPHP.PrimaryContainer.ImagePullPolicy, - Container: nginxPHP.PrimaryContainer.Container, + Name: nginxPHP.PrimaryContainer.Name, + Container: nginxPHP.PrimaryContainer.Container, }, SecondaryContainer: ServiceContainer{ - Name: nginxPHP.SecondaryContainer.Name, - ImagePullPolicy: nginxPHP.SecondaryContainer.ImagePullPolicy, - Container: nginxPHP.SecondaryContainer.Container, + Name: nginxPHP.SecondaryContainer.Name, + Container: nginxPHP.SecondaryContainer.Container, Volumes: []corev1.Volume{ { Name: "{{ .ServiceValues.PersistentVolumeName }}-twig", diff --git a/internal/servicetypes/node.go b/internal/servicetypes/node.go index 3dcc630b..a28f4822 100644 --- a/internal/servicetypes/node.go +++ b/internal/servicetypes/node.go @@ -24,9 +24,9 @@ var node = ServiceType{ }, }, PrimaryContainer: ServiceContainer{ - Name: "node", - ImagePullPolicy: corev1.PullAlways, + Name: "node", Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{ { Name: "http", @@ -72,9 +72,8 @@ var nodePersistent = ServiceType{ Name: "node-persistent", Ports: node.Ports, PrimaryContainer: ServiceContainer{ - Name: node.PrimaryContainer.Name, - ImagePullPolicy: node.PrimaryContainer.ImagePullPolicy, - Container: node.PrimaryContainer.Container, + Name: node.PrimaryContainer.Name, + Container: node.PrimaryContainer.Container, }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", diff --git a/internal/servicetypes/opensearch.go b/internal/servicetypes/opensearch.go index fbc449b0..58009555 100644 --- a/internal/servicetypes/opensearch.go +++ b/internal/servicetypes/opensearch.go @@ -4,14 +4,16 @@ import ( "fmt" "github.com/uselagoon/build-deploy-tool/internal/helpers" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" ) var defaultOpensearchPort int32 = 9200 var opensearch = ServiceType{ - Name: "opensearch", + Name: "opensearch-persistent", Ports: ServicePorts{ Ports: []corev1.ServicePort{ { @@ -26,8 +28,47 @@ var opensearch = ServiceType{ }, }, PrimaryContainer: ServiceContainer{ - Name: "opensearch", - ImagePullPolicy: corev1.PullAlways, + Name: "opensearch", + Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, + Ports: []corev1.ContainerPort{ + { + Name: fmt.Sprintf("%d-tcp", defaultOpensearchPort), + ContainerPort: defaultOpensearchPort, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: defaultOpensearchPort, + }, + }, + }, + InitialDelaySeconds: 1, + TimeoutSeconds: 1, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + TCPSocket: &corev1.TCPSocketAction{ + Port: intstr.IntOrString{ + Type: intstr.Int, + IntVal: defaultOpensearchPort, + }, + }, + }, + InitialDelaySeconds: 120, + PeriodSeconds: 5, + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("10m"), + corev1.ResourceMemory: resource.MustParse("10Mi"), + }, + }, + }, }, InitContainer: ServiceContainer{ Name: "set-max-map-count", @@ -55,6 +96,9 @@ fi`, HasDefault: true, FSGroup: 0, }, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RecreateDeploymentStrategyType, + }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, diff --git a/internal/servicetypes/postgres.go b/internal/servicetypes/postgres.go index 1e327a40..743f0a80 100644 --- a/internal/servicetypes/postgres.go +++ b/internal/servicetypes/postgres.go @@ -27,9 +27,9 @@ var postgresSingle = ServiceType{ }, }, PrimaryContainer: ServiceContainer{ - Name: "postgres", - ImagePullPolicy: corev1.PullAlways, + Name: "postgres", Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{ { Name: fmt.Sprintf("%d-tcp", defaultPostgresPort), diff --git a/internal/servicetypes/python.go b/internal/servicetypes/python.go index d3c9ca4b..0d6987b6 100644 --- a/internal/servicetypes/python.go +++ b/internal/servicetypes/python.go @@ -24,9 +24,9 @@ var python = ServiceType{ }, }, PrimaryContainer: ServiceContainer{ - Name: "python", - ImagePullPolicy: corev1.PullAlways, + Name: "python", Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{ { Name: "http", @@ -72,9 +72,8 @@ var pythonPersistent = ServiceType{ Name: "python-persistent", Ports: python.Ports, PrimaryContainer: ServiceContainer{ - Name: python.PrimaryContainer.Name, - ImagePullPolicy: python.PrimaryContainer.ImagePullPolicy, - Container: python.PrimaryContainer.Container, + Name: python.PrimaryContainer.Name, + Container: python.PrimaryContainer.Container, }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", diff --git a/internal/servicetypes/rabbitmq.go b/internal/servicetypes/rabbitmq.go index a411b08a..d977a0e7 100644 --- a/internal/servicetypes/rabbitmq.go +++ b/internal/servicetypes/rabbitmq.go @@ -37,9 +37,9 @@ var rabbitmq = ServiceType{ }, }, PrimaryContainer: ServiceContainer{ - Name: "rabbitmq", - ImagePullPolicy: corev1.PullAlways, + Name: "rabbitmq", Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{ { Name: fmt.Sprintf("%d-tcp", defaultRabbitMQPort), diff --git a/internal/servicetypes/redis.go b/internal/servicetypes/redis.go index c85ecb39..748ebe13 100644 --- a/internal/servicetypes/redis.go +++ b/internal/servicetypes/redis.go @@ -26,9 +26,9 @@ var redis = ServiceType{ }, }, PrimaryContainer: ServiceContainer{ - Name: "redis", - ImagePullPolicy: corev1.PullAlways, + Name: "redis", Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{ { Name: fmt.Sprintf("%d-tcp", defaultRedisPort), @@ -73,13 +73,17 @@ var redis = ServiceType{ var redisPersistent = ServiceType{ Name: "redis-persistent", Ports: redis.Ports, + PrimaryContainer: ServiceContainer{ + Name: redis.PrimaryContainer.Name, + Container: redis.PrimaryContainer.Container, + }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/data", BackupConfiguration: BackupConfiguration{ - Command: `/bin/sh -c "/bin/busybox tar -cf - -C /data ."`, - FileExtension: ".{{ .OverrideName }}.tar", + Command: `/bin/sh -c "/bin/busybox tar -cf - -C {{ if .ServiceValues.PersistentVolumePath }}{{.ServiceValues.PersistentVolumePath}}{{else}}{{.ServiceTypeValues.Volumes.PersistentVolumePath}}{{end}} ."`, + FileExtension: ".{{ .ServiceValues.OverrideName }}.tar", }, }, } diff --git a/internal/servicetypes/solr.go b/internal/servicetypes/solr.go index 9b35f21b..7a60e42f 100644 --- a/internal/servicetypes/solr.go +++ b/internal/servicetypes/solr.go @@ -26,9 +26,9 @@ var solr = ServiceType{ }, }, PrimaryContainer: ServiceContainer{ - Name: "solr", - ImagePullPolicy: corev1.PullAlways, + Name: "solr", Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{ { Name: fmt.Sprintf("%d-tcp", defaultSolrPort), diff --git a/internal/servicetypes/varnish.go b/internal/servicetypes/varnish.go index 2d479581..3495a5f1 100644 --- a/internal/servicetypes/varnish.go +++ b/internal/servicetypes/varnish.go @@ -35,9 +35,9 @@ var varnish = ServiceType{ }, }, PrimaryContainer: ServiceContainer{ - Name: "varnish", - ImagePullPolicy: corev1.PullAlways, + Name: "varnish", Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{ { Name: "http", @@ -87,13 +87,17 @@ var varnish = ServiceType{ var varnishPersistent = ServiceType{ Name: "varnish-persistent", Ports: varnish.Ports, + PrimaryContainer: ServiceContainer{ + Name: varnish.PrimaryContainer.Name, + Container: varnish.PrimaryContainer.Container, + }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/var/cache/varnish", BackupConfiguration: BackupConfiguration{ - Command: `/bin/sh -c "/bin/busybox tar -cf - -C /var/cache/varnish ."`, - FileExtension: ".{{ .OverrideName }}.tar", + Command: `/bin/sh -c "/bin/busybox tar -cf - -C {{ if .ServiceValues.PersistentVolumePath }}{{.ServiceValues.PersistentVolumePath}}{{else}}{{.ServiceTypeValues.Volumes.PersistentVolumePath}}{{end}} ."`, + FileExtension: ".{{ .ServiceValues.OverrideName }}.tar", }, }, } diff --git a/internal/servicetypes/worker.go b/internal/servicetypes/worker.go index cd613d75..b65425d6 100644 --- a/internal/servicetypes/worker.go +++ b/internal/servicetypes/worker.go @@ -10,9 +10,9 @@ var defaultWorkerPort int32 = 3000 var worker = ServiceType{ Name: "worker", PrimaryContainer: ServiceContainer{ - Name: "worker", - ImagePullPolicy: corev1.PullAlways, + Name: "worker", Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, ReadinessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ Exec: &corev1.ExecAction{ @@ -47,8 +47,7 @@ var worker = ServiceType{ var workerPersistent = ServiceType{ Name: "worker-persistent", PrimaryContainer: ServiceContainer{ - Name: worker.PrimaryContainer.Name, - ImagePullPolicy: worker.PrimaryContainer.ImagePullPolicy, - Container: worker.PrimaryContainer.Container, + Name: worker.PrimaryContainer.Name, + Container: worker.PrimaryContainer.Container, }, } diff --git a/internal/templating/services/test-resources/deployment/result-basic-1.yaml b/internal/templating/services/test-resources/deployment/result-basic-1.yaml index a77b868b..8f1dc300 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-1.yaml @@ -56,6 +56,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: @@ -145,6 +146,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice-po@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: @@ -231,6 +233,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice-persist@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: @@ -317,6 +320,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice-persist-po@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: @@ -403,6 +407,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice-persist-posize@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/templating/services/test-resources/deployment/result-basic-2.yaml b/internal/templating/services/test-resources/deployment/result-basic-2.yaml index 9ddd46f9..e6f51315 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-2.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-2.yaml @@ -63,6 +63,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice-po@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/templating/services/test-resources/deployment/result-basic-3.yaml b/internal/templating/services/test-resources/deployment/result-basic-3.yaml index 3d2d7a35..11f096e8 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-3.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-3.yaml @@ -63,6 +63,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice-po@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml index 61688784..903df580 100644 --- a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml @@ -24,7 +24,8 @@ spec: matchLabels: app.kubernetes.io/instance: myservice app.kubernetes.io/name: elasticsearch - strategy: {} + strategy: + type: Recreate template: metadata: annotations: @@ -56,8 +57,26 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice@latest + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 9200 name: elasticsearch - resources: {} + ports: + - containerPort: 9200 + name: 9200-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 9200 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 10Mi volumeMounts: - mountPath: /usr/share/elasticsearch/data name: myservice @@ -114,7 +133,8 @@ spec: matchLabels: app.kubernetes.io/instance: myservice-size app.kubernetes.io/name: elasticsearch - strategy: {} + strategy: + type: Recreate template: metadata: annotations: @@ -146,8 +166,26 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice-size@latest + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 9200 name: elasticsearch - resources: {} + ports: + - containerPort: 9200 + name: 9200-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 9200 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 10Mi volumeMounts: - mountPath: /usr/share/elasticsearch/data name: myservice-size diff --git a/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml b/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml index e72e05c4..4eb03539 100644 --- a/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml @@ -24,14 +24,15 @@ spec: matchLabels: app.kubernetes.io/instance: mariadb app.kubernetes.io/name: mariadb-single - strategy: {} + strategy: + type: Recreate template: metadata: annotations: k8up.syn.tools/backupcommand: /bin/sh -c 'mysqldump --max-allowed-packet=500M --events --routines --quick --add-locks --no-autocommit --single-transaction --all-databases' - k8up.syn.tools/file-extension: . + k8up.syn.tools/file-extension: .mariadb.sql lagoon.sh/branch: environment-name lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x @@ -57,8 +58,26 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/mariadb@latest - name: "" - resources: {} + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 3306 + name: mariadb-single + ports: + - containerPort: 3306 + name: 3306-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 3306 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 10Mi volumeMounts: - mountPath: /var/lib/mysql name: mariadb diff --git a/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml b/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml index 161bad76..3e1850a1 100644 --- a/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml @@ -24,13 +24,14 @@ spec: matchLabels: app.kubernetes.io/instance: mongodb app.kubernetes.io/name: mongodb-single - strategy: {} + strategy: + type: Recreate template: metadata: annotations: k8up.syn.tools/backupcommand: /bin/sh -c 'tar -cf - -C "/data/db" --exclude="lost\+found" . || [ $? -eq 1 ]' - k8up.syn.tools/file-extension: . + k8up.syn.tools/file-extension: .mongodb.tar lagoon.sh/branch: environment-name lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x @@ -56,8 +57,26 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/mongodb@latest - name: "" - resources: {} + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 27017 + name: mongodb-single + ports: + - containerPort: 27017 + name: 27017-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 27017 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 10Mi volumeMounts: - mountPath: /data/db name: mongodb diff --git a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml index f366e2a3..037bde1a 100644 --- a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml @@ -55,6 +55,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/nginx@latest + imagePullPolicy: Always livenessProbe: failureThreshold: 5 httpGet: @@ -86,6 +87,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/php@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 periodSeconds: 10 @@ -171,6 +173,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/nginx2@latest + imagePullPolicy: Always livenessProbe: failureThreshold: 5 httpGet: @@ -205,6 +208,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/php2@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 periodSeconds: 10 diff --git a/internal/templating/services/test-resources/deployment/result-nginx-2.yaml b/internal/templating/services/test-resources/deployment/result-nginx-2.yaml index 8fd783ad..69265610 100644 --- a/internal/templating/services/test-resources/deployment/result-nginx-2.yaml +++ b/internal/templating/services/test-resources/deployment/result-nginx-2.yaml @@ -55,6 +55,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/nginx@latest + imagePullPolicy: Always livenessProbe: failureThreshold: 5 httpGet: @@ -86,6 +87,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/php@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 periodSeconds: 10 @@ -172,6 +174,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/nginx2@latest + imagePullPolicy: Always livenessProbe: failureThreshold: 5 httpGet: @@ -206,6 +209,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/php2@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 periodSeconds: 10 diff --git a/internal/templating/services/test-resources/deployment/result-node-1.yaml b/internal/templating/services/test-resources/deployment/result-node-1.yaml index 9adea579..2994ca9b 100644 --- a/internal/templating/services/test-resources/deployment/result-node-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-node-1.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/node@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: @@ -137,6 +138,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/node-persist@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml index e417e1bd..a65aa3ce 100644 --- a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml @@ -9,22 +9,23 @@ metadata: labels: app.kubernetes.io/instance: myservice app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: opensearch + app.kubernetes.io/name: opensearch-persistent 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: opensearch - lagoon.sh/template: opensearch-0.1.0 + lagoon.sh/service-type: opensearch-persistent + lagoon.sh/template: opensearch-persistent-0.1.0 name: myservice spec: replicas: 1 selector: matchLabels: app.kubernetes.io/instance: myservice - app.kubernetes.io/name: opensearch - strategy: {} + app.kubernetes.io/name: opensearch-persistent + strategy: + type: Recreate template: metadata: annotations: @@ -38,14 +39,14 @@ spec: labels: app.kubernetes.io/instance: myservice app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: opensearch + app.kubernetes.io/name: opensearch-persistent 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: opensearch - lagoon.sh/template: opensearch-0.1.0 + lagoon.sh/service-type: opensearch-persistent + lagoon.sh/template: opensearch-persistent-0.1.0 spec: containers: - env: @@ -56,8 +57,26 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice@latest + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 9200 name: opensearch - resources: {} + ports: + - containerPort: 9200 + name: 9200-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 9200 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 10Mi volumeMounts: - mountPath: /usr/share/opensearch/data name: myservice @@ -99,22 +118,23 @@ metadata: labels: app.kubernetes.io/instance: myservice-size app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: opensearch + app.kubernetes.io/name: opensearch-persistent lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-size - lagoon.sh/service-type: opensearch - lagoon.sh/template: opensearch-0.1.0 + lagoon.sh/service-type: opensearch-persistent + lagoon.sh/template: opensearch-persistent-0.1.0 name: myservice-size spec: replicas: 1 selector: matchLabels: app.kubernetes.io/instance: myservice-size - app.kubernetes.io/name: opensearch - strategy: {} + app.kubernetes.io/name: opensearch-persistent + strategy: + type: Recreate template: metadata: annotations: @@ -128,14 +148,14 @@ spec: labels: app.kubernetes.io/instance: myservice-size app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: opensearch + app.kubernetes.io/name: opensearch-persistent lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-size - lagoon.sh/service-type: opensearch - lagoon.sh/template: opensearch-0.1.0 + lagoon.sh/service-type: opensearch-persistent + lagoon.sh/template: opensearch-persistent-0.1.0 spec: containers: - env: @@ -146,8 +166,26 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice-size@latest + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 9200 name: opensearch - resources: {} + ports: + - containerPort: 9200 + name: 9200-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 9200 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 10Mi volumeMounts: - mountPath: /usr/share/opensearch/data name: myservice-size diff --git a/internal/templating/services/test-resources/deployment/result-postgres-1.yaml b/internal/templating/services/test-resources/deployment/result-postgres-1.yaml index a0314753..c5c9ee65 100644 --- a/internal/templating/services/test-resources/deployment/result-postgres-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-postgres-1.yaml @@ -58,6 +58,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/postgres@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 120 periodSeconds: 5 diff --git a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml index ece1e969..821baa9e 100644 --- a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml @@ -58,6 +58,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 120 periodSeconds: 5 diff --git a/internal/templating/services/test-resources/deployment/result-python-1.yaml b/internal/templating/services/test-resources/deployment/result-python-1.yaml index 04c7674d..ca878909 100644 --- a/internal/templating/services/test-resources/deployment/result-python-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-python-1.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/python@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: @@ -137,6 +138,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/python-persist@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml b/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml index 4529b4b4..df7e7711 100644 --- a/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml @@ -59,6 +59,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/rabbitmq@latest + imagePullPolicy: Always livenessProbe: failureThreshold: 5 initialDelaySeconds: 90 diff --git a/internal/templating/services/test-resources/deployment/result-redis-1.yaml b/internal/templating/services/test-resources/deployment/result-redis-1.yaml index 95232b37..30a7a2e6 100644 --- a/internal/templating/services/test-resources/deployment/result-redis-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-redis-1.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/redis@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 120 tcpSocket: @@ -114,7 +115,7 @@ spec: annotations: k8up.syn.tools/backupcommand: /bin/sh -c "/bin/busybox tar -cf - -C /data ." - k8up.syn.tools/file-extension: . + k8up.syn.tools/file-extension: .redis-persist.tar lagoon.sh/branch: environment-name lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x @@ -140,8 +141,26 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/redis-persist@latest - name: "" - resources: {} + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + tcpSocket: + port: 6379 + timeoutSeconds: 10 + name: redis + ports: + - containerPort: 6379 + name: 6379-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 6379 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M volumeMounts: - mountPath: /data name: redis-persist diff --git a/internal/templating/services/test-resources/deployment/result-solr-1.yaml b/internal/templating/services/test-resources/deployment/result-solr-1.yaml index 457cdc34..4ed8aa59 100644 --- a/internal/templating/services/test-resources/deployment/result-solr-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-solr-1.yaml @@ -56,6 +56,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/solr@latest + imagePullPolicy: Always livenessProbe: failureThreshold: 5 initialDelaySeconds: 90 diff --git a/internal/templating/services/test-resources/deployment/result-varnish-1.yaml b/internal/templating/services/test-resources/deployment/result-varnish-1.yaml index 5cf321e8..6ff72a00 100644 --- a/internal/templating/services/test-resources/deployment/result-varnish-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-varnish-1.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/varnish@latest + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: @@ -117,7 +118,7 @@ spec: annotations: k8up.syn.tools/backupcommand: /bin/sh -c "/bin/busybox tar -cf - -C /var/cache/varnish ." - k8up.syn.tools/file-extension: . + k8up.syn.tools/file-extension: .varnish-persist.tar lagoon.sh/branch: environment-name lagoon.sh/configMapSha: 32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273 lagoon.sh/version: v2.x.x @@ -143,8 +144,29 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/varnish-persist@latest - name: "" - resources: {} + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 8080 + timeoutSeconds: 10 + name: varnish + ports: + - containerPort: 8080 + name: http + protocol: TCP + - containerPort: 6082 + name: controlport + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 8080 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M volumeMounts: - mountPath: /var/cache/varnish name: varnish-persist diff --git a/internal/templating/services/test-resources/deployment/result-worker-1.yaml b/internal/templating/services/test-resources/deployment/result-worker-1.yaml index 7bdaa272..d48efeae 100644 --- a/internal/templating/services/test-resources/deployment/result-worker-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-worker-1.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/worker@latest + imagePullPolicy: Always name: worker readinessProbe: exec: @@ -137,6 +138,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/worker-persist@latest + imagePullPolicy: Always name: worker readinessProbe: exec: diff --git a/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml b/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml index bba20827..18ed3b19 100644 --- a/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml @@ -11,14 +11,14 @@ metadata: labels: app.kubernetes.io/instance: myservice app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: opensearch + app.kubernetes.io/name: opensearch-persistent 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: opensearch - lagoon.sh/template: opensearch-0.1.0 + lagoon.sh/service-type: opensearch-persistent + lagoon.sh/template: opensearch-persistent-0.1.0 name: myservice spec: accessModes: @@ -40,14 +40,14 @@ metadata: labels: app.kubernetes.io/instance: myservice-size app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: opensearch + app.kubernetes.io/name: opensearch-persistent lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-size - lagoon.sh/service-type: opensearch - lagoon.sh/template: opensearch-0.1.0 + lagoon.sh/service-type: opensearch-persistent + lagoon.sh/template: opensearch-persistent-0.1.0 name: myservice-size spec: accessModes: diff --git a/internal/templating/services/test-resources/service/result-opensearch-1.yaml b/internal/templating/services/test-resources/service/result-opensearch-1.yaml index 7f530e35..54221a88 100644 --- a/internal/templating/services/test-resources/service/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/service/result-opensearch-1.yaml @@ -9,14 +9,14 @@ metadata: labels: app.kubernetes.io/instance: myservice app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: opensearch + app.kubernetes.io/name: opensearch-persistent 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: opensearch - lagoon.sh/template: opensearch-0.1.0 + lagoon.sh/service-type: opensearch-persistent + lagoon.sh/template: opensearch-persistent-0.1.0 name: myservice spec: ports: @@ -26,7 +26,7 @@ spec: targetPort: 9200 selector: app.kubernetes.io/instance: myservice - app.kubernetes.io/name: opensearch + app.kubernetes.io/name: opensearch-persistent status: loadBalancer: {} --- @@ -40,14 +40,14 @@ metadata: labels: app.kubernetes.io/instance: myservice-size app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: opensearch + app.kubernetes.io/name: opensearch-persistent lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project lagoon.sh/service: myservice-size - lagoon.sh/service-type: opensearch - lagoon.sh/template: opensearch-0.1.0 + lagoon.sh/service-type: opensearch-persistent + lagoon.sh/template: opensearch-persistent-0.1.0 name: myservice-size spec: ports: @@ -57,6 +57,6 @@ spec: targetPort: 9200 selector: app.kubernetes.io/instance: myservice-size - app.kubernetes.io/name: opensearch + app.kubernetes.io/name: opensearch-persistent status: loadBalancer: {} diff --git a/internal/testdata/basic/service-templates/service1/deployment-node.yaml b/internal/testdata/basic/service-templates/service1/deployment-node.yaml index ac5f3224..3380df93 100644 --- a/internal/testdata/basic/service-templates/service1/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service1/deployment-node.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml index 79a6fa9e..d9fa6b9d 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/lnd@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml index 15c8455a..b5c9c179 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/thunderhub@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/basic/service-templates/service2/deployment-tor.yaml b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml index f05a2939..f7550505 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-tor.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/tor@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml index 79a6fa9e..d9fa6b9d 100644 --- a/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml +++ b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/lnd@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/basic/service-templates/service3/deployment-tor.yaml b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml index d425fd8a..ac21f790 100644 --- a/internal/testdata/basic/service-templates/service3/deployment-tor.yaml +++ b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/tor@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always name: worker readinessProbe: exec: diff --git a/internal/testdata/basic/service-templates/service4/deployment-node.yaml b/internal/testdata/basic/service-templates/service4/deployment-node.yaml index 68e8ad2e..941ee4d1 100644 --- a/internal/testdata/basic/service-templates/service4/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service4/deployment-node.yaml @@ -51,6 +51,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/basic/service-templates/service5/deployment-node.yaml b/internal/testdata/basic/service-templates/service5/deployment-node.yaml index d1e65d6a..d300f037 100644 --- a/internal/testdata/basic/service-templates/service5/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service5/deployment-node.yaml @@ -57,6 +57,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/pr-123/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml index 65d854be..35657621 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml @@ -55,6 +55,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: failureThreshold: 5 httpGet: @@ -89,6 +90,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 periodSeconds: 10 diff --git a/internal/testdata/complex/service-templates/service1/deployment-redis.yaml b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml index 7f2ec91e..3fe947cb 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-redis.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/redis@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 120 tcpSocket: diff --git a/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml index 92ff10cc..c726d705 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/varnish@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: diff --git a/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml index 37facd80..31f4bda3 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml @@ -55,6 +55,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: failureThreshold: 5 httpGet: @@ -89,6 +90,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 periodSeconds: 10 diff --git a/internal/testdata/complex/service-templates/service2/deployment-redis.yaml b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml index 72bd8927..58afe308 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-redis.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/redis@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 120 tcpSocket: diff --git a/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml index 08f1d9df..242ec6b6 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/varnish@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always livenessProbe: initialDelaySeconds: 60 tcpSocket: From 235c42a9c3c7a282a28c68fba303515cc5341384 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 29 Jan 2024 18:11:26 +1100 Subject: [PATCH 58/92] fix: commands for identify, and task runner to use new lagoonyml location --- cmd/identify_imagebuild.go | 13 +++++++++---- cmd/tasks_run.go | 14 +++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cmd/identify_imagebuild.go b/cmd/identify_imagebuild.go index 057b2615..bd1b063d 100644 --- a/cmd/identify_imagebuild.go +++ b/cmd/identify_imagebuild.go @@ -1,6 +1,7 @@ package cmd import ( + "encoding/json" "fmt" "github.com/spf13/cobra" @@ -8,11 +9,11 @@ import ( ) var imageBuildIdentify = &cobra.Command{ - Use: "image-build", - Aliases: []string{"ib"}, + Use: "image-builds", + Aliases: []string{"image-build", "img-build", "ib"}, Short: "Identify the configuration for building images for a Lagoon build", RunE: func(cmd *cobra.Command, args []string) error { - gen, err := generator.GenerateInput(*rootCmd, true) + gen, err := generator.GenerateInput(*rootCmd, false) if err != nil { return err } @@ -20,7 +21,11 @@ var imageBuildIdentify = &cobra.Command{ if err != nil { return err } - fmt.Println(out) + bc, err := json.Marshal(out) + if err != nil { + return err + } + fmt.Println(string(bc)) return nil }, } diff --git a/cmd/tasks_run.go b/cmd/tasks_run.go index 8708db8d..b21023c9 100644 --- a/cmd/tasks_run.go +++ b/cmd/tasks_run.go @@ -57,7 +57,7 @@ var tasksPreRun = &cobra.Command{ if err != nil { return err } - lYAML, lagoonConditionalEvaluationEnvironment, buildValues, err := getEnvironmentInfo(generator) + lagoonConditionalEvaluationEnvironment, buildValues, err := getEnvironmentInfo(generator) if err != nil { return err } @@ -69,7 +69,7 @@ var tasksPreRun = &cobra.Command{ os.Exit(1) } - err = runTasks(taskIterator, lYAML.Tasks.Prerollout, lagoonConditionalEvaluationEnvironment) + err = runTasks(taskIterator, buildValues.LagoonYAML.Tasks.Prerollout, lagoonConditionalEvaluationEnvironment) if err != nil { fmt.Println("Pre-rollout Tasks Failed with the following error: ", err.Error()) os.Exit(1) @@ -88,7 +88,7 @@ var tasksPostRun = &cobra.Command{ if err != nil { return err } - lYAML, lagoonConditionalEvaluationEnvironment, buildValues, err := getEnvironmentInfo(generator) + lagoonConditionalEvaluationEnvironment, buildValues, err := getEnvironmentInfo(generator) if err != nil { return err } @@ -100,7 +100,7 @@ var tasksPostRun = &cobra.Command{ fmt.Println("Pre-rollout Tasks Failed with the following error: ", err.Error()) os.Exit(1) } - err = runTasks(taskIterator, lYAML.Tasks.Postrollout, lagoonConditionalEvaluationEnvironment) + err = runTasks(taskIterator, buildValues.LagoonYAML.Tasks.Postrollout, lagoonConditionalEvaluationEnvironment) if err != nil { fmt.Println("Post-rollout Tasks Failed with the following error: ", err.Error()) os.Exit(1) @@ -110,13 +110,13 @@ var tasksPostRun = &cobra.Command{ }, } -func getEnvironmentInfo(g generator.GeneratorInput) (lagoon.YAML, tasklib.TaskEnvironment, generator.BuildValues, error) { +func getEnvironmentInfo(g generator.GeneratorInput) (tasklib.TaskEnvironment, generator.BuildValues, error) { // read the .lagoon.yml file lagoonBuild, err := generator.NewGenerator( g, ) if err != nil { - return lagoon.YAML{}, nil, generator.BuildValues{}, err + return nil, generator.BuildValues{}, err } lagoonConditionalEvaluationEnvironment := tasklib.TaskEnvironment{} @@ -125,7 +125,7 @@ func getEnvironmentInfo(g generator.GeneratorInput) (lagoon.YAML, tasklib.TaskEn lagoonConditionalEvaluationEnvironment[envVar.Name] = envVar.Value } } - return *lagoonBuild.LagoonYAML, lagoonConditionalEvaluationEnvironment, *lagoonBuild.BuildValues, nil + return lagoonConditionalEvaluationEnvironment, *lagoonBuild.BuildValues, nil } // runTasks is essentially an interpreter. It takes in a runner function (that does the interpreting), the task list (a series of instructions) From dc08f472472d26d330c46a690f2592be52c03509 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 29 Jan 2024 18:11:54 +1100 Subject: [PATCH 59/92] fix: jq defaults for new image builds --- legacy/build-deploy-docker-compose.sh | 28 ++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 8e35109d..ca094e70 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -2,7 +2,7 @@ # get the buildname from the pod, $HOSTNAME contains this in the running pod, so we can use this # set it to something usable here -LAGOON_BUILD_NAME=$HOSTNAME +export LAGOON_BUILD_NAME=$HOSTNAME BUILD_WARNING_COUNT=0 @@ -685,9 +685,10 @@ set -x # seed all the push images for use later on, push images relate to images that may not be built by this build # but are required from somewhere else like a promote environment or from another registry -ENVIRONMENT_IMAGE_BUILD_DATA=$(build-deploy-tool identify image-builds | jq -r) -for IMAGE_BUILD_DATA in $(echo $ENVIRONMENT_IMAGE_BUILD_DATA | jq -r '.images[]') +ENVIRONMENT_IMAGE_BUILD_DATA=$(build-deploy-tool identify image-builds) +for IMAGE_BUILD_DATA in $(echo "$ENVIRONMENT_IMAGE_BUILD_DATA" | jq -c '.images[]') do + SERVICE_NAME=$(echo "$IMAGE_BUILD_DATA" | jq -r '.name // false') # add the image name to the array of images to push. this is consumed later in the build process IMAGES_PUSH["${SERVICE_NAME}"]="$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.buildImage')" if [ "$BUILD_TYPE" == "promote" ]; then @@ -702,17 +703,19 @@ if [[ "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ]]; then BUILD_ARGS=() # build args are now calculated in the build-deploy tool in the generator step # this loop extracts the build arguments from the response from the build deploy tools previous identify image-builds call for IMAGE_BUILD_ARGUMENTS in $(echo "$ENVIRONMENT_IMAGE_BUILD_DATA" | jq -r '.buildArguments | to_entries[] | @base64'); do - BUILD_ARGS+=('--build-arg '$(echo "$IMAGE_BUILD_ARGUMENTS" | jq -Rr '@base64d | fromjson | .key')'="'$(echo "$IMAGE_BUILD_ARGUMENTS" | jq -Rr '@base64d | fromjson | .value')'"') + BUILD_ARG_NAME=$(echo "$IMAGE_BUILD_ARGUMENTS" | jq -Rr '@base64d | fromjson | .key') + BUILD_ARG_VALUE=$(echo "$IMAGE_BUILD_ARGUMENTS" | jq -Rr '@base64d | fromjson | .value') + BUILD_ARGS+=(--build-arg ${BUILD_ARG_NAME}="${BUILD_ARG_VALUE}") done # now we loop through the images in the build data and determine if they need to be pulled or build - for IMAGE_BUILD_DATA in $(echo $ENVIRONMENT_IMAGE_BUILD_DATA | jq -r '.images[]') + for IMAGE_BUILD_DATA in $(echo "$ENVIRONMENT_IMAGE_BUILD_DATA" | jq -c '.images[]') do - SERVICE_NAME=$(echo "$IMAGE_BUILD_DATA" | jq -r '.name' // false) - DOCKERFILE=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.dockerFile' // false) + SERVICE_NAME=$(echo "$IMAGE_BUILD_DATA" | jq -r '.name // false') + DOCKERFILE=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.dockerFile // false') # if there is no dockerfile, then this image needs to be pulled from somewhere else if [ $DOCKERFILE == "false" ]; then - PULL_IMAGE=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.pullImage' // false) + PULL_IMAGE=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.pullImage // false') if [ "$PULL_IMAGE" != "false" ]; then IMAGES_PULL["${SERVICE_NAME}"]="${PULL_IMAGE}" fi @@ -721,19 +724,18 @@ if [[ "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ]]; then # this is a temporary image name to use for the build, it is based on the namespace and service, this can probably be deprecated and the images could just be # built with the name they are meant to be. only 1 build can run at a time within a namespace # the temporary name would clash here as well if there were multiple builds (it could use the `imageBuild.buildImage` value) - TEMPORARY_IMAGE_NAME=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.temporaryImage' // false) + TEMPORARY_IMAGE_NAME=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.temporaryImage // false') # the context for this image build, the original source for this value is from the `docker-compose file` - BUILD_CONTEXT=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.context' // "") + BUILD_CONTEXT=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.context // ""') # the build target for this image build, the original source for this value is from the `docker-compose file` - BUILD_TARGET=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.target' // false) + BUILD_TARGET=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.target // false') set +x # reduce noise in build logs # determine if buildkit should be used for this build DOCKER_BUILDKIT=0 - if [ "$(echo ${ENVIRONMENT_IMAGE_BUILD_DATA} | jq -r '.buildKit' // false)" == "true" ]; then + if [ "$(echo "${ENVIRONMENT_IMAGE_BUILD_DATA}" | jq -r '.buildKit // false')" == "true" ]; then DOCKER_BUILDKIT=1 echo "Using BuildKit for $DOCKERFILE"; fi - done # now do the actual image build if [ $BUILD_TARGET == "false" ]; then From eff8f5779f79ae4106d1ed3936a387efc9ef94cc Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 1 Feb 2024 09:42:38 +1100 Subject: [PATCH 60/92] fix: postgres backup variable names for user,pass, and db --- internal/servicetypes/postgres.go | 5 +++-- internal/servicetypes/types.go | 1 + internal/templating/services/templates_deployment.go | 3 +++ .../test-resources/deployment/result-postgres-1.yaml | 2 +- .../test-resources/deployment/result-postgres-single-1.yaml | 6 +++--- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/servicetypes/postgres.go b/internal/servicetypes/postgres.go index 743f0a80..4afa7112 100644 --- a/internal/servicetypes/postgres.go +++ b/internal/servicetypes/postgres.go @@ -12,7 +12,8 @@ import ( var defaultPostgresPort int32 = 5432 var postgresSingle = ServiceType{ - Name: "postgres-single", + Name: "postgres-single", + EnableServiceLinks: true, Ports: ServicePorts{ Ports: []corev1.ServicePort{ { @@ -81,7 +82,7 @@ var postgresSingle = ServiceType{ PersistentVolumeType: corev1.ReadWriteOnce, PersistentVolumePath: "/var/lib/postgresql/data", BackupConfiguration: BackupConfiguration{ - Command: `/bin/sh -c "PGPASSWORD=${{ .ServiceValues.OverrideName | FixServiceName }}_PASSWORD pg_dump --host=localhost --port=${{ .ServiceValues.OverrideName | FixServiceName }}_SERVICE_PORT --dbname=${{ .ServiceValues.OverrideName | FixServiceName }}_DB --username=${{ .ServiceValues.OverrideName | FixServiceName }}_USER --format=t -w"`, + Command: `/bin/sh -c "PGPASSWORD=$POSTGRES_PASSWORD pg_dump --host=localhost --port=${{ .ServiceValues.OverrideName | FixServiceName }}_SERVICE_PORT --dbname=$POSTGRES_DB --username=$POSTGRES_USER --format=t -w"`, FileExtension: ".{{ .ServiceValues.OverrideName }}.tar", }, }, diff --git a/internal/servicetypes/types.go b/internal/servicetypes/types.go index 57d55745..935983b8 100644 --- a/internal/servicetypes/types.go +++ b/internal/servicetypes/types.go @@ -14,6 +14,7 @@ type ServiceType struct { InitContainer ServiceContainer SecondaryContainer ServiceContainer PodSecurityContext ServicePodSecurityContext + EnableServiceLinks bool } type ServicePodSecurityContext struct { diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index b4997b1e..e671b70f 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -187,6 +187,9 @@ func GenerateDeploymentTemplate( // disable service links, this prevents some environment variables that confuse lagoon services being // added to the containers deployment.Spec.Template.Spec.EnableServiceLinks = helpers.BoolPtr(false) + if serviceTypeValues.EnableServiceLinks { + deployment.Spec.Template.Spec.EnableServiceLinks = helpers.BoolPtr(true) + } // set the priority class deployment.Spec.Template.Spec.PriorityClassName = fmt.Sprintf("lagoon-priority-%s", buildValues.EnvironmentType) diff --git a/internal/templating/services/test-resources/deployment/result-postgres-1.yaml b/internal/templating/services/test-resources/deployment/result-postgres-1.yaml index c5c9ee65..17e1362c 100644 --- a/internal/templating/services/test-resources/deployment/result-postgres-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-postgres-1.yaml @@ -81,7 +81,7 @@ spec: volumeMounts: - mountPath: /var/lib/postgresql/data name: postgres - enableServiceLinks: false + enableServiceLinks: true imagePullSecrets: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production diff --git a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml index 821baa9e..0dbb9d70 100644 --- a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml @@ -29,8 +29,8 @@ spec: template: metadata: annotations: - k8up.syn.tools/backupcommand: /bin/sh -c "PGPASSWORD=$MYSERVICE_PASSWORD pg_dump - --host=localhost --port=$MYSERVICE_SERVICE_PORT --dbname=$MYSERVICE_DB --username=$MYSERVICE_USER + k8up.syn.tools/backupcommand: /bin/sh -c "PGPASSWORD=$POSTGRES_PASSWORD pg_dump + --host=localhost --port=$MYSERVICE_SERVICE_PORT --dbname=$POSTGRES_DB --username=$POSTGRES_USER --format=t -w" k8up.syn.tools/file-extension: .myservice.tar lagoon.sh/branch: environment-name @@ -81,7 +81,7 @@ spec: volumeMounts: - mountPath: /var/lib/postgresql/data name: myservice - enableServiceLinks: false + enableServiceLinks: true imagePullSecrets: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production From 78e97fe508a4acb63ccf9a9bf04a5eda1b416392 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 12 Feb 2024 13:06:32 +1100 Subject: [PATCH 61/92] chore: remove unused backup-generation script --- legacy/scripts/exec-backup-generation.sh | 336 ----------------------- 1 file changed, 336 deletions(-) delete mode 100755 legacy/scripts/exec-backup-generation.sh diff --git a/legacy/scripts/exec-backup-generation.sh b/legacy/scripts/exec-backup-generation.sh deleted file mode 100755 index df4dc63c..00000000 --- a/legacy/scripts/exec-backup-generation.sh +++ /dev/null @@ -1,336 +0,0 @@ -#!/bin/bash - -############################################## -# it is possible to override the retention using a variable defined in the api -# -# if you want to use a different retention period for production branches, you can use the following -# LAGOON_BACKUP_PROD_RETENTION="H:D:W:M" - -# if you want to use a different retention period for development branches, you can use the following -# LAGOON_BACKUP_DEV_RETENTION="H:D:W:M" -# -# if you want to use a different retention period for pullrequest environments, you can use the following -# LAGOON_BACKUP_PR_RETENTION="H:D:W:M" -# -# Where the value H:D:W:M (hourly:daily:weekly:monthly) is numbers representing the retention period -# eg: 0:7:6:1 -# 0 Hourly -# 7 Daily -# 6 Weekly -# 1 Montly -# -############################################## - -# Implement global default value for backup retentions -if [ -z "$MONTHLY_BACKUP_DEFAULT_RETENTION" ] -then - MONTHLY_BACKUP_DEFAULT_RETENTION=1 -fi -if [ -z "$WEEKLY_BACKUP_DEFAULT_RETENTION" ] -then - WEEKLY_BACKUP_DEFAULT_RETENTION=6 -fi -if [ -z "$DAILY_BACKUP_DEFAULT_RETENTION" ] -then - DAILY_BACKUP_DEFAULT_RETENTION=7 -fi -if [ -z "$HOURLY_BACKUP_DEFAULT_RETENTION" ] -then - HOURLY_BACKUP_DEFAULT_RETENTION=0 -fi - -############################################## -# it is possible to override the schedule using a variable defined in the api -# -# if you want to use a different schedule period for development branches, you can use the following -# LAGOON_BACKUP_DEV_SCHEDULE="M H(22-2) * * *" -# -# if you want to use a different retention period for pullrequest environments, you can use the following -# LAGOON_BACKUP_PR_SCHEDULE="M H(22-2) * * *" -# -# Where the value is a supported cronjob pattern for k8up -############################################## - - -############################################## -### Backup Settings -############################################## - -# If k8up is supported by this cluster we create the schedule definition -if [[ "${CAPABILITIES[@]}" =~ "backup.appuio.ch/v1alpha1/Schedule" ]]; then - - # Parse out custom baas backup location variables - if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then - BAAS_CUSTOM_BACKUP_ENDPOINT=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_BAAS_CUSTOM_BACKUP_ENDPOINT") | "\(.value)"')) - BAAS_CUSTOM_BACKUP_BUCKET=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_BAAS_CUSTOM_BACKUP_BUCKET") | "\(.value)"')) - BAAS_CUSTOM_BACKUP_ACCESS_KEY=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_BAAS_CUSTOM_BACKUP_ACCESS_KEY") | "\(.value)"')) - BAAS_CUSTOM_BACKUP_SECRET_KEY=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_BAAS_CUSTOM_BACKUP_SECRET_KEY") | "\(.value)"')) - - if [ ! -z $BAAS_CUSTOM_BACKUP_ENDPOINT ] && [ ! -z $BAAS_CUSTOM_BACKUP_BUCKET ] && [ ! -z $BAAS_CUSTOM_BACKUP_ACCESS_KEY ] && [ ! -z $BAAS_CUSTOM_BACKUP_SECRET_KEY ]; then - CUSTOM_BAAS_BACKUP_ENABLED=1 - - HELM_CUSTOM_BAAS_BACKUP_ACCESS_KEY=${BAAS_CUSTOM_BACKUP_ACCESS_KEY} - HELM_CUSTOM_BAAS_BACKUP_SECRET_KEY=${BAAS_CUSTOM_BACKUP_SECRET_KEY} - else - kubectl --insecure-skip-tls-verify -n ${NAMESPACE} delete secret baas-custom-backup-credentials --ignore-not-found - fi - fi - - # Parse out custom baas restore location variables - if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then - BAAS_CUSTOM_RESTORE_ENDPOINT=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_BAAS_CUSTOM_RESTORE_ENDPOINT") | "\(.value)"')) - BAAS_CUSTOM_RESTORE_BUCKET=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_BAAS_CUSTOM_RESTORE_BUCKET") | "\(.value)"')) - BAAS_CUSTOM_RESTORE_ACCESS_KEY=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_BAAS_CUSTOM_RESTORE_ACCESS_KEY") | "\(.value)"')) - BAAS_CUSTOM_RESTORE_SECRET_KEY=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_BAAS_CUSTOM_RESTORE_SECRET_KEY") | "\(.value)"')) - - if [ ! -z $BAAS_CUSTOM_RESTORE_ENDPOINT ] && [ ! -z $BAAS_CUSTOM_RESTORE_BUCKET ] && [ ! -z $BAAS_CUSTOM_RESTORE_ACCESS_KEY ] && [ ! -z $BAAS_CUSTOM_RESTORE_SECRET_KEY ]; then - HELM_CUSTOM_BAAS_RESTORE_ACCESS_KEY=${BAAS_CUSTOM_RESTORE_ACCESS_KEY} - HELM_CUSTOM_BAAS_RESTORE_SECRET_KEY=${BAAS_CUSTOM_RESTORE_SECRET_KEY} - else - kubectl --insecure-skip-tls-verify -n ${NAMESPACE} delete secret baas-custom-restore-credentials --ignore-not-found - fi - fi - - if ! kubectl --insecure-skip-tls-verify -n ${NAMESPACE} get secret baas-repo-pw &> /dev/null; then - # Create baas-repo-pw secret based on the project secret - kubectl --insecure-skip-tls-verify -n ${NAMESPACE} create secret generic baas-repo-pw --from-literal=repo-pw=$(echo -n "$PROJECT_SECRET-BAAS-REPO-PW" | sha256sum | cut -d " " -f 1) - fi - - TEMPLATE_PARAMETERS=() - - # Check for custom baas bucket name - if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then - BAAS_BUCKET_NAME=$(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_BAAS_BUCKET_NAME") | "\(.value)"') - fi - if [ -z $BAAS_BUCKET_NAME ]; then - # check for shared/cluster scoped bucket - # use build scope for now for testing - SHARED_BUCKET_NAME=$(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "internal_system" and .name == "LAGOON_SYSTEM_PROJECT_SHARED_BUCKET") | "\(.value)"') - if [ -z $SHARED_BUCKET_NAME ]; then - # if no shared bucketname, create as normal - BAAS_BUCKET_NAME=baas-${PROJECT} - else - # if shared, create using shared bucketname - BAAS_BUCKET_NAME=${SHARED_BUCKET_NAME}/baas-${PROJECT} - fi - fi - - # Pull in .lagoon.yml variables - PRODUCTION_MONTHLY_BACKUP_RETENTION=$(cat .lagoon.yml | shyaml get-value backup-retention.production.monthly "") - PRODUCTION_WEEKLY_BACKUP_RETENTION=$(cat .lagoon.yml | shyaml get-value backup-retention.production.weekly "") - PRODUCTION_DAILY_BACKUP_RETENTION=$(cat .lagoon.yml | shyaml get-value backup-retention.production.daily "") - PRODUCTION_HOURLY_BACKUP_RETENTION=$(cat .lagoon.yml | shyaml get-value backup-retention.production.hourly "") - - # Set template parameters for retention values (prefer .lagoon.yml values over supplied defaults after ensuring they are valid integers via "-eq" comparison) - if [[ ! -z $PRODUCTION_MONTHLY_BACKUP_RETENTION ]] && [[ "$PRODUCTION_MONTHLY_BACKUP_RETENTION" -eq "$PRODUCTION_MONTHLY_BACKUP_RETENTION" ]] && [[ $ENVIRONMENT_TYPE = 'production' ]]; then - MONTHLY_BACKUP_DEFAULT_RETENTION=${PRODUCTION_MONTHLY_BACKUP_RETENTION} - else - MONTHLY_BACKUP_RETENTION=${MONTHLY_BACKUP_DEFAULT_RETENTION} - fi - if [[ ! -z $PRODUCTION_WEEKLY_BACKUP_RETENTION ]] && [[ "$PRODUCTION_WEEKLY_BACKUP_RETENTION" -eq "$PRODUCTION_WEEKLY_BACKUP_RETENTION" ]] && [[ $ENVIRONMENT_TYPE = 'production' ]]; then - WEEKLY_BACKUP_DEFAULT_RETENTION=${PRODUCTION_WEEKLY_BACKUP_RETENTION} - else - WEEKLY_BACKUP_RETENTION=${WEEKLY_BACKUP_DEFAULT_RETENTION} - fi - if [[ ! -z $PRODUCTION_DAILY_BACKUP_RETENTION ]] && [[ "$PRODUCTION_DAILY_BACKUP_RETENTION" -eq "$PRODUCTION_DAILY_BACKUP_RETENTION" ]] && [[ $ENVIRONMENT_TYPE = 'production' ]]; then - DAILY_BACKUP_DEFAULT_RETENTION=${PRODUCTION_DAILY_BACKUP_RETENTION} - else - DAILY_BACKUP_RETENTION=${DAILY_BACKUP_DEFAULT_RETENTION} - fi - if [[ ! -z $PRODUCTION_HOURLY_BACKUP_RETENTION ]] && [[ "$PRODUCTION_HOURLY_BACKUP_RETENTION" -eq "$PRODUCTION_HOURLY_BACKUP_RETENTION" ]] && [[ $ENVIRONMENT_TYPE = 'production' ]]; then - HOURLY_BACKUP_DEFAULT_RETENTION=${PRODUCTION_HOURLY_BACKUP_RETENTION} - else - HOURLY_BACKUP_RETENTION=${HOURLY_BACKUP_DEFAULT_RETENTION} - fi - - ############################################## - # check if the feature for custom backup configuration is enabled LAGOON_FEATURE_FLAG(_FORCE|_DEFAULT)_CUSTOM_BACKUP_CONFIG=enabled - # this feature is experimental and may cause issues with your backups if incorrectly used, talk to your lagoon administrators before you use this - # _ - # __| | __ _ _ __ __ _ ___ _ __ - # / _` |/ _` | '_ \ / _` |/ _ \ '__| - # | (_| | (_| | | | | (_| | __/ | - # \__,_|\__,_|_| |_|\__, |\___|_| - # |___/ - ############################################## - - if [ "$(featureFlag CUSTOM_BACKUP_CONFIG)" = enabled ]; then - # check if a specific override has been defined in the api - case "$BUILD_TYPE" in - promote) - if [ "${ENVIRONMENT_TYPE}" == "production" ]; then - # check if the API defined variable LAGOON_BACKUP_PROD_RETENTION contains what is needed - # if one in the API is not defined, fall back to what could be injected by the controller LAGOON_BACKUP_PROD_RETENTION - BACKUP_RETENTION=$(projectEnvironmentVariableCheck LAGOON_BACKUP_PROD_RETENTION "${LAGOON_FEATURE_BACKUP_PROD_RETENTION}") - if [ ! -z "$BACKUP_RETENTION" ]; then - IFS=':' read -ra BACKUP_RETENTION_SPLIT <<< "$BACKUP_RETENTION" - HOURLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[0]} - DAILY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[1]} - WEEKLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[2]} - MONTHLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[3]} - fi - fi - ;; - branch) - if [ "${ENVIRONMENT_TYPE}" == "production" ]; then - # check if the API defined variable LAGOON_BACKUP_PROD_RETENTION contains what is needed - # if one in the API is not defined, fall back to what could be injected by the controller LAGOON_BACKUP_PROD_RETENTION - BACKUP_RETENTION=$(projectEnvironmentVariableCheck LAGOON_BACKUP_PROD_RETENTION "${LAGOON_FEATURE_BACKUP_PROD_RETENTION}") - if [ ! -z "$BACKUP_RETENTION" ]; then - IFS=':' read -ra BACKUP_RETENTION_SPLIT <<< "$BACKUP_RETENTION" - HOURLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[0]} - DAILY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[1]} - WEEKLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[2]} - MONTHLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[3]} - fi - fi - if [ "${ENVIRONMENT_TYPE}" == "development" ]; then - # check if the API defined variable LAGOON_BACKUP_DEV_RETENTION contains what is needed - # if one in the API is not defined, fall back to what could be injected by the controller LAGOON_FEATURE_BACKUP_DEV_RETENTION - BACKUP_RETENTION=$(projectEnvironmentVariableCheck LAGOON_BACKUP_DEV_RETENTION "${LAGOON_FEATURE_BACKUP_DEV_RETENTION}") - if [ ! -z "$BACKUP_RETENTION" ]; then - IFS=':' read -ra BACKUP_RETENTION_SPLIT <<< "$BACKUP_RETENTION" - HOURLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[0]} - DAILY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[1]} - WEEKLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[2]} - MONTHLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[3]} - fi - fi - ;; - pullrequest) - # check if the API defined variable LAGOON_BACKUP_PR_RETENTION contains what is needed - # if one in the API is not defined, fall back to what could be injected by the controller LAGOON_FEATURE_BACKUP_PR_RETENTION - BACKUP_RETENTION=$(projectEnvironmentVariableCheck LAGOON_BACKUP_PR_RETENTION "${LAGOON_FEATURE_BACKUP_PR_RETENTION}") - if [ ! -z "$BACKUP_RETENTION" ]; then - IFS=':' read -ra BACKUP_RETENTION_SPLIT <<< "$BACKUP_RETENTION" - HOURLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[0]} - DAILY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[1]} - WEEKLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[2]} - MONTHLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[3]} - fi - if [ -z "$BACKUP_RETENTION" ];then - ## fall back to dev retention if no pr retention is defined - # check if the API defined variable LAGOON_BACKUP_DEV_RETENTION contains what is needed - # if one in the API is not defined, fall back to what could be injected by the controller LAGOON_FEATURE_BACKUP_DEV_RETENTION - BACKUP_RETENTION=$(projectEnvironmentVariableCheck LAGOON_BACKUP_DEV_RETENTION "${LAGOON_FEATURE_BACKUP_DEV_RETENTION}") - if [ ! -z "$BACKUP_RETENTION" ]; then - IFS=':' read -ra BACKUP_RETENTION_SPLIT <<< "$BACKUP_RETENTION" - HOURLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[0]} - DAILY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[1]} - WEEKLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[2]} - MONTHLY_BACKUP_DEFAULT_RETENTION=${BACKUP_RETENTION_SPLIT[3]} - fi - fi - ;; - *) - echo "${BUILD_TYPE} not implemented"; exit 1; - esac - fi - - MONTHLY_BACKUP_RETENTION=${MONTHLY_BACKUP_DEFAULT_RETENTION} - WEEKLY_BACKUP_RETENTION=${WEEKLY_BACKUP_DEFAULT_RETENTION} - DAILY_BACKUP_RETENTION=${DAILY_BACKUP_DEFAULT_RETENTION} - HOURLY_BACKUP_RETENTION=${HOURLY_BACKUP_DEFAULT_RETENTION} - - # Set template parameters for backup schedule value (prefer .lagoon.yml values over supplied defaults after ensuring they are valid) - PRODUCTION_BACKUP_SCHEDULE=$(cat .lagoon.yml | shyaml get-value backup-schedule.production "") - - if [[ ! -z $PRODUCTION_BACKUP_SCHEDULE ]] && [[ $ENVIRONMENT_TYPE = 'production' ]]; then - if [[ "$PRODUCTION_BACKUP_SCHEDULE" =~ ^M\ ]]; then - DEFAULT_BACKUP_SCHEDULE=${PRODUCTION_BACKUP_SCHEDULE} - else - echo "Error parsing custom backup schedule: '$PRODUCTION_BACKUP_SCHEDULE'"; exit 1 - fi - fi - - if [ "$(featureFlag CUSTOM_BACKUP_CONFIG)" = enabled ]; then - # check if a specific override has been defined in the api - case "$BUILD_TYPE" in - promote) - if [ "${ENVIRONMENT_TYPE}" == "production" ]; then - # check if the API defined variable LAGOON_BACKUP_PROD_SCHEDULE contains what is needed - # if one in the API is not defined, fall back to what could be injected by the controller LAGOON_FEATURE_BACKUP_DEV_SCHEDULE - DEFAULT_BACKUP_SCHEDULE=$(projectEnvironmentVariableCheck LAGOON_BACKUP_PROD_SCHEDULE "${LAGOON_FEATURE_BACKUP_PROD_SCHEDULE}") - fi - ;; - branch) - if [ "${ENVIRONMENT_TYPE}" == "production" ]; then - # check if the API defined variable LAGOON_BACKUP_PROD_SCHEDULE contains what is needed - # if one in the API is not defined, fall back to what could be injected by the controller LAGOON_FEATURE_BACKUP_DEV_SCHEDULE - DEFAULT_BACKUP_SCHEDULE=$(projectEnvironmentVariableCheck LAGOON_BACKUP_PROD_SCHEDULE "${LAGOON_FEATURE_BACKUP_PROD_SCHEDULE}") - fi - if [ "${ENVIRONMENT_TYPE}" == "development" ]; then - # check if the API defined variable LAGOON_BACKUP_DEV_SCHEDULE contains what is needed - # if one in the API is not defined, fall back to what could be injected by the controller LAGOON_FEATURE_BACKUP_DEV_SCHEDULE - DEFAULT_BACKUP_SCHEDULE=$(projectEnvironmentVariableCheck LAGOON_BACKUP_DEV_SCHEDULE "${LAGOON_FEATURE_BACKUP_DEV_SCHEDULE}") - fi - ;; - pullrequest) - # check if the API defined variable LAGOON_BACKUP_PR_SCHEDULE contains what is needed - # if one in the API is not defined, fall back to what could be injected by the controller LAGOON_FEATURE_BACKUP_PR_SCHEDULE - DEFAULT_BACKUP_SCHEDULE=$(projectEnvironmentVariableCheck LAGOON_BACKUP_PR_SCHEDULE "${LAGOON_FEATURE_BACKUP_PR_SCHEDULE}") - if [ -z "$DEFAULT_BACKUP_SCHEDULE" ];then - ## fall back to dev schedule if no pr schedule is defined - # check if the API defined variable LAGOON_BACKUP_DEV_SCHEDULE contains what is needed - # if one in the API is not defined, fall back to what could be injected by the controller LAGOON_FEATURE_BACKUP_DEV_SCHEDULE - DEFAULT_BACKUP_SCHEDULE=$(projectEnvironmentVariableCheck LAGOON_BACKUP_DEV_SCHEDULE "${LAGOON_FEATURE_BACKUP_DEV_SCHEDULE}") - fi - ;; - *) - echo "${BUILD_TYPE} not implemented"; exit 1; - esac - fi - - # Implement global default value for backup schedule - if [ -z "$DEFAULT_BACKUP_SCHEDULE" ] - then - DEFAULT_BACKUP_SCHEDULE="M H(22-2) * * *" - fi - - BACKUP_SCHEDULE=$( /kubectl-build-deploy/scripts/convert-crontab.sh "${NAMESPACE}" "${DEFAULT_BACKUP_SCHEDULE}") - - if [ ! -z $K8UP_WEEKLY_RANDOM_FEATURE_FLAG ] && [ $K8UP_WEEKLY_RANDOM_FEATURE_FLAG = 'enabled' ]; then - # Let the controller deduplicate checks (will run weekly at a random time throughout the week) - CHECK_SCHEDULE="@weekly-random" - else - # Run Checks on Sunday at 0300-0600 - CHECK_SCHEDULE=$( /kubectl-build-deploy/scripts/convert-crontab.sh "${NAMESPACE}" "M H(3-6) * * 0") - fi - - if [ ! -z $K8UP_WEEKLY_RANDOM_FEATURE_FLAG ] && [ $K8UP_WEEKLY_RANDOM_FEATURE_FLAG = 'enabled' ]; then - # Let the controller deduplicate prunes (will run weekly at a random time throughout the week) - PRUNE_SCHEDULE="@weekly-random" - else - # Run Prune on Saturday at 0300-0600 - PRUNE_SCHEDULE=$( /kubectl-build-deploy/scripts/convert-crontab.sh "${NAMESPACE}" "M H(3-6) * * 6") - fi - - # Set the S3 variables which should be passed to the helm chart - if [ ! -z $CUSTOM_BAAS_BACKUP_ENABLED ]; then - BAAS_BACKUP_ENDPOINT=${BAAS_CUSTOM_BACKUP_ENDPOINT} - BAAS_BACKUP_BUCKET=${BAAS_CUSTOM_BACKUP_BUCKET} - BAAS_BACKUP_SECRET_NAME='lagoon-baas-custom-backup-credentials' - else - BAAS_BACKUP_ENDPOINT='' - BAAS_BACKUP_BUCKET=${BAAS_BUCKET_NAME} - BAAS_BACKUP_SECRET_NAME='' - fi - - OPENSHIFT_TEMPLATE="/kubectl-build-deploy/openshift-templates/backup-schedule.yml" - helm template k8up-lagoon-backup-schedule /kubectl-build-deploy/helmcharts/k8up-schedule \ - -f /kubectl-build-deploy/values.yaml \ - --set backup.schedule="${BACKUP_SCHEDULE}" \ - --set check.schedule="${CHECK_SCHEDULE}" \ - --set prune.schedule="${PRUNE_SCHEDULE}" \ - --set prune.retention.keepMonthly=${MONTHLY_BACKUP_RETENTION} \ - --set prune.retention.keepWeekly=${WEEKLY_BACKUP_RETENTION} \ - --set prune.retention.keepDaily=${DAILY_BACKUP_RETENTION} \ - --set prune.retention.keepHourly=${HOURLY_BACKUP_RETENTION} \ - --set s3.endpoint="${BAAS_BACKUP_ENDPOINT}" \ - --set s3.bucket="${BAAS_BACKUP_BUCKET}" \ - --set s3.secretName="${BAAS_BACKUP_SECRET_NAME}" \ - --set customRestoreLocation.accessKey="${BAAS_CUSTOM_RESTORE_ACCESS_KEY}" \ - --set customRestoreLocation.secretKey="${BAAS_CUSTOM_RESTORE_SECRET_KEY}" \ - --set customBackupLocation.accessKey="${BAAS_CUSTOM_BACKUP_ACCESS_KEY}" \ - --set customBackupLocation.secretKey="${BAAS_CUSTOM_BACKUP_SECRET_KEY}" "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/k8up-lagoon-backup-schedule.yaml -fi From 48280ca3ab313daad53d808438aec0ece403a140 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 12 Feb 2024 13:07:08 +1100 Subject: [PATCH 62/92] refactor: handle dynamic secret generation in generator --- cmd/template_lagoonservices_test.go | 22 +++++ internal/generator/generator.go | 20 ++++ .../service6/deployment-node.yaml | 96 +++++++++++++++++++ .../service6/service-node.yaml | 39 ++++++++ internal/testdata/testdata.go | 9 ++ legacy/build-deploy-docker-compose.sh | 3 + legacy/scripts/exec-dynamic-secret-volumes.sh | 42 -------- 7 files changed, 189 insertions(+), 42 deletions(-) create mode 100644 internal/testdata/basic/service-templates/service6/deployment-node.yaml create mode 100644 internal/testdata/basic/service-templates/service6/service-node.yaml delete mode 100755 legacy/scripts/exec-dynamic-secret-volumes.sh diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index afbaa948..181d8200 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -183,6 +183,28 @@ func TestTemplateLagoonServices(t *testing.T) { templatePath: "testoutput", want: "internal/testdata/basic/service-templates/service5", }, + { + name: "test7 basic deployment with dynamic secrets", + vars: []helpers.EnvironmentVariable{ + { + Name: "EXTERNAL_REGISTRY_SECRETS", + Value: "lagoon-private-registry-custom-secret", + }, + }, + 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", + }, + DynamicSecrets: []string{"insights-token"}, + }, true), + templatePath: "testoutput", + want: "internal/testdata/basic/service-templates/service6", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/generator/generator.go b/internal/generator/generator.go index d3226b6c..fe137097 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -69,6 +69,7 @@ type GeneratorInput struct { Kubernetes string CI bool PrivateRegistryURLS []string + DynamicSecrets []string } func NewGenerator( @@ -111,6 +112,7 @@ func NewGenerator( gitSHA := helpers.GetEnv("LAGOON_GIT_SHA", generator.SourceRepository, generator.Debug) prHeadSHA := helpers.GetEnv("PR_HEAD_SHA", generator.PRHeadSHA, generator.Debug) prBaseSHA := helpers.GetEnv("PR_BASE_SHA", generator.PRBaseSHA, generator.Debug) + dynamicSecrets := helpers.GetEnv("DYNAMIC_SECRETS", strings.Join(generator.DynamicSecrets, ","), generator.Debug) // get any external registry urls that this build has so we can update any pullthrough images accordingly gExternalRegistryURLS := "" if generator.PrivateRegistryURLS != nil { @@ -259,6 +261,24 @@ func NewGenerator( } } + // handle the dynamic secret volume creation from input secret names + if dynamicSecrets != "" { + for _, ds := range strings.Split(dynamicSecrets, ",") { + buildValues.DynamicSecretMounts = append(buildValues.DynamicSecretMounts, DynamicSecretMounts{ + Name: fmt.Sprintf("dynamic-%s", ds), + MountPath: fmt.Sprintf("/var/run/secrets/lagoon/dynamic/%s", ds), + ReadOnly: true, + }) + buildValues.DynamicSecretVolumes = append(buildValues.DynamicSecretVolumes, DynamicSecretVolumes{ + Name: fmt.Sprintf("dynamic-%s", ds), + Secret: DynamicSecret{ + SecretName: ds, + Optional: false, + }, + }) + } + } + // unmarshal and then merge the two so there is only 1 set of variables to iterate over projectVars := []lagoon.EnvironmentVariable{} envVars := []lagoon.EnvironmentVariable{} diff --git a/internal/testdata/basic/service-templates/service6/deployment-node.yaml b/internal/testdata/basic/service-templates/service6/deployment-node.yaml new file mode 100644 index 00000000..8d979237 --- /dev/null +++ b/internal/testdata/basic/service-templates/service6/deployment-node.yaml @@ -0,0 +1,96 @@ +--- +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 + 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: 100M + volumeMounts: + - mountPath: /var/run/secrets/lagoon/dynamic/insights-token + name: dynamic-insights-token + readOnly: true + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-private-registry-custom-secret + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: dynamic-insights-token + secret: + optional: false + secretName: insights-token +status: {} diff --git a/internal/testdata/basic/service-templates/service6/service-node.yaml b/internal/testdata/basic/service-templates/service6/service-node.yaml new file mode 100644 index 00000000..6b286993 --- /dev/null +++ b/internal/testdata/basic/service-templates/service6/service-node.yaml @@ -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: {} diff --git a/internal/testdata/testdata.go b/internal/testdata/testdata.go index 35ebf470..0919f13f 100644 --- a/internal/testdata/testdata.go +++ b/internal/testdata/testdata.go @@ -3,6 +3,7 @@ package testdata import ( "encoding/json" "os" + "strings" "time" "github.com/spf13/cobra" @@ -53,6 +54,7 @@ type TestData struct { ImageRegistry string PromotionSourceEnvironment string PrivateRegistryURLS []string + DynamicSecrets []string } // helper function to set up all the environment variables from provided testdata @@ -171,6 +173,10 @@ func SetupEnvironment(rootCmd cobra.Command, templatePath string, t TestData) (g if err != nil { return generator.GeneratorInput{}, err } + err = os.Setenv("DYNAMIC_SECRETS", strings.Join(t.DynamicSecrets, ",")) + if err != nil { + return generator.GeneratorInput{}, err + } generator, err := generator.GenerateInput(rootCmd, false) if err != nil { @@ -302,5 +308,8 @@ func GetSeedData(t TestData, defaultProjectVariables bool) TestData { if t.PrivateRegistryURLS != nil { rt.PrivateRegistryURLS = t.PrivateRegistryURLS } + if t.DynamicSecrets != nil { + rt.DynamicSecrets = t.DynamicSecrets + } return rt } diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index ca094e70..cef23b47 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -1476,6 +1476,9 @@ do yq3 write -i -- /kubectl-build-deploy/images.yaml 'images.'$COMPOSE_SERVICE'' ${SERVICE_NAME_IMAGE_HASH} done +# handle dynamic secret collection here, @TODO this will go into the state collector eventually +export DYNAMIC_SECRETS=$(kubectl -n ${NAMESPACE} get secrets -l lagoon.sh/dynamic-secret -o json | jq -r '[.items[] | .metadata.name] | join(",")') + echo "=== BEGIN deployment template for services ===" LAGOON_SERVICES_YAML_FOLDER="/kubectl-build-deploy/lagoon/service-deployments" mkdir -p $LAGOON_SERVICES_YAML_FOLDER diff --git a/legacy/scripts/exec-dynamic-secret-volumes.sh b/legacy/scripts/exec-dynamic-secret-volumes.sh deleted file mode 100755 index 131cd288..00000000 --- a/legacy/scripts/exec-dynamic-secret-volumes.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -# Dynamic secret loading -# This script will look in the current namespace for any secrets that have been - -DYNAMIC_SECRET_LABEL="lagoon.sh/dynamic-secret" - -KBD_SERVICE_VALUES_FILE="/${KBD_SERVICE_VALUES_OUTDIR:-kubectl-build-deploy}/${SERVICE_NAME}-values.yaml" - -VOLUME_MOUNT_BASE_PATH="/var/run/secrets/lagoon/dynamic/" - -VOLUME_NAME_PREFIX="dynamic-" -SECRET_NAME_PREFIX="dynamic-" - -RAW_KUBECTL_JSON_SECRET_LIST=$(kubectl --namespace ${NAMESPACE} get secrets -l $DYNAMIC_SECRET_LABEL -o json) - - -SECRET_MOUNT_VALUES=$'dynamicSecretMounts:\n' -SECRET_VOL_VALUES=$'dynamicSecretVolumes:\n' - -echo "$RAW_KUBECTL_JSON_SECRET_LIST" | jq -c --raw-output '.items[] | .metadata.name' | ( - while IFS=$"\n" read -r name; do - # so we have to do two things here. Generate the volume and the mount - MOUNT_PATH="$VOLUME_MOUNT_BASE_PATH$name" - SECRET_NAME="$name" - VOLUME_NAME="$VOLUME_NAME_PREFIX$name" - SECRET_MOUNT_VALUES+="\ - - name: $VOLUME_NAME - mountPath: "$MOUNT_PATH" - readOnly: true -" - - SECRET_VOL_VALUES+="\ - - name: $VOLUME_NAME - secret: - secretName: $SECRET_NAME - optional: false -" - done - echo "$SECRET_MOUNT_VALUES" >> $KBD_SERVICE_VALUES_FILE - echo "$SECRET_VOL_VALUES" >> $KBD_SERVICE_VALUES_FILE -) From 522f6488d83e7ad22f1f8bda7bb0e7d3a5b68d42 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 13 Feb 2024 19:34:08 +1100 Subject: [PATCH 63/92] refactor: consume container-registries from .lagoon.yml and provide to the build and create the secrets for those registries as required --- cmd/identify_imagebuild.go | 8 +- cmd/identify_imagebuild_test.go | 20 +- cmd/template_lagoonservices.go | 17 ++ cmd/template_lagoonservices_test.go | 16 +- internal/generator/build_data.go | 85 +++++++ internal/generator/buildvalues.go | 20 +- internal/generator/container_registries.go | 68 +++++ internal/generator/generator.go | 233 +----------------- internal/generator/helpers_generator.go | 61 +++++ internal/generator/lagoon_yaml.go | 61 +++++ internal/generator/services.go | 13 +- internal/lagoon/lagoon.go | 23 +- internal/lagoon/lagoon_test.go | 34 +++ .../lagoon-yaml/test8/lagoon.yml | 14 ++ .../template_networkpolicy_test.go | 9 +- .../registrysecret/registrysecret.go | 106 ++++++++ .../registrysecret/registrysecret_test.go | 90 +++++++ .../test-resources/registry-secret1.yaml | 21 ++ .../templating/services/templates_cronjob.go | 13 +- .../services/templates_cronjob_test.go | 5 - .../services/templates_deployment.go | 13 +- .../services/templates_deployment_test.go | 120 ++------- .../basic/lagoon.container-registry.yml | 16 ++ .../service1/deployment-node.yaml | 2 +- ...n-private-registry-my-custom-registry.yaml | 21 ++ .../service6/deployment-node.yaml | 2 +- ...n-private-registry-my-custom-registry.yaml | 21 ++ internal/testdata/complex/lagoon.varnish2.yml | 6 + 28 files changed, 726 insertions(+), 392 deletions(-) create mode 100644 internal/generator/build_data.go create mode 100644 internal/generator/container_registries.go create mode 100644 internal/generator/lagoon_yaml.go create mode 100644 internal/lagoon/test-resources/lagoon-yaml/test8/lagoon.yml create mode 100644 internal/templating/registrysecret/registrysecret.go create mode 100644 internal/templating/registrysecret/registrysecret_test.go create mode 100644 internal/templating/registrysecret/test-resources/registry-secret1.yaml create mode 100644 internal/testdata/basic/lagoon.container-registry.yml create mode 100644 internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-custom-registry.yaml create mode 100644 internal/testdata/basic/service-templates/service6/lagoon-private-registry-my-custom-registry.yaml diff --git a/cmd/identify_imagebuild.go b/cmd/identify_imagebuild.go index bd1b063d..23495f84 100644 --- a/cmd/identify_imagebuild.go +++ b/cmd/identify_imagebuild.go @@ -31,9 +31,10 @@ var imageBuildIdentify = &cobra.Command{ } type imageBuild struct { - BuildKit bool `json:"buildKit"` - Images []imageBuilds `json:"images"` - BuildArguments map[string]string `json:"buildArguments"` + BuildKit bool `json:"buildKit"` + Images []imageBuilds `json:"images"` + BuildArguments map[string]string `json:"buildArguments"` + ContainerRegistries []generator.ContainerRegistry `json:"containerRegistries,omitempty"` } type imageBuilds struct { @@ -68,6 +69,7 @@ func ImageBuildConfigurationIdentification(g generator.GeneratorInput) (imageBui }) } } + lServices.ContainerRegistries = lagoonBuild.BuildValues.ContainerRegistry return lServices, nil } diff --git a/cmd/identify_imagebuild_test.go b/cmd/identify_imagebuild_test.go index 7be84b3d..e7cf12b1 100644 --- a/cmd/identify_imagebuild_test.go +++ b/cmd/identify_imagebuild_test.go @@ -478,12 +478,6 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { }, { name: "test8 nginx-php external pull images", - vars: []helpers.EnvironmentVariable{ - { - Name: "EXTERNAL_REGISTRY_URLS", - Value: "registry1.example.com", - }, - }, args: testdata.GetSeedData( testdata.TestData{ Namespace: "example-project-main", @@ -491,9 +485,6 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { EnvironmentName: "main", Branch: "main", LagoonYAML: "internal/testdata/complex/lagoon.varnish2.yml", - // PrivateRegistryURLS: []string{ - // "registry1.example.com", - // }, ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_IMAGECACHE_REGISTRY", @@ -519,6 +510,17 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { "PHP_IMAGE": "example-project-main-php", "LAGOON_FEATURE_FLAG_IMAGECACHE_REGISTRY": "imagecache.example.com", }, + ContainerRegistries: []generator.ContainerRegistry{ + { + Name: "my-custom-registry", + Username: "registry_user", + Password: "REGISTRY_PASSWORD", + SecretName: "lagoon-private-registry-my-custom-registry", + URL: "registry1.example.com", + UsernameSource: ".lagoon.yml", + PasswordSource: ".lagoon.yml (we recommend using an environment variable, see the docs on container-registries for more information)", + }, + }, Images: []imageBuilds{ { Name: "cli", diff --git a/cmd/template_lagoonservices.go b/cmd/template_lagoonservices.go index 4d4ac296..7c1d9d78 100644 --- a/cmd/template_lagoonservices.go +++ b/cmd/template_lagoonservices.go @@ -9,6 +9,7 @@ import ( generator "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/templating/networkpolicy" + "github.com/uselagoon/build-deploy-tool/internal/templating/registrysecret" servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating/services" "sigs.k8s.io/yaml" ) @@ -52,6 +53,22 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { savedTemplates := g.SavedTemplatesPath // generate the templates + secrets, err := registrysecret.GenerateRegistrySecretTemplate(*lagoonBuild.BuildValues) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + for _, secret := range secrets { + serviceBytes, err := yaml.Marshal(secret) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + separator := []byte("---\n") + restoreResult := append(separator[:], serviceBytes[:]...) + if g.Debug { + fmt.Println(fmt.Sprintf("Templating registry secret manifests %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, secret.Name))) + } + helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, secret.Name), restoreResult) + } services, err := servicestemplates.GenerateServiceTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index 181d8200..5ba85ec4 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -27,18 +27,12 @@ func TestTemplateLagoonServices(t *testing.T) { }{ { name: "test1 basic deployment", - vars: []helpers.EnvironmentVariable{ - { - Name: "EXTERNAL_REGISTRY_SECRETS", - Value: "lagoon-private-registry-custom-secret", - }, - }, args: testdata.GetSeedData( testdata.TestData{ ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "internal/testdata/basic/lagoon.yml", + LagoonYAML: "internal/testdata/basic/lagoon.container-registry.yml", ImageReferences: map[string]string{ "node": "harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, @@ -185,18 +179,12 @@ func TestTemplateLagoonServices(t *testing.T) { }, { name: "test7 basic deployment with dynamic secrets", - vars: []helpers.EnvironmentVariable{ - { - Name: "EXTERNAL_REGISTRY_SECRETS", - Value: "lagoon-private-registry-custom-secret", - }, - }, args: testdata.GetSeedData( testdata.TestData{ ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "internal/testdata/basic/lagoon.yml", + LagoonYAML: "internal/testdata/basic/lagoon.container-registry.yml", ImageReferences: map[string]string{ "node": "harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, diff --git a/internal/generator/build_data.go b/internal/generator/build_data.go new file mode 100644 index 00000000..15012b4a --- /dev/null +++ b/internal/generator/build_data.go @@ -0,0 +1,85 @@ +package generator + +import ( + "fmt" + "strings" + + "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/lagoon" +) + +// this creates a bunch of standard environment variables that are injected into the `lagoon-env` configmap normally +func collectBuildVariables(buildValues BuildValues) []lagoon.EnvironmentVariable { + vars := []lagoon.EnvironmentVariable{} + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_PROJECT", Value: buildValues.Project, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ENVIRONMENT", Value: buildValues.Environment, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ENVIRONMENT_TYPE", Value: buildValues.EnvironmentType, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_SHA", Value: buildValues.GitSHA, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_KUBERNETES", Value: buildValues.Kubernetes, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_SAFE_BRANCH", Value: buildValues.Environment, Scope: "runtime"}) //deprecated??? (https://github.com/uselagoon/lagoon/blob/1053965321495213591f4c9110f90a9d9dcfc946/images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh#L748) + if buildValues.BuildType == "branch" { + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_BRANCH", Value: buildValues.Branch, Scope: "runtime"}) + } + if buildValues.BuildType == "pullrequest" { + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_PR_HEAD_BRANCH", Value: buildValues.PRHeadBranch, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_PR_BASE_BRANCH", Value: buildValues.PRBaseBranch, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_PR_TITLE", Value: buildValues.PRTitle, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_PR_NUMBER", Value: buildValues.PRNumber, Scope: "runtime"}) + } + if buildValues.ActiveEnvironment != "" { + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ACTIVE_ENVIRONMENT", Value: buildValues.ActiveEnvironment, Scope: "runtime"}) + } + if buildValues.StandbyEnvironment != "" { + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_STANDBY_ENVIRONMENT", Value: buildValues.StandbyEnvironment, Scope: "runtime"}) + } + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ROUTE", Value: buildValues.Route, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ROUTES", Value: strings.Join(buildValues.Routes, ","), Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_AUTOGENERATED_ROUTES", Value: strings.Join(buildValues.AutogeneratedRoutes, ","), Scope: "runtime"}) + return vars +} + +// this creates all the build arguments that an image build can consume +func collectImageBuildArguments(buildValues BuildValues) map[string]string { + buildArgs := map[string]string{} + // source any from the environment variables in the project/environment that are `global` or `build` scoped + for _, envvar := range buildValues.EnvironmentVariables { + if helpers.Contains([]string{"global", "build"}, envvar.Scope) { + buildArgs[envvar.Name] = envvar.Value + } + } + // set the standard ones + if buildValues.IsCI { + buildArgs["IMAGE_REPO"] = "172.17.0.1:5000/lagoon" + } + buildArgs["LAGOON_PROJECT"] = buildValues.Project + buildArgs["LAGOON_ENVIRONMENT"] = buildValues.Environment + buildArgs["LAGOON_ENVIRONMENT_TYPE"] = buildValues.EnvironmentType + buildArgs["LAGOON_BUILD_TYPE"] = buildValues.BuildType + buildArgs["LAGOON_GIT_SOURCE_REPOSITORY"] = buildValues.SourceRepository + buildArgs["LAGOON_KUBERNETES"] = buildValues.Kubernetes + // set any specific build type overrides + if buildValues.BuildType == "branch" { + buildArgs["LAGOON_GIT_SHA"] = buildValues.GitSHA + buildArgs["LAGOON_GIT_BRANCH"] = buildValues.Branch + } + if buildValues.BuildType == "pullrequest" { + buildArgs["LAGOON_GIT_SHA"] = buildValues.GitSHA + buildArgs["LAGOON_PR_HEAD_BRANCH"] = buildValues.PRHeadBranch + buildArgs["LAGOON_PR_HEAD_SHA"] = buildValues.PRHeadSHA + buildArgs["LAGOON_PR_BASE_BRANCH"] = buildValues.PRBaseBranch + buildArgs["LAGOON_PR_BASE_SHA"] = buildValues.PRBaseSHA + buildArgs["LAGOON_PR_TITLE"] = buildValues.PRTitle + buildArgs["LAGOON_PR_NUMBER"] = buildValues.PRNumber + } + // Add in random data as per https://github.com/uselagoon/lagoon/issues/2246 + buildArgs["LAGOON_BUILD_NAME"] = buildValues.BuildName + // and now that we know the temporary image names upfront, they can be passed to all image build steps without + // needing to wait for the other images to be built + for _, service := range buildValues.Services { + if service.ImageBuild != nil && service.ImageBuild.TemporaryImage != "" { + // add the temporary image name to the payload + buildArgs[fmt.Sprintf("%s_IMAGE", strings.ToUpper(service.Name))] = service.ImageBuild.TemporaryImage + } + } + return buildArgs +} diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index d79991cc..3c2c6be9 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -7,6 +7,10 @@ import ( corev1 "k8s.io/api/core/v1" ) +const ( + DefaultImagePullSecret = "lagoon-internal-registry-secret" +) + // BuildValues is the values file data generated by the lagoon build type BuildValues struct { SourceRepository string `json:"sourceRepository" description:"the source repository for the project"` @@ -24,7 +28,6 @@ type BuildValues struct { IsActiveEnvironment bool `json:"isActiveEnvironment" activestandby:"true" description:"flag to determine if this environment is currently an active environment"` IsStandbyEnvironment bool `json:"isStandbyEnvironment" activestandby:"true" description:"flag to determine if this environment is currently a standby environment"` PodSecurityContext PodSecurityContext `json:"podSecurityContext" description:"stores the podsecuritycontext overrides"` - ImagePullSecrets []ImagePullSecrets `json:"imagePullSecrets" description:"stores any image pull secrets that the deployments in this environment need to know about"` Branch string `json:"branch" buildtype:"branch" description:"the branch used for this environment"` PRNumber string `json:"prNumber" buildtype:"pullrequest" description:"pullrequest number"` PRTitle string `json:"prTitle" buildtype:"pullrequest" description:"title of the pullrequest"` @@ -69,6 +72,7 @@ type BuildValues struct { IsCI bool `json:"isCI" description:"this controls aspects of the environment or build depending on if a CI job"` RWX2RWO bool `json:"RWX2RWO" description:"this controls whether the ReadWriteMany to ReadWriteOnce override should be used"` IsolationNetworkPolicy bool `json:"isolationNetworkPolicy" description:"this controls whether isolation network policies should be enabled"` + ContainerRegistry []ContainerRegistry `json:"containerRegistry" description:"this contains any private container registries that may exist within the environment that need to be logged into"` } type Resources struct { @@ -85,6 +89,16 @@ type ResourceRequests struct { EphemeralStorage string `json:"ephemeral-storage"` } +type ContainerRegistry struct { + Name string `json:"name" description:"name of the registry collected from the .lagoon.yml file"` + Username string `json:"username" description:"the username to use to log in to the registry"` + Password string `json:"password" description:"the password or password variable reference to use to log in to the registry"` + URL string `json:"url" description:"the registry url"` + UsernameSource string `json:"usernameSource" description:"information regarding the source of the username"` + PasswordSource string `json:"passwordSource" description:"information regarding the source of the password"` + SecretName string `json:"secretName" description:"the name of the secret to be created for this registry"` +} + type PodSecurityContext struct { FsGroup int64 `json:"fsGroup"` RunAsGroup int64 `json:"runAsGroup"` @@ -104,10 +118,6 @@ type MonitoringConfig struct { StatusPageID string `json:"statusPageID"` } -type ImagePullSecrets struct { - Name string `json:"name"` -} - type DynamicSecretMounts struct { Name string `json:"name"` MountPath string `json:"mountPath"` diff --git a/internal/generator/container_registries.go b/internal/generator/container_registries.go new file mode 100644 index 00000000..3c385d29 --- /dev/null +++ b/internal/generator/container_registries.go @@ -0,0 +1,68 @@ +package generator + +import ( + "fmt" + "net/url" + "strings" + + "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/lagoon" + machinerynamespace "github.com/uselagoon/machinery/utils/namespace" + "k8s.io/apimachinery/pkg/util/validation" +) + +// this converts lagoon.yml container registry definitions into build values container registry definitions +// that are then used to generate secrets, or get passed to docker login commands within the build +func configureContainerRegistries(buildValues *BuildValues) error { + for n, cr := range buildValues.LagoonYAML.ContainerRegistries { + // check for required inputs + if cr.Username == "" { + return fmt.Errorf("no username defined for registry %s", n) + } + if cr.Password == "" { + return fmt.Errorf("no password defined for registry %s", n) + } + // check for an override password + password, _ := lagoon.GetLagoonVariable(fmt.Sprintf("REGISTRY_%s_PASSWORD", n), []string{"container_registry"}, buildValues.EnvironmentVariables) + passwordSource := fmt.Sprintf("Lagoon API environment variable %s", fmt.Sprintf("REGISTRY_%s_PASSWORD", n)) + if password == nil { + // no override found, check for a variable that matches the name in the password field + password, _ = lagoon.GetLagoonVariable(cr.Password, []string{"container_registry"}, buildValues.EnvironmentVariables) + passwordSource = fmt.Sprintf("Lagoon API environment variable %s", cr.Password) + } + if password == nil { + // finally, if no password is found in any variables, pass in the one from the `.lagoon.yml` directly + password = &lagoon.EnvironmentVariable{Value: cr.Password} + passwordSource = ".lagoon.yml (we recommend using an environment variable, see the docs on container-registries for more information)" + } + // check for an override username + username, _ := lagoon.GetLagoonVariable(fmt.Sprintf("REGISTRY_%s_USERNAME", n), []string{"container_registry"}, buildValues.EnvironmentVariables) + usernameSource := fmt.Sprintf("Lagoon API environment variable %s", fmt.Sprintf("REGISTRY_%s_USERNAME", n)) + if username == nil { + username = &lagoon.EnvironmentVariable{Value: cr.Username} + usernameSource = ".lagoon.yml" + } + eru := cr.URL + u, _ := url.Parse(eru) + if u.Host == "" { + eru = fmt.Sprintf("%s", eru) + } else { + eru = fmt.Sprintf("%s", u.Host) + } + // truncate the secret name to fit within the DNS1123subdomain spec before creating it + secretName := fmt.Sprintf("lagoon-private-registry-%s", machinerynamespace.MakeSafe(n)) + if err := validation.IsDNS1123Subdomain(strings.ToLower(secretName)); err != nil { + secretName = fmt.Sprintf("%s-%s", secretName[:len(secretName)-10], helpers.GetMD5HashWithNewLine(machinerynamespace.MakeSafe(n))[:5]) + } + buildValues.ContainerRegistry = append(buildValues.ContainerRegistry, ContainerRegistry{ + Name: n, + Username: username.Value, + Password: password.Value, + URL: eru, + UsernameSource: usernameSource, + PasswordSource: passwordSource, + SecretName: secretName, + }) + } + return nil +} diff --git a/internal/generator/generator.go b/internal/generator/generator.go index fe137097..eba138d6 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -1,20 +1,15 @@ package generator import ( - "encoding/base64" "encoding/json" - "errors" "fmt" "net/url" - "os" "strconv" "strings" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" - "k8s.io/apimachinery/pkg/api/resource" - "sigs.k8s.io/yaml" ) type Generator struct { @@ -62,13 +57,11 @@ type GeneratorInput struct { Debug bool DBaaSClient *dbaasclient.Client ImageReferences map[string]string - ImagePullSecrets []string Namespace string DefaultBackupSchedule string ImageRegistry string Kubernetes string CI bool - PrivateRegistryURLS []string DynamicSecrets []string } @@ -113,38 +106,6 @@ func NewGenerator( prHeadSHA := helpers.GetEnv("PR_HEAD_SHA", generator.PRHeadSHA, generator.Debug) prBaseSHA := helpers.GetEnv("PR_BASE_SHA", generator.PRBaseSHA, generator.Debug) dynamicSecrets := helpers.GetEnv("DYNAMIC_SECRETS", strings.Join(generator.DynamicSecrets, ","), generator.Debug) - // get any external registry urls that this build has so we can update any pullthrough images accordingly - gExternalRegistryURLS := "" - if generator.PrivateRegistryURLS != nil { - gExternalRegistryURLS = strings.Join(generator.PrivateRegistryURLS, ",") - } - sExternalRegistryURLs := helpers.GetEnv("EXTERNAL_REGISTRY_URLS", gExternalRegistryURLS, generator.Debug) - if sExternalRegistryURLs != "" { - externalRegistryURLs := strings.Split(sExternalRegistryURLs, ",") - for _, eru := range externalRegistryURLs { - // strip the scheme, only provide the host - u, _ := url.Parse(eru) - if u.Host == "" { - eru = fmt.Sprintf("%s/", eru) - buildValues.PrivateRegistryURLS = append(buildValues.PrivateRegistryURLS, eru) - } else { - eru = fmt.Sprintf("%s/", u.Host) - buildValues.PrivateRegistryURLS = append(buildValues.PrivateRegistryURLS, eru) - } - } - } - // get any external registry secrets from the environment - gExternalRegistrySecrets := "" - if generator.PrivateRegistryURLS != nil { - gExternalRegistrySecrets = strings.Join(generator.ImagePullSecrets, ",") - } - sExternalRegistrySecrets := helpers.GetEnv("EXTERNAL_REGISTRY_SECRETS", gExternalRegistrySecrets, generator.Debug) - if sExternalRegistrySecrets != "" { - externalRegistrySecrets := strings.Split(sExternalRegistrySecrets, ",") - for _, ers := range externalRegistrySecrets { - buildValues.ImagePullSecrets = append(buildValues.ImagePullSecrets, ImagePullSecrets{Name: ers}) - } - } // this is used by CI systems to influence builds, it is rarely used and should probably be abandoned buildValues.IsCI = helpers.GetEnvBool("CI", generator.CI, generator.Debug) @@ -157,9 +118,6 @@ func NewGenerator( buildValues.PromotionSourceEnvironment = promotionSourceEnvironment // get the image references values from the build images output buildValues.ImageReferences = generator.ImageReferences - // add standard lagoon imagepull secret name - buildValues.ImagePullSecrets = append(buildValues.ImagePullSecrets, ImagePullSecrets{Name: "lagoon-internal-registry-secret"}) - defaultBackupSchedule := helpers.GetEnv("DEFAULT_BACKUP_SCHEDULE", generator.DefaultBackupSchedule, generator.Debug) if defaultBackupSchedule == "" { defaultBackupSchedule = "M H(22-2) * * *" @@ -291,6 +249,11 @@ func NewGenerator( // this will later be used to add `runtime|global` scope into the `lagoon-env` configmap buildValues.EnvironmentVariables = lagoon.MergeVariables(mergedVariables, configVars) + // handle generating the container registry login generation here, extract from the `.lagoon.yml` firstly + if err := configureContainerRegistries(&buildValues); err != nil { + return nil, err + } + // check for readwritemany to readwriteonce flag, disabled by default rwx2rwo := CheckFeatureFlag("RWX_TO_RWO", buildValues.EnvironmentVariables, generator.Debug) if rwx2rwo == "enabled" { @@ -442,7 +405,9 @@ func NewGenerator( } /* end route generation configuration */ - // finally return the generator values + // finally return the generator values, this should be a mostly complete version of the resulting data needed for a build + // another step will collect the current or known state of a build. + // the output of the generator and the output of that state collector will eventually replace a lot of the legacy BASH script return &Generator{ BuildValues: &buildValues, ActiveEnvironment: &buildValues.IsActiveEnvironment, @@ -452,185 +417,3 @@ func NewGenerator( ActiveStandbyRoutes: activeStandbyRoutes, }, nil } - -func LoadAndUnmarshalLagoonYml(lagoonYml string, lagoonYmlOverride string, lagoonYmlOverrideEnvVarName string, lYAML *lagoon.YAML, projectName string, debug bool) error { - - // First we load the primary file - if err := lagoon.UnmarshalLagoonYAML(lagoonYml, lYAML, projectName); err != nil { - return fmt.Errorf("couldn't unmarshal file %v: %v", lagoonYml, err) - } - - // Here we try and merge in .lagoon.yml override - if _, err := os.Stat(lagoonYmlOverride); err == nil { - overLagoonYaml := &lagoon.YAML{} - if err := lagoon.UnmarshalLagoonYAML(lagoonYmlOverride, overLagoonYaml, projectName); err != nil { - return fmt.Errorf("couldn't unmarshal file %v: %v", lagoonYmlOverride, err) - } - //now we merge - if err := lagoon.MergeLagoonYAMLs(lYAML, overLagoonYaml); err != nil { - return fmt.Errorf("unable to merge %v over %v: %v", lagoonYmlOverride, lagoonYml, err) - } - } - // Now we see if there are any environment vars set for .lagoon.yml overrides - envLagoonYamlStringBase64 := helpers.GetEnv(lagoonYmlOverrideEnvVarName, "", debug) - if envLagoonYamlStringBase64 != "" { - //Decode it - envLagoonYamlString, err := base64.StdEncoding.DecodeString(envLagoonYamlStringBase64) - if err != nil { - return fmt.Errorf("Unable to decode %v - is it base64 encoded?", lagoonYmlOverrideEnvVarName) - } - envLagoonYaml := &lagoon.YAML{} - lEnvLagoonPolysite := make(map[string]interface{}) - - err = yaml.Unmarshal(envLagoonYamlString, envLagoonYaml) - if err != nil { - return fmt.Errorf("Unable to unmarshal env var %v: %v", lagoonYmlOverrideEnvVarName, err) - } - err = yaml.Unmarshal(envLagoonYamlString, lEnvLagoonPolysite) - if err != nil { - return fmt.Errorf("Unable to unmarshal env var %v: %v", lagoonYmlOverrideEnvVarName, err) - } - - if _, ok := lEnvLagoonPolysite[projectName]; ok { - s, _ := yaml.Marshal(lEnvLagoonPolysite[projectName]) - _ = yaml.Unmarshal(s, &envLagoonYaml) - } - //now we merge - if err := lagoon.MergeLagoonYAMLs(lYAML, envLagoonYaml); err != nil { - return fmt.Errorf("unable to merge LAGOON_YAML_OVERRIDE over %v: %v", lagoonYml, err) - } - } - return nil -} - -// this creates a bunch of standard environment variables that are injected into the `lagoon-env` configmap normally -func collectBuildVariables(buildValues BuildValues) []lagoon.EnvironmentVariable { - vars := []lagoon.EnvironmentVariable{} - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_PROJECT", Value: buildValues.Project, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ENVIRONMENT", Value: buildValues.Environment, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ENVIRONMENT_TYPE", Value: buildValues.EnvironmentType, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_SHA", Value: buildValues.GitSHA, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_KUBERNETES", Value: buildValues.Kubernetes, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_SAFE_BRANCH", Value: buildValues.Environment, Scope: "runtime"}) //deprecated??? (https://github.com/uselagoon/lagoon/blob/1053965321495213591f4c9110f90a9d9dcfc946/images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh#L748) - if buildValues.BuildType == "branch" { - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_BRANCH", Value: buildValues.Branch, Scope: "runtime"}) - } - if buildValues.BuildType == "pullrequest" { - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_PR_HEAD_BRANCH", Value: buildValues.PRHeadBranch, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_PR_BASE_BRANCH", Value: buildValues.PRBaseBranch, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_PR_TITLE", Value: buildValues.PRTitle, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_PR_NUMBER", Value: buildValues.PRNumber, Scope: "runtime"}) - } - if buildValues.ActiveEnvironment != "" { - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ACTIVE_ENVIRONMENT", Value: buildValues.ActiveEnvironment, Scope: "runtime"}) - } - if buildValues.StandbyEnvironment != "" { - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_STANDBY_ENVIRONMENT", Value: buildValues.StandbyEnvironment, Scope: "runtime"}) - } - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ROUTE", Value: buildValues.Route, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ROUTES", Value: strings.Join(buildValues.Routes, ","), Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_AUTOGENERATED_ROUTES", Value: strings.Join(buildValues.AutogeneratedRoutes, ","), Scope: "runtime"}) - return vars -} - -// this creates all the build arguments that an image build can consume -func collectImageBuildArguments(buildValues BuildValues) map[string]string { - buildArgs := map[string]string{} - // source any from the environment variables in the project/environment that are `global` or `build` scoped - for _, envvar := range buildValues.EnvironmentVariables { - if helpers.Contains([]string{"global", "build"}, envvar.Scope) { - buildArgs[envvar.Name] = envvar.Value - } - } - // set the standard ones - if buildValues.IsCI { - buildArgs["IMAGE_REPO"] = "172.17.0.1:5000/lagoon" - } - buildArgs["LAGOON_PROJECT"] = buildValues.Project - buildArgs["LAGOON_ENVIRONMENT"] = buildValues.Environment - buildArgs["LAGOON_ENVIRONMENT_TYPE"] = buildValues.EnvironmentType - buildArgs["LAGOON_BUILD_TYPE"] = buildValues.BuildType - buildArgs["LAGOON_GIT_SOURCE_REPOSITORY"] = buildValues.SourceRepository - buildArgs["LAGOON_KUBERNETES"] = buildValues.Kubernetes - // set any specific build type overrides - if buildValues.BuildType == "branch" { - buildArgs["LAGOON_GIT_SHA"] = buildValues.GitSHA - buildArgs["LAGOON_GIT_BRANCH"] = buildValues.Branch - } - if buildValues.BuildType == "pullrequest" { - buildArgs["LAGOON_GIT_SHA"] = buildValues.GitSHA - buildArgs["LAGOON_PR_HEAD_BRANCH"] = buildValues.PRHeadBranch - buildArgs["LAGOON_PR_HEAD_SHA"] = buildValues.PRHeadSHA - buildArgs["LAGOON_PR_BASE_BRANCH"] = buildValues.PRBaseBranch - buildArgs["LAGOON_PR_BASE_SHA"] = buildValues.PRBaseSHA - buildArgs["LAGOON_PR_TITLE"] = buildValues.PRTitle - buildArgs["LAGOON_PR_NUMBER"] = buildValues.PRNumber - } - // Add in random data as per https://github.com/uselagoon/lagoon/issues/2246 - buildArgs["LAGOON_BUILD_NAME"] = buildValues.BuildName - // and now that we know the temporary image names upfront, they can be passed to all image build steps without - // needing to wait for the other images to be built - for _, service := range buildValues.Services { - if service.ImageBuild != nil && service.ImageBuild.TemporaryImage != "" { - // add the temporary image name to the payload - buildArgs[fmt.Sprintf("%s_IMAGE", strings.ToUpper(service.Name))] = service.ImageBuild.TemporaryImage - } - } - return buildArgs -} - -// checks the provided environment variables looking for feature flag based variables -func CheckFeatureFlag(key string, envVariables []lagoon.EnvironmentVariable, debug bool) string { - // check for force value - if value, ok := os.LookupEnv(fmt.Sprintf("LAGOON_FEATURE_FLAG_FORCE_%s", key)); ok { - if debug { - fmt.Println(fmt.Sprintf("Using forced flag value from build variable %s", fmt.Sprintf("LAGOON_FEATURE_FLAG_FORCE_%s", key))) - } - return value - } - // check lagoon environment variables - for _, lVar := range envVariables { - if strings.Contains(lVar.Name, fmt.Sprintf("LAGOON_FEATURE_FLAG_%s", key)) { - if debug { - fmt.Println(fmt.Sprintf("Using flag value from Lagoon environment variable %s", fmt.Sprintf("LAGOON_FEATURE_FLAG_%s", key))) - } - return lVar.Value - } - } - // return default - if value, ok := os.LookupEnv(fmt.Sprintf("LAGOON_FEATURE_FLAG_DEFAULT_%s", key)); ok { - if debug { - fmt.Println(fmt.Sprintf("Using default flag value from build variable %s", fmt.Sprintf("LAGOON_FEATURE_FLAG_DEFAULT_%s", key))) - } - return value - } - // otherwise nothing - return "" -} - -func CheckAdminFeatureFlag(key string, debug bool) string { - if value, ok := os.LookupEnv(fmt.Sprintf("ADMIN_LAGOON_FEATURE_FLAG_%s", key)); ok { - if debug { - fmt.Println(fmt.Sprintf("Using admin feature flag value from build variable %s", fmt.Sprintf("ADMIN_LAGOON_FEATURE_FLAG_%s", key))) - } - return value - } - return "" -} - -func ValidateResourceQuantity(s string) (err error) { - defer func() { - if r := recover(); r != nil { - switch x := r.(type) { - case string: - err = errors.New(x) - case error: - err = x - default: - err = errors.New(fmt.Sprint(x)) - } - } - }() - resource.MustParse(s) - return nil -} diff --git a/internal/generator/helpers_generator.go b/internal/generator/helpers_generator.go index 6686fde1..231c1701 100644 --- a/internal/generator/helpers_generator.go +++ b/internal/generator/helpers_generator.go @@ -1,10 +1,15 @@ package generator import ( + "errors" "fmt" + "os" + "strings" "github.com/spf13/cobra" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" + "github.com/uselagoon/build-deploy-tool/internal/lagoon" + "k8s.io/apimachinery/pkg/api/resource" ) // helper function that reads flag overrides and retruns a generated input dataset @@ -137,3 +142,59 @@ func GenerateInput(rootCmd cobra.Command, debug bool) (GeneratorInput, error) { DefaultBackupSchedule: defaultBackupSchedule, }, nil } + +// checks the provided environment variables looking for feature flag based variables +func CheckFeatureFlag(key string, envVariables []lagoon.EnvironmentVariable, debug bool) string { + // check for force value + if value, ok := os.LookupEnv(fmt.Sprintf("LAGOON_FEATURE_FLAG_FORCE_%s", key)); ok { + if debug { + fmt.Println(fmt.Sprintf("Using forced flag value from build variable %s", fmt.Sprintf("LAGOON_FEATURE_FLAG_FORCE_%s", key))) + } + return value + } + // check lagoon environment variables + for _, lVar := range envVariables { + if strings.Contains(lVar.Name, fmt.Sprintf("LAGOON_FEATURE_FLAG_%s", key)) { + if debug { + fmt.Println(fmt.Sprintf("Using flag value from Lagoon environment variable %s", fmt.Sprintf("LAGOON_FEATURE_FLAG_%s", key))) + } + return lVar.Value + } + } + // return default + if value, ok := os.LookupEnv(fmt.Sprintf("LAGOON_FEATURE_FLAG_DEFAULT_%s", key)); ok { + if debug { + fmt.Println(fmt.Sprintf("Using default flag value from build variable %s", fmt.Sprintf("LAGOON_FEATURE_FLAG_DEFAULT_%s", key))) + } + return value + } + // otherwise nothing + return "" +} + +func CheckAdminFeatureFlag(key string, debug bool) string { + if value, ok := os.LookupEnv(fmt.Sprintf("ADMIN_LAGOON_FEATURE_FLAG_%s", key)); ok { + if debug { + fmt.Println(fmt.Sprintf("Using admin feature flag value from build variable %s", fmt.Sprintf("ADMIN_LAGOON_FEATURE_FLAG_%s", key))) + } + return value + } + return "" +} + +func ValidateResourceQuantity(s string) (err error) { + defer func() { + if r := recover(); r != nil { + switch x := r.(type) { + case string: + err = errors.New(x) + case error: + err = x + default: + err = errors.New(fmt.Sprint(x)) + } + } + }() + resource.MustParse(s) + return nil +} diff --git a/internal/generator/lagoon_yaml.go b/internal/generator/lagoon_yaml.go new file mode 100644 index 00000000..bb9f5722 --- /dev/null +++ b/internal/generator/lagoon_yaml.go @@ -0,0 +1,61 @@ +package generator + +import ( + "encoding/base64" + "fmt" + "os" + + "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/lagoon" + "sigs.k8s.io/yaml" +) + +func LoadAndUnmarshalLagoonYml(lagoonYml string, lagoonYmlOverride string, lagoonYmlOverrideEnvVarName string, lYAML *lagoon.YAML, projectName string, debug bool) error { + + // First we load the primary file + if err := lagoon.UnmarshalLagoonYAML(lagoonYml, lYAML, projectName); err != nil { + return fmt.Errorf("couldn't unmarshal file %v: %v", lagoonYml, err) + } + + // Here we try and merge in .lagoon.yml override + if _, err := os.Stat(lagoonYmlOverride); err == nil { + overLagoonYaml := &lagoon.YAML{} + if err := lagoon.UnmarshalLagoonYAML(lagoonYmlOverride, overLagoonYaml, projectName); err != nil { + return fmt.Errorf("couldn't unmarshal file %v: %v", lagoonYmlOverride, err) + } + //now we merge + if err := lagoon.MergeLagoonYAMLs(lYAML, overLagoonYaml); err != nil { + return fmt.Errorf("unable to merge %v over %v: %v", lagoonYmlOverride, lagoonYml, err) + } + } + // Now we see if there are any environment vars set for .lagoon.yml overrides + envLagoonYamlStringBase64 := helpers.GetEnv(lagoonYmlOverrideEnvVarName, "", debug) + if envLagoonYamlStringBase64 != "" { + //Decode it + envLagoonYamlString, err := base64.StdEncoding.DecodeString(envLagoonYamlStringBase64) + if err != nil { + return fmt.Errorf("Unable to decode %v - is it base64 encoded?", lagoonYmlOverrideEnvVarName) + } + envLagoonYaml := &lagoon.YAML{} + lEnvLagoonPolysite := make(map[string]interface{}) + + err = yaml.Unmarshal(envLagoonYamlString, envLagoonYaml) + if err != nil { + return fmt.Errorf("Unable to unmarshal env var %v: %v", lagoonYmlOverrideEnvVarName, err) + } + err = yaml.Unmarshal(envLagoonYamlString, lEnvLagoonPolysite) + if err != nil { + return fmt.Errorf("Unable to unmarshal env var %v: %v", lagoonYmlOverrideEnvVarName, err) + } + + if _, ok := lEnvLagoonPolysite[projectName]; ok { + s, _ := yaml.Marshal(lEnvLagoonPolysite[projectName]) + _ = yaml.Unmarshal(s, &envLagoonYaml) + } + //now we merge + if err := lagoon.MergeLagoonYAMLs(lYAML, envLagoonYaml); err != nil { + return fmt.Errorf("unable to merge LAGOON_YAML_OVERRIDE over %v: %v", lagoonYml, err) + } + } + return nil +} diff --git a/internal/generator/services.go b/internal/generator/services.go index 8e91f255..0a0ca93d 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -470,7 +470,7 @@ func composeToServiceValues( } else { imageBuild.PullImage = pullImage } - if !helpers.ContainsR(buildValues.PrivateRegistryURLS, pullImage) { + if !ContainsRegistry(buildValues.ContainerRegistry, pullImage) { if buildValues.ImageCache != "" { imageBuild.PullImage = fmt.Sprintf("%s%s", buildValues.ImageCache, imageBuild.PullImage) } @@ -606,3 +606,14 @@ func checkDuplicateCronjobs(cronjobs []lagoon.Cronjob) error { } return nil } + +// ContainsR checks if a string slice contains a specific string regex match. +func ContainsRegistry(regex []ContainerRegistry, match string) bool { + for _, v := range regex { + m, _ := regexp.MatchString(v.URL, match) + if m { + return true + } + } + return false +} diff --git a/internal/lagoon/lagoon.go b/internal/lagoon/lagoon.go index f0ddf0b7..3714be0f 100644 --- a/internal/lagoon/lagoon.go +++ b/internal/lagoon/lagoon.go @@ -61,14 +61,21 @@ type Tasks struct { // YAML represents the .lagoon.yml file. type YAML struct { - DockerComposeYAML string `json:"docker-compose-yaml"` - Environments Environments `json:"environments"` - ProductionRoutes *ProductionRoutes `json:"production_routes"` - Tasks Tasks `json:"tasks"` - Routes Routes `json:"routes"` - BackupRetention BackupRetention `json:"backup-retention"` - BackupSchedule BackupSchedule `json:"backup-schedule"` - EnvironmentVariables EnvironmentVariables `json:"environment_variables,omitempty"` + DockerComposeYAML string `json:"docker-compose-yaml"` + Environments Environments `json:"environments"` + ProductionRoutes *ProductionRoutes `json:"production_routes"` + Tasks Tasks `json:"tasks"` + Routes Routes `json:"routes"` + BackupRetention BackupRetention `json:"backup-retention"` + BackupSchedule BackupSchedule `json:"backup-schedule"` + EnvironmentVariables EnvironmentVariables `json:"environment_variables,omitempty"` + ContainerRegistries map[string]ContainerRegistry `json:"container-registries,omitempty"` +} + +type ContainerRegistry struct { + Username string `json:"username"` + Password string `json:"password"` + URL string `json:"url"` } type EnvironmentVariables struct { diff --git a/internal/lagoon/lagoon_test.go b/internal/lagoon/lagoon_test.go index ba423ec5..70c4b888 100644 --- a/internal/lagoon/lagoon_test.go +++ b/internal/lagoon/lagoon_test.go @@ -354,6 +354,40 @@ func TestUnmarshalLagoonYAML(t *testing.T) { }, }, }, + { + name: "test container registries", + args: args{ + file: "test-resources/lagoon-yaml/test8/lagoon.yml", + l: &YAML{}, + }, + want: &YAML{ + DockerComposeYAML: "docker-compose.yml", + ContainerRegistries: map[string]ContainerRegistry{ + "my-custom-registry": { + Username: "myownregistryuser", + Password: "REGISTRY_PASSWORD", + URL: "my.own.registry.com", + }, + }, + Environments: Environments{ + "main": Environment{ + Routes: []map[string][]Route{ + { + "nginx": { + { + Ingresses: map[string]Ingress{ + "a.example.com": { + TLSAcme: helpers.BoolPtr(true), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/lagoon/test-resources/lagoon-yaml/test8/lagoon.yml b/internal/lagoon/test-resources/lagoon-yaml/test8/lagoon.yml new file mode 100644 index 00000000..71ae0074 --- /dev/null +++ b/internal/lagoon/test-resources/lagoon-yaml/test8/lagoon.yml @@ -0,0 +1,14 @@ +docker-compose-yaml: docker-compose.yml + +container-registries: + my-custom-registry: + username: myownregistryuser + password: REGISTRY_PASSWORD + url: my.own.registry.com + +environments: + main: + routes: + - nginx: + - a.example.com: + tls-acme: true \ No newline at end of file diff --git a/internal/templating/networkpolicy/template_networkpolicy_test.go b/internal/templating/networkpolicy/template_networkpolicy_test.go index 583640a3..6598c254 100644 --- a/internal/templating/networkpolicy/template_networkpolicy_test.go +++ b/internal/templating/networkpolicy/template_networkpolicy_test.go @@ -32,13 +32,8 @@ func TestGenerateNetworkPolicy(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, - GitSHA: "0", - ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", ImageReferences: map[string]string{ "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", "myservice-po": "harbor.example.com/example-project/environment-name/myservice-po@latest", diff --git a/internal/templating/registrysecret/registrysecret.go b/internal/templating/registrysecret/registrysecret.go new file mode 100644 index 00000000..464350fb --- /dev/null +++ b/internal/templating/registrysecret/registrysecret.go @@ -0,0 +1,106 @@ +package registrysecret + +import ( + "encoding/base64" + "fmt" + + "github.com/uselagoon/build-deploy-tool/internal/generator" + "github.com/uselagoon/build-deploy-tool/internal/helpers" + corev1 "k8s.io/api/core/v1" + apivalidation "k8s.io/apimachinery/pkg/api/validation" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" +) + +// GenerateRegistrySecretTemplate generates the lagoon template to apply. +func GenerateRegistrySecretTemplate( + buildValues generator.BuildValues, +) ([]corev1.Secret, error) { + var result []corev1.Secret + + // add the default labels + labels := map[string]string{ + "app.kubernetes.io/managed-by": "build-deploy-tool", + "lagoon.sh/project": buildValues.Project, + "lagoon.sh/environment": buildValues.Environment, + "lagoon.sh/environmentType": buildValues.EnvironmentType, + "lagoon.sh/buildType": buildValues.BuildType, + } + + // add the default annotations + annotations := map[string]string{ + "lagoon.sh/version": buildValues.LagoonVersion, + } + + // add any additional labels + if buildValues.BuildType == "branch" { + annotations["lagoon.sh/branch"] = buildValues.Branch + } else if buildValues.BuildType == "pullrequest" { + annotations["lagoon.sh/prNumber"] = buildValues.PRNumber + annotations["lagoon.sh/prHeadBranch"] = buildValues.PRHeadBranch + annotations["lagoon.sh/prBaseBranch"] = buildValues.PRBaseBranch + } + // iterate over the container registries and generate any kubernetes secrets + for _, containerRegistry := range buildValues.ContainerRegistry { + additionalLabels := map[string]string{} + additionalAnnotations := map[string]string{} + + additionalLabels["app.kubernetes.io/name"] = containerRegistry.Name + additionalLabels["app.kubernetes.io/instance"] = "internal-registry-secret" + additionalLabels["lagoon.sh/template"] = fmt.Sprintf("internal-registry-secret-%s", "0.1.0") + + irs := &corev1.Secret{ + TypeMeta: metav1.TypeMeta{ + Kind: "Secret", + APIVersion: corev1.SchemeGroupVersion.Version, + }, + ObjectMeta: metav1.ObjectMeta{ + Name: containerRegistry.SecretName, + }, + Type: corev1.SecretTypeDockerConfigJson, + StringData: map[string]string{ + ".dockerconfigjson": base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf(`{"auths":{"%s":{"username":"%s","password":"%s","auth":"%s"}}}`, + containerRegistry.URL, + containerRegistry.Username, + containerRegistry.Password, + base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", containerRegistry.Username, containerRegistry.Password)))))), + }, + } + + labelsCopy := &map[string]string{} + helpers.DeepCopy(labels, labelsCopy) + annotationsCopy := &map[string]string{} + helpers.DeepCopy(annotations, annotationsCopy) + + for key, value := range additionalLabels { + (*labelsCopy)[key] = value + } + // add any additional annotations + for key, value := range additionalAnnotations { + (*annotationsCopy)[key] = value + } + irs.ObjectMeta.Labels = *labelsCopy + irs.ObjectMeta.Annotations = *annotationsCopy + // validate any annotations + if err := apivalidation.ValidateAnnotations(irs.ObjectMeta.Annotations, nil); err != nil { + if len(err) != 0 { + return nil, fmt.Errorf("the annotations for %s are not valid: %v", containerRegistry.Name, err) + } + } + // validate any labels + if err := metavalidation.ValidateLabels(irs.ObjectMeta.Labels, nil); err != nil { + if len(err) != 0 { + return nil, fmt.Errorf("the labels for %s are not valid: %v", containerRegistry.Name, err) + } + } + // check length of labels + err := helpers.CheckLabelLength(irs.ObjectMeta.Labels) + if err != nil { + return nil, err + } + + // end registry secret template + result = append(result, *irs) + } + return result, nil +} diff --git a/internal/templating/registrysecret/registrysecret_test.go b/internal/templating/registrysecret/registrysecret_test.go new file mode 100644 index 00000000..b8b39294 --- /dev/null +++ b/internal/templating/registrysecret/registrysecret_test.go @@ -0,0 +1,90 @@ +package registrysecret + +import ( + "os" + "reflect" + "testing" + + "github.com/andreyvit/diff" + "github.com/uselagoon/build-deploy-tool/internal/generator" + "sigs.k8s.io/yaml" +) + +func TestGenerateRegistrySecretTemplate(t *testing.T) { + type args struct { + buildValues generator.BuildValues + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + { + name: "test1", + 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", + DBaaSEnvironment: "development", + }, + { + Name: "myservice-po", + OverrideName: "myservice-po", + Type: "basic", + DBaaSEnvironment: "development", + ServicePort: 8080, + }, + }, + ContainerRegistry: []generator.ContainerRegistry{ + { + Name: "secret1", + SecretName: "internal-registry-secret-secret1", + Username: "username", + Password: "password", + URL: "my.registry.example.com", + }, + }, + }, + }, + want: "test-resources/registry-secret1.yaml", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GenerateRegistrySecretTemplate(tt.args.buildValues) + if (err != nil) != tt.wantErr { + t.Errorf("GenerateRegistrySecretTemplate() error = %v, wantErr %v", err, tt.wantErr) + return + } + r1, err := os.ReadFile(tt.want) + if err != nil { + t.Errorf("couldn't read file %v: %v", tt.want, err) + } + separator := []byte("---\n") + var result []byte + for _, d := range got { + secretBytes, err := yaml.Marshal(d) + if err != nil { + t.Errorf("couldn't generate template %v", err) + } + restoreResult := append(separator[:], secretBytes[:]...) + result = append(result, restoreResult[:]...) + } + if !reflect.DeepEqual(string(result), string(r1)) { + t.Errorf("GenerateRegistrySecretTemplate() = \n%v", diff.LineDiff(string(r1), string(result))) + } + }) + } +} diff --git a/internal/templating/registrysecret/test-resources/registry-secret1.yaml b/internal/templating/registrysecret/test-resources/registry-secret1.yaml new file mode 100644 index 00000000..c1da97fd --- /dev/null +++ b/internal/templating/registrysecret/test-resources/registry-secret1.yaml @@ -0,0 +1,21 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + annotations: + lagoon.sh/branch: environment-name + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: internal-registry-secret + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: secret1 + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-name + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/template: internal-registry-secret-0.1.0 + name: internal-registry-secret-secret1 +stringData: + .dockerconfigjson: eyJhdXRocyI6eyJteS5yZWdpc3RyeS5leGFtcGxlLmNvbSI6eyJ1c2VybmFtZSI6InVzZXJuYW1lIiwicGFzc3dvcmQiOiJwYXNzd29yZCIsImF1dGgiOiJkWE5sY201aGJXVTZjR0Z6YzNkdmNtUT0ifX19 +type: kubernetes.io/dockerconfigjson diff --git a/internal/templating/services/templates_cronjob.go b/internal/templating/services/templates_cronjob.go index b37d597b..9ecea26b 100644 --- a/internal/templating/services/templates_cronjob.go +++ b/internal/templating/services/templates_cronjob.go @@ -254,11 +254,16 @@ func GenerateCronjobTemplate( // end set up any volumes this cronjob can use - // handle any image pull secrets - pullsecrets := []corev1.LocalObjectReference{} - for _, pullsecret := range buildValues.ImagePullSecrets { + // handle any image pull secrets, add the default one first + pullsecrets := []corev1.LocalObjectReference{ + { + Name: generator.DefaultImagePullSecret, + }, + } + // then consume any from the custom provided container registries + for _, pullsecret := range buildValues.ContainerRegistry { pullsecrets = append(pullsecrets, corev1.LocalObjectReference{ - Name: pullsecret.Name, + Name: pullsecret.SecretName, }) } cronjob.Spec.JobTemplate.Spec.Template.Spec.ImagePullSecrets = pullsecrets diff --git a/internal/templating/services/templates_cronjob_test.go b/internal/templating/services/templates_cronjob_test.go index a5226518..1abc686c 100644 --- a/internal/templating/services/templates_cronjob_test.go +++ b/internal/templating/services/templates_cronjob_test.go @@ -33,11 +33,6 @@ func TestGenerateCronjobTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, ImageReferences: map[string]string{ "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", "myservice-persist": "harbor.example.com/example-project/environment-name/myservice-persistent@latest", diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index e671b70f..b2f83606 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -262,11 +262,16 @@ func GenerateDeploymentTemplate( // end set up any volumes this deployment can use - // handle any image pull secrets - pullsecrets := []corev1.LocalObjectReference{} - for _, pullsecret := range buildValues.ImagePullSecrets { + // handle any image pull secrets, add the default one first + pullsecrets := []corev1.LocalObjectReference{ + { + Name: generator.DefaultImagePullSecret, + }, + } + // then consume any from the custom provided container registries + for _, pullsecret := range buildValues.ContainerRegistry { pullsecrets = append(pullsecrets, corev1.LocalObjectReference{ - Name: pullsecret.Name, + Name: pullsecret.SecretName, }) } deployment.Spec.Template.Spec.ImagePullSecrets = pullsecrets diff --git a/internal/templating/services/templates_deployment_test.go b/internal/templating/services/templates_deployment_test.go index f348a0c6..2665af26 100644 --- a/internal/templating/services/templates_deployment_test.go +++ b/internal/templating/services/templates_deployment_test.go @@ -35,13 +35,8 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, - GitSHA: "0", - ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", ImageReferences: map[string]string{ "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", "myservice-po": "harbor.example.com/example-project/environment-name/myservice-po@latest", @@ -131,11 +126,6 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, FeatureFlags: map[string]bool{ "rootlessworkloads": true, }, @@ -199,13 +189,8 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, - GitSHA: "0", - ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", ImageReferences: map[string]string{ "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", "myservice-persist": "harbor.example.com/example-project/environment-name/myservice-persist@latest", @@ -242,13 +227,8 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, - GitSHA: "0", - ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", ImageReferences: map[string]string{ "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", }, @@ -276,13 +256,8 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, - GitSHA: "0", - ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", ImageReferences: map[string]string{ "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", "myservice-size": "harbor.example.com/example-project/environment-name/myservice-size@latest", @@ -319,13 +294,8 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, - GitSHA: "0", - ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", ImageReferences: map[string]string{ "myservice": "harbor.example.com/example-project/environment-name/myservice@latest", "myservice-size": "harbor.example.com/example-project/environment-name/myservice-size@latest", @@ -362,13 +332,8 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, - GitSHA: "0", - ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", ImageReferences: map[string]string{ "myservice-po": "harbor.example.com/example-project/environment-name/myservice-po@latest", }, @@ -414,13 +379,8 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, - GitSHA: "0", - ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", + GitSHA: "0", + ConfigMapSha: "32bf1359ac92178c8909f0ef938257b477708aa0d78a5a15ad7c2d7919adf273", ImageReferences: map[string]string{ "solr": "harbor.example.com/example-project/environment-name/solr@latest", }, @@ -448,11 +408,6 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, Resources: generator.Resources{ Limits: generator.ResourceLimits{ Memory: "16Gi", @@ -509,12 +464,7 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, - ImageCache: "imagecache.example.com/", + ImageCache: "imagecache.example.com/", FeatureFlags: map[string]bool{ "rootlessworkloads": true, }, @@ -579,11 +529,6 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, PodSecurityContext: generator.PodSecurityContext{ RunAsGroup: 0, RunAsUser: 10000, @@ -624,11 +569,6 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, PodSecurityContext: generator.PodSecurityContext{ RunAsGroup: 0, RunAsUser: 10000, @@ -669,11 +609,6 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, PodSecurityContext: generator.PodSecurityContext{ RunAsGroup: 0, RunAsUser: 10000, @@ -714,11 +649,6 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, PodSecurityContext: generator.PodSecurityContext{ RunAsGroup: 0, RunAsUser: 10000, @@ -759,11 +689,6 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, PodSecurityContext: generator.PodSecurityContext{ RunAsGroup: 0, RunAsUser: 10000, @@ -804,11 +729,6 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, PodSecurityContext: generator.PodSecurityContext{ RunAsGroup: 0, RunAsUser: 10000, @@ -843,11 +763,6 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, PodSecurityContext: generator.PodSecurityContext{ RunAsGroup: 0, RunAsUser: 10000, @@ -882,11 +797,6 @@ func TestGenerateDeploymentTemplate(t *testing.T) { LagoonVersion: "v2.x.x", Kubernetes: "generator.local", Branch: "environment-name", - ImagePullSecrets: []generator.ImagePullSecrets{ - { - Name: "lagoon-internal-registry-secret", - }, - }, PodSecurityContext: generator.PodSecurityContext{ RunAsGroup: 0, RunAsUser: 10000, diff --git a/internal/testdata/basic/lagoon.container-registry.yml b/internal/testdata/basic/lagoon.container-registry.yml new file mode 100644 index 00000000..d85dc5e8 --- /dev/null +++ b/internal/testdata/basic/lagoon.container-registry.yml @@ -0,0 +1,16 @@ +docker-compose-yaml: internal/testdata/basic/docker-compose.yml + +container-registries: + my-custom-registry: + username: myownregistryuser + password: REGISTRY_PASSWORD + url: my.own.registry.com + +environment_variables: + git_sha: "true" + +environments: + main: + routes: + - node: + - example.com diff --git a/internal/testdata/basic/service-templates/service1/deployment-node.yaml b/internal/testdata/basic/service-templates/service1/deployment-node.yaml index 3380df93..da12702c 100644 --- a/internal/testdata/basic/service-templates/service1/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service1/deployment-node.yaml @@ -81,7 +81,7 @@ spec: memory: 100M enableServiceLinks: false imagePullSecrets: - - name: lagoon-private-registry-custom-secret - name: lagoon-internal-registry-secret + - name: lagoon-private-registry-my-custom-registry priorityClassName: lagoon-priority-production status: {} diff --git a/internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-custom-registry.yaml b/internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-custom-registry.yaml new file mode 100644 index 00000000..0d7e8057 --- /dev/null +++ b/internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-custom-registry.yaml @@ -0,0 +1,21 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: internal-registry-secret + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: my-custom-registry + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/template: internal-registry-secret-0.1.0 + name: lagoon-private-registry-my-custom-registry +stringData: + .dockerconfigjson: eyJhdXRocyI6eyJteS5vd24ucmVnaXN0cnkuY29tIjp7InVzZXJuYW1lIjoibXlvd25yZWdpc3RyeXVzZXIiLCJwYXNzd29yZCI6IlJFR0lTVFJZX1BBU1NXT1JEIiwiYXV0aCI6ImJYbHZkMjV5WldkcGMzUnllWFZ6WlhJNlVrVkhTVk5VVWxsZlVFRlRVMWRQVWtRPSJ9fX0= +type: kubernetes.io/dockerconfigjson diff --git a/internal/testdata/basic/service-templates/service6/deployment-node.yaml b/internal/testdata/basic/service-templates/service6/deployment-node.yaml index 8d979237..c716a5d1 100644 --- a/internal/testdata/basic/service-templates/service6/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service6/deployment-node.yaml @@ -85,8 +85,8 @@ spec: readOnly: true enableServiceLinks: false imagePullSecrets: - - name: lagoon-private-registry-custom-secret - name: lagoon-internal-registry-secret + - name: lagoon-private-registry-my-custom-registry priorityClassName: lagoon-priority-production volumes: - name: dynamic-insights-token diff --git a/internal/testdata/basic/service-templates/service6/lagoon-private-registry-my-custom-registry.yaml b/internal/testdata/basic/service-templates/service6/lagoon-private-registry-my-custom-registry.yaml new file mode 100644 index 00000000..0d7e8057 --- /dev/null +++ b/internal/testdata/basic/service-templates/service6/lagoon-private-registry-my-custom-registry.yaml @@ -0,0 +1,21 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: internal-registry-secret + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: my-custom-registry + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/template: internal-registry-secret-0.1.0 + name: lagoon-private-registry-my-custom-registry +stringData: + .dockerconfigjson: eyJhdXRocyI6eyJteS5vd24ucmVnaXN0cnkuY29tIjp7InVzZXJuYW1lIjoibXlvd25yZWdpc3RyeXVzZXIiLCJwYXNzd29yZCI6IlJFR0lTVFJZX1BBU1NXT1JEIiwiYXV0aCI6ImJYbHZkMjV5WldkcGMzUnllWFZ6WlhJNlVrVkhTVk5VVWxsZlVFRlRVMWRQVWtRPSJ9fX0= +type: kubernetes.io/dockerconfigjson diff --git a/internal/testdata/complex/lagoon.varnish2.yml b/internal/testdata/complex/lagoon.varnish2.yml index 77fa431a..71d4cdd5 100644 --- a/internal/testdata/complex/lagoon.varnish2.yml +++ b/internal/testdata/complex/lagoon.varnish2.yml @@ -3,6 +3,12 @@ docker-compose-yaml: internal/testdata/complex/docker-compose.varnish2.yml project: example-com +container-registries: + my-custom-registry: + username: registry_user + password: REGISTRY_PASSWORD + url: registry1.example.com + environments: main: routes: From 6d22fbc209a0a78d43af16e208a1a81e7bb0f813 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 13 Feb 2024 19:34:49 +1100 Subject: [PATCH 64/92] refactor: modify the bash so that any remaining calls to .lagoon.yml are performed AFTER the initial validation --- legacy/build-deploy-docker-compose.sh | 85 ++++++++++--- legacy/build-deploy.sh | 170 +------------------------- 2 files changed, 76 insertions(+), 179 deletions(-) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index cef23b47..d09aeeba 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -325,6 +325,26 @@ else echo "lagoon-linter found no issues with the .lagoon.yml file" fi +################## +# build deploy-tool can collect this value now from the lagoon.yml file +# this means further use of `LAGOON_GIT_SHA` can eventually be +# completely handled with build-deploy-tool wherever this value could be consumed +# this logic can then just be replaced entirely with a single export so that the build-deploy-tool +# will know what the value is, and performs the switch based on what the lagoon.yml provides +# this is retained for now until the remaining functionality that uses it is moved to the build-deploy-tool +# +# export LAGOON_GIT_SHA=`git rev-parse HEAD` +# +INJECT_GIT_SHA=$(cat .lagoon.yml | shyaml get-value environment_variables.git_sha false) +if [ "$INJECT_GIT_SHA" == "true" ] +then + # export this so the build-deploy-tool can read it + export LAGOON_GIT_SHA=`git rev-parse HEAD` +else + export LAGOON_GIT_SHA="0000000000000000000000000000000000000000" +fi +################## + currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "lagoonYmlValidation" ".lagoon.yml Validation" "false" previousStepEnd=${currentStepEnd} @@ -650,22 +670,8 @@ set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${buildStartTime}" "${currentStepEnd}" "${NAMESPACE}" "configureVars" "Configure Variables" "false" previousStepEnd=${currentStepEnd} -beginBuildStep "Image Builds" "buildingImages" -set -x -############################################## -### CACHE IMAGE LIST GENERATION -############################################## - -LAGOON_CACHE_BUILD_ARGS=() -readarray LAGOON_CACHE_BUILD_ARGS < <(kubectl -n ${NAMESPACE} get deployments -o yaml -l 'lagoon.sh/service' | yq e '.items[].spec.template.spec.containers[].image | capture("^(?P.+\/.+\/.+\/(?P.+)\@.*)$") | "LAGOON_CACHE_" + .name + "=" + .image' -) - - - -############################################## -### BUILD IMAGES -############################################## +beginBuildStep "Container Regstiry Login" "registryLogin" -set +x # reduce noise in build logs # Get the pre-rollout and post-rollout vars if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then LAGOON_PREROLLOUT_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_PREROLLOUT_DISABLED") | "\(.value)"')) @@ -686,6 +692,45 @@ set -x # seed all the push images for use later on, push images relate to images that may not be built by this build # but are required from somewhere else like a promote environment or from another registry ENVIRONMENT_IMAGE_BUILD_DATA=$(build-deploy-tool identify image-builds) + +set +x # reduce noise in build logs +# log in to any container registries before building or pulling images +for PRIVATE_CONTAINER_REGISTRY in $(echo "$ENVIRONMENT_IMAGE_BUILD_DATA" | jq -c '.containerRegistries[]') +do + PRIVATE_CONTAINER_REGISTRY_URL=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.url // false') + PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.username // false') + PRIVATE_CONTAINER_REGISTRY_USERNAME_SOURCE=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.usernameSource // false') + PRIVATE_REGISTRY_CREDENTIAL=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.password // false') + PRIVATE_REGISTRY_CREDENTIAL_SOURCE=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.passwordSource // false') + if [ $PRIVATE_CONTAINER_REGISTRY_URL != "false" ]; then + echo "Attempting to log in to $PRIVATE_CONTAINER_REGISTRY_URL with user $PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME from $PRIVATE_CONTAINER_REGISTRY_USERNAME_SOURCE" + echo "Using password sourced from $PRIVATE_REGISTRY_CREDENTIAL_SOURCE" + docker login --username $PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME --password $PRIVATE_REGISTRY_CREDENTIAL $PRIVATE_CONTAINER_REGISTRY_URL + else + echo "Attempting to log in to docker hub with user $PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME from $PRIVATE_CONTAINER_REGISTRY_USERNAME_SOURCE" + echo "Using password sourced from $PRIVATE_REGISTRY_CREDENTIAL_SOURCE" + docker login --username $PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME --password $PRIVATE_REGISTRY_CREDENTIAL + fi +done + +currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" +patchBuildStep "${buildStartTime}" "${buildStartTime}" "${currentStepEnd}" "${NAMESPACE}" "registryLogin" "Container Regstiry Login" "false" +previousStepEnd=${currentStepEnd} +beginBuildStep "Image Builds" "buildingImages" +set -x + +############################################## +### CACHE IMAGE LIST GENERATION +############################################## + +LAGOON_CACHE_BUILD_ARGS=() +readarray LAGOON_CACHE_BUILD_ARGS < <(kubectl -n ${NAMESPACE} get deployments -o yaml -l 'lagoon.sh/service' | yq e '.items[].spec.template.spec.containers[].image | capture("^(?P.+\/.+\/.+\/(?P.+)\@.*)$") | "LAGOON_CACHE_" + .name + "=" + .image' -) + + +############################################## +### BUILD IMAGES +############################################## + for IMAGE_BUILD_DATA in $(echo "$ENVIRONMENT_IMAGE_BUILD_DATA" | jq -c '.images[]') do SERVICE_NAME=$(echo "$IMAGE_BUILD_DATA" | jq -r '.name // false') @@ -1479,6 +1524,16 @@ done # handle dynamic secret collection here, @TODO this will go into the state collector eventually export DYNAMIC_SECRETS=$(kubectl -n ${NAMESPACE} get secrets -l lagoon.sh/dynamic-secret -o json | jq -r '[.items[] | .metadata.name] | join(",")') +# delete any custom private registry secrets, they will get re-created by the lagoon-services templates +EXISTING_REGISTRY_SECRETS=$(kubectl -n ${NAMESPACE} get secrets --no-headers | cut -d " " -f 1 | xargs) +for EXISTING_REGISTRY_SECRET in ${EXISTING_REGISTRY_SECRETS}; do + if [[ "${EXISTING_REGISTRY_SECRET}" =~ "lagoon-private-registry-" ]]; then + if kubectl -n ${NAMESPACE} get secret ${EXISTING_REGISTRY_SECRET} &> /dev/null; then + kubectl -n ${NAMESPACE} delete secret ${EXISTING_REGISTRY_SECRET} + fi + fi +done + echo "=== BEGIN deployment template for services ===" LAGOON_SERVICES_YAML_FOLDER="/kubectl-build-deploy/lagoon/service-deployments" mkdir -p $LAGOON_SERVICES_YAML_FOLDER diff --git a/legacy/build-deploy.sh b/legacy/build-deploy.sh index 2138a134..98c11b74 100755 --- a/legacy/build-deploy.sh +++ b/legacy/build-deploy.sh @@ -37,35 +37,9 @@ if [ ! -f .lagoon.yml ]; then echo "no .lagoon.yml file found"; exit 1; fi -################## -# build deploy-tool can collect this value now from the lagoon.yml file -# this means further use of `LAGOON_GIT_SHA` can eventually be -# completely handled with build-deploy-tool wherever this value could be consumed -# this logic can then just be replaced entirely with a single export so that the build-deploy-tool -# will know what the value is, and performs the switch based on what the lagoon.yml provides -# this is retained for now until the remaining functionality that uses it is moved to the build-deploy-tool -# -# export LAGOON_GIT_SHA=`git rev-parse HEAD` -# -INJECT_GIT_SHA=$(cat .lagoon.yml | shyaml get-value environment_variables.git_sha false) -if [ "$INJECT_GIT_SHA" == "true" ] -then - # export this so the build-deploy-tool can read it - export LAGOON_GIT_SHA=`git rev-parse HEAD` -else - export LAGOON_GIT_SHA="0000000000000000000000000000000000000000" -fi -################## - echo -e "##############################################\nBEGIN Kubernetes and Container Registry Setup\n##############################################" sleep 0.5s -REGISTRY_SECRETS=() -PRIVATE_REGISTRY_COUNTER=0 -PRIVATE_REGISTRY_URLS=() -PRIVATE_DOCKER_HUB_REGISTRY=0 -PRIVATE_EXTERNAL_REGISTRY=0 - set +x # reduce noise in build logs if [[ -f "/var/run/secrets/kubernetes.io/serviceaccount/token" ]]; then DEPLOYER_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) @@ -83,15 +57,16 @@ kubectl config set-cluster kubernetes.default.svc --server=https://kubernetes.de kubectl config set-context default/lagoon/kubernetes.default.svc --user=lagoon/kubernetes.default.svc --namespace="${NAMESPACE}" --cluster=kubernetes.default.svc kubectl config use-context default/lagoon/kubernetes.default.svc +# log in to the provided registry if details are provided if [ ! -z ${INTERNAL_REGISTRY_URL} ] ; then echo "Creating secret for internal registry access" if [ ! -z ${INTERNAL_REGISTRY_USERNAME} ] && [ ! -z ${INTERNAL_REGISTRY_PASSWORD} ] ; then echo "docker login -u '${INTERNAL_REGISTRY_USERNAME}' -p '${INTERNAL_REGISTRY_PASSWORD}' ${INTERNAL_REGISTRY_URL}" | /bin/bash - # create lagoon-internal-registry-secret if it does not exist yet - if ! kubectl -n ${NAMESPACE} get secret lagoon-internal-registry-secret &> /dev/null; then - kubectl create secret docker-registry lagoon-internal-registry-secret --docker-server=${INTERNAL_REGISTRY_URL} --docker-username=${INTERNAL_REGISTRY_USERNAME} --docker-password=${INTERNAL_REGISTRY_PASSWORD} --dry-run -o yaml | kubectl apply -f - - fi - REGISTRY_SECRETS+=("lagoon-internal-registry-secret") + # create lagoon-internal-registry-secret if it does not exist yet + # TODO: remove this, the secret is created by the remote-controller, builds only need to log in to it now + # if ! kubectl -n ${NAMESPACE} get secret lagoon-internal-registry-secret &> /dev/null; then + # kubectl create secret docker-registry lagoon-internal-registry-secret --docker-server=${INTERNAL_REGISTRY_URL} --docker-username=${INTERNAL_REGISTRY_USERNAME} --docker-password=${INTERNAL_REGISTRY_PASSWORD} --dry-run -o yaml | kubectl apply -f - + # fi REGISTRY=$INTERNAL_REGISTRY_URL # This will handle pointing Lagoon at the correct registry for non local builds echo "Set internal registry secrets for token ${INTERNAL_REGISTRY_USERNAME} in ${REGISTRY}" else @@ -104,139 +79,6 @@ if [ ! -z ${INTERNAL_REGISTRY_URL} ] ; then fi fi -############################################## -### PRIVATE REGISTRY LOGINS -############################################## -# we want to be able to support private container registries -# grab all the container-registries that are defined in the `.lagoon.yml` file -PRIVATE_CONTAINER_REGISTRIES=($(cat .lagoon.yml | shyaml keys container-registries 2> /dev/null || echo "")) -if [ ! -z $PRIVATE_CONTAINER_REGISTRIES ]; then - echo -e "##############################################\nBEGIN Custom Container Registries Setup\n##############################################" - sleep 0.5s -fi -for PRIVATE_CONTAINER_REGISTRY in "${PRIVATE_CONTAINER_REGISTRIES[@]}" -do - echo "Checking details for $PRIVATE_CONTAINER_REGISTRY"; - # check if a url is set, if none set proceed against docker hub - PRIVATE_CONTAINER_REGISTRY_URL=$(cat .lagoon.yml | shyaml get-value container-registries.$PRIVATE_CONTAINER_REGISTRY.url false) - if [ $PRIVATE_CONTAINER_REGISTRY_URL == "false" ]; then - echo "No 'url' defined for registry $PRIVATE_CONTAINER_REGISTRY, will proceed against docker hub"; - fi - # check the username and passwords are defined in yaml - PRIVATE_CONTAINER_REGISTRY_USERNAME=$(cat .lagoon.yml | shyaml get-value container-registries.$PRIVATE_CONTAINER_REGISTRY.username false) - if [ $PRIVATE_CONTAINER_REGISTRY_USERNAME == "false" ]; then - echo "No 'username' defined for registry $PRIVATE_CONTAINER_REGISTRY"; exit 1; - fi - if [ $PRIVATE_CONTAINER_REGISTRY_USERNAME != "false" ]; then - # check if we have an override password defined anywhere in the api - PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME="" - PRIVATE_CONTAINER_REGISTRY_USERNAME_OVERRIDE_KEY="REGISTRY_${PRIVATE_CONTAINER_REGISTRY}_USERNAME" - - if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then - TEMP_PRIVATE_REGISTRY_CREDENTIAL_USERNAME=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "container_registry" and .name == "'$PRIVATE_CONTAINER_REGISTRY_USERNAME_OVERRIDE_KEY'") | "\(.value)"')) - if [ ! -z "$TEMP_PRIVATE_REGISTRY_CREDENTIAL_USERNAME" ]; then - PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME=$TEMP_PRIVATE_REGISTRY_CREDENTIAL_USERNAME - PRIVATE_CONTAINER_REGISTRY_USERNAME_SOURCE="Lagoon API project variable $PRIVATE_CONTAINER_REGISTRY_USERNAME_OVERRIDE_KEY" - fi - fi - if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then - TEMP_PRIVATE_REGISTRY_CREDENTIAL_USERNAME=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.scope == "container_registry" and .name == "'$PRIVATE_CONTAINER_REGISTRY_USERNAME_OVERRIDE_KEY'") | "\(.value)"')) - if [ ! -z "$TEMP_PRIVATE_REGISTRY_CREDENTIAL_USERNAME" ]; then - PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME=$TEMP_PRIVATE_REGISTRY_CREDENTIAL_USERNAME - PRIVATE_CONTAINER_REGISTRY_USERNAME_SOURCE="Lagoon API environment variable $PRIVATE_CONTAINER_REGISTRY_USERNAME_OVERRIDE_KEY" - fi - fi - - if [ -z $PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME ]; then - #if no password defined in the lagoon api, pass the one in `.lagoon.yml` as a password - PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME=$PRIVATE_CONTAINER_REGISTRY_USERNAME - PRIVATE_CONTAINER_REGISTRY_USERNAME_SOURCE=".lagoon.yml" - fi - fi - PRIVATE_CONTAINER_REGISTRY_PASSWORD=$(cat .lagoon.yml | shyaml get-value container-registries.$PRIVATE_CONTAINER_REGISTRY.password false) - if [[ $PRIVATE_CONTAINER_REGISTRY_PASSWORD == "false" ]]; then - echo "No 'password' defined for registry $PRIVATE_CONTAINER_REGISTRY"; exit 1; - fi - # if we have everything we need, we can proceed to logging in - if [ $PRIVATE_CONTAINER_REGISTRY_PASSWORD != "false" ]; then - PRIVATE_REGISTRY_CREDENTIAL="" - # check if we have a password defined anywhere in the api first - if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then - TEMP_PRIVATE_REGISTRY_CREDENTIAL=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "container_registry" and .name == "'$PRIVATE_CONTAINER_REGISTRY_PASSWORD'") | "\(.value)"')) - if [ ! -z "$TEMP_PRIVATE_REGISTRY_CREDENTIAL" ]; then - PRIVATE_REGISTRY_CREDENTIAL=$TEMP_PRIVATE_REGISTRY_CREDENTIAL - PRIVATE_REGISTRY_CREDENTIAL_SOURCE="Lagoon API project variable $PRIVATE_CONTAINER_REGISTRY_PASSWORD" - fi - fi - if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then - TEMP_PRIVATE_REGISTRY_CREDENTIAL=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.scope == "container_registry" and .name == "'$PRIVATE_CONTAINER_REGISTRY_PASSWORD'") | "\(.value)"')) - if [ ! -z "$TEMP_PRIVATE_REGISTRY_CREDENTIAL" ]; then - PRIVATE_REGISTRY_CREDENTIAL=$TEMP_PRIVATE_REGISTRY_CREDENTIAL - PRIVATE_REGISTRY_CREDENTIAL_SOURCE="Lagoon API environment variable $PRIVATE_CONTAINER_REGISTRY_PASSWORD" - fi - fi - - # check if we have an override password defined anywhere in the api - PRIVATE_CONTAINER_REGISTRY_OVERRIDE_KEY="REGISTRY_${PRIVATE_CONTAINER_REGISTRY}_PASSWORD" - - if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then - TEMP_PRIVATE_REGISTRY_CREDENTIAL=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "container_registry" and .name == "'$PRIVATE_CONTAINER_REGISTRY_OVERRIDE_KEY'") | "\(.value)"')) - if [ ! -z "$TEMP_PRIVATE_REGISTRY_CREDENTIAL" ]; then - PRIVATE_REGISTRY_CREDENTIAL=$TEMP_PRIVATE_REGISTRY_CREDENTIAL - PRIVATE_REGISTRY_CREDENTIAL_SOURCE="Lagoon API project variable $PRIVATE_CONTAINER_REGISTRY_OVERRIDE_KEY" - fi - fi - if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then - TEMP_PRIVATE_REGISTRY_CREDENTIAL=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.scope == "container_registry" and .name == "'$PRIVATE_CONTAINER_REGISTRY_OVERRIDE_KEY'") | "\(.value)"')) - if [ ! -z "$TEMP_PRIVATE_REGISTRY_CREDENTIAL" ]; then - PRIVATE_REGISTRY_CREDENTIAL=$TEMP_PRIVATE_REGISTRY_CREDENTIAL - PRIVATE_REGISTRY_CREDENTIAL_SOURCE="Lagoon API environment variable $PRIVATE_CONTAINER_REGISTRY_OVERRIDE_KEY" - fi - fi - - if [ -z $PRIVATE_REGISTRY_CREDENTIAL ]; then - #if no password defined in the lagoon api, pass the one in `.lagoon.yml` as a password - PRIVATE_REGISTRY_CREDENTIAL=$PRIVATE_CONTAINER_REGISTRY_PASSWORD - PRIVATE_REGISTRY_CREDENTIAL_SOURCE=".lagoon.yml (we recommend using an environment variable, see the docs on container-registries for more information)" - fi - if [ -z "$PRIVATE_REGISTRY_CREDENTIAL" ]; then - echo -e "A private container registry was defined in the .lagoon.yml file, but no password could be found in either the .lagoon.yml or in the Lagoon API\n\nPlease check if the password has been set correctly." - exit 1 - fi - if [ $PRIVATE_CONTAINER_REGISTRY_URL != "false" ]; then - echo "Attempting to log in to $PRIVATE_CONTAINER_REGISTRY_URL with user $PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME from $PRIVATE_CONTAINER_REGISTRY_USERNAME_SOURCE" - echo "Using password sourced from $PRIVATE_REGISTRY_CREDENTIAL_SOURCE" - docker login --username $PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME --password $PRIVATE_REGISTRY_CREDENTIAL $PRIVATE_CONTAINER_REGISTRY_URL - kubectl create secret docker-registry "lagoon-private-registry-${PRIVATE_REGISTRY_COUNTER}-secret" --docker-server=$PRIVATE_CONTAINER_REGISTRY_URL --docker-username=$PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME --docker-password=$PRIVATE_REGISTRY_CREDENTIAL --dry-run -o yaml | kubectl apply -f - - REGISTRY_SECRETS+=("lagoon-private-registry-${PRIVATE_REGISTRY_COUNTER}-secret") - PRIVATE_REGISTRY_URLS+=($PRIVATE_CONTAINER_REGISTRY_URL) - PRIVATE_EXTERNAL_REGISTRY=1 - let ++PRIVATE_REGISTRY_COUNTER - else - echo "Attempting to log in to docker hub with user $PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME from $PRIVATE_CONTAINER_REGISTRY_USERNAME_SOURCE" - echo "Using password sourced from $PRIVATE_REGISTRY_CREDENTIAL_SOURCE" - docker login --username $PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME --password $PRIVATE_REGISTRY_CREDENTIAL - kubectl create secret docker-registry "lagoon-private-registry-${PRIVATE_REGISTRY_COUNTER}-secret" --docker-server="https://index.docker.io/v1/" --docker-username=$PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME --docker-password=$PRIVATE_REGISTRY_CREDENTIAL --dry-run -o yaml | kubectl apply -f - - REGISTRY_SECRETS+=("lagoon-private-registry-${PRIVATE_REGISTRY_COUNTER}-secret") - PRIVATE_REGISTRY_URLS+=("") - PRIVATE_DOCKER_HUB_REGISTRY=1 - let ++PRIVATE_REGISTRY_COUNTER - fi - fi -done -if [ ! -z $PRIVATE_CONTAINER_REGISTRIES ]; then - if [ $PRIVATE_REGISTRY_COUNTER -gt 0 ]; then - if [ $PRIVATE_EXTERNAL_REGISTRY ]; then - # export the external registry urls so that the build-deploy-tool can consume it later on - export EXTERNAL_REGISTRY_URLS=$(echo ${PRIVATE_REGISTRY_URLS[*]} | tr ' ' ,) - # export all the external registry secret names so that the build-deploy-tool can consume it later on - export EXTERNAL_REGISTRY_SECRETS=$(echo ${REGISTRY_SECRETS[*]} | tr ' ' ,) - fi - fi - echo -e "##############################################\nEND Custom Container Registries Setup\n##############################################" - sleep 0.5s -fi - echo -e "\n\n##############################################\nStart Build Process\n##############################################" set -x . /kubectl-build-deploy/build-deploy-docker-compose.sh From 86288a3017d0ac439d4f6464512aa92b5d249788 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 13 Feb 2024 19:52:03 +1100 Subject: [PATCH 65/92] test: fix after merge conflicts --- cmd/template_backups_test.go | 6 +++--- internal/testdata/node/docker-compose.nostorage.yml | 2 +- internal/testdata/node/lagoon.nostorage.yml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/template_backups_test.go b/cmd/template_backups_test.go index cf53f1cd..cb47cfe0 100644 --- a/cmd/template_backups_test.go +++ b/cmd/template_backups_test.go @@ -203,7 +203,7 @@ func TestBackupTemplateGeneration(t *testing.T) { EnvironmentName: "main", Branch: "main", K8UPVersion: "v2", - LagoonYAML: "../internal/testdata/node/lagoon.nostorage.yml", + LagoonYAML: "internal/testdata/node/lagoon.nostorage.yml", ProjectVariables: []lagoon.EnvironmentVariable{ { Name: "LAGOON_FEATURE_FLAG_IMAGECACHE_REGISTRY", @@ -214,7 +214,7 @@ func TestBackupTemplateGeneration(t *testing.T) { }, true), templatePath: "testdata/output", emptyDir: true, - want: "../internal/testdata/node/backup-templates/backup-7", + want: "internal/testdata/node/backup-templates/backup-7", }, } for _, tt := range tests { @@ -252,7 +252,7 @@ func TestBackupTemplateGeneration(t *testing.T) { } resultSize := 0 if !tt.emptyDir { - results, err = ioutil.ReadDir(tt.want) + results, err = os.ReadDir(tt.want) if err != nil { t.Errorf("couldn't read directory %v: %v", tt.want, err) } diff --git a/internal/testdata/node/docker-compose.nostorage.yml b/internal/testdata/node/docker-compose.nostorage.yml index 48a7c45b..e7f39fea 100644 --- a/internal/testdata/node/docker-compose.nostorage.yml +++ b/internal/testdata/node/docker-compose.nostorage.yml @@ -5,7 +5,7 @@ services: - amazeeio-network - default build: - context: . + context: internal/testdata/node/docker dockerfile: node.dockerfile labels: lagoon.type: node diff --git a/internal/testdata/node/lagoon.nostorage.yml b/internal/testdata/node/lagoon.nostorage.yml index 78c5f5f1..a8aceff9 100644 --- a/internal/testdata/node/lagoon.nostorage.yml +++ b/internal/testdata/node/lagoon.nostorage.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../internal/testdata/node/docker-compose.nostorage.yml +docker-compose-yaml: internal/testdata/node/docker-compose.nostorage.yml routes: autogenerate: From 7c8d358b4f58ec270970e41b2d58de80b515c68c Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 14 Feb 2024 13:29:44 +1100 Subject: [PATCH 66/92] fix: container registry login iterator, additional formatting --- legacy/build-deploy-docker-compose.sh | 28 +++++++++++++-------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 5197b685..5fa3c130 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -673,29 +673,27 @@ previousStepEnd=${currentStepEnd} beginBuildStep "Container Regstiry Login" "registryLogin" # Get the pre-rollout and post-rollout vars - if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then - LAGOON_PREROLLOUT_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_PREROLLOUT_DISABLED") | "\(.value)"')) - LAGOON_POSTROLLOUT_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_POSTROLLOUT_DISABLED") | "\(.value)"')) +if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then + LAGOON_PREROLLOUT_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_PREROLLOUT_DISABLED") | "\(.value)"')) + LAGOON_POSTROLLOUT_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_POSTROLLOUT_DISABLED") | "\(.value)"')) +fi +if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then + TEMP_LAGOON_PREROLLOUT_DISABLED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_PREROLLOUT_DISABLED") | "\(.value)"')) + TEMP_LAGOON_POSTROLLOUT_DISABLED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_POSTROLLOUT_DISABLED") | "\(.value)"')) + if [ ! -z $TEMP_LAGOON_PREROLLOUT_DISABLED ]; then + LAGOON_PREROLLOUT_DISABLED=$TEMP_LAGOON_PREROLLOUT_DISABLED fi - if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then - TEMP_LAGOON_PREROLLOUT_DISABLED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_PREROLLOUT_DISABLED") | "\(.value)"')) - TEMP_LAGOON_POSTROLLOUT_DISABLED=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_POSTROLLOUT_DISABLED") | "\(.value)"')) - if [ ! -z $TEMP_LAGOON_PREROLLOUT_DISABLED ]; then - LAGOON_PREROLLOUT_DISABLED=$TEMP_LAGOON_PREROLLOUT_DISABLED - fi - if [ ! -z $TEMP_LAGOON_POSTROLLOUT_DISABLED ]; then - LAGOON_POSTROLLOUT_DISABLED=$TEMP_LAGOON_POSTROLLOUT_DISABLED - fi + if [ ! -z $TEMP_LAGOON_POSTROLLOUT_DISABLED ]; then + LAGOON_POSTROLLOUT_DISABLED=$TEMP_LAGOON_POSTROLLOUT_DISABLED fi -set -x +fi # seed all the push images for use later on, push images relate to images that may not be built by this build # but are required from somewhere else like a promote environment or from another registry ENVIRONMENT_IMAGE_BUILD_DATA=$(build-deploy-tool identify image-builds) -set +x # reduce noise in build logs # log in to any container registries before building or pulling images -for PRIVATE_CONTAINER_REGISTRY in $(echo "$ENVIRONMENT_IMAGE_BUILD_DATA" | jq -c '.containerRegistries[]') +for PRIVATE_CONTAINER_REGISTRY in $(echo "$ENVIRONMENT_IMAGE_BUILD_DATA" | jq -c '.containerRegistries[]?') do PRIVATE_CONTAINER_REGISTRY_URL=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.url // false') PRIVATE_CONTAINER_REGISTRY_CREDENTIAL_USERNAME=$(echo "$PRIVATE_CONTAINER_REGISTRY" | jq -r '.username // false') From 23bb571a8dd1db8e562cbf2932f1338e16d047d4 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 14 Feb 2024 13:42:47 +1100 Subject: [PATCH 67/92] refactor: move container registry logins to login section --- legacy/build-deploy-docker-compose.sh | 25 +++++++++++++++++++------ legacy/build-deploy.sh | 10 +--------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 5fa3c130..6cc5dab3 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -666,12 +666,6 @@ do done -set +x -currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" -patchBuildStep "${buildStartTime}" "${buildStartTime}" "${currentStepEnd}" "${NAMESPACE}" "configureVars" "Configure Variables" "false" -previousStepEnd=${currentStepEnd} -beginBuildStep "Container Regstiry Login" "registryLogin" - # Get the pre-rollout and post-rollout vars if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then LAGOON_PREROLLOUT_DISABLED=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_PREROLLOUT_DISABLED") | "\(.value)"')) @@ -688,10 +682,29 @@ if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then fi fi +currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" +patchBuildStep "${buildStartTime}" "${buildStartTime}" "${currentStepEnd}" "${NAMESPACE}" "configureVars" "Configure Variables" "false" +previousStepEnd=${currentStepEnd} +beginBuildStep "Container Regstiry Login" "registryLogin" + # seed all the push images for use later on, push images relate to images that may not be built by this build # but are required from somewhere else like a promote environment or from another registry ENVIRONMENT_IMAGE_BUILD_DATA=$(build-deploy-tool identify image-builds) +# log in to the provided registry if details are provided +if [ ! -z ${INTERNAL_REGISTRY_URL} ] ; then + echo "Logging in to Lagoon main registry" + if [ ! -z ${INTERNAL_REGISTRY_USERNAME} ] && [ ! -z ${INTERNAL_REGISTRY_PASSWORD} ] ; then + echo "docker login -u '${INTERNAL_REGISTRY_USERNAME}' -p '${INTERNAL_REGISTRY_PASSWORD}' ${INTERNAL_REGISTRY_URL}" | /bin/bash + # create lagoon-internal-registry-secret if it does not exist yet + # TODO: remove this, the secret is created by the remote-controller, builds only need to log in to it now + # if ! kubectl -n ${NAMESPACE} get secret lagoon-internal-registry-secret &> /dev/null; then + # kubectl create secret docker-registry lagoon-internal-registry-secret --docker-server=${INTERNAL_REGISTRY_URL} --docker-username=${INTERNAL_REGISTRY_USERNAME} --docker-password=${INTERNAL_REGISTRY_PASSWORD} --dry-run -o yaml | kubectl apply -f - + # fi + echo "Set internal registry secrets for token ${INTERNAL_REGISTRY_USERNAME} in ${REGISTRY}" + fi +fi + # log in to any container registries before building or pulling images for PRIVATE_CONTAINER_REGISTRY in $(echo "$ENVIRONMENT_IMAGE_BUILD_DATA" | jq -c '.containerRegistries[]?') do diff --git a/legacy/build-deploy.sh b/legacy/build-deploy.sh index 98c11b74..964836e1 100755 --- a/legacy/build-deploy.sh +++ b/legacy/build-deploy.sh @@ -37,7 +37,7 @@ if [ ! -f .lagoon.yml ]; then echo "no .lagoon.yml file found"; exit 1; fi -echo -e "##############################################\nBEGIN Kubernetes and Container Registry Setup\n##############################################" +echo -e "##############################################\nBEGIN Kubernetes Setup\n##############################################" sleep 0.5s set +x # reduce noise in build logs @@ -59,16 +59,8 @@ kubectl config use-context default/lagoon/kubernetes.default.svc # log in to the provided registry if details are provided if [ ! -z ${INTERNAL_REGISTRY_URL} ] ; then - echo "Creating secret for internal registry access" if [ ! -z ${INTERNAL_REGISTRY_USERNAME} ] && [ ! -z ${INTERNAL_REGISTRY_PASSWORD} ] ; then - echo "docker login -u '${INTERNAL_REGISTRY_USERNAME}' -p '${INTERNAL_REGISTRY_PASSWORD}' ${INTERNAL_REGISTRY_URL}" | /bin/bash - # create lagoon-internal-registry-secret if it does not exist yet - # TODO: remove this, the secret is created by the remote-controller, builds only need to log in to it now - # if ! kubectl -n ${NAMESPACE} get secret lagoon-internal-registry-secret &> /dev/null; then - # kubectl create secret docker-registry lagoon-internal-registry-secret --docker-server=${INTERNAL_REGISTRY_URL} --docker-username=${INTERNAL_REGISTRY_USERNAME} --docker-password=${INTERNAL_REGISTRY_PASSWORD} --dry-run -o yaml | kubectl apply -f - - # fi REGISTRY=$INTERNAL_REGISTRY_URL # This will handle pointing Lagoon at the correct registry for non local builds - echo "Set internal registry secrets for token ${INTERNAL_REGISTRY_USERNAME} in ${REGISTRY}" else if [ ! $INTERNAL_REGISTRY_USERNAME ]; then echo "No token created for registry ${INTERNAL_REGISTRY_URL}"; exit 1; From b916434f0bd731913786f639c427db21eb491665 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 14 Feb 2024 13:49:37 +1100 Subject: [PATCH 68/92] refactor: reduce usage of set -+ x --- legacy/build-deploy-docker-compose.sh | 67 ++++----------------------- 1 file changed, 9 insertions(+), 58 deletions(-) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 6cc5dab3..55534ca1 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -1,5 +1,6 @@ #!/bin/bash +set +x # get the buildname from the pod, $HOSTNAME contains this in the running pod, so we can use this # set it to something usable here export LAGOON_BUILD_NAME=$HOSTNAME @@ -95,9 +96,7 @@ function projectEnvironmentVariableCheck() { echo "$2" } -set +x SCC_CHECK=$(kubectl -n ${NAMESPACE} get pod ${LAGOON_BUILD_NAME} -o json | jq -r '.metadata.annotations."openshift.io/scc" // false') -set -x function beginBuildStep() { [ "$1" ] || return #Buildstep start @@ -145,18 +144,14 @@ function patchBuildStep() { ### PREPARATION ############################################## -set +x buildStartTime="$(date +"%Y-%m-%d %H:%M:%S")" beginBuildStep "Initial Environment Setup" "initialSetup" echo "STEP: Preparation started ${buildStartTime}" -set -x ############################################## ### PUSH the latest .lagoon.yml into lagoon-yaml configmap as a pre-deploy field ############################################## -set +x - # set the imagecache registry if it is provided IMAGECACHE_REGISTRY="" if [ ! -z "$(featureFlag IMAGECACHE_REGISTRY)" ]; then @@ -349,7 +344,7 @@ currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "lagoonYmlValidation" ".lagoon.yml Validation" "false" previousStepEnd=${currentStepEnd} beginBuildStep "Configure Variables" "configuringVariables" -set -x + DEPLOY_TYPE=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH//./\\.}.deploy-type default) # Load all Services that are defined @@ -381,15 +376,12 @@ declare -A IMAGES_PROMOTE # this array stores the hashes of the built images declare -A IMAGE_HASHES -set +x HELM_ARGUMENTS=() . /kubectl-build-deploy/scripts/kubectl-get-cluster-capabilities.sh for CAPABILITIES in "${CAPABILITIES[@]}"; do HELM_ARGUMENTS+=(-a "${CAPABILITIES}") done -set -x -set +x # reduce noise in build logs # Allow the servicetype be overridden by the lagoon API # This accepts colon separated values like so `SERVICE_NAME:SERVICE_TYPE_OVERRIDE`, and multiple overrides # separated by commas @@ -418,7 +410,6 @@ if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then LAGOON_DBAAS_ENVIRONMENT_TYPES=$TEMP_LAGOON_DBAAS_ENVIRONMENT_TYPES fi fi -set -x for COMPOSE_SERVICE in "${COMPOSE_SERVICES[@]}" do @@ -728,7 +719,6 @@ currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${buildStartTime}" "${currentStepEnd}" "${NAMESPACE}" "registryLogin" "Container Regstiry Login" "false" previousStepEnd=${currentStepEnd} beginBuildStep "Image Builds" "buildingImages" -set -x ############################################## ### CACHE IMAGE LIST GENERATION @@ -785,7 +775,6 @@ if [[ "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ]]; then BUILD_CONTEXT=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.context // ""') # the build target for this image build, the original source for this value is from the `docker-compose file` BUILD_TARGET=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.target // false') - set +x # reduce noise in build logs # determine if buildkit should be used for this build DOCKER_BUILDKIT=0 if [ "$(echo "${ENVIRONMENT_IMAGE_BUILD_DATA}" | jq -r '.buildKit // false')" == "true" ]; then @@ -801,7 +790,6 @@ if [[ "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ]]; then echo "Building target ${BUILD_TARGET} for ${BUILD_CONTEXT}/${DOCKERFILE}" DOCKER_BUILDKIT=$DOCKER_BUILDKIT docker build --network=host "${BUILD_ARGS[@]}" -t $TEMPORARY_IMAGE_NAME -f $BUILD_CONTEXT/$DOCKERFILE --target $BUILD_TARGET $BUILD_CONTEXT fi - set -x # Keep a list of the images we have built, as we need to push them to the registry later IMAGES_BUILD["${SERVICE_NAME}"]="${TEMPORARY_IMAGE_NAME}" @@ -812,7 +800,6 @@ if [[ "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ]]; then done fi -set +x # print information about built image sizes function printBytes { local -i bytes=$1; @@ -828,14 +815,11 @@ do TEMPORARY_IMAGE_NAME="${IMAGES_BUILD[${IMAGE_NAME}]}" echo -e "Image ${TEMPORARY_IMAGE_NAME}\t\t$(printBytes $(docker inspect ${TEMPORARY_IMAGE_NAME} | jq -r '.[0].Size'))" done -set -x -set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "imageBuildComplete" "Image Builds" "false" previousStepEnd=${currentStepEnd} beginBuildStep "Pre-Rollout Tasks" "runningPreRolloutTasks" -set -x ############################################## ### RUN PRE-ROLLOUT tasks defined in .lagoon.yml @@ -845,18 +829,13 @@ if [ "${LAGOON_PREROLLOUT_DISABLED}" != "true" ]; then build-deploy-tool tasks pre-rollout else echo "pre-rollout tasks are currently disabled LAGOON_PREROLLOUT_DISABLED is set to true" - set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "preRolloutsCompleted" "Pre-Rollout Tasks" "false" - set -x fi -set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" previousStepEnd=${currentStepEnd} beginBuildStep "Service Configuration Phase 1" "serviceConfigurationPhase1" -set -x - ############################################## ### CONFIGURE SERVICES, AUTOGENERATED ROUTES AND DBAAS CONFIG @@ -885,7 +864,6 @@ yq3 write -i -- /kubectl-build-deploy/values.yaml 'kubernetes' $KUBERNETES yq3 write -i -- /kubectl-build-deploy/values.yaml 'lagoonVersion' $LAGOON_VERSION # check for ROOTLESS_WORKLOAD feature flag, disabled by default -set +x if [ "${SCC_CHECK}" != "false" ]; then # openshift permissions are different, this is to set the fsgroup to the supplemental group from the openshift annotations # this applies it to all deployments in this environment because we don't isolate by service type its applied to all @@ -893,7 +871,6 @@ if [ "${SCC_CHECK}" != "false" ]; then echo "Setting openshift fsGroup to ${OPENSHIFT_SUPPLEMENTAL_GROUP}" yq3 write -i -- /kubectl-build-deploy/values.yaml 'podSecurityContext.fsGroup' $OPENSHIFT_SUPPLEMENTAL_GROUP fi -set -x echo -e "\ LAGOON_PROJECT=${PROJECT}\n\ @@ -932,12 +909,10 @@ LAGOON_PR_NUMBER=${PR_NUMBER}\n\ " >> /kubectl-build-deploy/values.env fi -set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "serviceConfigurationComplete" "Service Configuration Phase 1" "false" previousStepEnd=${currentStepEnd} beginBuildStep "Service Configuration Phase 2" "serviceConfigurationPhase2" -set -x ############################################## ### CUSTOM FASTLY API SECRETS .lagoon.yml @@ -964,7 +939,6 @@ FASTLY_API_SECRET_PREFIX="fastly-api-" FASTLY_API_SECRETS_COUNTER=0 FASTLY_API_SECRETS=() -set +x # reduce noise in build logs if [ -n "$(cat .lagoon.yml | shyaml keys fastly.api-secrets.$FASTLY_API_SECRETS_COUNTER 2> /dev/null)" ]; then while [ -n "$(cat .lagoon.yml | shyaml get-value fastly.api-secrets.$FASTLY_API_SECRETS_COUNTER 2> /dev/null)" ]; do FASTLY_API_SECRET_NAME=$FASTLY_API_SECRET_PREFIX$(cat .lagoon.yml | shyaml get-value fastly.api-secrets.$FASTLY_API_SECRETS_COUNTER.name 2> /dev/null) @@ -1002,13 +976,12 @@ if [ -n "$(cat .lagoon.yml | shyaml keys fastly.api-secrets.$FASTLY_API_SECRETS_ # run the script to create the secrets . /kubectl-build-deploy/scripts/exec-fastly-api-secrets.sh + set +x let FASTLY_API_SECRETS_COUNTER=FASTLY_API_SECRETS_COUNTER+1 done fi -set -x -set +x # reduce noise in build logs # FASTLY API SECRETS FROM LAGOON API VARIABLE # Allow for defining fastly api secrets using lagoon api variables # This accepts colon separated values like so `SECRET_NAME:FASTLY_API_TOKEN:FASTLY_PLATFORMTLS_CONFIGURATION_ID`, and multiple overrides @@ -1042,11 +1015,10 @@ if [ ! -z "$LAGOON_FASTLY_API_SECRETS" ]; then FASTLY_API_PLATFORMTLS_CONFIGURATION=${LAGOON_FASTLY_API_SECRET_SPLIT[2]} # run the script to create the secrets . /kubectl-build-deploy/scripts/exec-fastly-api-secrets.sh + set +x done fi -set -x -set +x # reduce noise in build logs # FASTLY SERVICE ID PER INGRESS OVERRIDE FROM LAGOON API VARIABLE # Allow the fastly serviceid for specific ingress to be overridden by the lagoon API # This accepts colon separated values like so `INGRESS_DOMAIN:FASTLY_SERVICE_ID:WATCH_STATUS:SECRET_NAME(OPTIONAL)`, and multiple overrides @@ -1067,7 +1039,6 @@ if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then LAGOON_FASTLY_SERVICE_IDS=$TEMP_LAGOON_FASTLY_SERVICE_IDS fi fi -set -x ############################################## ### CREATE SERVICES, AUTOGENERATED ROUTES AND DBAAS CONFIG @@ -1141,7 +1112,6 @@ do fi done -set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "serviceConfiguration2Complete" "Service Configuration Phase 2" "false" previousStepEnd=${currentStepEnd} @@ -1189,7 +1159,6 @@ beginBuildStep "Route/Ingress Cleanup" "cleanupRoutes" ### CLEANUP Ingress/routes which have been removed from .lagoon.yml ##############################################s -set +x # collect the current routes excluding any certmanager requests. # its also possible to exclude ingress by adding a label 'route.lagoon.sh/remove=false', this is then used to skip this from the removal checks CURRENT_ROUTES=$(kubectl -n ${NAMESPACE} get ingress -l "lagoon.sh/autogenerated!=true" -l "acme.cert-manager.io/http01-solver!=true" --no-headers | cut -d " " -f 1 | xargs) @@ -1351,7 +1320,6 @@ LAGOON_AUTOGENERATED_ROUTES=${AUTOGENERATED_ROUTES}\n\ # Generate a Config Map with project wide env variables kubectl -n ${NAMESPACE} create configmap lagoon-env -o yaml --dry-run=client --from-env-file=/kubectl-build-deploy/values.env | kubectl apply -n ${NAMESPACE} -f - -set +x # reduce noise in build logs # Add environment variables from lagoon API if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then HAS_PROJECT_RUNTIME_VARS=$(echo $LAGOON_PROJECT_VARIABLES | jq -r 'map( select(.scope == "runtime" or .scope == "global") )') @@ -1395,14 +1363,17 @@ do mariadb-dbaas) . /kubectl-build-deploy/scripts/exec-kubectl-mariadb-dbaas.sh + set +x ;; postgres-dbaas) . /kubectl-build-deploy/scripts/exec-kubectl-postgres-dbaas.sh + set +x ;; mongodb-dbaas) . /kubectl-build-deploy/scripts/exec-kubectl-mongodb-dbaas.sh + set +x ;; *) @@ -1415,7 +1386,6 @@ currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "updateConfigmapComplete" "Update Configmap" "false" previousStepEnd=${currentStepEnd} beginBuildStep "Image Push to Registry" "pushingImages" -set -x ############################################## ### REDEPLOY DEPLOYMENTS IF CONFIG MAP CHANGES @@ -1489,12 +1459,10 @@ elif [ "$BUILD_TYPE" == "promote" ]; then # promote end fi -set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "imagePushComplete" "Image Push to Registry" "false" previousStepEnd=${currentStepEnd} beginBuildStep "Backup Configuration" "configuringBackups" -set -x # Run the backup generation script @@ -1545,24 +1513,20 @@ if [ ! "$BACKUPS_DISABLED" == true ]; then else echo ">> Backup configurations disabled for this build" fi -set -x if [ "$(ls -A $YAML_FOLDER/)" ]; then find $YAML_FOLDER -type f -exec cat {} \; kubectl apply -n ${NAMESPACE} -f $YAML_FOLDER/ fi -set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "backupConfigurationComplete" "Backup Configuration" "false" previousStepEnd=${currentStepEnd} beginBuildStep "Deployment Templating" "templatingDeployments" -set -x ############################################## ### CREATE PVC, DEPLOYMENTS AND CRONJOBS ############################################## -set +x # generate a map of servicename>imagename+hash json for the build-deploy-tool to use when templating # this reduces the need for the crazy logic with how services are currently mapped together in the case of nginx-php type deploymentss @@ -1595,7 +1559,6 @@ currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "deploymentTemplatingComplete" "Deployment Templating" "false" previousStepEnd=${currentStepEnd} beginBuildStep "Applying Deployments" "applyingDeployments" -set -x ############################################## ### APPLY RESOURCES @@ -1607,7 +1570,6 @@ for STORAGE_CALCULATOR_POD in $STORAGE_CALCULATOR_PODS; do kubectl -n ${NAMESPACE} delete pod ${STORAGE_CALCULATOR_POD} done -set +x if [ "$(ls -A $LAGOON_SERVICES_YAML_FOLDER/)" ]; then echo "=== deployment templates for services ===" ls -A $LAGOON_SERVICES_YAML_FOLDER @@ -1621,7 +1583,6 @@ if [ "$(ls -A $LAGOON_SERVICES_YAML_FOLDER/)" ]; then kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/ fi fi -set -x ############################################## ### WAIT FOR POST-ROLLOUT TO BE FINISHED @@ -1657,15 +1618,14 @@ do elif [ ! $SERVICE_ROLLOUT_TYPE == "false" ]; then . /kubectl-build-deploy/scripts/exec-monitor-deploy.sh + set +x fi done -set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "deploymentApplyComplete" "Applying Deployments" "false" previousStepEnd=${currentStepEnd} beginBuildStep "Cronjob Cleanup" "cleaningUpCronjobs" -set -x ############################################## ### CLEANUP NATIVE CRONJOBS which have been removed from .lagoon.yml or modified to run more frequently than every 15 minutes @@ -1695,12 +1655,10 @@ for DC in ${!DELETE_CRONJOBS[@]}; do fi done -set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "cronjobCleanupComplete" "Cronjob Cleanup" "false" previousStepEnd=${currentStepEnd} beginBuildStep "Post-Rollout Tasks" "runningPostRolloutTasks" -set -x ############################################## ### RUN POST-ROLLOUT tasks defined in .lagoon.yml @@ -1711,23 +1669,18 @@ if [ "${LAGOON_POSTROLLOUT_DISABLED}" != "true" ]; then build-deploy-tool tasks post-rollout else echo "post-rollout tasks are currently disabled LAGOON_POSTROLLOUT_DISABLED is set to true" - set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "postRolloutsCompleted" "Post-Rollout Tasks" "false" - set -x fi -set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" previousStepEnd=${currentStepEnd} beginBuildStep "Build and Deploy" "finalizingBuild" -set -x ############################################## ### PUSH the latest .lagoon.yml into lagoon-yaml configmap ############################################## -set +x echo "Updating lagoon-yaml configmap with a post-deploy version of the .lagoon.yml file" if kubectl -n ${NAMESPACE} get configmap lagoon-yaml &> /dev/null; then # replace it, no need to check if the key is different, as that will happen in the pre-deploy phase @@ -1760,9 +1713,7 @@ for TLS_FALSE_INGRESS in $TLS_FALSE_INGRESSES; do fi done done -set -x -set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "deployCompleted" "Build and Deploy" "false" previousStepEnd=${currentStepEnd} @@ -1777,6 +1728,7 @@ if [ "$(featureFlag INSIGHTS)" = enabled ]; then do IMAGE_FULL="${IMAGES_PUSH[${IMAGE_NAME}]}" #extract the push image name from the images to push list . /kubectl-build-deploy/scripts/exec-generate-insights-configmap.sh + set +x done currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" @@ -1811,4 +1763,3 @@ else fi fi fi -set -x From 35f12f933b41b4d6817077c7522c85310c73d1e8 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 6 Mar 2024 09:44:28 +1100 Subject: [PATCH 69/92] chore: clean up unused files --- Dockerfile | 1 - legacy/Dockerfile.kubectl-build-deploy-dind | 1 - legacy/rootless.values.yaml | 6 ------ 3 files changed, 8 deletions(-) delete mode 100644 legacy/rootless.values.yaml diff --git a/Dockerfile b/Dockerfile index 5cac30c0..239894d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -96,7 +96,6 @@ WORKDIR /kubectl-build-deploy/git COPY legacy/docker-entrypoint.sh /lagoon/entrypoints/100-docker-entrypoint.sh COPY legacy/build-deploy.sh /kubectl-build-deploy/build-deploy.sh COPY legacy/build-deploy-docker-compose.sh /kubectl-build-deploy/build-deploy-docker-compose.sh -COPY legacy/rootless.values.yaml /kubectl-build-deploy/rootless.values.yaml COPY legacy/scripts /kubectl-build-deploy/scripts diff --git a/legacy/Dockerfile.kubectl-build-deploy-dind b/legacy/Dockerfile.kubectl-build-deploy-dind index 0b7724a7..6dfc4400 100644 --- a/legacy/Dockerfile.kubectl-build-deploy-dind +++ b/legacy/Dockerfile.kubectl-build-deploy-dind @@ -12,7 +12,6 @@ WORKDIR /kubectl-build-deploy/git COPY docker-entrypoint.sh /lagoon/entrypoints/100-docker-entrypoint.sh COPY build-deploy.sh /kubectl-build-deploy/build-deploy.sh COPY build-deploy-docker-compose.sh /kubectl-build-deploy/build-deploy-docker-compose.sh -COPY rootless.values.yaml /kubectl-build-deploy/rootless.values.yaml COPY scripts /kubectl-build-deploy/scripts diff --git a/legacy/rootless.values.yaml b/legacy/rootless.values.yaml deleted file mode 100644 index c7bba35f..00000000 --- a/legacy/rootless.values.yaml +++ /dev/null @@ -1,6 +0,0 @@ -# This is used in build-deploy-docker-compose.sh to specify the rootless -# podSecurityContext for Lagoon helmcharts. -podSecurityContext: - fsGroup: 10001 - runAsGroup: 0 - runAsUser: 10000 From 120e594251d0f8d0bad0ce5ab9ca3d1953ea4a0c Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 7 Mar 2024 09:20:20 +1100 Subject: [PATCH 70/92] feat: add support for dynamic dbaas secret loading --- cmd/template_lagoonservices_test.go | 3 ++- internal/generator/buildvalues.go | 1 + internal/generator/generator.go | 6 +++++ .../templating/services/templates_cronjob.go | 13 +++++++--- .../services/templates_deployment.go | 26 ++++++++++++++----- .../service6/deployment-node.yaml | 2 ++ internal/testdata/testdata.go | 8 ++++++ legacy/build-deploy-docker-compose.sh | 3 +++ 8 files changed, 52 insertions(+), 10 deletions(-) diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index 5ba85ec4..4fa0314e 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -188,7 +188,8 @@ func TestTemplateLagoonServices(t *testing.T) { ImageReferences: map[string]string{ "node": "harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, - DynamicSecrets: []string{"insights-token"}, + DynamicSecrets: []string{"insights-token"}, + DynamicDBaaSSecrets: []string{"mariadb-dbaas-a4hs12h3"}, }, true), templatePath: "testoutput", want: "internal/testdata/basic/service-templates/service6", diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index e5811ac4..463bb608 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -56,6 +56,7 @@ type BuildValues struct { TaskScaleWaitTime int `json:"taskScaleWaitTime" description:"the time to wait for pods to scale for pre and post rollout tasks"` DynamicSecretMounts []DynamicSecretMounts `json:"dynamicSecretMounts" description:"stores any dynamic secret mount definitions"` DynamicSecretVolumes []DynamicSecretVolumes `json:"dynamicSecretVolumes" description:"stores any dynamic secret volume definitions"` + DynamicDBaaSSecrets []string `json:"dynamicDBaaSSecrets" description:"stores any dynamic dbaas secret definitions"` ImageCache string `json:"imageCache" description:"if an imagecache has been provided for images outside of the imageregistry"` DefaultBackupSchedule string `json:"defaultBackupSchedule" description:"the default backup scheduled"` DBaaSClient *dbaasclient.Client `json:"-" description:"used to store connection information for the dbaas operator endpoint"` diff --git a/internal/generator/generator.go b/internal/generator/generator.go index eba138d6..34d7fd96 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -63,6 +63,7 @@ type GeneratorInput struct { Kubernetes string CI bool DynamicSecrets []string + DynamicDBaaSSecrets []string } func NewGenerator( @@ -106,6 +107,7 @@ func NewGenerator( prHeadSHA := helpers.GetEnv("PR_HEAD_SHA", generator.PRHeadSHA, generator.Debug) prBaseSHA := helpers.GetEnv("PR_BASE_SHA", generator.PRBaseSHA, generator.Debug) dynamicSecrets := helpers.GetEnv("DYNAMIC_SECRETS", strings.Join(generator.DynamicSecrets, ","), generator.Debug) + dynamicDBaaSSecrets := helpers.GetEnv("DYNAMIC_DBAAS_SECRETS", strings.Join(generator.DynamicDBaaSSecrets, ","), generator.Debug) // this is used by CI systems to influence builds, it is rarely used and should probably be abandoned buildValues.IsCI = helpers.GetEnvBool("CI", generator.CI, generator.Debug) @@ -236,6 +238,10 @@ func NewGenerator( }) } } + if dynamicDBaaSSecrets != "" { + // if there are any dynamic dbaas secrets defined, send them here + buildValues.DynamicDBaaSSecrets = strings.Split(dynamicDBaaSSecrets, ",") + } // unmarshal and then merge the two so there is only 1 set of variables to iterate over projectVars := []lagoon.EnvironmentVariable{} diff --git a/internal/templating/services/templates_cronjob.go b/internal/templating/services/templates_cronjob.go index 9ecea26b..12b6a3fd 100644 --- a/internal/templating/services/templates_cronjob.go +++ b/internal/templating/services/templates_cronjob.go @@ -323,9 +323,7 @@ func GenerateCronjobTemplate( Value: serviceValues.OverrideName, }, } - for _, envvar := range envvars { - container.Container.Env = append(container.Container.Env, envvar) - } + container.Container.Env = append(container.Container.Env, envvars...) container.Container.EnvFrom = []corev1.EnvFromSource{ { ConfigMapRef: &corev1.ConfigMapEnvSource{ @@ -335,6 +333,15 @@ func GenerateCronjobTemplate( }, }, } + for _, dds := range buildValues.DynamicDBaaSSecrets { + container.Container.EnvFrom = append(container.Container.EnvFrom, corev1.EnvFromSource{ + SecretRef: &corev1.SecretEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: dds, + }, + }, + }) + } // mount the volumes in the primary container for _, dsm := range buildValues.DynamicSecretMounts { diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index b2f83606..e7ae6b31 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -400,9 +400,7 @@ func GenerateDeploymentTemplate( }, } // expose any container envvars as required here - for _, envvar := range envvars { - container.Container.Env = append(container.Container.Env, envvar) - } + container.Container.Env = append(container.Container.Env, envvars...) // consume the lagoon-env configmap here container.Container.EnvFrom = []corev1.EnvFromSource{ { @@ -413,6 +411,15 @@ func GenerateDeploymentTemplate( }, }, } + for _, dds := range buildValues.DynamicDBaaSSecrets { + container.Container.EnvFrom = append(container.Container.EnvFrom, corev1.EnvFromSource{ + SecretRef: &corev1.SecretEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: dds, + }, + }, + }) + } // mount the volumes in the primary container for _, dsm := range buildValues.DynamicSecretMounts { @@ -505,9 +512,7 @@ func GenerateDeploymentTemplate( Value: buildValues.GitSHA, }, } - for _, envvar := range envvars { - linkedContainer.Container.Env = append(linkedContainer.Container.Env, envvar) - } + linkedContainer.Container.Env = append(linkedContainer.Container.Env, envvars...) linkedContainer.Container.EnvFrom = []corev1.EnvFromSource{ { ConfigMapRef: &corev1.ConfigMapEnvSource{ @@ -517,6 +522,15 @@ func GenerateDeploymentTemplate( }, }, } + for _, dds := range buildValues.DynamicDBaaSSecrets { + linkedContainer.Container.EnvFrom = append(linkedContainer.Container.EnvFrom, corev1.EnvFromSource{ + SecretRef: &corev1.SecretEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: dds, + }, + }, + }) + } for _, dsm := range buildValues.DynamicSecretMounts { volumeMount := corev1.VolumeMount{ Name: dsm.Name, diff --git a/internal/testdata/basic/service-templates/service6/deployment-node.yaml b/internal/testdata/basic/service-templates/service6/deployment-node.yaml index c716a5d1..0f78afd6 100644 --- a/internal/testdata/basic/service-templates/service6/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service6/deployment-node.yaml @@ -52,6 +52,8 @@ spec: envFrom: - configMapRef: name: lagoon-env + - secretRef: + name: mariadb-dbaas-a4hs12h3 image: harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 imagePullPolicy: Always livenessProbe: diff --git a/internal/testdata/testdata.go b/internal/testdata/testdata.go index 0919f13f..bb524dd5 100644 --- a/internal/testdata/testdata.go +++ b/internal/testdata/testdata.go @@ -55,6 +55,7 @@ type TestData struct { PromotionSourceEnvironment string PrivateRegistryURLS []string DynamicSecrets []string + DynamicDBaaSSecrets []string } // helper function to set up all the environment variables from provided testdata @@ -177,6 +178,10 @@ func SetupEnvironment(rootCmd cobra.Command, templatePath string, t TestData) (g if err != nil { return generator.GeneratorInput{}, err } + err = os.Setenv("DYNAMIC_DBAAS_SECRETS", strings.Join(t.DynamicDBaaSSecrets, ",")) + if err != nil { + return generator.GeneratorInput{}, err + } generator, err := generator.GenerateInput(rootCmd, false) if err != nil { @@ -311,5 +316,8 @@ func GetSeedData(t TestData, defaultProjectVariables bool) TestData { if t.DynamicSecrets != nil { rt.DynamicSecrets = t.DynamicSecrets } + if t.DynamicDBaaSSecrets != nil { + rt.DynamicDBaaSSecrets = t.DynamicDBaaSSecrets + } return rt } diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index c9d65c7a..50b2a5f7 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -1380,6 +1380,9 @@ done # handle dynamic secret collection here, @TODO this will go into the state collector eventually export DYNAMIC_SECRETS=$(kubectl -n ${NAMESPACE} get secrets -l lagoon.sh/dynamic-secret -o json | jq -r '[.items[] | .metadata.name] | join(",")') +# label subject to change +export DYNAMIC_DBAAS_SECRETS=$(kubectl -n ${NAMESPACE} get secrets -l secret.lagoon.sh/dbaas=true -o json | jq -r '[.items[] | .metadata.name] | join(",")') + # delete any custom private registry secrets, they will get re-created by the lagoon-services templates EXISTING_REGISTRY_SECRETS=$(kubectl -n ${NAMESPACE} get secrets --no-headers | cut -d " " -f 1 | xargs) for EXISTING_REGISTRY_SECRET in ${EXISTING_REGISTRY_SECRETS}; do From 3dae278898c0241ae72a451e16951c204aa54a4c Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 8 Mar 2024 18:15:10 +1100 Subject: [PATCH 71/92] test: add services test for dbaas detection and templating --- cmd/template_dbaas_test.go | 4 +- cmd/template_lagoonservices_test.go | 43 +++++++ .../docker-compose.compact-services.yml | 39 +++++++ .../complex/docker-compose.services.yml | 4 +- .../testdata/complex/docker/web.dockerfile | 1 + .../complex/lagoon.compact-services.yml | 5 + internal/testdata/complex/lagoon.services.yml | 2 +- .../service3/deployment-mariadb-10-5.yaml | 92 +++++++++++++++ .../service3/deployment-opensearch-2.yaml | 109 ++++++++++++++++++ .../service3/deployment-postgres-11.yaml | 92 +++++++++++++++ .../service3/deployment-redis-6.yaml | 80 +++++++++++++ .../service3/deployment-redis-7.yaml | 80 +++++++++++++ .../service3/deployment-solr-8.yaml | 91 +++++++++++++++ .../service3/deployment-web.yaml | 87 ++++++++++++++ .../service3/pvc-mariadb-10-5.yaml | 29 +++++ .../service3/pvc-opensearch-2.yaml | 29 +++++ .../service3/pvc-postgres-11.yaml | 29 +++++ .../service3/pvc-solr-8.yaml | 29 +++++ .../service-templates/service3/pvc-web.yaml | 30 +++++ .../service3/service-mariadb-10-5.yaml | 31 +++++ .../service3/service-opensearch-2.yaml | 31 +++++ .../service3/service-postgres-11.yaml | 31 +++++ .../service3/service-redis-6.yaml | 31 +++++ .../service3/service-redis-7.yaml | 31 +++++ .../service3/service-solr-8.yaml | 31 +++++ .../service3/service-web.yaml | 31 +++++ .../service4/deployment-mariadb-10-11.yaml | 92 +++++++++++++++ .../service4/deployment-mariadb-10-5.yaml | 92 +++++++++++++++ .../service4/deployment-mongo-4.yaml | 91 +++++++++++++++ .../service4/deployment-postgres-11.yaml | 92 +++++++++++++++ .../service4/deployment-postgres-15.yaml | 92 +++++++++++++++ .../service4/pvc-mariadb-10-11.yaml | 29 +++++ .../service4/pvc-mariadb-10-5.yaml | 29 +++++ .../service4/pvc-mongo-4.yaml | 29 +++++ .../service4/pvc-postgres-11.yaml | 29 +++++ .../service4/pvc-postgres-15.yaml | 29 +++++ .../service4/service-mariadb-10-11.yaml | 31 +++++ .../service4/service-mariadb-10-5.yaml | 31 +++++ .../service4/service-mongo-4.yaml | 31 +++++ .../service4/service-postgres-11.yaml | 31 +++++ .../service4/service-postgres-15.yaml | 31 +++++ 41 files changed, 1846 insertions(+), 5 deletions(-) create mode 100644 internal/testdata/complex/docker-compose.compact-services.yml create mode 100644 internal/testdata/complex/docker/web.dockerfile create mode 100644 internal/testdata/complex/lagoon.compact-services.yml create mode 100644 internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml create mode 100644 internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml create mode 100644 internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml create mode 100644 internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml create mode 100644 internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml create mode 100644 internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml create mode 100644 internal/testdata/complex/service-templates/service3/deployment-web.yaml create mode 100644 internal/testdata/complex/service-templates/service3/pvc-mariadb-10-5.yaml create mode 100644 internal/testdata/complex/service-templates/service3/pvc-opensearch-2.yaml create mode 100644 internal/testdata/complex/service-templates/service3/pvc-postgres-11.yaml create mode 100644 internal/testdata/complex/service-templates/service3/pvc-solr-8.yaml create mode 100644 internal/testdata/complex/service-templates/service3/pvc-web.yaml create mode 100644 internal/testdata/complex/service-templates/service3/service-mariadb-10-5.yaml create mode 100644 internal/testdata/complex/service-templates/service3/service-opensearch-2.yaml create mode 100644 internal/testdata/complex/service-templates/service3/service-postgres-11.yaml create mode 100644 internal/testdata/complex/service-templates/service3/service-redis-6.yaml create mode 100644 internal/testdata/complex/service-templates/service3/service-redis-7.yaml create mode 100644 internal/testdata/complex/service-templates/service3/service-solr-8.yaml create mode 100644 internal/testdata/complex/service-templates/service3/service-web.yaml create mode 100644 internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml create mode 100644 internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml create mode 100644 internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml create mode 100644 internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml create mode 100644 internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml create mode 100644 internal/testdata/complex/service-templates/service4/pvc-mariadb-10-11.yaml create mode 100644 internal/testdata/complex/service-templates/service4/pvc-mariadb-10-5.yaml create mode 100644 internal/testdata/complex/service-templates/service4/pvc-mongo-4.yaml create mode 100644 internal/testdata/complex/service-templates/service4/pvc-postgres-11.yaml create mode 100644 internal/testdata/complex/service-templates/service4/pvc-postgres-15.yaml create mode 100644 internal/testdata/complex/service-templates/service4/service-mariadb-10-11.yaml create mode 100644 internal/testdata/complex/service-templates/service4/service-mariadb-10-5.yaml create mode 100644 internal/testdata/complex/service-templates/service4/service-mongo-4.yaml create mode 100644 internal/testdata/complex/service-templates/service4/service-postgres-11.yaml create mode 100644 internal/testdata/complex/service-templates/service4/service-postgres-15.yaml diff --git a/cmd/template_dbaas_test.go b/cmd/template_dbaas_test.go index 4309cc99..4838f56d 100644 --- a/cmd/template_dbaas_test.go +++ b/cmd/template_dbaas_test.go @@ -96,13 +96,13 @@ func TestDBaaSTemplateGeneration(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "../internal/testdata/complex/lagoon.services.yml", + LagoonYAML: "internal/testdata/complex/lagoon.services.yml", ProjectVariables: []lagoon.EnvironmentVariable{ {Name: "LAGOON_DBAAS_ENVIRONMENT_TYPES", Value: "postgres-15:production-postgres,mongo-4:production-mongo", Scope: "build"}, }, }, true), templatePath: "testdata/output", - want: "../internal/testdata/complex/dbaas-templates/dbaas-4", + want: "internal/testdata/complex/dbaas-templates/dbaas-4", }, } for _, tt := range tests { diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index 4fa0314e..1efd3136 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -194,6 +194,49 @@ func TestTemplateLagoonServices(t *testing.T) { templatePath: "testoutput", want: "internal/testdata/basic/service-templates/service6", }, + { + name: "test8 services deployment", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "internal/testdata/complex/lagoon.services.yml", + ImageReferences: map[string]string{ + "web": "harbor.example/example-project/main/web@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "mariadb-10-5": "harbor.example/example-project/main/mariadb-10-5@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "postgres-11": "harbor.example/example-project/main/postgres-11@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "opensearch-2": "harbor.example/example-project/main/opensearch-2@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "redis-6": "harbor.example/example-project/main/redis-6@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "redis-7": "harbor.example/example-project/main/redis-7@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "solr-8": "harbor.example/example-project/main/solr-8@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + }, + }, true), + templatePath: "testoutput", + want: "internal/testdata/complex/service-templates/service3", + }, + { + name: "test9 compact services meta dbaas deployment", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "internal/testdata/complex/lagoon.compact-services.yml", + ImageReferences: map[string]string{ + "mariadb-10-5": "harbor.example/example-project/main/mariadb-10-5@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "mariadb-10-11": "harbor.example/example-project/main/mariadb-10-11@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "postgres-11": "harbor.example/example-project/main/postgres-11@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "postgres-15": "harbor.example/example-project/main/postgres-15@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + "mongo-4": "harbor.example/example-project/main/mongo-4@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", + }, + ProjectVariables: []lagoon.EnvironmentVariable{ + {Name: "LAGOON_DBAAS_ENVIRONMENT_TYPES", Value: "postgres-15:production-postgres,mongo-4:production-mongo,mariadb-10-11:production-mariadb", Scope: "build"}, + }, + }, true), + templatePath: "testoutput", + want: "internal/testdata/complex/service-templates/service4", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/testdata/complex/docker-compose.compact-services.yml b/internal/testdata/complex/docker-compose.compact-services.yml new file mode 100644 index 00000000..686c9c4e --- /dev/null +++ b/internal/testdata/complex/docker-compose.compact-services.yml @@ -0,0 +1,39 @@ +version: '2' + +services: + mariadb-10-5: + image: uselagoon/mariadb-10.5:latest + labels: + lagoon.type: mariadb-single + lagoon.persistent.size: 100Mi + ports: + - '3306' + + mariadb-10-11: + image: uselagoon/mariadb-10.11:latest + labels: + lagoon.type: mariadb + ports: + - '3306' + + postgres-11: + image: uselagoon/postgres-11:latest + labels: + lagoon.type: postgres-single + lagoon.persistent.size: 100Mi + ports: + - '5432' + + postgres-15: + image: uselagoon/postgres-15:latest + labels: + lagoon.type: postgres + ports: + - '5432' + + mongo-4: + image: uselagoon/mongo-4:latest + labels: + lagoon.type: mongo + ports: + - '27017' \ No newline at end of file diff --git a/internal/testdata/complex/docker-compose.services.yml b/internal/testdata/complex/docker-compose.services.yml index 84077db5..b337f17c 100644 --- a/internal/testdata/complex/docker-compose.services.yml +++ b/internal/testdata/complex/docker-compose.services.yml @@ -9,8 +9,8 @@ volumes: services: web: build: - context: . - dockerfile: Dockerfile + context: internal/testdata/complex/docker + dockerfile: web.dockerfile labels: lagoon.type: basic-persistent lagoon.persistent: /app/files diff --git a/internal/testdata/complex/docker/web.dockerfile b/internal/testdata/complex/docker/web.dockerfile new file mode 100644 index 00000000..0127ef9b --- /dev/null +++ b/internal/testdata/complex/docker/web.dockerfile @@ -0,0 +1 @@ +FROM uselagoon/fake-web:latest diff --git a/internal/testdata/complex/lagoon.compact-services.yml b/internal/testdata/complex/lagoon.compact-services.yml new file mode 100644 index 00000000..2697c522 --- /dev/null +++ b/internal/testdata/complex/lagoon.compact-services.yml @@ -0,0 +1,5 @@ +--- +docker-compose-yaml: internal/testdata/complex/docker-compose.compact-services.yml + +environment_variables: + git_sha: 'true' \ No newline at end of file diff --git a/internal/testdata/complex/lagoon.services.yml b/internal/testdata/complex/lagoon.services.yml index 0557c7f0..3e501476 100644 --- a/internal/testdata/complex/lagoon.services.yml +++ b/internal/testdata/complex/lagoon.services.yml @@ -1,5 +1,5 @@ --- -docker-compose-yaml: ../internal/testdata/complex/docker-compose.services.yml +docker-compose-yaml: internal/testdata/complex/docker-compose.services.yml environment_variables: git_sha: 'true' \ No newline at end of file diff --git a/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml new file mode 100644 index 00000000..b1687edb --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml @@ -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: mariadb-10-5 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb-10-5 + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + name: mariadb-10-5 +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: mariadb-10-5 + app.kubernetes.io/name: mariadb-single + strategy: + type: Recreate + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c 'mysqldump --max-allowed-packet=500M + --events --routines --quick --add-locks --no-autocommit --single-transaction + --all-databases' + k8up.syn.tools/file-extension: .mariadb-10-5.sql + lagoon.sh/branch: main + lagoon.sh/configMapSha: abcdefg1234567890 + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mariadb-10-5 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb-10-5 + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: abcdefg123456 + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/mariadb-10-5@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 3306 + name: mariadb-single + ports: + - containerPort: 3306 + name: 3306-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 3306 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 10Mi + volumeMounts: + - mountPath: /var/lib/mysql + name: mariadb-10-5 + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: mariadb-10-5 + persistentVolumeClaim: + claimName: mariadb-10-5 +status: {} diff --git a/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml b/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml new file mode 100644 index 00000000..b1e29b57 --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml @@ -0,0 +1,109 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: opensearch-2 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: opensearch-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: opensearch-2 + lagoon.sh/service-type: opensearch-persistent + lagoon.sh/template: opensearch-persistent-0.1.0 + name: opensearch-2 +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: opensearch-2 + app.kubernetes.io/name: opensearch-persistent + strategy: + type: Recreate + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c "tar -cf - -C /usr/share/opensearch/data + ." + k8up.syn.tools/file-extension: .opensearch-2.tar + lagoon.sh/branch: main + lagoon.sh/configMapSha: abcdefg1234567890 + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: opensearch-2 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: opensearch-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: opensearch-2 + lagoon.sh/service-type: opensearch-persistent + lagoon.sh/template: opensearch-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: abcdefg123456 + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/opensearch-2@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 9200 + name: opensearch + ports: + - containerPort: 9200 + name: 9200-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 9200 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 10Mi + volumeMounts: + - mountPath: /usr/share/opensearch/data + name: opensearch-2 + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + initContainers: + - command: + - sh + - -c + - |- + set -xe + DESIRED="262144" + CURRENT=$(sysctl -n vm.max_map_count) + if [ "$DESIRED" -gt "$CURRENT" ]; then + sysctl -w vm.max_map_count=$DESIRED + fi + image: library/busybox:latest + imagePullPolicy: IfNotPresent + name: set-max-map-count + resources: {} + securityContext: + privileged: true + runAsUser: 0 + priorityClassName: lagoon-priority-production + volumes: + - name: opensearch-2 + persistentVolumeClaim: + claimName: opensearch-2 +status: {} diff --git a/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml b/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml new file mode 100644 index 00000000..3cafd9cc --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml @@ -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: postgres-11 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres-11 + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + name: postgres-11 +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: postgres-11 + app.kubernetes.io/name: postgres-single + strategy: + type: Recreate + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c "PGPASSWORD=$POSTGRES_PASSWORD pg_dump + --host=localhost --port=$POSTGRES_11_SERVICE_PORT --dbname=$POSTGRES_DB + --username=$POSTGRES_USER --format=t -w" + k8up.syn.tools/file-extension: .postgres-11.tar + lagoon.sh/branch: main + lagoon.sh/configMapSha: abcdefg1234567890 + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: postgres-11 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres-11 + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: abcdefg123456 + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/postgres-11@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 5432 + name: postgres + ports: + - containerPort: 5432 + name: 5432-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 5432 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: postgres-11 + enableServiceLinks: true + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: postgres-11 + persistentVolumeClaim: + claimName: postgres-11 +status: {} diff --git a/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml b/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml new file mode 100644 index 00000000..a252c0ee --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml @@ -0,0 +1,80 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis-6 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis-6 + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + name: redis-6 +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: redis-6 + app.kubernetes.io/name: redis + 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: redis-6 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis-6 + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: abcdefg123456 + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/redis-6@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + tcpSocket: + port: 6379 + timeoutSeconds: 10 + name: redis + ports: + - containerPort: 6379 + name: 6379-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 6379 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production +status: {} diff --git a/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml b/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml new file mode 100644 index 00000000..9e468a59 --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml @@ -0,0 +1,80 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis-7 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis-7 + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + name: redis-7 +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: redis-7 + app.kubernetes.io/name: redis + 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: redis-7 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis-7 + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: abcdefg123456 + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/redis-7@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + tcpSocket: + port: 6379 + timeoutSeconds: 10 + name: redis + ports: + - containerPort: 6379 + name: 6379-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 6379 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production +status: {} diff --git a/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml b/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml new file mode 100644 index 00000000..3657fb5a --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml @@ -0,0 +1,91 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: solr-8 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: solr-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: solr-8 + lagoon.sh/service-type: solr-php-persistent + lagoon.sh/template: solr-php-persistent-0.1.0 + name: solr-8 +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: solr-8 + app.kubernetes.io/name: solr-php-persistent + strategy: {} + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c 'tar -cf - -C "/var/solr" --exclude="lost\+found" + . || [ $? -eq 1 ]' + k8up.syn.tools/file-extension: .solr-8.tar + lagoon.sh/branch: main + lagoon.sh/configMapSha: abcdefg1234567890 + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: solr-8 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: solr-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: solr-8 + lagoon.sh/service-type: solr-php-persistent + lagoon.sh/template: solr-php-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: abcdefg123456 + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/solr-8@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always + livenessProbe: + failureThreshold: 5 + initialDelaySeconds: 90 + tcpSocket: + port: 8983 + timeoutSeconds: 3 + name: solr + ports: + - containerPort: 8983 + name: 8983-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + periodSeconds: 3 + tcpSocket: + port: 8983 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/solr + name: solr-8 + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: solr-8 + persistentVolumeClaim: + claimName: solr-8 +status: {} diff --git a/internal/testdata/complex/service-templates/service3/deployment-web.yaml b/internal/testdata/complex/service-templates/service3/deployment-web.yaml new file mode 100644 index 00000000..71ca0eb7 --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/deployment-web.yaml @@ -0,0 +1,87 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: web + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: web + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: web +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: web + app.kubernetes.io/name: basic-persistent + 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: web + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: web + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: abcdefg123456 + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/web@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 60 + tcpSocket: + port: 3000 + timeoutSeconds: 10 + name: basic + ports: + - containerPort: 3000 + name: basic + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 3000 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /app/files + name: web + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: web + persistentVolumeClaim: + claimName: web +status: {} diff --git a/internal/testdata/complex/service-templates/service3/pvc-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service3/pvc-mariadb-10-5.yaml new file mode 100644 index 00000000..9f7a2c03 --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/pvc-mariadb-10-5.yaml @@ -0,0 +1,29 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mariadb-10-5 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb-10-5 + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + name: mariadb-10-5 +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Mi +status: {} diff --git a/internal/testdata/complex/service-templates/service3/pvc-opensearch-2.yaml b/internal/testdata/complex/service-templates/service3/pvc-opensearch-2.yaml new file mode 100644 index 00000000..678209b9 --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/pvc-opensearch-2.yaml @@ -0,0 +1,29 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: opensearch-2 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: opensearch-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: opensearch-2 + lagoon.sh/service-type: opensearch-persistent + lagoon.sh/template: opensearch-persistent-0.1.0 + name: opensearch-2 +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Mi +status: {} diff --git a/internal/testdata/complex/service-templates/service3/pvc-postgres-11.yaml b/internal/testdata/complex/service-templates/service3/pvc-postgres-11.yaml new file mode 100644 index 00000000..60c75f0b --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/pvc-postgres-11.yaml @@ -0,0 +1,29 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: postgres-11 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres-11 + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + name: postgres-11 +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Mi +status: {} diff --git a/internal/testdata/complex/service-templates/service3/pvc-solr-8.yaml b/internal/testdata/complex/service-templates/service3/pvc-solr-8.yaml new file mode 100644 index 00000000..30ce27eb --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/pvc-solr-8.yaml @@ -0,0 +1,29 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: solr-8 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: solr-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: solr-8 + lagoon.sh/service-type: solr-php-persistent + lagoon.sh/template: solr-php-persistent-0.1.0 + name: solr-8 +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Mi +status: {} diff --git a/internal/testdata/complex/service-templates/service3/pvc-web.yaml b/internal/testdata/complex/service-templates/service3/pvc-web.yaml new file mode 100644 index 00000000..123ad2ba --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/pvc-web.yaml @@ -0,0 +1,30 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "true" + k8up.syn.tools/backup: "true" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: web + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: web + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: web +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 10Mi + storageClassName: bulk +status: {} diff --git a/internal/testdata/complex/service-templates/service3/service-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service3/service-mariadb-10-5.yaml new file mode 100644 index 00000000..8ce04e6d --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/service-mariadb-10-5.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mariadb-10-5 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb-10-5 + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + name: mariadb-10-5 +spec: + ports: + - name: 3306-tcp + port: 3306 + protocol: TCP + targetPort: 3306 + selector: + app.kubernetes.io/instance: mariadb-10-5 + app.kubernetes.io/name: mariadb-single +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service3/service-opensearch-2.yaml b/internal/testdata/complex/service-templates/service3/service-opensearch-2.yaml new file mode 100644 index 00000000..a492649e --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/service-opensearch-2.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: opensearch-2 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: opensearch-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: opensearch-2 + lagoon.sh/service-type: opensearch-persistent + lagoon.sh/template: opensearch-persistent-0.1.0 + name: opensearch-2 +spec: + ports: + - name: 9200-tcp + port: 9200 + protocol: TCP + targetPort: 9200 + selector: + app.kubernetes.io/instance: opensearch-2 + app.kubernetes.io/name: opensearch-persistent +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service3/service-postgres-11.yaml b/internal/testdata/complex/service-templates/service3/service-postgres-11.yaml new file mode 100644 index 00000000..fe6e202b --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/service-postgres-11.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: postgres-11 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres-11 + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + name: postgres-11 +spec: + ports: + - name: 5432-tcp + port: 5432 + protocol: TCP + targetPort: 5432 + selector: + app.kubernetes.io/instance: postgres-11 + app.kubernetes.io/name: postgres-single +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service3/service-redis-6.yaml b/internal/testdata/complex/service-templates/service3/service-redis-6.yaml new file mode 100644 index 00000000..7fc881f4 --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/service-redis-6.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis-6 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis-6 + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + name: redis-6 +spec: + ports: + - name: 6379-tcp + port: 6379 + protocol: TCP + targetPort: 6379 + selector: + app.kubernetes.io/instance: redis-6 + app.kubernetes.io/name: redis +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service3/service-redis-7.yaml b/internal/testdata/complex/service-templates/service3/service-redis-7.yaml new file mode 100644 index 00000000..5b09e030 --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/service-redis-7.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: redis-7 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: redis + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: redis-7 + lagoon.sh/service-type: redis + lagoon.sh/template: redis-0.1.0 + name: redis-7 +spec: + ports: + - name: 6379-tcp + port: 6379 + protocol: TCP + targetPort: 6379 + selector: + app.kubernetes.io/instance: redis-7 + app.kubernetes.io/name: redis +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service3/service-solr-8.yaml b/internal/testdata/complex/service-templates/service3/service-solr-8.yaml new file mode 100644 index 00000000..eefbc6c9 --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/service-solr-8.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: solr-8 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: solr-php-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: solr-8 + lagoon.sh/service-type: solr-php-persistent + lagoon.sh/template: solr-php-persistent-0.1.0 + name: solr-8 +spec: + ports: + - name: 8983-tcp + port: 8983 + protocol: TCP + targetPort: 8983 + selector: + app.kubernetes.io/instance: solr-8 + app.kubernetes.io/name: solr-php-persistent +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service3/service-web.yaml b/internal/testdata/complex/service-templates/service3/service-web.yaml new file mode 100644 index 00000000..39fe1e1c --- /dev/null +++ b/internal/testdata/complex/service-templates/service3/service-web.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: web + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: basic-persistent + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: web + lagoon.sh/service-type: basic-persistent + lagoon.sh/template: basic-persistent-0.1.0 + name: web +spec: + ports: + - name: basic + port: 3000 + protocol: TCP + targetPort: basic + selector: + app.kubernetes.io/instance: web + app.kubernetes.io/name: basic-persistent +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml new file mode 100644 index 00000000..f4b27e3b --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml @@ -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: mariadb-10-11 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb-10-11 + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + name: mariadb-10-11 +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: mariadb-10-11 + app.kubernetes.io/name: mariadb-single + strategy: + type: Recreate + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c 'mysqldump --max-allowed-packet=500M + --events --routines --quick --add-locks --no-autocommit --single-transaction + --all-databases' + k8up.syn.tools/file-extension: .mariadb-10-11.sql + lagoon.sh/branch: main + lagoon.sh/configMapSha: abcdefg1234567890 + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mariadb-10-11 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb-10-11 + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: abcdefg123456 + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/mariadb-10-11@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 3306 + name: mariadb-single + ports: + - containerPort: 3306 + name: 3306-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 3306 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 10Mi + volumeMounts: + - mountPath: /var/lib/mysql + name: mariadb-10-11 + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: mariadb-10-11 + persistentVolumeClaim: + claimName: mariadb-10-11 +status: {} diff --git a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml new file mode 100644 index 00000000..b1687edb --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml @@ -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: mariadb-10-5 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb-10-5 + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + name: mariadb-10-5 +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: mariadb-10-5 + app.kubernetes.io/name: mariadb-single + strategy: + type: Recreate + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c 'mysqldump --max-allowed-packet=500M + --events --routines --quick --add-locks --no-autocommit --single-transaction + --all-databases' + k8up.syn.tools/file-extension: .mariadb-10-5.sql + lagoon.sh/branch: main + lagoon.sh/configMapSha: abcdefg1234567890 + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mariadb-10-5 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb-10-5 + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: abcdefg123456 + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/mariadb-10-5@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 3306 + name: mariadb-single + ports: + - containerPort: 3306 + name: 3306-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 3306 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 10Mi + volumeMounts: + - mountPath: /var/lib/mysql + name: mariadb-10-5 + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: mariadb-10-5 + persistentVolumeClaim: + claimName: mariadb-10-5 +status: {} diff --git a/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml b/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml new file mode 100644 index 00000000..86786a8c --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml @@ -0,0 +1,91 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mongo-4 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mongodb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mongo-4 + lagoon.sh/service-type: mongodb-single + lagoon.sh/template: mongodb-single-0.1.0 + name: mongo-4 +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: mongo-4 + app.kubernetes.io/name: mongodb-single + strategy: + type: Recreate + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c 'tar -cf - -C "/data/db" --exclude="lost\+found" + . || [ $? -eq 1 ]' + k8up.syn.tools/file-extension: .mongo-4.tar + lagoon.sh/branch: main + lagoon.sh/configMapSha: abcdefg1234567890 + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mongo-4 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mongodb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mongo-4 + lagoon.sh/service-type: mongodb-single + lagoon.sh/template: mongodb-single-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: abcdefg123456 + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/mongo-4@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 27017 + name: mongodb-single + ports: + - containerPort: 27017 + name: 27017-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 27017 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 10Mi + volumeMounts: + - mountPath: /data/db + name: mongo-4 + enableServiceLinks: false + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: mongo-4 + persistentVolumeClaim: + claimName: mongo-4 +status: {} diff --git a/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml b/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml new file mode 100644 index 00000000..3cafd9cc --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml @@ -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: postgres-11 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres-11 + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + name: postgres-11 +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: postgres-11 + app.kubernetes.io/name: postgres-single + strategy: + type: Recreate + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c "PGPASSWORD=$POSTGRES_PASSWORD pg_dump + --host=localhost --port=$POSTGRES_11_SERVICE_PORT --dbname=$POSTGRES_DB + --username=$POSTGRES_USER --format=t -w" + k8up.syn.tools/file-extension: .postgres-11.tar + lagoon.sh/branch: main + lagoon.sh/configMapSha: abcdefg1234567890 + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: postgres-11 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres-11 + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: abcdefg123456 + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/postgres-11@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 5432 + name: postgres + ports: + - containerPort: 5432 + name: 5432-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 5432 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: postgres-11 + enableServiceLinks: true + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: postgres-11 + persistentVolumeClaim: + claimName: postgres-11 +status: {} diff --git a/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml b/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml new file mode 100644 index 00000000..c1189c37 --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml @@ -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: postgres-15 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres-15 + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + name: postgres-15 +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/instance: postgres-15 + app.kubernetes.io/name: postgres-single + strategy: + type: Recreate + template: + metadata: + annotations: + k8up.syn.tools/backupcommand: /bin/sh -c "PGPASSWORD=$POSTGRES_PASSWORD pg_dump + --host=localhost --port=$POSTGRES_15_SERVICE_PORT --dbname=$POSTGRES_DB + --username=$POSTGRES_USER --format=t -w" + k8up.syn.tools/file-extension: .postgres-15.tar + lagoon.sh/branch: main + lagoon.sh/configMapSha: abcdefg1234567890 + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: postgres-15 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres-15 + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + spec: + containers: + - env: + - name: LAGOON_GIT_SHA + value: abcdefg123456 + - name: CRONJOBS + envFrom: + - configMapRef: + name: lagoon-env + image: harbor.example/example-project/main/postgres-15@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always + livenessProbe: + initialDelaySeconds: 120 + periodSeconds: 5 + tcpSocket: + port: 5432 + name: postgres + ports: + - containerPort: 5432 + name: 5432-tcp + protocol: TCP + readinessProbe: + initialDelaySeconds: 1 + tcpSocket: + port: 5432 + timeoutSeconds: 1 + resources: + requests: + cpu: 10m + memory: 100M + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: postgres-15 + enableServiceLinks: true + imagePullSecrets: + - name: lagoon-internal-registry-secret + priorityClassName: lagoon-priority-production + volumes: + - name: postgres-15 + persistentVolumeClaim: + claimName: postgres-15 +status: {} diff --git a/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-11.yaml b/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-11.yaml new file mode 100644 index 00000000..0a2e8667 --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-11.yaml @@ -0,0 +1,29 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mariadb-10-11 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb-10-11 + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + name: mariadb-10-11 +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi +status: {} diff --git a/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-5.yaml new file mode 100644 index 00000000..9f7a2c03 --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-5.yaml @@ -0,0 +1,29 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mariadb-10-5 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb-10-5 + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + name: mariadb-10-5 +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Mi +status: {} diff --git a/internal/testdata/complex/service-templates/service4/pvc-mongo-4.yaml b/internal/testdata/complex/service-templates/service4/pvc-mongo-4.yaml new file mode 100644 index 00000000..067a1ed0 --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/pvc-mongo-4.yaml @@ -0,0 +1,29 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mongo-4 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mongodb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mongo-4 + lagoon.sh/service-type: mongodb-single + lagoon.sh/template: mongodb-single-0.1.0 + name: mongo-4 +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi +status: {} diff --git a/internal/testdata/complex/service-templates/service4/pvc-postgres-11.yaml b/internal/testdata/complex/service-templates/service4/pvc-postgres-11.yaml new file mode 100644 index 00000000..60c75f0b --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/pvc-postgres-11.yaml @@ -0,0 +1,29 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: postgres-11 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres-11 + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + name: postgres-11 +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Mi +status: {} diff --git a/internal/testdata/complex/service-templates/service4/pvc-postgres-15.yaml b/internal/testdata/complex/service-templates/service4/pvc-postgres-15.yaml new file mode 100644 index 00000000..06468f15 --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/pvc-postgres-15.yaml @@ -0,0 +1,29 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + k8up.io/backup: "false" + k8up.syn.tools/backup: "false" + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: postgres-15 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres-15 + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + name: postgres-15 +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi +status: {} diff --git a/internal/testdata/complex/service-templates/service4/service-mariadb-10-11.yaml b/internal/testdata/complex/service-templates/service4/service-mariadb-10-11.yaml new file mode 100644 index 00000000..e9ff6fa0 --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/service-mariadb-10-11.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mariadb-10-11 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb-10-11 + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + name: mariadb-10-11 +spec: + ports: + - name: 3306-tcp + port: 3306 + protocol: TCP + targetPort: 3306 + selector: + app.kubernetes.io/instance: mariadb-10-11 + app.kubernetes.io/name: mariadb-single +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service4/service-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service4/service-mariadb-10-5.yaml new file mode 100644 index 00000000..8ce04e6d --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/service-mariadb-10-5.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mariadb-10-5 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mariadb-10-5 + lagoon.sh/service-type: mariadb-single + lagoon.sh/template: mariadb-single-0.1.0 + name: mariadb-10-5 +spec: + ports: + - name: 3306-tcp + port: 3306 + protocol: TCP + targetPort: 3306 + selector: + app.kubernetes.io/instance: mariadb-10-5 + app.kubernetes.io/name: mariadb-single +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service4/service-mongo-4.yaml b/internal/testdata/complex/service-templates/service4/service-mongo-4.yaml new file mode 100644 index 00000000..27ba47eb --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/service-mongo-4.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mongo-4 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mongodb-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mongo-4 + lagoon.sh/service-type: mongodb-single + lagoon.sh/template: mongodb-single-0.1.0 + name: mongo-4 +spec: + ports: + - name: 27017-tcp + port: 27017 + protocol: TCP + targetPort: 27017 + selector: + app.kubernetes.io/instance: mongo-4 + app.kubernetes.io/name: mongodb-single +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service4/service-postgres-11.yaml b/internal/testdata/complex/service-templates/service4/service-postgres-11.yaml new file mode 100644 index 00000000..fe6e202b --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/service-postgres-11.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: postgres-11 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres-11 + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + name: postgres-11 +spec: + ports: + - name: 5432-tcp + port: 5432 + protocol: TCP + targetPort: 5432 + selector: + app.kubernetes.io/instance: postgres-11 + app.kubernetes.io/name: postgres-single +status: + loadBalancer: {} diff --git a/internal/testdata/complex/service-templates/service4/service-postgres-15.yaml b/internal/testdata/complex/service-templates/service4/service-postgres-15.yaml new file mode 100644 index 00000000..d039c1a7 --- /dev/null +++ b/internal/testdata/complex/service-templates/service4/service-postgres-15.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: postgres-15 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: postgres-single + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: postgres-15 + lagoon.sh/service-type: postgres-single + lagoon.sh/template: postgres-single-0.1.0 + name: postgres-15 +spec: + ports: + - name: 5432-tcp + port: 5432 + protocol: TCP + targetPort: 5432 + selector: + app.kubernetes.io/instance: postgres-15 + app.kubernetes.io/name: postgres-single +status: + loadBalancer: {} From 03e33a3fd77e62fc0dfc021676f6401613b1a329 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 29 Apr 2024 16:01:03 +1000 Subject: [PATCH 72/92] chore: backport #310 container-registries refactoring --- cmd/template_lagoonservices_test.go | 29 ++++++++++- internal/generator/container_registries.go | 51 ++++++++++++++----- internal/lagoon/lagoon_test.go | 9 ++++ .../lagoon-yaml/test8/lagoon.yml | 11 ++++ .../services/templates_deployment.go | 4 ++ .../basic/lagoon.container-registry-deep.yml | 27 ++++++++++ .../basic/lagoon.container-registry.yml | 1 + .../service1/deployment-node.yaml | 3 ++ .../lagoon-private-registry-dockerhub.yaml | 21 ++++++++ ...n-private-registry-my-custom-registry.yaml | 2 +- ...private-registry-my-hardcode-registry.yaml | 21 ++++++++ ...on-private-registry-my-other-registry.yaml | 21 ++++++++ 12 files changed, 186 insertions(+), 14 deletions(-) create mode 100644 internal/testdata/basic/lagoon.container-registry-deep.yml create mode 100644 internal/testdata/basic/service-templates/service1/lagoon-private-registry-dockerhub.yaml create mode 100644 internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-hardcode-registry.yaml create mode 100644 internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-other-registry.yaml diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index 1efd3136..d308416a 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -32,10 +32,37 @@ func TestTemplateLagoonServices(t *testing.T) { ProjectName: "example-project", EnvironmentName: "main", Branch: "main", - LagoonYAML: "internal/testdata/basic/lagoon.container-registry.yml", + LagoonYAML: "internal/testdata/basic/lagoon.container-registry-deep.yml", ImageReferences: map[string]string{ "node": "harbor.example/example-project/main/node@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8", }, + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "REGISTRY_PASSWORD", + Value: "myenvvarregistrypassword", + Scope: "container_registry", + }, + { + Name: "REGISTRY_DOCKERHUB_USERNAME", + Value: "dockerhubusername", + Scope: "container_registry", + }, + { + Name: "REGISTRY_DOCKERHUB_PASSWORD", + Value: "dockerhubpassword", + Scope: "container_registry", + }, + { + Name: "REGISTRY_MY_OTHER_REGISTRY_USERNAME", + Value: "otherusername", + Scope: "container_registry", + }, + { + Name: "REGISTRY_MY_OTHER_REGISTRY_PASSWORD", + Value: "otherpassword", + Scope: "container_registry", + }, + }, }, true), templatePath: "testoutput", want: "internal/testdata/basic/service-templates/service1", diff --git a/internal/generator/container_registries.go b/internal/generator/container_registries.go index 3c385d29..20f26817 100644 --- a/internal/generator/container_registries.go +++ b/internal/generator/container_registries.go @@ -15,33 +15,60 @@ import ( // that are then used to generate secrets, or get passed to docker login commands within the build func configureContainerRegistries(buildValues *BuildValues) error { for n, cr := range buildValues.LagoonYAML.ContainerRegistries { - // check for required inputs - if cr.Username == "" { - return fmt.Errorf("no username defined for registry %s", n) - } - if cr.Password == "" { - return fmt.Errorf("no password defined for registry %s", n) - } // check for an override password + // check lowercase registry name password, _ := lagoon.GetLagoonVariable(fmt.Sprintf("REGISTRY_%s_PASSWORD", n), []string{"container_registry"}, buildValues.EnvironmentVariables) passwordSource := fmt.Sprintf("Lagoon API environment variable %s", fmt.Sprintf("REGISTRY_%s_PASSWORD", n)) if password == nil { // no override found, check for a variable that matches the name in the password field - password, _ = lagoon.GetLagoonVariable(cr.Password, []string{"container_registry"}, buildValues.EnvironmentVariables) - passwordSource = fmt.Sprintf("Lagoon API environment variable %s", cr.Password) + // check fixed uppercased dashtounderscore safe name + password, _ = lagoon.GetLagoonVariable(fmt.Sprintf("REGISTRY_%s_PASSWORD", helpers.FixServiceName(n)), []string{"container_registry"}, buildValues.EnvironmentVariables) + passwordSource = fmt.Sprintf("Lagoon API environment variable %s", fmt.Sprintf("REGISTRY_%s_PASSWORD", n)) + if password == nil { + // no override found, check for a variable that matches the name in the password field + password, _ = lagoon.GetLagoonVariable(cr.Password, []string{"container_registry"}, buildValues.EnvironmentVariables) + passwordSource = fmt.Sprintf("Lagoon API environment variable %s", cr.Password) + } } + // if no overide is found if password == nil { - // finally, if no password is found in any variables, pass in the one from the `.lagoon.yml` directly - password = &lagoon.EnvironmentVariable{Value: cr.Password} - passwordSource = ".lagoon.yml (we recommend using an environment variable, see the docs on container-registries for more information)" + // check if one is defined in the yaml + if cr.Password == "" { + return fmt.Errorf("no password defined for registry %s", n) + } else { + // if one is defined in the yaml, check first if there is an environment variable of the provided value + // check for a user provided override variable name that matches + password, _ = lagoon.GetLagoonVariable(cr.Password, []string{"container_registry"}, buildValues.EnvironmentVariables) + if password == nil { + // finally, if no password is found in any variables, pass in the one from the `.lagoon.yml` directly + password = &lagoon.EnvironmentVariable{Value: cr.Password} + passwordSource = ".lagoon.yml (we recommend using an environment variable, see the docs on container-registries for more information)" + } else { + // otherwise the source was from the api variable + passwordSource = fmt.Sprintf("Lagoon API environment variable %s", cr.Password) + } + } } // check for an override username + // check lowercase registry name username, _ := lagoon.GetLagoonVariable(fmt.Sprintf("REGISTRY_%s_USERNAME", n), []string{"container_registry"}, buildValues.EnvironmentVariables) usernameSource := fmt.Sprintf("Lagoon API environment variable %s", fmt.Sprintf("REGISTRY_%s_USERNAME", n)) if username == nil { + // no override found, check for a variable that matches the name in the password field + // check fixed uppercased dashtounderscore safe name + username, _ = lagoon.GetLagoonVariable(fmt.Sprintf("REGISTRY_%s_USERNAME", helpers.FixServiceName(n)), []string{"container_registry"}, buildValues.EnvironmentVariables) + usernameSource = fmt.Sprintf("Lagoon API environment variable %s", fmt.Sprintf("REGISTRY_%s_USERNAME", n)) + } + if username == nil { + if cr.Username == "" { + return fmt.Errorf("no username defined for registry %s", n) + } username = &lagoon.EnvironmentVariable{Value: cr.Username} usernameSource = ".lagoon.yml" } + if cr.URL == "" { + cr.URL = "index.docker.io" + } eru := cr.URL u, _ := url.Parse(eru) if u.Host == "" { diff --git a/internal/lagoon/lagoon_test.go b/internal/lagoon/lagoon_test.go index 70c4b888..57611b75 100644 --- a/internal/lagoon/lagoon_test.go +++ b/internal/lagoon/lagoon_test.go @@ -368,6 +368,15 @@ func TestUnmarshalLagoonYAML(t *testing.T) { Password: "REGISTRY_PASSWORD", URL: "my.own.registry.com", }, + "my-hardcode-registry": { + Username: "myhardcoderegistryuser", + Password: "myhardcoderegistrypassword", + URL: "my.hardcode.registry.com", + }, + "my-other-registry": { + URL: "my.other.registry.com", + }, + "dockerhub": {}, }, Environments: Environments{ "main": Environment{ diff --git a/internal/lagoon/test-resources/lagoon-yaml/test8/lagoon.yml b/internal/lagoon/test-resources/lagoon-yaml/test8/lagoon.yml index 71ae0074..c1fa37bc 100644 --- a/internal/lagoon/test-resources/lagoon-yaml/test8/lagoon.yml +++ b/internal/lagoon/test-resources/lagoon-yaml/test8/lagoon.yml @@ -2,9 +2,20 @@ docker-compose-yaml: docker-compose.yml container-registries: my-custom-registry: + description: "passwords in variable" username: myownregistryuser password: REGISTRY_PASSWORD url: my.own.registry.com + my-hardcode-registry: + description: "password hardcoded" + username: myhardcoderegistryuser + password: myhardcoderegistrypassword + url: my.hardcode.registry.com + my-other-registry: + description: "password and username in variable" + url: my.other.registry.com + dockerhub: + description: "password and username in variable, default docker.io url" environments: main: diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index e7ae6b31..0757371b 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -2,6 +2,7 @@ package services import ( "fmt" + "sort" "strings" "github.com/uselagoon/build-deploy-tool/internal/generator" @@ -269,6 +270,9 @@ func GenerateDeploymentTemplate( }, } // then consume any from the custom provided container registries + sort.Slice(buildValues.ContainerRegistry, func(i, j int) bool { + return buildValues.ContainerRegistry[i].Name < buildValues.ContainerRegistry[j].Name + }) for _, pullsecret := range buildValues.ContainerRegistry { pullsecrets = append(pullsecrets, corev1.LocalObjectReference{ Name: pullsecret.SecretName, diff --git a/internal/testdata/basic/lagoon.container-registry-deep.yml b/internal/testdata/basic/lagoon.container-registry-deep.yml new file mode 100644 index 00000000..397bf7d4 --- /dev/null +++ b/internal/testdata/basic/lagoon.container-registry-deep.yml @@ -0,0 +1,27 @@ +docker-compose-yaml: internal/testdata/basic/docker-compose.yml + +container-registries: + my-custom-registry: + description: "passwords in variable" + username: myownregistryuser + password: REGISTRY_PASSWORD + url: my.own.registry.com + my-hardcode-registry: + description: "password hardcoded" + username: myhardcoderegistryuser + password: myhardcoderegistrypassword + url: my.hardcode.registry.com + my-other-registry: + description: "password and username in variable" + url: my.other.registry.com + dockerhub: + description: "password and username in variable, default docker.io url" + +environment_variables: + git_sha: "true" + +environments: + main: + routes: + - node: + - example.com diff --git a/internal/testdata/basic/lagoon.container-registry.yml b/internal/testdata/basic/lagoon.container-registry.yml index d85dc5e8..edfcc412 100644 --- a/internal/testdata/basic/lagoon.container-registry.yml +++ b/internal/testdata/basic/lagoon.container-registry.yml @@ -2,6 +2,7 @@ docker-compose-yaml: internal/testdata/basic/docker-compose.yml container-registries: my-custom-registry: + description: "passwords in variable" username: myownregistryuser password: REGISTRY_PASSWORD url: my.own.registry.com diff --git a/internal/testdata/basic/service-templates/service1/deployment-node.yaml b/internal/testdata/basic/service-templates/service1/deployment-node.yaml index da12702c..86b88406 100644 --- a/internal/testdata/basic/service-templates/service1/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service1/deployment-node.yaml @@ -82,6 +82,9 @@ spec: enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret + - name: lagoon-private-registry-dockerhub - name: lagoon-private-registry-my-custom-registry + - name: lagoon-private-registry-my-hardcode-registry + - name: lagoon-private-registry-my-other-registry priorityClassName: lagoon-priority-production status: {} diff --git a/internal/testdata/basic/service-templates/service1/lagoon-private-registry-dockerhub.yaml b/internal/testdata/basic/service-templates/service1/lagoon-private-registry-dockerhub.yaml new file mode 100644 index 00000000..8f64fa98 --- /dev/null +++ b/internal/testdata/basic/service-templates/service1/lagoon-private-registry-dockerhub.yaml @@ -0,0 +1,21 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: internal-registry-secret + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: dockerhub + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/template: internal-registry-secret-0.1.0 + name: lagoon-private-registry-dockerhub +stringData: + .dockerconfigjson: eyJhdXRocyI6eyJpbmRleC5kb2NrZXIuaW8iOnsidXNlcm5hbWUiOiJkb2NrZXJodWJ1c2VybmFtZSIsInBhc3N3b3JkIjoiZG9ja2VyaHVicGFzc3dvcmQiLCJhdXRoIjoiWkc5amEyVnlhSFZpZFhObGNtNWhiV1U2Wkc5amEyVnlhSFZpY0dGemMzZHZjbVE9In19fQ== +type: kubernetes.io/dockerconfigjson diff --git a/internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-custom-registry.yaml b/internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-custom-registry.yaml index 0d7e8057..13637404 100644 --- a/internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-custom-registry.yaml +++ b/internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-custom-registry.yaml @@ -17,5 +17,5 @@ metadata: lagoon.sh/template: internal-registry-secret-0.1.0 name: lagoon-private-registry-my-custom-registry stringData: - .dockerconfigjson: eyJhdXRocyI6eyJteS5vd24ucmVnaXN0cnkuY29tIjp7InVzZXJuYW1lIjoibXlvd25yZWdpc3RyeXVzZXIiLCJwYXNzd29yZCI6IlJFR0lTVFJZX1BBU1NXT1JEIiwiYXV0aCI6ImJYbHZkMjV5WldkcGMzUnllWFZ6WlhJNlVrVkhTVk5VVWxsZlVFRlRVMWRQVWtRPSJ9fX0= + .dockerconfigjson: eyJhdXRocyI6eyJteS5vd24ucmVnaXN0cnkuY29tIjp7InVzZXJuYW1lIjoibXlvd25yZWdpc3RyeXVzZXIiLCJwYXNzd29yZCI6Im15ZW52dmFycmVnaXN0cnlwYXNzd29yZCIsImF1dGgiOiJiWGx2ZDI1eVpXZHBjM1J5ZVhWelpYSTZiWGxsYm5aMllYSnlaV2RwYzNSeWVYQmhjM04zYjNKayJ9fX0= type: kubernetes.io/dockerconfigjson diff --git a/internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-hardcode-registry.yaml b/internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-hardcode-registry.yaml new file mode 100644 index 00000000..af7c74ea --- /dev/null +++ b/internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-hardcode-registry.yaml @@ -0,0 +1,21 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: internal-registry-secret + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: my-hardcode-registry + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/template: internal-registry-secret-0.1.0 + name: lagoon-private-registry-my-hardcode-registry +stringData: + .dockerconfigjson: eyJhdXRocyI6eyJteS5oYXJkY29kZS5yZWdpc3RyeS5jb20iOnsidXNlcm5hbWUiOiJteWhhcmRjb2RlcmVnaXN0cnl1c2VyIiwicGFzc3dvcmQiOiJteWhhcmRjb2RlcmVnaXN0cnlwYXNzd29yZCIsImF1dGgiOiJiWGxvWVhKa1kyOWtaWEpsWjJsemRISjVkWE5sY2pwdGVXaGhjbVJqYjJSbGNtVm5hWE4wY25sd1lYTnpkMjl5WkE9PSJ9fX0= +type: kubernetes.io/dockerconfigjson diff --git a/internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-other-registry.yaml b/internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-other-registry.yaml new file mode 100644 index 00000000..d62a5c2b --- /dev/null +++ b/internal/testdata/basic/service-templates/service1/lagoon-private-registry-my-other-registry.yaml @@ -0,0 +1,21 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: internal-registry-secret + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: my-other-registry + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/template: internal-registry-secret-0.1.0 + name: lagoon-private-registry-my-other-registry +stringData: + .dockerconfigjson: eyJhdXRocyI6eyJteS5vdGhlci5yZWdpc3RyeS5jb20iOnsidXNlcm5hbWUiOiJvdGhlcnVzZXJuYW1lIiwicGFzc3dvcmQiOiJvdGhlcnBhc3N3b3JkIiwiYXV0aCI6ImIzUm9aWEoxYzJWeWJtRnRaVHB2ZEdobGNuQmhjM04zYjNKayJ9fX0= +type: kubernetes.io/dockerconfigjson From 805d29c0f3d6de4c7a8b5f80c6fd118e34981150 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 14 May 2024 13:18:03 +1000 Subject: [PATCH 73/92] refactor: dont use imagecache if image appears to not be in dockerhub --- cmd/identify_imagebuild_test.go | 4 ++-- internal/generator/services.go | 3 ++- internal/testdata/complex/docker-compose.varnish.yml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/identify_imagebuild_test.go b/cmd/identify_imagebuild_test.go index e7cf12b1..e7e37893 100644 --- a/cmd/identify_imagebuild_test.go +++ b/cmd/identify_imagebuild_test.go @@ -115,7 +115,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { Name: "redis", ImageBuild: generator.ImageBuild{ BuildImage: "harbor.example/example-project/main/redis:latest", - PullImage: "amazeeio/redis", + PullImage: "quay.io/notlagoon/redis", }, }, { Name: "varnish", @@ -202,7 +202,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { Name: "redis", ImageBuild: generator.ImageBuild{ BuildImage: "harbor.example/example-project/main/redis:latest", - PullImage: "imagecache.example.com/amazeeio/redis", + PullImage: "quay.io/notlagoon/redis", }, }, { Name: "varnish", diff --git a/internal/generator/services.go b/internal/generator/services.go index 6277a10c..1de1b629 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -554,7 +554,8 @@ func composeToServiceValues( imageBuild.PullImage = pullImage } if !ContainsRegistry(buildValues.ContainerRegistry, pullImage) { - if buildValues.ImageCache != "" { + // if the image isn't in dockerhub, then the imagecache can't be used + if buildValues.ImageCache != "" && strings.Count(pullImage, "/") == 1 { imageBuild.PullImage = fmt.Sprintf("%s%s", buildValues.ImageCache, imageBuild.PullImage) } } diff --git a/internal/testdata/complex/docker-compose.varnish.yml b/internal/testdata/complex/docker-compose.varnish.yml index a03f9926..be10aec1 100644 --- a/internal/testdata/complex/docker-compose.varnish.yml +++ b/internal/testdata/complex/docker-compose.varnish.yml @@ -101,7 +101,7 @@ services: lagoon.type: mariadb redis: - image: amazeeio/redis + image: quay.io/notlagoon/redis labels: lagoon.type: redis From 14534b96dc525683f30bbc3812fc1a6df4b60f3a Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 24 May 2024 16:00:53 +1000 Subject: [PATCH 74/92] chore: fix redis template test for backup cmd --- .../services/test-resources/deployment/result-redis-1.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/templating/services/test-resources/deployment/result-redis-1.yaml b/internal/templating/services/test-resources/deployment/result-redis-1.yaml index 30a7a2e6..960d1193 100644 --- a/internal/templating/services/test-resources/deployment/result-redis-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-redis-1.yaml @@ -113,7 +113,7 @@ spec: template: metadata: annotations: - k8up.syn.tools/backupcommand: /bin/sh -c "/bin/busybox tar -cf - -C /data + k8up.syn.tools/backupcommand: /bin/sh -c "timeout 5400 tar -cf - -C /data ." k8up.syn.tools/file-extension: .redis-persist.tar lagoon.sh/branch: environment-name From fb6924b5e389f9cbabde43f953675be95f0fad61 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 24 May 2024 16:07:44 +1000 Subject: [PATCH 75/92] chore: remove labels from cronjobs that deployments use as selectors --- .../templating/services/templates_cronjob.go | 20 ++++++++++--------- .../test-resources/cronjob/result-cli-1.yaml | 12 ----------- .../cronjob-cronjob-cli-drush-cron2.yaml | 4 ---- .../cronjob-cronjob-cli-drush-cron2.yaml | 4 ---- 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/internal/templating/services/templates_cronjob.go b/internal/templating/services/templates_cronjob.go index 12b6a3fd..4f9b75d2 100644 --- a/internal/templating/services/templates_cronjob.go +++ b/internal/templating/services/templates_cronjob.go @@ -34,15 +34,17 @@ func GenerateCronjobTemplate( // add the default labels labels := map[string]string{ "app.kubernetes.io/managed-by": "build-deploy-tool", - "app.kubernetes.io/name": serviceTypeValues.Name, - "app.kubernetes.io/instance": serviceValues.OverrideName, - "lagoon.sh/project": buildValues.Project, - "lagoon.sh/environment": buildValues.Environment, - "lagoon.sh/environmentType": buildValues.EnvironmentType, - "lagoon.sh/buildType": buildValues.BuildType, - "lagoon.sh/template": fmt.Sprintf("%s-%s", serviceTypeValues.Name, "0.1.0"), - "lagoon.sh/service": serviceValues.OverrideName, - "lagoon.sh/service-type": serviceTypeValues.Name, + // @TODO: these are removed for now to resolve a deployment label matching issue + // that can crop up + // "app.kubernetes.io/name": serviceTypeValues.Name, + // "app.kubernetes.io/instance": serviceValues.OverrideName, + "lagoon.sh/project": buildValues.Project, + "lagoon.sh/environment": buildValues.Environment, + "lagoon.sh/environmentType": buildValues.EnvironmentType, + "lagoon.sh/buildType": buildValues.BuildType, + "lagoon.sh/template": fmt.Sprintf("%s-%s", serviceTypeValues.Name, "0.1.0"), + "lagoon.sh/service": serviceValues.OverrideName, + "lagoon.sh/service-type": serviceTypeValues.Name, } // add the default annotations diff --git a/internal/templating/services/test-resources/cronjob/result-cli-1.yaml b/internal/templating/services/test-resources/cronjob/result-cli-1.yaml index 79a6b539..6fd4aaab 100644 --- a/internal/templating/services/test-resources/cronjob/result-cli-1.yaml +++ b/internal/templating/services/test-resources/cronjob/result-cli-1.yaml @@ -7,9 +7,7 @@ metadata: 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: cli lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production @@ -33,9 +31,7 @@ spec: 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: cli lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production @@ -95,9 +91,7 @@ metadata: 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: cli lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production @@ -121,9 +115,7 @@ spec: 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: cli lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production @@ -183,9 +175,7 @@ metadata: lagoon.sh/version: v2.x.x creationTimestamp: null labels: - app.kubernetes.io/instance: myservice-persist app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production @@ -209,9 +199,7 @@ spec: lagoon.sh/version: v2.x.x creationTimestamp: null labels: - app.kubernetes.io/instance: myservice-persist app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production diff --git a/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml b/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml index e6dd7311..0346bbec 100644 --- a/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml +++ b/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml @@ -7,9 +7,7 @@ metadata: lagoon.sh/version: v2.7.x creationTimestamp: null labels: - app.kubernetes.io/instance: cli app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent lagoon.sh/buildType: branch lagoon.sh/environment: main lagoon.sh/environmentType: production @@ -33,9 +31,7 @@ spec: lagoon.sh/version: v2.7.x creationTimestamp: null labels: - app.kubernetes.io/instance: cli app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent lagoon.sh/buildType: branch lagoon.sh/environment: main lagoon.sh/environmentType: production diff --git a/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml b/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml index a2785c23..9dc51457 100644 --- a/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml +++ b/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml @@ -7,9 +7,7 @@ metadata: lagoon.sh/version: v2.7.x creationTimestamp: null labels: - app.kubernetes.io/instance: cli app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent lagoon.sh/buildType: branch lagoon.sh/environment: main lagoon.sh/environmentType: production @@ -33,9 +31,7 @@ spec: lagoon.sh/version: v2.7.x creationTimestamp: null labels: - app.kubernetes.io/instance: cli app.kubernetes.io/managed-by: build-deploy-tool - app.kubernetes.io/name: cli-persistent lagoon.sh/buildType: branch lagoon.sh/environment: main lagoon.sh/environmentType: production From 5c90dbb949b25c14391550f69da324f2e2f56858 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 29 May 2024 15:02:03 +1000 Subject: [PATCH 76/92] chore: apply other templates individually --- legacy/build-deploy-docker-compose.sh | 54 ++++++++++++++++++--------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 532f015b..c850a90b 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -915,7 +915,15 @@ fi # generate the autogenerated ingress if [ ! "$AUTOGEN_ROUTES_DISABLED" == true ]; then - build-deploy-tool template autogenerated-ingress + LAGOON_AUTOGEN_YAML_FOLDER="/kubectl-build-deploy/lagoon/autogen-routes" + mkdir -p $LAGOON_AUTOGEN_YAML_FOLDER + build-deploy-tool template autogenerated-ingress --saved-templates-path ${LAGOON_AUTOGEN_YAML_FOLDER} + + # apply autogenerated ingress + if [ "$(ls -A $LAGOON_AUTOGEN_YAML_FOLDER/)" ]; then + find $LAGOON_AUTOGEN_YAML_FOLDER -type f -exec cat {} \; + kubectl apply -n ${NAMESPACE} -f $LAGOON_AUTOGEN_YAML_FOLDER/ + fi else echo ">> Autogenerated ingress templates disabled for this build" # end custom route @@ -961,7 +969,9 @@ do done # generate the dbaas templates if any -build-deploy-tool template dbaas +LAGOON_DBAAS_YAML_FOLDER="/kubectl-build-deploy/lagoon/dbaas" +mkdir -p $LAGOON_DBAAS_YAML_FOLDER +build-deploy-tool template dbaas --saved-templates-path ${LAGOON_DBAAS_YAML_FOLDER} set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" @@ -969,6 +979,12 @@ patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${N previousStepEnd=${currentStepEnd} beginBuildStep "Route/Ingress Configuration" "configuringRoutes" +# apply dbaas +if [ "$(ls -A $LAGOON_DBAAS_YAML_FOLDER/)" ]; then + find $LAGOON_DBAAS_YAML_FOLDER -type f -exec cat {} \; + kubectl apply -n ${NAMESPACE} -f $LAGOON_DBAAS_YAML_FOLDER/ +fi + TEMPLATE_PARAMETERS=() ############################################## @@ -990,16 +1006,18 @@ if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then fi if [ ! "$CUSTOM_ROUTES_DISABLED" == true ]; then -build-deploy-tool template ingress + LAGOON_ROUTES_YAML_FOLDER="/kubectl-build-deploy/lagoon/routes" + mkdir -p $LAGOON_ROUTES_YAML_FOLDER + build-deploy-tool template ingress --saved-templates-path ${LAGOON_ROUTES_YAML_FOLDER} + + # apply the routes + if [ "$(ls -A $LAGOON_ROUTES_YAML_FOLDER/)" ]; then + find $LAGOON_ROUTES_YAML_FOLDER -type f -exec cat {} \; + kubectl apply -n ${NAMESPACE} -f $LAGOON_ROUTES_YAML_FOLDER/ + fi else echo ">> Custom ingress templates disabled for this build" -# end custom route -fi - -# apply the currently templated components out so that the route and lagoon-env configmaps gets what they need -if [ "$(ls -A $YAML_FOLDER/)" ]; then - find $YAML_FOLDER -type f -exec cat {} \; - kubectl apply -n ${NAMESPACE} -f $YAML_FOLDER/ + # end custom route fi currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" @@ -1372,6 +1390,8 @@ fi if [ ! "$BACKUPS_DISABLED" == true ]; then # check if k8up v2 feature flag is enabled + LAGOON_BACKUP_YAML_FOLDER="/kubectl-build-deploy/lagoon/backup" + mkdir -p $LAGOON_BACKUP_YAML_FOLDER if [ "$(featureFlag K8UP_V2)" = enabled ]; then # build-tool doesn't do any capability checks yet, so do this for now if [[ "${CAPABILITIES[@]}" =~ "k8up.io/v1/Schedule" ]]; then @@ -1380,7 +1400,7 @@ if [ ! "$BACKUPS_DISABLED" == true ]; then # Create baas-repo-pw secret based on the project secret kubectl --insecure-skip-tls-verify -n ${NAMESPACE} create secret generic baas-repo-pw --from-literal=repo-pw=$(echo -n "${PROJECT_SECRET}-BAAS-REPO-PW" | sha256sum | cut -d " " -f 1) fi - build-deploy-tool template backup-schedule --version v2 + build-deploy-tool template backup-schedule --version v2 --saved-templates-path ${LAGOON_BACKUP_YAML_FOLDER} # check if the existing schedule exists, and delete it if [[ "${CAPABILITIES[@]}" =~ "backup.appuio.ch/v1alpha1/Schedule" ]]; then if kubectl --insecure-skip-tls-verify -n ${NAMESPACE} get schedules.backup.appuio.ch k8up-lagoon-backup-schedule &> /dev/null; then @@ -1401,17 +1421,17 @@ if [ ! "$BACKUPS_DISABLED" == true ]; then # Create baas-repo-pw secret based on the project secret kubectl --insecure-skip-tls-verify -n ${NAMESPACE} create secret generic baas-repo-pw --from-literal=repo-pw=$(echo -n "${PROJECT_SECRET}-BAAS-REPO-PW" | sha256sum | cut -d " " -f 1) fi - build-deploy-tool template backup-schedule --version v1 + build-deploy-tool template backup-schedule --version v1 --saved-templates-path ${LAGOON_BACKUP_YAML_FOLDER} + fi + # apply backup templates + if [ "$(ls -A $LAGOON_BACKUP_YAML_FOLDER/)" ]; then + find $LAGOON_BACKUP_YAML_FOLDER -type f -exec cat {} \; + kubectl apply -n ${NAMESPACE} -f $LAGOON_BACKUP_YAML_FOLDER/ fi else echo ">> Backup configurations disabled for this build" fi -if [ "$(ls -A $YAML_FOLDER/)" ]; then - find $YAML_FOLDER -type f -exec cat {} \; - kubectl apply -n ${NAMESPACE} -f $YAML_FOLDER/ -fi - currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "backupConfigurationComplete" "Backup Configuration" "false" previousStepEnd=${currentStepEnd} From e03b20001271cca59c438961c3dd6ec256039eb2 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 21 Jun 2024 09:10:52 +1000 Subject: [PATCH 77/92] fix: template creation for dbaas and other fmt fixes --- cmd/config_fastly.go | 4 - cmd/identify_dbaas_test.go | 24 ----- cmd/identify_feature_test.go | 24 ----- cmd/identify_ingress_test.go | 23 ----- cmd/identify_lagoonservices.go | 30 +++--- cmd/identify_native_cronjobs_test.go | 26 ------ cmd/root.go | 2 +- cmd/tasks_run.go | 8 +- cmd/template_autogen_ingress.go | 2 +- cmd/template_autogen_ingress_test.go | 2 +- cmd/template_dbaas.go | 8 +- cmd/template_dbaas_test.go | 29 +++++- cmd/template_ingress.go | 4 +- cmd/template_lagoonservices.go | 92 +++++++++---------- .../basic/dbaas-templates/dbaas-1/.gitkeep | 0 legacy/build-deploy-docker-compose.sh | 20 ++-- 16 files changed, 104 insertions(+), 194 deletions(-) create mode 100644 internal/testdata/basic/dbaas-templates/dbaas-1/.gitkeep diff --git a/cmd/config_fastly.go b/cmd/config_fastly.go index c27b8543..92e73801 100644 --- a/cmd/config_fastly.go +++ b/cmd/config_fastly.go @@ -9,10 +9,6 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/lagoon" ) -var ( - domainName string -) - var fastlyConfigGeneration = &cobra.Command{ Use: "fastly", Aliases: []string{"f"}, diff --git a/cmd/identify_dbaas_test.go b/cmd/identify_dbaas_test.go index 1d7c2c74..e08ee046 100644 --- a/cmd/identify_dbaas_test.go +++ b/cmd/identify_dbaas_test.go @@ -13,30 +13,6 @@ import ( // these tests uses the same files as the dbaas templates func TestIdentifyDBaaSConsumers(t *testing.T) { - type args struct { - name string - alertContact string - statusPageID string - projectName string - environmentName string - branch string - prNumber string - prHeadBranch string - prBaseBranch string - environmentType string - buildType string - activeEnvironment string - standbyEnvironment string - cacheNoCache string - serviceID string - secretPrefix string - projectVars string - envVars string - lagoonVersion string - lagoonYAML string - valuesFilePath string - templatePath string - } tests := []struct { name string args testdata.TestData diff --git a/cmd/identify_feature_test.go b/cmd/identify_feature_test.go index b1468c73..7f596f2e 100644 --- a/cmd/identify_feature_test.go +++ b/cmd/identify_feature_test.go @@ -13,30 +13,6 @@ import ( ) func TestIdentifyFeatureFlag(t *testing.T) { - type args struct { - name string - alertContact string - statusPageID string - projectName string - environmentName string - branch string - prNumber string - prHeadBranch string - prBaseBranch string - environmentType string - buildType string - activeEnvironment string - standbyEnvironment string - cacheNoCache string - serviceID string - secretPrefix string - projectVars string - envVars string - lagoonVersion string - lagoonYAML string - valuesFilePath string - templatePath string - } tests := []struct { name string args testdata.TestData diff --git a/cmd/identify_ingress_test.go b/cmd/identify_ingress_test.go index 7b05a5bd..25f31c4a 100644 --- a/cmd/identify_ingress_test.go +++ b/cmd/identify_ingress_test.go @@ -388,29 +388,6 @@ func TestIdentifyRoute(t *testing.T) { } func TestCreatedIngressIdentification(t *testing.T) { - type args struct { - alertContact string - statusPageID string - projectName string - environmentName string - branch string - prNumber string - prHeadBranch string - prBaseBranch string - environmentType string - buildType string - activeEnvironment string - standbyEnvironment string - cacheNoCache string - serviceID string - secretPrefix string - projectVars string - envVars string - lagoonVersion string - lagoonYAML string - valuesFilePath string - templatePath string - } tests := []struct { name string args testdata.TestData diff --git a/cmd/identify_lagoonservices.go b/cmd/identify_lagoonservices.go index b88ff617..d17b8ad9 100644 --- a/cmd/identify_lagoonservices.go +++ b/cmd/identify_lagoonservices.go @@ -76,25 +76,23 @@ func LagoonServiceTemplateIdentification(g generator.GeneratorInput) ([]identify if err != nil { return nil, fmt.Errorf("couldn't generate template: %v", err) } - if deployments != nil { - for _, d := range deployments { - dcs := []containers{} - for _, dc := range d.Spec.Template.Spec.Containers { - dcp := []ports{} - for _, p := range dc.Ports { - dcp = append(dcp, ports{Port: p.ContainerPort}) - } - dcs = append(dcs, containers{ - Name: dc.Name, - Ports: dcp, - }) + for _, d := range deployments { + dcs := []containers{} + for _, dc := range d.Spec.Template.Spec.Containers { + dcp := []ports{} + for _, p := range dc.Ports { + dcp = append(dcp, ports{Port: p.ContainerPort}) } - lServices = append(lServices, identifyServices{ - Name: d.Name, - Type: d.ObjectMeta.Labels["lagoon.sh/service-type"], - Containers: dcs, + dcs = append(dcs, containers{ + Name: dc.Name, + Ports: dcp, }) } + lServices = append(lServices, identifyServices{ + Name: d.Name, + Type: d.ObjectMeta.Labels["lagoon.sh/service-type"], + Containers: dcs, + }) } return lServices, nil } diff --git a/cmd/identify_native_cronjobs_test.go b/cmd/identify_native_cronjobs_test.go index 54e85f38..b0bef816 100644 --- a/cmd/identify_native_cronjobs_test.go +++ b/cmd/identify_native_cronjobs_test.go @@ -14,32 +14,6 @@ import ( ) func TestIdentifyNativeCronjobs(t *testing.T) { - type args struct { - alertContact string - statusPageID string - projectName string - environmentName string - branch string - prNumber string - prHeadBranch string - prBaseBranch string - environmentType string - buildType string - activeEnvironment string - standbyEnvironment string - cacheNoCache string - serviceID string - secretPrefix string - ingressClass string - rootlessWorkloads string - projectVars string - envVars string - lagoonVersion string - lagoonYAML string - valuesFilePath string - templatePath string - imageReferences map[string]string - } tests := []struct { name string args testdata.TestData diff --git a/cmd/root.go b/cmd/root.go index d9e2af1e..e88ae3cc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -87,7 +87,7 @@ var versionCmd = &cobra.Command{ } func displayVersionInfo() { - fmt.Println(fmt.Sprintf("%s %s (built: %s / go %s)", bdtName, bdtVersion, bdtBuild, goVersion)) + fmt.Printf("%s %s (built: %s / go %s)\n", bdtName, bdtVersion, bdtBuild, goVersion) } func init() { diff --git a/cmd/tasks_run.go b/cmd/tasks_run.go index b21023c9..4b4b760c 100644 --- a/cmd/tasks_run.go +++ b/cmd/tasks_run.go @@ -12,8 +12,6 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/tasklib" ) -var runPreRollout, runPostRollout, outOfClusterConfig bool - const ( preRolloutTasks = iota postRolloutTasks @@ -38,11 +36,11 @@ func unidleThenRun(namespace string, prePost string, incoming lagoon.Task) error if !incoming.RequiresEnvironment { // we don't have to kill this build if we can't bring the services up, so we just note the issue and continue fmt.Println("Namespace unidling is taking longer than expected - this might affect pre-rollout tasks that rely on multiple services") } else { - return fmt.Errorf("Unable to unidle the environment for pre-rollout tasks in time (waited %v seconds, retried %v times) - exiting as the task is defined as requiring the environment to be up.", + return fmt.Errorf("unable to unidle the environment for pre-rollout tasks in time (waited %v seconds, retried %v times) - exiting as the task is defined as requiring the environment to be up", incoming.ScaleWaitTime, incoming.ScaleMaxIterations) } default: - return fmt.Errorf("There was a problem when unidling the environment for pre-rollout tasks: %v", err.Error()) + return fmt.Errorf("there was a problem when unidling the environment for pre-rollout tasks: %v", err.Error()) } } return runCleanTaskInEnvironment(namespace, prePost, incoming) @@ -218,7 +216,7 @@ func evaluateWhenConditionsForTaskInEnvironment(environment tasklib.TaskEnvironm } retBool, okay := ret.(bool) if !okay { - err := fmt.Errorf("Expression doesn't evaluate to a boolean") + err := fmt.Errorf("expression doesn't evaluate to a boolean") if debug { fmt.Println(err.Error()) } diff --git a/cmd/template_autogen_ingress.go b/cmd/template_autogen_ingress.go index 06364728..5ab47649 100644 --- a/cmd/template_autogen_ingress.go +++ b/cmd/template_autogen_ingress.go @@ -36,7 +36,7 @@ func AutogeneratedIngressGeneration(g generator.GeneratorInput) error { for _, route := range lagoonBuild.AutogeneratedRoutes.Routes { // autogenerated routes use the `servicename` as the name of the ingress resource, use `IngressName` in routev2 to handle this if g.Debug { - fmt.Println(fmt.Sprintf("Templating autogenerated ingress manifest for %s to %s", route.Domain, fmt.Sprintf("%s/%s.yaml", savedTemplates, route.LagoonService))) + fmt.Printf("Templating autogenerated ingress manifest for %s to %s\n", route.Domain, fmt.Sprintf("%s/%s.yaml", savedTemplates, route.LagoonService)) } templateYAML, err := ingresstemplate.GenerateIngressTemplate(route, *lagoonBuild.BuildValues) if err != nil { diff --git a/cmd/template_autogen_ingress_test.go b/cmd/template_autogen_ingress_test.go index 9a300e41..63d8fbd0 100644 --- a/cmd/template_autogen_ingress_test.go +++ b/cmd/template_autogen_ingress_test.go @@ -555,7 +555,7 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", savedTemplates, err) } - fmt.Println(fmt.Sprintf("%s/%s", savedTemplates, f.Name())) + fmt.Printf("%s/%s\n", savedTemplates, f.Name()) fmt.Println(string(f1)) } t.Errorf("resulting templates do not match") diff --git a/cmd/template_dbaas.go b/cmd/template_dbaas.go index a63bbbd8..ad304602 100644 --- a/cmd/template_dbaas.go +++ b/cmd/template_dbaas.go @@ -37,9 +37,11 @@ func DBaaSTemplateGeneration(g generator.GeneratorInput, if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "dbaas"), templateYAML) - if g.Debug { - fmt.Println(fmt.Sprintf("Templating dbaas consumers to %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "dbaas"))) + if len(templateYAML) > 0 { + helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "dbaas"), templateYAML) + if g.Debug { + fmt.Printf("Templating dbaas consumers to %s\n", fmt.Sprintf("%s/%s.yaml", savedTemplates, "dbaas")) + } } return nil } diff --git a/cmd/template_dbaas_test.go b/cmd/template_dbaas_test.go index 4838f56d..b902e8e2 100644 --- a/cmd/template_dbaas_test.go +++ b/cmd/template_dbaas_test.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "io/fs" "os" "reflect" "testing" @@ -21,6 +22,7 @@ func TestDBaaSTemplateGeneration(t *testing.T) { args testdata.TestData templatePath string want string + emptyDir bool // if no templates are generated, then there will be a .gitkeep file in there wantErr bool }{ { @@ -104,6 +106,19 @@ func TestDBaaSTemplateGeneration(t *testing.T) { templatePath: "testdata/output", want: "internal/testdata/complex/dbaas-templates/dbaas-4", }, + { + name: "test7 - basic - no dbaas", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "internal/testdata/basic/lagoon.yml", + }, true), + templatePath: "testdata/output", + emptyDir: true, + want: "internal/testdata/basic/dbaas-templates/dbaas-1", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -135,11 +150,17 @@ func TestDBaaSTemplateGeneration(t *testing.T) { if err != nil { t.Errorf("couldn't read directory %v: %v", savedTemplates, err) } - results, err := os.ReadDir(tt.want) - if err != nil { - t.Errorf("couldn't read directory %v: %v", tt.want, err) + resultSize := 0 + results := []fs.DirEntry{} + if !tt.emptyDir { + results, err = os.ReadDir(tt.want) + if err != nil { + t.Errorf("couldn't read directory %v: %v", tt.want, err) + } + // .gitkeep file needs to be subtracted to equal 0 + resultSize = len(results) } - if len(files) != len(results) { + if len(files) != resultSize { for _, f := range files { f1, err := os.ReadFile(fmt.Sprintf("%s/%s", savedTemplates, f.Name())) if err != nil { diff --git a/cmd/template_ingress.go b/cmd/template_ingress.go index 993c8d40..19afe880 100644 --- a/cmd/template_ingress.go +++ b/cmd/template_ingress.go @@ -35,7 +35,7 @@ func IngressTemplateGeneration(g generator.GeneratorInput) error { // generate the templates for _, route := range lagoonBuild.MainRoutes.Routes { if g.Debug { - fmt.Println(fmt.Sprintf("Templating ingress manifest for %s to %s", route.Domain, fmt.Sprintf("%s/%s.yaml", savedTemplates, route.Domain))) + fmt.Printf("Templating ingress manifest for %s to %s\n", route.Domain, fmt.Sprintf("%s/%s.yaml", savedTemplates, route.Domain)) } templateYAML, err := ingresstemplate.GenerateIngressTemplate(route, *lagoonBuild.BuildValues) if err != nil { @@ -51,7 +51,7 @@ func IngressTemplateGeneration(g generator.GeneratorInput) error { // generate the templates for active/standby routes separately to normal routes for _, route := range lagoonBuild.ActiveStandbyRoutes.Routes { if g.Debug { - fmt.Println(fmt.Sprintf("Templating active/standby ingress manifest for %s to %s", route.Domain, fmt.Sprintf("%s/%s.yaml", savedTemplates, route.Domain))) + fmt.Printf("Templating active/standby ingress manifest for %s to %s\n", route.Domain, fmt.Sprintf("%s/%s.yaml", savedTemplates, route.Domain)) } templateYAML, err := ingresstemplate.GenerateIngressTemplate(route, *lagoonBuild.BuildValues) if err != nil { diff --git a/cmd/template_lagoonservices.go b/cmd/template_lagoonservices.go index 7c1d9d78..17b364d3 100644 --- a/cmd/template_lagoonservices.go +++ b/cmd/template_lagoonservices.go @@ -65,7 +65,7 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { separator := []byte("---\n") restoreResult := append(separator[:], serviceBytes[:]...) if g.Debug { - fmt.Println(fmt.Sprintf("Templating registry secret manifests %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, secret.Name))) + fmt.Printf("Templating registry secret manifests %s\n", fmt.Sprintf("%s/%s.yaml", savedTemplates, secret.Name)) } helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, secret.Name), restoreResult) } @@ -73,73 +73,65 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - if services != nil { - for _, d := range services { - serviceBytes, err := yaml.Marshal(d) - if err != nil { - return fmt.Errorf("couldn't generate template: %v", err) - } - separator := []byte("---\n") - restoreResult := append(separator[:], serviceBytes[:]...) - if g.Debug { - fmt.Println(fmt.Sprintf("Templating service manifests %s", fmt.Sprintf("%s/service-%s.yaml", savedTemplates, d.Name))) - } - helpers.WriteTemplateFile(fmt.Sprintf("%s/service-%s.yaml", savedTemplates, d.Name), restoreResult) + for _, d := range services { + serviceBytes, err := yaml.Marshal(d) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + separator := []byte("---\n") + restoreResult := append(separator[:], serviceBytes[:]...) + if g.Debug { + fmt.Printf("Templating service manifests %s\n", fmt.Sprintf("%s/service-%s.yaml", savedTemplates, d.Name)) } + helpers.WriteTemplateFile(fmt.Sprintf("%s/service-%s.yaml", savedTemplates, d.Name), restoreResult) } pvcs, err := servicestemplates.GeneratePVCTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - if pvcs != nil { - for _, d := range pvcs { - serviceBytes, err := yaml.Marshal(d) - if err != nil { - return fmt.Errorf("couldn't generate template: %v", err) - } - separator := []byte("---\n") - restoreResult := append(separator[:], serviceBytes[:]...) - if g.Debug { - fmt.Println(fmt.Sprintf("Templating pvc manifests %s", fmt.Sprintf("%s/pvc-%s.yaml", savedTemplates, d.Name))) - } - helpers.WriteTemplateFile(fmt.Sprintf("%s/pvc-%s.yaml", savedTemplates, d.Name), restoreResult) + for _, d := range pvcs { + serviceBytes, err := yaml.Marshal(d) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + separator := []byte("---\n") + restoreResult := append(separator[:], serviceBytes[:]...) + if g.Debug { + fmt.Printf("Templating pvc manifests %s\n", fmt.Sprintf("%s/pvc-%s.yaml", savedTemplates, d.Name)) } + helpers.WriteTemplateFile(fmt.Sprintf("%s/pvc-%s.yaml", savedTemplates, d.Name), restoreResult) } deployments, err := servicestemplates.GenerateDeploymentTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - if deployments != nil { - for _, d := range deployments { - deploymentBytes, err := yaml.Marshal(d) - if err != nil { - return fmt.Errorf("couldn't generate template: %v", err) - } - separator := []byte("---\n") - restoreResult := append(separator[:], deploymentBytes[:]...) - if g.Debug { - fmt.Println(fmt.Sprintf("Templating deployment manifests %s", fmt.Sprintf("%s/deployment-%s.yaml", savedTemplates, d.Name))) - } - helpers.WriteTemplateFile(fmt.Sprintf("%s/deployment-%s.yaml", savedTemplates, d.Name), restoreResult) + for _, d := range deployments { + deploymentBytes, err := yaml.Marshal(d) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + separator := []byte("---\n") + restoreResult := append(separator[:], deploymentBytes[:]...) + if g.Debug { + fmt.Printf("Templating deployment manifests %s\n", fmt.Sprintf("%s/deployment-%s.yaml", savedTemplates, d.Name)) } + helpers.WriteTemplateFile(fmt.Sprintf("%s/deployment-%s.yaml", savedTemplates, d.Name), restoreResult) } cronjobs, err := servicestemplates.GenerateCronjobTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - if cronjobs != nil { - for _, d := range cronjobs { - deploymentBytes, err := yaml.Marshal(d) - if err != nil { - return fmt.Errorf("couldn't generate template: %v", err) - } - separator := []byte("---\n") - restoreResult := append(separator[:], deploymentBytes[:]...) - if g.Debug { - fmt.Println(fmt.Sprintf("Templating cronjob manifests %s", fmt.Sprintf("%s/cronjob-%s.yaml", savedTemplates, d.Name))) - } - helpers.WriteTemplateFile(fmt.Sprintf("%s/cronjob-%s.yaml", savedTemplates, d.Name), restoreResult) + for _, d := range cronjobs { + deploymentBytes, err := yaml.Marshal(d) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + separator := []byte("---\n") + restoreResult := append(separator[:], deploymentBytes[:]...) + if g.Debug { + fmt.Printf("Templating cronjob manifests %s\n", fmt.Sprintf("%s/cronjob-%s.yaml", savedTemplates, d.Name)) } + helpers.WriteTemplateFile(fmt.Sprintf("%s/cronjob-%s.yaml", savedTemplates, d.Name), restoreResult) } if lagoonBuild.BuildValues.IsolationNetworkPolicy { // if isolation network policies are enabled, template that here @@ -154,7 +146,7 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { separator := []byte("---\n") restoreResult := append(separator[:], npBytes[:]...) if g.Debug { - fmt.Println(fmt.Sprintf("Templating networkpolicy manifest %s", fmt.Sprintf("%s/isolation-network-policy.yaml", savedTemplates))) + fmt.Printf("Templating networkpolicy manifest %s\n", fmt.Sprintf("%s/isolation-network-policy.yaml", savedTemplates)) } helpers.WriteTemplateFile(fmt.Sprintf("%s/isolation-network-policy.yaml", savedTemplates), restoreResult) } diff --git a/internal/testdata/basic/dbaas-templates/dbaas-1/.gitkeep b/internal/testdata/basic/dbaas-templates/dbaas-1/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 8cec086c..e038676b 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -920,7 +920,7 @@ if [ ! "$AUTOGEN_ROUTES_DISABLED" == true ]; then build-deploy-tool template autogenerated-ingress --saved-templates-path ${LAGOON_AUTOGEN_YAML_FOLDER} # apply autogenerated ingress - if [ "$(ls -A $LAGOON_AUTOGEN_YAML_FOLDER/)" ]; then + if [ -n "$(ls -A $LAGOON_AUTOGEN_YAML_FOLDER/ 2>/dev/null)" ]; then find $LAGOON_AUTOGEN_YAML_FOLDER -type f -exec cat {} \; kubectl apply -n ${NAMESPACE} -f $LAGOON_AUTOGEN_YAML_FOLDER/ fi @@ -973,18 +973,18 @@ LAGOON_DBAAS_YAML_FOLDER="/kubectl-build-deploy/lagoon/dbaas" mkdir -p $LAGOON_DBAAS_YAML_FOLDER build-deploy-tool template dbaas --saved-templates-path ${LAGOON_DBAAS_YAML_FOLDER} +# apply dbaas +if [ -n "$(ls -A $LAGOON_DBAAS_YAML_FOLDER/ 2>/dev/null)" ]; then + find $LAGOON_DBAAS_YAML_FOLDER -type f -exec cat {} \; + kubectl apply -n ${NAMESPACE} -f $LAGOON_DBAAS_YAML_FOLDER/ +fi + set +x currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "serviceConfiguration2Complete" "Service Configuration Phase 2" "false" previousStepEnd=${currentStepEnd} beginBuildStep "Route/Ingress Configuration" "configuringRoutes" -# apply dbaas -if [ "$(ls -A $LAGOON_DBAAS_YAML_FOLDER/)" ]; then - find $LAGOON_DBAAS_YAML_FOLDER -type f -exec cat {} \; - kubectl apply -n ${NAMESPACE} -f $LAGOON_DBAAS_YAML_FOLDER/ -fi - TEMPLATE_PARAMETERS=() ############################################## @@ -1011,7 +1011,7 @@ if [ ! "$CUSTOM_ROUTES_DISABLED" == true ]; then build-deploy-tool template ingress --saved-templates-path ${LAGOON_ROUTES_YAML_FOLDER} # apply the routes - if [ "$(ls -A $LAGOON_ROUTES_YAML_FOLDER/)" ]; then + if [ -n "$(ls -A $LAGOON_ROUTES_YAML_FOLDER/ 2>/dev/null)" ]; then find $LAGOON_ROUTES_YAML_FOLDER -type f -exec cat {} \; kubectl apply -n ${NAMESPACE} -f $LAGOON_ROUTES_YAML_FOLDER/ fi @@ -1422,7 +1422,7 @@ if [ ! "$BACKUPS_DISABLED" == true ]; then build-deploy-tool template backup-schedule --version v1 --saved-templates-path ${LAGOON_BACKUP_YAML_FOLDER} fi # apply backup templates - if [ "$(ls -A $LAGOON_BACKUP_YAML_FOLDER/)" ]; then + if [ -n "$(ls -A $LAGOON_BACKUP_YAML_FOLDER/ 2>/dev/null)" ]; then find $LAGOON_BACKUP_YAML_FOLDER -type f -exec cat {} \; kubectl apply -n ${NAMESPACE} -f $LAGOON_BACKUP_YAML_FOLDER/ fi @@ -1492,7 +1492,7 @@ if [ "$(ls -A $LAGOON_SERVICES_YAML_FOLDER/)" ]; then # cat $LAGOON_SERVICES_YAML_FOLDER/pvcs.yaml # cat $LAGOON_SERVICES_YAML_FOLDER/deployments.yaml # cat $LAGOON_SERVICES_YAML_FOLDER/cronjobs.yaml - if [ "$(ls -A $LAGOON_SERVICES_YAML_FOLDER/)" ]; then + if [ -n "$(ls -A $LAGOON_SERVICES_YAML_FOLDER/ 2>/dev/null)" ]; then find $LAGOON_SERVICES_YAML_FOLDER -type f -exec cat {} \; kubectl apply -n ${NAMESPACE} -f $LAGOON_SERVICES_YAML_FOLDER/ fi From 693e226ae92dde31b789fdc6de42f1f67a660fa2 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 21 Jun 2024 11:34:33 +1000 Subject: [PATCH 78/92] fix: image reference checks --- cmd/template_lagoonservices.go | 29 ++++++++++++------- cmd/template_lagoonservices_test.go | 21 ++++++++++++++ .../testdata/complex/images-service1.yaml | 6 ++++ legacy/build-deploy-docker-compose.sh | 5 ++-- 4 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 internal/testdata/complex/images-service1.yaml diff --git a/cmd/template_lagoonservices.go b/cmd/template_lagoonservices.go index 17b364d3..2efc7df4 100644 --- a/cmd/template_lagoonservices.go +++ b/cmd/template_lagoonservices.go @@ -1,9 +1,8 @@ package cmd import ( - "encoding/base64" - "encoding/json" "fmt" + "os" "github.com/spf13/cobra" generator "github.com/uselagoon/build-deploy-tool/internal/generator" @@ -14,6 +13,10 @@ import ( "sigs.k8s.io/yaml" ) +type ImageReferences struct { + Images map[string]string `json:"images"` +} + var lagoonServiceGeneration = &cobra.Command{ Use: "lagoon-services", Aliases: []string{"ls"}, @@ -27,21 +30,27 @@ var lagoonServiceGeneration = &cobra.Command{ if err != nil { return fmt.Errorf("error reading images flag: %v", err) } - var imageRefs struct { - Images map[string]string `json:"images"` - } - imagesStr, err := base64.StdEncoding.DecodeString(images) + imageRefs, err := loadImagesFromFile(images) if err != nil { - return fmt.Errorf("error decoding images payload: %v", err) - } - if err := json.Unmarshal(imagesStr, &imageRefs); err != nil { - return fmt.Errorf("error unmarshalling images payload: %v", err) + return err } gen.ImageReferences = imageRefs.Images return LagoonServiceTemplateGeneration(gen) }, } +func loadImagesFromFile(file string) (*ImageReferences, error) { + imageRefs := &ImageReferences{} + imageYAML, err := os.ReadFile(file) + if err != nil { + return nil, fmt.Errorf("couldn't read file %v: %v", file, err) + } + if err := yaml.Unmarshal(imageYAML, imageRefs); err != nil { + return nil, fmt.Errorf("error unmarshalling images payload: %v", err) + } + return imageRefs, nil +} + // LagoonServiceTemplateGeneration . func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { lagoonBuild, err := generator.NewGenerator( diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index d308416a..e5e5d659 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -23,6 +23,7 @@ func TestTemplateLagoonServices(t *testing.T) { args testdata.TestData templatePath string want string + imageData string vars []helpers.EnvironmentVariable }{ { @@ -86,6 +87,19 @@ func TestTemplateLagoonServices(t *testing.T) { templatePath: "testoutput", want: "internal/testdata/complex/service-templates/service1", }, + { + name: "test2a1 nginx-php deployment using images from images.yaml file (same as test2a result)", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", + }, true), + imageData: "internal/testdata/complex/images-service1.yaml", + templatePath: "testoutput", + want: "internal/testdata/complex/service-templates/service1", + }, { name: "test2b nginx-php deployment - rootless", args: testdata.GetSeedData( @@ -295,6 +309,13 @@ func TestTemplateLagoonServices(t *testing.T) { t.Errorf("%v", err) } + if tt.imageData != "" { + imageRefs, err := loadImagesFromFile(tt.imageData) + if err != nil { + t.Errorf("%v", err) + } + generator.ImageReferences = imageRefs.Images + } err = LagoonServiceTemplateGeneration(generator) if err != nil { t.Errorf("%v", err) diff --git a/internal/testdata/complex/images-service1.yaml b/internal/testdata/complex/images-service1.yaml new file mode 100644 index 00000000..4b242ea0 --- /dev/null +++ b/internal/testdata/complex/images-service1.yaml @@ -0,0 +1,6 @@ +images: + nginx: harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + php: harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + cli: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + redis: harbor.example/example-project/main/redis@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + varnish: harbor.example/example-project/main/varnish@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 \ No newline at end of file diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index e038676b..bf2580ae 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -1349,6 +1349,7 @@ if [ "$BUILD_TYPE" == "pullrequest" ] || [ "$BUILD_TYPE" == "branch" ]; then # load the image hashes for just pushed images for IMAGE_NAME in "${!IMAGES_BUILD[@]}" do + PUSH_IMAGE="${IMAGES_PUSH[${IMAGE_NAME}]}" #extract the push image name from the images to push list JQ_QUERY=(jq -r ".[]|select(test(\"${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}@\"))") IMAGE_HASHES[${IMAGE_NAME}]=$(docker inspect ${PUSH_IMAGE} --format '{{json .RepoDigests}}' | "${JQ_QUERY[@]}") done @@ -1445,7 +1446,7 @@ touch /kubectl-build-deploy/images.yaml for COMPOSE_SERVICE in "${COMPOSE_SERVICES[@]}" do SERVICE_NAME_IMAGE_HASH="${IMAGE_HASHES[${COMPOSE_SERVICE}]}" - yq3 write -i -- /kubectl-build-deploy/images.yaml 'images.'$COMPOSE_SERVICE'' ${SERVICE_NAME_IMAGE_HASH} + yq -i '.images.'$COMPOSE_SERVICE' = "'${SERVICE_NAME_IMAGE_HASH}'"' /kubectl-build-deploy/images.yaml done # handle dynamic secret collection here, @TODO this will go into the state collector eventually @@ -1467,7 +1468,7 @@ done echo "=== BEGIN deployment template for services ===" LAGOON_SERVICES_YAML_FOLDER="/kubectl-build-deploy/lagoon/service-deployments" mkdir -p $LAGOON_SERVICES_YAML_FOLDER -build-deploy-tool template lagoon-services --saved-templates-path ${LAGOON_SERVICES_YAML_FOLDER} --images $(yq3 r -j /kubectl-build-deploy/images.yaml | jq -M -c | base64 -w0) +build-deploy-tool template lagoon-services --saved-templates-path ${LAGOON_SERVICES_YAML_FOLDER} --images /kubectl-build-deploy/images.yaml currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")" patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "deploymentTemplatingComplete" "Deployment Templating" "false" From 8bca88616bd41e9efaa1372ebcf4caa0ed9bfc71 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 25 Jun 2024 16:06:14 +1000 Subject: [PATCH 79/92] fix: long branch domain truncating hash --- cmd/template_autogen_ingress_test.go | 12 +++++ internal/generator/ingress.go | 2 +- .../autogen-templates/ingress-1/nginx.yaml | 47 +++++++++++++++++++ .../testdata/basic/docker-compose.nginx.yml | 20 ++++++++ internal/testdata/basic/lagoon.nginx.yml | 10 ++++ 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 internal/testdata/basic/autogen-templates/ingress-1/nginx.yaml create mode 100644 internal/testdata/basic/docker-compose.nginx.yml create mode 100644 internal/testdata/basic/lagoon.nginx.yml diff --git a/cmd/template_autogen_ingress_test.go b/cmd/template_autogen_ingress_test.go index 63d8fbd0..38263658 100644 --- a/cmd/template_autogen_ingress_test.go +++ b/cmd/template_autogen_ingress_test.go @@ -483,6 +483,18 @@ func TestAutogeneratedIngressGeneration(t *testing.T) { emptyDir: true, want: "", }, + { + name: "test27 autogenerated routes longbranch", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "abc-skyforce", + EnvironmentName: "feature-skycms-10626-update-permissions-b-b92f", + Branch: "feature/skycms-10626-update-permissions-by-term", + LagoonYAML: "internal/testdata/basic/lagoon.nginx.yml", + }, true), + templatePath: "testoutput", + want: "internal/testdata/basic/autogen-templates/ingress-1", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/generator/ingress.go b/internal/generator/ingress.go index 9f452761..91a97ea8 100644 --- a/internal/generator/ingress.go +++ b/internal/generator/ingress.go @@ -224,7 +224,7 @@ func autogeneratedDomainFromPattern(pattern, service, projectName, environmentNa } domainParts := strings.Split(domain, ".") - domainHash := helpers.GetSha256Hash(domain) + domainHash := helpers.GetBase32EncodedLowercase(helpers.GetSha256Hash(domain)) finalDomain := "" for count, part := range domainParts { domainPart := part diff --git a/internal/testdata/basic/autogen-templates/ingress-1/nginx.yaml b/internal/testdata/basic/autogen-templates/ingress-1/nginx.yaml new file mode 100644 index 00000000..43611fbe --- /dev/null +++ b/internal/testdata/basic/autogen-templates/ingress-1/nginx.yaml @@ -0,0 +1,47 @@ +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + fastly.amazee.io/watch: "false" + ingress.kubernetes.io/ssl-redirect: "false" + kubernetes.io/tls-acme: "true" + lagoon.sh/branch: feature/skycms-10626-update-permissions-by-term + lagoon.sh/version: v2.7.x + monitor.stakater.com/enabled: "false" + nginx.ingress.kubernetes.io/server-snippet: | + add_header X-Robots-Tag "noindex, nofollow"; + nginx.ingress.kubernetes.io/ssl-redirect: "false" + creationTimestamp: null + labels: + app.kubernetes.io/instance: nginx + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: autogenerated-ingress + helm.sh/chart: autogenerated-ingress-0.1.0 + lagoon.sh/autogenerated: "true" + lagoon.sh/buildType: branch + lagoon.sh/environment: feature-skycms-10626-update-permissions-b-b92f + lagoon.sh/environmentType: production + lagoon.sh/project: abc-skyforce + lagoon.sh/service: nginx + lagoon.sh/service-type: basic + name: nginx +spec: + rules: + - host: nginx-abc-skyforce-feature-skycms-10626-update-permiss-pzsnrv3o.example.com + http: + paths: + - backend: + service: + name: nginx + port: + name: tcp-8080 + path: / + pathType: Prefix + tls: + - hosts: + - nginx-g47wgggi-7ntzklib.example.com + - nginx-abc-skyforce-feature-skycms-10626-update-permiss-pzsnrv3o.example.com + secretName: nginx-tls +status: + loadBalancer: {} diff --git a/internal/testdata/basic/docker-compose.nginx.yml b/internal/testdata/basic/docker-compose.nginx.yml new file mode 100644 index 00000000..2cd50ffb --- /dev/null +++ b/internal/testdata/basic/docker-compose.nginx.yml @@ -0,0 +1,20 @@ +version: '2' +services: + nginx: + networks: + - amazeeio-network + - default + build: + context: internal/testdata/basic/docker + dockerfile: basic.dockerfile + labels: + lagoon.type: basic + lagoon.service.usecomposeports: true + volumes: + - .:/app:delegated + ports: + - '8080' + +networks: + amazeeio-network: + external: true \ No newline at end of file diff --git a/internal/testdata/basic/lagoon.nginx.yml b/internal/testdata/basic/lagoon.nginx.yml new file mode 100644 index 00000000..3eed5847 --- /dev/null +++ b/internal/testdata/basic/lagoon.nginx.yml @@ -0,0 +1,10 @@ +docker-compose-yaml: internal/testdata/basic/docker-compose.nginx.yml + +environment_variables: + git_sha: "true" + +environments: + main: + routes: + - node: + - example.com From bf7b8dac02a94fd0343f0069f678cc79ff515b3f Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 27 Jun 2024 10:14:21 +1000 Subject: [PATCH 80/92] fix: network policy --- internal/templating/networkpolicy/template_networkpolicy.go | 2 ++ .../templating/networkpolicy/test-resources/result-np-1.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/templating/networkpolicy/template_networkpolicy.go b/internal/templating/networkpolicy/template_networkpolicy.go index 60f5011e..9e5f3016 100644 --- a/internal/templating/networkpolicy/template_networkpolicy.go +++ b/internal/templating/networkpolicy/template_networkpolicy.go @@ -49,6 +49,8 @@ func GenerateNetworkPolicy( From: []networkv1.NetworkPolicyPeer{ { PodSelector: &metav1.LabelSelector{}, + }, + { NamespaceSelector: &metav1.LabelSelector{ MatchExpressions: []metav1.LabelSelectorRequirement{ { diff --git a/internal/templating/networkpolicy/test-resources/result-np-1.yaml b/internal/templating/networkpolicy/test-resources/result-np-1.yaml index 4495a11c..5af02b6a 100644 --- a/internal/templating/networkpolicy/test-resources/result-np-1.yaml +++ b/internal/templating/networkpolicy/test-resources/result-np-1.yaml @@ -16,9 +16,9 @@ metadata: spec: ingress: - from: + - podSelector: {} - namespaceSelector: matchExpressions: - key: lagoon.sh/environment operator: DoesNotExist - podSelector: {} podSelector: {} From 5371cd31a482a5a5df3a84f93d54c25e9cf670ac Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 27 Jun 2024 10:15:06 +1000 Subject: [PATCH 81/92] fix: imagepullpolicy, recreate strategy for redis, and empty seccontext --- internal/servicetypes/basic.go | 1 + internal/servicetypes/cli.go | 5 +++-- internal/servicetypes/elasticsearch.go | 1 + internal/servicetypes/mariadb.go | 1 + internal/servicetypes/mongodb.go | 1 + internal/servicetypes/nginx.go | 3 +++ internal/servicetypes/node.go | 1 + internal/servicetypes/opensearch.go | 1 + internal/servicetypes/postgres.go | 1 + internal/servicetypes/python.go | 1 + internal/servicetypes/rabbitmq.go | 1 + internal/servicetypes/redis.go | 5 +++++ internal/servicetypes/solr.go | 1 + internal/servicetypes/varnish.go | 1 + internal/servicetypes/worker.go | 3 +-- .../services/test-resources/cronjob/result-cli-1.yaml | 6 ++++++ .../services/test-resources/deployment/result-basic-1.yaml | 5 +++++ .../services/test-resources/deployment/result-basic-2.yaml | 1 + .../services/test-resources/deployment/result-basic-3.yaml | 1 + .../services/test-resources/deployment/result-cli-1.yaml | 4 ++++ .../test-resources/deployment/result-elasticsearch-1.yaml | 2 ++ .../test-resources/deployment/result-mariadb-1.yaml | 1 + .../test-resources/deployment/result-mongodb-1.yaml | 1 + .../services/test-resources/deployment/result-nginx-1.yaml | 4 ++++ .../services/test-resources/deployment/result-nginx-2.yaml | 4 ++++ .../services/test-resources/deployment/result-node-1.yaml | 2 ++ .../test-resources/deployment/result-opensearch-1.yaml | 2 ++ .../test-resources/deployment/result-postgres-1.yaml | 1 + .../test-resources/deployment/result-postgres-single-1.yaml | 1 + .../services/test-resources/deployment/result-python-1.yaml | 2 ++ .../test-resources/deployment/result-rabbitmq-1.yaml | 1 + .../services/test-resources/deployment/result-redis-1.yaml | 5 ++++- .../services/test-resources/deployment/result-solr-1.yaml | 1 + .../test-resources/deployment/result-varnish-1.yaml | 2 ++ .../services/test-resources/deployment/result-worker-1.yaml | 2 ++ .../basic/service-templates/service1/deployment-node.yaml | 1 + .../basic/service-templates/service2/deployment-lnd.yaml | 1 + .../service-templates/service2/deployment-thunderhub.yaml | 1 + .../basic/service-templates/service2/deployment-tor.yaml | 1 + .../basic/service-templates/service3/deployment-lnd.yaml | 1 + .../basic/service-templates/service3/deployment-tor.yaml | 1 + .../basic/service-templates/service4/deployment-node.yaml | 1 + .../basic/service-templates/service5/deployment-node.yaml | 1 + .../service5/isolation-network-policy.yaml | 2 +- .../basic/service-templates/service6/deployment-node.yaml | 1 + .../service1/cronjob-cronjob-cli-drush-cron2.yaml | 2 ++ .../complex/service-templates/service1/deployment-cli.yaml | 2 ++ .../service-templates/service1/deployment-nginx-php.yaml | 2 ++ .../service-templates/service1/deployment-redis.yaml | 1 + .../service-templates/service1/deployment-varnish.yaml | 1 + .../service2/cronjob-cronjob-cli-drush-cron2.yaml | 2 ++ .../complex/service-templates/service2/deployment-cli.yaml | 2 ++ .../service-templates/service2/deployment-nginx-php.yaml | 2 ++ .../service-templates/service2/deployment-redis.yaml | 1 + .../service-templates/service2/deployment-varnish.yaml | 1 + .../service-templates/service3/deployment-mariadb-10-5.yaml | 1 + .../service-templates/service3/deployment-opensearch-2.yaml | 1 + .../service-templates/service3/deployment-postgres-11.yaml | 1 + .../service-templates/service3/deployment-redis-6.yaml | 1 + .../service-templates/service3/deployment-redis-7.yaml | 1 + .../service-templates/service3/deployment-solr-8.yaml | 1 + .../complex/service-templates/service3/deployment-web.yaml | 1 + .../service4/deployment-mariadb-10-11.yaml | 1 + .../service-templates/service4/deployment-mariadb-10-5.yaml | 1 + .../service-templates/service4/deployment-mongo-4.yaml | 1 + .../service-templates/service4/deployment-postgres-11.yaml | 1 + .../service-templates/service4/deployment-postgres-15.yaml | 1 + 67 files changed, 108 insertions(+), 6 deletions(-) diff --git a/internal/servicetypes/basic.go b/internal/servicetypes/basic.go index f85dc07b..0bb7133e 100644 --- a/internal/servicetypes/basic.go +++ b/internal/servicetypes/basic.go @@ -29,6 +29,7 @@ var basic = ServiceType{ Name: "basic", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: "basic", diff --git a/internal/servicetypes/cli.go b/internal/servicetypes/cli.go index bcbde51c..755fffcd 100644 --- a/internal/servicetypes/cli.go +++ b/internal/servicetypes/cli.go @@ -10,8 +10,7 @@ import ( var cli = ServiceType{ Name: "cli", PrimaryContainer: ServiceContainer{ - Name: "cli", - ImagePullPolicy: corev1.PullAlways, + Name: "cli", Volumes: []corev1.Volume{ { Name: "lagoon-sshkey", @@ -24,6 +23,8 @@ var cli = ServiceType{ }, }, Container: corev1.Container{ + ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, VolumeMounts: []corev1.VolumeMount{ { Name: "lagoon-sshkey", diff --git a/internal/servicetypes/elasticsearch.go b/internal/servicetypes/elasticsearch.go index 14a73f00..2e60917d 100644 --- a/internal/servicetypes/elasticsearch.go +++ b/internal/servicetypes/elasticsearch.go @@ -31,6 +31,7 @@ var elasticsearch = ServiceType{ Name: "elasticsearch", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: fmt.Sprintf("%d-tcp", defaultElasticsearchPort), diff --git a/internal/servicetypes/mariadb.go b/internal/servicetypes/mariadb.go index 269d8c25..1811f35f 100644 --- a/internal/servicetypes/mariadb.go +++ b/internal/servicetypes/mariadb.go @@ -30,6 +30,7 @@ var mariadbSingle = ServiceType{ Name: "mariadb-single", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: fmt.Sprintf("%d-tcp", defaultMariaDBPort), diff --git a/internal/servicetypes/mongodb.go b/internal/servicetypes/mongodb.go index f9c2caf3..b1ce8bff 100644 --- a/internal/servicetypes/mongodb.go +++ b/internal/servicetypes/mongodb.go @@ -30,6 +30,7 @@ var mongodbSingle = ServiceType{ Name: "mongodb-single", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: fmt.Sprintf("%d-tcp", defaultMongoDBPort), diff --git a/internal/servicetypes/nginx.go b/internal/servicetypes/nginx.go index 98d27434..c5ad261a 100644 --- a/internal/servicetypes/nginx.go +++ b/internal/servicetypes/nginx.go @@ -29,6 +29,7 @@ var nginx = ServiceType{ Name: "nginx", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: "http", @@ -80,6 +81,7 @@ var nginxPHP = ServiceType{ Name: "nginx", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: "http", @@ -132,6 +134,7 @@ var nginxPHP = ServiceType{ Name: "php", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: "http", diff --git a/internal/servicetypes/node.go b/internal/servicetypes/node.go index a28f4822..f126b5ef 100644 --- a/internal/servicetypes/node.go +++ b/internal/servicetypes/node.go @@ -27,6 +27,7 @@ var node = ServiceType{ Name: "node", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: "http", diff --git a/internal/servicetypes/opensearch.go b/internal/servicetypes/opensearch.go index 58009555..0388d6a6 100644 --- a/internal/servicetypes/opensearch.go +++ b/internal/servicetypes/opensearch.go @@ -31,6 +31,7 @@ var opensearch = ServiceType{ Name: "opensearch", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: fmt.Sprintf("%d-tcp", defaultOpensearchPort), diff --git a/internal/servicetypes/postgres.go b/internal/servicetypes/postgres.go index 4afa7112..c3c8e58c 100644 --- a/internal/servicetypes/postgres.go +++ b/internal/servicetypes/postgres.go @@ -31,6 +31,7 @@ var postgresSingle = ServiceType{ Name: "postgres", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: fmt.Sprintf("%d-tcp", defaultPostgresPort), diff --git a/internal/servicetypes/python.go b/internal/servicetypes/python.go index 0d6987b6..3f49bb34 100644 --- a/internal/servicetypes/python.go +++ b/internal/servicetypes/python.go @@ -27,6 +27,7 @@ var python = ServiceType{ Name: "python", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: "http", diff --git a/internal/servicetypes/rabbitmq.go b/internal/servicetypes/rabbitmq.go index d977a0e7..aa62db9a 100644 --- a/internal/servicetypes/rabbitmq.go +++ b/internal/servicetypes/rabbitmq.go @@ -40,6 +40,7 @@ var rabbitmq = ServiceType{ Name: "rabbitmq", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: fmt.Sprintf("%d-tcp", defaultRabbitMQPort), diff --git a/internal/servicetypes/redis.go b/internal/servicetypes/redis.go index 87dcdde0..0a29877a 100644 --- a/internal/servicetypes/redis.go +++ b/internal/servicetypes/redis.go @@ -3,6 +3,7 @@ package servicetypes import ( "fmt" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" @@ -29,6 +30,7 @@ var redis = ServiceType{ Name: "redis", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: fmt.Sprintf("%d-tcp", defaultRedisPort), @@ -86,4 +88,7 @@ var redisPersistent = ServiceType{ FileExtension: ".{{ .ServiceValues.OverrideName }}.tar", }, }, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RecreateDeploymentStrategyType, + }, } diff --git a/internal/servicetypes/solr.go b/internal/servicetypes/solr.go index 7a60e42f..36ae6eeb 100644 --- a/internal/servicetypes/solr.go +++ b/internal/servicetypes/solr.go @@ -29,6 +29,7 @@ var solr = ServiceType{ Name: "solr", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: fmt.Sprintf("%d-tcp", defaultSolrPort), diff --git a/internal/servicetypes/varnish.go b/internal/servicetypes/varnish.go index 3495a5f1..4abfc190 100644 --- a/internal/servicetypes/varnish.go +++ b/internal/servicetypes/varnish.go @@ -38,6 +38,7 @@ var varnish = ServiceType{ Name: "varnish", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { Name: "http", diff --git a/internal/servicetypes/worker.go b/internal/servicetypes/worker.go index b65425d6..1ed69796 100644 --- a/internal/servicetypes/worker.go +++ b/internal/servicetypes/worker.go @@ -5,14 +5,13 @@ import ( "k8s.io/apimachinery/pkg/api/resource" ) -var defaultWorkerPort int32 = 3000 - var worker = ServiceType{ Name: "worker", PrimaryContainer: ServiceContainer{ Name: "worker", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, + SecurityContext: &corev1.SecurityContext{}, ReadinessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ Exec: &corev1.ExecAction{ diff --git a/internal/templating/services/test-resources/cronjob/result-cli-1.yaml b/internal/templating/services/test-resources/cronjob/result-cli-1.yaml index 6fd4aaab..5229e4a2 100644 --- a/internal/templating/services/test-resources/cronjob/result-cli-1.yaml +++ b/internal/templating/services/test-resources/cronjob/result-cli-1.yaml @@ -53,11 +53,13 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice@latest + imagePullPolicy: Always name: cronjob-myservice-my-cronjobbb resources: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ name: lagoon-sshkey @@ -137,11 +139,13 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice@latest + imagePullPolicy: Always name: cronjob-myservice-my-other-cronjobbb resources: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ name: lagoon-sshkey @@ -221,11 +225,13 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice-persistent@latest + imagePullPolicy: Always name: cronjob-myservice-my-cronjobbb resources: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ name: lagoon-sshkey diff --git a/internal/templating/services/test-resources/deployment/result-basic-1.yaml b/internal/templating/services/test-resources/deployment/result-basic-1.yaml index 8f1dc300..fc832738 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-1.yaml @@ -76,6 +76,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret @@ -166,6 +167,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret @@ -253,6 +255,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /storage/data name: basic @@ -340,6 +343,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /storage/data name: basic @@ -427,6 +431,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /storage/data name: basic diff --git a/internal/templating/services/test-resources/deployment/result-basic-2.yaml b/internal/templating/services/test-resources/deployment/result-basic-2.yaml index e6f51315..9f112a0c 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-2.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-2.yaml @@ -86,6 +86,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret diff --git a/internal/templating/services/test-resources/deployment/result-basic-3.yaml b/internal/templating/services/test-resources/deployment/result-basic-3.yaml index 11f096e8..8fc74101 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-3.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-3.yaml @@ -90,6 +90,7 @@ spec: cpu: 10m ephemeral-storage: 1Gi memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret diff --git a/internal/templating/services/test-resources/deployment/result-cli-1.yaml b/internal/templating/services/test-resources/deployment/result-cli-1.yaml index 44a9f20a..19e88447 100644 --- a/internal/templating/services/test-resources/deployment/result-cli-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-cli-1.yaml @@ -53,6 +53,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice@latest + imagePullPolicy: Always name: cli readinessProbe: exec: @@ -68,6 +69,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ name: lagoon-sshkey @@ -137,6 +139,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example.com/example-project/environment-name/myservice-persist@latest + imagePullPolicy: Always name: cli readinessProbe: exec: @@ -152,6 +155,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ name: lagoon-sshkey diff --git a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml index 903df580..4944fcf7 100644 --- a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml @@ -77,6 +77,7 @@ spec: requests: cpu: 10m memory: 10Mi + securityContext: {} volumeMounts: - mountPath: /usr/share/elasticsearch/data name: myservice @@ -186,6 +187,7 @@ spec: requests: cpu: 10m memory: 10Mi + securityContext: {} volumeMounts: - mountPath: /usr/share/elasticsearch/data name: myservice-size diff --git a/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml b/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml index 882f3d2c..70ebb4b6 100644 --- a/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml @@ -78,6 +78,7 @@ spec: requests: cpu: 10m memory: 10Mi + securityContext: {} volumeMounts: - mountPath: /var/lib/mysql name: mariadb diff --git a/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml b/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml index 3e1850a1..32a6e70d 100644 --- a/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml @@ -77,6 +77,7 @@ spec: requests: cpu: 10m memory: 10Mi + securityContext: {} volumeMounts: - mountPath: /data/db name: mongodb diff --git a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml index 037bde1a..9f9896bf 100644 --- a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml @@ -78,6 +78,7 @@ spec: requests: cpu: 10m memory: 10M + securityContext: {} - env: - name: NGINX_FASTCGI_PASS value: 127.0.0.1 @@ -107,6 +108,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret @@ -196,6 +198,7 @@ spec: requests: cpu: 10m memory: 10M + securityContext: {} volumeMounts: - mountPath: /storage/data name: nginx2 @@ -228,6 +231,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /storage/data name: nginx2 diff --git a/internal/templating/services/test-resources/deployment/result-nginx-2.yaml b/internal/templating/services/test-resources/deployment/result-nginx-2.yaml index 69265610..e549ad32 100644 --- a/internal/templating/services/test-resources/deployment/result-nginx-2.yaml +++ b/internal/templating/services/test-resources/deployment/result-nginx-2.yaml @@ -78,6 +78,7 @@ spec: requests: cpu: 10m memory: 10M + securityContext: {} - env: - name: NGINX_FASTCGI_PASS value: 127.0.0.1 @@ -107,6 +108,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret @@ -197,6 +199,7 @@ spec: requests: cpu: 10m memory: 10M + securityContext: {} volumeMounts: - mountPath: /storage/data name: nginx2 @@ -229,6 +232,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /storage/data name: nginx2 diff --git a/internal/templating/services/test-resources/deployment/result-node-1.yaml b/internal/templating/services/test-resources/deployment/result-node-1.yaml index 2994ca9b..7b656cec 100644 --- a/internal/templating/services/test-resources/deployment/result-node-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-node-1.yaml @@ -73,6 +73,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret @@ -158,6 +159,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: "" name: node-persist diff --git a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml index a65aa3ce..58e143a4 100644 --- a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml @@ -77,6 +77,7 @@ spec: requests: cpu: 10m memory: 10Mi + securityContext: {} volumeMounts: - mountPath: /usr/share/opensearch/data name: myservice @@ -186,6 +187,7 @@ spec: requests: cpu: 10m memory: 10Mi + securityContext: {} volumeMounts: - mountPath: /usr/share/opensearch/data name: myservice-size diff --git a/internal/templating/services/test-resources/deployment/result-postgres-1.yaml b/internal/templating/services/test-resources/deployment/result-postgres-1.yaml index 17e1362c..d316900c 100644 --- a/internal/templating/services/test-resources/deployment/result-postgres-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-postgres-1.yaml @@ -78,6 +78,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/lib/postgresql/data name: postgres diff --git a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml index 0dbb9d70..dc8acec2 100644 --- a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml @@ -78,6 +78,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/lib/postgresql/data name: myservice diff --git a/internal/templating/services/test-resources/deployment/result-python-1.yaml b/internal/templating/services/test-resources/deployment/result-python-1.yaml index ca878909..81cc9b2d 100644 --- a/internal/templating/services/test-resources/deployment/result-python-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-python-1.yaml @@ -73,6 +73,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret @@ -158,6 +159,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: "" name: python-persist diff --git a/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml b/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml index df7e7711..72970c6e 100644 --- a/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml @@ -80,6 +80,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/lib/rabbitmq name: rabbitmq diff --git a/internal/templating/services/test-resources/deployment/result-redis-1.yaml b/internal/templating/services/test-resources/deployment/result-redis-1.yaml index 960d1193..98104ecc 100644 --- a/internal/templating/services/test-resources/deployment/result-redis-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-redis-1.yaml @@ -73,6 +73,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret @@ -109,7 +110,8 @@ spec: matchLabels: app.kubernetes.io/instance: redis-persist app.kubernetes.io/name: redis-persistent - strategy: {} + strategy: + type: Recreate template: metadata: annotations: @@ -161,6 +163,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /data name: redis-persist diff --git a/internal/templating/services/test-resources/deployment/result-solr-1.yaml b/internal/templating/services/test-resources/deployment/result-solr-1.yaml index 4ed8aa59..62bb1130 100644 --- a/internal/templating/services/test-resources/deployment/result-solr-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-solr-1.yaml @@ -77,6 +77,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/solr name: solr diff --git a/internal/templating/services/test-resources/deployment/result-varnish-1.yaml b/internal/templating/services/test-resources/deployment/result-varnish-1.yaml index 6ff72a00..c1c32dd4 100644 --- a/internal/templating/services/test-resources/deployment/result-varnish-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-varnish-1.yaml @@ -76,6 +76,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret @@ -167,6 +168,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/cache/varnish name: varnish-persist diff --git a/internal/templating/services/test-resources/deployment/result-worker-1.yaml b/internal/templating/services/test-resources/deployment/result-worker-1.yaml index d48efeae..0f262ecf 100644 --- a/internal/templating/services/test-resources/deployment/result-worker-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-worker-1.yaml @@ -69,6 +69,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ name: lagoon-sshkey @@ -154,6 +155,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ name: lagoon-sshkey diff --git a/internal/testdata/basic/service-templates/service1/deployment-node.yaml b/internal/testdata/basic/service-templates/service1/deployment-node.yaml index 86b88406..9d3894e6 100644 --- a/internal/testdata/basic/service-templates/service1/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service1/deployment-node.yaml @@ -79,6 +79,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret diff --git a/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml index d9fa6b9d..d21eb004 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml @@ -76,6 +76,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /app/storage name: lnd diff --git a/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml index b5c9c179..2b9edfcb 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml @@ -73,6 +73,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /data name: lnd diff --git a/internal/testdata/basic/service-templates/service2/deployment-tor.yaml b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml index f7550505..c17594fa 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-tor.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml @@ -76,6 +76,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret diff --git a/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml index d9fa6b9d..d21eb004 100644 --- a/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml +++ b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml @@ -76,6 +76,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /app/storage name: lnd diff --git a/internal/testdata/basic/service-templates/service3/deployment-tor.yaml b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml index ac21f790..8c0a7957 100644 --- a/internal/testdata/basic/service-templates/service3/deployment-tor.yaml +++ b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml @@ -69,6 +69,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ name: lagoon-sshkey diff --git a/internal/testdata/basic/service-templates/service4/deployment-node.yaml b/internal/testdata/basic/service-templates/service4/deployment-node.yaml index 941ee4d1..316cf196 100644 --- a/internal/testdata/basic/service-templates/service4/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service4/deployment-node.yaml @@ -77,6 +77,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret diff --git a/internal/testdata/basic/service-templates/service5/deployment-node.yaml b/internal/testdata/basic/service-templates/service5/deployment-node.yaml index d300f037..2a70993c 100644 --- a/internal/testdata/basic/service-templates/service5/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service5/deployment-node.yaml @@ -83,6 +83,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret diff --git a/internal/testdata/basic/service-templates/service5/isolation-network-policy.yaml b/internal/testdata/basic/service-templates/service5/isolation-network-policy.yaml index d93bc282..d333ee32 100644 --- a/internal/testdata/basic/service-templates/service5/isolation-network-policy.yaml +++ b/internal/testdata/basic/service-templates/service5/isolation-network-policy.yaml @@ -18,9 +18,9 @@ metadata: spec: ingress: - from: + - podSelector: {} - namespaceSelector: matchExpressions: - key: lagoon.sh/environment operator: DoesNotExist - podSelector: {} podSelector: {} diff --git a/internal/testdata/basic/service-templates/service6/deployment-node.yaml b/internal/testdata/basic/service-templates/service6/deployment-node.yaml index 0f78afd6..75f0cd2a 100644 --- a/internal/testdata/basic/service-templates/service6/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service6/deployment-node.yaml @@ -81,6 +81,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/dynamic/insights-token name: dynamic-insights-token diff --git a/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml b/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml index 0346bbec..00a1094f 100644 --- a/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml +++ b/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml @@ -53,11 +53,13 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always name: cronjob-cli-drush-cron2 resources: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ name: lagoon-sshkey diff --git a/internal/testdata/complex/service-templates/service1/deployment-cli.yaml b/internal/testdata/complex/service-templates/service1/deployment-cli.yaml index 1bcf72e1..c40c2a8d 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-cli.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-cli.yaml @@ -55,6 +55,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always name: cli readinessProbe: exec: @@ -70,6 +71,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ name: lagoon-sshkey diff --git a/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml index 35657621..d0522b6e 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml @@ -78,6 +78,7 @@ spec: requests: cpu: 10m memory: 10M + securityContext: {} volumeMounts: - mountPath: /app/docroot/sites/default/files/ name: nginx-php @@ -110,6 +111,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /app/docroot/sites/default/files/ name: nginx-php diff --git a/internal/testdata/complex/service-templates/service1/deployment-redis.yaml b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml index 3fe947cb..42ecec1d 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-redis.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml @@ -73,6 +73,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret diff --git a/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml index c726d705..2a06cab6 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml @@ -76,6 +76,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret diff --git a/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml b/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml index 9dc51457..6f4b8bdc 100644 --- a/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml +++ b/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml @@ -53,11 +53,13 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always name: cronjob-cli-drush-cron2 resources: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ name: lagoon-sshkey diff --git a/internal/testdata/complex/service-templates/service2/deployment-cli.yaml b/internal/testdata/complex/service-templates/service2/deployment-cli.yaml index f023e948..cdb39551 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-cli.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-cli.yaml @@ -55,6 +55,7 @@ spec: - configMapRef: name: lagoon-env image: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 + imagePullPolicy: Always name: cli readinessProbe: exec: @@ -70,6 +71,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ name: lagoon-sshkey diff --git a/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml index 31f4bda3..1c7ad25e 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml @@ -78,6 +78,7 @@ spec: requests: cpu: 10m memory: 10M + securityContext: {} volumeMounts: - mountPath: /app/docroot/sites/default/files/ name: nginx-php @@ -110,6 +111,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /app/docroot/sites/default/files/ name: nginx-php diff --git a/internal/testdata/complex/service-templates/service2/deployment-redis.yaml b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml index 58afe308..340b9e61 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-redis.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml @@ -73,6 +73,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret diff --git a/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml index 242ec6b6..2322c53e 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml @@ -76,6 +76,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret diff --git a/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml index 34906f06..feec72d3 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml @@ -78,6 +78,7 @@ spec: requests: cpu: 10m memory: 10Mi + securityContext: {} volumeMounts: - mountPath: /var/lib/mysql name: mariadb-10-5 diff --git a/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml b/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml index b1e29b57..612e4c18 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml @@ -77,6 +77,7 @@ spec: requests: cpu: 10m memory: 10Mi + securityContext: {} volumeMounts: - mountPath: /usr/share/opensearch/data name: opensearch-2 diff --git a/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml b/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml index 3cafd9cc..b6f224e3 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml @@ -78,6 +78,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/lib/postgresql/data name: postgres-11 diff --git a/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml b/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml index a252c0ee..d050405d 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml @@ -73,6 +73,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret diff --git a/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml b/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml index 9e468a59..85b09976 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml @@ -73,6 +73,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} enableServiceLinks: false imagePullSecrets: - name: lagoon-internal-registry-secret diff --git a/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml b/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml index 3657fb5a..dfdc6db9 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml @@ -77,6 +77,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/solr name: solr-8 diff --git a/internal/testdata/complex/service-templates/service3/deployment-web.yaml b/internal/testdata/complex/service-templates/service3/deployment-web.yaml index 71ca0eb7..007a4ea0 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-web.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-web.yaml @@ -73,6 +73,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /app/files name: web diff --git a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml index a4c660c5..ceb289d0 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml @@ -78,6 +78,7 @@ spec: requests: cpu: 10m memory: 10Mi + securityContext: {} volumeMounts: - mountPath: /var/lib/mysql name: mariadb-10-11 diff --git a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml index 34906f06..feec72d3 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml @@ -78,6 +78,7 @@ spec: requests: cpu: 10m memory: 10Mi + securityContext: {} volumeMounts: - mountPath: /var/lib/mysql name: mariadb-10-5 diff --git a/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml b/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml index 86786a8c..e4761388 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml @@ -77,6 +77,7 @@ spec: requests: cpu: 10m memory: 10Mi + securityContext: {} volumeMounts: - mountPath: /data/db name: mongo-4 diff --git a/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml b/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml index 3cafd9cc..b6f224e3 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml @@ -78,6 +78,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/lib/postgresql/data name: postgres-11 diff --git a/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml b/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml index c1189c37..4d77c61d 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml @@ -78,6 +78,7 @@ spec: requests: cpu: 10m memory: 100M + securityContext: {} volumeMounts: - mountPath: /var/lib/postgresql/data name: postgres-15 From 5bd18c095224d7a4f60c61cc491bec6cbb5499c7 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 27 Jun 2024 10:43:18 +1000 Subject: [PATCH 82/92] fix: add missing SERVICE_NAME variable to deployments --- internal/templating/services/templates_deployment.go | 8 ++++++++ internal/templating/services/templates_service.go | 2 -- .../test-resources/deployment/result-basic-1.yaml | 10 ++++++++++ .../test-resources/deployment/result-basic-2.yaml | 2 ++ .../test-resources/deployment/result-basic-3.yaml | 2 ++ .../test-resources/deployment/result-cli-1.yaml | 4 ++++ .../deployment/result-elasticsearch-1.yaml | 4 ++++ .../test-resources/deployment/result-mariadb-1.yaml | 2 ++ .../test-resources/deployment/result-mongodb-1.yaml | 2 ++ .../test-resources/deployment/result-nginx-1.yaml | 8 ++++++++ .../test-resources/deployment/result-nginx-2.yaml | 8 ++++++++ .../test-resources/deployment/result-node-1.yaml | 4 ++++ .../test-resources/deployment/result-opensearch-1.yaml | 4 ++++ .../test-resources/deployment/result-postgres-1.yaml | 2 ++ .../deployment/result-postgres-single-1.yaml | 2 ++ .../test-resources/deployment/result-python-1.yaml | 4 ++++ .../test-resources/deployment/result-rabbitmq-1.yaml | 2 ++ .../test-resources/deployment/result-redis-1.yaml | 4 ++++ .../test-resources/deployment/result-solr-1.yaml | 2 ++ .../test-resources/deployment/result-varnish-1.yaml | 4 ++++ .../test-resources/deployment/result-worker-1.yaml | 4 ++++ .../service-templates/service1/deployment-node.yaml | 2 ++ .../service-templates/service2/deployment-lnd.yaml | 2 ++ .../service2/deployment-thunderhub.yaml | 2 ++ .../service-templates/service2/deployment-tor.yaml | 2 ++ .../service-templates/service3/deployment-lnd.yaml | 2 ++ .../service-templates/service3/deployment-tor.yaml | 2 ++ .../service-templates/service4/deployment-node.yaml | 2 ++ .../service-templates/service5/deployment-node.yaml | 2 ++ .../service-templates/service6/deployment-node.yaml | 2 ++ .../service-templates/service1/deployment-cli.yaml | 2 ++ .../service1/deployment-nginx-php.yaml | 4 ++++ .../service-templates/service1/deployment-redis.yaml | 2 ++ .../service-templates/service1/deployment-varnish.yaml | 2 ++ .../service-templates/service2/deployment-cli.yaml | 2 ++ .../service2/deployment-nginx-php.yaml | 4 ++++ .../service-templates/service2/deployment-redis.yaml | 2 ++ .../service-templates/service2/deployment-varnish.yaml | 2 ++ .../service3/deployment-mariadb-10-5.yaml | 2 ++ .../service3/deployment-opensearch-2.yaml | 2 ++ .../service3/deployment-postgres-11.yaml | 2 ++ .../service-templates/service3/deployment-redis-6.yaml | 2 ++ .../service-templates/service3/deployment-redis-7.yaml | 2 ++ .../service-templates/service3/deployment-solr-8.yaml | 2 ++ .../service-templates/service3/deployment-web.yaml | 2 ++ .../service4/deployment-mariadb-10-11.yaml | 2 ++ .../service4/deployment-mariadb-10-5.yaml | 2 ++ .../service-templates/service4/deployment-mongo-4.yaml | 2 ++ .../service4/deployment-postgres-11.yaml | 2 ++ .../service4/deployment-postgres-15.yaml | 2 ++ 50 files changed, 144 insertions(+), 2 deletions(-) diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/services/templates_deployment.go index 0757371b..8decc1b2 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/services/templates_deployment.go @@ -402,6 +402,10 @@ func GenerateDeploymentTemplate( Name: "CRONJOBS", Value: cronjobs, }, + { + Name: "SERVICE_NAME", + Value: serviceValues.OverrideName, + }, } // expose any container envvars as required here container.Container.Env = append(container.Container.Env, envvars...) @@ -515,6 +519,10 @@ func GenerateDeploymentTemplate( Name: "LAGOON_GIT_SHA", Value: buildValues.GitSHA, }, + { + Name: "SERVICE_NAME", + Value: serviceValues.OverrideName, + }, } linkedContainer.Container.Env = append(linkedContainer.Container.Env, envvars...) linkedContainer.Container.EnvFrom = []corev1.EnvFromSource{ diff --git a/internal/templating/services/templates_service.go b/internal/templating/services/templates_service.go index d76fd6ae..cae60856 100644 --- a/internal/templating/services/templates_service.go +++ b/internal/templating/services/templates_service.go @@ -14,8 +14,6 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" ) -var separator = []byte("---\n") - // GenerateServiceTemplate generates the lagoon template to apply. func GenerateServiceTemplate( buildValues generator.BuildValues, diff --git a/internal/templating/services/test-resources/deployment/result-basic-1.yaml b/internal/templating/services/test-resources/deployment/result-basic-1.yaml index fc832738..2ce3c8df 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-1.yaml @@ -52,6 +52,8 @@ spec: value: | M/5 * * * * drush cron M/15 * * * * other cronjob + - name: SERVICE_NAME + value: myservice envFrom: - configMapRef: name: lagoon-env @@ -143,6 +145,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: myservice-po envFrom: - configMapRef: name: lagoon-env @@ -231,6 +235,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: myservice-persist envFrom: - configMapRef: name: lagoon-env @@ -319,6 +325,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: myservice-persist-po envFrom: - configMapRef: name: lagoon-env @@ -407,6 +415,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: myservice-persist-posize envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-basic-2.yaml b/internal/templating/services/test-resources/deployment/result-basic-2.yaml index 9f112a0c..7e75eba5 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-2.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-2.yaml @@ -59,6 +59,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: myservice-po envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-basic-3.yaml b/internal/templating/services/test-resources/deployment/result-basic-3.yaml index 8fc74101..e8d2913e 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-3.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-3.yaml @@ -59,6 +59,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: myservice-po envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-cli-1.yaml b/internal/templating/services/test-resources/deployment/result-cli-1.yaml index 19e88447..b767adab 100644 --- a/internal/templating/services/test-resources/deployment/result-cli-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-cli-1.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: myservice envFrom: - configMapRef: name: lagoon-env @@ -135,6 +137,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: myservice-persist envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml index 4944fcf7..7ca2037f 100644 --- a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml @@ -53,6 +53,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: myservice envFrom: - configMapRef: name: lagoon-env @@ -163,6 +165,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: myservice-size envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml b/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml index 70ebb4b6..f9ab3486 100644 --- a/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml @@ -54,6 +54,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: mariadb envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml b/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml index 32a6e70d..b86b637c 100644 --- a/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml @@ -53,6 +53,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: mongodb envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml index 9f9896bf..c36ab1d3 100644 --- a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml @@ -51,6 +51,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: nginx envFrom: - configMapRef: name: lagoon-env @@ -84,6 +86,8 @@ spec: value: 127.0.0.1 - name: LAGOON_GIT_SHA value: "0" + - name: SERVICE_NAME + value: nginx envFrom: - configMapRef: name: lagoon-env @@ -171,6 +175,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: nginx-2 envFrom: - configMapRef: name: lagoon-env @@ -207,6 +213,8 @@ spec: value: 127.0.0.1 - name: LAGOON_GIT_SHA value: "0" + - name: SERVICE_NAME + value: nginx-2 envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-nginx-2.yaml b/internal/templating/services/test-resources/deployment/result-nginx-2.yaml index e549ad32..d0e90119 100644 --- a/internal/templating/services/test-resources/deployment/result-nginx-2.yaml +++ b/internal/templating/services/test-resources/deployment/result-nginx-2.yaml @@ -51,6 +51,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: nginx envFrom: - configMapRef: name: lagoon-env @@ -84,6 +86,8 @@ spec: value: 127.0.0.1 - name: LAGOON_GIT_SHA value: "0" + - name: SERVICE_NAME + value: nginx envFrom: - configMapRef: name: lagoon-env @@ -172,6 +176,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: nginx-2 envFrom: - configMapRef: name: lagoon-env @@ -208,6 +214,8 @@ spec: value: 127.0.0.1 - name: LAGOON_GIT_SHA value: "0" + - name: SERVICE_NAME + value: nginx-2 envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-node-1.yaml b/internal/templating/services/test-resources/deployment/result-node-1.yaml index 7b656cec..5b4dcc01 100644 --- a/internal/templating/services/test-resources/deployment/result-node-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-node-1.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: node envFrom: - configMapRef: name: lagoon-env @@ -135,6 +137,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: node-persist envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml index 58e143a4..253912e8 100644 --- a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml @@ -53,6 +53,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: myservice envFrom: - configMapRef: name: lagoon-env @@ -163,6 +165,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: myservice-size envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-postgres-1.yaml b/internal/templating/services/test-resources/deployment/result-postgres-1.yaml index d316900c..7e64f7dc 100644 --- a/internal/templating/services/test-resources/deployment/result-postgres-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-postgres-1.yaml @@ -54,6 +54,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: postgres envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml index dc8acec2..00316bae 100644 --- a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml @@ -54,6 +54,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: myservice envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-python-1.yaml b/internal/templating/services/test-resources/deployment/result-python-1.yaml index 81cc9b2d..a43e4ca6 100644 --- a/internal/templating/services/test-resources/deployment/result-python-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-python-1.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: python envFrom: - configMapRef: name: lagoon-env @@ -135,6 +137,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: python-persist envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml b/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml index 72970c6e..273e08d1 100644 --- a/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml @@ -55,6 +55,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: rabbitmq envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-redis-1.yaml b/internal/templating/services/test-resources/deployment/result-redis-1.yaml index 98104ecc..bf6056ac 100644 --- a/internal/templating/services/test-resources/deployment/result-redis-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-redis-1.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: redis envFrom: - configMapRef: name: lagoon-env @@ -139,6 +141,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: redis-persist envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-solr-1.yaml b/internal/templating/services/test-resources/deployment/result-solr-1.yaml index 62bb1130..564e9065 100644 --- a/internal/templating/services/test-resources/deployment/result-solr-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-solr-1.yaml @@ -52,6 +52,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: solr envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-varnish-1.yaml b/internal/templating/services/test-resources/deployment/result-varnish-1.yaml index c1c32dd4..92817e4b 100644 --- a/internal/templating/services/test-resources/deployment/result-varnish-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-varnish-1.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: varnish envFrom: - configMapRef: name: lagoon-env @@ -141,6 +143,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: varnish-persist envFrom: - configMapRef: name: lagoon-env diff --git a/internal/templating/services/test-resources/deployment/result-worker-1.yaml b/internal/templating/services/test-resources/deployment/result-worker-1.yaml index 0f262ecf..564d9eff 100644 --- a/internal/templating/services/test-resources/deployment/result-worker-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-worker-1.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: worker envFrom: - configMapRef: name: lagoon-env @@ -135,6 +137,8 @@ spec: - name: LAGOON_GIT_SHA value: "0" - name: CRONJOBS + - name: SERVICE_NAME + value: worker-persist envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/basic/service-templates/service1/deployment-node.yaml b/internal/testdata/basic/service-templates/service1/deployment-node.yaml index 9d3894e6..c8e15eee 100644 --- a/internal/testdata/basic/service-templates/service1/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service1/deployment-node.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: node envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml index d21eb004..c95c9cd5 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0000000000000000000000000000000000000000" - name: CRONJOBS + - name: SERVICE_NAME + value: lnd envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml index 2b9edfcb..99887e5b 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0000000000000000000000000000000000000000" - name: CRONJOBS + - name: SERVICE_NAME + value: thunderhub envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/basic/service-templates/service2/deployment-tor.yaml b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml index c17594fa..a4d6c520 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-tor.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0000000000000000000000000000000000000000" - name: CRONJOBS + - name: SERVICE_NAME + value: tor envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml index d21eb004..c95c9cd5 100644 --- a/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml +++ b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0000000000000000000000000000000000000000" - name: CRONJOBS + - name: SERVICE_NAME + value: lnd envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/basic/service-templates/service3/deployment-tor.yaml b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml index 8c0a7957..0a13c7e7 100644 --- a/internal/testdata/basic/service-templates/service3/deployment-tor.yaml +++ b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0000000000000000000000000000000000000000" - name: CRONJOBS + - name: SERVICE_NAME + value: tor envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/basic/service-templates/service4/deployment-node.yaml b/internal/testdata/basic/service-templates/service4/deployment-node.yaml index 316cf196..51013ea4 100644 --- a/internal/testdata/basic/service-templates/service4/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service4/deployment-node.yaml @@ -47,6 +47,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: node envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/basic/service-templates/service5/deployment-node.yaml b/internal/testdata/basic/service-templates/service5/deployment-node.yaml index 2a70993c..ac14fc79 100644 --- a/internal/testdata/basic/service-templates/service5/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service5/deployment-node.yaml @@ -53,6 +53,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: node envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/basic/service-templates/service6/deployment-node.yaml b/internal/testdata/basic/service-templates/service6/deployment-node.yaml index 75f0cd2a..7ddd426f 100644 --- a/internal/testdata/basic/service-templates/service6/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service6/deployment-node.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: node envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service1/deployment-cli.yaml b/internal/testdata/complex/service-templates/service1/deployment-cli.yaml index c40c2a8d..198e4a49 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-cli.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-cli.yaml @@ -51,6 +51,8 @@ spec: - name: CRONJOBS value: | 3,18,33,48 * * * * drush cron + - name: SERVICE_NAME + value: cli envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml index d0522b6e..c8e49f47 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml @@ -51,6 +51,8 @@ spec: - name: LAGOON_GIT_SHA value: "0000000000000000000000000000000000000000" - name: CRONJOBS + - name: SERVICE_NAME + value: nginx-php envFrom: - configMapRef: name: lagoon-env @@ -87,6 +89,8 @@ spec: value: 127.0.0.1 - name: LAGOON_GIT_SHA value: "0000000000000000000000000000000000000000" + - name: SERVICE_NAME + value: nginx-php envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service1/deployment-redis.yaml b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml index 42ecec1d..406e9783 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-redis.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0000000000000000000000000000000000000000" - name: CRONJOBS + - name: SERVICE_NAME + value: redis envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml index 2a06cab6..9d441e6a 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0000000000000000000000000000000000000000" - name: CRONJOBS + - name: SERVICE_NAME + value: varnish envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service2/deployment-cli.yaml b/internal/testdata/complex/service-templates/service2/deployment-cli.yaml index cdb39551..a88b6c82 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-cli.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-cli.yaml @@ -51,6 +51,8 @@ spec: - name: CRONJOBS value: | 3,18,33,48 * * * * drush cron + - name: SERVICE_NAME + value: cli envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml index 1c7ad25e..2ef8dd4f 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml @@ -51,6 +51,8 @@ spec: - name: LAGOON_GIT_SHA value: "0000000000000000000000000000000000000000" - name: CRONJOBS + - name: SERVICE_NAME + value: nginx-php envFrom: - configMapRef: name: lagoon-env @@ -87,6 +89,8 @@ spec: value: 127.0.0.1 - name: LAGOON_GIT_SHA value: "0000000000000000000000000000000000000000" + - name: SERVICE_NAME + value: nginx-php envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service2/deployment-redis.yaml b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml index 340b9e61..37054470 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-redis.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0000000000000000000000000000000000000000" - name: CRONJOBS + - name: SERVICE_NAME + value: redis envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml index 2322c53e..785e85af 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: "0000000000000000000000000000000000000000" - name: CRONJOBS + - name: SERVICE_NAME + value: varnish envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml index feec72d3..9f7bab32 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml @@ -54,6 +54,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: mariadb-10-5 envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml b/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml index 612e4c18..80c7ed62 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml @@ -53,6 +53,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: opensearch-2 envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml b/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml index b6f224e3..926bdb93 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml @@ -54,6 +54,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: postgres-11 envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml b/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml index d050405d..c9b72608 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: redis-6 envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml b/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml index 85b09976..5ec0e297 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: redis-7 envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml b/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml index dfdc6db9..7e7a64e2 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml @@ -52,6 +52,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: solr-8 envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service3/deployment-web.yaml b/internal/testdata/complex/service-templates/service3/deployment-web.yaml index 007a4ea0..5952505a 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-web.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-web.yaml @@ -49,6 +49,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: web envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml index ceb289d0..6b4989cc 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml @@ -54,6 +54,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: mariadb-10-11 envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml index feec72d3..9f7bab32 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml @@ -54,6 +54,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: mariadb-10-5 envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml b/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml index e4761388..a5c2d0ae 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml @@ -53,6 +53,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: mongo-4 envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml b/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml index b6f224e3..926bdb93 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml @@ -54,6 +54,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: postgres-11 envFrom: - configMapRef: name: lagoon-env diff --git a/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml b/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml index 4d77c61d..4ba263c8 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml @@ -54,6 +54,8 @@ spec: - name: LAGOON_GIT_SHA value: abcdefg123456 - name: CRONJOBS + - name: SERVICE_NAME + value: postgres-15 envFrom: - configMapRef: name: lagoon-env From edd966e28cfaefca56924f9bafac172275f62f61 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 3 Jul 2024 19:22:51 +1000 Subject: [PATCH 83/92] chore: backport #329 --- cmd/template_backups_test.go | 24 +++++++ internal/generator/backups.go | 26 +++---- internal/generator/backups_test.go | 72 +++++++++++++++++++ internal/generator/container_registries.go | 6 +- internal/generator/generator.go | 6 +- internal/generator/helpers_generator.go | 8 +-- internal/generator/ingress.go | 4 +- internal/generator/lagoon_yaml.go | 6 +- internal/generator/services.go | 67 ++++------------- internal/generator/services_test.go | 1 - .../backup-8/k8up-lagoon-backup-schedule.yaml | 42 +++++++++++ 11 files changed, 181 insertions(+), 81 deletions(-) create mode 100644 internal/testdata/node/backup-templates/backup-8/k8up-lagoon-backup-schedule.yaml diff --git a/cmd/template_backups_test.go b/cmd/template_backups_test.go index cb47cfe0..d16b2e9d 100644 --- a/cmd/template_backups_test.go +++ b/cmd/template_backups_test.go @@ -215,6 +215,30 @@ func TestBackupTemplateGeneration(t *testing.T) { templatePath: "testdata/output", emptyDir: true, want: "internal/testdata/node/backup-templates/backup-7", + }, { + name: "test10 - generic backup with random check prune feature flags", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + EnvironmentType: "production", + LagoonYAML: "internal/testdata/node/lagoon.yml", + EnvVariables: []lagoon.EnvironmentVariable{ + { + Name: "LAGOON_FEATURE_FLAG_K8UP_WEEKLY_RANDOM_CHECK", + Value: "enabled", + Scope: "global", + }, + { + Name: "LAGOON_FEATURE_FLAG_K8UP_WEEKLY_RANDOM_PRUNE", + Value: "enabled", + Scope: "global", + }, + }, + }, true), + templatePath: "testdata/output", + want: "internal/testdata/node/backup-templates/backup-8", }, } for _, tt := range tests { diff --git a/internal/generator/backups.go b/internal/generator/backups.go index 98627ca0..b2fbeb93 100644 --- a/internal/generator/backups.go +++ b/internal/generator/backups.go @@ -94,44 +94,46 @@ func generateBackupValues( buildValues.Backup.BackupSchedule, err = helpers.ConvertCrontab(buildValues.Namespace, newBackupSchedule) if err != nil { - return fmt.Errorf("Unable to convert crontab for default backup schedule: %v", err) + return fmt.Errorf("unable to convert crontab for default backup schedule: %v", err) } // start: get variables from the build pod that may have been added by the controller flagCheckSchedule := helpers.GetEnv("K8UP_WEEKLY_RANDOM_FEATURE_FLAG", defaultCheckSchedule, debug) - if flagCheckSchedule == "enabled" { + lffCheckSchedule := CheckFeatureFlag("K8UP_WEEKLY_RANDOM_CHECK", mergedVariables, debug) + if flagCheckSchedule == "enabled" || lffCheckSchedule == "enabled" { buildValues.Backup.CheckSchedule = "@weekly-random" } else { - buildValues.Backup.CheckSchedule, err = helpers.ConvertCrontab(fmt.Sprintf("%s", buildValues.Namespace), defaultCheckSchedule) + buildValues.Backup.CheckSchedule, err = helpers.ConvertCrontab(buildValues.Namespace, defaultCheckSchedule) if err != nil { - return fmt.Errorf("Unable to convert crontab for default check schedule: %v", err) + return fmt.Errorf("unable to convert crontab for default check schedule: %v", err) } } flagPruneSchedule := helpers.GetEnv("K8UP_WEEKLY_RANDOM_FEATURE_FLAG", defaultPruneSchedule, debug) - if flagPruneSchedule == "enabled" { + lffPruneSchedule := CheckFeatureFlag("K8UP_WEEKLY_RANDOM_PRUNE", mergedVariables, debug) + if flagPruneSchedule == "enabled" || lffPruneSchedule == "enabled" { buildValues.Backup.PruneSchedule = "@weekly-random" } else { - buildValues.Backup.PruneSchedule, err = helpers.ConvertCrontab(fmt.Sprintf("%s", buildValues.Namespace), defaultPruneSchedule) + buildValues.Backup.PruneSchedule, err = helpers.ConvertCrontab(buildValues.Namespace, defaultPruneSchedule) if err != nil { - return fmt.Errorf("Unable to convert crontab for default prune schedule: %v", err) + return fmt.Errorf("unable to convert crontab for default prune schedule: %v", err) } } buildValues.Backup.PruneRetention.Hourly, err = helpers.EGetEnvInt("HOURLY_BACKUP_DEFAULT_RETENTION", hourlyDefaultBackupRetention, debug) if err != nil { - return fmt.Errorf("Unable to convert hourly retention provided in the environment variable to integer") + return fmt.Errorf("unable to convert hourly retention provided in the environment variable to integer") } buildValues.Backup.PruneRetention.Daily, err = helpers.EGetEnvInt("DAILY_BACKUP_DEFAULT_RETENTION", dailyDefaultBackupRetention, debug) if err != nil { - return fmt.Errorf("Unable to convert daily retention provided in the environment variable to integer") + return fmt.Errorf("unable to convert daily retention provided in the environment variable to integer") } buildValues.Backup.PruneRetention.Weekly, err = helpers.EGetEnvInt("WEEKLY_BACKUP_DEFAULT_RETENTION", weeklyDefaultBackupRetention, debug) if err != nil { - return fmt.Errorf("Unable to convert weekly retention provided in the environment variable to integer") + return fmt.Errorf("unable to convert weekly retention provided in the environment variable to integer") } buildValues.Backup.PruneRetention.Monthly, err = helpers.EGetEnvInt("MONTHLY_BACKUP_DEFAULT_RETENTION", monthlyDefaultBackupRetention, debug) if err != nil { - return fmt.Errorf("Unable to convert monthly retention provided in the environment variable to integer") + return fmt.Errorf("unable to convert monthly retention provided in the environment variable to integer") } // :end @@ -150,7 +152,7 @@ func generateBackupValues( if buildValues.LagoonYAML.BackupSchedule.Production != "" && buildValues.EnvironmentType == "production" { buildValues.Backup.BackupSchedule, err = helpers.ConvertCrontab(buildValues.Namespace, buildValues.LagoonYAML.BackupSchedule.Production) if err != nil { - return fmt.Errorf("Unable to convert crontab for default backup schedule from .lagoon.yml: %v", err) + return fmt.Errorf("unable to convert crontab for default backup schedule from .lagoon.yml: %v", err) } } diff --git a/internal/generator/backups_test.go b/internal/generator/backups_test.go index a0852545..38a54bc5 100644 --- a/internal/generator/backups_test.go +++ b/internal/generator/backups_test.go @@ -703,6 +703,78 @@ func Test_generateBackupValues(t *testing.T) { }, }, }, + { + name: "test18 - LAGOON_FEATURE_FLAG_K8UP_WEEKLY_RANDOM_CHECK enabled", + args: args{ + buildValues: &BuildValues{ + BuildType: "branch", + EnvironmentType: "development", + Project: "example-project", + Namespace: "example-com-main", + DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, + }, + mergedVariables: []lagoon.EnvironmentVariable{ + {Name: "LAGOON_FEATURE_FLAG_K8UP_WEEKLY_RANDOM_CHECK", Value: "enabled", Scope: "global"}, + }, + }, + vars: []helpers.EnvironmentVariable{}, + want: &BuildValues{ + BuildType: "branch", + EnvironmentType: "development", + Project: "example-project", + Namespace: "example-com-main", + DefaultBackupSchedule: "M H(22-2) * * *", + Backup: BackupConfiguration{ + BackupSchedule: "31 1 * * *", + CheckSchedule: "@weekly-random", + PruneSchedule: "31 4 * * 0", + S3BucketName: "baas-example-project", + PruneRetention: PruneRetention{ + Hourly: 0, + Daily: 7, + Weekly: 6, + Monthly: 1, + }, + }, + }, + }, + { + name: "test19 - LAGOON_FEATURE_FLAG_K8UP_WEEKLY_RANDOM_PRUNE enabled", + args: args{ + buildValues: &BuildValues{ + BuildType: "branch", + EnvironmentType: "development", + Project: "example-project", + Namespace: "example-com-main", + DefaultBackupSchedule: "M H(22-2) * * *", + LagoonYAML: lagoon.YAML{}, + }, + mergedVariables: []lagoon.EnvironmentVariable{ + {Name: "LAGOON_FEATURE_FLAG_K8UP_WEEKLY_RANDOM_PRUNE", Value: "enabled", Scope: "global"}, + }, + }, + vars: []helpers.EnvironmentVariable{}, + want: &BuildValues{ + BuildType: "branch", + EnvironmentType: "development", + Project: "example-project", + Namespace: "example-com-main", + DefaultBackupSchedule: "M H(22-2) * * *", + Backup: BackupConfiguration{ + BackupSchedule: "31 1 * * *", + CheckSchedule: "31 6 * * 1", + PruneSchedule: "@weekly-random", + S3BucketName: "baas-example-project", + PruneRetention: PruneRetention{ + Hourly: 0, + Daily: 7, + Weekly: 6, + Monthly: 1, + }, + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/generator/container_registries.go b/internal/generator/container_registries.go index 20f26817..1ca72fd1 100644 --- a/internal/generator/container_registries.go +++ b/internal/generator/container_registries.go @@ -71,10 +71,8 @@ func configureContainerRegistries(buildValues *BuildValues) error { } eru := cr.URL u, _ := url.Parse(eru) - if u.Host == "" { - eru = fmt.Sprintf("%s", eru) - } else { - eru = fmt.Sprintf("%s", u.Host) + if u.Host != "" { + eru = u.Host } // truncate the secret name to fit within the DNS1123subdomain spec before creating it secretName := fmt.Sprintf("lagoon-private-registry-%s", machinerynamespace.MakeSafe(n)) diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 87371a28..3b48d91c 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -189,16 +189,16 @@ func NewGenerator( // break out of the generator if these requirements are missing if projectName == "" || environmentName == "" || environmentType == "" || buildType == "" { - return nil, fmt.Errorf("Missing arguments: project-name, environment-name, environment-type, or build-type not defined") + return nil, fmt.Errorf("missing arguments: project-name, environment-name, environment-type, or build-type not defined") } switch buildType { case "branch", "promote": if branch == "" { - return nil, fmt.Errorf("Missing arguments: branch not defined") + return nil, fmt.Errorf("missing arguments: branch not defined") } case "pullrequest": if prNumber == "" || prHeadBranch == "" || prBaseBranch == "" { - return nil, fmt.Errorf("Missing arguments: pullrequest-number, pullrequest-head-branch, or pullrequest-base-branch not defined") + return nil, fmt.Errorf("missing arguments: pullrequest-number, pullrequest-head-branch, or pullrequest-base-branch not defined") } } diff --git a/internal/generator/helpers_generator.go b/internal/generator/helpers_generator.go index 231c1701..5a71de65 100644 --- a/internal/generator/helpers_generator.go +++ b/internal/generator/helpers_generator.go @@ -148,7 +148,7 @@ func CheckFeatureFlag(key string, envVariables []lagoon.EnvironmentVariable, deb // check for force value if value, ok := os.LookupEnv(fmt.Sprintf("LAGOON_FEATURE_FLAG_FORCE_%s", key)); ok { if debug { - fmt.Println(fmt.Sprintf("Using forced flag value from build variable %s", fmt.Sprintf("LAGOON_FEATURE_FLAG_FORCE_%s", key))) + fmt.Printf("Using forced flag value from build variable %s\n", fmt.Sprintf("LAGOON_FEATURE_FLAG_FORCE_%s", key)) } return value } @@ -156,7 +156,7 @@ func CheckFeatureFlag(key string, envVariables []lagoon.EnvironmentVariable, deb for _, lVar := range envVariables { if strings.Contains(lVar.Name, fmt.Sprintf("LAGOON_FEATURE_FLAG_%s", key)) { if debug { - fmt.Println(fmt.Sprintf("Using flag value from Lagoon environment variable %s", fmt.Sprintf("LAGOON_FEATURE_FLAG_%s", key))) + fmt.Printf("Using flag value from Lagoon environment variable %s\n", fmt.Sprintf("LAGOON_FEATURE_FLAG_%s", key)) } return lVar.Value } @@ -164,7 +164,7 @@ func CheckFeatureFlag(key string, envVariables []lagoon.EnvironmentVariable, deb // return default if value, ok := os.LookupEnv(fmt.Sprintf("LAGOON_FEATURE_FLAG_DEFAULT_%s", key)); ok { if debug { - fmt.Println(fmt.Sprintf("Using default flag value from build variable %s", fmt.Sprintf("LAGOON_FEATURE_FLAG_DEFAULT_%s", key))) + fmt.Printf("Using default flag value from build variable %s\n", fmt.Sprintf("LAGOON_FEATURE_FLAG_DEFAULT_%s", key)) } return value } @@ -175,7 +175,7 @@ func CheckFeatureFlag(key string, envVariables []lagoon.EnvironmentVariable, deb func CheckAdminFeatureFlag(key string, debug bool) string { if value, ok := os.LookupEnv(fmt.Sprintf("ADMIN_LAGOON_FEATURE_FLAG_%s", key)); ok { if debug { - fmt.Println(fmt.Sprintf("Using admin feature flag value from build variable %s", fmt.Sprintf("ADMIN_LAGOON_FEATURE_FLAG_%s", key))) + fmt.Printf("Using admin feature flag value from build variable %s\n", fmt.Sprintf("ADMIN_LAGOON_FEATURE_FLAG_%s", key)) } return value } diff --git a/internal/generator/ingress.go b/internal/generator/ingress.go index 91a97ea8..32784aa6 100644 --- a/internal/generator/ingress.go +++ b/internal/generator/ingress.go @@ -247,7 +247,7 @@ func generateActiveStandbyRoutes( ) (lagoon.RoutesV2, error) { activeStanbyRoutes := &lagoon.RoutesV2{} if buildValues.LagoonYAML.ProductionRoutes != nil { - if buildValues.IsActiveEnvironment == true { + if buildValues.IsActiveEnvironment { if buildValues.LagoonYAML.ProductionRoutes.Active != nil { if buildValues.LagoonYAML.ProductionRoutes.Active.Routes != nil { for _, routeMap := range buildValues.LagoonYAML.ProductionRoutes.Active.Routes { @@ -259,7 +259,7 @@ func generateActiveStandbyRoutes( } } } - if buildValues.IsStandbyEnvironment == true { + if buildValues.IsStandbyEnvironment { if buildValues.LagoonYAML.ProductionRoutes.Standby != nil { if buildValues.LagoonYAML.ProductionRoutes.Standby.Routes != nil { for _, routeMap := range buildValues.LagoonYAML.ProductionRoutes.Standby.Routes { diff --git a/internal/generator/lagoon_yaml.go b/internal/generator/lagoon_yaml.go index bb9f5722..edff1848 100644 --- a/internal/generator/lagoon_yaml.go +++ b/internal/generator/lagoon_yaml.go @@ -34,18 +34,18 @@ func LoadAndUnmarshalLagoonYml(lagoonYml string, lagoonYmlOverride string, lagoo //Decode it envLagoonYamlString, err := base64.StdEncoding.DecodeString(envLagoonYamlStringBase64) if err != nil { - return fmt.Errorf("Unable to decode %v - is it base64 encoded?", lagoonYmlOverrideEnvVarName) + return fmt.Errorf("unable to decode %v - is it base64 encoded?", lagoonYmlOverrideEnvVarName) } envLagoonYaml := &lagoon.YAML{} lEnvLagoonPolysite := make(map[string]interface{}) err = yaml.Unmarshal(envLagoonYamlString, envLagoonYaml) if err != nil { - return fmt.Errorf("Unable to unmarshal env var %v: %v", lagoonYmlOverrideEnvVarName, err) + return fmt.Errorf("unable to unmarshal env var %v: %v", lagoonYmlOverrideEnvVarName, err) } err = yaml.Unmarshal(envLagoonYamlString, lEnvLagoonPolysite) if err != nil { - return fmt.Errorf("Unable to unmarshal env var %v: %v", lagoonYmlOverrideEnvVarName, err) + return fmt.Errorf("unable to unmarshal env var %v: %v", lagoonYmlOverrideEnvVarName, err) } if _, ok := lEnvLagoonPolysite[projectName]; ok { diff --git a/internal/generator/services.go b/internal/generator/services.go index db467cb7..3ada786a 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -79,42 +79,6 @@ var typesWithBackups = []string{ "mongodb-single", } -// just some default values for services -var defaultServiceValues = map[string]map[string]string{ - "elasticsearch": { - "persistentPath": "/usr/share/elasticsearch/data", - "persistentSize": "5Gi", - }, - "opensearch": { - "persistentPath": "/usr/share/opensearch/data", - "persistentSize": "5Gi", - }, - "mariadb-single": { - "persistentPath": "/var/lib/mysql", - "persistentSize": "5Gi", - }, - "postgres-single": { - "persistentPath": "/var/lib/postgresql/data", - "persistentSize": "5Gi", - }, - "mongodb-single": { - "persistentPath": "/data/db", - "persistentSize": "5Gi", - }, - "varnish-persistent": { - "persistentPath": "/var/cache/varnish", - "persistentSize": "5Gi", - }, - "rabbitmq": { - "persistentPath": "/var/lib/rabbitmq", - "persistentSize": "5Gi", - }, - "redis-persistent": { - "persistentPath": "/data", - "persistentSize": "5Gi", - }, -} - // generateServicesFromDockerCompose unmarshals the docker-compose file and processes the services using composeToServiceValues func generateServicesFromDockerCompose( buildValues *BuildValues, @@ -170,20 +134,20 @@ func composeToServiceValues( lagoonType = lagoon.CheckServiceLagoonLabel(composeServiceValues.Labels, "lagoon.type") } if lagoonType == "" { - return ServiceValues{}, fmt.Errorf("No lagoon.type has been set for service %s. If a Lagoon service is not required, please set the lagoon.type to 'none' for this service in docker-compose.yaml. See the Lagoon documentation for supported service types.", composeService) + return ServiceValues{}, fmt.Errorf("no lagoon.type has been set for service %s. If a Lagoon service is not required, please set the lagoon.type to 'none' for this service in docker-compose.yaml. See the Lagoon documentation for supported service types", composeService) } else { // if the lagoontype is populated, even none is valid as there may be a servicetype override in an environment variable autogenEnabled := true autogenTLSAcmeEnabled := true // check if autogenerated routes are disabled if buildValues.LagoonYAML.Routes.Autogenerate.Enabled != nil { - if *buildValues.LagoonYAML.Routes.Autogenerate.Enabled == false { + if !*buildValues.LagoonYAML.Routes.Autogenerate.Enabled { autogenEnabled = false } } // check if pullrequests autogenerated routes are disabled if buildValues.BuildType == "pullrequest" && buildValues.LagoonYAML.Routes.Autogenerate.AllowPullRequests != nil { - if *buildValues.LagoonYAML.Routes.Autogenerate.AllowPullRequests == false { + if !*buildValues.LagoonYAML.Routes.Autogenerate.AllowPullRequests { autogenEnabled = false } else { autogenEnabled = true @@ -191,7 +155,7 @@ func composeToServiceValues( } // check if this environment has autogenerated routes disabled if buildValues.LagoonYAML.Environments[buildValues.Branch].AutogenerateRoutes != nil { - if *buildValues.LagoonYAML.Environments[buildValues.Branch].AutogenerateRoutes == false { + if !*buildValues.LagoonYAML.Environments[buildValues.Branch].AutogenerateRoutes { autogenEnabled = false } else { autogenEnabled = true @@ -199,7 +163,7 @@ func composeToServiceValues( } // check if autogenerated routes tls-acme disabled if buildValues.LagoonYAML.Routes.Autogenerate.TLSAcme != nil { - if *buildValues.LagoonYAML.Routes.Autogenerate.TLSAcme == false { + if !*buildValues.LagoonYAML.Routes.Autogenerate.TLSAcme { autogenTLSAcmeEnabled = false } } @@ -306,10 +270,10 @@ func composeToServiceValues( if err != nil { // @TODO eventually this error should be handled and fail a build, with a flag to override https://github.com/uselagoon/build-deploy-tool/issues/56 // if !buildValues.DBaaSFallbackSingle { - // return ServiceValues{}, fmt.Errorf("Unable to check the DBaaS endpoint %s: %v", buildValues.DBaaSOperatorEndpoint, err) + // return ServiceValues{}, fmt.Errorf("unable to check the DBaaS endpoint %s: %v", buildValues.DBaaSOperatorEndpoint, err) // } if debug { - fmt.Println(fmt.Sprintf("Unable to check the DBaaS endpoint %s, falling back to %s-single: %v", buildValues.DBaaSOperatorEndpoint, lagoonType, err)) + fmt.Printf("Unable to check the DBaaS endpoint %s, falling back to %s-single: %v\n", buildValues.DBaaSOperatorEndpoint, lagoonType, err) } // normally we would fall back to doing a cluster capability check, this is phased out in the build tool, it isn't reliable // and noone should be doing checks that way any more @@ -331,17 +295,17 @@ func composeToServiceValues( // if there are overrides defined in the lagoon API `LAGOON_DBAAS_ENVIRONMENT_TYPES` // handle those here - exists, err := getDBaasEnvironment(buildValues, &dbaasEnvironment, lagoonOverrideName, lagoonType, debug) + exists, err := getDBaasEnvironment(buildValues, &dbaasEnvironment, lagoonOverrideName, lagoonType) if err != nil { // @TODO eventually this error should be handled and fail a build, with a flag to override https://github.com/uselagoon/build-deploy-tool/issues/56 // if !buildValues.DBaaSFallbackSingle { // return ServiceValues{}, err // } if debug { - fmt.Println(fmt.Sprintf( - "There was an error checking DBaaS endpoint %s, falling back to %s-single: %v", + fmt.Printf( + "There was an error checking DBaaS endpoint %s, falling back to %s-single: %v\n", buildValues.DBaaSOperatorEndpoint, lagoonType, err, - )) + ) } } @@ -429,11 +393,11 @@ func composeToServiceValues( var err error inpod, err := helpers.IsInPodCronjob(cronjob.Schedule) if err != nil { - return ServiceValues{}, fmt.Errorf("Unable to validate crontab for cronjob %s: %v", cronjob.Name, err) + return ServiceValues{}, fmt.Errorf("unable to validate crontab for cronjob %s: %v", cronjob.Name, err) } cronjob.Schedule, err = helpers.ConvertCrontab(buildValues.Namespace, cronjob.Schedule) if err != nil { - return ServiceValues{}, fmt.Errorf("Unable to convert crontab for cronjob %s: %v", cronjob.Name, err) + return ServiceValues{}, fmt.Errorf("unable to convert crontab for cronjob %s: %v", cronjob.Name, err) } if inpod { inpodcronjobs = append(inpodcronjobs, cronjob) @@ -617,7 +581,7 @@ func composeToServiceValues( sPort, err := strconv.Atoi(servicePortOverride) if err != nil { return ServiceValues{}, fmt.Errorf( - "The provided service port %s for service %s is not a valid integer: %v", + "the provided service port %s for service %s is not a valid integer: %v", servicePortOverride, composeService, err, ) } @@ -643,7 +607,6 @@ func getDBaasEnvironment( dbaasEnvironment *string, lagoonOverrideName, lagoonType string, - debug bool, ) (bool, error) { if buildValues.DBaaSEnvironmentTypeOverrides != nil { dbaasEnvironmentTypeSplit := strings.Split(buildValues.DBaaSEnvironmentTypeOverrides.Value, ",") @@ -656,7 +619,7 @@ func getDBaasEnvironment( } exists, err := buildValues.DBaaSClient.CheckProvider(buildValues.DBaaSOperatorEndpoint, lagoonType, *dbaasEnvironment) if err != nil { - return exists, fmt.Errorf("There was an error checking DBaaS endpoint %s: %v", buildValues.DBaaSOperatorEndpoint, err) + return exists, fmt.Errorf("there was an error checking DBaaS endpoint %s: %v", buildValues.DBaaSOperatorEndpoint, err) } return exists, nil } diff --git a/internal/generator/services_test.go b/internal/generator/services_test.go index cd740937..f52eb5c0 100644 --- a/internal/generator/services_test.go +++ b/internal/generator/services_test.go @@ -17,7 +17,6 @@ func Test_composeToServiceValues(t *testing.T) { buildValues *BuildValues composeService string composeServiceValues composetypes.ServiceConfig - lagoonEnvVars []lagoon.EnvironmentVariable } tests := []struct { name string diff --git a/internal/testdata/node/backup-templates/backup-8/k8up-lagoon-backup-schedule.yaml b/internal/testdata/node/backup-templates/backup-8/k8up-lagoon-backup-schedule.yaml new file mode 100644 index 00000000..65e347dd --- /dev/null +++ b/internal/testdata/node/backup-templates/backup-8/k8up-lagoon-backup-schedule.yaml @@ -0,0 +1,42 @@ +--- +apiVersion: backup.appuio.ch/v1alpha1 +kind: Schedule +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: k8up-lagoon-backup-schedule + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: k8up-schedule + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: k8up-lagoon-backup-schedule + lagoon.sh/service-type: k8up-schedule + lagoon.sh/template: k8up-schedule-0.1.0 + name: k8up-lagoon-backup-schedule +spec: + backend: + repoPasswordSecretRef: + key: repo-pw + name: baas-repo-pw + s3: + bucket: baas-example-project + backup: + resources: {} + schedule: 48 22 * * * + check: + resources: {} + schedule: '@weekly-random' + prune: + resources: {} + retention: + keepDaily: 7 + keepMonthly: 1 + keepWeekly: 6 + schedule: '@weekly-random' + resourceRequirementsTemplate: {} +status: {} From 333784da6da9017ea9f2035c03cb75767a03ddbd Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 15 Jul 2024 11:05:21 +1000 Subject: [PATCH 84/92] fix: set enableservicelinks to be correct for -singles, adjust postgres container name and memory --- internal/servicetypes/mariadb.go | 3 ++- internal/servicetypes/mongodb.go | 3 ++- internal/servicetypes/postgres.go | 4 ++-- .../services/test-resources/deployment/result-mariadb-1.yaml | 2 +- .../services/test-resources/deployment/result-mongodb-1.yaml | 2 +- .../services/test-resources/deployment/result-postgres-1.yaml | 4 ++-- .../test-resources/deployment/result-postgres-single-1.yaml | 4 ++-- .../service-templates/service3/deployment-mariadb-10-5.yaml | 2 +- .../service-templates/service3/deployment-postgres-11.yaml | 4 ++-- .../service-templates/service4/deployment-mariadb-10-11.yaml | 2 +- .../service-templates/service4/deployment-mariadb-10-5.yaml | 2 +- .../service-templates/service4/deployment-mongo-4.yaml | 2 +- .../service-templates/service4/deployment-postgres-11.yaml | 4 ++-- .../service-templates/service4/deployment-postgres-15.yaml | 4 ++-- 14 files changed, 22 insertions(+), 20 deletions(-) diff --git a/internal/servicetypes/mariadb.go b/internal/servicetypes/mariadb.go index 1811f35f..23d5e5d0 100644 --- a/internal/servicetypes/mariadb.go +++ b/internal/servicetypes/mariadb.go @@ -12,7 +12,8 @@ import ( var defaultMariaDBPort int32 = 3306 var mariadbSingle = ServiceType{ - Name: "mariadb-single", + Name: "mariadb-single", + EnableServiceLinks: true, Ports: ServicePorts{ Ports: []corev1.ServicePort{ { diff --git a/internal/servicetypes/mongodb.go b/internal/servicetypes/mongodb.go index b1ce8bff..e9987fa6 100644 --- a/internal/servicetypes/mongodb.go +++ b/internal/servicetypes/mongodb.go @@ -12,7 +12,8 @@ import ( var defaultMongoDBPort int32 = 27017 var mongodbSingle = ServiceType{ - Name: "mongodb-single", + Name: "mongodb-single", + EnableServiceLinks: true, Ports: ServicePorts{ Ports: []corev1.ServicePort{ { diff --git a/internal/servicetypes/postgres.go b/internal/servicetypes/postgres.go index c3c8e58c..7972ce47 100644 --- a/internal/servicetypes/postgres.go +++ b/internal/servicetypes/postgres.go @@ -28,7 +28,7 @@ var postgresSingle = ServiceType{ }, }, PrimaryContainer: ServiceContainer{ - Name: "postgres", + Name: "postgres-single", Container: corev1.Container{ ImagePullPolicy: corev1.PullAlways, SecurityContext: &corev1.SecurityContext{}, @@ -66,7 +66,7 @@ var postgresSingle = ServiceType{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), - corev1.ResourceMemory: resource.MustParse("100M"), + corev1.ResourceMemory: resource.MustParse("10Mi"), }, }, }, diff --git a/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml b/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml index f9ab3486..36dd765c 100644 --- a/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml @@ -84,7 +84,7 @@ spec: volumeMounts: - mountPath: /var/lib/mysql name: mariadb - enableServiceLinks: false + enableServiceLinks: true imagePullSecrets: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production diff --git a/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml b/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml index b86b637c..c1499331 100644 --- a/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml @@ -83,7 +83,7 @@ spec: volumeMounts: - mountPath: /data/db name: mongodb - enableServiceLinks: false + enableServiceLinks: true imagePullSecrets: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production diff --git a/internal/templating/services/test-resources/deployment/result-postgres-1.yaml b/internal/templating/services/test-resources/deployment/result-postgres-1.yaml index 7e64f7dc..b051f0a4 100644 --- a/internal/templating/services/test-resources/deployment/result-postgres-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-postgres-1.yaml @@ -66,7 +66,7 @@ spec: periodSeconds: 5 tcpSocket: port: 5432 - name: postgres + name: postgres-single ports: - containerPort: 5432 name: 5432-tcp @@ -79,7 +79,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/lib/postgresql/data diff --git a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml index 00316bae..be3e011a 100644 --- a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml @@ -66,7 +66,7 @@ spec: periodSeconds: 5 tcpSocket: port: 5432 - name: postgres + name: postgres-single ports: - containerPort: 5432 name: 5432-tcp @@ -79,7 +79,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/lib/postgresql/data diff --git a/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml index 9f7bab32..bf281550 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-mariadb-10-5.yaml @@ -84,7 +84,7 @@ spec: volumeMounts: - mountPath: /var/lib/mysql name: mariadb-10-5 - enableServiceLinks: false + enableServiceLinks: true imagePullSecrets: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production diff --git a/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml b/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml index 926bdb93..797edcb0 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-postgres-11.yaml @@ -66,7 +66,7 @@ spec: periodSeconds: 5 tcpSocket: port: 5432 - name: postgres + name: postgres-single ports: - containerPort: 5432 name: 5432-tcp @@ -79,7 +79,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/lib/postgresql/data diff --git a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml index 6b4989cc..65e8ebbc 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml @@ -84,7 +84,7 @@ spec: volumeMounts: - mountPath: /var/lib/mysql name: mariadb-10-11 - enableServiceLinks: false + enableServiceLinks: true imagePullSecrets: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production diff --git a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml index 9f7bab32..bf281550 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml @@ -84,7 +84,7 @@ spec: volumeMounts: - mountPath: /var/lib/mysql name: mariadb-10-5 - enableServiceLinks: false + enableServiceLinks: true imagePullSecrets: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production diff --git a/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml b/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml index a5c2d0ae..9302c15f 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml @@ -83,7 +83,7 @@ spec: volumeMounts: - mountPath: /data/db name: mongo-4 - enableServiceLinks: false + enableServiceLinks: true imagePullSecrets: - name: lagoon-internal-registry-secret priorityClassName: lagoon-priority-production diff --git a/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml b/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml index 926bdb93..797edcb0 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml @@ -66,7 +66,7 @@ spec: periodSeconds: 5 tcpSocket: port: 5432 - name: postgres + name: postgres-single ports: - containerPort: 5432 name: 5432-tcp @@ -79,7 +79,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/lib/postgresql/data diff --git a/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml b/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml index 4ba263c8..d95c7f40 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml @@ -66,7 +66,7 @@ spec: periodSeconds: 5 tcpSocket: port: 5432 - name: postgres + name: postgres-single ports: - containerPort: 5432 name: 5432-tcp @@ -79,7 +79,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/lib/postgresql/data From 651d718e80a2693eb047e2eab2422b871ef22b11 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 15 Jul 2024 11:11:07 +1000 Subject: [PATCH 85/92] fix: opensearch/elasticsearch liveness and readiness probes --- internal/servicetypes/elasticsearch.go | 10 ++++---- internal/servicetypes/opensearch.go | 10 ++++---- .../deployment/result-elasticsearch-1.yaml | 24 +++++++++---------- .../deployment/result-opensearch-1.yaml | 24 +++++++++---------- .../service3/deployment-opensearch-2.yaml | 12 +++++----- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/internal/servicetypes/elasticsearch.go b/internal/servicetypes/elasticsearch.go index 2e60917d..ba777c56 100644 --- a/internal/servicetypes/elasticsearch.go +++ b/internal/servicetypes/elasticsearch.go @@ -41,19 +41,20 @@ var elasticsearch = ServiceType{ }, ReadinessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ - TCPSocket: &corev1.TCPSocketAction{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/_cluster/health?local=true", Port: intstr.IntOrString{ Type: intstr.Int, IntVal: defaultElasticsearchPort, }, }, }, - InitialDelaySeconds: 1, - TimeoutSeconds: 1, + InitialDelaySeconds: 20, }, LivenessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ - TCPSocket: &corev1.TCPSocketAction{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/_cluster/health?local=true", Port: intstr.IntOrString{ Type: intstr.Int, IntVal: defaultElasticsearchPort, @@ -61,7 +62,6 @@ var elasticsearch = ServiceType{ }, }, InitialDelaySeconds: 120, - PeriodSeconds: 5, }, Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ diff --git a/internal/servicetypes/opensearch.go b/internal/servicetypes/opensearch.go index 0388d6a6..eda243ea 100644 --- a/internal/servicetypes/opensearch.go +++ b/internal/servicetypes/opensearch.go @@ -41,19 +41,20 @@ var opensearch = ServiceType{ }, ReadinessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ - TCPSocket: &corev1.TCPSocketAction{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/_cluster/health?local=true", Port: intstr.IntOrString{ Type: intstr.Int, IntVal: defaultOpensearchPort, }, }, }, - InitialDelaySeconds: 1, - TimeoutSeconds: 1, + InitialDelaySeconds: 20, }, LivenessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ - TCPSocket: &corev1.TCPSocketAction{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/_cluster/health?local=true", Port: intstr.IntOrString{ Type: intstr.Int, IntVal: defaultOpensearchPort, @@ -61,7 +62,6 @@ var opensearch = ServiceType{ }, }, InitialDelaySeconds: 120, - PeriodSeconds: 5, }, Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ diff --git a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml index 7ca2037f..0bb0ab98 100644 --- a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml @@ -61,20 +61,20 @@ spec: image: harbor.example.com/example-project/environment-name/myservice@latest imagePullPolicy: Always livenessProbe: - initialDelaySeconds: 120 - periodSeconds: 5 - tcpSocket: + httpGet: + path: /_cluster/health?local=true port: 9200 + initialDelaySeconds: 120 name: elasticsearch ports: - containerPort: 9200 name: 9200-tcp protocol: TCP readinessProbe: - initialDelaySeconds: 1 - tcpSocket: + httpGet: + path: /_cluster/health?local=true port: 9200 - timeoutSeconds: 1 + initialDelaySeconds: 20 resources: requests: cpu: 10m @@ -173,20 +173,20 @@ spec: image: harbor.example.com/example-project/environment-name/myservice-size@latest imagePullPolicy: Always livenessProbe: - initialDelaySeconds: 120 - periodSeconds: 5 - tcpSocket: + httpGet: + path: /_cluster/health?local=true port: 9200 + initialDelaySeconds: 120 name: elasticsearch ports: - containerPort: 9200 name: 9200-tcp protocol: TCP readinessProbe: - initialDelaySeconds: 1 - tcpSocket: + httpGet: + path: /_cluster/health?local=true port: 9200 - timeoutSeconds: 1 + initialDelaySeconds: 20 resources: requests: cpu: 10m diff --git a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml index 253912e8..5970eaf8 100644 --- a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml @@ -61,20 +61,20 @@ spec: image: harbor.example.com/example-project/environment-name/myservice@latest imagePullPolicy: Always livenessProbe: - initialDelaySeconds: 120 - periodSeconds: 5 - tcpSocket: + httpGet: + path: /_cluster/health?local=true port: 9200 + initialDelaySeconds: 120 name: opensearch ports: - containerPort: 9200 name: 9200-tcp protocol: TCP readinessProbe: - initialDelaySeconds: 1 - tcpSocket: + httpGet: + path: /_cluster/health?local=true port: 9200 - timeoutSeconds: 1 + initialDelaySeconds: 20 resources: requests: cpu: 10m @@ -173,20 +173,20 @@ spec: image: harbor.example.com/example-project/environment-name/myservice-size@latest imagePullPolicy: Always livenessProbe: - initialDelaySeconds: 120 - periodSeconds: 5 - tcpSocket: + httpGet: + path: /_cluster/health?local=true port: 9200 + initialDelaySeconds: 120 name: opensearch ports: - containerPort: 9200 name: 9200-tcp protocol: TCP readinessProbe: - initialDelaySeconds: 1 - tcpSocket: + httpGet: + path: /_cluster/health?local=true port: 9200 - timeoutSeconds: 1 + initialDelaySeconds: 20 resources: requests: cpu: 10m diff --git a/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml b/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml index 80c7ed62..9046eef9 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-opensearch-2.yaml @@ -61,20 +61,20 @@ spec: image: harbor.example/example-project/main/opensearch-2@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8 imagePullPolicy: Always livenessProbe: - initialDelaySeconds: 120 - periodSeconds: 5 - tcpSocket: + httpGet: + path: /_cluster/health?local=true port: 9200 + initialDelaySeconds: 120 name: opensearch ports: - containerPort: 9200 name: 9200-tcp protocol: TCP readinessProbe: - initialDelaySeconds: 1 - tcpSocket: + httpGet: + path: /_cluster/health?local=true port: 9200 - timeoutSeconds: 1 + initialDelaySeconds: 20 resources: requests: cpu: 10m From 1b69bf8136bf72e965ab3a32536b8d92f93d5480 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 15 Jul 2024 11:13:41 +1000 Subject: [PATCH 86/92] fix: redis liveness and memory --- internal/servicetypes/redis.go | 4 ++-- .../test-resources/deployment/result-redis-1.yaml | 8 ++++---- .../service-templates/service1/deployment-redis.yaml | 4 ++-- .../service-templates/service2/deployment-redis.yaml | 4 ++-- .../service-templates/service3/deployment-redis-6.yaml | 4 ++-- .../service-templates/service3/deployment-redis-7.yaml | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/servicetypes/redis.go b/internal/servicetypes/redis.go index 0a29877a..31acbf4d 100644 --- a/internal/servicetypes/redis.go +++ b/internal/servicetypes/redis.go @@ -60,12 +60,12 @@ var redis = ServiceType{ }, }, InitialDelaySeconds: 120, - TimeoutSeconds: 10, + TimeoutSeconds: 1, }, Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), - corev1.ResourceMemory: resource.MustParse("100M"), + corev1.ResourceMemory: resource.MustParse("10Mi"), }, }, }, diff --git a/internal/templating/services/test-resources/deployment/result-redis-1.yaml b/internal/templating/services/test-resources/deployment/result-redis-1.yaml index bf6056ac..fd6f8b8f 100644 --- a/internal/templating/services/test-resources/deployment/result-redis-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-redis-1.yaml @@ -60,7 +60,7 @@ spec: initialDelaySeconds: 120 tcpSocket: port: 6379 - timeoutSeconds: 10 + timeoutSeconds: 1 name: redis ports: - containerPort: 6379 @@ -74,7 +74,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: @@ -152,7 +152,7 @@ spec: initialDelaySeconds: 120 tcpSocket: port: 6379 - timeoutSeconds: 10 + timeoutSeconds: 1 name: redis ports: - containerPort: 6379 @@ -166,7 +166,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /data diff --git a/internal/testdata/complex/service-templates/service1/deployment-redis.yaml b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml index 406e9783..667e1a96 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-redis.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-redis.yaml @@ -60,7 +60,7 @@ spec: initialDelaySeconds: 120 tcpSocket: port: 6379 - timeoutSeconds: 10 + timeoutSeconds: 1 name: redis ports: - containerPort: 6379 @@ -74,7 +74,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: diff --git a/internal/testdata/complex/service-templates/service2/deployment-redis.yaml b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml index 37054470..605ae453 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-redis.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-redis.yaml @@ -60,7 +60,7 @@ spec: initialDelaySeconds: 120 tcpSocket: port: 6379 - timeoutSeconds: 10 + timeoutSeconds: 1 name: redis ports: - containerPort: 6379 @@ -74,7 +74,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: diff --git a/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml b/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml index c9b72608..5f4ce0b3 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-redis-6.yaml @@ -60,7 +60,7 @@ spec: initialDelaySeconds: 120 tcpSocket: port: 6379 - timeoutSeconds: 10 + timeoutSeconds: 1 name: redis ports: - containerPort: 6379 @@ -74,7 +74,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: diff --git a/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml b/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml index 5ec0e297..d87cf544 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-redis-7.yaml @@ -60,7 +60,7 @@ spec: initialDelaySeconds: 120 tcpSocket: port: 6379 - timeoutSeconds: 10 + timeoutSeconds: 1 name: redis ports: - containerPort: 6379 @@ -74,7 +74,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: From ba199e0d2117d08da037ae180425552b38f9651c Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 15 Jul 2024 11:18:33 +1000 Subject: [PATCH 87/92] fix: solr recreate strategy and memory --- internal/servicetypes/solr.go | 6 +++++- .../services/test-resources/deployment/result-solr-1.yaml | 5 +++-- .../service-templates/service3/deployment-solr-8.yaml | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/servicetypes/solr.go b/internal/servicetypes/solr.go index 36ae6eeb..0eecff10 100644 --- a/internal/servicetypes/solr.go +++ b/internal/servicetypes/solr.go @@ -3,6 +3,7 @@ package servicetypes import ( "fmt" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/intstr" @@ -65,11 +66,14 @@ var solr = ServiceType{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), - corev1.ResourceMemory: resource.MustParse("100M"), + corev1.ResourceMemory: resource.MustParse("10Mi"), }, }, }, }, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RecreateDeploymentStrategyType, + }, Volumes: ServiceVolume{ PersistentVolumeSize: "5Gi", PersistentVolumeType: corev1.ReadWriteOnce, diff --git a/internal/templating/services/test-resources/deployment/result-solr-1.yaml b/internal/templating/services/test-resources/deployment/result-solr-1.yaml index 564e9065..b2329ea0 100644 --- a/internal/templating/services/test-resources/deployment/result-solr-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-solr-1.yaml @@ -24,7 +24,8 @@ spec: matchLabels: app.kubernetes.io/instance: solr app.kubernetes.io/name: solr-php-persistent - strategy: {} + strategy: + type: Recreate template: metadata: annotations: @@ -78,7 +79,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/solr diff --git a/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml b/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml index 7e7a64e2..208edd30 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-solr-8.yaml @@ -24,7 +24,8 @@ spec: matchLabels: app.kubernetes.io/instance: solr-8 app.kubernetes.io/name: solr-php-persistent - strategy: {} + strategy: + type: Recreate template: metadata: annotations: @@ -78,7 +79,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/solr From b4a582a32d66f4408f22c6c32f255ebb19941cbd Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 15 Jul 2024 11:36:11 +1000 Subject: [PATCH 88/92] fix: adjust other memory to match legacy helm values --- internal/servicetypes/basic.go | 2 +- internal/servicetypes/cli.go | 2 +- internal/servicetypes/nginx.go | 6 +++--- internal/servicetypes/node.go | 2 +- internal/servicetypes/python.go | 2 +- internal/servicetypes/rabbitmq.go | 2 +- internal/servicetypes/varnish.go | 2 +- internal/servicetypes/worker.go | 2 +- .../services/test-resources/cronjob/result-cli-1.yaml | 6 +++--- .../test-resources/deployment/result-basic-1.yaml | 10 +++++----- .../test-resources/deployment/result-basic-2.yaml | 2 +- .../test-resources/deployment/result-basic-3.yaml | 2 +- .../test-resources/deployment/result-cli-1.yaml | 4 ++-- .../test-resources/deployment/result-nginx-1.yaml | 8 ++++---- .../test-resources/deployment/result-nginx-2.yaml | 8 ++++---- .../test-resources/deployment/result-node-1.yaml | 4 ++-- .../test-resources/deployment/result-python-1.yaml | 4 ++-- .../test-resources/deployment/result-varnish-1.yaml | 4 ++-- .../test-resources/deployment/result-worker-1.yaml | 4 ++-- .../service-templates/service1/deployment-node.yaml | 2 +- .../service-templates/service2/deployment-lnd.yaml | 2 +- .../service2/deployment-thunderhub.yaml | 2 +- .../service-templates/service2/deployment-tor.yaml | 2 +- .../service-templates/service3/deployment-lnd.yaml | 2 +- .../service-templates/service3/deployment-tor.yaml | 2 +- .../service-templates/service4/deployment-node.yaml | 2 +- .../service-templates/service5/deployment-node.yaml | 2 +- .../service-templates/service6/deployment-node.yaml | 2 +- .../service1/cronjob-cronjob-cli-drush-cron2.yaml | 2 +- .../service-templates/service1/deployment-cli.yaml | 2 +- .../service1/deployment-nginx-php.yaml | 4 ++-- .../service-templates/service1/deployment-varnish.yaml | 2 +- .../service2/cronjob-cronjob-cli-drush-cron2.yaml | 2 +- .../service-templates/service2/deployment-cli.yaml | 2 +- .../service2/deployment-nginx-php.yaml | 4 ++-- .../service-templates/service2/deployment-varnish.yaml | 2 +- .../service-templates/service3/deployment-web.yaml | 2 +- 37 files changed, 58 insertions(+), 58 deletions(-) diff --git a/internal/servicetypes/basic.go b/internal/servicetypes/basic.go index 0bb7133e..58a649f0 100644 --- a/internal/servicetypes/basic.go +++ b/internal/servicetypes/basic.go @@ -64,7 +64,7 @@ var basic = ServiceType{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), - corev1.ResourceMemory: resource.MustParse("100M"), + corev1.ResourceMemory: resource.MustParse("10Mi"), }, }, }, diff --git a/internal/servicetypes/cli.go b/internal/servicetypes/cli.go index 755fffcd..00d2c871 100644 --- a/internal/servicetypes/cli.go +++ b/internal/servicetypes/cli.go @@ -49,7 +49,7 @@ var cli = ServiceType{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), - corev1.ResourceMemory: resource.MustParse("100M"), + corev1.ResourceMemory: resource.MustParse("10Mi"), }, }, }, diff --git a/internal/servicetypes/nginx.go b/internal/servicetypes/nginx.go index c5ad261a..5ef283c1 100644 --- a/internal/servicetypes/nginx.go +++ b/internal/servicetypes/nginx.go @@ -67,7 +67,7 @@ var nginx = ServiceType{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), - corev1.ResourceMemory: resource.MustParse("10M"), + corev1.ResourceMemory: resource.MustParse("10Mi"), }, }, }, @@ -125,7 +125,7 @@ var nginxPHP = ServiceType{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), - corev1.ResourceMemory: resource.MustParse("10M"), + corev1.ResourceMemory: resource.MustParse("10Mi"), }, }, }, @@ -175,7 +175,7 @@ var nginxPHP = ServiceType{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), - corev1.ResourceMemory: resource.MustParse("100M"), + corev1.ResourceMemory: resource.MustParse("100Mi"), }, }, }, diff --git a/internal/servicetypes/node.go b/internal/servicetypes/node.go index f126b5ef..5547afe8 100644 --- a/internal/servicetypes/node.go +++ b/internal/servicetypes/node.go @@ -62,7 +62,7 @@ var node = ServiceType{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), - corev1.ResourceMemory: resource.MustParse("100M"), + corev1.ResourceMemory: resource.MustParse("100Mi"), }, }, }, diff --git a/internal/servicetypes/python.go b/internal/servicetypes/python.go index 3f49bb34..dbe57248 100644 --- a/internal/servicetypes/python.go +++ b/internal/servicetypes/python.go @@ -62,7 +62,7 @@ var python = ServiceType{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), - corev1.ResourceMemory: resource.MustParse("100M"), + corev1.ResourceMemory: resource.MustParse("10Mi"), }, }, }, diff --git a/internal/servicetypes/rabbitmq.go b/internal/servicetypes/rabbitmq.go index aa62db9a..e3820c65 100644 --- a/internal/servicetypes/rabbitmq.go +++ b/internal/servicetypes/rabbitmq.go @@ -82,7 +82,7 @@ var rabbitmq = ServiceType{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), - corev1.ResourceMemory: resource.MustParse("100M"), + corev1.ResourceMemory: resource.MustParse("10Mi"), }, }, }, diff --git a/internal/servicetypes/varnish.go b/internal/servicetypes/varnish.go index 4abfc190..78376cd2 100644 --- a/internal/servicetypes/varnish.go +++ b/internal/servicetypes/varnish.go @@ -78,7 +78,7 @@ var varnish = ServiceType{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), - corev1.ResourceMemory: resource.MustParse("100M"), + corev1.ResourceMemory: resource.MustParse("10Mi"), }, }, }, diff --git a/internal/servicetypes/worker.go b/internal/servicetypes/worker.go index 1ed69796..b9201296 100644 --- a/internal/servicetypes/worker.go +++ b/internal/servicetypes/worker.go @@ -36,7 +36,7 @@ var worker = ServiceType{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("10m"), - corev1.ResourceMemory: resource.MustParse("100M"), + corev1.ResourceMemory: resource.MustParse("10Mi"), }, }, }, diff --git a/internal/templating/services/test-resources/cronjob/result-cli-1.yaml b/internal/templating/services/test-resources/cronjob/result-cli-1.yaml index 5229e4a2..0bf9b243 100644 --- a/internal/templating/services/test-resources/cronjob/result-cli-1.yaml +++ b/internal/templating/services/test-resources/cronjob/result-cli-1.yaml @@ -58,7 +58,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ @@ -144,7 +144,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ @@ -230,7 +230,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ diff --git a/internal/templating/services/test-resources/deployment/result-basic-1.yaml b/internal/templating/services/test-resources/deployment/result-basic-1.yaml index 2ce3c8df..169d044a 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-1.yaml @@ -77,7 +77,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: @@ -170,7 +170,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: @@ -260,7 +260,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /storage/data @@ -350,7 +350,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /storage/data @@ -440,7 +440,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /storage/data diff --git a/internal/templating/services/test-resources/deployment/result-basic-2.yaml b/internal/templating/services/test-resources/deployment/result-basic-2.yaml index 7e75eba5..7670d3d0 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-2.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-2.yaml @@ -87,7 +87,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: diff --git a/internal/templating/services/test-resources/deployment/result-basic-3.yaml b/internal/templating/services/test-resources/deployment/result-basic-3.yaml index e8d2913e..83897642 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-3.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-3.yaml @@ -91,7 +91,7 @@ spec: requests: cpu: 10m ephemeral-storage: 1Gi - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: diff --git a/internal/templating/services/test-resources/deployment/result-cli-1.yaml b/internal/templating/services/test-resources/deployment/result-cli-1.yaml index b767adab..d2f2ab60 100644 --- a/internal/templating/services/test-resources/deployment/result-cli-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-cli-1.yaml @@ -70,7 +70,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ @@ -158,7 +158,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ diff --git a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml index c36ab1d3..5f36889e 100644 --- a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-nginx-1.yaml @@ -79,7 +79,7 @@ spec: resources: requests: cpu: 10m - memory: 10M + memory: 10Mi securityContext: {} - env: - name: NGINX_FASTCGI_PASS @@ -111,7 +111,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 100Mi securityContext: {} enableServiceLinks: false imagePullSecrets: @@ -203,7 +203,7 @@ spec: resources: requests: cpu: 10m - memory: 10M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /storage/data @@ -238,7 +238,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 100Mi securityContext: {} volumeMounts: - mountPath: /storage/data diff --git a/internal/templating/services/test-resources/deployment/result-nginx-2.yaml b/internal/templating/services/test-resources/deployment/result-nginx-2.yaml index d0e90119..2dc0e24b 100644 --- a/internal/templating/services/test-resources/deployment/result-nginx-2.yaml +++ b/internal/templating/services/test-resources/deployment/result-nginx-2.yaml @@ -79,7 +79,7 @@ spec: resources: requests: cpu: 10m - memory: 10M + memory: 10Mi securityContext: {} - env: - name: NGINX_FASTCGI_PASS @@ -111,7 +111,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 100Mi securityContext: {} enableServiceLinks: false imagePullSecrets: @@ -204,7 +204,7 @@ spec: resources: requests: cpu: 10m - memory: 10M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /storage/data @@ -239,7 +239,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 100Mi securityContext: {} volumeMounts: - mountPath: /storage/data diff --git a/internal/templating/services/test-resources/deployment/result-node-1.yaml b/internal/templating/services/test-resources/deployment/result-node-1.yaml index 5b4dcc01..702b388f 100644 --- a/internal/templating/services/test-resources/deployment/result-node-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-node-1.yaml @@ -74,7 +74,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 100Mi securityContext: {} enableServiceLinks: false imagePullSecrets: @@ -162,7 +162,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 100Mi securityContext: {} volumeMounts: - mountPath: "" diff --git a/internal/templating/services/test-resources/deployment/result-python-1.yaml b/internal/templating/services/test-resources/deployment/result-python-1.yaml index a43e4ca6..27980c42 100644 --- a/internal/templating/services/test-resources/deployment/result-python-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-python-1.yaml @@ -74,7 +74,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: @@ -162,7 +162,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: "" diff --git a/internal/templating/services/test-resources/deployment/result-varnish-1.yaml b/internal/templating/services/test-resources/deployment/result-varnish-1.yaml index 92817e4b..b0d5e6fb 100644 --- a/internal/templating/services/test-resources/deployment/result-varnish-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-varnish-1.yaml @@ -77,7 +77,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: @@ -171,7 +171,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/cache/varnish diff --git a/internal/templating/services/test-resources/deployment/result-worker-1.yaml b/internal/templating/services/test-resources/deployment/result-worker-1.yaml index 564d9eff..b38ff315 100644 --- a/internal/templating/services/test-resources/deployment/result-worker-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-worker-1.yaml @@ -70,7 +70,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ @@ -158,7 +158,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ diff --git a/internal/testdata/basic/service-templates/service1/deployment-node.yaml b/internal/testdata/basic/service-templates/service1/deployment-node.yaml index c8e15eee..5684eb16 100644 --- a/internal/testdata/basic/service-templates/service1/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service1/deployment-node.yaml @@ -80,7 +80,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: diff --git a/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml index c95c9cd5..62105f11 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-lnd.yaml @@ -77,7 +77,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /app/storage diff --git a/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml index 99887e5b..ad515770 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-thunderhub.yaml @@ -74,7 +74,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /data diff --git a/internal/testdata/basic/service-templates/service2/deployment-tor.yaml b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml index a4d6c520..7748bd7a 100644 --- a/internal/testdata/basic/service-templates/service2/deployment-tor.yaml +++ b/internal/testdata/basic/service-templates/service2/deployment-tor.yaml @@ -77,7 +77,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: diff --git a/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml index c95c9cd5..62105f11 100644 --- a/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml +++ b/internal/testdata/basic/service-templates/service3/deployment-lnd.yaml @@ -77,7 +77,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /app/storage diff --git a/internal/testdata/basic/service-templates/service3/deployment-tor.yaml b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml index 0a13c7e7..c3d4c1db 100644 --- a/internal/testdata/basic/service-templates/service3/deployment-tor.yaml +++ b/internal/testdata/basic/service-templates/service3/deployment-tor.yaml @@ -70,7 +70,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ diff --git a/internal/testdata/basic/service-templates/service4/deployment-node.yaml b/internal/testdata/basic/service-templates/service4/deployment-node.yaml index 51013ea4..e7373c84 100644 --- a/internal/testdata/basic/service-templates/service4/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service4/deployment-node.yaml @@ -78,7 +78,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: diff --git a/internal/testdata/basic/service-templates/service5/deployment-node.yaml b/internal/testdata/basic/service-templates/service5/deployment-node.yaml index ac14fc79..a3b58f00 100644 --- a/internal/testdata/basic/service-templates/service5/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service5/deployment-node.yaml @@ -84,7 +84,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: diff --git a/internal/testdata/basic/service-templates/service6/deployment-node.yaml b/internal/testdata/basic/service-templates/service6/deployment-node.yaml index 7ddd426f..ffbf7065 100644 --- a/internal/testdata/basic/service-templates/service6/deployment-node.yaml +++ b/internal/testdata/basic/service-templates/service6/deployment-node.yaml @@ -82,7 +82,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/dynamic/insights-token diff --git a/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml b/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml index 00a1094f..d4acab09 100644 --- a/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml +++ b/internal/testdata/complex/service-templates/service1/cronjob-cronjob-cli-drush-cron2.yaml @@ -58,7 +58,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ diff --git a/internal/testdata/complex/service-templates/service1/deployment-cli.yaml b/internal/testdata/complex/service-templates/service1/deployment-cli.yaml index 198e4a49..f7a10935 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-cli.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-cli.yaml @@ -72,7 +72,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ diff --git a/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml index c8e49f47..eec5dbd8 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-nginx-php.yaml @@ -79,7 +79,7 @@ spec: resources: requests: cpu: 10m - memory: 10M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /app/docroot/sites/default/files/ @@ -114,7 +114,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 100Mi securityContext: {} volumeMounts: - mountPath: /app/docroot/sites/default/files/ diff --git a/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml index 9d441e6a..470d1dd8 100644 --- a/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml +++ b/internal/testdata/complex/service-templates/service1/deployment-varnish.yaml @@ -77,7 +77,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: diff --git a/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml b/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml index 6f4b8bdc..b860120b 100644 --- a/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml +++ b/internal/testdata/complex/service-templates/service2/cronjob-cronjob-cli-drush-cron2.yaml @@ -58,7 +58,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ diff --git a/internal/testdata/complex/service-templates/service2/deployment-cli.yaml b/internal/testdata/complex/service-templates/service2/deployment-cli.yaml index a88b6c82..ac370e98 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-cli.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-cli.yaml @@ -72,7 +72,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /var/run/secrets/lagoon/sshkey/ diff --git a/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml index 2ef8dd4f..aba76bd9 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-nginx-php.yaml @@ -79,7 +79,7 @@ spec: resources: requests: cpu: 10m - memory: 10M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /app/docroot/sites/default/files/ @@ -114,7 +114,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 100Mi securityContext: {} volumeMounts: - mountPath: /app/docroot/sites/default/files/ diff --git a/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml index 785e85af..a1f2743d 100644 --- a/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml +++ b/internal/testdata/complex/service-templates/service2/deployment-varnish.yaml @@ -77,7 +77,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} enableServiceLinks: false imagePullSecrets: diff --git a/internal/testdata/complex/service-templates/service3/deployment-web.yaml b/internal/testdata/complex/service-templates/service3/deployment-web.yaml index 5952505a..90e69080 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-web.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-web.yaml @@ -74,7 +74,7 @@ spec: resources: requests: cpu: 10m - memory: 100M + memory: 10Mi securityContext: {} volumeMounts: - mountPath: /app/files From 7dc6df43034dfb7c44540da1a52a3cd4e7c06169 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 15 Jul 2024 18:30:17 +1000 Subject: [PATCH 89/92] fix: use http for default port names in services, other test data fixes --- cmd/template_ingress_test.go | 2 +- internal/servicetypes/basic.go | 6 +- internal/servicetypes/types.go | 2 + .../templating/ingress/templates_ingress.go | 6 +- .../ingress/templates_ingress_test.go | 79 +++++++++++++++++++ .../deployment/result-basic-1.yaml | 10 +-- .../service/result-basic-1.yaml | 16 ++-- .../service3/deployment-web.yaml | 2 +- .../service3/service-web.yaml | 4 +- internal/testdata/nginxphp/lagoon.nginx-1.yml | 2 +- internal/testdata/nginxphp/lagoon.nginx-2.yml | 2 +- .../ingress-11/test1.example.com.yaml | 2 +- .../ingress-19/performance.example.com.yaml | 2 +- .../ingress-20/performance.example.com.yaml | 2 +- internal/testdata/node/lagoon.polysite-pr.yml | 2 +- internal/testdata/node/lagoon.yml | 2 +- 16 files changed, 112 insertions(+), 29 deletions(-) diff --git a/cmd/template_ingress_test.go b/cmd/template_ingress_test.go index ac5ad99d..d55f7b91 100644 --- a/cmd/template_ingress_test.go +++ b/cmd/template_ingress_test.go @@ -199,7 +199,7 @@ func TestTemplateRoutes(t *testing.T) { }, { Name: "LAGOON_ROUTES_JSON", - Value: base64.StdEncoding.EncodeToString([]byte(`{"routes":[{"domain":"test1.example.com","service":"nginx","tls-acme":false,"monitoring-path":"/bypass-cache"}]}`)), + Value: base64.StdEncoding.EncodeToString([]byte(`{"routes":[{"domain":"test1.example.com","service":"node","tls-acme":false,"monitoring-path":"/bypass-cache"}]}`)), Scope: "build", }, }, diff --git a/internal/servicetypes/basic.go b/internal/servicetypes/basic.go index 58a649f0..f072ce6b 100644 --- a/internal/servicetypes/basic.go +++ b/internal/servicetypes/basic.go @@ -18,10 +18,10 @@ var basic = ServiceType{ Port: defaultBasicPort, // this is the default port for basic service type TargetPort: intstr.IntOrString{ Type: intstr.String, - StrVal: "basic", + StrVal: "http", }, Protocol: corev1.ProtocolTCP, - Name: "basic", + Name: "http", }, }, }, @@ -32,7 +32,7 @@ var basic = ServiceType{ SecurityContext: &corev1.SecurityContext{}, Ports: []corev1.ContainerPort{ { - Name: "basic", + Name: "http", ContainerPort: defaultBasicPort, Protocol: corev1.ProtocolTCP, }, diff --git a/internal/servicetypes/types.go b/internal/servicetypes/types.go index 935983b8..27c43d84 100644 --- a/internal/servicetypes/types.go +++ b/internal/servicetypes/types.go @@ -47,6 +47,8 @@ type BackupConfiguration struct { FileExtension string } +// when defining default ServicePorts for a service, the first port in the list should be the port that could be associated to an ingress +// the name of this port must be `http` type ServicePorts struct { CanChangePort bool Ports []corev1.ServicePort diff --git a/internal/templating/ingress/templates_ingress.go b/internal/templating/ingress/templates_ingress.go index b7c26aa1..3d5d3bb6 100644 --- a/internal/templating/ingress/templates_ingress.go +++ b/internal/templating/ingress/templates_ingress.go @@ -44,7 +44,7 @@ func GenerateIngressTemplate( ingress.ObjectMeta.Name = route.IngressName // if this is a wildcard ingress, handle templating that here - if route.Wildcard != nil && *route.Wildcard == true { + if route.Wildcard != nil && *route.Wildcard { truncatedRouteDomain = fmt.Sprintf("wildcard-%s", truncatedRouteDomain) if len(truncatedRouteDomain) >= 53 { subdomain := strings.Split(truncatedRouteDomain, "-")[0] @@ -236,7 +236,7 @@ func GenerateIngressTemplate( // this injects a shorter domain into the tls spec that is used in the k8s challenge // use the compose service name to check this, as this is how Services are populated from the compose generation for _, service := range lValues.Services { - if service.Name == route.ComposeService { + if service.OverrideName == route.LagoonService { if service.ShortAutogeneratedRouteDomain != "" && len(route.Domain) > 63 { ingress.Spec.TLS[0].Hosts = append(ingress.Spec.TLS[0].Hosts, service.ShortAutogeneratedRouteDomain) } @@ -246,6 +246,8 @@ func GenerateIngressTemplate( ingress.Spec.TLS[0].Hosts = append(ingress.Spec.TLS[0].Hosts, route.Domain) // default service port is http in all lagoon deployments + // this should be the port that usually would be accessible via an ingress if the service would normally + // allow this servicePort := networkv1.ServiceBackendPort{ Name: "http", } diff --git a/internal/templating/ingress/templates_ingress_test.go b/internal/templating/ingress/templates_ingress_test.go index 1321d026..adcda7e5 100644 --- a/internal/templating/ingress/templates_ingress_test.go +++ b/internal/templating/ingress/templates_ingress_test.go @@ -58,6 +58,13 @@ func TestGenerateKubeTemplate(t *testing.T) { StatusPageID: "12345", Enabled: true, }, + Services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + }, + }, Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/", }, activeStandby: true, @@ -96,6 +103,13 @@ func TestGenerateKubeTemplate(t *testing.T) { StatusPageID: "12345", Enabled: true, }, + Services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + }, + }, Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/", }, activeStandby: false, @@ -134,6 +148,13 @@ func TestGenerateKubeTemplate(t *testing.T) { StatusPageID: "12345", Enabled: true, }, + Services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + }, + }, Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/", }, activeStandby: false, @@ -173,6 +194,13 @@ func TestGenerateKubeTemplate(t *testing.T) { StatusPageID: "12345", Enabled: true, }, + Services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + }, + }, Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/", }, activeStandby: false, @@ -214,6 +242,13 @@ func TestGenerateKubeTemplate(t *testing.T) { StatusPageID: "12345", Enabled: true, }, + Services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + }, + }, Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/", }, activeStandby: false, @@ -258,6 +293,13 @@ func TestGenerateKubeTemplate(t *testing.T) { StatusPageID: "12345", Enabled: true, }, + Services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + }, + }, Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/", }, activeStandby: false, @@ -298,6 +340,13 @@ func TestGenerateKubeTemplate(t *testing.T) { StatusPageID: "12345", Enabled: true, }, + Services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + }, + }, }, activeStandby: false, }, @@ -377,6 +426,13 @@ func TestGenerateKubeTemplate(t *testing.T) { StatusPageID: "12345", Enabled: true, }, + Services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + }, + }, }, activeStandby: false, }, @@ -416,6 +472,13 @@ func TestGenerateKubeTemplate(t *testing.T) { StatusPageID: "12345", Enabled: true, }, + Services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + }, + }, }, activeStandby: false, }, @@ -455,6 +518,13 @@ func TestGenerateKubeTemplate(t *testing.T) { StatusPageID: "12345", Enabled: true, }, + Services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "nginx-php", + }, + }, }, activeStandby: false, }, @@ -498,6 +568,7 @@ func TestGenerateKubeTemplate(t *testing.T) { { Name: "myservice-po", OverrideName: "myservice-po", + Type: "basic", AdditionalServicePorts: []generator.AdditionalServicePort{ { ServiceName: "myservice-po-8192", @@ -559,6 +630,7 @@ func TestGenerateKubeTemplate(t *testing.T) { { Name: "myservice-po", OverrideName: "myservice-po", + Type: "basic", AdditionalServicePorts: []generator.AdditionalServicePort{ { ServiceName: "myservice-po-8192", @@ -615,6 +687,13 @@ func TestGenerateKubeTemplate(t *testing.T) { StatusPageID: "12345", Enabled: true, }, + Services: []generator.ServiceValues{ + { + Name: "nginx", + OverrideName: "nginx", + Type: "basic", + }, + }, Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/", }, activeStandby: false, diff --git a/internal/templating/services/test-resources/deployment/result-basic-1.yaml b/internal/templating/services/test-resources/deployment/result-basic-1.yaml index 169d044a..af7cfb0a 100644 --- a/internal/templating/services/test-resources/deployment/result-basic-1.yaml +++ b/internal/templating/services/test-resources/deployment/result-basic-1.yaml @@ -67,7 +67,7 @@ spec: name: basic ports: - containerPort: 3000 - name: basic + name: http protocol: TCP readinessProbe: initialDelaySeconds: 1 @@ -160,7 +160,7 @@ spec: name: basic ports: - containerPort: 8080 - name: basic + name: http protocol: TCP readinessProbe: initialDelaySeconds: 1 @@ -250,7 +250,7 @@ spec: name: basic ports: - containerPort: 3000 - name: basic + name: http protocol: TCP readinessProbe: initialDelaySeconds: 1 @@ -340,7 +340,7 @@ spec: name: basic ports: - containerPort: 8080 - name: basic + name: http protocol: TCP readinessProbe: initialDelaySeconds: 1 @@ -430,7 +430,7 @@ spec: name: basic ports: - containerPort: 8080 - name: basic + name: http protocol: TCP readinessProbe: initialDelaySeconds: 1 diff --git a/internal/templating/services/test-resources/service/result-basic-1.yaml b/internal/templating/services/test-resources/service/result-basic-1.yaml index 19e0ae6e..5d37a453 100644 --- a/internal/templating/services/test-resources/service/result-basic-1.yaml +++ b/internal/templating/services/test-resources/service/result-basic-1.yaml @@ -20,10 +20,10 @@ metadata: name: myservice spec: ports: - - name: basic + - name: http port: 3000 protocol: TCP - targetPort: basic + targetPort: http selector: app.kubernetes.io/instance: myservice app.kubernetes.io/name: basic @@ -51,10 +51,10 @@ metadata: name: myservice-po spec: ports: - - name: basic + - name: http port: 8080 protocol: TCP - targetPort: basic + targetPort: http selector: app.kubernetes.io/instance: myservice-po app.kubernetes.io/name: basic @@ -82,10 +82,10 @@ metadata: name: myservice-persist spec: ports: - - name: basic + - name: http port: 3000 protocol: TCP - targetPort: basic + targetPort: http selector: app.kubernetes.io/instance: myservice-persist app.kubernetes.io/name: basic-persistent @@ -113,10 +113,10 @@ metadata: name: myservice-persist-po spec: ports: - - name: basic + - name: http port: 8080 protocol: TCP - targetPort: basic + targetPort: http selector: app.kubernetes.io/instance: myservice-persist-po app.kubernetes.io/name: basic-persistent diff --git a/internal/testdata/complex/service-templates/service3/deployment-web.yaml b/internal/testdata/complex/service-templates/service3/deployment-web.yaml index 90e69080..9d15af59 100644 --- a/internal/testdata/complex/service-templates/service3/deployment-web.yaml +++ b/internal/testdata/complex/service-templates/service3/deployment-web.yaml @@ -64,7 +64,7 @@ spec: name: basic ports: - containerPort: 3000 - name: basic + name: http protocol: TCP readinessProbe: initialDelaySeconds: 1 diff --git a/internal/testdata/complex/service-templates/service3/service-web.yaml b/internal/testdata/complex/service-templates/service3/service-web.yaml index 39fe1e1c..0df077d9 100644 --- a/internal/testdata/complex/service-templates/service3/service-web.yaml +++ b/internal/testdata/complex/service-templates/service3/service-web.yaml @@ -20,10 +20,10 @@ metadata: name: web spec: ports: - - name: basic + - name: http port: 3000 protocol: TCP - targetPort: basic + targetPort: http selector: app.kubernetes.io/instance: web app.kubernetes.io/name: basic-persistent diff --git a/internal/testdata/nginxphp/lagoon.nginx-1.yml b/internal/testdata/nginxphp/lagoon.nginx-1.yml index 4212e188..c940fb28 100644 --- a/internal/testdata/nginxphp/lagoon.nginx-1.yml +++ b/internal/testdata/nginxphp/lagoon.nginx-1.yml @@ -12,5 +12,5 @@ environment_variables: environments: main: routes: - - node: + - nginx-php: - example.com diff --git a/internal/testdata/nginxphp/lagoon.nginx-2.yml b/internal/testdata/nginxphp/lagoon.nginx-2.yml index 3f676c05..deff1a71 100644 --- a/internal/testdata/nginxphp/lagoon.nginx-2.yml +++ b/internal/testdata/nginxphp/lagoon.nginx-2.yml @@ -6,5 +6,5 @@ environment_variables: environments: main: routes: - - node: + - nginx-php: - example.com diff --git a/internal/testdata/node/ingress-templates/ingress-11/test1.example.com.yaml b/internal/testdata/node/ingress-templates/ingress-11/test1.example.com.yaml index 2c588256..4f8b813e 100644 --- a/internal/testdata/node/ingress-templates/ingress-11/test1.example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-11/test1.example.com.yaml @@ -38,7 +38,7 @@ spec: paths: - backend: service: - name: nginx + name: node port: name: http path: / diff --git a/internal/testdata/node/ingress-templates/ingress-19/performance.example.com.yaml b/internal/testdata/node/ingress-templates/ingress-19/performance.example.com.yaml index 0db1225b..45fab283 100644 --- a/internal/testdata/node/ingress-templates/ingress-19/performance.example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-19/performance.example.com.yaml @@ -35,7 +35,7 @@ spec: paths: - backend: service: - name: nginx + name: node port: name: http path: / diff --git a/internal/testdata/node/ingress-templates/ingress-20/performance.example.com.yaml b/internal/testdata/node/ingress-templates/ingress-20/performance.example.com.yaml index 0db1225b..45fab283 100644 --- a/internal/testdata/node/ingress-templates/ingress-20/performance.example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-20/performance.example.com.yaml @@ -35,7 +35,7 @@ spec: paths: - backend: service: - name: nginx + name: node port: name: http path: / diff --git a/internal/testdata/node/lagoon.polysite-pr.yml b/internal/testdata/node/lagoon.polysite-pr.yml index c324dbef..04115874 100644 --- a/internal/testdata/node/lagoon.polysite-pr.yml +++ b/internal/testdata/node/lagoon.polysite-pr.yml @@ -19,7 +19,7 @@ example-project: - app.develop.example.com pr-4841: routes: - - nginx: + - node: - performance.example.com example-project2: diff --git a/internal/testdata/node/lagoon.yml b/internal/testdata/node/lagoon.yml index 97a55e2a..1ed5fd96 100644 --- a/internal/testdata/node/lagoon.yml +++ b/internal/testdata/node/lagoon.yml @@ -55,7 +55,7 @@ environments: pr-4841: routes: - - nginx: + - node: - performance.example.com alternativename: From 70f24747668ff8c2f6850d3cd2c5c202cbbc348c Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 15 Jul 2024 19:46:37 +1000 Subject: [PATCH 90/92] fix: isolation-network-policy labels --- internal/templating/networkpolicy/template_networkpolicy.go | 5 +++++ .../templating/networkpolicy/test-resources/result-np-1.yaml | 5 +++++ .../service-templates/service5/isolation-network-policy.yaml | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/internal/templating/networkpolicy/template_networkpolicy.go b/internal/templating/networkpolicy/template_networkpolicy.go index 9e5f3016..bc3ffb64 100644 --- a/internal/templating/networkpolicy/template_networkpolicy.go +++ b/internal/templating/networkpolicy/template_networkpolicy.go @@ -13,10 +13,15 @@ func GenerateNetworkPolicy( // add the default labels labels := map[string]string{ "app.kubernetes.io/managed-by": "build-deploy-tool", + "app.kubernetes.io/instance": "isolation-network-policy", + "app.kubernetes.io/name": "isolation-network-policy", + "lagoon.sh/template": "isolation-network-policy-0.1.0", "lagoon.sh/project": buildValues.Project, "lagoon.sh/environment": buildValues.Environment, "lagoon.sh/environmentType": buildValues.EnvironmentType, "lagoon.sh/buildType": buildValues.BuildType, + "lagoon.sh/service": "isolation-network-policy", + "lagoon.sh/service-type": "isolation-network-policy", } // add the default annotations diff --git a/internal/templating/networkpolicy/test-resources/result-np-1.yaml b/internal/templating/networkpolicy/test-resources/result-np-1.yaml index 5af02b6a..8130a3a8 100644 --- a/internal/templating/networkpolicy/test-resources/result-np-1.yaml +++ b/internal/templating/networkpolicy/test-resources/result-np-1.yaml @@ -7,11 +7,16 @@ metadata: lagoon.sh/version: v2.x.x creationTimestamp: null labels: + app.kubernetes.io/instance: isolation-network-policy app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: isolation-network-policy lagoon.sh/buildType: branch lagoon.sh/environment: environment-name lagoon.sh/environmentType: production lagoon.sh/project: example-project + lagoon.sh/service: isolation-network-policy + lagoon.sh/service-type: isolation-network-policy + lagoon.sh/template: isolation-network-policy-0.1.0 name: isolation-network-policy spec: ingress: diff --git a/internal/testdata/basic/service-templates/service5/isolation-network-policy.yaml b/internal/testdata/basic/service-templates/service5/isolation-network-policy.yaml index d333ee32..9cf414b6 100644 --- a/internal/testdata/basic/service-templates/service5/isolation-network-policy.yaml +++ b/internal/testdata/basic/service-templates/service5/isolation-network-policy.yaml @@ -9,11 +9,16 @@ metadata: lagoon.sh/version: v2.7.x creationTimestamp: null labels: + app.kubernetes.io/instance: isolation-network-policy app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: isolation-network-policy lagoon.sh/buildType: pullrequest lagoon.sh/environment: pr-123 lagoon.sh/environmentType: production lagoon.sh/project: example-project + lagoon.sh/service: isolation-network-policy + lagoon.sh/service-type: isolation-network-policy + lagoon.sh/template: isolation-network-policy-0.1.0 name: isolation-network-policy spec: ingress: From 3922f93589bf5a2c793518933f76359db6964906 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 15 Jul 2024 20:44:46 +1000 Subject: [PATCH 91/92] refactor: select lagoon core version if variable is present --- cmd/template_lagoonservices_test.go | 5 +++++ internal/generator/generator.go | 6 ++++++ .../service4/deployment-mariadb-10-11.yaml | 4 ++-- .../service-templates/service4/deployment-mariadb-10-5.yaml | 4 ++-- .../service-templates/service4/deployment-mongo-4.yaml | 4 ++-- .../service-templates/service4/deployment-postgres-11.yaml | 4 ++-- .../service-templates/service4/deployment-postgres-15.yaml | 4 ++-- .../service-templates/service4/pvc-mariadb-10-11.yaml | 2 +- .../service-templates/service4/pvc-mariadb-10-5.yaml | 2 +- .../complex/service-templates/service4/pvc-mongo-4.yaml | 2 +- .../complex/service-templates/service4/pvc-postgres-11.yaml | 2 +- .../complex/service-templates/service4/pvc-postgres-15.yaml | 2 +- .../service-templates/service4/service-mariadb-10-11.yaml | 2 +- .../service-templates/service4/service-mariadb-10-5.yaml | 2 +- .../complex/service-templates/service4/service-mongo-4.yaml | 2 +- .../service-templates/service4/service-postgres-11.yaml | 2 +- .../service-templates/service4/service-postgres-15.yaml | 2 +- 17 files changed, 31 insertions(+), 20 deletions(-) diff --git a/cmd/template_lagoonservices_test.go b/cmd/template_lagoonservices_test.go index e5e5d659..80f7b059 100644 --- a/cmd/template_lagoonservices_test.go +++ b/cmd/template_lagoonservices_test.go @@ -273,6 +273,11 @@ func TestTemplateLagoonServices(t *testing.T) { }, ProjectVariables: []lagoon.EnvironmentVariable{ {Name: "LAGOON_DBAAS_ENVIRONMENT_TYPES", Value: "postgres-15:production-postgres,mongo-4:production-mongo,mariadb-10-11:production-mariadb", Scope: "build"}, + { + Name: "LAGOON_SYSTEM_CORE_VERSION", + Value: "v2.19.0", + Scope: "internal_system", + }, }, }, true), templatePath: "testoutput", diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 3b48d91c..3aeb6548 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -255,6 +255,12 @@ func NewGenerator( // this will later be used to add `runtime|global` scope into the `lagoon-env` configmap buildValues.EnvironmentVariables = lagoon.MergeVariables(mergedVariables, configVars) + // if the core version is provided from the API, set the buildvalues LagoonVersion to this instead + lagoonCoreVersion, _ := lagoon.GetLagoonVariable("LAGOON_SYSTEM_CORE_VERSION", []string{"internal_system"}, buildValues.EnvironmentVariables) + if lagoonCoreVersion != nil { + buildValues.LagoonVersion = lagoonCoreVersion.Value + } + // handle generating the container registry login generation here, extract from the `.lagoon.yml` firstly if err := configureContainerRegistries(&buildValues); err != nil { return nil, err diff --git a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml index 65e8ebbc..bb9bfb2e 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-11.yaml @@ -4,7 +4,7 @@ kind: Deployment metadata: annotations: lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: mariadb-10-11 @@ -35,7 +35,7 @@ spec: k8up.syn.tools/file-extension: .mariadb-10-11.sql lagoon.sh/branch: main lagoon.sh/configMapSha: abcdefg1234567890 - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: mariadb-10-11 diff --git a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml index bf281550..40a69f51 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-mariadb-10-5.yaml @@ -4,7 +4,7 @@ kind: Deployment metadata: annotations: lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: mariadb-10-5 @@ -35,7 +35,7 @@ spec: k8up.syn.tools/file-extension: .mariadb-10-5.sql lagoon.sh/branch: main lagoon.sh/configMapSha: abcdefg1234567890 - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: mariadb-10-5 diff --git a/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml b/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml index 9302c15f..eccf956c 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-mongo-4.yaml @@ -4,7 +4,7 @@ kind: Deployment metadata: annotations: lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: mongo-4 @@ -34,7 +34,7 @@ spec: k8up.syn.tools/file-extension: .mongo-4.tar lagoon.sh/branch: main lagoon.sh/configMapSha: abcdefg1234567890 - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: mongo-4 diff --git a/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml b/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml index 797edcb0..8aea61ba 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-postgres-11.yaml @@ -4,7 +4,7 @@ kind: Deployment metadata: annotations: lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: postgres-11 @@ -35,7 +35,7 @@ spec: k8up.syn.tools/file-extension: .postgres-11.tar lagoon.sh/branch: main lagoon.sh/configMapSha: abcdefg1234567890 - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: postgres-11 diff --git a/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml b/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml index d95c7f40..61880eae 100644 --- a/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml +++ b/internal/testdata/complex/service-templates/service4/deployment-postgres-15.yaml @@ -4,7 +4,7 @@ kind: Deployment metadata: annotations: lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: postgres-15 @@ -35,7 +35,7 @@ spec: k8up.syn.tools/file-extension: .postgres-15.tar lagoon.sh/branch: main lagoon.sh/configMapSha: abcdefg1234567890 - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: postgres-15 diff --git a/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-11.yaml b/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-11.yaml index 0a2e8667..cd03528a 100644 --- a/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-11.yaml +++ b/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-11.yaml @@ -6,7 +6,7 @@ metadata: k8up.io/backup: "false" k8up.syn.tools/backup: "false" lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: mariadb-10-11 diff --git a/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-5.yaml index 9f7a2c03..bd27282a 100644 --- a/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-5.yaml +++ b/internal/testdata/complex/service-templates/service4/pvc-mariadb-10-5.yaml @@ -6,7 +6,7 @@ metadata: k8up.io/backup: "false" k8up.syn.tools/backup: "false" lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: mariadb-10-5 diff --git a/internal/testdata/complex/service-templates/service4/pvc-mongo-4.yaml b/internal/testdata/complex/service-templates/service4/pvc-mongo-4.yaml index 067a1ed0..dd86c2c1 100644 --- a/internal/testdata/complex/service-templates/service4/pvc-mongo-4.yaml +++ b/internal/testdata/complex/service-templates/service4/pvc-mongo-4.yaml @@ -6,7 +6,7 @@ metadata: k8up.io/backup: "false" k8up.syn.tools/backup: "false" lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: mongo-4 diff --git a/internal/testdata/complex/service-templates/service4/pvc-postgres-11.yaml b/internal/testdata/complex/service-templates/service4/pvc-postgres-11.yaml index 60c75f0b..00e251ff 100644 --- a/internal/testdata/complex/service-templates/service4/pvc-postgres-11.yaml +++ b/internal/testdata/complex/service-templates/service4/pvc-postgres-11.yaml @@ -6,7 +6,7 @@ metadata: k8up.io/backup: "false" k8up.syn.tools/backup: "false" lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: postgres-11 diff --git a/internal/testdata/complex/service-templates/service4/pvc-postgres-15.yaml b/internal/testdata/complex/service-templates/service4/pvc-postgres-15.yaml index 06468f15..1f9001c2 100644 --- a/internal/testdata/complex/service-templates/service4/pvc-postgres-15.yaml +++ b/internal/testdata/complex/service-templates/service4/pvc-postgres-15.yaml @@ -6,7 +6,7 @@ metadata: k8up.io/backup: "false" k8up.syn.tools/backup: "false" lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: postgres-15 diff --git a/internal/testdata/complex/service-templates/service4/service-mariadb-10-11.yaml b/internal/testdata/complex/service-templates/service4/service-mariadb-10-11.yaml index e9ff6fa0..c3001e7c 100644 --- a/internal/testdata/complex/service-templates/service4/service-mariadb-10-11.yaml +++ b/internal/testdata/complex/service-templates/service4/service-mariadb-10-11.yaml @@ -4,7 +4,7 @@ kind: Service metadata: annotations: lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: mariadb-10-11 diff --git a/internal/testdata/complex/service-templates/service4/service-mariadb-10-5.yaml b/internal/testdata/complex/service-templates/service4/service-mariadb-10-5.yaml index 8ce04e6d..14fedce2 100644 --- a/internal/testdata/complex/service-templates/service4/service-mariadb-10-5.yaml +++ b/internal/testdata/complex/service-templates/service4/service-mariadb-10-5.yaml @@ -4,7 +4,7 @@ kind: Service metadata: annotations: lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: mariadb-10-5 diff --git a/internal/testdata/complex/service-templates/service4/service-mongo-4.yaml b/internal/testdata/complex/service-templates/service4/service-mongo-4.yaml index 27ba47eb..4189670d 100644 --- a/internal/testdata/complex/service-templates/service4/service-mongo-4.yaml +++ b/internal/testdata/complex/service-templates/service4/service-mongo-4.yaml @@ -4,7 +4,7 @@ kind: Service metadata: annotations: lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: mongo-4 diff --git a/internal/testdata/complex/service-templates/service4/service-postgres-11.yaml b/internal/testdata/complex/service-templates/service4/service-postgres-11.yaml index fe6e202b..edd88114 100644 --- a/internal/testdata/complex/service-templates/service4/service-postgres-11.yaml +++ b/internal/testdata/complex/service-templates/service4/service-postgres-11.yaml @@ -4,7 +4,7 @@ kind: Service metadata: annotations: lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: postgres-11 diff --git a/internal/testdata/complex/service-templates/service4/service-postgres-15.yaml b/internal/testdata/complex/service-templates/service4/service-postgres-15.yaml index d039c1a7..bb4e32f2 100644 --- a/internal/testdata/complex/service-templates/service4/service-postgres-15.yaml +++ b/internal/testdata/complex/service-templates/service4/service-postgres-15.yaml @@ -4,7 +4,7 @@ kind: Service metadata: annotations: lagoon.sh/branch: main - lagoon.sh/version: v2.7.x + lagoon.sh/version: v2.19.0 creationTimestamp: null labels: app.kubernetes.io/instance: postgres-15 From 7e775fdf3924cacc02d050423048c49f0ff887b6 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 15 Jul 2024 20:45:01 +1000 Subject: [PATCH 92/92] refactor: use build-deploy-tool labels on ingress, not helm --- internal/generator/ingress.go | 2 +- internal/generator/ingress_test.go | 6 +++--- internal/helpers/helpers_test.go | 8 ++++---- internal/templating/ingress/templates_ingress.go | 4 ++-- .../ingress/test-resources/result-active-standby1.yaml | 4 ++-- .../ingress/test-resources/result-custom-ingress1.yaml | 4 ++-- .../ingress/test-resources/result-custom-ingress2.yaml | 4 ++-- .../ingress/test-resources/result-custom-ingress3.yaml | 4 ++-- .../ingress/test-resources/result-custom-ingress4.yaml | 4 ++-- .../ingress/test-resources/result-custom-ingress5.yaml | 4 ++-- .../ingress/test-resources/result-custom-ingress6.yaml | 4 ++-- .../ingress/test-resources/result-custom-ingress7.yaml | 4 ++-- .../ingress/test-resources/result-custom-ingress8.yaml | 4 ++-- .../ingress/test-resources/result-custom-ingress9.yaml | 4 ++-- .../ingress/test-resources/result-wildcard-ingress1.yaml | 4 ++-- .../ingress/test-resources/result-wildcard-ingress2.yaml | 4 ++-- .../testdata/basic/autogen-templates/ingress-1/nginx.yaml | 4 ++-- .../complex/autogen-templates/ingress-1/nginx.yaml | 4 ++-- .../complex/autogen-templates/ingress-2/nginx-php.yaml | 4 ++-- .../complex/autogen-templates/ingress-3/nginx.yaml | 4 ++-- .../ingress-templates/ingress-1/content.example.com.yaml | 4 ++-- .../nginxphp/autogen-templates/ingress-1/nginx.yaml | 4 ++-- .../nginxphp/autogen-templates/ingress-2/nginx.yaml | 4 ++-- .../nginxphp/autogen-templates/ingress-3/nginx-php.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-1/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-10/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-11/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-12/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-13/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-14/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-15/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-2/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-3/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-4/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-5/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-6/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-7/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-8/node.yaml | 4 ++-- .../testdata/node/autogen-templates/ingress-9/node.yaml | 4 ++-- .../node/ingress-templates/ingress-1/example.com.yaml | 4 ++-- .../ingress-templates/ingress-10/main-sb.example.com.yaml | 4 ++-- .../ingress-templates/ingress-10/standby.example.com.yaml | 4 ++-- .../ingress-templates/ingress-11/test1.example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-12/example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-13/example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-14/example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-15/example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-16/example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-17/example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-18/example.com.yaml | 4 ++-- .../ingress-templates/ingress-18/www.example.com.yaml | 4 ++-- .../ingress-19/performance.example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-2/example.com.yaml | 4 ++-- .../ingress-20/performance.example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-21/example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-22/example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-23/example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-3/example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-4/example.com.yaml | 4 ++-- .../ingress-templates/ingress-5/multiproject1.com.yaml | 4 ++-- .../ingress-templates/ingress-6/multiproject2.com.yaml | 4 ++-- .../node/ingress-templates/ingress-7/example.com.yaml | 4 ++-- .../node/ingress-templates/ingress-7/www.example.com.yaml | 4 ++-- .../ingress-8/customdomain-will-be-main-domain.com.yaml | 4 ++-- .../customdomain-will-be-not-be-main-domain.com.yaml | 4 ++-- .../ingress-templates/ingress-9/active.example.com.yaml | 4 ++-- .../ingress-templates/ingress-9/main.example.com.yaml | 4 ++-- 67 files changed, 136 insertions(+), 136 deletions(-) diff --git a/internal/generator/ingress.go b/internal/generator/ingress.go index c13de224..12128cf2 100644 --- a/internal/generator/ingress.go +++ b/internal/generator/ingress.go @@ -175,11 +175,11 @@ func generateAutogenRoutes( // overwrite the custom-ingress labels Labels: map[string]string{ "lagoon.sh/autogenerated": "true", - "helm.sh/chart": fmt.Sprintf("%s-%s", "autogenerated-ingress", "0.1.0"), "app.kubernetes.io/name": "autogenerated-ingress", "app.kubernetes.io/instance": serviceOverrideName, "lagoon.sh/service": serviceOverrideName, "lagoon.sh/service-type": service.Type, + "lagoon.sh/template": fmt.Sprintf("%s-%s", "autogenerated-ingress", "0.1.0"), }, IngressClass: ingressClass, Autogenerated: true, diff --git a/internal/generator/ingress_test.go b/internal/generator/ingress_test.go index d351295e..30903ddc 100644 --- a/internal/generator/ingress_test.go +++ b/internal/generator/ingress_test.go @@ -859,10 +859,10 @@ func Test_generateAutogenRoutes(t *testing.T) { Labels: map[string]string{ "app.kubernetes.io/instance": "nginx", "app.kubernetes.io/name": "autogenerated-ingress", - "helm.sh/chart": "autogenerated-ingress-0.1.0", "lagoon.sh/autogenerated": "true", "lagoon.sh/service": "nginx", "lagoon.sh/service-type": "nginx", + "lagoon.sh/template": "autogenerated-ingress-0.1.0", }, IngressName: "nginx", RequestVerification: helpers.BoolPtr(false), @@ -913,10 +913,10 @@ func Test_generateAutogenRoutes(t *testing.T) { Labels: map[string]string{ "app.kubernetes.io/instance": "nginx", "app.kubernetes.io/name": "autogenerated-ingress", - "helm.sh/chart": "autogenerated-ingress-0.1.0", "lagoon.sh/autogenerated": "true", "lagoon.sh/service": "nginx", "lagoon.sh/service-type": "nginx", + "lagoon.sh/template": "autogenerated-ingress-0.1.0", }, IngressName: "nginx", RequestVerification: helpers.BoolPtr(false), @@ -973,10 +973,10 @@ func Test_generateAutogenRoutes(t *testing.T) { Labels: map[string]string{ "app.kubernetes.io/instance": "nginx", "app.kubernetes.io/name": "autogenerated-ingress", - "helm.sh/chart": "autogenerated-ingress-0.1.0", "lagoon.sh/autogenerated": "true", "lagoon.sh/service": "nginx", "lagoon.sh/service-type": "nginx", + "lagoon.sh/template": "autogenerated-ingress-0.1.0", }, IngressName: "nginx", RequestVerification: helpers.BoolPtr(false), diff --git a/internal/helpers/helpers_test.go b/internal/helpers/helpers_test.go index d7ec3d87..294411b9 100644 --- a/internal/helpers/helpers_test.go +++ b/internal/helpers/helpers_test.go @@ -532,9 +532,8 @@ func TestCheckLabelLength(t *testing.T) { args: args{ labels: map[string]string{ "app.kubernetes.io/instance": "extra-long-name-f6c8a", - "app.kubernetes.io/managed-by": "Helm", + "app.kubernetes.io/managed-by": "build-deploy-tool", "app.kubernetes.io/name": "custom-ingress", - "helm.sh/chart": "custom-ingress-0.1.0", "lagoon.sh/autogenerated": "false", "lagoon.sh/buildType": "branch", "lagoon.sh/environment": "environment-with-really-really-reall-3fdb", @@ -542,6 +541,7 @@ func TestCheckLabelLength(t *testing.T) { "lagoon.sh/project": "example-project", "lagoon.sh/service": "extra-long-name-f6c8a", "lagoon.sh/service-type": "custom-ingress", + "lagoon.sh/template": "custom-ingress-0.1.0", }, }, }, @@ -550,9 +550,8 @@ func TestCheckLabelLength(t *testing.T) { args: args{ labels: map[string]string{ "app.kubernetes.io/instance": "extra-long-name.a-really-long-name-that-should-truncate.www.example.com", - "app.kubernetes.io/managed-by": "Helm", + "app.kubernetes.io/managed-by": "build-deploy-tool", "app.kubernetes.io/name": "custom-ingress", - "helm.sh/chart": "custom-ingress-0.1.0", "lagoon.sh/autogenerated": "false", "lagoon.sh/buildType": "branch", "lagoon.sh/environment": "environment-with-really-really-reall-3fdb", @@ -560,6 +559,7 @@ func TestCheckLabelLength(t *testing.T) { "lagoon.sh/project": "example-project", "lagoon.sh/service": "extra-long-name.a-really-long-name-that-should-truncate.www.example.com", "lagoon.sh/service-type": "custom-ingress", + "lagoon.sh/template": "custom-ingress-0.1.0", }, }, wantErr: true, diff --git a/internal/templating/ingress/templates_ingress.go b/internal/templating/ingress/templates_ingress.go index 3d5d3bb6..81ff3476 100644 --- a/internal/templating/ingress/templates_ingress.go +++ b/internal/templating/ingress/templates_ingress.go @@ -60,10 +60,10 @@ func GenerateIngressTemplate( // add the default labels ingress.ObjectMeta.Labels = map[string]string{ "lagoon.sh/autogenerated": "false", - "helm.sh/chart": fmt.Sprintf("%s-%s", "custom-ingress", "0.1.0"), "app.kubernetes.io/name": "custom-ingress", "app.kubernetes.io/instance": truncatedRouteDomain, - "app.kubernetes.io/managed-by": "Helm", + "app.kubernetes.io/managed-by": "build-deploy-tool", + "lagoon.sh/template": "custom-ingress-0.1.0", "lagoon.sh/service": truncatedRouteDomain, "lagoon.sh/service-type": "custom-ingress", "lagoon.sh/project": lValues.Project, diff --git a/internal/templating/ingress/test-resources/result-active-standby1.yaml b/internal/templating/ingress/test-resources/result-active-standby1.yaml index 67da9777..5e648500 100644 --- a/internal/templating/ingress/test-resources/result-active-standby1.yaml +++ b/internal/templating/ingress/test-resources/result-active-standby1.yaml @@ -20,9 +20,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "true" app.kubernetes.io/instance: extra-long-name-f6c8a - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: environment-with-really-really-reall-3fdb @@ -31,6 +30,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: extra-long-name-f6c8a lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com spec: rules: diff --git a/internal/templating/ingress/test-resources/result-custom-ingress1.yaml b/internal/templating/ingress/test-resources/result-custom-ingress1.yaml index 7cf3546e..8a78a257 100644 --- a/internal/templating/ingress/test-resources/result-custom-ingress1.yaml +++ b/internal/templating/ingress/test-resources/result-custom-ingress1.yaml @@ -20,9 +20,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: extra-long-name-f6c8a - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: environment-with-really-really-reall-3fdb @@ -31,6 +30,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: extra-long-name-f6c8a lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com spec: rules: diff --git a/internal/templating/ingress/test-resources/result-custom-ingress2.yaml b/internal/templating/ingress/test-resources/result-custom-ingress2.yaml index 2df0aaf0..ae9f2b86 100644 --- a/internal/templating/ingress/test-resources/result-custom-ingress2.yaml +++ b/internal/templating/ingress/test-resources/result-custom-ingress2.yaml @@ -16,9 +16,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: extra-long-name-f6c8a - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: environment-with-really-really-reall-3fdb @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: extra-long-name-f6c8a lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com spec: rules: diff --git a/internal/templating/ingress/test-resources/result-custom-ingress3.yaml b/internal/templating/ingress/test-resources/result-custom-ingress3.yaml index d3011ae3..e0e15996 100644 --- a/internal/templating/ingress/test-resources/result-custom-ingress3.yaml +++ b/internal/templating/ingress/test-resources/result-custom-ingress3.yaml @@ -17,9 +17,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: extra-long-name-f6c8a - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: environment-with-really-really-reall-3fdb @@ -27,6 +26,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: extra-long-name-f6c8a lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com spec: ingressClassName: nginx diff --git a/internal/templating/ingress/test-resources/result-custom-ingress4.yaml b/internal/templating/ingress/test-resources/result-custom-ingress4.yaml index a426a76b..cec63b19 100644 --- a/internal/templating/ingress/test-resources/result-custom-ingress4.yaml +++ b/internal/templating/ingress/test-resources/result-custom-ingress4.yaml @@ -19,9 +19,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: extra-long-name-f6c8a - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: environment-with-really-really-reall-3fdb @@ -29,6 +28,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: extra-long-name-f6c8a lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com spec: ingressClassName: nginx diff --git a/internal/templating/ingress/test-resources/result-custom-ingress5.yaml b/internal/templating/ingress/test-resources/result-custom-ingress5.yaml index 1d0f4242..df1b1712 100644 --- a/internal/templating/ingress/test-resources/result-custom-ingress5.yaml +++ b/internal/templating/ingress/test-resources/result-custom-ingress5.yaml @@ -20,9 +20,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: extra-long-name-f6c8a - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: environment-with-really-really-reall-3fdb @@ -30,6 +29,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: extra-long-name-f6c8a lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com spec: ingressClassName: nginx diff --git a/internal/templating/ingress/test-resources/result-custom-ingress6.yaml b/internal/templating/ingress/test-resources/result-custom-ingress6.yaml index 98ee2b78..581df712 100644 --- a/internal/templating/ingress/test-resources/result-custom-ingress6.yaml +++ b/internal/templating/ingress/test-resources/result-custom-ingress6.yaml @@ -17,9 +17,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: hmm-this-is-a-really-long-branch-name-designed-to-tes-0eda7 - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: environment-with-really-really-reall-3fdb @@ -27,6 +26,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: hmm-this-is-a-really-long-branch-name-designed-to-tes-0eda7 lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: hmm-this-is-a-really-long-branch-name-designed-to-test-a-specific-feature.www.example.com spec: ingressClassName: nginx diff --git a/internal/templating/ingress/test-resources/result-custom-ingress7.yaml b/internal/templating/ingress/test-resources/result-custom-ingress7.yaml index 5ac50549..eca1c38c 100644 --- a/internal/templating/ingress/test-resources/result-custom-ingress7.yaml +++ b/internal/templating/ingress/test-resources/result-custom-ingress7.yaml @@ -20,9 +20,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: extra-long-name-f6c8a - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: environment-with-really-really-reall-3fdb @@ -31,6 +30,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: extra-long-name-f6c8a lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com spec: rules: diff --git a/internal/templating/ingress/test-resources/result-custom-ingress8.yaml b/internal/templating/ingress/test-resources/result-custom-ingress8.yaml index 5ac50549..eca1c38c 100644 --- a/internal/templating/ingress/test-resources/result-custom-ingress8.yaml +++ b/internal/templating/ingress/test-resources/result-custom-ingress8.yaml @@ -20,9 +20,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: extra-long-name-f6c8a - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: environment-with-really-really-reall-3fdb @@ -31,6 +30,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: extra-long-name-f6c8a lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com spec: rules: diff --git a/internal/templating/ingress/test-resources/result-custom-ingress9.yaml b/internal/templating/ingress/test-resources/result-custom-ingress9.yaml index d285e713..282840c1 100644 --- a/internal/templating/ingress/test-resources/result-custom-ingress9.yaml +++ b/internal/templating/ingress/test-resources/result-custom-ingress9.yaml @@ -16,9 +16,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: extra-long-name-f6c8a - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: environment-with-really-really-reall-3fdb @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: extra-long-name-f6c8a lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com spec: rules: diff --git a/internal/templating/ingress/test-resources/result-wildcard-ingress1.yaml b/internal/templating/ingress/test-resources/result-wildcard-ingress1.yaml index 2a2e3cdf..d5307fd0 100644 --- a/internal/templating/ingress/test-resources/result-wildcard-ingress1.yaml +++ b/internal/templating/ingress/test-resources/result-wildcard-ingress1.yaml @@ -17,9 +17,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: wildcard-www.example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: environment @@ -27,6 +26,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: wildcard-www.example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: wildcard-www.example.com spec: ingressClassName: nginx diff --git a/internal/templating/ingress/test-resources/result-wildcard-ingress2.yaml b/internal/templating/ingress/test-resources/result-wildcard-ingress2.yaml index 061abbb7..08086de1 100644 --- a/internal/templating/ingress/test-resources/result-wildcard-ingress2.yaml +++ b/internal/templating/ingress/test-resources/result-wildcard-ingress2.yaml @@ -17,9 +17,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: wildcard-this-truncate-f1945 - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: environment @@ -27,6 +26,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: wildcard-this-truncate-f1945 lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: wildcard-this-truncate.extra-long-name.a-really-long-name-that-should-truncate.extra-long-name.a-really-long-name-that-should-truncate.extra-long-name.a-really-long-name-that-should-truncate.extra-long-name.a-really-long-name-that-should-truncate.www.e-f1945 spec: ingressClassName: nginx diff --git a/internal/testdata/basic/autogen-templates/ingress-1/nginx.yaml b/internal/testdata/basic/autogen-templates/ingress-1/nginx.yaml index 222bf8b3..321def9a 100644 --- a/internal/testdata/basic/autogen-templates/ingress-1/nginx.yaml +++ b/internal/testdata/basic/autogen-templates/ingress-1/nginx.yaml @@ -16,9 +16,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: nginx - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: feature-skycms-10626-update-permissions-b-b92f @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: abc-skyforce lagoon.sh/service: nginx lagoon.sh/service-type: basic + lagoon.sh/template: autogenerated-ingress-0.1.0 name: nginx spec: rules: diff --git a/internal/testdata/complex/autogen-templates/ingress-1/nginx.yaml b/internal/testdata/complex/autogen-templates/ingress-1/nginx.yaml index 95d6204f..53382f4b 100644 --- a/internal/testdata/complex/autogen-templates/ingress-1/nginx.yaml +++ b/internal/testdata/complex/autogen-templates/ingress-1/nginx.yaml @@ -15,9 +15,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: nginx - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: drush-first @@ -25,6 +24,7 @@ metadata: lagoon.sh/project: ci-drush-la-control-k8s lagoon.sh/service: nginx lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: autogenerated-ingress-0.1.0 name: nginx spec: rules: diff --git a/internal/testdata/complex/autogen-templates/ingress-2/nginx-php.yaml b/internal/testdata/complex/autogen-templates/ingress-2/nginx-php.yaml index a5166e3a..92b78554 100644 --- a/internal/testdata/complex/autogen-templates/ingress-2/nginx-php.yaml +++ b/internal/testdata/complex/autogen-templates/ingress-2/nginx-php.yaml @@ -15,9 +15,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: nginx-php - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: feature-migration @@ -25,6 +24,7 @@ metadata: lagoon.sh/project: content-example-com lagoon.sh/service: nginx-php lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: autogenerated-ingress-0.1.0 name: nginx-php spec: rules: diff --git a/internal/testdata/complex/autogen-templates/ingress-3/nginx.yaml b/internal/testdata/complex/autogen-templates/ingress-3/nginx.yaml index 92fd60fd..8b45801b 100644 --- a/internal/testdata/complex/autogen-templates/ingress-3/nginx.yaml +++ b/internal/testdata/complex/autogen-templates/ingress-3/nginx.yaml @@ -15,9 +15,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: nginx - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: feature @@ -25,6 +24,7 @@ metadata: lagoon.sh/project: test21-example-com lagoon.sh/service: nginx lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: autogenerated-ingress-0.1.0 name: nginx spec: rules: diff --git a/internal/testdata/complex/ingress-templates/ingress-1/content.example.com.yaml b/internal/testdata/complex/ingress-templates/ingress-1/content.example.com.yaml index d2563e44..1f99db85 100644 --- a/internal/testdata/complex/ingress-templates/ingress-1/content.example.com.yaml +++ b/internal/testdata/complex/ingress-templates/ingress-1/content.example.com.yaml @@ -19,9 +19,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: content.example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: production @@ -30,6 +29,7 @@ metadata: lagoon.sh/project: content-example-com lagoon.sh/service: content.example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: content.example.com spec: rules: diff --git a/internal/testdata/nginxphp/autogen-templates/ingress-1/nginx.yaml b/internal/testdata/nginxphp/autogen-templates/ingress-1/nginx.yaml index 1e361baf..cdb23a55 100644 --- a/internal/testdata/nginxphp/autogen-templates/ingress-1/nginx.yaml +++ b/internal/testdata/nginxphp/autogen-templates/ingress-1/nginx.yaml @@ -15,9 +15,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: nginx - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -25,6 +24,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: nginx lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: autogenerated-ingress-0.1.0 name: nginx spec: rules: diff --git a/internal/testdata/nginxphp/autogen-templates/ingress-2/nginx.yaml b/internal/testdata/nginxphp/autogen-templates/ingress-2/nginx.yaml index 1e361baf..cdb23a55 100644 --- a/internal/testdata/nginxphp/autogen-templates/ingress-2/nginx.yaml +++ b/internal/testdata/nginxphp/autogen-templates/ingress-2/nginx.yaml @@ -15,9 +15,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: nginx - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -25,6 +24,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: nginx lagoon.sh/service-type: nginx-php-persistent + lagoon.sh/template: autogenerated-ingress-0.1.0 name: nginx spec: rules: diff --git a/internal/testdata/nginxphp/autogen-templates/ingress-3/nginx-php.yaml b/internal/testdata/nginxphp/autogen-templates/ingress-3/nginx-php.yaml index 040062b2..e4d0a282 100644 --- a/internal/testdata/nginxphp/autogen-templates/ingress-3/nginx-php.yaml +++ b/internal/testdata/nginxphp/autogen-templates/ingress-3/nginx-php.yaml @@ -17,9 +17,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: nginx-php - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: pullrequest lagoon.sh/environment: pr-123 @@ -27,6 +26,7 @@ metadata: lagoon.sh/project: content-abcdefghijk-net-com-co lagoon.sh/service: nginx-php lagoon.sh/service-type: nginx-php + lagoon.sh/template: autogenerated-ingress-0.1.0 name: nginx-php spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-1/node.yaml b/internal/testdata/node/autogen-templates/ingress-1/node.yaml index 9174ef23..577f24f9 100644 --- a/internal/testdata/node/autogen-templates/ingress-1/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-1/node.yaml @@ -16,9 +16,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-10/node.yaml b/internal/testdata/node/autogen-templates/ingress-10/node.yaml index b14b709c..ddde3486 100644 --- a/internal/testdata/node/autogen-templates/ingress-10/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-10/node.yaml @@ -15,9 +15,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -25,6 +24,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-11/node.yaml b/internal/testdata/node/autogen-templates/ingress-11/node.yaml index e378fb4d..2ed1318f 100644 --- a/internal/testdata/node/autogen-templates/ingress-11/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-11/node.yaml @@ -15,9 +15,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -25,6 +24,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node-persistent + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-12/node.yaml b/internal/testdata/node/autogen-templates/ingress-12/node.yaml index 538ca3ac..01a988a3 100644 --- a/internal/testdata/node/autogen-templates/ingress-12/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-12/node.yaml @@ -16,9 +16,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-13/node.yaml b/internal/testdata/node/autogen-templates/ingress-13/node.yaml index 538ca3ac..01a988a3 100644 --- a/internal/testdata/node/autogen-templates/ingress-13/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-13/node.yaml @@ -16,9 +16,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-14/node.yaml b/internal/testdata/node/autogen-templates/ingress-14/node.yaml index 9174ef23..577f24f9 100644 --- a/internal/testdata/node/autogen-templates/ingress-14/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-14/node.yaml @@ -16,9 +16,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-15/node.yaml b/internal/testdata/node/autogen-templates/ingress-15/node.yaml index eb826845..5bbec8a1 100644 --- a/internal/testdata/node/autogen-templates/ingress-15/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-15/node.yaml @@ -16,9 +16,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-2/node.yaml b/internal/testdata/node/autogen-templates/ingress-2/node.yaml index 98322c63..b5cad9ba 100644 --- a/internal/testdata/node/autogen-templates/ingress-2/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-2/node.yaml @@ -17,9 +17,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: pullrequest lagoon.sh/environment: pr-123 @@ -27,6 +26,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-3/node.yaml b/internal/testdata/node/autogen-templates/ingress-3/node.yaml index d98027d8..9d48c2c7 100644 --- a/internal/testdata/node/autogen-templates/ingress-3/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-3/node.yaml @@ -16,9 +16,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-4/node.yaml b/internal/testdata/node/autogen-templates/ingress-4/node.yaml index 8ab7adad..43af5057 100644 --- a/internal/testdata/node/autogen-templates/ingress-4/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-4/node.yaml @@ -16,9 +16,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: short-router-url-from-a-very-l-ebe8 @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: ci-features-control-k8s lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-5/node.yaml b/internal/testdata/node/autogen-templates/ingress-5/node.yaml index 9174ef23..577f24f9 100644 --- a/internal/testdata/node/autogen-templates/ingress-5/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-5/node.yaml @@ -16,9 +16,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-6/node.yaml b/internal/testdata/node/autogen-templates/ingress-6/node.yaml index 0afd6471..5057b566 100644 --- a/internal/testdata/node/autogen-templates/ingress-6/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-6/node.yaml @@ -17,9 +17,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -27,6 +26,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-7/node.yaml b/internal/testdata/node/autogen-templates/ingress-7/node.yaml index 0afd6471..5057b566 100644 --- a/internal/testdata/node/autogen-templates/ingress-7/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-7/node.yaml @@ -17,9 +17,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -27,6 +26,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-8/node.yaml b/internal/testdata/node/autogen-templates/ingress-8/node.yaml index 7b8e6ddc..be2e8868 100644 --- a/internal/testdata/node/autogen-templates/ingress-8/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-8/node.yaml @@ -18,9 +18,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -28,6 +27,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/autogen-templates/ingress-9/node.yaml b/internal/testdata/node/autogen-templates/ingress-9/node.yaml index 8ffbc240..ef5b046c 100644 --- a/internal/testdata/node/autogen-templates/ingress-9/node.yaml +++ b/internal/testdata/node/autogen-templates/ingress-9/node.yaml @@ -15,9 +15,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: node - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: autogenerated-ingress - helm.sh/chart: autogenerated-ingress-0.1.0 lagoon.sh/autogenerated: "true" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -25,6 +24,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: node lagoon.sh/service-type: node + lagoon.sh/template: autogenerated-ingress-0.1.0 name: node spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-1/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-1/example.com.yaml index 169c068e..4e997012 100644 --- a/internal/testdata/node/ingress-templates/ingress-1/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-1/example.com.yaml @@ -21,9 +21,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -32,6 +31,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-10/main-sb.example.com.yaml b/internal/testdata/node/ingress-templates/ingress-10/main-sb.example.com.yaml index c373d3f8..15cf2ace 100644 --- a/internal/testdata/node/ingress-templates/ingress-10/main-sb.example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-10/main-sb.example.com.yaml @@ -16,9 +16,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: main-sb.example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: main-sb @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: main-sb.example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: main-sb.example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-10/standby.example.com.yaml b/internal/testdata/node/ingress-templates/ingress-10/standby.example.com.yaml index 41c7bcf2..5476db88 100644 --- a/internal/testdata/node/ingress-templates/ingress-10/standby.example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-10/standby.example.com.yaml @@ -19,9 +19,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "true" app.kubernetes.io/instance: standby.example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: main-sb @@ -30,6 +29,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: standby.example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: standby.example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-11/test1.example.com.yaml b/internal/testdata/node/ingress-templates/ingress-11/test1.example.com.yaml index 4f8b813e..0e73d69a 100644 --- a/internal/testdata/node/ingress-templates/ingress-11/test1.example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-11/test1.example.com.yaml @@ -19,9 +19,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: test1.example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: noyamlroutes @@ -30,6 +29,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: test1.example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: test1.example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-12/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-12/example.com.yaml index 4a17dce5..1ff9f929 100644 --- a/internal/testdata/node/ingress-templates/ingress-12/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-12/example.com.yaml @@ -20,9 +20,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -31,6 +30,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: ingressClassName: nginx diff --git a/internal/testdata/node/ingress-templates/ingress-13/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-13/example.com.yaml index 8de5583e..425fd85a 100644 --- a/internal/testdata/node/ingress-templates/ingress-13/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-13/example.com.yaml @@ -20,9 +20,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: ingressclass @@ -31,6 +30,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: ingressClassName: custom-ingress diff --git a/internal/testdata/node/ingress-templates/ingress-14/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-14/example.com.yaml index 22a6bcf3..f354c535 100644 --- a/internal/testdata/node/ingress-templates/ingress-14/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-14/example.com.yaml @@ -20,9 +20,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -31,6 +30,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: ingressClassName: custom-ingress diff --git a/internal/testdata/node/ingress-templates/ingress-15/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-15/example.com.yaml index 22a6bcf3..f354c535 100644 --- a/internal/testdata/node/ingress-templates/ingress-15/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-15/example.com.yaml @@ -20,9 +20,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -31,6 +30,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: ingressClassName: custom-ingress diff --git a/internal/testdata/node/ingress-templates/ingress-16/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-16/example.com.yaml index 996c528c..6da7a02f 100644 --- a/internal/testdata/node/ingress-templates/ingress-16/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-16/example.com.yaml @@ -23,9 +23,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: hsts @@ -34,6 +33,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-17/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-17/example.com.yaml index 93fed089..4b7024e2 100644 --- a/internal/testdata/node/ingress-templates/ingress-17/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-17/example.com.yaml @@ -23,9 +23,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: hsts2 @@ -34,6 +33,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-18/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-18/example.com.yaml index 43cd6875..fd6447f5 100644 --- a/internal/testdata/node/ingress-templates/ingress-18/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-18/example.com.yaml @@ -19,9 +19,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: tworoutes @@ -30,6 +29,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-18/www.example.com.yaml b/internal/testdata/node/ingress-templates/ingress-18/www.example.com.yaml index db25905c..6d0d0070 100644 --- a/internal/testdata/node/ingress-templates/ingress-18/www.example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-18/www.example.com.yaml @@ -16,9 +16,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: www.example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: tworoutes @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: www.example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: www.example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-19/performance.example.com.yaml b/internal/testdata/node/ingress-templates/ingress-19/performance.example.com.yaml index 45fab283..281706f9 100644 --- a/internal/testdata/node/ingress-templates/ingress-19/performance.example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-19/performance.example.com.yaml @@ -17,9 +17,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: performance.example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: pullrequest lagoon.sh/environment: pr-4841 @@ -27,6 +26,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: performance.example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: performance.example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-2/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-2/example.com.yaml index 9eedb5f0..bb27ab4d 100644 --- a/internal/testdata/node/ingress-templates/ingress-2/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-2/example.com.yaml @@ -20,9 +20,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -31,6 +30,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-20/performance.example.com.yaml b/internal/testdata/node/ingress-templates/ingress-20/performance.example.com.yaml index 45fab283..281706f9 100644 --- a/internal/testdata/node/ingress-templates/ingress-20/performance.example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-20/performance.example.com.yaml @@ -17,9 +17,8 @@ metadata: creationTimestamp: null labels: app.kubernetes.io/instance: performance.example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: pullrequest lagoon.sh/environment: pr-4841 @@ -27,6 +26,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: performance.example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: performance.example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-21/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-21/example.com.yaml index 6fd8acc8..ff39bafc 100644 --- a/internal/testdata/node/ingress-templates/ingress-21/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-21/example.com.yaml @@ -19,9 +19,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: alternativename @@ -30,6 +29,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-22/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-22/example.com.yaml index 847041c6..54d755bb 100644 --- a/internal/testdata/node/ingress-templates/ingress-22/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-22/example.com.yaml @@ -16,9 +16,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: wildcard-example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: wildcard @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: wildcard-example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: wildcard-example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-23/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-23/example.com.yaml index d7f12eb7..877827b8 100644 --- a/internal/testdata/node/ingress-templates/ingress-23/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-23/example.com.yaml @@ -19,9 +19,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -30,6 +29,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-3/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-3/example.com.yaml index 9eedb5f0..bb27ab4d 100644 --- a/internal/testdata/node/ingress-templates/ingress-3/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-3/example.com.yaml @@ -20,9 +20,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -31,6 +30,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-4/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-4/example.com.yaml index 3cf087ba..cea108f6 100644 --- a/internal/testdata/node/ingress-templates/ingress-4/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-4/example.com.yaml @@ -19,9 +19,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -30,6 +29,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-5/multiproject1.com.yaml b/internal/testdata/node/ingress-templates/ingress-5/multiproject1.com.yaml index 18b9aadc..0750b877 100644 --- a/internal/testdata/node/ingress-templates/ingress-5/multiproject1.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-5/multiproject1.com.yaml @@ -19,9 +19,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: multiproject1.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: multiproject @@ -30,6 +29,7 @@ metadata: lagoon.sh/project: multiproject1 lagoon.sh/service: multiproject1.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: multiproject1.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-6/multiproject2.com.yaml b/internal/testdata/node/ingress-templates/ingress-6/multiproject2.com.yaml index 40c6f523..b87f6034 100644 --- a/internal/testdata/node/ingress-templates/ingress-6/multiproject2.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-6/multiproject2.com.yaml @@ -19,9 +19,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: multiproject2.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: multiproject @@ -30,6 +29,7 @@ metadata: lagoon.sh/project: multiproject2 lagoon.sh/service: multiproject2.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: multiproject2.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-7/example.com.yaml b/internal/testdata/node/ingress-templates/ingress-7/example.com.yaml index 43cd6875..fd6447f5 100644 --- a/internal/testdata/node/ingress-templates/ingress-7/example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-7/example.com.yaml @@ -19,9 +19,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: tworoutes @@ -30,6 +29,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-7/www.example.com.yaml b/internal/testdata/node/ingress-templates/ingress-7/www.example.com.yaml index db25905c..6d0d0070 100644 --- a/internal/testdata/node/ingress-templates/ingress-7/www.example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-7/www.example.com.yaml @@ -16,9 +16,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: www.example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: tworoutes @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: www.example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: www.example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-8/customdomain-will-be-main-domain.com.yaml b/internal/testdata/node/ingress-templates/ingress-8/customdomain-will-be-main-domain.com.yaml index 44495bc0..077f40d7 100644 --- a/internal/testdata/node/ingress-templates/ingress-8/customdomain-will-be-main-domain.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-8/customdomain-will-be-main-domain.com.yaml @@ -19,9 +19,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: customdomain-will-be-main-domain.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: branch-routes @@ -30,6 +29,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: customdomain-will-be-main-domain.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: customdomain-will-be-main-domain.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-8/customdomain-will-be-not-be-main-domain.com.yaml b/internal/testdata/node/ingress-templates/ingress-8/customdomain-will-be-not-be-main-domain.com.yaml index f510f3ee..3beb1b2c 100644 --- a/internal/testdata/node/ingress-templates/ingress-8/customdomain-will-be-not-be-main-domain.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-8/customdomain-will-be-not-be-main-domain.com.yaml @@ -16,9 +16,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: customdomain-will-be-not-be-main-domain.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: branch-routes @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: customdomain-will-be-not-be-main-domain.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: customdomain-will-be-not-be-main-domain.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-9/active.example.com.yaml b/internal/testdata/node/ingress-templates/ingress-9/active.example.com.yaml index aa9648a4..c6ffbfcd 100644 --- a/internal/testdata/node/ingress-templates/ingress-9/active.example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-9/active.example.com.yaml @@ -19,9 +19,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "true" app.kubernetes.io/instance: active.example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -30,6 +29,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: active.example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: active.example.com spec: rules: diff --git a/internal/testdata/node/ingress-templates/ingress-9/main.example.com.yaml b/internal/testdata/node/ingress-templates/ingress-9/main.example.com.yaml index 92696506..6a92657c 100644 --- a/internal/testdata/node/ingress-templates/ingress-9/main.example.com.yaml +++ b/internal/testdata/node/ingress-templates/ingress-9/main.example.com.yaml @@ -16,9 +16,8 @@ metadata: labels: activestandby.lagoon.sh/migrate: "false" app.kubernetes.io/instance: main.example.com - app.kubernetes.io/managed-by: Helm + app.kubernetes.io/managed-by: build-deploy-tool app.kubernetes.io/name: custom-ingress - helm.sh/chart: custom-ingress-0.1.0 lagoon.sh/autogenerated: "false" lagoon.sh/buildType: branch lagoon.sh/environment: main @@ -26,6 +25,7 @@ metadata: lagoon.sh/project: example-project lagoon.sh/service: main.example.com lagoon.sh/service-type: custom-ingress + lagoon.sh/template: custom-ingress-0.1.0 name: main.example.com spec: rules: