|
5 | 5 | "fmt" |
6 | 6 | "os/exec" |
7 | 7 | "path/filepath" |
8 | | - "regexp" |
9 | | - "strconv" |
10 | 8 | "strings" |
11 | 9 | "time" |
12 | 10 |
|
@@ -1047,101 +1045,4 @@ var _ = g.Describe("[sig-operator][Jira:OLM] OLMv0 should", func() { |
1047 | 1045 | e2e.Logf("PrometheusRule validation passed: Alert rule is properly configured to monitor catalogsource_ready metric") |
1048 | 1046 | }) |
1049 | 1047 |
|
1050 | | - g.It("PolarionID:43975-[OTP]olm operator serviceaccount should not rely on external networking for health check[Disruptive][Slow]", g.Label("NonHyperShiftHOST"), func() { |
1051 | | - g.By("1) get the cluster infrastructure") |
1052 | | - infra, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("infrastructures", "cluster", "-o=jsonpath={.status.infrastructureTopology}").Output() |
1053 | | - if err != nil { |
1054 | | - e2e.Failf("Fail to get the cluster infra") |
1055 | | - } |
1056 | | - if infra != "SingleReplica" { |
1057 | | - g.Skip("Not SNO cluster - skipping test ...") |
1058 | | - } |
1059 | | - |
1060 | | - originProfile := olmv0util.GetResource(oc, exutil.AsAdmin, exutil.WithoutNamespace, "apiserver", "cluster", "-o=jsonpath={.spec.audit.profile}") |
1061 | | - o.Expect(originProfile).NotTo(o.BeEmpty()) |
1062 | | - if strings.Compare(originProfile, "Default") != 0 { |
1063 | | - g.Skip("audit profile is not Default - skipping test ...") |
1064 | | - } |
1065 | | - |
1066 | | - g.By("2) get revision number") |
1067 | | - revisionNumber1 := 0 |
1068 | | - reg := regexp.MustCompile(`at revision (\d+)`) |
1069 | | - if reg == nil { |
1070 | | - e2e.Failf("get revision number regexp err!") |
1071 | | - } |
1072 | | - output, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("kubeapiserver", "-o=jsonpath={..status.conditions[?(@.type==\"NodeInstallerProgressing\")]}").Output() |
1073 | | - if err != nil { |
1074 | | - e2e.Failf("Fail to get kubeapiserver") |
1075 | | - } |
1076 | | - result := reg.FindAllStringSubmatch(output, -1) |
1077 | | - if result != nil { |
1078 | | - revisionNumberStr1 := result[0][1] |
1079 | | - revisionNumber1, _ = strconv.Atoi(revisionNumberStr1) |
1080 | | - e2e.Logf("origin revision number is : %v", revisionNumber1) |
1081 | | - } else { |
1082 | | - e2e.Failf("Fail to get revision number") |
1083 | | - } |
1084 | | - |
1085 | | - g.By("3) Configuring the audit log policy to AllRequestBodies") |
1086 | | - defer func() { |
1087 | | - pathJSON := fmt.Sprintf("{\"spec\":{\"audit\":{\"profile\":\"%s\"}}}", originProfile) |
1088 | | - e2e.Logf("recover to be %v", pathJSON) |
1089 | | - exutil.PatchResource(oc, exutil.AsAdmin, exutil.WithoutNamespace, "apiserver", "cluster", "-p", pathJSON, "--type=merge") |
1090 | | - output = olmv0util.GetResource(oc, exutil.AsAdmin, exutil.WithoutNamespace, "apiserver", "cluster", "-o=jsonpath={.spec.audit.profile}") |
1091 | | - o.Expect(output).To(o.Equal("Default")) |
1092 | | - }() |
1093 | | - exutil.PatchResource(oc, exutil.AsAdmin, exutil.WithoutNamespace, "apiserver", "cluster", "-p", "{\"spec\":{\"audit\":{\"profile\":\"AllRequestBodies\"}}}", "--type=merge") |
1094 | | - output = olmv0util.GetResource(oc, exutil.AsAdmin, exutil.WithoutNamespace, "apiserver", "cluster", "-o=jsonpath={.spec.audit.profile}") |
1095 | | - o.Expect(output).To(o.Equal("AllRequestBodies")) |
1096 | | - |
1097 | | - g.By("4) Wait for api rollout") |
1098 | | - err = wait.PollUntilContextTimeout(context.TODO(), 30*time.Second, 600*time.Second, false, func(ctx context.Context) (bool, error) { |
1099 | | - output, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("kubeapiserver", "-o=jsonpath={..status.conditions[?(@.type==\"NodeInstallerProgressing\")]}").Output() |
1100 | | - e2e.Logf("kubeapiserver status output: %s", output) |
1101 | | - if err != nil { |
1102 | | - e2e.Logf("Fail to get kubeapiserver status, go next round") |
1103 | | - return false, nil |
1104 | | - } |
1105 | | - if !strings.Contains(output, "AllNodesAtLatestRevision") { |
1106 | | - e2e.Logf("the api is rolling, go next round") |
1107 | | - return false, nil |
1108 | | - } |
1109 | | - result := reg.FindAllStringSubmatch(output, -1) |
1110 | | - if result != nil { |
1111 | | - revisionNumberStr2 := result[0][1] |
1112 | | - revisionNumber2, _ := strconv.Atoi(revisionNumberStr2) |
1113 | | - e2e.Logf("revision number is : %v", revisionNumber2) |
1114 | | - if revisionNumber2 > revisionNumber1 { |
1115 | | - return true, nil |
1116 | | - } |
1117 | | - e2e.Logf("revision number is not changed, go next round") |
1118 | | - return false, nil |
1119 | | - |
1120 | | - } |
1121 | | - e2e.Logf("Fail to get revision number, go next round") |
1122 | | - return false, nil |
1123 | | - }) |
1124 | | - exutil.AssertWaitPollNoErr(err, "api not rollout") |
1125 | | - |
1126 | | - // According to the case steps, wait for 5 minutes, then check the audit log doesn't contain olm-operator-serviceaccount. |
1127 | | - g.By("Wait for 5 minutes, then check the audit log") |
1128 | | - time.Sleep(5 * time.Minute) |
1129 | | - |
1130 | | - g.By("check the audit log") |
1131 | | - nodeName, err := exutil.GetFirstMasterNode(oc) |
1132 | | - e2e.Logf("master node name: %s", nodeName) |
1133 | | - o.Expect(err).NotTo(o.HaveOccurred()) |
1134 | | - auditlogPath := "43975.log" |
1135 | | - defer func() { |
1136 | | - _, _ = exec.Command("bash", "-c", "rm -fr "+auditlogPath).Output() |
1137 | | - }() |
1138 | | - outputPath, err := oc.AsAdmin().WithoutNamespace().Run("adm").Args("node-logs", nodeName, "--path=kube-apiserver/audit.log").OutputToFile(auditlogPath) |
1139 | | - o.Expect(err).NotTo(o.HaveOccurred()) |
1140 | | - commandParserLog := "cat " + outputPath + " | grep -i health | grep -i subjectaccessreviews | grep -v Unhealth | jq -r '.user.username' | sort | uniq" |
1141 | | - resultParserLog, err := exec.Command("bash", "-c", commandParserLog).Output() |
1142 | | - o.Expect(err).NotTo(o.HaveOccurred()) |
1143 | | - e2e.Logf("Found usernames in audit log: %s", string(resultParserLog)) |
1144 | | - o.Expect(resultParserLog).NotTo(o.ContainSubstring("olm-operator-serviceaccount")) |
1145 | | - }) |
1146 | | - |
1147 | 1048 | }) |
0 commit comments