• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NVIDIA / skyhook / 20072025419

09 Dec 2025 05:02PM UTC coverage: 77.041% (+2.1%) from 74.963%
20072025419

Pull #124

github

t0mmylam
feat(cli): Add node management commands and ignore label support
Pull Request #124: feat(cli): Add node management commands and ignore label support

1059 of 1277 new or added lines in 13 files covered. (82.93%)

56 existing lines in 3 files now uncovered.

5701 of 7400 relevant lines covered (77.04%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.68
/operator/internal/cli/node/node_ignore.go
1
/*
2
 * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3
 * SPDX-License-Identifier: Apache-2.0
4
 *
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18

19
package node
20

21
import (
22
        "context"
23
        "fmt"
24

25
        "github.com/spf13/cobra"
26
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27

28
        "github.com/NVIDIA/skyhook/operator/api/v1alpha1"
29
        "github.com/NVIDIA/skyhook/operator/internal/cli/client"
30
        cliContext "github.com/NVIDIA/skyhook/operator/internal/cli/context"
31
        "github.com/NVIDIA/skyhook/operator/internal/cli/utils"
32
)
33

34
const labelValueTrue = "true"
35

36
// NewIgnoreCmd creates the node ignore command
37
func NewIgnoreCmd(ctx *cliContext.CLIContext) *cobra.Command {
1✔
38
        cmd := &cobra.Command{
1✔
39
                Use:   "ignore <node-name...>",
1✔
40
                Short: "Ignore node(s) from Skyhook processing",
1✔
41
                Long: `Ignore node(s) from all Skyhook processing by setting the ignore label.
1✔
42

1✔
43
When a node is ignored, Skyhook will skip it during package execution.
1✔
44
This is useful for maintenance windows or debugging.
1✔
45

1✔
46
Node names can be exact matches or regex patterns.`,
1✔
47
                Example: `  # Ignore a single node
1✔
48
  kubectl skyhook node ignore worker-1
1✔
49

1✔
50
  # Ignore multiple nodes
1✔
51
  kubectl skyhook node ignore worker-1 worker-2 worker-3
1✔
52

1✔
53
  # Ignore all nodes matching a pattern
1✔
54
  kubectl skyhook node ignore "worker-.*"
1✔
55

1✔
56
  # Ignore GPU nodes for maintenance
1✔
57
  kubectl skyhook node ignore "gpu-node-[0-9]+"`,
1✔
58
                Args: cobra.MinimumNArgs(1),
1✔
59
                RunE: func(cmd *cobra.Command, args []string) error {
1✔
NEW
60
                        clientFactory := client.NewFactory(ctx.GlobalFlags.ConfigFlags)
×
NEW
61
                        kubeClient, err := clientFactory.Client()
×
NEW
62
                        if err != nil {
×
NEW
63
                                return fmt.Errorf("initializing kubernetes client: %w", err)
×
NEW
64
                        }
×
65

NEW
66
                        return runIgnore(cmd.Context(), cmd, kubeClient, args, ctx, true)
×
67
                },
68
        }
69

70
        return cmd
1✔
71
}
72

73
// NewUnignoreCmd creates the node unignore command
74
func NewUnignoreCmd(ctx *cliContext.CLIContext) *cobra.Command {
1✔
75
        cmd := &cobra.Command{
1✔
76
                Use:   "unignore <node-name...>",
1✔
77
                Short: "Remove ignore label from node(s)",
1✔
78
                Long: `Remove the ignore label from node(s), re-enabling Skyhook processing.
1✔
79

1✔
80
After unignoring, Skyhook will resume package execution on these nodes.
1✔
81

1✔
82
Node names can be exact matches or regex patterns.`,
1✔
83
                Example: `  # Unignore a single node
1✔
84
  kubectl skyhook node unignore worker-1
1✔
85

1✔
86
  # Unignore multiple nodes
1✔
87
  kubectl skyhook node unignore worker-1 worker-2 worker-3
1✔
88

1✔
89
  # Unignore all nodes matching a pattern
1✔
90
  kubectl skyhook node unignore "gpu-node-[0-9]+"`,
1✔
91
                Args: cobra.MinimumNArgs(1),
1✔
92
                RunE: func(cmd *cobra.Command, args []string) error {
1✔
NEW
93
                        clientFactory := client.NewFactory(ctx.GlobalFlags.ConfigFlags)
×
NEW
94
                        kubeClient, err := clientFactory.Client()
×
NEW
95
                        if err != nil {
×
NEW
96
                                return fmt.Errorf("initializing kubernetes client: %w", err)
×
NEW
97
                        }
×
98

NEW
99
                        return runIgnore(cmd.Context(), cmd, kubeClient, args, ctx, false)
×
100
                },
101
        }
102

103
        return cmd
1✔
104
}
105

106
func runIgnore(ctx context.Context, cmd *cobra.Command, kubeClient *client.Client, nodePatterns []string, cliCtx *cliContext.CLIContext, ignore bool) error {
1✔
107
        // Get all nodes
1✔
108
        nodeList, err := kubeClient.Kubernetes().CoreV1().Nodes().List(ctx, metav1.ListOptions{})
1✔
109
        if err != nil {
1✔
NEW
110
                return fmt.Errorf("listing nodes: %w", err)
×
NEW
111
        }
×
112

113
        // Collect all node names for pattern matching
114
        allNodeNames := make([]string, 0, len(nodeList.Items))
1✔
115
        nodeMap := make(map[string]int) // node name -> index in nodeList.Items
1✔
116
        for i, node := range nodeList.Items {
2✔
117
                allNodeNames = append(allNodeNames, node.Name)
1✔
118
                nodeMap[node.Name] = i
1✔
119
        }
1✔
120

121
        // Match nodes
122
        matchedNodes, err := utils.MatchNodes(nodePatterns, allNodeNames)
1✔
123
        if err != nil {
1✔
NEW
124
                return fmt.Errorf("matching nodes: %w", err)
×
NEW
125
        }
×
126

127
        if len(matchedNodes) == 0 {
2✔
128
                _, _ = fmt.Fprintf(cmd.OutOrStdout(), "No nodes matched the specified patterns\n")
1✔
129
                return nil
1✔
130
        }
1✔
131

132
        action := "Ignoring"
1✔
133
        if !ignore {
2✔
134
                action = "Unignoring"
1✔
135
        }
1✔
136

137
        _, _ = fmt.Fprintf(cmd.OutOrStdout(), "%s %d node(s):\n", action, len(matchedNodes))
1✔
138
        for _, nodeName := range matchedNodes {
2✔
139
                _, _ = fmt.Fprintf(cmd.OutOrStdout(), "  - %s\n", nodeName)
1✔
140
        }
1✔
141

142
        // Dry run check
143
        if cliCtx.GlobalFlags.DryRun {
2✔
144
                _, _ = fmt.Fprintf(cmd.OutOrStdout(), "\n[dry-run] No changes applied\n")
1✔
145
                return nil
1✔
146
        }
1✔
147

148
        // Apply changes
149
        var updateErrors []string
1✔
150
        successCount := 0
1✔
151

1✔
152
        for _, nodeName := range matchedNodes {
2✔
153
                idx := nodeMap[nodeName]
1✔
154
                node := nodeList.Items[idx].DeepCopy()
1✔
155

1✔
156
                if node.Labels == nil {
2✔
157
                        node.Labels = make(map[string]string)
1✔
158
                }
1✔
159

160
                if ignore {
2✔
161
                        // Check if already ignored
1✔
162
                        if val, ok := node.Labels[v1alpha1.NodeIgnoreLabel]; ok && val == labelValueTrue {
2✔
163
                                _, _ = fmt.Fprintf(cmd.OutOrStdout(), "  %s: already ignored\n", nodeName)
1✔
164
                                continue
1✔
165
                        }
166
                        node.Labels[v1alpha1.NodeIgnoreLabel] = labelValueTrue
1✔
167
                } else {
1✔
168
                        // Check if not ignored
1✔
169
                        if val, ok := node.Labels[v1alpha1.NodeIgnoreLabel]; !ok || val != labelValueTrue {
2✔
170
                                _, _ = fmt.Fprintf(cmd.OutOrStdout(), "  %s: not ignored\n", nodeName)
1✔
171
                                continue
1✔
172
                        }
173
                        delete(node.Labels, v1alpha1.NodeIgnoreLabel)
1✔
174
                }
175

176
                _, err := kubeClient.Kubernetes().CoreV1().Nodes().Update(ctx, node, metav1.UpdateOptions{})
1✔
177
                if err != nil {
1✔
NEW
178
                        updateErrors = append(updateErrors, fmt.Sprintf("%s: %v", nodeName, err))
×
NEW
179
                        continue
×
180
                }
181
                successCount++
1✔
182
        }
183

184
        // Print results
185
        if len(updateErrors) > 0 {
1✔
NEW
186
                _, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nErrors updating some nodes:\n")
×
NEW
187
                for _, e := range updateErrors {
×
NEW
188
                        _, _ = fmt.Fprintf(cmd.OutOrStdout(), "  - %s\n", e)
×
NEW
189
                }
×
190
        }
191

192
        if successCount > 0 {
2✔
193
                verb := "ignored"
1✔
194
                if !ignore {
2✔
195
                        verb = "unignored"
1✔
196
                }
1✔
197
                _, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nSuccessfully %s %d node(s)\n", verb, successCount)
1✔
198
        }
199

200
        return nil
1✔
201
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc