Skip to content

Commit

Permalink
Add images.go to group all container images definitions
Browse files Browse the repository at this point in the history
Change-Id: Ic45d2f291270cc0b51b56f2927b3b1b8704fdeb1
  • Loading branch information
morucci committed Oct 17, 2023
1 parent eec4f64 commit 2366cac
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 45 deletions.
9 changes: 4 additions & 5 deletions cli/sfconfig/cmd/gerrit/gerrit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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{
Expand All @@ -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"),
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion controllers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "/"),
Expand Down
5 changes: 2 additions & 3 deletions controllers/git_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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{
{
Expand All @@ -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),
Expand Down
39 changes: 39 additions & 0 deletions controllers/libs/base/images.go
Original file line number Diff line number Diff line change
@@ -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})
}
7 changes: 2 additions & 5 deletions controllers/libs/monitoring/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)($|/)"
Expand All @@ -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)),
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions controllers/logserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions controllers/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 5 additions & 8 deletions controllers/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var nodepoolStatsdMappingConfigTemplate string
var httpdBuildLogsDirConfig string

const (
version = "9.0.0-6"
nodepoolIdent = "nodepool"
launcherIdent = nodepoolIdent + "-launcher"
shortIdent = "np"
Expand All @@ -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)
Expand Down Expand Up @@ -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(),
Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions controllers/zookeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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

Expand Down
16 changes: 6 additions & 10 deletions controllers/zuul.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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"))),
Expand Down Expand Up @@ -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"))),
Expand Down Expand Up @@ -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)),
}

Expand Down Expand Up @@ -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"))),
}
Expand Down

0 comments on commit 2366cac

Please sign in to comment.