Skip to content

Commit

Permalink
Panic on kubelet compatibility annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
engedaam committed Nov 25, 2024
1 parent 10be54b commit 5dc684c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 5dc684c

Please sign in to comment.