Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion controllers/bootstrap/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,19 @@ func (b *Bootstrap) DeployCertManagerCR() error {
// NamespaceScope resources include common-service, nss-managedby-odlm, nss-odlm-scope, and odlm-scope-managedby-odlm
func (b *Bootstrap) CleanNamespaceScopeResources() error {

// get namespace-scope ConfigMap in operatorNamespace
nssCmNs, err := util.GetNssCmNs(b.Reader, b.CSData.OperatorNs)
if err != nil {
klog.Errorf("Failed to get %s configmap: %v", constant.NamespaceScopeConfigmapName, err)
return err
} else if nssCmNs == nil && err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we do not need to check err == nil, it has been checked by err != nil already.

Suggested change
} else if nssCmNs == nil && err == nil {
} else if nssCmNs == nil {

klog.Infof("The %s configmap is not found in the %s namespace, skip cleaning up", constant.NamespaceScopeConfigmapName, b.CSData.OperatorNs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
klog.Infof("The %s configmap is not found in the %s namespace, skip cleaning up", constant.NamespaceScopeConfigmapName, b.CSData.OperatorNs)
klog.Infof("The %s configmap is not found in the %s namespace, skip cleaning the NamespaceScope resources", constant.NamespaceScopeConfigmapName, b.CSData.OperatorNs)

return nil
}

// If the topology is (NOT ALL NS Mode) and (NOT Simple) , return
if b.CSData.WatchNamespaces != "" && len(strings.Split(b.CSData.WatchNamespaces, ",")) > 1 {
if b.CSData.WatchNamespaces != "" && len(nssCmNs) > 1 {
klog.Infof("The topology is not All Namespaces Mode or Simple Topology, skip cleaning up")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
klog.Infof("The topology is not All Namespaces Mode or Simple Topology, skip cleaning up")
klog.Infof("The topology is not All Namespaces Mode or Simple Topology, skip cleaning the NamespaceScope resources")

return nil
}

Expand Down
6 changes: 4 additions & 2 deletions controllers/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,9 @@ func GetRequestNs(r client.Reader) (requestNs []string) {
func GetNssCmNs(r client.Reader, cpfsNamespace string) ([]string, error) {
nssConfigMap, err := GetCmOfNss(r, cpfsNamespace)
if err != nil {
if errors.IsNotFound(err) {
return nil, nil
}
return nil, err
}
nssNsMems, ok := nssConfigMap.Data["namespaces"]
Expand All @@ -745,7 +748,7 @@ func GetCmOfNss(r client.Reader, operatorNs string) (*corev1.ConfigMap, error) {
nssConfigmap := &corev1.ConfigMap{}

for {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just remove this for loop? I feel that this is not needed anymore

if err := utilwait.PollImmediate(time.Second*10, time.Second*60, func() (done bool, err error) {
if err := utilwait.PollImmediate(time.Second*5, time.Second*30, func() (done bool, err error) {
err = r.Get(context.TODO(), types.NamespacedName{Name: cmName, Namespace: cmNs}, nssConfigmap)
if err != nil {
if errors.IsNotFound(err) {
Expand All @@ -757,7 +760,6 @@ func GetCmOfNss(r client.Reader, operatorNs string) (*corev1.ConfigMap, error) {
}); err == nil {
break
} else {
klog.Errorf("Failed to get configmap %v/%v: %v", operatorNs, constant.NamespaceScopeConfigmapName, err)
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the for loop is removed, I believe we could simplify the code to

if err:= utilwait.PollImmediate(); err != nil {
    return nil, err
}

}
Expand Down
2 changes: 1 addition & 1 deletion controllers/webhooks/commonservice/validatingwebhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (

// +kubebuilder:webhook:path=/validate-operator-ibm-com-v3-commonservice,mutating=false,failurePolicy=fail,sideEffects=None,groups=operator.ibm.com,resources=commonservices,verbs=create;update,versions=v3,name=vcommonservice.kb.io,admissionReviewVersions=v1

// CommonServiceDefaulter points to correct ServiceNamespace
// CommonServiceDefaulter points to correct ServicesNamespace
type Defaulter struct {
Reader client.Reader
Client client.Client
Expand Down