Skip to content

Commit ba3d0fb

Browse files
committed
mvp
Signed-off-by: Pavel Tishkov <[email protected]>
1 parent d2f4834 commit ba3d0fb

File tree

1 file changed

+30
-30
lines changed
  • images/hooks/cmd/cleanup-labels

1 file changed

+30
-30
lines changed

images/hooks/cmd/cleanup-labels/main.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import (
2626
"github.com/deckhouse/module-sdk/pkg"
2727
"github.com/deckhouse/module-sdk/pkg/app"
2828
"github.com/deckhouse/module-sdk/pkg/registry"
29-
"k8s.io/utils/ptr"
3029

3130
"hooks/pkg/common"
3231

3332
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33+
"k8s.io/utils/ptr"
3434
)
3535

3636
const (
@@ -49,9 +49,9 @@ type NodeInfo struct {
4949
Labels map[string]string `json:"labels"`
5050
}
5151

52-
var _ = registry.RegisterFunc(configDiscoveryService, handleCleanUpNodeLabels)
52+
var _ = registry.RegisterFunc(configVirtHandlerNodeCleanUp, handleCleanUpNodeLabels)
5353

54-
var configDiscoveryService = &pkg.HookConfig{
54+
var configVirtHandlerNodeCleanUp = &pkg.HookConfig{
5555
OnAfterDeleteHelm: &pkg.OrderedConfig{Order: 5},
5656
Kubernetes: []pkg.KubernetesConfig{
5757
{
@@ -68,7 +68,7 @@ var configDiscoveryService = &pkg.HookConfig{
6868
},
6969
},
7070
ExecuteHookOnSynchronization: ptr.To(false),
71-
ExecuteHookOnEvents: ptr.To(false),
71+
// ExecuteHookOnEvents: ptr.To(false),
7272
},
7373
},
7474

@@ -83,32 +83,32 @@ func handleCleanUpNodeLabels(_ context.Context, input *pkg.HookInput) error {
8383
return nil
8484
}
8585

86-
for _, node := range nodes {
87-
nodeInfo := &NodeInfo{}
88-
if err := node.UnmarshalTo(nodeInfo); err != nil {
89-
input.Logger.Error(fmt.Sprintf("Failed to unmarshal node metadata %v", err))
90-
continue
91-
}
92-
93-
patches := make([]map[string]string, 0)
94-
95-
for key, _ := range nodeInfo.Labels {
96-
if strings.Contains(key, labelPattern) {
97-
patches = append(patches, map[string]string{
98-
"op": "remove",
99-
"path": fmt.Sprintf("/metadata/labels/%s", jsonPatchEscape(key)),
100-
})
101-
}
102-
}
103-
104-
if len(patches) == 0 {
105-
continue
106-
} else {
107-
input.Logger.Info(fmt.Sprintf(logMessageTemplate, len(patches), labelPattern, nodeInfo.Name))
108-
}
109-
110-
input.PatchCollector.PatchWithJSON(patches, "v1", "Node", "", nodeInfo.Name)
111-
}
86+
// for _, node := range nodes {
87+
// nodeInfo := &NodeInfo{}
88+
// if err := node.UnmarshalTo(nodeInfo); err != nil {
89+
// input.Logger.Error(fmt.Sprintf("Failed to unmarshal node metadata %v", err))
90+
// continue
91+
// }
92+
93+
// patches := make([]map[string]string, 0)
94+
95+
// for key, _ := range nodeInfo.Labels {
96+
// if strings.Contains(key, labelPattern) {
97+
// patches = append(patches, map[string]string{
98+
// "op": "remove",
99+
// "path": fmt.Sprintf("/metadata/labels/%s", jsonPatchEscape(key)),
100+
// })
101+
// }
102+
// }
103+
104+
// if len(patches) == 0 {
105+
// continue
106+
// } else {
107+
// input.Logger.Info(fmt.Sprintf(logMessageTemplate, len(patches), labelPattern, nodeInfo.Name))
108+
// }
109+
110+
// input.PatchCollector.PatchWithJSON(patches, "v1", "Node", "", nodeInfo.Name)
111+
// }
112112
return nil
113113
}
114114

0 commit comments

Comments
 (0)