-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
controllers: determine necessary condition to start reconciliation
use an init container to wait till either we are running standalone or alongside with odf configured in provider mode Signed-off-by: Leela Venkaiah G <[email protected]>
- Loading branch information
Showing
7 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,6 +177,7 @@ func (c *OperatorConfigMapReconciler) SetupWithManager(mgr ctrl.Manager) error { | |
//+kubebuilder:rbac:groups=console.openshift.io,resources=consoleplugins,verbs=* | ||
//+kubebuilder:rbac:groups=operators.coreos.com,resources=subscriptions,verbs=get;list;watch;update | ||
//+kubebuilder:rbac:groups=admissionregistration.k8s.io,resources=validatingwebhookconfigurations,verbs=get;list;update;create;watch;delete | ||
//+kubebuilder:rbac:groups=ocs.openshift.io,resources=storageclusters,verbs=get;list | ||
|
||
// For more details, check Reconcile and its Result here: | ||
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,98 @@ | ||
package main | ||
|
||
func main() {} | ||
import ( | ||
"context" | ||
"os" | ||
"time" | ||
|
||
"github.com/red-hat-storage/ocs-client-operator/pkg/utils" | ||
|
||
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
k8serrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/klog/v2" | ||
"k8s.io/utils/clock" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
) | ||
|
||
// delay can be represented as duration * (factor ^ steps) | ||
// below will delay for 8 min at last step | ||
var delay = wait.Backoff{ | ||
Duration: 500 * time.Millisecond, | ||
Factor: 1.1, | ||
Steps: 50, | ||
} | ||
|
||
const resetMinutes = 10 | ||
|
||
func main() { | ||
// validations | ||
operatorNamespace := os.Getenv(utils.OperatorNamespaceEnvVar) | ||
if operatorNamespace == "" { | ||
klog.Exitf("%s env var is empty", utils.OperatorNamespaceEnvVar) | ||
} | ||
|
||
// creation of kube client | ||
scheme := runtime.NewScheme() | ||
cfg, err := config.GetConfig() | ||
if err != nil { | ||
klog.Exitf("Failed to get config: %v", err) | ||
} | ||
cl, err := client.New(cfg, client.Options{Scheme: scheme}) | ||
if err != nil { | ||
klog.Exitf("Failed to create controller runtime client: %v", err) | ||
} | ||
ctx := context.Background() | ||
|
||
storageClusterCRD := &metav1.PartialObjectMetadata{} | ||
storageClusterCRD.SetGroupVersionKind( | ||
extv1.SchemeGroupVersion.WithKind("CustomResourceDefinition"), | ||
) | ||
storageClusterCRD.Name = "storageclusters.ocs.openshift.io" | ||
|
||
delayFunc := delay.DelayWithReset(clock.RealClock{}, resetMinutes*time.Minute) | ||
|
||
var canDeploy bool | ||
for { | ||
// verify presence of StorageCluster CRD | ||
if err = cl.Get(ctx, client.ObjectKeyFromObject(storageClusterCRD), storageClusterCRD); err != nil { | ||
if k8serrors.IsNotFound(err) { | ||
// we did not find StorageCluster CRD and can proceed with reconciliation | ||
klog.Info("StorageCluster CRD not found and proceeding with reconciliation of operands") | ||
canDeploy = true | ||
} | ||
} else { | ||
// StorageCluster CRD exists, wait till StorageCluster CR is configured in Provider mode | ||
storageClusters := &metav1.PartialObjectMetadataList{} | ||
storageClusters.SetGroupVersionKind( | ||
schema.GroupVersionKind{ | ||
Group: "ocs.openshift.io", | ||
Version: "v1", | ||
Kind: "StorageCluster", | ||
}, | ||
) | ||
if err = cl.List(ctx, storageClusters, client.InNamespace(operatorNamespace)); err == nil { | ||
for _, metadata := range storageClusters.Items { | ||
if metadata.GetAnnotations()["ocs.openshift.io/deployment-mode"] == "provider" { | ||
klog.Info("StorageCluster is configured to run in 'Provider' mode and proceeding with reconciliation of operands") | ||
canDeploy = true | ||
} | ||
} | ||
if len(storageClusters.Items) == 0 { | ||
klog.Info("Waiting for StorageCluster to be deployed") | ||
} else { | ||
klog.Info("Waiting for StorageCluster deployed mode to be 'Provider'") | ||
} | ||
} | ||
} | ||
|
||
if canDeploy { | ||
break | ||
} | ||
time.Sleep(delayFunc()) | ||
} | ||
} |