Skip to content

Commit 3a1686d

Browse files
fix: reconcile AccessRequests only if labels are set (#59)
* fix: reconcile `AccessRequests` only if labels are set * fix(accessrequest): add nil check for empty cluster reference * fix: typo * fix: sort imports
1 parent 7da37fb commit 3a1686d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

internal/controller/accessrequest_controller.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"errors"
2222
"fmt"
2323

24+
"sigs.k8s.io/controller-runtime/pkg/predicate"
25+
2426
corev1 "k8s.io/api/core/v1"
2527
apierrors "k8s.io/apimachinery/pkg/api/errors"
2628
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -34,6 +36,8 @@ import (
3436
clustersv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
3537
commonapi "github.com/openmcp-project/openmcp-operator/api/common"
3638

39+
ctrlutils "github.com/openmcp-project/controller-utils/pkg/controller"
40+
3741
"github.com/openmcp-project/cluster-provider-kind/pkg/kind"
3842
)
3943

@@ -67,6 +71,10 @@ func (r *AccessRequestReconciler) Reconcile(ctx context.Context, req ctrl.Reques
6771

6872
defer r.Status().Update(ctx, ar) //nolint:errcheck
6973

74+
if ar.Spec.ClusterRef == nil {
75+
return ctrl.Result{}, fmt.Errorf("AccessRequest %q/%q has no Cluster reference", ar.Namespace, ar.Name)
76+
}
77+
7078
clusterRef := types.NamespacedName{Name: ar.Spec.ClusterRef.Name, Namespace: ar.Namespace}
7179
cluster := &clustersv1alpha1.Cluster{}
7280
if err := r.Get(ctx, clusterRef, cluster); err != nil {
@@ -75,7 +83,7 @@ func (r *AccessRequestReconciler) Reconcile(ctx context.Context, req ctrl.Reques
7583
}
7684

7785
if !isClusterProviderResponsible(cluster) {
78-
return ctrl.Result{}, fmt.Errorf("profile '%s' is not supported by kind controller", cluster.Spec.Profile)
86+
return ctrl.Result{}, fmt.Errorf("ClusterProfile '%s' is not supported by kind controller", cluster.Spec.Profile)
7987
}
8088

8189
// handle deletion
@@ -149,6 +157,10 @@ func getSecretNamespacedName(ar *clustersv1alpha1.AccessRequest) types.Namespace
149157
func (r *AccessRequestReconciler) SetupWithManager(mgr ctrl.Manager) error {
150158
return ctrl.NewControllerManagedBy(mgr).
151159
For(&clustersv1alpha1.AccessRequest{}).
160+
WithEventFilter(predicate.And(
161+
ctrlutils.HasLabelPredicate(clustersv1alpha1.ProviderLabel, "kind"),
162+
ctrlutils.HasLabelPredicate(clustersv1alpha1.ProfileLabel, ""),
163+
)).
152164
Named("accessrequest").
153165
Complete(r)
154166
}

0 commit comments

Comments
 (0)