Skip to content

Commit

Permalink
fix: using controller runtime v0.17 rather than aws operator package
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryce-Soghigian committed Jan 31, 2025
1 parent 6692984 commit 5633039
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import (
"fmt"
"time"

"sigs.k8s.io/karpenter/pkg/operator/injection"
controllerruntime "sigs.k8s.io/controller-runtime"
"github.com/awslabs/operatorpkg/singleton"

"github.com/Azure/karpenter-provider-azure/pkg/cloudprovider"
"github.com/samber/lo"
"go.uber.org/multierr"
v1 "k8s.io/api/core/v1"
Expand All @@ -42,21 +39,23 @@ import (

type VirtualMachine struct {
kubeClient client.Client
cloudProvider corecloudprovider.CloudProvider
successfulCount uint64 // keeps track of successful reconciles for more aggressive requeuing near the start of the controller
cloudProvider *cloudprovider.CloudProvider
successfulCount uint64 // keeps track of successful reconciles for more aggressive requeueing near the start of the controller
}

func NewVirtualMachine(kubeClient client.Client, cloudProvider corecloudprovider.CloudProvider) *VirtualMachine {
func NewVirtualMachine(kubeClient client.Client, cloudProvider *cloudprovider.CloudProvider) *VirtualMachine {
return &VirtualMachine{
kubeClient: kubeClient,
cloudProvider: cloudProvider,
successfulCount: 0,
}
}

func (c *VirtualMachine) Reconcile(ctx context.Context) (reconcile.Result, error) {
ctx = injection.WithControllerName(ctx, "instance.garbagecollection")
func (c *VirtualMachine) Name() string {
return "nodeclaim.garbagecollection"
}

func (c *VirtualMachine) Reconcile(ctx context.Context, _ reconcile.Request) (reconcile.Result, error) {
// We LIST VMs on the CloudProvider BEFORE we grab NodeClaims/Nodes on the cluster so that we make sure that, if
// LISTing instances takes a long time, our information is more updated by the time we get to nodeclaim and Node LIST
// This works since our CloudProvider instances are deleted based on whether the NodeClaim exists or not, not vice-versa
Expand Down Expand Up @@ -109,9 +108,6 @@ func (c *VirtualMachine) garbageCollect(ctx context.Context, nodeClaim *corev1be
return nil
}

func (c *VirtualMachine) Register(_ context.Context, m manager.Manager) error {
return controllerruntime.NewControllerManagedBy(m).
Named("instance.garbagecollection").
WatchesRawSource(singleton.Source()).
Complete(singleton.AsReconciler(c))
func (c *VirtualMachine) Builder(_ context.Context, m manager.Manager) controller.Builder {

Check failure on line 111 in pkg/controllers/nodeclaim/garbagecollection/instance_garbagecollection.go

View workflow job for this annotation

GitHub Actions / ci

undefined: controller

Check failure on line 111 in pkg/controllers/nodeclaim/garbagecollection/instance_garbagecollection.go

View workflow job for this annotation

GitHub Actions / ci

undefined: controller
return controller.NewSingletonManagedBy(m)

Check failure on line 112 in pkg/controllers/nodeclaim/garbagecollection/instance_garbagecollection.go

View workflow job for this annotation

GitHub Actions / ci

undefined: controller

Check failure on line 112 in pkg/controllers/nodeclaim/garbagecollection/instance_garbagecollection.go

View workflow job for this annotation

GitHub Actions / ci

undefined: controller
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ import (
"github.com/samber/lo"
"knative.dev/pkg/logging"

"github.com/awslabs/operatorpkg/singleton"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/util/workqueue"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/karpenter/pkg/operator/injection"
corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1"
"sigs.k8s.io/karpenter/pkg/operator/controller"

"github.com/Azure/karpenter-provider-azure/pkg/providers/instance"
)
Expand Down Expand Up @@ -76,8 +74,7 @@ func (c *NetworkInterface) populateUnremovableInterfaces(ctx context.Context) (s
return unremovableInterfaces, nil
}

func (c *NetworkInterface) Reconcile(ctx context.Context) (reconcile.Result, error) {
ctx = injection.WithControllerName(ctx, "networkinterface.garbagecollection")
func (c *NetworkInterface) Reconcile(ctx context.Context, _ reconcile.Request) (reconcile.Result, error) {
nics, err := c.instanceProvider.ListNics(ctx)
if err != nil {
return reconcile.Result{}, fmt.Errorf("listing NICs: %w", err)
Expand All @@ -104,9 +101,6 @@ func (c *NetworkInterface) Reconcile(ctx context.Context) (reconcile.Result, err
}, nil
}

func (c *NetworkInterface) Register(_ context.Context, m manager.Manager) error {
return controllerruntime.NewControllerManagedBy(m).
Named("networkinterface.garbagecollection").
WatchesRawSource(singleton.Source()).
Complete(singleton.AsReconciler(c))
func (c *NetworkInterface) Builder(_ context.Context, m manager.Manager) {
return controller.NewSingletonManagedBy(m)

Check failure on line 105 in pkg/controllers/nodeclaim/garbagecollection/nic_garbagecollection.go

View workflow job for this annotation

GitHub Actions / ci

too many return values

Check failure on line 105 in pkg/controllers/nodeclaim/garbagecollection/nic_garbagecollection.go

View workflow job for this annotation

GitHub Actions / ci

too many return values
}

0 comments on commit 5633039

Please sign in to comment.