Skip to content

Commit

Permalink
Merge pull request #248 from uselagoon/environment-services
Browse files Browse the repository at this point in the history
refactor: environment services
  • Loading branch information
shreddedbacon authored May 2, 2024
2 parents 710e627 + 7d5190e commit 099d915
Show file tree
Hide file tree
Showing 8 changed files with 289 additions and 41 deletions.
104 changes: 104 additions & 0 deletions config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,32 @@ spec:
type: string
environmentId:
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:
type: integer
name:
type: string
type:
type: string
updated:
type: string
type: object
type: array
jobName:
type: string
jobStatus:
Expand Down Expand Up @@ -328,6 +354,32 @@ spec:
type: string
environmentId:
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:
type: integer
name:
type: string
type:
type: string
updated:
type: string
type: object
type: array
jobName:
type: string
jobStatus:
Expand Down Expand Up @@ -419,6 +471,32 @@ spec:
type: string
environmentId:
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:
type: integer
name:
type: string
type:
type: string
updated:
type: string
type: object
type: array
jobName:
type: string
jobStatus:
Expand Down Expand Up @@ -512,6 +590,32 @@ spec:
type: string
environmentId:
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:
type: integer
name:
type: string
type:
type: string
updated:
type: string
type: object
type: array
jobName:
type: string
jobStatus:
Expand Down
104 changes: 104 additions & 0 deletions config/crd/bases/crd.lagoon.sh_lagoontasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,32 @@ spec:
type: string
environmentId:
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:
type: integer
name:
type: string
type:
type: string
updated:
type: string
type: object
type: array
jobName:
type: string
jobStatus:
Expand Down Expand Up @@ -310,6 +336,32 @@ spec:
type: string
environmentId:
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:
type: integer
name:
type: string
type:
type: string
updated:
type: string
type: object
type: array
jobName:
type: string
jobStatus:
Expand Down Expand Up @@ -401,6 +453,32 @@ spec:
type: string
environmentId:
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:
type: integer
name:
type: string
type:
type: string
updated:
type: string
type: object
type: array
jobName:
type: string
jobStatus:
Expand Down Expand Up @@ -494,6 +572,32 @@ spec:
type: string
environmentId:
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:
type: integer
name:
type: string
type:
type: string
updated:
type: string
type: object
type: array
jobName:
type: string
jobStatus:
Expand Down
22 changes: 16 additions & 6 deletions controllers/v1beta1/build_deletionhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,21 +306,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 {
Expand Down
24 changes: 17 additions & 7 deletions controllers/v1beta1/podmonitor_buildhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,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 {
Expand Down
22 changes: 16 additions & 6 deletions controllers/v1beta2/build_deletionhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 099d915

Please sign in to comment.