From 5dc684c495cf62efb70d793761146f0c3ad22f85 Mon Sep 17 00:00:00 2001 From: Amanuel Engeda Date: Mon, 25 Nov 2024 07:13:00 -0800 Subject: [PATCH] Panic on kubelet compatibility annotation --- pkg/operator/operator.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 0cf61272d1ca..665b23ebff59 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -39,6 +39,8 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/transport" + "sigs.k8s.io/controller-runtime/pkg/client" + clinetconfig "sigs.k8s.io/controller-runtime/pkg/client/config" "sigs.k8s.io/controller-runtime/pkg/log" crmetrics "sigs.k8s.io/controller-runtime/pkg/metrics" @@ -47,6 +49,7 @@ import ( prometheusv2 "github.com/jonathan-innis/aws-sdk-go-prometheus/v2" + "github.com/aws/karpenter-provider-aws/pkg/apis" sdk "github.com/aws/karpenter-provider-aws/pkg/aws" awscache "github.com/aws/karpenter-provider-aws/pkg/cache" "github.com/aws/karpenter-provider-aws/pkg/operator/options" @@ -86,6 +89,19 @@ type Operator struct { } func NewOperator(ctx context.Context, operator *operator.Operator) (context.Context, *Operator) { + kubeletCompatibilityAnnotationKey := fmt.Sprintf("%s/%s", apis.CompatibilityGroup, "v1beta1-kubelet-conversion") + // we are going to panic if any of the customer nodepools contain + // compatibility.karpenter.sh/v1beta1-kubelet-conversion + restConfig := clinetconfig.GetConfigOrDie() + kubeClient := lo.Must(client.New(restConfig, client.Options{})) + nodePoolList := &karpv1.NodePoolList{} + lo.Must0(kubeClient.List(ctx, nodePoolList)) + for _, np := range nodePoolList.Items { + if _, found := np.Annotations[kubeletCompatibilityAnnotationKey]; found { + panic(fmt.Sprintf("expected to %s nodepool to have %s removed", np.Name, kubeletCompatibilityAnnotationKey)) + } + } + cfg := prometheusv2.WithPrometheusMetrics(WithUserAgent(lo.Must(config.LoadDefaultConfig(ctx))), crmetrics.Registry) if cfg.Region == "" { log.FromContext(ctx).V(1).Info("retrieving region from IMDS")