mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-15 17:50:49 +00:00
Merge pull request #897 from marquiz/devel/drop-incubator
nfd-master: drop cleanup of ancient incubator labels
This commit is contained in:
commit
0abae922fa
2 changed files with 13 additions and 17 deletions
|
@ -533,3 +533,16 @@ func sortJsonPatches(p []apihelper.JsonPatch) []apihelper.JsonPatch {
|
|||
sort.Slice(p, func(i, j int) bool { return p[i].Path < p[j].Path })
|
||||
return p
|
||||
}
|
||||
|
||||
// Remove any labels having the given prefix
|
||||
func removeLabelsWithPrefix(n *api.Node, search string) []apihelper.JsonPatch {
|
||||
var p []apihelper.JsonPatch
|
||||
|
||||
for k := range n.Labels {
|
||||
if strings.HasPrefix(k, search) {
|
||||
p = append(p, apihelper.NewJsonPatch("remove", "/metadata/labels", k, ""))
|
||||
}
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
|
|
@ -580,10 +580,6 @@ func (m *nfdMaster) updateNodeFeatures(nodeName string, labels Labels, annotatio
|
|||
patches := createPatches(oldLabels, node.Labels, labels, "/metadata/labels")
|
||||
patches = append(patches, createPatches(nil, node.Annotations, annotations, "/metadata/annotations")...)
|
||||
|
||||
// Also, remove all labels with the old prefix, and the old version label
|
||||
patches = append(patches, removeLabelsWithPrefix(node, "node.alpha.kubernetes-incubator.io/nfd")...)
|
||||
patches = append(patches, removeLabelsWithPrefix(node, "node.alpha.kubernetes-incubator.io/node-feature-discovery")...)
|
||||
|
||||
// Patch the node object in the apiserver
|
||||
err = m.apihelper.PatchNode(cli, node.Name, patches)
|
||||
if err != nil {
|
||||
|
@ -612,19 +608,6 @@ func (m *nfdMaster) getKubeconfig() (*restclient.Config, error) {
|
|||
return m.kubeconfig, err
|
||||
}
|
||||
|
||||
// Remove any labels having the given prefix
|
||||
func removeLabelsWithPrefix(n *api.Node, search string) []apihelper.JsonPatch {
|
||||
var p []apihelper.JsonPatch
|
||||
|
||||
for k := range n.Labels {
|
||||
if strings.HasPrefix(k, search) {
|
||||
p = append(p, apihelper.NewJsonPatch("remove", "/metadata/labels", k, ""))
|
||||
}
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// createPatches is a generic helper that returns json patch operations to perform
|
||||
func createPatches(removeKeys []string, oldItems map[string]string, newItems map[string]string, jsonPath string) []apihelper.JsonPatch {
|
||||
patches := []apihelper.JsonPatch{}
|
||||
|
|
Loading…
Reference in a new issue