diff --git a/Dockerfile b/Dockerfile index 78be8f1ceb..77b1ffccab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,15 @@ FROM golang:1.21.13-alpine3.20 AS builder ARG HAWTIO_ONLINE_VERSION=latest ARG HAWTIO_ONLINE_IMAGE_NAME=quay.io/hawtio/online +ARG HAWTIO_ONLINE_GATEWAY_VERSION=latest ARG HAWTIO_ONLINE_GATEWAY_IMAGE_NAME=quay.io/hawtio/online-gateway ENV IMAGE_VERSION_FLAG="-X main.ImageVersion=${HAWTIO_ONLINE_VERSION}" ENV IMAGE_REPOSITORY_FLAG="-X main.ImageRepository=${HAWTIO_ONLINE_IMAGE_NAME}" +ENV GATEWAY_IMAGE_VERSION_FLAG="-X main.GatewayImageVersion=${HAWTIO_ONLINE_GATEWAY_VERSION}" ENV GATEWAY_IMAGE_REPOSITORY_FLAG="-X main.GatewayImageRepository=${HAWTIO_ONLINE_GATEWAY_IMAGE_NAME}" -ENV GOLDFLAGS="${IMAGE_VERSION_FLAG} ${IMAGE_REPOSITORY_FLAG} ${GATEWAY_IMAGE_REPOSITORY_FLAG}" +ENV GOLDFLAGS="${IMAGE_VERSION_FLAG} ${IMAGE_REPOSITORY_FLAG} ${GATEWAY_IMAGE_VERSION_FLAG} ${GATEWAY_IMAGE_REPOSITORY_FLAG}" RUN apk update RUN apk add git make diff --git a/Makefile b/Makefile index 92fa758b37..2d676ea1a3 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ IMAGE ?= $(DEFAULT_IMAGE) VERSION ?= 1.2.0 HAWTIO_ONLINE_VERSION ?= 2.2.0 HAWTIO_ONLINE_IMAGE_NAME ?= quay.io/${ORG}/online +HAWTIO_ONLINE_GATEWAY_VERSION ?= 2.1.0 HAWTIO_ONLINE_GATEWAY_IMAGE_NAME ?= quay.io/${ORG}/online-gateway DEBUG ?= false LAST_RELEASED_IMAGE_NAME := hawtio-operator @@ -82,6 +83,7 @@ endef #** HAWTIO_ONLINE_IMAGE_NAME Set the operator's target hawtio-online image name #** HAWTIO_ONLINE_GATEWAY_IMAGE_NAME Set the operator's target hawtio-online-gateway image name #** HAWTIO_ONLINE_VERSION Set the operator's target hawtio-online image version +#** HAWTIO_ONLINE_GATEWAY_VERSION Set the operator's target hawtio-online-gateway image version # #--- image: @@ -89,6 +91,7 @@ image: --build-arg HAWTIO_ONLINE_IMAGE_NAME=$(HAWTIO_ONLINE_IMAGE_NAME) \ --build-arg HAWTIO_ONLINE_GATEWAY_IMAGE_NAME=$(HAWTIO_ONLINE_GATEWAY_IMAGE_NAME) \ --build-arg HAWTIO_ONLINE_VERSION=$(HAWTIO_ONLINE_VERSION) \ + --build-arg HAWTIO_ONLINE_GATEWAY_VERSION=$(HAWTIO_ONLINE_GATEWAY_VERSION) \ . #--- @@ -103,6 +106,7 @@ image: #** HAWTIO_ONLINE_IMAGE_NAME Set the operator's target hawtio-online image name #** HAWTIO_ONLINE_GATEWAY_IMAGE_NAME Set the operator's target hawtio-online-gateway image name #** HAWTIO_ONLINE_VERSION Set the operator's target hawtio-online image version +#** HAWTIO_ONLINE_GATEWAY_VERSION Set the operator's target hawtio-online-gateway image version # #--- publish-image: image diff --git a/README.md b/README.md index ded4e0ec51..9d82870a03 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,10 @@ spec: ### Overriding the Version of `Hawtio-Online` Unlike previous versions of the operator, the version of the `Hawtio-Online` operand is now specified during the building of the operator. Therefore, it should be unnecessary to specify this version of the container image. However, should an override be required then it is possible to add extra environment variables to the deployment resource of this operator. Specifically: -- IMAGE_VERSION: Adding this environment variable will override the version / tag of the `Hawtio-Online` container image, eg. `2.0.0-20231208`; -- IMAGE_REPOSITORY: Adding this environment variable will override the image name / repository of the `Hawtio-Online` container image, eg. `quay.io/hawtio/online`. +- IMAGE_VERSION: Adding this environment variable will override the version / tag of the `Hawtio-Online` container image, eg. `2.1.0-20240725`; +- IMAGE_REPOSITORY: Adding this environment variable will override the image name / repository of the `Hawtio-Online` container image, eg. `quay.io/hawtio/online`; +- GATEWAY_IMAGE_VERSION: Adding this environment variable will override the version / tag of the 'Hawtio-Online-Gateway' container image, eg. `2.1.0-20240725`; +- GATEWAY_IMAGE_REPOSITORY: Adding this environment variable will override the image name / repository of the `Hawtio-Online-Gateway` container image, eg. `quay.io/hawtio/gateway`. ## Features diff --git a/cmd/manager/main.go b/cmd/manager/main.go index 36abce2d2e..adddea058b 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -30,6 +30,7 @@ import ( var ( ImageRepository string ImageVersion string + GatewayImageVersion string GatewayImageRepository string LegacyServingCertificateMountVersion string ProductName string @@ -49,6 +50,7 @@ func printBuildVars(bv util.BuildVariables) { log.Info(fmt.Sprintf("Hawtio Online Image Repository: %s", bv.ImageRepository)) log.Info(fmt.Sprintf("Hawtio Online Image Version: %s", bv.ImageVersion)) log.Info(fmt.Sprintf("Hawtio Online Gateway Image Repository: %s", bv.GatewayImageRepository)) + log.Info(fmt.Sprintf("Hawtio Online Gateway Image Version: %s", bv.GatewayImageVersion)) } func main() { @@ -152,6 +154,7 @@ func operatorRun(namespace string, cfg *rest.Config) error { bv := util.BuildVariables{ ImageRepository: ImageRepository, ImageVersion: ImageVersion, + GatewayImageVersion: GatewayImageVersion, GatewayImageRepository: GatewayImageRepository, LegacyServingCertificateMountVersion: LegacyServingCertificateMountVersion, ProductName: ProductName, diff --git a/pkg/resources/deployment.go b/pkg/resources/deployment.go index bf6523ae31..b041781b8a 100644 --- a/pkg/resources/deployment.go +++ b/pkg/resources/deployment.go @@ -82,9 +82,10 @@ func newDeployment(hawtio *hawtiov1.Hawtio, replicas *int32, pts corev1.PodTempl * */ func newPodTemplateSpec(hawtio *hawtiov1.Hawtio, apiSpec *capabilities.ApiServerSpec, openShiftConsoleURL string, configMapVersion string, clientCertSecretVersion string, buildVariables util.BuildVariables) (corev1.PodTemplateSpec, error) { - hawtioVersion := getVersion(buildVariables) + hawtioVersion := getOnlineVersion(buildVariables) hawtioContainer := newHawtioContainer(hawtio, newHawtioEnvVars(hawtio, apiSpec, openShiftConsoleURL), hawtioVersion, buildVariables.ImageRepository) - gatewayContainer := newGatewayContainer(hawtio, newGatewayEnvVars(hawtio), hawtioVersion, buildVariables.GatewayImageRepository) + gatewayVersion := getGatewayVersion(buildVariables) + gatewayContainer := newGatewayContainer(hawtio, newGatewayEnvVars(hawtio), gatewayVersion, buildVariables.GatewayImageRepository) annotations := map[string]string{ configVersionAnnotation: configMapVersion, @@ -271,7 +272,7 @@ func getServingCertificateMountPath(version string, legacyServingCertificateMoun return serviceSigningSecretVolumeMountPath, nil } -func getVersion(buildVariables util.BuildVariables) string { +func getOnlineVersion(buildVariables util.BuildVariables) string { fmt.Println("Getting version from IMAGE_VERSION environment variable ...") version := os.Getenv("IMAGE_VERSION") if version == "" { @@ -284,3 +285,17 @@ func getVersion(buildVariables util.BuildVariables) string { } return version } + +func getGatewayVersion(buildVariables util.BuildVariables) string { + fmt.Println("Getting version from GATEWAY_IMAGE_VERSION environment variable ...") + version := os.Getenv("GATEWAY_IMAGE_VERSION") + if version == "" { + fmt.Println("Getting version from build variable GatewayImageVersion") + version = buildVariables.GatewayImageVersion + if len(version) == 0 { + fmt.Println("Defaulting to online version") + version = getOnlineVersion(buildVariables) + } + } + return version +} diff --git a/pkg/util/variables.go b/pkg/util/variables.go index a7b743f313..c4bbd33b68 100644 --- a/pkg/util/variables.go +++ b/pkg/util/variables.go @@ -8,6 +8,8 @@ type BuildVariables struct { GatewayImageRepository string // The hawtio-online operand image version ImageVersion string + // The hawtio-gateway operand image version + GatewayImageVersion string // Legacy serving certificate version LegacyServingCertificateMountVersion string // Product name