Skip to content

Commit

Permalink
fix: Splits the online version from the gateway version
Browse files Browse the repository at this point in the history
* When building, the versions of images can end up differently so the
  ONLINE_VERSION cannot be used for both.
  • Loading branch information
phantomjinx committed Nov 20, 2024
1 parent e936b10 commit 1e6eaa2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -82,13 +83,15 @@ 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:
docker build -t $(IMAGE):$(VERSION) \
--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) \
.

#---
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
var (
ImageRepository string
ImageVersion string
GatewayImageVersion string
GatewayImageRepository string
LegacyServingCertificateMountVersion string
ProductName string
Expand All @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 18 additions & 3 deletions pkg/resources/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 == "" {
Expand All @@ -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
}
2 changes: 2 additions & 0 deletions pkg/util/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1e6eaa2

Please sign in to comment.