From 390d5ce0c4884c84fac421030c85ea009dc1ec3d Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Thu, 18 Aug 2022 18:50:48 +0200 Subject: [PATCH] limitador version as env var --- config/deploy/manfiests.yaml | 3 +++ config/manager/manager.yaml | 3 +++ pkg/limitador/image.go | 15 +++++++++++++++ pkg/limitador/image_test.go | 11 +++++++++++ pkg/limitador/k8s_objects.go | 12 ++++++------ pkg/limitador/k8s_objects_test.go | 4 +--- 6 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 pkg/limitador/image.go create mode 100644 pkg/limitador/image_test.go diff --git a/config/deploy/manfiests.yaml b/config/deploy/manfiests.yaml index 14a51b00..96c5dd8f 100644 --- a/config/deploy/manfiests.yaml +++ b/config/deploy/manfiests.yaml @@ -372,6 +372,9 @@ spec: - --leader-elect command: - /manager + env: + - name: RELATED_IMAGE_LIMITADOR + value: quay.io/3scale/limitador:latest image: quay.io/kuadrant/limitador-operator:latest livenessProbe: httpGet: diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 79adfe72..273598ff 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -29,6 +29,9 @@ spec: - /manager args: - --leader-elect + env: + - name: RELATED_IMAGE_LIMITADOR + value: "quay.io/3scale/limitador:latest" image: controller:latest name: manager securityContext: diff --git a/pkg/limitador/image.go b/pkg/limitador/image.go new file mode 100644 index 00000000..f88fe135 --- /dev/null +++ b/pkg/limitador/image.go @@ -0,0 +1,15 @@ +package limitador + +import ( + "fmt" + + "github.com/kuadrant/limitador-operator/pkg/helpers" +) + +var ( + defaultImageVersion = fmt.Sprintf("%s:%s", LimitadorRepository, "latest") +) + +func GetLimitadorImageVersion() string { + return helpers.FetchEnv("RELATED_IMAGE_LIMITADOR", defaultImageVersion) +} diff --git a/pkg/limitador/image_test.go b/pkg/limitador/image_test.go new file mode 100644 index 00000000..c17681c6 --- /dev/null +++ b/pkg/limitador/image_test.go @@ -0,0 +1,11 @@ +package limitador + +import ( + "testing" + + "gotest.tools/assert" +) + +func TestLimitadorDefaulImage(t *testing.T) { + assert.Equal(t, GetLimitadorImageVersion(), "quay.io/3scale/limitador:latest") +} diff --git a/pkg/limitador/k8s_objects.go b/pkg/limitador/k8s_objects.go index 52899c5c..b8a61633 100644 --- a/pkg/limitador/k8s_objects.go +++ b/pkg/limitador/k8s_objects.go @@ -4,18 +4,18 @@ import ( "crypto/md5" "fmt" - limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "sigs.k8s.io/yaml" + + limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" ) const ( - DefaultVersion = "latest" DefaultReplicas = 1 - Image = "quay.io/3scale/limitador" + LimitadorRepository = "quay.io/3scale/limitador" StatusEndpoint = "/status" LimitadorConfigFileName = "limitador-config.yaml" LimitadorCMHash = "hash" @@ -64,9 +64,9 @@ func LimitadorDeployment(limitador *limitadorv1alpha1.Limitador) *appsv1.Deploym replicas = int32(*limitador.Spec.Replicas) } - version := DefaultVersion + image := GetLimitadorImageVersion() if limitador.Spec.Version != nil { - version = *limitador.Spec.Version + image = fmt.Sprintf("%s:%s", LimitadorRepository, *limitador.Spec.Version) } return &appsv1.Deployment{ @@ -93,7 +93,7 @@ func LimitadorDeployment(limitador *limitadorv1alpha1.Limitador) *appsv1.Deploym Containers: []v1.Container{ { Name: "limitador", - Image: Image + ":" + version, + Image: image, Ports: []v1.ContainerPort{ { Name: "http", diff --git a/pkg/limitador/k8s_objects_test.go b/pkg/limitador/k8s_objects_test.go index df16df1a..45e7d9b1 100644 --- a/pkg/limitador/k8s_objects_test.go +++ b/pkg/limitador/k8s_objects_test.go @@ -9,9 +9,8 @@ import ( ) func TestConstants(t *testing.T) { - assert.Check(t, "latest" == DefaultVersion) assert.Check(t, 1 == DefaultReplicas) - assert.Check(t, "quay.io/3scale/limitador" == Image) + assert.Check(t, "quay.io/3scale/limitador" == LimitadorRepository) assert.Check(t, "/status" == StatusEndpoint) assert.Check(t, "limitador-config.yaml" == LimitadorConfigFileName) assert.Check(t, "hash" == LimitadorCMHash) @@ -47,7 +46,6 @@ func newTestLimitadorObj(name, namespace string, limits []limitadorv1alpha1.Rate Limits: limits, }, } - } func TestServiceName(t *testing.T) {