Skip to content

Commit

Permalink
feat: support for services v2
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Jan 5, 2024
1 parent 0e99812 commit 12e74a1
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 1 deletion.
6 changes: 6 additions & 0 deletions apis/lagoon/v1beta1/lagoonmessaging_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions apis/lagoon/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
48 changes: 48 additions & 0 deletions config/crd/bases/crd.lagoon.sh_lagoontasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions controllers/v1beta1/build_deletionhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 14 additions & 1 deletion controllers/v1beta1/podmonitor_buildhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 12e74a1

Please sign in to comment.