From 12e74a154c149ae4db454b34b0ee2006afd8b1a3 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 5 Jan 2024 20:17:54 +1100 Subject: [PATCH 1/3] feat: support for services v2 --- apis/lagoon/v1beta1/lagoonmessaging_types.go | 6 +++ apis/lagoon/v1beta1/zz_generated.deepcopy.go | 20 ++++++++ .../crd/bases/crd.lagoon.sh_lagoonbuilds.yaml | 48 +++++++++++++++++++ .../crd/bases/crd.lagoon.sh_lagoontasks.yaml | 48 +++++++++++++++++++ controllers/v1beta1/build_deletionhandlers.go | 13 +++++ .../v1beta1/podmonitor_buildhandlers.go | 15 +++++- 6 files changed, 149 insertions(+), 1 deletion(-) diff --git a/apis/lagoon/v1beta1/lagoonmessaging_types.go b/apis/lagoon/v1beta1/lagoonmessaging_types.go index f9fe6ecd..7ee42727 100644 --- a/apis/lagoon/v1beta1/lagoonmessaging_types.go +++ b/apis/lagoon/v1beta1/lagoonmessaging_types.go @@ -35,12 +35,18 @@ type LagoonLogMeta struct { Routes []string `json:"routes,omitempty"` StartTime string `json:"startTime,omitempty"` Services []string `json:"services,omitempty"` + ServicesV2 []LagoonService `json:"servicesv2,omitempty"` Task *LagoonTaskInfo `json:"task,omitempty"` Key string `json:"key,omitempty"` AdvancedData string `json:"advancedData,omitempty"` Cluster string `json:"clusterName,omitempty"` } +type LagoonService struct { + Name string `json:"name"` + Type string `json:"type"` +} + // LagoonMessage is used for sending build info back to Lagoon // messaging queue to update the environment or deployment type LagoonMessage struct { diff --git a/apis/lagoon/v1beta1/zz_generated.deepcopy.go b/apis/lagoon/v1beta1/zz_generated.deepcopy.go index 842af614..56844afb 100644 --- a/apis/lagoon/v1beta1/zz_generated.deepcopy.go +++ b/apis/lagoon/v1beta1/zz_generated.deepcopy.go @@ -241,6 +241,11 @@ func (in *LagoonLogMeta) DeepCopyInto(out *LagoonLogMeta) { *out = make([]string, len(*in)) copy(*out, *in) } + if in.ServicesV2 != nil { + in, out := &in.ServicesV2, &out.ServicesV2 + *out = make([]LagoonService, len(*in)) + copy(*out, *in) + } if in.Task != nil { in, out := &in.Task, &out.Task *out = new(LagoonTaskInfo) @@ -318,6 +323,21 @@ func (in *LagoonMiscInfo) DeepCopy() *LagoonMiscInfo { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LagoonService) DeepCopyInto(out *LagoonService) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LagoonService. +func (in *LagoonService) DeepCopy() *LagoonService { + if in == nil { + return nil + } + out := new(LagoonService) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LagoonStatusMessages) DeepCopyInto(out *LagoonStatusMessages) { *out = *in diff --git a/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml b/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml index bbc2dc2d..7f97619c 100644 --- a/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml +++ b/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml @@ -265,6 +265,18 @@ spec: items: type: string type: array + servicesv2: + items: + properties: + name: + type: string + type: + type: string + required: + - name + - type + type: object + type: array startTime: type: string task: @@ -354,6 +366,18 @@ spec: items: type: string type: array + servicesv2: + items: + properties: + name: + type: string + type: + type: string + required: + - name + - type + type: object + type: array startTime: type: string task: @@ -445,6 +469,18 @@ spec: items: type: string type: array + servicesv2: + items: + properties: + name: + type: string + type: + type: string + required: + - name + - type + type: object + type: array startTime: type: string task: @@ -538,6 +574,18 @@ spec: items: type: string type: array + servicesv2: + items: + properties: + name: + type: string + type: + type: string + required: + - name + - type + type: object + type: array startTime: type: string task: diff --git a/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml b/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml index f1394f91..4bbe35b9 100644 --- a/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml +++ b/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml @@ -247,6 +247,18 @@ spec: items: type: string type: array + servicesv2: + items: + properties: + name: + type: string + type: + type: string + required: + - name + - type + type: object + type: array startTime: type: string task: @@ -336,6 +348,18 @@ spec: items: type: string type: array + servicesv2: + items: + properties: + name: + type: string + type: + type: string + required: + - name + - type + type: object + type: array startTime: type: string task: @@ -427,6 +451,18 @@ spec: items: type: string type: array + servicesv2: + items: + properties: + name: + type: string + type: + type: string + required: + - name + - type + type: object + type: array startTime: type: string task: @@ -520,6 +556,18 @@ spec: items: type: string type: array + servicesv2: + items: + properties: + name: + type: string + type: + type: string + required: + - name + - type + type: object + type: array startTime: type: string task: diff --git a/controllers/v1beta1/build_deletionhandlers.go b/controllers/v1beta1/build_deletionhandlers.go index fba4c0e2..d4ec0ff7 100644 --- a/controllers/v1beta1/build_deletionhandlers.go +++ b/controllers/v1beta1/build_deletionhandlers.go @@ -313,21 +313,34 @@ func (r *LagoonBuildReconciler) updateDeploymentAndEnvironmentTask(ctx context.C }) podList := &corev1.PodList{} serviceNames := []string{} + services := []lagoonv1beta1.LagoonService{} if err := r.List(context.TODO(), podList, listOption); err == nil { // generate the list of services to add to the environment for _, pod := range podList.Items { + var serviceName, serviceType string if _, ok := pod.ObjectMeta.Labels["lagoon.sh/service"]; ok { for _, container := range pod.Spec.Containers { serviceNames = append(serviceNames, container.Name) + serviceName = container.Name } } if _, ok := pod.ObjectMeta.Labels["service"]; ok { + // @TODO: remove this as this label shouldn't exist by now for _, container := range pod.Spec.Containers { serviceNames = append(serviceNames, container.Name) + serviceName = container.Name } } + if sType, ok := pod.ObjectMeta.Labels["lagoon.sh/service-type"]; ok { + serviceType = sType + } + services = append(services, lagoonv1beta1.LagoonService{ + Name: serviceName, + Type: serviceType, + }) } msg.Meta.Services = serviceNames + msg.Meta.ServicesV2 = services } // if we aren't being provided the lagoon config, we can skip adding the routes etc if lagoonEnv != nil { diff --git a/controllers/v1beta1/podmonitor_buildhandlers.go b/controllers/v1beta1/podmonitor_buildhandlers.go index 0159cb65..169cbebf 100644 --- a/controllers/v1beta1/podmonitor_buildhandlers.go +++ b/controllers/v1beta1/podmonitor_buildhandlers.go @@ -296,21 +296,34 @@ func (r *LagoonMonitorReconciler) updateDeploymentAndEnvironmentTask(ctx context }) depList := &appsv1.DeploymentList{} serviceNames := []string{} + services := []lagoonv1beta1.LagoonService{} if err := r.List(context.TODO(), depList, listOption); err == nil { - // generate the list of services to add to the environment + // generate the list of services to add or update to the environment for _, deployment := range depList.Items { + var serviceName, serviceType string if _, ok := deployment.ObjectMeta.Labels["lagoon.sh/service"]; ok { for _, container := range deployment.Spec.Template.Spec.Containers { serviceNames = append(serviceNames, container.Name) + serviceName = container.Name } } if _, ok := deployment.ObjectMeta.Labels["service"]; ok { + // @TODO: remove this as this label shouldn't exist by now for _, container := range deployment.Spec.Template.Spec.Containers { serviceNames = append(serviceNames, container.Name) + serviceName = container.Name } } + if sType, ok := deployment.ObjectMeta.Labels["lagoon.sh/service-type"]; ok { + serviceType = sType + } + services = append(services, lagoonv1beta1.LagoonService{ + Name: serviceName, + Type: serviceType, + }) } msg.Meta.Services = serviceNames + msg.Meta.ServicesV2 = services } // if we aren't being provided the lagoon config, we can skip adding the routes etc if lagoonEnv != nil { From c5c260a16edbb154695f4202a3514721a8062377 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 9 Jan 2024 15:52:36 +1100 Subject: [PATCH 2/3] feat: support for passing new env service info to api --- apis/lagoon/v1beta1/lagoonmessaging_types.go | 64 ++++++----- apis/lagoon/v1beta1/zz_generated.deepcopy.go | 4 +- .../crd/bases/crd.lagoon.sh_lagoonbuilds.yaml | 108 ++++++++++-------- .../crd/bases/crd.lagoon.sh_lagoontasks.yaml | 108 ++++++++++-------- controllers/v1beta1/build_deletionhandlers.go | 23 ++-- .../v1beta1/podmonitor_buildhandlers.go | 23 ++-- 6 files changed, 179 insertions(+), 151 deletions(-) diff --git a/apis/lagoon/v1beta1/lagoonmessaging_types.go b/apis/lagoon/v1beta1/lagoonmessaging_types.go index 7ee42727..789c01da 100644 --- a/apis/lagoon/v1beta1/lagoonmessaging_types.go +++ b/apis/lagoon/v1beta1/lagoonmessaging_types.go @@ -15,36 +15,46 @@ type LagoonLog struct { // LagoonLogMeta is the metadata that is used by logging in Lagoon. type LagoonLogMeta struct { - BranchName string `json:"branchName,omitempty"` - BuildName string `json:"buildName,omitempty"` - BuildPhase string `json:"buildPhase,omitempty"` // @TODO: deprecate once controller-handler is fixed - BuildStatus string `json:"buildStatus,omitempty"` - BuildStep string `json:"buildStep,omitempty"` - EndTime string `json:"endTime,omitempty"` - Environment string `json:"environment,omitempty"` - EnvironmentID *uint `json:"environmentId,omitempty"` - JobName string `json:"jobName,omitempty"` // used by tasks/jobs - JobStatus string `json:"jobStatus,omitempty"` // used by tasks/jobs - JobStep string `json:"jobStep,omitempty"` // used by tasks/jobs - LogLink string `json:"logLink,omitempty"` - Project string `json:"project,omitempty"` - ProjectID *uint `json:"projectId,omitempty"` - ProjectName string `json:"projectName,omitempty"` - RemoteID string `json:"remoteId,omitempty"` - Route string `json:"route,omitempty"` - Routes []string `json:"routes,omitempty"` - StartTime string `json:"startTime,omitempty"` - Services []string `json:"services,omitempty"` - ServicesV2 []LagoonService `json:"servicesv2,omitempty"` - Task *LagoonTaskInfo `json:"task,omitempty"` - Key string `json:"key,omitempty"` - AdvancedData string `json:"advancedData,omitempty"` - Cluster string `json:"clusterName,omitempty"` + BranchName string `json:"branchName,omitempty"` + BuildName string `json:"buildName,omitempty"` + BuildPhase string `json:"buildPhase,omitempty"` // @TODO: deprecate once controller-handler is fixed + BuildStatus string `json:"buildStatus,omitempty"` + BuildStep string `json:"buildStep,omitempty"` + EndTime string `json:"endTime,omitempty"` + Environment string `json:"environment,omitempty"` + EnvironmentID *uint `json:"environmentId,omitempty"` + JobName string `json:"jobName,omitempty"` // used by tasks/jobs + JobStatus string `json:"jobStatus,omitempty"` // used by tasks/jobs + JobStep string `json:"jobStep,omitempty"` // used by tasks/jobs + LogLink string `json:"logLink,omitempty"` + Project string `json:"project,omitempty"` + ProjectID *uint `json:"projectId,omitempty"` + ProjectName string `json:"projectName,omitempty"` + RemoteID string `json:"remoteId,omitempty"` + Route string `json:"route,omitempty"` + Routes []string `json:"routes,omitempty"` + StartTime string `json:"startTime,omitempty"` + Services []string `json:"services,omitempty"` + EnvironmentServices []LagoonService `json:"environmentServices,omitempty"` + Task *LagoonTaskInfo `json:"task,omitempty"` + Key string `json:"key,omitempty"` + AdvancedData string `json:"advancedData,omitempty"` + Cluster string `json:"clusterName,omitempty"` } +// LagoonService is the same as EnvironmentService type from the lagoon Schema type LagoonService struct { - Name string `json:"name"` - Type string `json:"type"` + ID int `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Type string `json:"type,omitempty"` + Updated string `json:"updated,omitempty"` + Containers []EnvironmentContainer `json:"containers,omitempty"` + Created string `json:"created,omitempty"` +} + +// EnvironmentService is based on the Lagoon API type. +type EnvironmentContainer struct { + Name string `json:"name,omitempty"` } // LagoonMessage is used for sending build info back to Lagoon diff --git a/apis/lagoon/v1beta1/zz_generated.deepcopy.go b/apis/lagoon/v1beta1/zz_generated.deepcopy.go index 56844afb..d4d52735 100644 --- a/apis/lagoon/v1beta1/zz_generated.deepcopy.go +++ b/apis/lagoon/v1beta1/zz_generated.deepcopy.go @@ -241,8 +241,8 @@ func (in *LagoonLogMeta) DeepCopyInto(out *LagoonLogMeta) { *out = make([]string, len(*in)) copy(*out, *in) } - if in.ServicesV2 != nil { - in, out := &in.ServicesV2, &out.ServicesV2 + if in.EnvironmentServices != nil { + in, out := &in.EnvironmentServices, &out.EnvironmentServices *out = make([]LagoonService, len(*in)) copy(*out, *in) } diff --git a/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml b/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml index 7f97619c..10599775 100644 --- a/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml +++ b/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml @@ -237,6 +237,21 @@ spec: type: string environmentId: type: integer + environmentServices: + items: + properties: + created: + type: string + id: + type: integer + name: + type: string + type: + type: string + updated: + type: string + type: object + type: array jobName: type: string jobStatus: @@ -265,18 +280,6 @@ spec: items: type: string type: array - servicesv2: - items: - properties: - name: - type: string - type: - type: string - required: - - name - - type - type: object - type: array startTime: type: string task: @@ -338,6 +341,21 @@ spec: type: string environmentId: type: integer + environmentServices: + items: + properties: + created: + type: string + id: + type: integer + name: + type: string + type: + type: string + updated: + type: string + type: object + type: array jobName: type: string jobStatus: @@ -366,18 +384,6 @@ spec: items: type: string type: array - servicesv2: - items: - properties: - name: - type: string - type: - type: string - required: - - name - - type - type: object - type: array startTime: type: string task: @@ -441,6 +447,21 @@ spec: type: string environmentId: type: integer + environmentServices: + items: + properties: + created: + type: string + id: + type: integer + name: + type: string + type: + type: string + updated: + type: string + type: object + type: array jobName: type: string jobStatus: @@ -469,18 +490,6 @@ spec: items: type: string type: array - servicesv2: - items: - properties: - name: - type: string - type: - type: string - required: - - name - - type - type: object - type: array startTime: type: string task: @@ -546,6 +555,21 @@ spec: type: string environmentId: type: integer + environmentServices: + items: + properties: + created: + type: string + id: + type: integer + name: + type: string + type: + type: string + updated: + type: string + type: object + type: array jobName: type: string jobStatus: @@ -574,18 +598,6 @@ spec: items: type: string type: array - servicesv2: - items: - properties: - name: - type: string - type: - type: string - required: - - name - - type - type: object - type: array startTime: type: string task: diff --git a/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml b/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml index 4bbe35b9..1ce640e0 100644 --- a/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml +++ b/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml @@ -219,6 +219,21 @@ spec: type: string environmentId: type: integer + environmentServices: + items: + properties: + created: + type: string + id: + type: integer + name: + type: string + type: + type: string + updated: + type: string + type: object + type: array jobName: type: string jobStatus: @@ -247,18 +262,6 @@ spec: items: type: string type: array - servicesv2: - items: - properties: - name: - type: string - type: - type: string - required: - - name - - type - type: object - type: array startTime: type: string task: @@ -320,6 +323,21 @@ spec: type: string environmentId: type: integer + environmentServices: + items: + properties: + created: + type: string + id: + type: integer + name: + type: string + type: + type: string + updated: + type: string + type: object + type: array jobName: type: string jobStatus: @@ -348,18 +366,6 @@ spec: items: type: string type: array - servicesv2: - items: - properties: - name: - type: string - type: - type: string - required: - - name - - type - type: object - type: array startTime: type: string task: @@ -423,6 +429,21 @@ spec: type: string environmentId: type: integer + environmentServices: + items: + properties: + created: + type: string + id: + type: integer + name: + type: string + type: + type: string + updated: + type: string + type: object + type: array jobName: type: string jobStatus: @@ -451,18 +472,6 @@ spec: items: type: string type: array - servicesv2: - items: - properties: - name: - type: string - type: - type: string - required: - - name - - type - type: object - type: array startTime: type: string task: @@ -528,6 +537,21 @@ spec: type: string environmentId: type: integer + environmentServices: + items: + properties: + created: + type: string + id: + type: integer + name: + type: string + type: + type: string + updated: + type: string + type: object + type: array jobName: type: string jobStatus: @@ -556,18 +580,6 @@ spec: items: type: string type: array - servicesv2: - items: - properties: - name: - type: string - type: - type: string - required: - - name - - type - type: object - type: array startTime: type: string task: diff --git a/controllers/v1beta1/build_deletionhandlers.go b/controllers/v1beta1/build_deletionhandlers.go index d4ec0ff7..0ab6450b 100644 --- a/controllers/v1beta1/build_deletionhandlers.go +++ b/controllers/v1beta1/build_deletionhandlers.go @@ -318,29 +318,26 @@ func (r *LagoonBuildReconciler) updateDeploymentAndEnvironmentTask(ctx context.C // generate the list of services to add to the environment for _, pod := range podList.Items { var serviceName, serviceType string - if _, ok := pod.ObjectMeta.Labels["lagoon.sh/service"]; ok { + containers := []lagoonv1beta1.EnvironmentContainer{} + if name, ok := pod.ObjectMeta.Labels["lagoon.sh/service"]; ok { + serviceName = name + serviceNames = append(serviceNames, serviceName) for _, container := range pod.Spec.Containers { - serviceNames = append(serviceNames, container.Name) - serviceName = container.Name - } - } - if _, ok := pod.ObjectMeta.Labels["service"]; ok { - // @TODO: remove this as this label shouldn't exist by now - for _, container := range pod.Spec.Containers { - serviceNames = append(serviceNames, container.Name) - serviceName = container.Name + containers = append(containers, lagoonv1beta1.EnvironmentContainer{Name: container.Name}) } } if sType, ok := pod.ObjectMeta.Labels["lagoon.sh/service-type"]; ok { serviceType = sType } + // probably need to collect dbaas consumers too at some stage services = append(services, lagoonv1beta1.LagoonService{ - Name: serviceName, - Type: serviceType, + Name: serviceName, + Type: serviceType, + Containers: containers, }) } msg.Meta.Services = serviceNames - msg.Meta.ServicesV2 = services + msg.Meta.EnvironmentServices = services } // if we aren't being provided the lagoon config, we can skip adding the routes etc if lagoonEnv != nil { diff --git a/controllers/v1beta1/podmonitor_buildhandlers.go b/controllers/v1beta1/podmonitor_buildhandlers.go index 169cbebf..df3396d3 100644 --- a/controllers/v1beta1/podmonitor_buildhandlers.go +++ b/controllers/v1beta1/podmonitor_buildhandlers.go @@ -301,29 +301,26 @@ func (r *LagoonMonitorReconciler) updateDeploymentAndEnvironmentTask(ctx context // generate the list of services to add or update to the environment for _, deployment := range depList.Items { var serviceName, serviceType string - if _, ok := deployment.ObjectMeta.Labels["lagoon.sh/service"]; ok { + containers := []lagoonv1beta1.EnvironmentContainer{} + if name, ok := deployment.ObjectMeta.Labels["lagoon.sh/service"]; ok { + serviceName = name + serviceNames = append(serviceNames, serviceName) for _, container := range deployment.Spec.Template.Spec.Containers { - serviceNames = append(serviceNames, container.Name) - serviceName = container.Name - } - } - if _, ok := deployment.ObjectMeta.Labels["service"]; ok { - // @TODO: remove this as this label shouldn't exist by now - for _, container := range deployment.Spec.Template.Spec.Containers { - serviceNames = append(serviceNames, container.Name) - serviceName = container.Name + containers = append(containers, lagoonv1beta1.EnvironmentContainer{Name: container.Name}) } } if sType, ok := deployment.ObjectMeta.Labels["lagoon.sh/service-type"]; ok { serviceType = sType } + // probably need to collect dbaas consumers too at some stage services = append(services, lagoonv1beta1.LagoonService{ - Name: serviceName, - Type: serviceType, + Name: serviceName, + Type: serviceType, + Containers: containers, }) } msg.Meta.Services = serviceNames - msg.Meta.ServicesV2 = services + msg.Meta.EnvironmentServices = services } // if we aren't being provided the lagoon config, we can skip adding the routes etc if lagoonEnv != nil { From 7d5190e68a7ca934ce814758e4118ae15290dea1 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 2 May 2024 13:08:09 +1000 Subject: [PATCH 3/3] fix: add environment services changes to v1beta2 controller and other fixes --- apis/lagoon/v1beta1/zz_generated.deepcopy.go | 103 ------------------ .../crd/bases/crd.lagoon.sh_lagoonbuilds.yaml | 44 ++++++++ .../crd/bases/crd.lagoon.sh_lagoontasks.yaml | 44 ++++++++ controllers/v1beta1/build_deletionhandlers.go | 8 +- .../v1beta1/podmonitor_buildhandlers.go | 8 +- controllers/v1beta2/build_deletionhandlers.go | 22 +++- .../v1beta2/podmonitor_buildhandlers.go | 24 ++-- go.mod | 10 +- go.sum | 20 ++-- 9 files changed, 144 insertions(+), 139 deletions(-) diff --git a/apis/lagoon/v1beta1/zz_generated.deepcopy.go b/apis/lagoon/v1beta1/zz_generated.deepcopy.go index d57f59fa..c11c785c 100644 --- a/apis/lagoon/v1beta1/zz_generated.deepcopy.go +++ b/apis/lagoon/v1beta1/zz_generated.deepcopy.go @@ -199,94 +199,6 @@ func (in *LagoonBuildStatus) DeepCopy() *LagoonBuildStatus { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -<<<<<<< HEAD -func (in *LagoonLog) DeepCopyInto(out *LagoonLog) { - *out = *in - if in.Meta != nil { - in, out := &in.Meta, &out.Meta - *out = new(LagoonLogMeta) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LagoonLog. -func (in *LagoonLog) DeepCopy() *LagoonLog { - if in == nil { - return nil - } - out := new(LagoonLog) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LagoonLogMeta) DeepCopyInto(out *LagoonLogMeta) { - *out = *in - if in.EnvironmentID != nil { - in, out := &in.EnvironmentID, &out.EnvironmentID - *out = new(uint) - **out = **in - } - if in.ProjectID != nil { - in, out := &in.ProjectID, &out.ProjectID - *out = new(uint) - **out = **in - } - if in.Routes != nil { - in, out := &in.Routes, &out.Routes - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.Services != nil { - in, out := &in.Services, &out.Services - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.EnvironmentServices != nil { - in, out := &in.EnvironmentServices, &out.EnvironmentServices - *out = make([]LagoonService, len(*in)) - copy(*out, *in) - } - if in.Task != nil { - in, out := &in.Task, &out.Task - *out = new(LagoonTaskInfo) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LagoonLogMeta. -func (in *LagoonLogMeta) DeepCopy() *LagoonLogMeta { - if in == nil { - return nil - } - out := new(LagoonLogMeta) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LagoonMessage) DeepCopyInto(out *LagoonMessage) { - *out = *in - if in.Meta != nil { - in, out := &in.Meta, &out.Meta - *out = new(LagoonLogMeta) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LagoonMessage. -func (in *LagoonMessage) DeepCopy() *LagoonMessage { - if in == nil { - return nil - } - out := new(LagoonMessage) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -======= ->>>>>>> main-v1beta2 func (in *LagoonMiscBackupInfo) DeepCopyInto(out *LagoonMiscBackupInfo) { *out = *in } @@ -326,21 +238,6 @@ func (in *LagoonMiscInfo) DeepCopy() *LagoonMiscInfo { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LagoonService) DeepCopyInto(out *LagoonService) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LagoonService. -func (in *LagoonService) DeepCopy() *LagoonService { - if in == nil { - return nil - } - out := new(LagoonService) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LagoonStatusMessages) DeepCopyInto(out *LagoonStatusMessages) { *out = *in diff --git a/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml b/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml index d9d377e2..ed182224 100644 --- a/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml +++ b/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml @@ -241,7 +241,18 @@ spec: type: integer environmentServices: items: + description: EnvironmentService is based on the Lagoon + API type. properties: + containers: + items: + description: ServiceContainer is based on the Lagoon + API type. + properties: + name: + type: string + type: object + type: array created: type: string id: @@ -345,7 +356,18 @@ spec: type: integer environmentServices: items: + description: EnvironmentService is based on the Lagoon + API type. properties: + containers: + items: + description: ServiceContainer is based on the Lagoon + API type. + properties: + name: + type: string + type: object + type: array created: type: string id: @@ -451,7 +473,18 @@ spec: type: integer environmentServices: items: + description: EnvironmentService is based on the Lagoon + API type. properties: + containers: + items: + description: ServiceContainer is based on the Lagoon + API type. + properties: + name: + type: string + type: object + type: array created: type: string id: @@ -559,7 +592,18 @@ spec: type: integer environmentServices: items: + description: EnvironmentService is based on the Lagoon + API type. properties: + containers: + items: + description: ServiceContainer is based on the Lagoon + API type. + properties: + name: + type: string + type: object + type: array created: type: string id: diff --git a/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml b/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml index e4343f9e..5be4d4aa 100644 --- a/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml +++ b/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml @@ -223,7 +223,18 @@ spec: type: integer environmentServices: items: + description: EnvironmentService is based on the Lagoon + API type. properties: + containers: + items: + description: ServiceContainer is based on the Lagoon + API type. + properties: + name: + type: string + type: object + type: array created: type: string id: @@ -327,7 +338,18 @@ spec: type: integer environmentServices: items: + description: EnvironmentService is based on the Lagoon + API type. properties: + containers: + items: + description: ServiceContainer is based on the Lagoon + API type. + properties: + name: + type: string + type: object + type: array created: type: string id: @@ -433,7 +455,18 @@ spec: type: integer environmentServices: items: + description: EnvironmentService is based on the Lagoon + API type. properties: + containers: + items: + description: ServiceContainer is based on the Lagoon + API type. + properties: + name: + type: string + type: object + type: array created: type: string id: @@ -541,7 +574,18 @@ spec: type: integer environmentServices: items: + description: EnvironmentService is based on the Lagoon + API type. properties: + containers: + items: + description: ServiceContainer is based on the Lagoon + API type. + properties: + name: + type: string + type: object + type: array created: type: string id: diff --git a/controllers/v1beta1/build_deletionhandlers.go b/controllers/v1beta1/build_deletionhandlers.go index 6c24e670..c7f7292b 100644 --- a/controllers/v1beta1/build_deletionhandlers.go +++ b/controllers/v1beta1/build_deletionhandlers.go @@ -306,24 +306,24 @@ func (r *LagoonBuildReconciler) updateDeploymentAndEnvironmentTask(ctx context.C }) podList := &corev1.PodList{} serviceNames := []string{} - services := []lagoonv1beta1.LagoonService{} + services := []schema.EnvironmentService{} if err := r.List(context.TODO(), podList, listOption); err == nil { // generate the list of services to add to the environment for _, pod := range podList.Items { var serviceName, serviceType string - containers := []lagoonv1beta1.EnvironmentContainer{} + containers := []schema.ServiceContainer{} if name, ok := pod.ObjectMeta.Labels["lagoon.sh/service"]; ok { serviceName = name serviceNames = append(serviceNames, serviceName) for _, container := range pod.Spec.Containers { - containers = append(containers, lagoonv1beta1.EnvironmentContainer{Name: container.Name}) + containers = append(containers, schema.ServiceContainer{Name: container.Name}) } } if sType, ok := pod.ObjectMeta.Labels["lagoon.sh/service-type"]; ok { serviceType = sType } // probably need to collect dbaas consumers too at some stage - services = append(services, lagoonv1beta1.LagoonService{ + services = append(services, schema.EnvironmentService{ Name: serviceName, Type: serviceType, Containers: containers, diff --git a/controllers/v1beta1/podmonitor_buildhandlers.go b/controllers/v1beta1/podmonitor_buildhandlers.go index 220e0692..96a69d34 100644 --- a/controllers/v1beta1/podmonitor_buildhandlers.go +++ b/controllers/v1beta1/podmonitor_buildhandlers.go @@ -290,24 +290,24 @@ func (r *LagoonMonitorReconciler) updateDeploymentAndEnvironmentTask( }) depList := &appsv1.DeploymentList{} serviceNames := []string{} - services := []lagoonv1beta1.LagoonService{} + services := []schema.EnvironmentService{} if err := r.List(context.TODO(), depList, listOption); err == nil { // generate the list of services to add or update to the environment for _, deployment := range depList.Items { var serviceName, serviceType string - containers := []lagoonv1beta1.EnvironmentContainer{} + containers := []schema.ServiceContainer{} if name, ok := deployment.ObjectMeta.Labels["lagoon.sh/service"]; ok { serviceName = name serviceNames = append(serviceNames, serviceName) for _, container := range deployment.Spec.Template.Spec.Containers { - containers = append(containers, lagoonv1beta1.EnvironmentContainer{Name: container.Name}) + containers = append(containers, schema.ServiceContainer{Name: container.Name}) } } if sType, ok := deployment.ObjectMeta.Labels["lagoon.sh/service-type"]; ok { serviceType = sType } // probably need to collect dbaas consumers too at some stage - services = append(services, lagoonv1beta1.LagoonService{ + services = append(services, schema.EnvironmentService{ Name: serviceName, Type: serviceType, Containers: containers, diff --git a/controllers/v1beta2/build_deletionhandlers.go b/controllers/v1beta2/build_deletionhandlers.go index 51096a47..e9fb7f26 100644 --- a/controllers/v1beta2/build_deletionhandlers.go +++ b/controllers/v1beta2/build_deletionhandlers.go @@ -305,21 +305,31 @@ func (r *LagoonBuildReconciler) updateDeploymentAndEnvironmentTask(ctx context.C }) podList := &corev1.PodList{} serviceNames := []string{} + services := []schema.EnvironmentService{} if err := r.List(context.TODO(), podList, listOption); err == nil { // generate the list of services to add to the environment for _, pod := range podList.Items { - if _, ok := pod.ObjectMeta.Labels["lagoon.sh/service"]; ok { + var serviceName, serviceType string + containers := []schema.ServiceContainer{} + if name, ok := pod.ObjectMeta.Labels["lagoon.sh/service"]; ok { + serviceName = name + serviceNames = append(serviceNames, serviceName) for _, container := range pod.Spec.Containers { - serviceNames = append(serviceNames, container.Name) + containers = append(containers, schema.ServiceContainer{Name: container.Name}) } } - if _, ok := pod.ObjectMeta.Labels["service"]; ok { - for _, container := range pod.Spec.Containers { - serviceNames = append(serviceNames, container.Name) - } + if sType, ok := pod.ObjectMeta.Labels["lagoon.sh/service-type"]; ok { + serviceType = sType } + // probably need to collect dbaas consumers too at some stage + services = append(services, schema.EnvironmentService{ + Name: serviceName, + Type: serviceType, + Containers: containers, + }) } msg.Meta.Services = serviceNames + msg.Meta.EnvironmentServices = services } // if we aren't being provided the lagoon config, we can skip adding the routes etc if lagoonEnv != nil { diff --git a/controllers/v1beta2/podmonitor_buildhandlers.go b/controllers/v1beta2/podmonitor_buildhandlers.go index b79a0bd6..9d2ae42a 100644 --- a/controllers/v1beta2/podmonitor_buildhandlers.go +++ b/controllers/v1beta2/podmonitor_buildhandlers.go @@ -296,21 +296,31 @@ func (r *LagoonMonitorReconciler) updateDeploymentAndEnvironmentTask( }) depList := &appsv1.DeploymentList{} serviceNames := []string{} + services := []schema.EnvironmentService{} if err := r.List(context.TODO(), depList, listOption); err == nil { - // generate the list of services to add to the environment + // generate the list of services to add or update to the environment for _, deployment := range depList.Items { - if _, ok := deployment.ObjectMeta.Labels["lagoon.sh/service"]; ok { + var serviceName, serviceType string + containers := []schema.ServiceContainer{} + if name, ok := deployment.ObjectMeta.Labels["lagoon.sh/service"]; ok { + serviceName = name + serviceNames = append(serviceNames, serviceName) for _, container := range deployment.Spec.Template.Spec.Containers { - serviceNames = append(serviceNames, container.Name) + containers = append(containers, schema.ServiceContainer{Name: container.Name}) } } - if _, ok := deployment.ObjectMeta.Labels["service"]; ok { - for _, container := range deployment.Spec.Template.Spec.Containers { - serviceNames = append(serviceNames, container.Name) - } + if sType, ok := deployment.ObjectMeta.Labels["lagoon.sh/service-type"]; ok { + serviceType = sType } + // probably need to collect dbaas consumers too at some stage + services = append(services, schema.EnvironmentService{ + Name: serviceName, + Type: serviceType, + Containers: containers, + }) } msg.Meta.Services = serviceNames + msg.Meta.EnvironmentServices = services } // if we aren't being provided the lagoon config, we can skip adding the routes etc if lagoonEnv != nil { diff --git a/go.mod b/go.mod index b394be17..3f0b7efb 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.29.0 github.com/prometheus/client_golang v1.16.0 - github.com/uselagoon/machinery v0.0.17-0.20240109062854-3b567fb41003 + github.com/uselagoon/machinery v0.0.20 github.com/vshn/k8up v1.99.99 github.com/xhit/go-str2duration/v2 v2.1.0 gopkg.in/matryer/try.v1 v1.0.0-20150601225556-312d2599e12e @@ -84,10 +84,10 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/net v0.19.0 // indirect - golang.org/x/oauth2 v0.10.0 // indirect - golang.org/x/sys v0.15.0 // indirect - golang.org/x/term v0.15.0 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/oauth2 v0.17.0 // indirect + golang.org/x/sys v0.17.0 // indirect + golang.org/x/term v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.3.0 // indirect gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect diff --git a/go.sum b/go.sum index f689c8cf..2fecfb90 100644 --- a/go.sum +++ b/go.sum @@ -1254,8 +1254,8 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= -github.com/uselagoon/machinery v0.0.17-0.20240109062854-3b567fb41003 h1:fLhncKjshd8f0DBFB45u7OWsF1H6OgNmpkswJYqwCA8= -github.com/uselagoon/machinery v0.0.17-0.20240109062854-3b567fb41003/go.mod h1:Duljjz/3d/7m0jbmF1nVRDTNaMxMr6m+5LkgjiRrQaU= +github.com/uselagoon/machinery v0.0.20 h1:4pGGX/Y5UwbT86TU9vaP7QyjGk8wvikUVDvkTpesvbs= +github.com/uselagoon/machinery v0.0.20/go.mod h1:NbgtEofjK2XY0iUpk9aMYazIo+W/NI56+UF72jv8zVY= github.com/uudashr/gocognit v0.0.0-20190926065955-1655d0de0517/go.mod h1:j44Ayx2KW4+oB6SWMv8KsmHzZrOInQav7D3cQMJ5JUM= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.2.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s= @@ -1531,8 +1531,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1546,8 +1546,8 @@ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.10.0 h1:zHCpF2Khkwy4mMB4bv0U37YtJdTGW8jI0glAApi0Kh8= -golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI= +golang.org/x/oauth2 v0.17.0 h1:6m3ZPmLEFdVxKKWnKq4VqZ60gutO35zm+zrAHVmHyDQ= +golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1676,16 +1676,16 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220405210540-1e041c57c461/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= -golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= +golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=