From 12e74a154c149ae4db454b34b0ee2006afd8b1a3 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 5 Jan 2024 20:17:54 +1100 Subject: [PATCH] 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 {