Skip to content
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
32 changes: 7 additions & 25 deletions controllers/bootstrap/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,33 +282,15 @@ func (b *Bootstrap) CreateCsCR() error {

if len(b.CSData.WatchNamespaces) == 0 {
// All Namespaces Mode:
// using `ibm-common-services` ns as ServicesNs if it exists
// Otherwise, do not create default CR
// Tolerate if someone manually create the default CR in operator NS
defaultCRReady := false
for !defaultCRReady {
_, err := b.GetObject(cs)
if errors.IsNotFound(err) {
ctx := context.Background()
ns := &corev1.Namespace{}
if err := b.Reader.Get(ctx, types.NamespacedName{Name: constant.MasterNamespace}, ns); err != nil {
if errors.IsNotFound(err) {
klog.Warningf("Not found well-known default namespace %v, please manually create the namespace", constant.MasterNamespace)
time.Sleep(10 * time.Second)
continue
}
return err
}
b.CSData.ServicesNs = constant.MasterNamespace
return b.renderTemplate(constant.CsCR, b.CSData)
} else if err != nil {
return err
}
defaultCRReady = true
// using `ibm-common-services` ns as ServicesNs if CS CR does not exist
if _, err := b.GetObject(cs); errors.IsNotFound(err) {
b.CSData.ServicesNs = constant.MasterNamespace
return b.renderTemplate(constant.CsCR, b.CSData)
} else if err != nil {
return err
}
} else {
_, err := b.GetObject(cs)
if errors.IsNotFound(err) { // Only if it's a fresh install
if _, err := b.GetObject(cs); errors.IsNotFound(err) { // Only if it's a fresh install
// Fresh Intall: No ODLM and NO CR
return b.renderTemplate(constant.CsCR, b.CSData)
} else if err != nil {
Expand Down
17 changes: 15 additions & 2 deletions controllers/commonservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (r *CommonServiceReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}
return ctrl.Result{}, client.IgnoreNotFound(err)
}
return r.ReconileNonConfigurableCR(ctx, instance)
return r.ReconcileNonConfigurableCR(ctx, instance)
}

if err := r.Bootstrap.Client.Get(ctx, req.NamespacedName, instance); err != nil {
Expand Down Expand Up @@ -171,6 +171,19 @@ func (r *CommonServiceReconciler) ReconcileMasterCR(ctx context.Context, instanc
os.Exit(1)
}
}
} else {
// check if the servicesNamespace is created
ns := &corev1.Namespace{}
if err := r.Reader.Get(ctx, types.NamespacedName{Name: r.Bootstrap.CSData.ServicesNs}, ns); err != nil {
if errors.IsNotFound(err) {
klog.Errorf("Not found servicesNamespace %s specified in the common-service CR.", r.Bootstrap.CSData.ServicesNs)
if err := r.updatePhase(ctx, instance, CRFailed); err != nil {
klog.Error(err)
}
klog.Errorf("Fail to reconcile %s/%s: %v", instance.Namespace, instance.Name, err)
return ctrl.Result{}, err
}
}
}

typeCorrect, err := r.Bootstrap.CheckClusterType(util.GetServicesNamespace(r.Reader))
Expand Down Expand Up @@ -344,7 +357,7 @@ func (r *CommonServiceReconciler) ReconcileGeneralCR(ctx context.Context, instan
}

// ReconileNonConfigurableCR is for setting the cloned Master CR status for advanced topologies
func (r *CommonServiceReconciler) ReconileNonConfigurableCR(ctx context.Context, instance *apiv3.CommonService) (ctrl.Result, error) {
func (r *CommonServiceReconciler) ReconcileNonConfigurableCR(ctx context.Context, instance *apiv3.CommonService) (ctrl.Result, error) {

if instance.Status.Phase == "" {
if err := r.updatePhase(ctx, instance, CRInitializing); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions controllers/operandconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ func (r *CommonServiceReconciler) updateOperandConfig(ctx context.Context, newCo
namespace = opconKey.Namespace
}

if newConfigForOperator.(map[string]interface{})["resources"] == nil {
continue
}

newResource := getItemByGVKNameNamespace(newConfigForOperator.(map[string]interface{})["resources"].([]interface{}), opconKey.Namespace, apiVersion, kind, name, namespace)
if newResource != nil {
opResources[i] = mergeCRsIntoOperandConfigWithDefaultRules(opResource.(map[string]interface{}), newResource.(map[string]interface{}))
Expand Down
18 changes: 1 addition & 17 deletions controllers/webhooks/commonservice/validatingwebhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (

// certmanagerv1alpha1 "github.com/ibm/ibm-cert-manager-operator/apis/certmanager/v1alpha1"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -138,21 +136,7 @@ func (r *Defaulter) CheckNamespace(name string) (bool, error) {
if name == "" {
return false, nil
}
// in cluster scope
if len(watchNamespaces) == 0 {
ctx := context.Background()
ns := &corev1.Namespace{}
nsKey := types.NamespacedName{
Name: name,
}
// check if this namespace exist
if err := r.Client.Get(ctx, nsKey, ns); err != nil {
klog.Errorf("Failed to get namespace %v: %v", name, err)
return true, err

}
// if it is not cluster scope
} else if len(watchNamespaces) != 0 && !util.Contains(strings.Split(watchNamespaces, ","), name) {
if len(watchNamespaces) != 0 && !util.Contains(strings.Split(watchNamespaces, ","), name) {
denied = true
}
return denied, nil
Expand Down