Skip to content
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

commonLabels applied to podAffinity labelSelector.matchLabels #1459

Closed
mshkrebtan opened this issue Aug 19, 2019 · 11 comments
Closed

commonLabels applied to podAffinity labelSelector.matchLabels #1459

mshkrebtan opened this issue Aug 19, 2019 · 11 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@mshkrebtan
Copy link

mshkrebtan commented Aug 19, 2019

I want to run an application (masterdata) on a host where Memcached is already running, hence I specify Affinity in the PodSpec.

I use kustomize version 3.1.0:

$ kustomize version
Version: {KustomizeVersion:3.1.0 GitCommit:95f3303493fdea243ae83b767978092396169baf BuildDate:2019-07-26T19:21:45+01:00 GoOs:darwin GoArch:amd64}

I build a configuration out of the following files:

kustomization.yaml:

---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

commonLabels:
  app: common-label

resources:
 - deployment.yaml

deployment.yaml:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: masterdata
    spec:
      affinity:
        podAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchLabels:
                  app: memcached
              topologyKey: kubernetes.io/hostname
      containers:

When I run kustomize build, I get the following:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: common-label
  name: deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: common-label
  template:
    metadata:
      labels:
        app: common-label
    spec:
      affinity:
        podAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchLabels:
                app: common-label
            topologyKey: kubernetes.io/hostname
      containers:

Pay attention to the matchLabels map in the affinity block. It was altered by Kustomize.

So, as a workaround, I have to use the matchExpressions array in the labelSelector:

      affinity:
        podAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: app
                    operator: In
                    values:
                      - memcached
              topologyKey: kubernetes.io/hostname

Then I get the output I need

$ kustomize build
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: common-label
  name: deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: common-label
  template:
    metadata:
      labels:
        app: common-label
    spec:
      affinity:
        podAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - memcached
            topologyKey: kubernetes.io/hostname
      containers:

In the docs here it's said:

commonLabels will also be applied both to Label Selector fields and Label fields in PodTemplates.

As seen now, it also affects affinity rules in a PodTemplate. So, is this a bug or a feature?

@litaxc
Copy link

litaxc commented Oct 16, 2019

just ran into the same situation

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 14, 2020
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Feb 13, 2020
@dan-j
Copy link

dan-j commented Feb 17, 2020

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Feb 17, 2020
@icoloma
Copy link

icoloma commented Mar 9, 2020

Can we agree that commonLabels should not affect matchLabels in general? I have the same issue with a Deployment, where I don't want a generic configuration overwriting matchLabels. That's scaling information for my ReplicaSet, not labeling information to extend. This issue has been reported in multiple places already.

@michaelkrupp
Copy link

It appears that maintainers are not paying any attention to this issue at all.

This bug has been repeatedly reported over the last 6 months now, with every single issue going rotten without any clear statement from any maintainer.

What are we supposed to do? Just sit there and wait for another year until we maybe get a reply? I'd happily implement the required changes, but I am not going to waste my time if we cannot even get a reply from anyone able to give us a direction here.

It's sad, but I think it's time to move on. There are enough alternatives out there.

(sorry for the rant, but this is really frustrating by now)

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 14, 2020
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jul 14, 2020
@Shell32-Natsu
Copy link
Contributor

#2034 (comment)

@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

8 participants