kubeflow/pytorch-operator

service label mismatches selector, which result in inconsistency

konnase opened this issue · 3 comments

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.

May I ask which PyTorch operator version you are using?

May I ask which PyTorch operator version you are using?

v0.7.0

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.