Skip to content

Cannot add custom network policies to Calico components #4772

@sebhoss

Description

@sebhoss

We just updated to the latest version of the operator (1.42) and the latest version of calico (3.32 OSS). 2 things broke for us:

  1. Prometheus can no longer scrape metrics from the calico-kube-controllers pods (but felix/typha seem to work fine)
  2. Whisker can no longer be reached through our Ingress

Since both endpoints are still working fine when using kubectl port-forward, we noticed #4438 which talks about adjusting network policies, but does not go into detail how we are supposed to adjust network policies.

What we had before was something like this:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: whisker-ingress
  namespace: calico-system
spec:
  ingress:
    - from:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: ingress-nginx
          podSelector:
            matchLabels:
              app.kubernetes.io/name: ingress-nginx
              app.kubernetes.io/instance: ingress-nginx
              app.kubernetes.io/component: controller
      ports:
        - port: 8081
          protocol: TCP
  podSelector:
    matchLabels:
      app.kubernetes.io/name: whisker
  policyTypes:
    - Ingress

I've tried converting that to a CNP like this:

apiVersion: projectcalico.org/v3
kind: NetworkPolicy
metadata:
  name: whisker-ingress
  namespace: calico-system
spec:
  ingress:
    - action: Allow
      protocol: TCP
      source:
        namespaceSelector: kubernetes.io/metadata.name == 'ingress-nginx'
        selector: app.kubernetes.io/name == 'ingress-nginx' && app.kubernetes.io/instance == 'ingress-nginx' && app.kubernetes.io/component == 'controller'
      destination:
        ports:
          - 8081
  selector: k8s-app == 'whisker'
  tier: calico-system
  types:
    - Ingress

However, it is not possible to apply this network policy because the API server rejects it with Error from server (NotFound): networkpolicies.projectcalico.org "whisker-ingress" not found. Likewise changing the name of the policy to calico-system.whisker-ingress or removing the spec.tier field entirely results in the same error message. We can apply CNPs in other namespaces without problem, but it seems something is rejecting our creation of new network policies in the calico-system namespace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions