Skip to content

Commit e0a2e17

Browse files
authored
Use control-plane selectors in network-policies and tests for now (#2218)
Until downstream is ready to use the "app.kubernetes.io/name" selector, continue to use the "control-plane" selector in the tests. Change the network-policies to use a "control-plane" selector (which is still on pods because the Deployment selector is immutable). This includes a revert of "Use old and new pod selectors during kustomize-to-helm transition" This reverts #2214 This reverts commit 6e22e2b.
1 parent ed3bdcf commit e0a2e17

8 files changed

+25
-32
lines changed

helm/olmv1/templates/networkpolicy/networkpolicy-olmv1-system-catalogd-controller-manager.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ spec:
2222
protocol: TCP
2323
podSelector:
2424
matchLabels:
25-
app.kubernetes.io/name: catalogd
25+
control-plane: catalogd-controller-manager
2626
policyTypes:
2727
- Ingress
2828
- Egress

helm/olmv1/templates/networkpolicy/networkpolicy-olmv1-system-operator-controller-controller-manager.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ spec:
1818
protocol: TCP
1919
podSelector:
2020
matchLabels:
21-
app.kubernetes.io/name: operator-controller
21+
control-plane: operator-controller-controller-manager
2222
policyTypes:
2323
- Ingress
2424
- Egress

manifests/experimental-e2e.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ spec:
4040
protocol: TCP
4141
podSelector:
4242
matchLabels:
43-
app.kubernetes.io/name: catalogd
43+
control-plane: catalogd-controller-manager
4444
policyTypes:
4545
- Ingress
4646
- Egress
@@ -82,7 +82,7 @@ spec:
8282
protocol: TCP
8383
podSelector:
8484
matchLabels:
85-
app.kubernetes.io/name: operator-controller
85+
control-plane: operator-controller-controller-manager
8686
policyTypes:
8787
- Ingress
8888
- Egress

manifests/experimental.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ spec:
4040
protocol: TCP
4141
podSelector:
4242
matchLabels:
43-
app.kubernetes.io/name: catalogd
43+
control-plane: catalogd-controller-manager
4444
policyTypes:
4545
- Ingress
4646
- Egress
@@ -82,7 +82,7 @@ spec:
8282
protocol: TCP
8383
podSelector:
8484
matchLabels:
85-
app.kubernetes.io/name: operator-controller
85+
control-plane: operator-controller-controller-manager
8686
policyTypes:
8787
- Ingress
8888
- Egress

manifests/standard-e2e.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ spec:
4040
protocol: TCP
4141
podSelector:
4242
matchLabels:
43-
app.kubernetes.io/name: catalogd
43+
control-plane: catalogd-controller-manager
4444
policyTypes:
4545
- Ingress
4646
- Egress
@@ -82,7 +82,7 @@ spec:
8282
protocol: TCP
8383
podSelector:
8484
matchLabels:
85-
app.kubernetes.io/name: operator-controller
85+
control-plane: operator-controller-controller-manager
8686
policyTypes:
8787
- Ingress
8888
- Egress

manifests/standard.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ spec:
4040
protocol: TCP
4141
podSelector:
4242
matchLabels:
43-
app.kubernetes.io/name: catalogd
43+
control-plane: catalogd-controller-manager
4444
policyTypes:
4545
- Ingress
4646
- Egress
@@ -82,7 +82,7 @@ spec:
8282
protocol: TCP
8383
podSelector:
8484
matchLabels:
85-
app.kubernetes.io/name: operator-controller
85+
control-plane: operator-controller-controller-manager
8686
policyTypes:
8787
- Ingress
8888
- Egress

test/e2e/metrics_test.go

Lines changed: 11 additions & 15 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, operatorManagerSelector)
35+
componentNamespace := getComponentNamespace(t, client, "control-plane=operator-controller-controller-manager")
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, catalogdManagerSelector)
55+
componentNamespace := getComponentNamespace(t, client, "control-plane=catalogd-controller-manager")
5656
metricsURL := fmt.Sprintf("https://catalogd-service.%s.svc.cluster.local:7443/metrics", componentNamespace)
5757

5858
config := NewMetricsTestConfig(
@@ -231,20 +231,16 @@ 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 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-
}
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)
245242
}
246-
t.Fatalf("No namespace found for selectors: %v", selectors)
247-
return ""
243+
return namespace
248244
}
249245

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

test/e2e/network_policy_test.go

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

2121
const (
2222
minJustificationLength = 40
23+
catalogdManagerSelector = "control-plane=catalogd-controller-manager"
24+
operatorManagerSelector = "control-plane=operator-controller-controller-manager"
2325
catalogdMetricsPort = 7443
2426
catalogdWebhookPort = 9443
2527
catalogServerPort = 8443
2628
operatorControllerMetricsPort = 8443
2729
)
2830

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-
3431
type portWithJustification struct {
3532
port []networkingv1.NetworkPolicyPort
3633
justification string
@@ -91,7 +88,7 @@ var prometheuSpec = allowedPolicyDefinition{
9188
// Ref: https://docs.google.com/document/d/1bHEEWzA65u-kjJFQRUY1iBuMIIM1HbPy4MeDLX4NI3o/edit?usp=sharing
9289
var allowedNetworkPolicies = map[string]allowedPolicyDefinition{
9390
"catalogd-controller-manager": {
94-
selector: metav1.LabelSelector{MatchLabels: map[string]string{"app.kubernetes.io/name": "catalogd"}},
91+
selector: metav1.LabelSelector{MatchLabels: map[string]string{"control-plane": "catalogd-controller-manager"}},
9592
policyTypes: []networkingv1.PolicyType{networkingv1.PolicyTypeIngress, networkingv1.PolicyTypeEgress},
9693
ingressRule: ingressRule{
9794
ports: []portWithJustification{
@@ -119,7 +116,7 @@ var allowedNetworkPolicies = map[string]allowedPolicyDefinition{
119116
},
120117
},
121118
"operator-controller-controller-manager": {
122-
selector: metav1.LabelSelector{MatchLabels: map[string]string{"app.kubernetes.io/name": "operator-controller"}},
119+
selector: metav1.LabelSelector{MatchLabels: map[string]string{"control-plane": "operator-controller-controller-manager"}},
123120
policyTypes: []networkingv1.PolicyType{networkingv1.PolicyTypeIngress, networkingv1.PolicyTypeEgress},
124121
ingressRule: ingressRule{
125122
ports: []portWithJustification{

0 commit comments

Comments
 (0)