Skip to content

Commit

Permalink
limitador version as env var
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Aug 18, 2022
1 parent 54391c5 commit 390d5ce
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
3 changes: 3 additions & 0 deletions config/deploy/manfiests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions pkg/limitador/image.go
Original file line number Diff line number Diff line change
@@ -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)
}
11 changes: 11 additions & 0 deletions pkg/limitador/image_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
12 changes: 6 additions & 6 deletions pkg/limitador/k8s_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand All @@ -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",
Expand Down
4 changes: 1 addition & 3 deletions pkg/limitador/k8s_objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -47,7 +46,6 @@ func newTestLimitadorObj(name, namespace string, limits []limitadorv1alpha1.Rate
Limits: limits,
},
}

}

func TestServiceName(t *testing.T) {
Expand Down

0 comments on commit 390d5ce

Please sign in to comment.