Skip to content

Commit

Permalink
Return "namespace not found" error to allow future reconciliation if …
Browse files Browse the repository at this point in the history
…namespace is created later

Signed-off-by: Rokibul Hasan <[email protected]>
  • Loading branch information
RokibulHasan7 committed Nov 13, 2024
1 parent f1f2f6f commit 78538c8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
5 changes: 1 addition & 4 deletions pkg/agent/controller/managedclusterrolebinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,10 @@ func (r *ManagedClusterRoleBindingReconciler) Reconcile(ctx context.Context, req
}
} else {
for _, ns := range managedCRB.RoleRef.Namespaces {
exist, err := utils.IsNamespaceExist(r.SpokeClient, ns)
_, err := utils.IsNamespaceExist(r.SpokeClient, ns)
if err != nil {
return reconcile.Result{}, err
}
if !exist {
continue
}

givenRolebinding := &rbac.RoleBinding{
TypeMeta: metav1.TypeMeta{
Expand Down
5 changes: 1 addition & 4 deletions pkg/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
authorizationv1alpha1 "github.com/kluster-manager/cluster-auth/apis/authorization/v1alpha1"

corev1 "k8s.io/api/core/v1"
kerr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -59,9 +58,7 @@ func ExtractServiceAccountNameAndNamespace(s string) (name, namespace string, er
func IsNamespaceExist(kc client.Client, name string) (bool, error) {
var ns corev1.Namespace
err := kc.Get(context.Background(), types.NamespacedName{Name: name}, &ns)
if err != nil && kerr.IsNotFound(err) {
return false, nil
} else if err != nil {
if err != nil {
return false, err
}
return true, nil
Expand Down

0 comments on commit 78538c8

Please sign in to comment.