Skip to content

Commit

Permalink
Merge branch '1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
phantomjinx committed Jul 19, 2024
2 parents c2155bb + d160264 commit 3d33fd5
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 74 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ jobs:
${{ runner.os }}-go-
- name: Build
run: make build
- name: Build image
run: |
make image
- name: Display image
run: |
docker images
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ FROM golang:1.20-alpine3.18 AS builder

ARG HAWTIO_ONLINE_VERSION=latest
ARG HAWTIO_ONLINE_IMAGE_NAME=quay.io/hawtio/online
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_REPOSITORY_FLAG="-X main.GatewayImageRepository=${HAWTIO_ONLINE_GATEWAY_IMAGE_NAME}"

ENV GOLDFLAGS="${IMAGE_VERSION_FLAG} ${IMAGE_REPOSITORY_FLAG}"
ENV GOLDFLAGS="${IMAGE_VERSION_FLAG} ${IMAGE_REPOSITORY_FLAG} ${GATEWAY_IMAGE_REPOSITORY_FLAG}"

RUN apk update
RUN apk add git make
Expand Down
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ IMAGE ?= $(DEFAULT_IMAGE)
VERSION ?= 1.1.1
HAWTIO_ONLINE_VERSION ?= 2.1.0
HAWTIO_ONLINE_IMAGE_NAME ?= quay.io/${ORG}/online
HAWTIO_ONLINE_GATEWAY_IMAGE_NAME ?= quay.io/${ORG}/online-gateway
DEBUG ?= false
LAST_RELEASED_IMAGE_NAME := hawtio-operator
LAST_RELEASED_VERSION ?= 1.1.0
Expand Down Expand Up @@ -76,15 +77,17 @@ endef
#== Compile the operator as a docker image
#
#* PARAMETERS:
#** IMAGE: Set a custom image for the container image
#** VERSION: Set a custom version for the container image tag
#** HAWTIO_ONLINE_IMAGE_NAME Set the operator's target hawtio-online image name
#** HAWTIO_ONLINE_VERSION Set the operator's target hawtio-online image version
#** IMAGE: Set a custom image for the container image
#** VERSION: Set a custom version for the container image tag
#** 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
#
#---
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) \
.

Expand All @@ -95,10 +98,11 @@ image:
#== Compile the operator as a docker image then push the image to the repository
#
#* PARAMETERS:
#** IMAGE: Set a custom image for the container image
#** VERSION: Set a custom version for the container image tag
#** HAWTIO_ONLINE_IMAGE_NAME Set the operator's target hawtio-online image name
#** HAWTIO_ONLINE_VERSION Set the operator's target hawtio-online image version
#** IMAGE: Set a custom image for the container image
#** VERSION: Set a custom version for the container image tag
#** 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
#
#---
publish-image: image
Expand Down
3 changes: 3 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
var (
ImageRepository string
ImageVersion string
GatewayImageRepository string
LegacyServingCertificateMountVersion string
ProductName string
ServerRootDirectory string
Expand All @@ -46,6 +47,7 @@ func printVersion() {
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))
}

func main() {
Expand Down Expand Up @@ -137,6 +139,7 @@ func operatorRun(namespace string, cfg *rest.Config) error {
bv := util.BuildVariables{
ImageRepository: ImageRepository,
ImageVersion: ImageVersion,
GatewayImageRepository: GatewayImageRepository,
LegacyServingCertificateMountVersion: LegacyServingCertificateMountVersion,
ProductName: ProductName,
ServerRootDirectory: ServerRootDirectory,
Expand Down
40 changes: 32 additions & 8 deletions pkg/controller/hawtio/hawtio_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ func TestHawtioController_Reconcile(t *testing.T) {
err = r.client.Get(context.TODO(), NamespacedName, &deployment)
require.NoError(t, err)

container := deployment.Spec.Template.Spec.Containers[0]
assert.Equal(t, container.Resources, hawtio.Spec.Resources)
hawtioContainer := deployment.Spec.Template.Spec.Containers[0]
assert.Equal(t, hawtioContainer.Resources, hawtio.Spec.Resources)

gatewayContainer := deployment.Spec.Template.Spec.Containers[1]
assert.Equal(t, gatewayContainer.Resources, hawtio.Spec.Resources)
})
t.Run("check if the ConfigMap has been created", func(t *testing.T) {
configMap := corev1.ConfigMap{}
Expand Down Expand Up @@ -137,8 +140,8 @@ func TestHawtioController_Reconcile(t *testing.T) {
err = r.client.Get(context.TODO(), NamespacedName, &deployment)
require.NoError(t, err)

container := deployment.Spec.Template.Spec.Containers[0]
assert.ElementsMatch(t, container.Env, []corev1.EnvVar{
hawtioContainer := deployment.Spec.Template.Spec.Containers[0]
assert.ElementsMatch(t, hawtioContainer.Env, []corev1.EnvVar{
{
Name: resources.HawtioTypeEnvVar,
Value: strings.ToLower(string(hawtiov1.NamespaceHawtioDeploymentType)),
Expand All @@ -156,15 +159,36 @@ func TestHawtioController_Reconcile(t *testing.T) {
Name: resources.HawtioOAuthClientEnvVar,
Value: hawtio.Name,
},
{
Name: resources.HawtioRbacEnvVar,
Value: "",
},
{
Name: resources.HawtioAuthEnvVar,
Value: "form",
},
})

gatewayContainer := deployment.Spec.Template.Spec.Containers[1]
assert.ElementsMatch(t, gatewayContainer.Env, []corev1.EnvVar{
{
Name: resources.GatewayWebSvrEnvVar,
Value: "https://localhost:8443",
},
{
Name: resources.GatewaySSLKeyEnvVar,
Value: "/etc/tls/private/serving/tls.key",
},
{
Name: resources.GatewaySSLCertEnvVar,
Value: "/etc/tls/private/serving/tls.crt",
},
{
Name: resources.GatewaySSLCertCAEnvVar,
Value: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt",
},
{
Name: resources.GatewayRbacEnvVar,
Value: "",
},
})

})
})
}
119 changes: 112 additions & 7 deletions pkg/resources/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,45 @@ import (
)

const containerPortName = "https"
const containerGatewayPortName = "express"

func newContainer(hawtio *hawtiov1.Hawtio, envVars []corev1.EnvVar, imageVersion string, imageRepository string) corev1.Container {
func newHawtioContainer(hawtio *hawtiov1.Hawtio, envVars []corev1.EnvVar, imageVersion string, imageRepository string) corev1.Container {
/*
* - name: hawtio-online-container
* image: quay.io/hawtio/online
* imagePullPolicy: Always
* ports:
* - name: https
* containerPort: 8443
* livenessProbe:
* httpGet:
* path: /online
* port: https
* scheme: HTTPS
* periodSeconds: 10
* timeoutSeconds: 1
* readinessProbe:
* httpGet:
* path: /online
* port: https
* scheme: HTTPS
* initialDelaySeconds: 5
* periodSeconds: 5
* timeoutSeconds: 1
* resources:
* requests:
* cpu: "0.2"
* memory: 32Mi
* limits:
* cpu: "1.0"
* memory: 500Mi
* volumeMounts:
* - name: hawtio-online-tls-serving
* mountPath: /etc/tls/private/serving
*/
container := corev1.Container{
Name: hawtio.Name + "-container",
Image: getImageFor(imageVersion, imageRepository),
Image: getHawtioImageFor(imageVersion, imageRepository),
Env: envVars,
ReadinessProbe: &corev1.Probe{
InitialDelaySeconds: 5,
Expand Down Expand Up @@ -53,13 +87,84 @@ func newContainer(hawtio *hawtiov1.Hawtio, envVars []corev1.EnvVar, imageVersion
return container
}

func getImageFor(tag string, imageRepository string) string {
repository := os.Getenv("IMAGE_REPOSITORY")
func newGatewayContainer(hawtio *hawtiov1.Hawtio, envVars []corev1.EnvVar, imageVersion string, imageGatewayRepository string) corev1.Container {
/*
* - name: hawtio-online-gateway-container
* image: quay.io/hawtio/online-gateway
* ports:
* - name: express
* containerPort: 3000
* livenessProbe:
* httpGet:
* path: /status
* port: express
* scheme: HTTPS
* periodSeconds: 120
* timeoutSeconds: 1
* readinessProbe:
* httpGet:
* path: /status
* port: express
* scheme: HTTPS
* initialDelaySeconds: 5
* periodSeconds: 30
* timeoutSeconds: 1
*/
container := corev1.Container{
Name: hawtio.Name + "-gateway-container",
Image: getGatewayImageFor(imageVersion, imageGatewayRepository),
Env: envVars,
Ports: []corev1.ContainerPort{
{
Name: containerGatewayPortName,
ContainerPort: 3000,
Protocol: "TCP",
},
},
LivenessProbe: &corev1.Probe{
Handler: corev1.Handler{
HTTPGet: &corev1.HTTPGetAction{
Port: intstr.FromString(containerGatewayPortName),
Path: "/status",
Scheme: "HTTPS",
},
},
PeriodSeconds: 10,
TimeoutSeconds: 1,
},
ReadinessProbe: &corev1.Probe{
Handler: corev1.Handler{
HTTPGet: &corev1.HTTPGetAction{
Port: intstr.FromString(containerGatewayPortName),
Path: "/status",
Scheme: "HTTPS",
},
},
InitialDelaySeconds: 5,
PeriodSeconds: 5,
TimeoutSeconds: 1,
},
Resources: hawtio.Spec.Resources,
}

return container
}

func getHawtioImageFor(tag string, imageRepository string) string {
return getImageFor(tag, imageRepository, "IMAGE_REPOSITORY", "quay.io/hawtio/online")
}

func getGatewayImageFor(tag string, gatewayImgRepository string) string {
return getImageFor(tag, gatewayImgRepository, "GATEWAY_IMAGE_REPOSITORY", "quay.io/hawtio/online-gateway")
}

func getImageFor(tag string, imgRepo string, envVar string, defaultVal string) string {
repository := os.Getenv(envVar)
if repository == "" {
if imageRepository != "" {
repository = imageRepository
if imgRepo != "" {
repository = imgRepo
} else {
repository = "quay.io/hawtio/online"
repository = defaultVal
}
}

Expand Down
Loading

0 comments on commit 3d33fd5

Please sign in to comment.