Skip to content

feat: Made ng labels env driven #6438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 21, 2025
48 changes: 33 additions & 15 deletions pkg/k8s/capacity/bean/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ package bean
import (
"context"
"fmt"
"os"
"strings"
"time"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/client-go/kubernetes"
"strings"
"time"
)

const (
Expand All @@ -43,21 +45,37 @@ const NamespaceAll string = ""

// below const set is used for pod filters
const (
daemonSetFatal = "DaemonSet-managed Pods (use --ignore-daemonsets to ignore)"
daemonSetWarning = "ignoring DaemonSet-managed Pods"
localStorageFatal = "Pods with local storage (use --delete-emptydir-data to override)"
localStorageWarning = "deleting Pods with local storage"
unmanagedFatal = "Pods declare no controller (use --force to override)"
unmanagedWarning = "deleting Pods that declare no controller"
AWSNodeGroupLabel = "alpha.eksctl.io/nodegroup-name"
AzureNodeGroupLabel = "kubernetes.azure.com/agentpool"
GcpNodeGroupLabel = "cloud.google.com/gke-nodepool"
KopsNodeGroupLabel = "kops.k8s.io/instancegroup"
AWSEKSNodeGroupLabel = "eks.amazonaws.com/nodegroup"
daemonSetFatal = "DaemonSet-managed Pods (use --ignore-daemonsets to ignore)"
daemonSetWarning = "ignoring DaemonSet-managed Pods"
localStorageFatal = "Pods with local storage (use --delete-emptydir-data to override)"
localStorageWarning = "deleting Pods with local storage"
unmanagedFatal = "Pods declare no controller (use --force to override)"
unmanagedWarning = "deleting Pods that declare no controller"
AWSNodeGroupLabel = "alpha.eksctl.io/nodegroup-name"
AzureNodeGroupLabel = "kubernetes.azure.com/agentpool"
GcpNodeGroupLabel = "cloud.google.com/gke-nodepool"
KopsNodeGroupLabel = "kops.k8s.io/instancegroup"
AWSEKSNodeGroupLabel = "eks.amazonaws.com/nodegroup"
KarpenterNodeGroupLabel = "karpenter.sh/nodepool"
// env var to override default node group labels
NodeGroupLabelsEnvVar = "NODE_GROUP_LABELS"
)

// TODO: add any new nodeGrouplabel in this array
var NodeGroupLabels = [5]string{AWSNodeGroupLabel, AzureNodeGroupLabel, GcpNodeGroupLabel, KopsNodeGroupLabel, AWSEKSNodeGroupLabel}
var NodeGroupLabels = []string{AWSNodeGroupLabel, AzureNodeGroupLabel, GcpNodeGroupLabel, KopsNodeGroupLabel, AWSEKSNodeGroupLabel, KarpenterNodeGroupLabel}

func init() {
if envLabels := os.Getenv(NodeGroupLabelsEnvVar); envLabels != "" {
customLabels := strings.Split(envLabels, ",")
// Trim spaces from labels
for i := range customLabels {
customLabels[i] = strings.TrimSpace(customLabels[i])
}
// Only update if we got valid labels
if len(customLabels) > 0 {
NodeGroupLabels = customLabels
}
}
}

// below const set is used for pod delete status
const (
Expand Down