-
Notifications
You must be signed in to change notification settings - Fork 13
Application image test rework #225
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,11 +23,8 @@ import ( | |
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| "k8s.io/apimachinery/pkg/types" | ||
|
|
||
| webserversv1alpha1 "github.com/web-servers/jws-operator/api/v1alpha1" | ||
| "github.com/web-servers/jws-operator/test/utils" | ||
| kbappsv1 "k8s.io/api/apps/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
|
|
@@ -39,8 +36,6 @@ var _ = Describe("WebServerControllerTest", Ordered, func() { | |
| name := "image-basic-test" | ||
| appName := "test-tomcat-demo" | ||
| testURI := "/health" | ||
| image := "quay.io/web-servers/tomcat10:latest" | ||
| newImage := "quay.io/web-servers/tomcat10update:latest" | ||
|
|
||
| webserver := &webserversv1alpha1.WebServer{ | ||
| TypeMeta: metav1.TypeMeta{ | ||
|
|
@@ -55,7 +50,7 @@ var _ = Describe("WebServerControllerTest", Ordered, func() { | |
| ApplicationName: appName, | ||
| Replicas: int32(2), | ||
| WebImage: &webserversv1alpha1.WebImageSpec{ | ||
| ApplicationImage: image, | ||
| ApplicationImage: testImg, | ||
| }, | ||
| }, | ||
| } | ||
|
|
@@ -70,6 +65,8 @@ var _ = Describe("WebServerControllerTest", Ordered, func() { | |
|
|
||
| Context("ApplicationImageTest", func() { | ||
| It("Basic Test", func() { | ||
| // Checks if Web Server was deployed with the PREVIOUS version of the image | ||
| waitForPodsActiveState(name) | ||
| _, err := utils.WebServerRouteTest(k8sClient, ctx, thetest, webserver, testURI, false, nil, false) | ||
| Expect(err).Should(Succeed()) | ||
| }) | ||
|
|
@@ -80,7 +77,7 @@ var _ = Describe("WebServerControllerTest", Ordered, func() { | |
| // Update WebImage and update WebServer | ||
| Eventually(func() bool { | ||
| createdWebserver = getWebServer(name) | ||
| createdWebserver.Spec.WebImage.ApplicationImage = newImage | ||
| createdWebserver.Spec.WebImage.ApplicationImage = testImgUpdate | ||
|
|
||
| err := k8sClient.Update(ctx, createdWebserver) | ||
| if err != nil { | ||
|
|
@@ -91,24 +88,10 @@ var _ = Describe("WebServerControllerTest", Ordered, func() { | |
| return true | ||
| }, time.Second*30, time.Millisecond*250).Should(BeTrue()) | ||
|
|
||
| foundDeployment := &kbappsv1.Deployment{} | ||
|
|
||
| // Wait until the replicas are available | ||
| Eventually(func() bool { | ||
| err := k8sClient.Get(ctx, types.NamespacedName{Name: appName, Namespace: namespace}, foundDeployment) | ||
| if err != nil { | ||
| thetest.Fatalf("can't read Deployment") | ||
| return false | ||
| } | ||
|
|
||
| foundImage := foundDeployment.Spec.Template.Spec.Containers[0].Image | ||
| if foundImage != newImage { | ||
| return false | ||
| } | ||
|
|
||
| return createdWebserver.Spec.Replicas == foundDeployment.Status.AvailableReplicas | ||
| }, time.Second*420, time.Second*30).Should(BeTrue(), "Image Update Test: Required amount of replicas with updated image were not achieved") | ||
| waitForPodsActiveState(name) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the difference between this check and check on the line 111? |
||
| isApplicationImageWasUpdated(createdWebserver, testImg) | ||
|
|
||
| // Checks if Web Server was deployed with the NEW version of the image | ||
| _, err := utils.WebServerRouteTest(k8sClient, ctx, thetest, webserver, testURI, false, nil, false) | ||
| Expect(err).Should(Succeed()) | ||
| }) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import ( | |
| . "github.com/onsi/gomega" | ||
| imagev1 "github.com/openshift/api/image/v1" | ||
| webserversv1alpha1 "github.com/web-servers/jws-operator/api/v1alpha1" | ||
| kbappsv1 "k8s.io/api/apps/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| "k8s.io/apimachinery/pkg/types" | ||
|
|
@@ -214,7 +215,7 @@ func checkOperatorLogs() { | |
| fmt.Println(">>>> Pod's log <<<<") | ||
| fmt.Println(buffer.String()) | ||
| fmt.Println(">>>> Pod's log <<<<") | ||
| Expect(true).Should(BeFalse()) | ||
| Expect(true).Should(BeFalse(), "The operator logs should not contain an error massage") | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -370,3 +371,48 @@ func waitForBuildPodsToSucceed() { | |
| return true | ||
| }, time.Minute*5, time.Second*5).Should(BeTrue(), "Building pods took too long time.") | ||
| } | ||
|
|
||
| func waitForPodsActiveState(webserverName string) { | ||
| foundDeployment := &kbappsv1.Deployment{} | ||
|
|
||
| Eventually(func() bool { | ||
| createdWebserver := getWebServer(webserverName) | ||
| webserverNamespacedName := types.NamespacedName{Name: webserverName, Namespace: createdWebserver.ObjectMeta.Namespace} | ||
|
|
||
| err := k8sClient.Get(ctx, webserverNamespacedName, foundDeployment) | ||
|
|
||
| if err != nil { | ||
| thetest.Fatalf("can't read Deployment") | ||
| return false | ||
| } | ||
|
|
||
| // Checks pods state in the operator | ||
| if int(createdWebserver.Spec.Replicas) != len(createdWebserver.Status.Pods) { | ||
| return false | ||
| } | ||
| for _, pod := range createdWebserver.Status.Pods { | ||
| if pod.State != webserversv1alpha1.PodStateActive { | ||
| fmt.Printf("Pod %s is in state %s\n", pod.Name, pod.State) | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| // Checks pods state in the cluster | ||
| return createdWebserver.Spec.Replicas == foundDeployment.Status.AvailableReplicas | ||
|
Comment on lines
+390
to
+401
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the check against Deployment.Status.AvailableReplicas sufficient? Why is it important to check pods from operator status and their state? |
||
| }, time.Second*420, time.Second*30).Should(BeTrue(), "Image Update Test: Required amount of replicas with updated image were not achieved") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function is in testHelper hence it is expected that multiple tests will use ti. Hence in the log message there should not be a name of one particular tests. |
||
| } | ||
|
|
||
| func isApplicationImageWasUpdated(createdWebserver *webserversv1alpha1.WebServer, oldImage string) bool { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| foundDeployment := &kbappsv1.Deployment{} | ||
| webserverNamespacedName := types.NamespacedName{Name: createdWebserver.Name, Namespace: createdWebserver.Namespace} | ||
|
|
||
| err := k8sClient.Get(ctx, webserverNamespacedName, foundDeployment) | ||
|
|
||
| if err != nil { | ||
| thetest.Fatalf("can't read Deployment") | ||
| return false | ||
| } | ||
|
|
||
| foundImage := foundDeployment.Spec.Template.Spec.Containers[0].Image | ||
| return foundImage != oldImage | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.