-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from Kuadrant/fix-status
fix status check
- Loading branch information
Showing
19 changed files
with
1,484 additions
and
617 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
appsv1 "k8s.io/api/apps/v1" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" | ||
"github.com/kuadrant/limitador-operator/pkg/limitador" | ||
) | ||
|
||
var _ = Describe("Limitador controller manages affinity", func() { | ||
|
||
var testNamespace string | ||
|
||
BeforeEach(func() { | ||
CreateNamespace(&testNamespace) | ||
}) | ||
|
||
AfterEach(DeleteNamespaceCallback(&testNamespace)) | ||
|
||
Context("Creating a new Limitador object with specific affinity", func() { | ||
var limitadorObj *limitadorv1alpha1.Limitador | ||
|
||
affinity := &v1.Affinity{ | ||
PodAntiAffinity: &v1.PodAntiAffinity{ | ||
PreferredDuringSchedulingIgnoredDuringExecution: []v1.WeightedPodAffinityTerm{ | ||
{ | ||
Weight: 100, | ||
PodAffinityTerm: v1.PodAffinityTerm{ | ||
LabelSelector: &metav1.LabelSelector{ | ||
MatchLabels: map[string]string{ | ||
"pod": "label", | ||
}, | ||
}, | ||
TopologyKey: "kubernetes.io/hostname", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
BeforeEach(func() { | ||
limitadorObj = basicLimitador(testNamespace) | ||
limitadorObj.Spec.Affinity = affinity | ||
Expect(k8sClient.Create(context.TODO(), limitadorObj)).Should(Succeed()) | ||
Eventually(testLimitadorIsReady(limitadorObj), time.Minute, 5*time.Second).Should(BeTrue()) | ||
}) | ||
|
||
It("Should create a new deployment with the custom affinity", func() { | ||
deployment := appsv1.Deployment{} | ||
Eventually(func() bool { | ||
err := k8sClient.Get( | ||
context.TODO(), | ||
types.NamespacedName{ | ||
Namespace: testNamespace, | ||
Name: limitador.DeploymentName(limitadorObj), | ||
}, | ||
&deployment) | ||
|
||
return err == nil | ||
}, timeout, interval).Should(BeTrue()) | ||
|
||
Expect(deployment.Spec.Template.Spec.Affinity).To(Equal(affinity)) | ||
}) | ||
}) | ||
|
||
Context("Updating limitador object with new affinity settings", func() { | ||
var limitadorObj *limitadorv1alpha1.Limitador | ||
|
||
affinity := &v1.Affinity{ | ||
PodAntiAffinity: &v1.PodAntiAffinity{ | ||
PreferredDuringSchedulingIgnoredDuringExecution: []v1.WeightedPodAffinityTerm{ | ||
{ | ||
Weight: 100, | ||
PodAffinityTerm: v1.PodAffinityTerm{ | ||
LabelSelector: &metav1.LabelSelector{ | ||
MatchLabels: map[string]string{ | ||
"pod": "label", | ||
}, | ||
}, | ||
TopologyKey: "kubernetes.io/hostname", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
BeforeEach(func() { | ||
limitadorObj = basicLimitador(testNamespace) | ||
Expect(k8sClient.Create(context.TODO(), limitadorObj)).Should(Succeed()) | ||
Eventually(testLimitadorIsReady(limitadorObj), time.Minute, 5*time.Second).Should(BeTrue()) | ||
}) | ||
|
||
It("Should modify the deployment with the affinity custom settings", func() { | ||
deployment := appsv1.Deployment{} | ||
Eventually(func() bool { | ||
err := k8sClient.Get(context.TODO(), types.NamespacedName{ | ||
Namespace: testNamespace, | ||
Name: limitador.DeploymentName(limitadorObj), | ||
}, &deployment) | ||
|
||
return err == nil | ||
}, timeout, interval).Should(BeTrue()) | ||
|
||
Expect(deployment.Spec.Template.Spec.Affinity).To(BeNil()) | ||
|
||
updatedLimitador := limitadorv1alpha1.Limitador{} | ||
Eventually(func() bool { | ||
err := k8sClient.Get(context.TODO(), types.NamespacedName{ | ||
Namespace: testNamespace, | ||
Name: limitadorObj.Name, | ||
}, &updatedLimitador) | ||
|
||
if err != nil { | ||
return false | ||
} | ||
|
||
updatedLimitador.Spec.Affinity = affinity.DeepCopy() | ||
|
||
return k8sClient.Update(context.TODO(), &updatedLimitador) == nil | ||
}, timeout, interval).Should(BeTrue()) | ||
|
||
Eventually(func() bool { | ||
newDeployment := appsv1.Deployment{} | ||
err := k8sClient.Get(context.TODO(), types.NamespacedName{ | ||
Namespace: testNamespace, | ||
Name: limitador.DeploymentName(limitadorObj), | ||
}, &newDeployment) | ||
|
||
if err != nil { | ||
return false | ||
} | ||
|
||
return reflect.DeepEqual(newDeployment.Spec.Template.Spec.Affinity, affinity) | ||
}, timeout, interval).Should(BeTrue()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/yaml" | ||
|
||
limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" | ||
"github.com/kuadrant/limitador-operator/pkg/limitador" | ||
) | ||
|
||
var _ = Describe("Limitador controller manages limits", func() { | ||
|
||
var testNamespace string | ||
|
||
BeforeEach(func() { | ||
CreateNamespace(&testNamespace) | ||
}) | ||
|
||
AfterEach(DeleteNamespaceCallback(&testNamespace)) | ||
|
||
Context("Creating a new Limitador object with specific limits", func() { | ||
var limitadorObj *limitadorv1alpha1.Limitador | ||
|
||
limits := []limitadorv1alpha1.RateLimit{ | ||
{ | ||
Conditions: []string{"req.method == 'GET'"}, | ||
MaxValue: 10, | ||
Namespace: "test-namespace", | ||
Seconds: 60, | ||
Variables: []string{"user_id"}, | ||
Name: "useless", | ||
}, | ||
{ | ||
Conditions: []string{"req.method == 'POST'"}, | ||
MaxValue: 5, | ||
Namespace: "test-namespace", | ||
Seconds: 60, | ||
Variables: []string{"user_id"}, | ||
}, | ||
} | ||
|
||
BeforeEach(func() { | ||
limitadorObj = basicLimitador(testNamespace) | ||
limitadorObj.Spec.Limits = limits | ||
Expect(k8sClient.Create(context.TODO(), limitadorObj)).Should(Succeed()) | ||
Eventually(testLimitadorIsReady(limitadorObj), time.Minute, 5*time.Second).Should(BeTrue()) | ||
}) | ||
|
||
It("Should create configmap with the custom limits", func() { | ||
cm := &v1.ConfigMap{} | ||
Eventually(func() bool { | ||
err := k8sClient.Get(context.TODO(), | ||
types.NamespacedName{ | ||
Namespace: testNamespace, | ||
Name: limitador.LimitsConfigMapName(limitadorObj), | ||
}, cm) | ||
|
||
return err == nil | ||
}, timeout, interval).Should(BeTrue()) | ||
|
||
var cmLimits []limitadorv1alpha1.RateLimit | ||
err := yaml.Unmarshal([]byte(cm.Data[limitador.LimitadorConfigFileName]), &cmLimits) | ||
Expect(err).To(BeNil()) | ||
Expect(cmLimits).To(Equal(limits)) | ||
}) | ||
}) | ||
|
||
Context("Updating limitador object with new limits", func() { | ||
var limitadorObj *limitadorv1alpha1.Limitador | ||
|
||
limits := []limitadorv1alpha1.RateLimit{ | ||
{ | ||
Conditions: []string{"req.method == 'GET'"}, | ||
MaxValue: 10, | ||
Namespace: "test-namespace", | ||
Seconds: 60, | ||
Variables: []string{"user_id"}, | ||
Name: "useless", | ||
}, | ||
{ | ||
Conditions: []string{"req.method == 'POST'"}, | ||
MaxValue: 5, | ||
Namespace: "test-namespace", | ||
Seconds: 60, | ||
Variables: []string{"user_id"}, | ||
}, | ||
} | ||
|
||
BeforeEach(func() { | ||
limitadorObj = basicLimitador(testNamespace) | ||
Expect(k8sClient.Create(context.TODO(), limitadorObj)).Should(Succeed()) | ||
Eventually(testLimitadorIsReady(limitadorObj), time.Minute, 5*time.Second).Should(BeTrue()) | ||
}) | ||
|
||
It("Should modify configmap with the new limits", func() { | ||
cm := &v1.ConfigMap{} | ||
Eventually(func() bool { | ||
err := k8sClient.Get(context.TODO(), | ||
types.NamespacedName{ | ||
Namespace: testNamespace, | ||
Name: limitador.LimitsConfigMapName(limitadorObj), | ||
}, cm) | ||
|
||
return err == nil | ||
}, timeout, interval).Should(BeTrue()) | ||
|
||
var cmLimits []limitadorv1alpha1.RateLimit | ||
err := yaml.Unmarshal([]byte(cm.Data[limitador.LimitadorConfigFileName]), &cmLimits) | ||
Expect(err).To(BeNil()) | ||
Expect(cmLimits).To(BeEmpty()) | ||
|
||
updatedLimitador := limitadorv1alpha1.Limitador{} | ||
Eventually(func() bool { | ||
err := k8sClient.Get(context.TODO(), types.NamespacedName{ | ||
Namespace: testNamespace, | ||
Name: limitadorObj.Name, | ||
}, &updatedLimitador) | ||
|
||
if err != nil { | ||
return false | ||
} | ||
|
||
updatedLimitador.Spec.Limits = limits | ||
|
||
return k8sClient.Update(context.TODO(), &updatedLimitador) == nil | ||
}, timeout, interval).Should(BeTrue()) | ||
|
||
Eventually(func() bool { | ||
newCM := &v1.ConfigMap{} | ||
err := k8sClient.Get(context.TODO(), | ||
types.NamespacedName{ | ||
Namespace: testNamespace, | ||
Name: limitador.LimitsConfigMapName(limitadorObj), | ||
}, newCM) | ||
|
||
if err != nil { | ||
return false | ||
} | ||
|
||
var cmLimits []limitadorv1alpha1.RateLimit | ||
err = yaml.Unmarshal([]byte(newCM.Data[limitador.LimitadorConfigFileName]), &cmLimits) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
return reflect.DeepEqual(cmLimits, limits) | ||
}, timeout, interval).Should(BeTrue()) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.