Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The labels in Rollouts spec.selector.matchLabels doesn't works #5295

Closed
felixrb86 opened this issue Aug 25, 2023 · 5 comments
Closed

The labels in Rollouts spec.selector.matchLabels doesn't works #5295

felixrb86 opened this issue Aug 25, 2023 · 5 comments
Labels
kind/support Categorizes issue or PR as a support question. triage/resolved Indicates an issue has been resolved or doesn't need to be resolved.

Comments

@felixrb86
Copy link

felixrb86 commented Aug 25, 2023

What happened?

I need to apply the
commonLabels in spec.selector.matchLabels in the Rollouts file.

What did you expect to happen?

It have to add the matchLabels in both files (deployment.yml and rollout.yml)

How can we reproduce it (as minimally and precisely as possible)?

# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../test-base

labels:
  - pairs:
      some-label: NEW-LABEL
    includeSelectors: true
    includeTemplates: true
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kubernetes.io/change-cause: "Deploy en pxt-qa 1.0"
  name: DEPLOYMENT_NAME
  namespace: pxt-qa
spec:
  revisionHistoryLimit: 5
  replicas: 0
  template:
    metadata:
      labels:
        some-label: value-of-label
    spec:
      containers:
        - name: CONTAINER_NAME
          image: IMAGE_NAME
          ports:
            - containerPort: 8080
          resources:
            limits:
              memory: "2000Mi"
              cpu: "1"
            requests:
              memory: "51Mi"
              cpu: "0.01"
          env:
            - name: MY_POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
# rollout.yaml
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: ROLLOUT_NAME
  namespace: pxt-qa
spec:
  revisionHistoryLimit: 5
  workloadRef: 
    apiVersion: apps/v1
    kind: Deployment
    name: DEPLOYMENT_NAME
  strategy:
    canary:
      stableMetadata:
        labels:
          role: current
      canaryMetadata:
        labels:
          role: new
      maxUnavailable: 0
      canaryService: canaryService-name
      stableService: stableService-name
      trafficRouting:
       istio:
         virtualService:
           name: stableService-name
           routes:
           - primary
      steps:
      - setWeight: 100

Expected output

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kubernetes.io/change-cause: Deploy en pxt-qa 1.0
  labels:
    new-label: NEW-LABEL
  name: DEPLOYMENT_NAME
  namespace: pxt-qa
spec:
  replicas: 0
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      new-label: NEW-LABEL
  template:
    metadata:
      labels:
        new-label: NEW-LABEL
        some-label: value-of-label
    spec:
      containers:
      - env:
        - name: MY_POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        image: IMAGE_NAME
        name: CONTAINER_NAME
        ports:
        - containerPort: 8080
        resources:
          limits:
            cpu: "1"
            memory: 2000Mi
          requests:
            cpu: "0.01"
            memory: 51Mi
---
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  labels:
    new-label: NEW-LABEL
  name: ROLLOUT_NAME
  namespace: pxt-qa
spec:
  selector:
    matchLabels:
      new-label: NEW-LABEL
  revisionHistoryLimit: 5
  strategy:
    canary:
      canaryMetadata:
        labels:
          role: new
      canaryService: canaryService-name
      maxUnavailable: 0
      stableMetadata:
        labels:
          role: current
      stableService: stableService-name
      steps:
      - setWeight: 100
      trafficRouting:
        istio:
          virtualService:
            name: stableService-name
            routes:
            - primary
  workloadRef:
    apiVersion: apps/v1
    kind: Deployment
    name: DEPLOYMENT_NAME

Actual output

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kubernetes.io/change-cause: Deploy en pxt-qa 1.0
  labels:
    new-label: NEW-LABEL
  name: DEPLOYMENT_NAME
  namespace: pxt-qa
spec:
  replicas: 0
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      new-label: NEW-LABEL
  template:
    metadata:
      labels:
        new-label: NEW-LABEL
        some-label: value-of-label
    spec:
      containers:
      - env:
        - name: MY_POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        image: IMAGE_NAME
        name: CONTAINER_NAME
        ports:
        - containerPort: 8080
        resources:
          limits:
            cpu: "1"
            memory: 2000Mi
          requests:
            cpu: "0.01"
            memory: 51Mi
---
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  labels:
    new-label: NEW-LABEL
  name: ROLLOUT_NAME
  namespace: pxt-qa
spec:
  revisionHistoryLimit: 5
  strategy:
    canary:
      canaryMetadata:
        labels:
          role: new
      canaryService: canaryService-name
      maxUnavailable: 0
      stableMetadata:
        labels:
          role: current
      stableService: stableService-name
      steps:
      - setWeight: 100
      trafficRouting:
        istio:
          virtualService:
            name: stableService-name
            routes:
            - primary
  workloadRef:
    apiVersion: apps/v1
    kind: Deployment
    name: DEPLOYMENT_NAME

Kustomize version

v5.1.0

Operating system

MacOS

@felixrb86 felixrb86 added the kind/bug Categorizes issue or PR as related to a bug. label Aug 25, 2023
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Aug 25, 2023
@DiptoChakrabarty
Copy link
Member

can confirm able to recreate the issue

@kuzm1ch
Copy link

kuzm1ch commented Oct 27, 2023

+1, the same issue but for another CRD(servicemonitor).

@annasong20 annasong20 changed the title The commonLabels in Rollouts spec.selector.matchLabels doesn't works The labels in Rollouts spec.selector.matchLabels doesn't works Dec 20, 2023
@annasong20
Copy link
Contributor

Hi @felixrb86, Kustomize only understands native Kubernetes objects. Because Rollout is defined by Argo, Kustomize has no way of knowing by default how to interact with it. Kustomize should not blindly add these fields to all Kubernetes objects it processes; this would be unexpected behaviors for many users and could lead to many bugs.

@kuzm1ch's comment #5295 (comment) is a great solution to your problem. This solution tells Kustomize to operate on specific fields of this new resource that Kustomize does not know about. Does this solution work for you?

Converting to GitHub discussion, as this is not a bug, but instead more of a support question.
/kind support
/triage resolved

@k8s-ci-robot k8s-ci-robot added kind/support Categorizes issue or PR as a support question. triage/resolved Indicates an issue has been resolved or doesn't need to be resolved. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Dec 20, 2023
@annasong20
Copy link
Contributor

/remove-kind bug

@k8s-ci-robot k8s-ci-robot removed the kind/bug Categorizes issue or PR as related to a bug. label Dec 20, 2023
@kubernetes-sigs kubernetes-sigs locked and limited conversation to collaborators Dec 20, 2023
@annasong20 annasong20 converted this issue into discussion #5496 Dec 20, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
kind/support Categorizes issue or PR as a support question. triage/resolved Indicates an issue has been resolved or doesn't need to be resolved.
Projects
None yet
Development

No branches or pull requests

5 participants