Skip to content

Commit db4ce7e

Browse files
Microzuul CIGerrit Code Review
authored andcommitted
Merge "Change the way sf-operator set images names in annotations"
2 parents daecac4 + 1eed491 commit db4ce7e

File tree

11 files changed

+44
-24
lines changed

11 files changed

+44
-24
lines changed

controllers/gateway.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package controllers
77

88
import (
99
_ "embed"
10+
"maps"
1011

1112
"github.com/softwarefactory-project/sf-operator/controllers/libs/base"
1213
"github.com/softwarefactory-project/sf-operator/controllers/libs/logging"
@@ -33,12 +34,14 @@ func (r *SFController) DeployHTTPDGateway() bool {
3334
})
3435

3536
annotations := map[string]string{
36-
"image": base.HTTPDImage(),
3737
"config-hash": utils.Checksum([]byte(gatewayConfig)),
3838
"serial": "1",
3939
}
4040

4141
dep := base.MkDeployment(ident, r.ns, base.HTTPDImage(), r.cr.Spec.ExtraLabels, r.isOpenShift)
42+
43+
maps.Copy(annotations, ImagesAnnotationsFromSpec(dep.Spec.Template.Spec.Containers))
44+
4245
dep.Spec.Template.ObjectMeta.Annotations = annotations
4346
dep.Spec.Template.Spec.Volumes = []apiv1.Volume{
4447
base.MkVolumeCM(ident, ident+"-config-map"),

controllers/git_server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package controllers
88
import (
99
_ "embed"
1010
"fmt"
11+
"maps"
1112
"slices"
1213
"strconv"
1314
"strings"
@@ -272,7 +273,6 @@ func (r *SFController) DeployGitServer() bool {
272273

273274
annotations := map[string]string{
274275
"config-hash": utils.Checksum([]byte(preInitScript)),
275-
"image": base.GitServerImage(),
276276
"fqdn": r.cr.Spec.FQDN,
277277
"serial": "3",
278278
}
@@ -292,6 +292,7 @@ func (r *SFController) DeployGitServer() bool {
292292
// Create the statefulset
293293
storage := r.getStorageConfOrDefault(r.cr.Spec.GitServer.Storage)
294294
sts := r.mkStatefulSet(GitServerIdent, base.GitServerImage(), storage, apiv1.ReadWriteOnce, r.cr.Spec.ExtraLabels, r.isOpenShift)
295+
maps.Copy(annotations, ImagesAnnotationsFromSpec(sts.Spec.Template.Spec.Containers))
295296
sts.Spec.Template.ObjectMeta.Annotations = annotations
296297
GSVolumeMountsRO := []apiv1.VolumeMount{
297298
{

controllers/hound-search.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
apiv1 "k8s.io/api/core/v1"
1414
"k8s.io/apimachinery/pkg/api/resource"
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16+
"maps"
1617
)
1718

1819
const houndSearchIdent = "hound-search"
@@ -104,10 +105,12 @@ func (r *SFController) DeployHoundSearch() bool {
104105
annotations := map[string]string{
105106
"config-hash": utils.Checksum([]byte(r.configBaseURL + r.cr.Spec.ConfigRepositoryLocation.Name)),
106107
"corporate-ca-certs-version": getCMVersion(corporateCM, corporateCMExists),
107-
"image": houndSearchImage,
108108
"serial": "1",
109109
"config-scripts": utils.Checksum([]byte(houndSearchRender + houndSearchInit + houndSearchConfig)),
110110
}
111+
112+
maps.Copy(annotations, ImagesAnnotationsFromSpec(sts.Spec.Template.Spec.Containers))
113+
111114
limits := v1.LimitsSpec{
112115
CPU: resource.MustParse("500m"),
113116
Memory: resource.MustParse("2Gi"),
@@ -123,6 +126,7 @@ func (r *SFController) DeployHoundSearch() bool {
123126
sts.Spec.Template.Spec.HostAliases = base.CreateHostAliases(r.cr.Spec.HostAliases)
124127

125128
sts.Spec.Template.ObjectMeta.Annotations = annotations
129+
126130
current, stsUpdated := r.ensureStatefulset(storage.StorageClassName, sts)
127131

128132
if stsUpdated {

controllers/logjuicer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/softwarefactory-project/sf-operator/controllers/libs/utils"
99
appsv1 "k8s.io/api/apps/v1"
1010
apiv1 "k8s.io/api/core/v1"
11+
"maps"
1112
)
1213

1314
func (r *SFController) AddCorporateCA(spec *apiv1.PodSpec) string {
@@ -77,11 +78,11 @@ func (r *SFController) EnsureLogJuicer() bool {
7778
}
7879

7980
dep.Spec.Template.ObjectMeta.Annotations = map[string]string{
80-
"image": base.LogJuicerImage(),
8181
"config-hash": utils.Checksum([]byte(config)),
8282
"serial": "1",
8383
"certs": r.AddCorporateCA(&dep.Spec.Template.Spec),
8484
}
85+
maps.Copy(dep.Spec.Template.ObjectMeta.Annotations, ImagesAnnotationsFromSpec(dep.Spec.Template.Spec.Containers))
8586
dep.Spec.Template.Spec.HostAliases = base.CreateHostAliases(r.cr.Spec.HostAliases)
8687

8788
// Reconcile deployment

controllers/logserver.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ package controllers
88
import (
99
_ "embed"
1010
"encoding/base64"
11+
"maps"
1112
"strconv"
1213

1314
"k8s.io/utils/ptr"
1415

15-
"golang.org/x/exp/maps"
1616
apiv1 "k8s.io/api/core/v1"
1717
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1818
"k8s.io/apimachinery/pkg/runtime"
@@ -296,11 +296,10 @@ func (r *SFController) DeployLogserver() bool {
296296
"config-hash": utils.Checksum([]byte(logserverConf)),
297297
"purgeLogConfig": "retentionDays:" + strconv.Itoa(r.cr.Spec.Logserver.RetentionDays) +
298298
" loopDelay:" + strconv.Itoa(r.cr.Spec.Logserver.LoopDelay),
299-
"httpd-image": base.HTTPDImage(),
300-
"purgelogs-image": base.PurgelogsImage(),
301-
"sshd-image": base.SSHDImage(),
302-
"authorized-key": utils.Checksum(pubKey),
299+
"authorized-key": utils.Checksum(pubKey),
303300
}
301+
maps.Copy(sts.Spec.Template.ObjectMeta.Annotations, ImagesAnnotationsFromSpec(sts.Spec.Template.Spec.Containers))
302+
304303
sts.Spec.Template.Spec.HostAliases = base.CreateHostAliases(r.cr.Spec.HostAliases)
305304

306305
current, stsUpdated := r.ensureStatefulset(storage.StorageClassName, sts)

controllers/mariadb.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package controllers
88
import (
99
_ "embed"
1010
"fmt"
11+
"maps"
1112
"strconv"
1213

1314
"github.com/go-sql-driver/mysql"
@@ -264,7 +265,7 @@ GRANT ALL ON *.* TO root@'%%' WITH GRANT OPTION;`,
264265

265266
annotations := map[string]string{
266267
"serial": "6",
267-
"image": base.MariaDBImage(),
268+
268269
"limits": limitstr,
269270
}
270271
if r.cr.Spec.FluentBitLogForwarding != nil {
@@ -276,6 +277,7 @@ GRANT ALL ON *.* TO root@'%%' WITH GRANT OPTION;`,
276277
statsExporter := sfmonitoring.MkNodeExporterSideCarContainer(MariaDBIdent, volumeMountsStatsExporter, r.isOpenShift)
277278
sts.Spec.Template.Spec.Containers = append(sts.Spec.Template.Spec.Containers, statsExporter)
278279

280+
maps.Copy(annotations, ImagesAnnotationsFromSpec(sts.Spec.Template.Spec.Containers))
279281
sts.Spec.Template.ObjectMeta.Annotations = annotations
280282

281283
sts.Spec.Template.Spec.HostAliases = base.CreateHostAliases(r.cr.Spec.HostAliases)

controllers/nodepool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package controllers
66

77
import (
88
_ "embed"
9+
"maps"
910
"strconv"
1011

1112
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
@@ -124,7 +125,6 @@ func createImageBuildLogForwarderSidecar(r *SFController, annotations map[string
124125
sidecar, storageEmptyDir := logging.CreateFluentBitSideCarContainer("diskimage-builder", builderFluentBitLabels, volumeMounts, r.isOpenShift)
125126
annotations["dib-fluent-bit.conf"] = utils.Checksum([]byte(fbForwarderConfig["fluent-bit.conf"]))
126127
annotations["dib-fluent-bit-parser"] = utils.Checksum([]byte(fbForwarderConfig["parsers.conf"]))
127-
annotations["dib-fluent-bit-image"] = sidecar.Image
128128
return []apiv1.Volume{volume, storageEmptyDir}, sidecar
129129

130130
}
@@ -518,7 +518,6 @@ func (r *SFController) DeployNodepoolBuilder(statsdExporterVolume apiv1.Volume,
518518
"ssh_config": utils.Checksum([]byte(builderSSHConfig)),
519519
"buildlogs_httpd_config": utils.Checksum([]byte(httpdBuildLogsDirConfig)),
520520
"statsd_mapping": utils.Checksum([]byte(nodepoolStatsdMappingConfig)),
521-
"image": base.NodepoolBuilderImage(),
522521
"nodepool-providers-secrets": getSecretsVersion(providersSecrets, providerSecretsExists),
523522
"serial": "18",
524523
"corporate-ca-certs-version": getCMVersion(corporateCM, corporateCMExists),
@@ -585,6 +584,7 @@ func (r *SFController) DeployNodepoolBuilder(statsdExporterVolume apiv1.Volume,
585584
nb.Spec.Template.Spec.Volumes = append(nb.Spec.Template.Spec.Volumes, fbVolumes...)
586585
}
587586

587+
maps.Copy(annotations, ImagesAnnotationsFromSpec(nb.Spec.Template.Spec.Containers))
588588
nb.Spec.Template.ObjectMeta.Annotations = annotations
589589

590590
// Append statsd exporter sidecar
@@ -715,7 +715,6 @@ func (r *SFController) DeployNodepoolLauncher(statsdExporterVolume apiv1.Volume,
715715
"statsd_mapping": utils.Checksum([]byte(nodepoolStatsdMappingConfig)),
716716
"serial": "12",
717717
// When the Secret ResourceVersion field change (when edited) we force a nodepool-launcher restart
718-
"image": base.NodepoolLauncherImage(),
719718
"nodepool-providers-secrets": getSecretsVersion(providersSecrets, providerSecretsExists),
720719
"corporate-ca-certs-version": getCMVersion(corporateCM, corporateCMExists),
721720
}
@@ -778,6 +777,7 @@ func (r *SFController) DeployNodepoolLauncher(statsdExporterVolume apiv1.Volume,
778777
nl.Spec.Template.Spec.Containers = []apiv1.Container{
779778
container,
780779
monitoring.MkStatsdExporterSideCarContainer(shortIdent, "statsd-config", relayAddress, r.isOpenShift)}
780+
maps.Copy(annotations, ImagesAnnotationsFromSpec(nl.Spec.Template.Spec.Containers))
781781
nl.Spec.Template.ObjectMeta.Annotations = annotations
782782
nl.Spec.Template.Spec.Containers[0].ReadinessProbe = base.MkReadinessHTTPProbe("/ready", launcherPort)
783783
nl.Spec.Template.Spec.Containers[0].LivenessProbe = base.MkLiveHTTPProbe("/ready", launcherPort)

controllers/utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,3 +857,11 @@ func RunPodCmdRaw(restConfig *rest.Config, kubeClientset *kubernetes.Clientset,
857857
func (r *SFUtilContext) RunPodCmd(podName string, containerName string, cmdArgs []string) (*bytes.Buffer, error) {
858858
return RunPodCmdRaw(r.RESTConfig, r.ClientSet, r.ns, podName, containerName, cmdArgs)
859859
}
860+
861+
func ImagesAnnotationsFromSpec(containers []apiv1.Container) map[string]string {
862+
annotations := map[string]string{}
863+
for _, container := range containers {
864+
annotations["image/"+container.Name] = container.Image
865+
}
866+
return annotations
867+
}

controllers/weeder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/softwarefactory-project/sf-operator/controllers/libs/utils"
1010
appsv1 "k8s.io/api/apps/v1"
1111
apiv1 "k8s.io/api/core/v1"
12+
"maps"
1213
)
1314

1415
func (r *SFController) EnsureZuulWeeder(checksum string) bool {
@@ -23,11 +24,11 @@ func (r *SFController) EnsureZuulWeeder(checksum string) bool {
2324
annotations := map[string]string{
2425
"config-hash": checksum,
2526
"serial": "2",
26-
"image": base.ZuulWeederImage(),
2727
}
2828

2929
dep := base.MkDeployment(ident, r.ns, base.ZuulWeederImage(), r.cr.Spec.ExtraLabels, r.isOpenShift)
3030
dep.Spec.Template.Spec.Containers[0].ImagePullPolicy = "Always"
31+
maps.Copy(annotations, ImagesAnnotationsFromSpec(dep.Spec.Template.Spec.Containers))
3132
dep.Spec.Template.ObjectMeta.Annotations = annotations
3233
dep.Spec.Template.Spec.Volumes = []apiv1.Volume{
3334
base.MkEmptyDirVolume("weeder-tmp"),

controllers/zookeeper.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package controllers
55

66
import (
77
_ "embed"
8+
"maps"
89

910
"github.com/softwarefactory-project/sf-operator/controllers/libs/base"
1011
"github.com/softwarefactory-project/sf-operator/controllers/libs/conds"
@@ -75,7 +76,6 @@ func (r *SFController) DeployZookeeper() bool {
7576

7677
annotations := map[string]string{
7778
"config-hash": utils.Checksum([]byte(configChecksumable)),
78-
"image": base.ZookeeperImage(),
7979
"serial": "8",
8080
}
8181

@@ -170,6 +170,7 @@ func (r *SFController) DeployZookeeper() bool {
170170
statsExporter := sfmonitoring.MkNodeExporterSideCarContainer(ZookeeperIdent, volumeMountsStatsExporter, r.isOpenShift)
171171
zk.Spec.Template.Spec.Containers = append(zk.Spec.Template.Spec.Containers, statsExporter)
172172

173+
maps.Copy(annotations, ImagesAnnotationsFromSpec(zk.Spec.Template.Spec.Containers))
173174
zk.Spec.Template.ObjectMeta.Annotations = annotations
174175

175176
zk.Spec.Template.Spec.HostAliases = base.CreateHostAliases(r.cr.Spec.HostAliases)

0 commit comments

Comments
 (0)