Skip to content

Commit 94bbe75

Browse files
committed
Update
1 parent e3a1110 commit 94bbe75

9 files changed

Lines changed: 100 additions & 13 deletions

test/helper/application_status.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ func DeleteNamespace(k8sClient client.Client, nsToDelete string) error {
173173
GinkgoT().Errorf("Unable to list ArgoCDs %v", err)
174174
// Report failure, but still continue
175175
}
176-
for _, item := range list.Items {
176+
for idx := range list.Items {
177+
item := list.Items[idx]
177178

178179
if len(item.Finalizers) == 0 {
179180
continue

test/openshift/e2e/ginkgo/fixture/fixture.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/argocd"
2929
deploymentFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/deployment"
3030
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s"
31+
osFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/os"
3132
subscriptionFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/subscription"
3233
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils"
3334
appsv1 "k8s.io/api/apps/v1"
@@ -785,3 +786,61 @@ func updateWithoutConflict(obj client.Object, modify func(client.Object)) error
785786

786787
return err
787788
}
789+
790+
// DebugOutputOperatorLogs can be used to debug a failing test: it will output the operator logs
791+
func DebugOutputOperatorLogs() {
792+
793+
k8sClient, _, err := utils.GetE2ETestKubeClientWithError()
794+
if err != nil {
795+
GinkgoWriter.Println(err)
796+
return
797+
}
798+
799+
// List all pods on the cluster
800+
var podList corev1.PodList
801+
if err := k8sClient.List(context.Background(), &podList); err != nil {
802+
GinkgoWriter.Println(err)
803+
return
804+
}
805+
806+
// Look specifically for operator pod
807+
matchingPods := []corev1.Pod{}
808+
for idx := range podList.Items {
809+
pod := podList.Items[idx]
810+
if strings.Contains(pod.Name, "openshift-gitops-operator-controller-manager") {
811+
matchingPods = append(matchingPods, pod)
812+
}
813+
}
814+
815+
if len(matchingPods) == 0 {
816+
// This can happen when the operator is not running on the cluster
817+
GinkgoWriter.Println("DebugOutputOperatorLogs was called, but no pods were found.")
818+
return
819+
}
820+
821+
if len(matchingPods) != 1 {
822+
GinkgoWriter.Println("unexpected number of operator pods", matchingPods)
823+
return
824+
}
825+
826+
// Extract operator logs
827+
kubectlLogOutput, err := osFixture.ExecCommandWithOutputParam(false, "kubectl", "logs", "pod/"+matchingPods[0].Name, "manager", "-n", matchingPods[0].Namespace)
828+
if err != nil {
829+
GinkgoWriter.Println("unable to extract operator logs", err)
830+
return
831+
}
832+
833+
// Output only the last 1000 lines
834+
lines := strings.Split(kubectlLogOutput, "\n")
835+
836+
count := 0
837+
output := []string{}
838+
for x := len(lines) - 1; x >= 0 && count < 1000; x-- {
839+
output = append(lines[x:x+1], output...)
840+
count++
841+
}
842+
843+
GinkgoWriter.Println("Log output from operator pod:")
844+
GinkgoWriter.Println(output)
845+
846+
}

test/openshift/e2e/ginkgo/fixture/os/fixture.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ func ExecCommandWithOutputParam(printOutput bool, cmdArgs ...string) (string, er
1616

1717
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
1818

19-
output, err := cmd.CombinedOutput()
19+
outputBytes, err := cmd.CombinedOutput()
20+
21+
var output string
22+
if outputBytes != nil {
23+
output = string(outputBytes)
24+
}
25+
2026
if printOutput {
21-
GinkgoWriter.Println(string(output))
27+
GinkgoWriter.Println(output)
2228
}
2329

24-
return string(output), err
30+
return output, err
2531
}

test/openshift/e2e/ginkgo/parallel/1-004_beta_to_alpha_conversion_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
119119
Expect(k8sClient.Delete(ctx, argoCDAlpha1)).To(Succeed())
120120

121121
By("verifying ArgoCD CR no long exists via v1alpha1 API")
122-
Expect(argoCDAlpha1).To(k8sFixture.NotExistByName())
122+
Eventually(argoCDAlpha1).Should(k8sFixture.NotExistByName())
123123

124124
By("verifying ArgoCD CR no long exists via v1beta1 API")
125125
Expect(argoCDBeta1).To(k8sFixture.NotExistByName())
126126

127127
By("verifying dex deployment is deleted as well")
128-
Eventually(dexDeployment).ShouldNot(k8sFixture.ExistByName())
128+
Eventually(dexDeployment).Should(k8sFixture.NotExistByName())
129129

130130
})
131131

test/openshift/e2e/ginkgo/parallel/1-073_validate_rhsso_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,16 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
221221
Expect(findLineInOutput("rootca", oidcConfigContents)).Should(Equal("'---BEGIN---END---'"))
222222

223223
By("extracting the access token for keycloak, to allow us to issue API commands")
224-
output, err := osFixture.ExecCommandWithOutputParam(false, "curl", "-d", "client_id=admin-cli", "-d", "username="+string(keycloakSecret.Data["SSO_USERNAME"]), "-d", "password="+string(keycloakSecret.Data["SSO_PASSWORD"]), "-d", "grant_type=password", "https://"+keycloakRouteHost+"/auth/realms/master/protocol/openid-connect/token", "-k")
224+
225+
ssoUsername, exists := keycloakSecret.Data["SSO_USERNAME"]
226+
Expect(exists).To(BeTrue())
227+
Expect(ssoUsername).ToNot(BeNil())
228+
229+
ssoPassword, exists := keycloakSecret.Data["SSO_PASSWORD"]
230+
Expect(exists).To(BeTrue())
231+
Expect(ssoPassword).ToNot(BeNil())
232+
233+
output, err := osFixture.ExecCommandWithOutputParam(false, "curl", "-d", "client_id=admin-cli", "-d", "username="+string(ssoUsername), "-d", "password="+string(ssoPassword), "-d", "grant_type=password", "https://"+keycloakRouteHost+"/auth/realms/master/protocol/openid-connect/token", "-k")
225234
Expect(err).ToNot(HaveOccurred())
226235

227236
// Extract the JSON part of the output
@@ -230,7 +239,8 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
230239
var jsonData map[string]any
231240
Expect(json.Unmarshal([]byte(output), &jsonData)).ToNot(HaveOccurred())
232241

233-
accessToken := jsonData["access_token"].(string)
242+
accessToken, success := jsonData["access_token"].(string)
243+
Expect(success).To(BeTrue())
234244

235245
By("executing the CURL command to verify the realm and client creation")
236246

test/openshift/e2e/ginkgo/parallel/1-083_validate_resource_customization_subkeys_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ spec:
165165
help.chatUrl: ""
166166
kustomize.buildOptions: ""
167167
oidc.config: ""
168-
repositories: ""
169-
repository.credentials: ""
168+
# repositories: ""
169+
# repository.credentials: ""
170170
resource.customizations.actions.apps_Deployment: |
171171
discovery.lua: |
172172
actions = {}

test/openshift/e2e/ginkgo/parallel/1-090_validate_permissions_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
4949

5050
It("ensure the GitOps Operator CSV has the correct cluster permissions and gitopsservices CRD has expected properties", func() {
5151

52+
if fixture.EnvCI() {
53+
Skip("AFAICT CSV does not exist when running E2E tests from gitops-operator repo")
54+
return
55+
}
56+
5257
if fixture.EnvLocalRun() || fixture.EnvNonOLM() {
5358
Skip("CSV does not exist in the local run or non-OLM case, so we skip")
5459
return
@@ -711,7 +716,7 @@ spec:
711716
}
712717
}
713718
By("if more than one possible CSV is found, we will fail.")
714-
Expect(gitopsCSVsFound).To(HaveLen(1), fmt.Sprintf("multiple CSVs were found: %v", gitopsCSVsFound))
719+
Expect(gitopsCSVsFound).To(HaveLen(1), fmt.Sprintf("Exactly one CSV should found: %v", gitopsCSVsFound))
715720

716721
actualCsv := &olmv1alpha1.ClusterServiceVersion{
717722
ObjectMeta: metav1.ObjectMeta{

test/openshift/e2e/ginkgo/sequential/1-036_validate_role_rolebinding_for_source_namespace_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
3333
ctx = context.Background()
3434
})
3535

36+
AfterEach(func() {
37+
if CurrentSpecReport().Failed() {
38+
fixture.DebugOutputOperatorLogs()
39+
}
40+
})
41+
3642
It("verifies that ArgoCD CR '.spec.sourceNamespaces' field wildcard-matching matches and manages only namespaces which match the wildcard", func() {
3743

3844
By("creating test NS")

test/openshift/e2e/ginkgo/parallel/1-102_validate_handle_terminating_namespaces_test.go renamed to test/openshift/e2e/ginkgo/sequential/1-102_validate_handle_terminating_namespaces_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package parallel
17+
package sequential
1818

1919
import (
2020
"context"
@@ -46,7 +46,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
4646
)
4747

4848
BeforeEach(func() {
49-
fixture.EnsureParallelCleanSlate()
49+
fixture.EnsureSequentialCleanSlate()
5050

5151
k8sClient, _ = fixtureUtils.GetE2ETestKubeClient()
5252
ctx = context.Background()

0 commit comments

Comments
 (0)