Skip to content

Commit 90e4d1c

Browse files
authored
Merge pull request #7 from logyball/logyball/add-karpenter-support
Include Karpenter-provisioned nodes into consideration
2 parents 8a913e0 + 71dec30 commit 90e4d1c

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,17 @@ kubectl nodepools list --label 'custom.domain.io/fancy-node-label'
4646
# list nodes with a nodepool using a custom label
4747
kubectl nodepools nodes -l 'custom.domain.io/fancy-node-label' $nodepool
4848
```
49+
50+
### Working with Karpenter
51+
Because [Karpenter](https://karpenter.sh/) does not provision node groups, it must be handled separately.
52+
By default, Karpenter nodes are listed in the format "(Karpenter) {Provisioner}".
53+
The [Provisioner](https://karpenter.sh/v0.27.1/concepts/provisioners/) refers to the provisioner that Karpenter used to create this particular node.
54+
In order to search for nodes from particular provisioners, use the `--label` flag.
55+
56+
```shell
57+
# list nodes with karpenter included
58+
kubectl nodepools list
59+
60+
# list nodes for a particular karpenter provisioner
61+
kubectl nodepools list --label 'karpenter.sh/provisioner-name' provisionerA
62+
```

main.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import (
1919
_ "k8s.io/client-go/plugin/pkg/client/auth"
2020
)
2121

22+
const (
23+
karpenterLabel string = "karpenter.sh/provisioner-name"
24+
karpenterNodeFmtStr string = "(Karpenter) %s"
25+
)
26+
2227
var (
2328
noHeaders bool
2429
onlyName bool
@@ -102,6 +107,12 @@ func findNodepool(node corev1.Node, label string) string {
102107
if np, ok := node.Labels[label]; ok {
103108
return np
104109
}
110+
111+
// check for karpenter nodes
112+
if np, ok := node.Labels[karpenterLabel]; ok {
113+
return fmt.Sprintf(karpenterNodeFmtStr, np)
114+
}
115+
105116
for _, lbl := range providerNodepoolLabels {
106117
if np, ok := node.Labels[lbl]; ok {
107118
return np
@@ -125,7 +136,7 @@ func instanceType(node corev1.Node) string {
125136

126137
type nodepool struct {
127138
Name string
128-
Type string
139+
Types map[string]bool
129140
Nodes uint
130141
}
131142

@@ -155,9 +166,13 @@ func listCmd() *cobra.Command {
155166
names = append(names, npName)
156167
np = &nodepool{
157168
Name: npName,
158-
Type: instanceType(n),
169+
Types: map[string]bool{
170+
instanceType(n): true,
171+
},
159172
}
160173
nps[npName] = np
174+
} else {
175+
np.Types[instanceType(n)] = true
161176
}
162177
np.Nodes += 1
163178
}
@@ -178,7 +193,12 @@ func listCmd() *cobra.Command {
178193
if onlyName {
179194
fmt.Fprintln(w, np.Name)
180195
} else {
181-
fmt.Fprintf(w, "%s\t%5d\t%s\n", np.Name, np.Nodes, np.Type)
196+
typeList := make([]string, 0, len(np.Types))
197+
for k := range np.Types {
198+
typeList = append(typeList, k)
199+
}
200+
sort.Strings(typeList)
201+
fmt.Fprintf(w, "%s\t%5d\t%s\n", np.Name, np.Nodes, strings.Join(typeList, ", "))
182202
}
183203
}
184204

0 commit comments

Comments
 (0)