Skip to content
This repository was archived by the owner on Nov 2, 2023. It is now read-only.
This repository was archived by the owner on Nov 2, 2023. It is now read-only.

[BUG] a node'label will be deleted if it deleted from a nodepool that has the same label #41

@chenyufeifei

Description

@chenyufeifei

What happened:
First, I create a nodePool

cat <<EOF | kubectl apply -f -
apiVersion: apps.openyurt.io/v1alpha1
kind: NodePool
metadata:
  name: test
spec:
  type: Edge
  labels:
    foo: bar
EOF

Second, I add a label in a node

kubectl label nodes kind-worker foo=bar

Third, I add the node to the nodepool

kubectl label node  kind-worker apps.openyurt.io/desired-nodepool=test

Last, I delete the node from the nodePool

kubectl label node kind-worker apps.openyurt.io/desired-nodepool-

1646841060068

What you expected to happen:

The node should have a label foo=bar

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

I read the source code, find it record the nodePool related attribute.

attrUpdated, err := conciliatePoolRelatedAttrs(&node,
NodePoolRelatedAttributes{
Labels: nodePool.Spec.Labels,
Annotations: nodePool.Spec.Annotations,
Taints: nodePool.Spec.Taints,
})

if err := cachePrevPoolAttrs(node, npra); err != nil {
return attrUpdated, err
}

When the node delete from the nodepool, all label will be deleted include the same label.

func removePoolRelatedAttrs(node *corev1.Node) error {
var npra NodePoolRelatedAttributes
if _, exist := node.Annotations[appsv1alpha1.AnnotationPrevAttrs]; !exist {
return nil
}
if err := json.Unmarshal(
[]byte(node.Annotations[appsv1alpha1.AnnotationPrevAttrs]),
&npra); err != nil {
return err
}
for lk, lv := range npra.Labels {
if node.Labels[lk] == lv {
delete(node.Labels, lk)
}
}
for ak, av := range npra.Annotations {
if node.Annotations[ak] == av {
delete(node.Annotations, ak)
}
}
for _, t := range npra.Taints {
if i, exist := containTaint(t, node.Spec.Taints); exist {
node.Spec.Taints = append(
node.Spec.Taints[:i],
node.Spec.Taints[i+1:]...)
}
}
delete(node.Annotations, appsv1alpha1.AnnotationPrevAttrs)
delete(node.Labels, appsv1alpha1.LabelCurrentNodePool)
return nil
}

Environment:

  • OpenYurt version:
  • Kubernetes version (use kubectl version):
  • OS (e.g: cat /etc/os-release):
  • Kernel (e.g. uname -a):
  • Install tools:
  • Others:

others

/kind bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions