Skip to content

Commit 132a1ad

Browse files
committed
feat: made nodelabels env driven
1 parent 6194b77 commit 132a1ad

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

pkg/k8s/capacity/bean/bean.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ package bean
1919
import (
2020
"context"
2121
"fmt"
22+
"os"
23+
"strings"
24+
"time"
25+
2226
corev1 "k8s.io/api/core/v1"
2327
apierrors "k8s.io/apimachinery/pkg/api/errors"
2428
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2529
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2630
"k8s.io/client-go/kubernetes"
27-
"strings"
28-
"time"
2931
)
3032

3133
const (
@@ -55,10 +57,25 @@ const (
5557
KopsNodeGroupLabel = "kops.k8s.io/instancegroup"
5658
AWSEKSNodeGroupLabel = "eks.amazonaws.com/nodegroup"
5759
KarpenterNodeGroupLabel = "karpenter.sh/nodepool"
60+
// env var to override default node group labels
61+
NodeGroupLabelsEnvVar = "NODE_GROUP_LABELS"
5862
)
5963

60-
// TODO: add any new nodeGrouplabel in this array
61-
var NodeGroupLabels = [6]string{AWSNodeGroupLabel, AzureNodeGroupLabel, GcpNodeGroupLabel, KopsNodeGroupLabel, AWSEKSNodeGroupLabel, KarpenterNodeGroupLabel}
64+
var NodeGroupLabels = []string{AWSNodeGroupLabel, AzureNodeGroupLabel, GcpNodeGroupLabel, KopsNodeGroupLabel, AWSEKSNodeGroupLabel, KarpenterNodeGroupLabel}
65+
66+
func init() {
67+
if envLabels := os.Getenv(NodeGroupLabelsEnvVar); envLabels != "" {
68+
customLabels := strings.Split(envLabels, ",")
69+
// Trim spaces from labels
70+
for i := range customLabels {
71+
customLabels[i] = strings.TrimSpace(customLabels[i])
72+
}
73+
// Only update if we got valid labels
74+
if len(customLabels) > 0 {
75+
NodeGroupLabels = customLabels
76+
}
77+
}
78+
}
6279

6380
// below const set is used for pod delete status
6481
const (

0 commit comments

Comments
 (0)