Skip to content
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

Adding cluster unpause reconcile for LinodeObjectStorageBucket and LinodeVPC #245

Merged
merged 7 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions controller/linodecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,9 @@
return fmt.Errorf("failed to build controller: %w", err)
}

err = controller.Watch(
return controller.Watch(

Check warning on line 224 in controller/linodecluster_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodecluster_controller.go#L224

Added line #L224 was not covered by tests
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
handler.EnqueueRequestsFromMapFunc(kutil.ClusterToInfrastructureMapFunc(context.TODO(), infrav1alpha1.GroupVersion.WithKind("LinodeCluster"), mgr.GetClient(), &infrav1alpha1.LinodeCluster{})),
predicates.ClusterUnpausedAndInfrastructureReady(mgr.GetLogger()),
)
if err != nil {
return fmt.Errorf("failed adding a watch for ready clusters: %w", err)
}

return nil
}
14 changes: 7 additions & 7 deletions controller/linodemachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,14 @@
return fmt.Errorf("failed to build controller: %w", err)
}

err = controller.Watch(
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
handler.EnqueueRequestsFromMapFunc(r.requeueLinodeMachinesForUnpausedCluster(mgr.GetLogger())),
predicates.ClusterUnpausedAndInfrastructureReady(mgr.GetLogger()),
)
linodeMachineMapper, err := kutil.ClusterToTypedObjectsMapper(r.Client, &infrav1alpha1.LinodeMachineList{}, mgr.GetScheme())

Check warning on line 593 in controller/linodemachine_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodemachine_controller.go#L593

Added line #L593 was not covered by tests
if err != nil {
return fmt.Errorf("failed adding a watch for ready clusters: %w", err)
return fmt.Errorf("failed to create mapper for LinodeMachines: %w", err)

Check warning on line 595 in controller/linodemachine_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodemachine_controller.go#L595

Added line #L595 was not covered by tests
}

return nil
return controller.Watch(
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
handler.EnqueueRequestsFromMapFunc(linodeMachineMapper),
predicates.ClusterUnpausedAndInfrastructureReady(mgr.GetLogger()),
)

Check warning on line 602 in controller/linodemachine_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodemachine_controller.go#L598-L602

Added lines #L598 - L602 were not covered by tests
}
31 changes: 0 additions & 31 deletions controller/linodemachine_controller_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,37 +215,6 @@ func (r *LinodeMachineReconciler) linodeClusterToLinodeMachines(logger logr.Logg
}
}

func (r *LinodeMachineReconciler) requeueLinodeMachinesForUnpausedCluster(logger logr.Logger) handler.MapFunc {
logger = logger.WithName("LinodeMachineReconciler").WithName("requeueLinodeMachinesForUnpausedCluster")

return func(ctx context.Context, o client.Object) []ctrl.Request {
ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultMappingTimeout)
defer cancel()

cluster, ok := o.(*clusterv1.Cluster)
if !ok {
logger.Info("Failed to cast object to Cluster")

return nil
}

if !cluster.ObjectMeta.DeletionTimestamp.IsZero() {
logger.Info("Cluster has a deletion timestamp, skipping mapping")

return nil
}

requests, err := r.requestsForCluster(ctx, cluster.Namespace, cluster.Name)
if err != nil {
logger.Error(err, "Failed to create request for cluster")

return nil
}

return requests
}
}

func (r *LinodeMachineReconciler) requestsForCluster(ctx context.Context, namespace, name string) ([]ctrl.Request, error) {
labels := map[string]string{clusterv1.ClusterNameLabel: name}

Expand Down
21 changes: 19 additions & 2 deletions controller/linodeobjectstoragebucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/tools/record"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
kutil "sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/predicates"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/source"

infrav1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
Expand Down Expand Up @@ -253,12 +256,26 @@

// SetupWithManager sets up the controller with the Manager.
func (r *LinodeObjectStorageBucketReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
controller, err := ctrl.NewControllerManagedBy(mgr).

Check warning on line 259 in controller/linodeobjectstoragebucket_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodeobjectstoragebucket_controller.go#L259

Added line #L259 was not covered by tests
For(&infrav1alpha1.LinodeObjectStorageBucket{}).
Owns(&corev1.Secret{}).
WithEventFilter(predicate.And(
predicates.ResourceHasFilterLabel(mgr.GetLogger(), r.WatchFilterValue),
predicate.GenerationChangedPredicate{},
)).
Complete(r)
Build(r)
if err != nil {
return fmt.Errorf("failed to build controller: %w", err)

Check warning on line 268 in controller/linodeobjectstoragebucket_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodeobjectstoragebucket_controller.go#L266-L268

Added lines #L266 - L268 were not covered by tests
}

linodeObjectStorageBucketMapper, err := kutil.ClusterToTypedObjectsMapper(r.Client, &infrav1alpha1.LinodeObjectStorageBucketList{}, mgr.GetScheme())
if err != nil {
return fmt.Errorf("failed to create mapper for LinodeObjectStorageBuckets: %w", err)

Check warning on line 273 in controller/linodeobjectstoragebucket_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodeobjectstoragebucket_controller.go#L271-L273

Added lines #L271 - L273 were not covered by tests
}

return controller.Watch(
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
handler.EnqueueRequestsFromMapFunc(linodeObjectStorageBucketMapper),
predicates.ClusterUnpausedAndInfrastructureReady(mgr.GetLogger()),
)

Check warning on line 280 in controller/linodeobjectstoragebucket_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodeobjectstoragebucket_controller.go#L276-L280

Added lines #L276 - L280 were not covered by tests
}
16 changes: 14 additions & 2 deletions controller/linodevpc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/tools/record"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
kutil "sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/predicates"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

infrav1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
"github.com/linode/cluster-api-provider-linode/cloud/scope"
Expand Down Expand Up @@ -264,7 +267,7 @@

// SetupWithManager sets up the controller with the Manager.
func (r *LinodeVPCReconciler) SetupWithManager(mgr ctrl.Manager) error {
_, err := ctrl.NewControllerManagedBy(mgr).
controller, err := ctrl.NewControllerManagedBy(mgr).

Check warning on line 270 in controller/linodevpc_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodevpc_controller.go#L270

Added line #L270 was not covered by tests
For(&infrav1alpha1.LinodeVPC{}).
WithEventFilter(
predicate.And(
Expand All @@ -280,5 +283,14 @@
return fmt.Errorf("failed to build controller: %w", err)
}

return nil
linodeVPCMapper, err := kutil.ClusterToTypedObjectsMapper(r.Client, &infrav1alpha1.LinodeVPCList{}, mgr.GetScheme())
if err != nil {
return fmt.Errorf("failed to create mapper for LinodeVPCs: %w", err)

Check warning on line 288 in controller/linodevpc_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodevpc_controller.go#L286-L288

Added lines #L286 - L288 were not covered by tests
}

return controller.Watch(
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
handler.EnqueueRequestsFromMapFunc(linodeVPCMapper),
predicates.ClusterUnpausedAndInfrastructureReady(mgr.GetLogger()),
)

Check warning on line 295 in controller/linodevpc_controller.go

View check run for this annotation

Codecov / codecov/patch

controller/linodevpc_controller.go#L291-L295

Added lines #L291 - L295 were not covered by tests
}
1 change: 1 addition & 0 deletions templates/addons/etcd-backup-restore/linode-obj.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ metadata:
app.kubernetes.io/part-of: cluster-api-provider-linode
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: cluster-api-provider-linode
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
name: ${CLUSTER_NAME}-etcd-backup
spec:
cluster: ${OBJ_BUCKET_REGION}
Expand Down
Loading