Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: environment services #248

Merged
merged 4 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading