MCPcopy
hub / github.com/fluid-cloudnative/fluid / CleanUpFuse

Method CleanUpFuse

pkg/ctrl/fuse.go:85–126  ·  view source on GitHub ↗

CleanUpFuse will cleanup node label for Fuse.

()

Source from the content-addressed store, hash-verified

83
84// CleanUpFuse will cleanup node label for Fuse.
85func (e *Helper) CleanUpFuse() (count int, err error) {
86 var (
87 nodeList = &corev1.NodeList{}
88 fuseLabelKey = utils.GetFuseLabelName(e.runtimeInfo.GetNamespace(), e.runtimeInfo.GetName(), e.runtimeInfo.GetOwnerDatasetUID())
89 )
90
91 labelNames := []string{fuseLabelKey}
92 e.log.Info("check node labels", "labelNames", labelNames)
93 fuseLabelSelector, err := labels.Parse(fmt.Sprintf("%s=true", fuseLabelKey))
94 if err != nil {
95 return
96 }
97
98 err = e.client.List(context.TODO(), nodeList, &client.ListOptions{
99 LabelSelector: fuseLabelSelector,
100 })
101 if err != nil {
102 return count, err
103 }
104
105 nodes := nodeList.Items
106 if len(nodes) == 0 {
107 e.log.Info("No node with fuse label need to be delete")
108 return
109 } else {
110 e.log.Info("Try to clean the fuse label for nodes", "len", len(nodes))
111 }
112
113 var labelsToModify common.LabelsToModify
114 labelsToModify.Delete(fuseLabelKey)
115
116 for _, node := range nodes {
117 _, err = utils.ChangeNodeLabelWithPatchMode(e.client, &node, labelsToModify)
118 if err != nil {
119 e.log.Error(err, "Error when patching labels on node", "nodeName", node.Name)
120 return count, errors.Wrapf(err, "error when patching labels on node %s", node.Name)
121 }
122 count++
123 }
124
125 return
126}
127
128// GetFuseNodes gets the node of fuses
129func (e *Helper) GetFuseNodes() (nodes []corev1.Node, err error) {

Callers 10

TestCleanUpFuseFunction · 0.95
cleanAllMethod · 0.80
cleanAllMethod · 0.80
cleanAllMethod · 0.80
cleanAllMethod · 0.80
cleanAllMethod · 0.80
cleanAllMethod · 0.80
cleanAllMethod · 0.80
cleanAllMethod · 0.80
cleanAllMethod · 0.80

Calls 7

DeleteMethod · 0.95
GetFuseLabelNameFunction · 0.92
GetNamespaceMethod · 0.65
GetNameMethod · 0.65
GetOwnerDatasetUIDMethod · 0.65
ErrorMethod · 0.45

Tested by 1

TestCleanUpFuseFunction · 0.76