Skip to content

Commit ef1a5f3

Browse files
committed
refactor: backwards compatible fallback for configmap check
1 parent 8036f48 commit ef1a5f3

4 files changed

Lines changed: 109 additions & 29 deletions

File tree

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/onsi/ginkgo/v2 v2.27.3
1717
github.com/onsi/gomega v1.38.3
1818
github.com/prometheus/client_golang v1.23.2
19-
github.com/uselagoon/machinery v0.0.35-0.20250907231937-622deb3fd70d
19+
github.com/uselagoon/machinery v0.0.35-0.20260211024046-9280cba22264
2020
github.com/vshn/k8up v1.99.99
2121
github.com/xhit/go-str2duration/v2 v2.1.0
2222
golang.org/x/text v0.32.0
@@ -111,10 +111,10 @@ require (
111111
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
112112
golang.org/x/mod v0.30.0 // indirect
113113
golang.org/x/net v0.47.0 // indirect
114-
golang.org/x/oauth2 v0.30.0 // indirect
114+
golang.org/x/oauth2 v0.34.0 // indirect
115115
golang.org/x/sync v0.19.0 // indirect
116-
golang.org/x/sys v0.38.0 // indirect
117-
golang.org/x/term v0.37.0 // indirect
116+
golang.org/x/sys v0.40.0 // indirect
117+
golang.org/x/term v0.39.0 // indirect
118118
golang.org/x/time v0.9.0 // indirect
119119
golang.org/x/tools v0.39.0 // indirect
120120
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,8 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb
12411241
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
12421242
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
12431243
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
1244-
github.com/uselagoon/machinery v0.0.35-0.20250907231937-622deb3fd70d h1:7qifEQS0lMjRlwRy9NbhAUUNqbvrGej6oKtesSDMaLQ=
1245-
github.com/uselagoon/machinery v0.0.35-0.20250907231937-622deb3fd70d/go.mod h1:G0ujppuNR0BrtAnlmH8xDb9TDfayb4A36aeo0DYg7fQ=
1244+
github.com/uselagoon/machinery v0.0.35-0.20260211024046-9280cba22264 h1:GwvwniG/hln2THN0f0c4QjqC6BsPtYqVp3J6FLhPtJ0=
1245+
github.com/uselagoon/machinery v0.0.35-0.20260211024046-9280cba22264/go.mod h1:UVqIxwF/Q9xO3LQMkQhWeuegpuKcsrxmBa4LE52SiWQ=
12461246
github.com/uudashr/gocognit v0.0.0-20190926065955-1655d0de0517/go.mod h1:j44Ayx2KW4+oB6SWMv8KsmHzZrOInQav7D3cQMJ5JUM=
12471247
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
12481248
github.com/valyala/fasthttp v1.2.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s=
@@ -1531,8 +1531,8 @@ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ
15311531
golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
15321532
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
15331533
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
1534-
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
1535-
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
1534+
golang.org/x/oauth2 v0.34.0 h1:hqK/t4AKgbqWkdkcAeI8XLmbK+4m4G5YeQRrmiotGlw=
1535+
golang.org/x/oauth2 v0.34.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
15361536
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
15371537
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
15381538
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -1660,16 +1660,16 @@ golang.org/x/sys v0.0.0-20220405210540-1e041c57c461/go.mod h1:oPkhp1MJrh7nUepCBc
16601660
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
16611661
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
16621662
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1663-
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
1664-
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
1663+
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
1664+
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
16651665
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
16661666
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
16671667
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
16681668
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
16691669
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
16701670
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
1671-
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=
1672-
golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=
1671+
golang.org/x/term v0.39.0 h1:RclSuaJf32jOqZz74CkPA9qFuVTX7vhLlpfj/IGWlqY=
1672+
golang.org/x/term v0.39.0/go.mod h1:yxzUCTP/U+FzoxfdKmLaA0RV1WgE0VY7hXBwKtY/4ww=
16731673
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
16741674
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
16751675
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

internal/controllers/v1beta2/buildpodmonitor_handlers.go

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ import (
1616
lagooncrd "github.com/uselagoon/remote-controller/api/lagoon/v1beta2"
1717
"github.com/uselagoon/remote-controller/internal/helpers"
1818
"github.com/uselagoon/remote-controller/internal/metrics"
19+
appsv1 "k8s.io/api/apps/v1"
1920
corev1 "k8s.io/api/core/v1"
2021
meta "k8s.io/apimachinery/pkg/api/meta"
2122
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/apimachinery/pkg/labels"
24+
"k8s.io/apimachinery/pkg/selection"
2225
"k8s.io/apimachinery/pkg/types"
2326
ctrl "sigs.k8s.io/controller-runtime"
2427
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -292,14 +295,50 @@ func (r *BuildMonitorReconciler) updateDeploymentAndEnvironmentTask(
292295
if helpers.IgnoreNotFound(err) != nil {
293296
return err
294297
}
295-
}
296-
if val, ok := lagoonServices.Data["post-deploy"]; ok {
297-
serviceConfig := LagoonServices{}
298-
err := json.Unmarshal([]byte(val), &serviceConfig)
299-
if err == nil {
300-
fmt.Println(serviceConfig.Services)
301-
fmt.Println(serviceConfig.Volumes)
302-
msg.Meta.EnvironmentServices = serviceConfig.Services
298+
// if configmap doesn't exist, fall back to previous service check behaviour
299+
labelRequirements1, _ := labels.NewRequirement("lagoon.sh/service", selection.NotIn, []string{"faketest"})
300+
listOption := (&client.ListOptions{}).ApplyOptions([]client.ListOption{
301+
client.InNamespace(jobPod.Namespace),
302+
client.MatchingLabelsSelector{
303+
Selector: labels.NewSelector().Add(*labelRequirements1),
304+
},
305+
})
306+
depList := &appsv1.DeploymentList{}
307+
serviceNames := []string{}
308+
services := []schema.EnvironmentService{}
309+
if err := r.APIReader.List(context.TODO(), depList, listOption); err == nil {
310+
// generate the list of services to add or update to the environment
311+
for _, deployment := range depList.Items {
312+
var serviceName, serviceType string
313+
containers := []schema.ServiceContainer{}
314+
if name, ok := deployment.Labels["lagoon.sh/service"]; ok {
315+
serviceName = name
316+
serviceNames = append(serviceNames, serviceName)
317+
for _, container := range deployment.Spec.Template.Spec.Containers {
318+
containers = append(containers, schema.ServiceContainer{Name: container.Name})
319+
}
320+
}
321+
if sType, ok := deployment.Labels["lagoon.sh/service-type"]; ok {
322+
serviceType = sType
323+
}
324+
// probably need to collect dbaas consumers too at some stage
325+
services = append(services, schema.EnvironmentService{
326+
Name: serviceName,
327+
Type: serviceType,
328+
Containers: containers,
329+
})
330+
}
331+
msg.Meta.Services = serviceNames
332+
msg.Meta.EnvironmentServices = services
333+
}
334+
} else {
335+
// otherwise get the values from configmap
336+
if val, ok := lagoonServices.Data["post-deploy"]; ok {
337+
serviceConfig := LagoonServices{}
338+
err := json.Unmarshal([]byte(val), &serviceConfig)
339+
if err == nil {
340+
msg.Meta.EnvironmentServices = serviceConfig.Services
341+
}
303342
}
304343
}
305344
route, routes, err := helpers.GetLagoonEnvRoutes(ctx, opLog, r.Client, namespace.Name)

internal/messenger/build_messenger.go

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ import (
1111
"github.com/uselagoon/machinery/api/schema"
1212
lagooncrd "github.com/uselagoon/remote-controller/api/lagoon/v1beta2"
1313
"github.com/uselagoon/remote-controller/internal/helpers"
14+
appsv1 "k8s.io/api/apps/v1"
1415
corev1 "k8s.io/api/core/v1"
16+
"k8s.io/apimachinery/pkg/labels"
17+
"k8s.io/apimachinery/pkg/selection"
1518
"k8s.io/apimachinery/pkg/types"
19+
"sigs.k8s.io/controller-runtime/pkg/client"
1620
)
1721

1822
type LagoonServices struct {
@@ -119,20 +123,57 @@ func (m *Messenger) UpdateDeploymentAndEnvironmentTask(
119123
Cluster: targetName,
120124
},
121125
}
126+
122127
lagoonServices := &corev1.ConfigMap{}
123-
if err := m.APIReader.Get(ctx, types.NamespacedName{Namespace: lagoonBuild.Namespace, Name: "lagoon-services"}, lagoonServices); err != nil {
128+
if err := m.Client.Get(ctx, types.NamespacedName{Namespace: lagoonBuild.Namespace, Name: "lagoon-services"}, lagoonServices); err != nil {
124129
if helpers.IgnoreNotFound(err) != nil {
125130
opLog.Error(err, "configmap %s not found", "lagoon-services")
126131
return
127132
}
128-
}
129-
if val, ok := lagoonServices.Data["post-deploy"]; ok {
130-
serviceConfig := LagoonServices{}
131-
err := json.Unmarshal([]byte(val), &serviceConfig)
132-
if err == nil {
133-
fmt.Println(serviceConfig.Services)
134-
fmt.Println(serviceConfig.Volumes)
135-
msg.Meta.EnvironmentServices = serviceConfig.Services
133+
// if configmap doesn't exist, fall back to previous service check behaviour
134+
labelRequirements1, _ := labels.NewRequirement("lagoon.sh/service", selection.NotIn, []string{"faketest"})
135+
listOption := (&client.ListOptions{}).ApplyOptions([]client.ListOption{
136+
client.InNamespace(lagoonBuild.Namespace),
137+
client.MatchingLabelsSelector{
138+
Selector: labels.NewSelector().Add(*labelRequirements1),
139+
},
140+
})
141+
depList := &appsv1.DeploymentList{}
142+
serviceNames := []string{}
143+
services := []schema.EnvironmentService{}
144+
if err := m.Client.List(context.TODO(), depList, listOption); err == nil {
145+
// generate the list of services to add or update to the environment
146+
for _, deployment := range depList.Items {
147+
var serviceName, serviceType string
148+
containers := []schema.ServiceContainer{}
149+
if name, ok := deployment.Labels["lagoon.sh/service"]; ok {
150+
serviceName = name
151+
serviceNames = append(serviceNames, serviceName)
152+
for _, container := range deployment.Spec.Template.Spec.Containers {
153+
containers = append(containers, schema.ServiceContainer{Name: container.Name})
154+
}
155+
}
156+
if sType, ok := deployment.Labels["lagoon.sh/service-type"]; ok {
157+
serviceType = sType
158+
}
159+
// probably need to collect dbaas consumers too at some stage
160+
services = append(services, schema.EnvironmentService{
161+
Name: serviceName,
162+
Type: serviceType,
163+
Containers: containers,
164+
})
165+
}
166+
msg.Meta.Services = serviceNames
167+
msg.Meta.EnvironmentServices = services
168+
}
169+
} else {
170+
// otherwise get the values from configmap
171+
if val, ok := lagoonServices.Data["post-deploy"]; ok {
172+
serviceConfig := LagoonServices{}
173+
err := json.Unmarshal([]byte(val), &serviceConfig)
174+
if err == nil {
175+
msg.Meta.EnvironmentServices = serviceConfig.Services
176+
}
136177
}
137178
}
138179
if checkLagoonEnv {

0 commit comments

Comments
 (0)