diff --git a/pkg/controllers/controllers.go b/pkg/controllers/controllers.go index ffc0872dc924..350a1cc7b484 100644 --- a/pkg/controllers/controllers.go +++ b/pkg/controllers/controllers.go @@ -85,7 +85,7 @@ func NewControllers( nodeclassstatus.NewController(kubeClient, subnetProvider, securityGroupProvider, amiProvider, instanceProfileProvider, launchTemplateProvider), nodeclasstermination.NewController(kubeClient, recorder, instanceProfileProvider, launchTemplateProvider), nodeclaimgarbagecollection.NewController(kubeClient, cloudProvider), - nodeclaimtagging.NewController(kubeClient, instanceProvider), + nodeclaimtagging.NewController(kubeClient, cloudProvider, instanceProvider), controllerspricing.NewController(pricingProvider), controllersinstancetype.NewController(instanceTypeProvider), controllersinstancetypecapacity.NewController(kubeClient, cloudProvider, instanceTypeProvider), diff --git a/pkg/controllers/nodeclaim/tagging/controller.go b/pkg/controllers/nodeclaim/tagging/controller.go index 6c3294a810e5..383cfa0bf985 100644 --- a/pkg/controllers/nodeclaim/tagging/controller.go +++ b/pkg/controllers/nodeclaim/tagging/controller.go @@ -21,6 +21,7 @@ import ( "k8s.io/apimachinery/pkg/api/equality" controllerruntime "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/log" @@ -28,6 +29,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/karpenter/pkg/operator/injection" + "sigs.k8s.io/karpenter/pkg/utils/nodeclaim" "github.com/samber/lo" @@ -44,12 +46,14 @@ import ( type Controller struct { kubeClient client.Client + cloudProvider cloudprovider.CloudProvider instanceProvider instance.Provider } -func NewController(kubeClient client.Client, instanceProvider instance.Provider) *Controller { +func NewController(kubeClient client.Client, cloudProvider cloudprovider.CloudProvider, instanceProvider instance.Provider) *Controller { return &Controller{ kubeClient: kubeClient, + cloudProvider: cloudProvider, instanceProvider: instanceProvider, } } @@ -86,7 +90,7 @@ func (c *Controller) Reconcile(ctx context.Context, nodeClaim *karpv1.NodeClaim) func (c *Controller) Register(_ context.Context, m manager.Manager) error { return controllerruntime.NewControllerManagedBy(m). Named("nodeclaim.tagging"). - For(&karpv1.NodeClaim{}). + For(&karpv1.NodeClaim{}, builder.WithPredicates(nodeclaim.IsManagedPredicateFuncs(c.cloudProvider))). WithEventFilter(predicate.NewPredicateFuncs(func(o client.Object) bool { return isTaggable(o.(*karpv1.NodeClaim)) })). diff --git a/pkg/controllers/nodeclaim/tagging/suite_test.go b/pkg/controllers/nodeclaim/tagging/suite_test.go index 5039f4d86ae2..5f284108543f 100644 --- a/pkg/controllers/nodeclaim/tagging/suite_test.go +++ b/pkg/controllers/nodeclaim/tagging/suite_test.go @@ -19,17 +19,20 @@ import ( "fmt" "testing" + "sigs.k8s.io/karpenter/pkg/events" "sigs.k8s.io/karpenter/pkg/test/v1alpha1" "github.com/aws/aws-sdk-go-v2/aws" ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/samber/lo" corev1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/tools/record" karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1" coretest "sigs.k8s.io/karpenter/pkg/test" "github.com/aws/karpenter-provider-aws/pkg/apis" v1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1" + "github.com/aws/karpenter-provider-aws/pkg/cloudprovider" "github.com/aws/karpenter-provider-aws/pkg/controllers/nodeclaim/tagging" "github.com/aws/karpenter-provider-aws/pkg/fake" "github.com/aws/karpenter-provider-aws/pkg/operator/options" @@ -60,7 +63,9 @@ var _ = BeforeSuite(func() { ctx = coreoptions.ToContext(ctx, coretest.Options()) ctx = options.ToContext(ctx, test.Options()) awsEnv = test.NewEnvironment(ctx, env) - taggingController = tagging.NewController(env.Client, awsEnv.InstanceProvider) + cloudProvider := cloudprovider.New(awsEnv.InstanceTypesProvider, awsEnv.InstanceProvider, events.NewRecorder(&record.FakeRecorder{}), + env.Client, awsEnv.AMIProvider, awsEnv.SecurityGroupProvider) + taggingController = tagging.NewController(env.Client, cloudProvider, awsEnv.InstanceProvider) }) var _ = AfterSuite(func() { Expect(env.Stop()).To(Succeed(), "Failed to stop environment")