From 2366cacf378044bdcc4b657ccd8cafe56ab24d20 Mon Sep 17 00:00:00 2001 From: Fabien Boucher Date: Mon, 16 Oct 2023 09:54:28 +0000 Subject: [PATCH] Add images.go to group all container images definitions Change-Id: Ic45d2f291270cc0b51b56f2927b3b1b8704fdeb1 --- cli/sfconfig/cmd/gerrit/gerrit.go | 9 +++--- controllers/config.go | 2 +- controllers/git_server.go | 5 ++- controllers/libs/base/images.go | 39 +++++++++++++++++++++++ controllers/libs/monitoring/monitoring.go | 7 ++-- controllers/logserver_controller.go | 9 ++---- controllers/mariadb.go | 6 ++-- controllers/nodepool.go | 13 +++----- controllers/zookeeper.go | 4 +-- controllers/zuul.go | 16 ++++------ 10 files changed, 65 insertions(+), 45 deletions(-) create mode 100644 controllers/libs/base/images.go diff --git a/cli/sfconfig/cmd/gerrit/gerrit.go b/cli/sfconfig/cmd/gerrit/gerrit.go index 486aae30..9c4f64d7 100644 --- a/cli/sfconfig/cmd/gerrit/gerrit.go +++ b/cli/sfconfig/cmd/gerrit/gerrit.go @@ -39,7 +39,6 @@ const gerritSSHDPort = 29418 const gerritSSHDPortName = "gerrit-sshd" const gerritSiteMountPath = "/gerrit" const gerritIdent = "gerrit" -const gerritImage = "quay.io/software-factory/gerrit:3.6.4-8" //go:embed static/entrypoint.sh var entrypoint string @@ -249,7 +248,7 @@ func SetGerritSTSContainer(sts *appsv1.StatefulSet, volumeMounts []apiv1.VolumeM } func SetGerritMSFRContainer(sts *appsv1.StatefulSet, fqdn string) { - container := base.MkContainer(managesfResourcesIdent, controllers.BusyboxImage) + container := base.MkContainer(managesfResourcesIdent, base.BusyboxImage) container.Command = []string{"sh", "-c", managesfEntrypoint} container.Env = []apiv1.EnvVar{ base.MkEnvVar("HOME", "/tmp"), @@ -286,7 +285,7 @@ func GerritPostInitContainer(jobName string, fqdn string) apiv1.Container { base.MkSecretEnvVar("ZUUL_HTTP_PASSWORD", "zuul-gerrit-api-key", "zuul-gerrit-api-key"), } - container := base.MkContainer(fmt.Sprintf("%s-container", jobName), controllers.BusyboxImage) + container := base.MkContainer(fmt.Sprintf("%s-container", jobName), base.BusyboxImage) container.Command = []string{"sh", "-c", postInitScript} container.Env = env container.VolumeMounts = []apiv1.VolumeMount{ @@ -303,7 +302,7 @@ func GerritPostInitContainer(jobName string, fqdn string) apiv1.Container { } func GerritInitContainers(volumeMounts []apiv1.VolumeMount, fqdn string) apiv1.Container { - container := base.MkContainer("gerrit-init", gerritImage) + container := base.MkContainer("gerrit-init", base.GerritImage) container.Command = []string{"sh", "-c", gerritInitScript} container.Env = []apiv1.EnvVar{ base.MkSecretEnvVar("GERRIT_ADMIN_SSH_PUB", "admin-ssh-key", "pub"), @@ -338,7 +337,7 @@ func (g *GerritCMDContext) ensureGerritSTS() { name := gerritIdent _, err := g.getSTS(name) if err != nil && errors.IsNotFound(err) { - container := base.MkContainer(name, gerritImage) + container := base.MkContainer(name, base.GerritImage) storageConfig := controllers.BaseGetStorageConfOrDefault(v1.StorageSpec{}, "") pvc := base.MkPVC(name, g.env.Ns, storageConfig, apiv1.ReadWriteOnce) sts := base.MkStatefulset( diff --git a/controllers/config.go b/controllers/config.go index 7c0675bc..796e7a17 100644 --- a/controllers/config.go +++ b/controllers/config.go @@ -127,7 +127,7 @@ func (r *SFController) SetupBaseSecrets() bool { } func (r *SFController) RunCommand(name string, args []string, extraVars []apiv1.EnvVar) *batchv1.Job { - jobContainer := base.MkContainer("sf-operator", BusyboxImage) + jobContainer := base.MkContainer("sf-operator", base.BusyboxImage) jobContainer.Command = append([]string{"python3", "/sf_operator/main.py"}, args...) jobContainer.Env = append([]apiv1.EnvVar{ base.MkEnvVar("PYTHONPATH", "/"), diff --git a/controllers/git_server.go b/controllers/git_server.go index d0171363..3e302381 100644 --- a/controllers/git_server.go +++ b/controllers/git_server.go @@ -23,7 +23,6 @@ import ( const gsIdent = "git-server" const gsGitPort = 9418 const gsGitPortName = "git-server-port" -const gsImage = "quay.io/software-factory/git-deamon:2.39.1-3" const gsGitMountPath = "/git" const gsPiMountPath = "/entry" @@ -66,7 +65,7 @@ func (r *SFController) DeployGitServer() bool { // Create the deployment replicas := int32(1) - dep := r.mkStatefulSet(gsIdent, gsImage, r.getStorageConfOrDefault(r.cr.Spec.GitServer.Storage), replicas, apiv1.ReadWriteOnce) + dep := r.mkStatefulSet(gsIdent, base.GitServerImage, r.getStorageConfOrDefault(r.cr.Spec.GitServer.Storage), replicas, apiv1.ReadWriteOnce) dep.Spec.Template.ObjectMeta.Annotations = annotations dep.Spec.Template.Spec.Containers[0].VolumeMounts = []apiv1.VolumeMount{ { @@ -84,7 +83,7 @@ func (r *SFController) DeployGitServer() bool { } // Define initContainer - initContainer := base.MkContainer("init-config", gsImage) + initContainer := base.MkContainer("init-config", base.GitServerImage) initContainer.Command = []string{"/bin/bash", "/entry/pre-init.sh"} initContainer.Env = []apiv1.EnvVar{ base.MkEnvVar("FQDN", r.cr.Spec.FQDN), diff --git a/controllers/libs/base/images.go b/controllers/libs/base/images.go new file mode 100644 index 00000000..3c2a727f --- /dev/null +++ b/controllers/libs/base/images.go @@ -0,0 +1,39 @@ +// Copyright (C) 2023 Red Hat +// SPDX-License-Identifier: Apache-2.0 +// + +package base + +type Image struct { + Path string + Version string +} + +func ImageToString(i Image) string { + return i.Path + ":" + i.Version +} + +const ( + nodepoolImageVersion = "9.0.0-6" + zuulImageVersion = "9.2.0-1" +) + +var ( + BusyboxImage = ImageToString(Image{Path: "quay.io/software-factory/sf-op-busybox", Version: "1.5-3"}) + GerritImage = ImageToString(Image{Path: "quay.io/software-factory/gerrit", Version: "3.6.4-8"}) + GitServerImage = ImageToString(Image{Path: "quay.io/software-factory/git-deamon", Version: "2.39.1-3"}) + SSHDImage = ImageToString(Image{Path: "quay.io/software-factory/sshd", Version: "0.1-2"}) + PurgeLogsImage = ImageToString(Image{Path: "quay.io/software-factory/purgelogs", Version: "0.2.3-2"}) + NodepoolLauncherImage = ImageToString(Image{Path: "quay.io/software-factory/nodepool-launcher", Version: nodepoolImageVersion}) + NodepoolBuilderImage = ImageToString(Image{Path: "quay.io/software-factory/nodepool-builder", Version: nodepoolImageVersion}) + MariabDBImage = ImageToString(Image{Path: "quay.io/software-factory/mariadb", Version: "10.5.16-4"}) + ZookeeperImage = ImageToString(Image{Path: "quay.io/software-factory/zookeeper", Version: "3.8.0-5"}) + // https://catalog.redhat.com/software/containers/ubi8/httpd-24/6065b844aee24f523c207943?q=httpd&architecture=amd64&image=651f274c8ce9242f7bb3e011 + HTTPDImage = ImageToString(Image{Path: "registry.access.redhat.com/ubi8/httpd-24", Version: "1-284.1696531168"}) + NodeExporterImage = ImageToString(Image{Path: "quay.io/prometheus/node-exporter", Version: "v1.6.1"}) + StatsdExporterImage = ImageToString(Image{Path: "quay.io/prometheus/statsd-exporter", Version: "v0.24.0"}) +) + +func ZuulImage(service string) string { + return ImageToString(Image{Path: "quay.io/software-factory/" + service, Version: zuulImageVersion}) +} diff --git a/controllers/libs/monitoring/monitoring.go b/controllers/libs/monitoring/monitoring.go index 64e8ae4a..177c0273 100644 --- a/controllers/libs/monitoring/monitoring.go +++ b/controllers/libs/monitoring/monitoring.go @@ -37,8 +37,6 @@ const NodeExporterNameSuffix = "-nodeexporter" const NodeExporterPortNameSuffix = "-ne" const nodeExporterPort = 9100 -const NodeExporterImage = "quay.io/prometheus/node-exporter:latest" - // Fun fact: arrays cannot be consts, so we define our args in this function. func getNodeExporterArgs(volumeMounts []apiv1.VolumeMount) []string { var excludePaths = "^(/etc/hosts|/etc/hostname|/etc/passwd|/etc/resolv.conf|/run/.containerenv|/run/secrets|/dev|/proc|/sys)($|/)" @@ -50,7 +48,7 @@ func getNodeExporterArgs(volumeMounts []apiv1.VolumeMount) []string { } func MkNodeExporterSideCarContainer(serviceName string, volumeMounts []apiv1.VolumeMount) apiv1.Container { - container := base.MkContainer(serviceName+NodeExporterNameSuffix, NodeExporterImage) + container := base.MkContainer(serviceName+NodeExporterNameSuffix, base.NodeExporterImage) container.Args = getNodeExporterArgs(volumeMounts) container.Ports = []apiv1.ContainerPort{ base.MkContainerPort(nodeExporterPort, GetTruncatedPortName(serviceName, NodeExporterPortNameSuffix)), @@ -74,7 +72,6 @@ const statsdExporterPortNameSuffix = "-se" const StatsdExporterPortListen = int32(9125) const statsdExporterPortExpose = int32(9102) const StatsdExporterConfigFile = "statsd_mapping.yaml" -const statsdExporterImage = "quay.io/prometheus/statsd-exporter:v0.24.0" type StatsdMetricMappingLabel struct { LabelName string @@ -132,7 +129,7 @@ func MkStatsdExporterSideCarContainer(serviceName string, configVolumeName strin ContainerPort: statsdExporterPortExpose, }, } - sidecar := base.MkContainer(serviceName+statsdExporterNameSuffix, statsdExporterImage) + sidecar := base.MkContainer(serviceName+statsdExporterNameSuffix, base.StatsdExporterImage) sidecar.Args = args sidecar.VolumeMounts = volumeMounts sidecar.Ports = ports diff --git a/controllers/logserver_controller.go b/controllers/logserver_controller.go index 10bdb3b8..48e60e7a 100644 --- a/controllers/logserver_controller.go +++ b/controllers/logserver_controller.go @@ -47,8 +47,6 @@ var logserverEntrypoint string const sshdPort = 2222 const sshdPortName = "logserver-sshd" -const sshdImage = "quay.io/software-factory/sshd:0.1-2" - const httpdBaseDir = "/opt/rh/httpd24/root" const httpdData = "/var/www" @@ -57,7 +55,6 @@ const httpdData = "/var/www" var logserverRun string const purgelogIdent = "purgelogs" -const purgeLogsImage = "quay.io/software-factory/purgelogs:0.2.3-2" const purgelogsLogsDir = "/home/logs" //go:embed static/logserver/logserver.conf.tmpl @@ -240,7 +237,7 @@ func (r *LogServerController) DeployLogserver() sfv1.LogServerStatus { } // Create the deployment - dep := base.MkDeployment(logserverIdent, r.ns, HTTPDImage) + dep := base.MkDeployment(logserverIdent, r.ns, base.HTTPDImage) // Setup the main container dep.Spec.Template.Spec.Containers[0].VolumeMounts = volumeMounts @@ -300,7 +297,7 @@ func (r *LogServerController) DeployLogserver() sfv1.LogServerStatus { r.GetOrCreate(&httpdService) // Setup the sidecar container for sshd - sshdContainer := base.MkContainer(sshdPortName, sshdImage) + sshdContainer := base.MkContainer(sshdPortName, base.SSHDImage) sshdContainer.Command = []string{"bash", "/conf/run.sh"} sshdContainer.Env = []apiv1.EnvVar{ base.MkEnvVar("AUTHORIZED_KEY", r.cr.Spec.AuthorizedSSHKey), @@ -328,7 +325,7 @@ func (r *LogServerController) DeployLogserver() sfv1.LogServerStatus { loopdelay, retentiondays := getLogserverSettingsOrDefault(r.cr.Spec.Settings) - purgelogsContainer := base.MkContainer(purgelogIdent, purgeLogsImage) + purgelogsContainer := base.MkContainer(purgelogIdent, base.PurgeLogsImage) purgelogsContainer.Command = []string{ "/usr/local/bin/purgelogs", "--retention-days", diff --git a/controllers/mariadb.go b/controllers/mariadb.go index f3efc618..8de7cdc7 100644 --- a/controllers/mariadb.go +++ b/controllers/mariadb.go @@ -18,8 +18,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -const DBImage = "quay.io/software-factory/mariadb:10.5.16-4" - const mariadbPort = 3306 const mariaDBPortName = "mariadb-port" @@ -37,7 +35,7 @@ type ZuulDBOpts struct { func (r *SFController) CreateDBInitContainer(username string, password string, dbname string) apiv1.Container { c := "CREATE DATABASE IF NOT EXISTS " + dbname + " CHARACTER SET utf8 COLLATE utf8_general_ci; " g := "GRANT ALL PRIVILEGES ON " + dbname + ".* TO '" + username + "'@'%' IDENTIFIED BY '${USER_PASSWORD}' WITH GRANT OPTION; FLUSH PRIVILEGES;" - container := base.MkContainer("mariadb-client", DBImage) + container := base.MkContainer("mariadb-client", base.MariabDBImage) container.Command = []string{"sh", "-c", ` echo 'Running: mysql --host=mariadb --user=root --password="$MYSQL_ROOT_PASSWORD" -e "` + c + g + `"' ATTEMPT=0 @@ -126,7 +124,7 @@ func (r *SFController) DeployMariadb() bool { r.EnsureSecretUUID(passName) replicas := int32(1) - dep := r.mkStatefulSet("mariadb", DBImage, r.getStorageConfOrDefault(r.cr.Spec.MariaDB.DBStorage), replicas, apiv1.ReadWriteOnce) + dep := r.mkStatefulSet("mariadb", base.MariabDBImage, r.getStorageConfOrDefault(r.cr.Spec.MariaDB.DBStorage), replicas, apiv1.ReadWriteOnce) dep.Spec.VolumeClaimTemplates = append( dep.Spec.VolumeClaimTemplates, diff --git a/controllers/nodepool.go b/controllers/nodepool.go index 15f064cb..77bfb094 100644 --- a/controllers/nodepool.go +++ b/controllers/nodepool.go @@ -41,7 +41,6 @@ var nodepoolStatsdMappingConfigTemplate string var httpdBuildLogsDirConfig string const ( - version = "9.0.0-6" nodepoolIdent = "nodepool" launcherIdent = nodepoolIdent + "-launcher" shortIdent = "np" @@ -51,8 +50,6 @@ const ( buildLogsHttpdPortName = "buildlogs-http" NodepoolProvidersSecretsName = "nodepool-providers-secrets" builderIdent = nodepoolIdent + "-builder" - nodepoolLauncherImage = "quay.io/software-factory/" + launcherIdent + ":" + version - nodepoolBuilderImage = "quay.io/software-factory/" + builderIdent + ":" + version ) var nodepoolStatsdExporterPortName = monitoring.GetStatsdExporterPort(shortIdent) @@ -432,7 +429,7 @@ func (r *SFController) DeployNodepoolBuilder(statsdExporterVolume apiv1.Volume, "serial": "7", } - initContainer := base.MkContainer("nodepool-builder-init", BusyboxImage) + initContainer := base.MkContainer("nodepool-builder-init", base.BusyboxImage) initContainer.Command = []string{"bash", "-c", "mkdir -p ~/dib; /usr/local/bin/generate-config.sh"} initContainer.Env = append(r.getNodepoolConfigEnvs(), @@ -452,7 +449,7 @@ func (r *SFController) DeployNodepoolBuilder(statsdExporterVolume apiv1.Volume, replicas := int32(1) nb := r.mkStatefulSet( - builderIdent, nodepoolBuilderImage, r.getStorageConfOrDefault(r.cr.Spec.Nodepool.Builder.Storage), + builderIdent, base.NodepoolBuilderImage, r.getStorageConfOrDefault(r.cr.Spec.Nodepool.Builder.Storage), replicas, apiv1.ReadWriteOnce) nb.Spec.Template.ObjectMeta.Annotations = annotations @@ -581,7 +578,7 @@ func (r *SFController) DeployNodepoolLauncher(statsdExporterVolume apiv1.Volume, "serial": "6", // When the Secret ResourceVersion field change (when edited) we force a nodepool-launcher restart "nodepool-providers-secrets": string(nodepoolProvidersSecrets.ResourceVersion), - "nodepool-launcher-image": nodepoolLauncherImage, + "nodepool-launcher-image": base.NodepoolLauncherImage, } if r.isConfigRepoSet() { @@ -590,13 +587,13 @@ func (r *SFController) DeployNodepoolLauncher(statsdExporterVolume apiv1.Volume, nl := base.MkDeployment("nodepool-launcher", r.ns, "") - container := base.MkContainer("launcher", nodepoolLauncherImage) + container := base.MkContainer("launcher", base.NodepoolLauncherImage) container.VolumeMounts = volumeMount container.Command = []string{"/usr/local/bin/dumb-init", "--", "/usr/local/bin/nodepool-launcher", "-f", "-l", "/etc/nodepool-logging/logging.yaml"} container.Env = r.getNodepoolConfigEnvs() - initContainer := base.MkContainer("nodepool-launcher-init", BusyboxImage) + initContainer := base.MkContainer("nodepool-launcher-init", base.BusyboxImage) initContainer.Command = []string{"/usr/local/bin/generate-config.sh"} initContainer.Env = r.getNodepoolConfigEnvs() diff --git a/controllers/zookeeper.go b/controllers/zookeeper.go index 02b2a120..957edb65 100644 --- a/controllers/zookeeper.go +++ b/controllers/zookeeper.go @@ -38,8 +38,6 @@ const zkServerPort = 2888 const zkIdent = "zookeeper" const zkPIMountPath = "/config-scripts" -const zkImage = "quay.io/software-factory/" + zkIdent + ":3.8.0-5" - func (r *SFController) DeployZookeeper() bool { dnsNames := r.MkClientDNSNames(zkIdent) privateKey := certv1.CertificatePrivateKey{ @@ -93,7 +91,7 @@ func (r *SFController) DeployZookeeper() bool { }, } - container := base.MkContainer(zkIdent, zkImage) + container := base.MkContainer(zkIdent, base.ZookeeperImage) container.Command = []string{"/bin/bash", "/config-scripts/run.sh"} container.VolumeMounts = volumes diff --git a/controllers/zuul.go b/controllers/zuul.go index 591b3367..79b24b4a 100644 --- a/controllers/zuul.go +++ b/controllers/zuul.go @@ -50,10 +50,6 @@ var zuulLoggingConfig string // Common config sections for all Zuul components var commonIniConfigSections = []string{"zookeeper", "keystore", "database"} -func ZuulImage(service string) string { - return "quay.io/software-factory/" + service + ":9.2.0-1" -} - func isStatefulset(service string) bool { return service == "zuul-scheduler" || service == "zuul-executor" || service == "zuul-merger" } @@ -116,7 +112,7 @@ func (r *SFController) mkZuulContainer(service string) []apiv1.Container { } container := apiv1.Container{ Name: service, - Image: ZuulImage(service), + Image: base.ZuulImage(service), Command: command, Env: envs, VolumeMounts: volumes, @@ -180,7 +176,7 @@ func (r *SFController) getTenantsEnvs() []apiv1.EnvVar { } func (r *SFController) mkInitSchedulerConfigContainer() apiv1.Container { - container := base.MkContainer("init-scheduler-config", BusyboxImage) + container := base.MkContainer("init-scheduler-config", base.BusyboxImage) container.Command = []string{"/usr/local/bin/generate-zuul-tenant-yaml.sh"} container.Env = append(r.getTenantsEnvs(), base.MkEnvVar("HOME", "/var/lib/zuul"), base.MkEnvVar("INIT_CONTAINER", "1")) @@ -253,7 +249,7 @@ func (r *SFController) EnsureZuulScheduler(initContainers []apiv1.Container, cfg annotations := map[string]string{ "zuul-common-config": utils.IniSectionsChecksum(cfg, commonIniConfigSections), "zuul-component-config": utils.IniSectionsChecksum(cfg, sections), - "zuul-image": ZuulImage("zuul-scheduler"), + "zuul-image": base.ZuulImage("zuul-scheduler"), "statsd_mapping": utils.Checksum([]byte(zuulStatsdMappingConfig)), "serial": "3", "zuul-logging": utils.Checksum([]byte(r.getZuulLoggingString("zuul-scheduler"))), @@ -323,7 +319,7 @@ func (r *SFController) EnsureZuulExecutor(cfg *ini.File) bool { annotations := map[string]string{ "zuul-common-config": utils.IniSectionsChecksum(cfg, commonIniConfigSections), "zuul-component-config": utils.IniSectionsChecksum(cfg, sections), - "zuul-image": ZuulImage("zuul-executor"), + "zuul-image": base.ZuulImage("zuul-executor"), "replicas": strconv.Itoa(int(r.cr.Spec.Zuul.Executor.Replicas)), "serial": "1", "zuul-logging": utils.Checksum([]byte(r.getZuulLoggingString("zuul-executor"))), @@ -373,7 +369,7 @@ func (r *SFController) EnsureZuulMerger(cfg *ini.File) bool { annotations := map[string]string{ "zuul-common-config": utils.IniSectionsChecksum(cfg, commonIniConfigSections), "zuul-component-config": utils.IniSectionsChecksum(cfg, sections), - "zuul-image": ZuulImage(service), + "zuul-image": base.ZuulImage(service), "replicas": strconv.Itoa(int(r.cr.Spec.Zuul.Merger.MinReplicas)), } @@ -414,7 +410,7 @@ func (r *SFController) EnsureZuulWeb(cfg *ini.File) bool { annotations := map[string]string{ "zuul-common-config": utils.IniSectionsChecksum(cfg, commonIniConfigSections), "zuul-component-config": utils.IniSectionsChecksum(cfg, sections), - "zuul-image": ZuulImage("zuul-web"), + "zuul-image": base.ZuulImage("zuul-web"), "serial": "1", "zuul-logging": utils.Checksum([]byte(r.getZuulLoggingString("zuul-web"))), }