Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

service label mismatches selector, which result in inconsistency #360

Open
konnase opened this issue Nov 5, 2021 · 3 comments
Open

service label mismatches selector, which result in inconsistency #360

konnase opened this issue Nov 5, 2021 · 3 comments
Labels

Comments

@konnase
Copy link

konnase commented Nov 5, 2021

Service label is app: pytorch-operator, while selector is name: pytorch-operator. Deployment spec label and selector are both name: pytorch-operator.

image

In such a case, both the service and deployment have been deployed via kubectl create -f manifests/base. Then we want to update the operator image, but now we need to run kubectl apply -k manifests/overlays/latest. kustomize will add all the labels of service to selector, as shown below:

$ kustomize build manifests/overlays/latest
apiVersion: v1
kind: Service
metadata:
  annotations:
    prometheus.io/path: /metrics
    prometheus.io/port: "8443"
    prometheus.io/scrape: "true"
  labels:
    app: pytorch-operator
  name: pytorch-operator
  namespace: phx-system
spec:
  ports:
  - name: monitoring-port
    port: 8443
    targetPort: 8443
  selector:
    app: pytorch-operator
    name: pytorch-operator
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: pytorch-operator
  name: pytorch-operator
  namespace: phx-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pytorch-operator
      name: pytorch-operator
  template:
    metadata:
      labels:
        app: pytorch-operator
        name: pytorch-operator
    spec:
      containers:
        command:
        - /pytorch-operator.v1
        - --alsologtostderr
        - -v=1
        - --monitoring-port=8443
        env:
        - name: KUBEFLOW_NAMESPACE
          value: kubeflow
        image: ${pytorch-operator-image}
        name: pytorch-operator
      serviceAccountName: pytorch-operator

Then the following error occurs:

$ kubectl apply -k manifests/overlays/latest
serviceaccount/pytorch-operator unchanged
clusterrole.rbac.authorization.k8s.io/pytorch-operator unchanged
clusterrolebinding.rbac.authorization.k8s.io/pytorch-operator unchanged
service/pytorch-operator configured
The Deployment "pytorch-operator" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app":"pytorch-operator", "name":"pytorch-operator"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable

Better to match service labels with selectors and deployment's labels and selectors.

@gaocegege
Copy link
Member

May I ask which PyTorch operator version you are using?

@konnase
Copy link
Author

konnase commented Nov 8, 2021

May I ask which PyTorch operator version you are using?

v0.7.0

@konnase
Copy link
Author

konnase commented Nov 8, 2021

I made a mistake. The label app: pytorch-operator added by kustomize is defined in the commonLabels field of kustomization.yaml.

Sorry to mislead all.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants