Skip to content

Commit 6e22e2b

Browse files
authored
Use old and new pod selectors during kustomize-to-helm transition (#2214)
Downstream e2es are failing because the old selectors are still being used.
1 parent febdb59 commit 6e22e2b

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

test/e2e/metrics_test.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
func TestOperatorControllerMetricsExportedEndpoint(t *testing.T) {
3333
client := utils.FindK8sClient(t)
3434
curlNamespace := createRandomNamespace(t, client)
35-
componentNamespace := getComponentNamespace(t, client, "app.kubernetes.io/name=operator-controller")
35+
componentNamespace := getComponentNamespace(t, client, operatorManagerSelector)
3636
metricsURL := fmt.Sprintf("https://operator-controller-service.%s.svc.cluster.local:8443/metrics", componentNamespace)
3737

3838
config := NewMetricsTestConfig(
@@ -52,7 +52,7 @@ func TestOperatorControllerMetricsExportedEndpoint(t *testing.T) {
5252
func TestCatalogdMetricsExportedEndpoint(t *testing.T) {
5353
client := utils.FindK8sClient(t)
5454
curlNamespace := createRandomNamespace(t, client)
55-
componentNamespace := getComponentNamespace(t, client, "app.kubernetes.io/name=catalogd")
55+
componentNamespace := getComponentNamespace(t, client, catalogdManagerSelector)
5656
metricsURL := fmt.Sprintf("https://catalogd-service.%s.svc.cluster.local:7443/metrics", componentNamespace)
5757

5858
config := NewMetricsTestConfig(
@@ -231,16 +231,20 @@ func createRandomNamespace(t *testing.T, client string) string {
231231
}
232232

233233
// getComponentNamespace returns the namespace where operator-controller or catalogd is running
234-
func getComponentNamespace(t *testing.T, client, selector string) string {
235-
cmd := exec.Command(client, "get", "pods", "--all-namespaces", "--selector="+selector, "--output=jsonpath={.items[0].metadata.namespace}")
236-
output, err := cmd.CombinedOutput()
237-
require.NoError(t, err, "Error determining namespace: %s", string(output))
238-
239-
namespace := string(bytes.TrimSpace(output))
240-
if namespace == "" {
241-
t.Fatal("No namespace found for selector " + selector)
234+
func getComponentNamespace(t *testing.T, client string, selectors []string) string {
235+
for _, selector := range selectors {
236+
cmd := exec.Command(client, "get", "pods", "--all-namespaces", "--selector="+selector, "--output=jsonpath={.items[0].metadata.namespace}")
237+
output, err := cmd.CombinedOutput()
238+
if err != nil {
239+
continue
240+
}
241+
namespace := string(bytes.TrimSpace(output))
242+
if namespace != "" {
243+
return namespace
244+
}
242245
}
243-
return namespace
246+
t.Fatalf("No namespace found for selectors: %v", selectors)
247+
return ""
244248
}
245249

246250
func stdoutAndCombined(cmd *exec.Cmd) ([]byte, []byte, error) {

test/e2e/network_policy_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ import (
2020

2121
const (
2222
minJustificationLength = 40
23-
catalogdManagerSelector = "app.kubernetes.io/name=catalogd"
24-
operatorManagerSelector = "app.kubernetes.io/name=operator-controller"
2523
catalogdMetricsPort = 7443
2624
catalogdWebhookPort = 9443
2725
catalogServerPort = 8443
2826
operatorControllerMetricsPort = 8443
2927
)
3028

29+
var (
30+
catalogdManagerSelector = []string{"app.kubernetes.io/name=catalogd", "control-plane=catalogd-controller-manager"}
31+
operatorManagerSelector = []string{"app.kubernetes.io/name=operator-controller", "control-plane=operator-controller-controller-manager"}
32+
)
33+
3134
type portWithJustification struct {
3235
port []networkingv1.NetworkPolicyPort
3336
justification string

0 commit comments

Comments
 (0)