Skip to content

Commit 9f48ad2

Browse files
authored
enhance the delete logic (#48)
1 parent 76ab73d commit 9f48ad2

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

controllers/namespacescope_controller.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ func (r *NamespaceScopeReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
6464
// indicated by the deletion timestamp being set.
6565
if !instance.GetDeletionTimestamp().IsZero() {
6666
if util.Contains(instance.GetFinalizers(), constant.NamespaceScopeFinalizer) {
67-
if err := r.DeleteAllRbac(instance); err != nil {
67+
instance = r.setDefaults(instance)
68+
69+
if err := r.UpdateConfigMap(instance); err != nil {
6870
return ctrl.Result{}, err
6971
}
7072

71-
if err := r.UpdateConfigMap(instance); err != nil {
73+
if err := r.DeleteAllRbac(instance); err != nil {
7274
return ctrl.Result{}, err
7375
}
7476

@@ -698,14 +700,14 @@ func (r *NamespaceScopeReconciler) getValidatedNamespaces(instance *operatorv1.N
698700
}
699701
}
700702
if ns.Status.Phase == corev1.NamespaceTerminating {
701-
klog.Infof("Namespace %s is terminating. Ignore this namespace ", nsMem)
703+
klog.Infof("Namespace %s is terminating. Ignore this namespace", nsMem)
702704
continue
703705
}
704706
}
705707
validatedNs = append(validatedNs, nsMem)
706708
} else {
707-
klog.Infof("ibm-namespace-scope-operator has not admin permission in namespace %s", nsMem)
708-
r.Recorder.Eventf(instance, corev1.EventTypeWarning, "Forbidden", "ibm-namespace-scope-operator has not admin permission in namespace %s", nsMem)
709+
klog.Infof("ibm-namespace-scope-operator doesn't have admin permission in namespace %s", nsMem)
710+
r.Recorder.Eventf(instance, corev1.EventTypeWarning, "Forbidden", "ibm-namespace-scope-operator doesn't have admin permission in namespace %s", nsMem)
709711
}
710712
}
711713
return validatedNs, nil

scripts/authorize-namespace.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function help() {
2626
echo "WHERE:"
2727
echo " namespace: It is the name of the namespace you wish to authorize. This namespace MUST exist. "
2828
echo " By default, the current namespace is assumed"
29-
echo " -to namespace: It is the name of the namespace of the NamespaceScope operator that you want to authorize."
29+
echo " -to namespace: It is the name of the namespace of the NamespaceScope operator."
3030
echo " This namespace MUST exist. The default is ibm-common-services."
3131
echo " -delete: It removes the ability for the NamespaceScope operator in tonamespace to manage artifacts in the namespace."
3232
echo ""
@@ -130,11 +130,11 @@ fi
130130
#
131131
# Define a role for service accounts
132132
#
133-
cat <<EOF | oc apply -n $TONS -f -
133+
cat <<EOF | oc apply -n $TARGETNS -f -
134134
apiVersion: rbac.authorization.k8s.io/v1
135135
kind: Role
136136
metadata:
137-
name: nss-managed-role-from-$TARGETNS
137+
name: nss-managed-role-from-$TONS
138138
rules:
139139
- apiGroups:
140140
- "*"
@@ -147,17 +147,17 @@ EOF
147147
#
148148
# Bind the service account in the TO namespace to the Role in the target namespace
149149
#
150-
cat <<EOF | oc apply -n $TONS -f -
150+
cat <<EOF | oc apply -n $TARGETNS -f -
151151
kind: RoleBinding
152152
apiVersion: rbac.authorization.k8s.io/v1
153153
metadata:
154-
name: nss-managed-rolebinding-from-$TARGETNS
154+
name: nss-managed-role-from-$TONS
155155
subjects:
156156
- kind: ServiceAccount
157157
name: ibm-namespace-scope-operator
158-
namespace: $TARGETNS
158+
namespace: $TONS
159159
roleRef:
160160
kind: Role
161-
name: nss-managed-role-from-$TARGETNS
161+
name: nss-managed-role-from-$TONS
162162
apiGroup: rbac.authorization.k8s.io
163163
EOF

0 commit comments

Comments
 (0)