Skip to content

Commit 5ca0da6

Browse files
pierDipiknative-prow-robot
authored andcommitted
Add e2e test
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
1 parent 9aaacc7 commit 5ca0da6

6 files changed

Lines changed: 94 additions & 4 deletions

File tree

pkg/reconciler/common/transformers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func InjectNamespace(manifest *mf.Manifest, instance base.KComponent, extra ...m
8484
return nil
8585
}
8686

87+
// InjectLabel adds the given key and value as label.
8788
func InjectLabel(key, value string) mf.Transformer {
8889
return func(u *unstructured.Unstructured) error {
8990
curr := u.GetLabels()

pkg/reconciler/knativeeventing/controller.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ import (
3737
)
3838

3939
const (
40-
SelectorKey = "app.kubernetes.io/name"
40+
// SelectorKey is the key of the selector for the KnativeEventing resources.
41+
SelectorKey = "app.kubernetes.io/name"
42+
// SelectorValue is the value of the selector for the KnativeEventing resources.
4143
SelectorValue = "knative-eventing"
42-
Selector = SelectorKey + "=" + SelectorValue
44+
// Selector is the selector for the KnativeEventing resources.
45+
Selector = SelectorKey + "=" + SelectorValue
4346
)
4447

4548
// NewController initializes the controller and is called by the generated code

pkg/reconciler/knativeserving/controller.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl
4343
}
4444

4545
const (
46-
SelectorKey = "app.kubernetes.io/name"
46+
// SelectorKey is the key of the selector for the KnativeServing resources.
47+
SelectorKey = "app.kubernetes.io/name"
48+
// SelectorValue is the value of the selector for the KnativeServing resources.
4749
SelectorValue = "knative-serving"
48-
Selector = SelectorKey + "=" + SelectorValue
50+
// Selector is the selector for the KnativeServing resources.
51+
Selector = SelectorKey + "=" + SelectorValue
4952
)
5053

5154
// NewExtendedController returns a controller extended to a specific platform

test/e2e/knativeeventingdeployment_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func TestKnativeEventingDeployment(t *testing.T) {
5353
t.Run("restore", func(t *testing.T) {
5454
resources.AssertKEOperatorCRReadyStatus(t, clients, names)
5555
resources.DeleteAndVerifyEventingDeployments(t, clients, names)
56+
resources.DeleteAndVerifyEventingConfigMaps(t, clients, names)
5657
})
5758

5859
// Delete the KnativeEventing to see if all resources will be removed

test/e2e/knativeservingdeployment_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func TestKnativeServingDeployment(t *testing.T) {
5858
t.Run("restore", func(t *testing.T) {
5959
resources.AssertKSOperatorCRReadyStatus(t, clients, names)
6060
resources.DeleteAndVerifyDeployments(t, clients, names)
61+
resources.DeleteAndVerifyConfigMaps(t, clients, names)
6162
})
6263

6364
// Delete the KnativeServing to see if all resources will be removed

test/resources/verify.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,47 @@ func DeleteAndVerifyDeployments(t *testing.T, clients *test.Clients, names test.
211211
t.Logf("The deployment %s/%s reached the desired state.", deployment.Namespace, deployment.Name)
212212
}
213213

214+
// DeleteAndVerifyConfigMaps verify whether all the ConfigMaps for knative serving are able to recreate, when they are deleted.
215+
func DeleteAndVerifyConfigMaps(t *testing.T, clients *test.Clients, names test.ResourceNames) {
216+
cmList, err := clients.KubeClient.CoreV1().ConfigMaps(names.Namespace).List(context.TODO(), metav1.ListOptions{})
217+
if err != nil {
218+
t.Fatalf("Failed to get any ConfigMap under the namespace %q: %v",
219+
test.ServingOperatorNamespace, err)
220+
}
221+
if len(cmList.Items) == 0 {
222+
t.Fatalf("No ConfigMap under the namespace %q was found",
223+
test.ServingOperatorNamespace)
224+
}
225+
// Delete the first ConfigMap and verify the operator recreates it
226+
configMap := cmList.Items[0]
227+
if err := clients.KubeClient.CoreV1().ConfigMaps(configMap.Namespace).Delete(context.TODO(), configMap.Name, metav1.DeleteOptions{}); err != nil {
228+
t.Fatalf("Failed to delete ConfigMap %s/%s: %v", configMap.Namespace, configMap.Name, err)
229+
}
230+
231+
waitErr := wait.PollUntilContextTimeout(context.TODO(), Interval, Timeout, true, func(context.Context) (bool, error) {
232+
_, err := clients.KubeClient.CoreV1().ConfigMaps(configMap.Namespace).Get(context.TODO(), configMap.Name, metav1.GetOptions{})
233+
if err != nil {
234+
// If the ConfigMap is not found, we continue to wait for the availability.
235+
if apierrs.IsNotFound(err) {
236+
return false, nil
237+
}
238+
return false, err
239+
}
240+
// For ConfigMaps, we consider it recreated as soon as it reappears.
241+
return true, nil
242+
})
243+
244+
if waitErr != nil {
245+
t.Fatalf("The ConfigMap %s/%s failed to be recreated: %v", configMap.Namespace, configMap.Name, err)
246+
}
247+
248+
if _, err := WaitForKnativeServingState(clients.KnativeServing(), test.OperatorName,
249+
IsKnativeServingReady); err != nil {
250+
t.Fatalf("KnativeService %q failed to reach the desired state: %v", test.OperatorName, err)
251+
}
252+
t.Logf("The ConfigMap %s/%s was successfully recreated.", configMap.Namespace, configMap.Name)
253+
}
254+
214255
// KSOperatorCRDelete deletes tha KnativeServing to see if all resources will be deleted
215256
func KSOperatorCRDelete(t *testing.T, clients *test.Clients, names test.ResourceNames) {
216257
if err := clients.KnativeServing().Delete(context.TODO(), names.KnativeServing, metav1.DeleteOptions{}); err != nil {
@@ -399,6 +440,46 @@ func DeleteAndVerifyEventingDeployments(t *testing.T, clients *test.Clients, nam
399440
t.Logf("The deployment %s/%s reached the desired state.", deployment.Namespace, deployment.Name)
400441
}
401442

443+
// DeleteAndVerifyEventingConfigMaps verify whether all the ConfigMaps for knative eventing are able to recreate, when they are deleted.
444+
func DeleteAndVerifyEventingConfigMaps(t *testing.T, clients *test.Clients, names test.ResourceNames) {
445+
cmList, err := clients.KubeClient.CoreV1().ConfigMaps(names.Namespace).List(context.TODO(), metav1.ListOptions{})
446+
if err != nil {
447+
t.Fatalf("Failed to get any ConfigMap under the namespace %q: %v",
448+
test.EventingOperatorNamespace, err)
449+
}
450+
if len(cmList.Items) == 0 {
451+
t.Fatalf("No ConfigMap under the namespace %q was found",
452+
test.EventingOperatorNamespace)
453+
}
454+
// Delete the first ConfigMap and verify the operator recreates it
455+
configMap := cmList.Items[0]
456+
if err := clients.KubeClient.CoreV1().ConfigMaps(configMap.Namespace).Delete(context.TODO(), configMap.Name, metav1.DeleteOptions{}); err != nil {
457+
t.Fatalf("Failed to delete ConfigMap %s/%s: %v", configMap.Namespace, configMap.Name, err)
458+
}
459+
460+
waitErr := wait.PollUntilContextTimeout(context.TODO(), Interval, Timeout, true, func(context.Context) (bool, error) {
461+
_, err := clients.KubeClient.CoreV1().ConfigMaps(configMap.Namespace).Get(context.TODO(), configMap.Name, metav1.GetOptions{})
462+
if err != nil {
463+
// If the ConfigMap is not found, we continue to wait for the availability.
464+
if apierrs.IsNotFound(err) {
465+
return false, nil
466+
}
467+
return false, err
468+
}
469+
return true, nil
470+
})
471+
472+
if waitErr != nil {
473+
t.Fatalf("The ConfigMap %s/%s failed to reach the desired state: %v", configMap.Namespace, configMap.Name, err)
474+
}
475+
476+
if _, err := WaitForKnativeEventingState(clients.KnativeEventing(), test.OperatorName,
477+
IsKnativeEventingReady); err != nil {
478+
t.Fatalf("KnativeService %q failed to reach the desired state: %v", test.OperatorName, err)
479+
}
480+
t.Logf("The ConfigMap %s/%s reached the desired state.", configMap.Namespace, configMap.Name)
481+
}
482+
402483
// KEOperatorCRDelete deletes tha KnativeEventing to see if all resources will be deleted
403484
func KEOperatorCRDelete(t *testing.T, clients *test.Clients, names test.ResourceNames) {
404485
if err := clients.KnativeEventing().Delete(context.TODO(), names.KnativeEventing, metav1.DeleteOptions{}); err != nil {

0 commit comments

Comments
 (0)