Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limitador version from env var #37

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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 Expand Up @@ -212,4 +215,7 @@ spec:
provider:
name: Red Hat
url: https://github.com/Kuadrant/limitador-operator
relatedImages:
- image: quay.io/3scale/limitador:latest
name: limitador
version: 0.0.0
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename it to something like LIMITADOR_SERVICE_IMAGE or LIMITADOR_INSTANCE_IMAGE or just LIMITADOR_IMAGE ... regarding the last one, we could make the distinction with LIMITADOR_OPERATOR_IMAGE if needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RELATED_IMAGE prefix is commonly in OSBS for productization purposes.

I am preparing it for the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the relatedImages section in the bundle is automatically created because of that prefix is being used.

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"
didierofrivia marked this conversation as resolved.
Show resolved Hide resolved
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you are thinking on having extra capabilities for the image and repository, but if not we could simply use FetchEnv here like:

image := helpers.FetchEnv(RELATED_IMAGE_LIMITADOR, fmt.Sprintf("%s:%s", LimitadorRepository, DefaultVersion) )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only included the logic in a method to be testable in image_test.go

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