diff --git a/controllers/checlusterbackup/backup_context.go b/controllers/checlusterbackup/backup_context.go index 59de05a89d..b3381b50f4 100644 --- a/controllers/checlusterbackup/backup_context.go +++ b/controllers/checlusterbackup/backup_context.go @@ -48,7 +48,7 @@ func NewBackupContext(r *ReconcileCheClusterBackup, backupCR *chev1.CheClusterBa // After the preparations, a new reconcile loop will be triggered, so backupServer will not be nil any more. } - cheCR, _, err := util.FindCheClusterCRInNamespace(r.client, namespace) + cheCR, _, err := util.FindCheClusterCRInNamespace(r.cachingClient, namespace) if err != nil { return nil, err } diff --git a/controllers/checlusterbackup/backup_data_collector.go b/controllers/checlusterbackup/backup_data_collector.go index d623a7c4f0..8df9277d06 100644 --- a/controllers/checlusterbackup/backup_data_collector.go +++ b/controllers/checlusterbackup/backup_data_collector.go @@ -60,7 +60,7 @@ func createBackupMetadataFile(bctx *BackupContext, destDir string) (bool, error) var appsDomain string if util.IsOpenShift { - host, err := util.GetRouterCanonicalHostname(bctx.r.client, bctx.namespace) + host, err := util.GetRouterCanonicalHostname(bctx.r.nonCachingClient, bctx.namespace) if err != nil { return false, err } @@ -129,7 +129,7 @@ func prepareDirectory(destDir string) error { func backupCheCR(bctx *BackupContext, destDir string) (bool, error) { cheCR := &orgv1.CheCluster{} namespacedName := types.NamespacedName{Namespace: bctx.namespace, Name: bctx.cheCR.GetName()} - if err := bctx.r.client.Get(context.TODO(), namespacedName, cheCR); err != nil { + if err := bctx.r.cachingClient.Get(context.TODO(), namespacedName, cheCR); err != nil { return false, err } util.ClearMetadata(&cheCR.ObjectMeta) @@ -221,7 +221,7 @@ func backupConfigMaps(bctx *BackupContext, destDir string) (bool, error) { } fakeDeployContext := &deploy.DeployContext{ - ClusterAPI: deploy.ClusterAPI{Client: bctx.r.client}, + ClusterAPI: deploy.ClusterAPI{Client: bctx.r.nonCachingClient}, CheCluster: bctx.cheCR, } caBundlesConfigmaps, err := deploy.GetCACertsConfigMaps(fakeDeployContext) @@ -268,7 +268,7 @@ func backupSecrets(bctx *BackupContext, destDir string) (bool, error) { for _, secretName := range secretsNames { secret := &corev1.Secret{} namespacedName := types.NamespacedName{Name: secretName, Namespace: bctx.namespace} - if err := bctx.r.client.Get(context.TODO(), namespacedName, secret); err != nil { + if err := bctx.r.nonCachingClient.Get(context.TODO(), namespacedName, secret); err != nil { return false, err } diff --git a/controllers/checlusterbackup/checlusterbackup_controller.go b/controllers/checlusterbackup/checlusterbackup_controller.go index 51a5ed5762..4305d4dc97 100644 --- a/controllers/checlusterbackup/checlusterbackup_controller.go +++ b/controllers/checlusterbackup/checlusterbackup_controller.go @@ -28,7 +28,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/source" ) @@ -43,15 +42,16 @@ const ( type ReconcileCheClusterBackup struct { // This client, initialized using mgr.Client() above, is a split client // that reads objects from the cache and writes to the apiserver - client client.Client - scheme *runtime.Scheme + cachingClient client.Client + nonCachingClient client.Client + scheme *runtime.Scheme // the namespace to which to limit the reconciliation. If empty, all namespaces are considered namespace string } // NewReconciler returns a new reconcile.Reconciler -func NewReconciler(mgr manager.Manager, namespace string) *ReconcileCheClusterBackup { - return &ReconcileCheClusterBackup{client: mgr.GetClient(), scheme: mgr.GetScheme(), namespace: namespace} +func NewReconciler(cachingClient client.Client, noncachingClient client.Client, scheme *runtime.Scheme, namespace string) *ReconcileCheClusterBackup { + return &ReconcileCheClusterBackup{cachingClient: cachingClient, nonCachingClient: noncachingClient, scheme: scheme, namespace: namespace} } // SetupWithManager sets up the controller with the Manager. @@ -92,7 +92,7 @@ func (r *ReconcileCheClusterBackup) SetupWithManager(mgr ctrl.Manager) error { func (r *ReconcileCheClusterBackup) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) { // Fetch the CheClusterBackup instance backupCR := &chev1.CheClusterBackup{} - err := r.client.Get(context.TODO(), request.NamespacedName, backupCR) + err := r.cachingClient.Get(context.TODO(), request.NamespacedName, backupCR) if err != nil { if errors.IsNotFound(err) { // Request object not found, could have been deleted after reconcile request. @@ -156,7 +156,7 @@ func (r *ReconcileCheClusterBackup) doReconcile(backupCR *chev1.CheClusterBackup if backupCR.Spec.BackupServerConfigRef != "" { backupServerConfigCR = &chev1.CheBackupServerConfiguration{} backupServerConfigNamespacedName := types.NamespacedName{Namespace: backupCR.GetNamespace(), Name: backupCR.Spec.BackupServerConfigRef} - if err := r.client.Get(context.TODO(), backupServerConfigNamespacedName, backupServerConfigCR); err != nil { + if err := r.cachingClient.Get(context.TODO(), backupServerConfigNamespacedName, backupServerConfigCR); err != nil { if errors.IsNotFound(err) { return true, fmt.Errorf("backup server configuration with name '%s' not found in '%s' namespace", backupCR.Spec.BackupServerConfigRef, backupCR.GetNamespace()) } @@ -198,7 +198,7 @@ func (r *ReconcileCheClusterBackup) doReconcile(backupCR *chev1.CheClusterBackup bctx.UpdateBackupStatusPhase() // Make sure, that backup server configuration in the CR is valid and cache cluster resources - done, err := bctx.backupServer.PrepareConfiguration(bctx.r.client, bctx.namespace) + done, err := bctx.backupServer.PrepareConfiguration(bctx.r.nonCachingClient, bctx.namespace) if err != nil || !done { return done, err } @@ -261,7 +261,7 @@ func (r *ReconcileCheClusterBackup) doReconcile(backupCR *chev1.CheClusterBackup } func (r *ReconcileCheClusterBackup) UpdateCR(cr *chev1.CheClusterBackup) error { - err := r.client.Update(context.TODO(), cr) + err := r.cachingClient.Update(context.TODO(), cr) if err != nil { logrus.Errorf("Failed to update %s CR: %s", cr.Name, err.Error()) return err @@ -270,7 +270,7 @@ func (r *ReconcileCheClusterBackup) UpdateCR(cr *chev1.CheClusterBackup) error { } func (r *ReconcileCheClusterBackup) UpdateCRStatus(cr *chev1.CheClusterBackup) error { - err := r.client.Status().Update(context.TODO(), cr) + err := r.cachingClient.Status().Update(context.TODO(), cr) if err != nil { logrus.Errorf("Failed to update %s CR status: %s", cr.Name, err.Error()) return err diff --git a/controllers/checlusterbackup/internal_backup_server.go b/controllers/checlusterbackup/internal_backup_server.go index 8bc7a9a0e4..e807a32162 100644 --- a/controllers/checlusterbackup/internal_backup_server.go +++ b/controllers/checlusterbackup/internal_backup_server.go @@ -67,7 +67,7 @@ func ensureInternalBackupServerDeploymentExist(bctx *BackupContext) (bool, error Namespace: bctx.namespace, Name: BackupServerDeploymentName, } - err := bctx.r.client.Get(context.TODO(), namespacedName, backupServerDeployment) + err := bctx.r.nonCachingClient.Get(context.TODO(), namespacedName, backupServerDeployment) if err == nil { return true, nil } @@ -78,7 +78,7 @@ func ensureInternalBackupServerDeploymentExist(bctx *BackupContext) (bool, error // Get default configuration of the backup server deployment backupServerDeployment = getBackupServerDeploymentSpec(bctx) // Create backup server deployment - err = bctx.r.client.Create(context.TODO(), backupServerDeployment) + err = bctx.r.nonCachingClient.Create(context.TODO(), backupServerDeployment) if err != nil { return false, err } @@ -149,7 +149,7 @@ func ensureInternalBackupServerPodReady(bctx *BackupContext) (bool, error) { if err != nil { return true, err } - _, err = backupServer.PrepareConfiguration(bctx.r.client, bctx.namespace) + _, err = backupServer.PrepareConfiguration(bctx.r.nonCachingClient, bctx.namespace) if err != nil { return true, err } @@ -172,7 +172,7 @@ func ensureInternalBackupServerServiceExists(bctx *BackupContext) (bool, error) Namespace: bctx.namespace, Name: backupServerServiceName, } - err := bctx.r.client.Get(context.TODO(), namespacedName, backupServerService) + err := bctx.r.nonCachingClient.Get(context.TODO(), namespacedName, backupServerService) if err == nil { // Backup server service already exists, do nothing return true, nil @@ -184,7 +184,7 @@ func ensureInternalBackupServerServiceExists(bctx *BackupContext) (bool, error) // Backup server service doesn't exists, create it backupServerService = getBackupServerServiceSpec(bctx) // Create backup server service - err = bctx.r.client.Create(context.TODO(), backupServerService) + err = bctx.r.nonCachingClient.Create(context.TODO(), backupServerService) if err != nil { return false, err } @@ -228,13 +228,13 @@ func ensureInternalBackupServerConfigurationExistAndCorrect(bctx *BackupContext) // Check if the internal backup server configuration exists internalBackupServerConfiguration := &chev1.CheBackupServerConfiguration{} namespacedName := types.NamespacedName{Namespace: bctx.namespace, Name: BackupServerConfigurationName} - err := bctx.r.client.Get(context.TODO(), namespacedName, internalBackupServerConfiguration) + err := bctx.r.cachingClient.Get(context.TODO(), namespacedName, internalBackupServerConfiguration) if err == nil { // Configuration exist, check if it is correct expectedInternalRestServerConfig := getExpectedInternalRestServerConfiguration(bctx) if *internalBackupServerConfiguration.Spec.Rest != *expectedInternalRestServerConfig { // Something is wrong in the configuration - if err := bctx.r.client.Delete(context.TODO(), internalBackupServerConfiguration); err != nil { + if err := bctx.r.cachingClient.Delete(context.TODO(), internalBackupServerConfiguration); err != nil { return false, err } // Reconcile to recreate the configuration @@ -249,7 +249,7 @@ func ensureInternalBackupServerConfigurationExistAndCorrect(bctx *BackupContext) // Create internal backup server configuration internalBackupServerConfiguration = getInternalBackupServerConfigurationSpec(bctx) - err = bctx.r.client.Create(context.TODO(), internalBackupServerConfiguration) + err = bctx.r.cachingClient.Create(context.TODO(), internalBackupServerConfiguration) if err != nil { return false, err } @@ -310,7 +310,7 @@ func ensureInternalBackupServerSecretExists(bctx *BackupContext) (bool, error) { Namespace: bctx.namespace, Name: bctx.backupServerConfigCR.Spec.Rest.RepositoryPasswordSecretRef, } - err := bctx.r.client.Get(context.TODO(), namespacedName, repoPasswordSecret) + err := bctx.r.nonCachingClient.Get(context.TODO(), namespacedName, repoPasswordSecret) if err == nil { return true, nil } @@ -320,7 +320,7 @@ func ensureInternalBackupServerSecretExists(bctx *BackupContext) (bool, error) { repoPassword := util.GeneratePasswd(12) repoPasswordSecret = getRepoPasswordSecretSpec(bctx, repoPassword) - err = bctx.r.client.Create(context.TODO(), repoPasswordSecret) + err = bctx.r.nonCachingClient.Create(context.TODO(), repoPasswordSecret) if err != nil { return false, err } diff --git a/controllers/checlusterrestore/backup_data_restorer.go b/controllers/checlusterrestore/backup_data_restorer.go index a85ddd6ffb..da282f1f3b 100644 --- a/controllers/checlusterrestore/backup_data_restorer.go +++ b/controllers/checlusterrestore/backup_data_restorer.go @@ -124,14 +124,14 @@ func cleanPreviousInstallation(rctx *RestoreContext, dataDir string) (bool, erro } // Delete Che CR to stop operator from dealing with current installation - actualCheCR, cheCRCount, err := util.FindCheClusterCRInNamespace(rctx.r.client, rctx.namespace) + actualCheCR, cheCRCount, err := util.FindCheClusterCRInNamespace(rctx.r.cachingClient, rctx.namespace) if cheCRCount == -1 { // error occurred while retreiving CheCluster CR return false, err } else if actualCheCR != nil { if actualCheCR.GetObjectMeta().GetDeletionTimestamp().IsZero() { logrus.Infof("Restore: Deleteing CheCluster custom resource in '%s' namespace", rctx.namespace) - err := rctx.r.client.Delete(context.TODO(), actualCheCR) + err := rctx.r.cachingClient.Delete(context.TODO(), actualCheCR) if err == nil { // Che CR is marked for deletion, but actually still exists. // Wait for finalizers and actual resource deletion (not found expected). @@ -161,45 +161,45 @@ func cleanPreviousInstallation(rctx *RestoreContext, dataDir string) (bool, erro // Delete all Che related deployments, but keep operator (excluded by name) and internal backup server (excluded by label) deploymentsList := &appsv1.DeploymentList{} - if err := rctx.r.client.List(context.TODO(), deploymentsList, cheResourcesListOptions); err != nil { + if err := rctx.r.nonCachingClient.List(context.TODO(), deploymentsList, cheResourcesListOptions); err != nil { return false, err } for _, deployment := range deploymentsList.Items { if strings.Contains(deployment.GetName(), cheFlavor+"-operator") { continue } - if err := rctx.r.client.Delete(context.TODO(), &deployment); err != nil && !errors.IsNotFound(err) { + if err := rctx.r.nonCachingClient.Delete(context.TODO(), &deployment); err != nil && !errors.IsNotFound(err) { return false, err } } // Delete all Che related secrets, but keep backup server ones (excluded by label) - if err := rctx.r.client.DeleteAllOf(context.TODO(), &corev1.Secret{}, client.InNamespace(rctx.namespace), cheResourcesMatchingLabelsSelector); err != nil { + if err := rctx.r.nonCachingClient.DeleteAllOf(context.TODO(), &corev1.Secret{}, client.InNamespace(rctx.namespace), cheResourcesMatchingLabelsSelector); err != nil { return false, err } // Delete all configmaps with custom CA certificates - if err := rctx.r.client.DeleteAllOf(context.TODO(), &corev1.ConfigMap{}, client.InNamespace(rctx.namespace), cheResourcesMatchingLabelsSelector); err != nil { + if err := rctx.r.nonCachingClient.DeleteAllOf(context.TODO(), &corev1.ConfigMap{}, client.InNamespace(rctx.namespace), cheResourcesMatchingLabelsSelector); err != nil { return false, err } // Delete all Che related config maps - if err := rctx.r.client.DeleteAllOf(context.TODO(), &corev1.ConfigMap{}, client.InNamespace(rctx.namespace), cheResourcesMatchingLabelsSelector); err != nil { + if err := rctx.r.nonCachingClient.DeleteAllOf(context.TODO(), &corev1.ConfigMap{}, client.InNamespace(rctx.namespace), cheResourcesMatchingLabelsSelector); err != nil { return false, err } // Delete all Che related ingresses / routes if rctx.isOpenShift { - err = rctx.r.client.DeleteAllOf(context.TODO(), &routev1.Route{}, client.InNamespace(rctx.namespace), cheResourcesMatchingLabelsSelector) + err = rctx.r.nonCachingClient.DeleteAllOf(context.TODO(), &routev1.Route{}, client.InNamespace(rctx.namespace), cheResourcesMatchingLabelsSelector) } else { - err = rctx.r.client.DeleteAllOf(context.TODO(), &networking.Ingress{}, client.InNamespace(rctx.namespace), cheResourcesMatchingLabelsSelector) + err = rctx.r.nonCachingClient.DeleteAllOf(context.TODO(), &networking.Ingress{}, client.InNamespace(rctx.namespace), cheResourcesMatchingLabelsSelector) } if err != nil { return false, err } // Delete all Che related persistent volumes - if err := rctx.r.client.DeleteAllOf(context.TODO(), &corev1.PersistentVolumeClaim{}, client.InNamespace(rctx.namespace), cheResourcesMatchingLabelsSelector); err != nil { + if err := rctx.r.nonCachingClient.DeleteAllOf(context.TODO(), &corev1.PersistentVolumeClaim{}, client.InNamespace(rctx.namespace), cheResourcesMatchingLabelsSelector); err != nil { return false, err } @@ -215,10 +215,10 @@ func deleteKeycloakPod(rctx *RestoreContext) (bool, error) { } keycloakPodNsN := types.NamespacedName{Name: keycloakPodName, Namespace: rctx.namespace} keycloakPod := &corev1.Pod{} - if err := rctx.r.client.Get(context.TODO(), keycloakPodNsN, keycloakPod); err != nil { + if err := rctx.r.nonCachingClient.Get(context.TODO(), keycloakPodNsN, keycloakPod); err != nil { return false, err } - if err := rctx.r.client.Delete(context.TODO(), keycloakPod); err != nil { + if err := rctx.r.nonCachingClient.Delete(context.TODO(), keycloakPod); err != nil { return false, err } return true, nil @@ -264,15 +264,15 @@ func restoreConfigMaps(rctx *RestoreContext, dataDir string) (bool, error) { configMap.ObjectMeta.Namespace = rctx.namespace - if err := rctx.r.client.Create(context.TODO(), configMap); err != nil { + if err := rctx.r.nonCachingClient.Create(context.TODO(), configMap); err != nil { if !errors.IsAlreadyExists(err) { return false, err } - if err := rctx.r.client.Delete(context.TODO(), configMap); err != nil { + if err := rctx.r.nonCachingClient.Delete(context.TODO(), configMap); err != nil { return false, err } - if err := rctx.r.client.Create(context.TODO(), configMap); err != nil { + if err := rctx.r.nonCachingClient.Create(context.TODO(), configMap); err != nil { return false, err } } @@ -306,15 +306,15 @@ func restoreSecrets(rctx *RestoreContext, dataDir string) (bool, error) { secret.ObjectMeta.Namespace = rctx.namespace secret.ObjectMeta.OwnerReferences = nil - if err := rctx.r.client.Create(context.TODO(), secret); err != nil { + if err := rctx.r.nonCachingClient.Create(context.TODO(), secret); err != nil { if !errors.IsAlreadyExists(err) { return false, err } - if err := rctx.r.client.Delete(context.TODO(), secret); err != nil { + if err := rctx.r.nonCachingClient.Delete(context.TODO(), secret); err != nil { return false, err } - if err := rctx.r.client.Create(context.TODO(), secret); err != nil { + if err := rctx.r.nonCachingClient.Create(context.TODO(), secret); err != nil { return false, err } } @@ -329,7 +329,7 @@ func restoreCheCR(rctx *RestoreContext, dataDir string) (bool, error) { return done, err } - if err := rctx.r.client.Create(context.TODO(), cheCR); err != nil { + if err := rctx.r.cachingClient.Create(context.TODO(), cheCR); err != nil { if errors.IsAlreadyExists(err) { // We should take into account that every step can be executed several times due to async behavior. // 1. We ensured that CheCluster is removed before restoring. @@ -499,7 +499,7 @@ func getDatabaseOwner(rctx *RestoreContext, dbName string) (string, error) { Name: rctx.cheCR.Spec.Database.ChePostgresSecret, Namespace: rctx.namespace, } - if err := rctx.r.client.Get(context.TODO(), chePostgresCredentialSecretNsN, secret); err != nil { + if err := rctx.r.nonCachingClient.Get(context.TODO(), chePostgresCredentialSecretNsN, secret); err != nil { return "", err } return string(secret.Data["user"]), nil @@ -533,7 +533,7 @@ func getPatchDatabaseScript(rctx *RestoreContext, dbName string, dataDir string) newNamespace := rctx.namespace appsDomain := "" if rctx.isOpenShift { - appsDomain, err = util.GetRouterCanonicalHostname(rctx.r.client, rctx.namespace) + appsDomain, err = util.GetRouterCanonicalHostname(rctx.r.nonCachingClient, rctx.namespace) if err != nil { return "", err } diff --git a/controllers/checlusterrestore/checlusterrestore_controller.go b/controllers/checlusterrestore/checlusterrestore_controller.go index 2953290eeb..256003af51 100644 --- a/controllers/checlusterrestore/checlusterrestore_controller.go +++ b/controllers/checlusterrestore/checlusterrestore_controller.go @@ -28,7 +28,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/source" ) @@ -41,15 +40,16 @@ const ( type ReconcileCheClusterRestore struct { // This client, initialized using mgr.Client() above, is a split client // that reads objects from the cache and writes to the apiserver - client client.Client - scheme *runtime.Scheme + cachingClient client.Client + nonCachingClient client.Client + scheme *runtime.Scheme // the namespace to which to limit the reconciliation. If empty, all namespaces are considered namespace string } // NewReconciler returns a new reconcile.Reconciler -func NewReconciler(mgr manager.Manager, namespace string) *ReconcileCheClusterRestore { - return &ReconcileCheClusterRestore{client: mgr.GetClient(), scheme: mgr.GetScheme(), namespace: namespace} +func NewReconciler(cachingClient client.Client, noncachingClient client.Client, scheme *runtime.Scheme, namespace string) *ReconcileCheClusterRestore { + return &ReconcileCheClusterRestore{cachingClient: cachingClient, nonCachingClient: noncachingClient, scheme: scheme, namespace: namespace} } func (r *ReconcileCheClusterRestore) SetupWithManager(mgr ctrl.Manager) error { @@ -89,7 +89,7 @@ func (r *ReconcileCheClusterRestore) SetupWithManager(mgr ctrl.Manager) error { func (r *ReconcileCheClusterRestore) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) { // Fetch the CheClusterRestore instance restoreCR := &chev1.CheClusterRestore{} - err := r.client.Get(context.TODO(), request.NamespacedName, restoreCR) + err := r.cachingClient.Get(context.TODO(), request.NamespacedName, restoreCR) if err != nil { if errors.IsNotFound(err) { // Request object not found, could have been deleted after reconcile request. @@ -149,7 +149,7 @@ func (r *ReconcileCheClusterRestore) doReconcile(restoreCR *chev1.CheClusterRest // Try to find backup server configuration in the same namespace cheBackupServersConfigurationList := &chev1.CheBackupServerConfigurationList{} listOptions := &client.ListOptions{Namespace: restoreCR.GetNamespace()} - if err := r.client.List(context.TODO(), cheBackupServersConfigurationList, listOptions); err != nil { + if err := r.cachingClient.List(context.TODO(), cheBackupServersConfigurationList, listOptions); err != nil { return false, err } if len(cheBackupServersConfigurationList.Items) != 1 { @@ -159,7 +159,7 @@ func (r *ReconcileCheClusterRestore) doReconcile(restoreCR *chev1.CheClusterRest } backupServerConfigCR = &chev1.CheBackupServerConfiguration{} backupServerConfigNamespacedName := types.NamespacedName{Namespace: restoreCR.GetNamespace(), Name: backupServerConfigName} - if err := r.client.Get(context.TODO(), backupServerConfigNamespacedName, backupServerConfigCR); err != nil { + if err := r.cachingClient.Get(context.TODO(), backupServerConfigNamespacedName, backupServerConfigCR); err != nil { if errors.IsNotFound(err) { return true, fmt.Errorf("backup server configuration with name '%s' not found in '%s' namespace", restoreCR.Spec.BackupServerConfigRef, restoreCR.GetNamespace()) } @@ -185,7 +185,7 @@ func (r *ReconcileCheClusterRestore) doReconcile(restoreCR *chev1.CheClusterRest } // Makrctxe sure, that backup server configuration in the CR is valid and cache cluster resources - done, err = rctx.backupServer.PrepareConfiguration(rctx.r.client, rctx.namespace) + done, err = rctx.backupServer.PrepareConfiguration(rctx.r.nonCachingClient, rctx.namespace) if err != nil || !done { return done, err } @@ -242,7 +242,7 @@ func (r *ReconcileCheClusterRestore) doReconcile(restoreCR *chev1.CheClusterRest } func (r *ReconcileCheClusterRestore) UpdateCR(cr *chev1.CheClusterRestore) error { - err := r.client.Update(context.TODO(), cr) + err := r.cachingClient.Update(context.TODO(), cr) if err != nil { logrus.Errorf("Failed to update %s CR: %s", cr.Name, err.Error()) return err @@ -251,7 +251,7 @@ func (r *ReconcileCheClusterRestore) UpdateCR(cr *chev1.CheClusterRestore) error } func (r *ReconcileCheClusterRestore) UpdateCRStatus(cr *chev1.CheClusterRestore) error { - err := r.client.Status().Update(context.TODO(), cr) + err := r.cachingClient.Status().Update(context.TODO(), cr) if err != nil { logrus.Errorf("Failed to update %s CR status: %s", cr.Name, err.Error()) return err diff --git a/controllers/checlusterrestore/restore_context.go b/controllers/checlusterrestore/restore_context.go index c2659e98cb..d7e049a92d 100644 --- a/controllers/checlusterrestore/restore_context.go +++ b/controllers/checlusterrestore/restore_context.go @@ -38,7 +38,7 @@ func NewRestoreContext(r *ReconcileCheClusterRestore, restoreCR *chev1.CheCluste return nil, err } - cheCR, CRCount, err := util.FindCheClusterCRInNamespace(r.client, namespace) + cheCR, CRCount, err := util.FindCheClusterCRInNamespace(r.cachingClient, namespace) if err != nil { // Check if Che CR is present if CRCount > 0 { diff --git a/main.go b/main.go index ac85322831..faeff64e69 100644 --- a/main.go +++ b/main.go @@ -245,8 +245,8 @@ func main() { } cheReconciler := checontroller.NewReconciler(mgr.GetClient(), noncachedClient, discoveryClient, mgr.GetScheme(), watchNamespace) - backupReconciler := backupcontroller.NewReconciler(mgr, watchNamespace) - restoreReconciler := restorecontroller.NewReconciler(mgr, watchNamespace) + backupReconciler := backupcontroller.NewReconciler(mgr.GetClient(), noncachedClient, mgr.GetScheme(), watchNamespace) + restoreReconciler := restorecontroller.NewReconciler(mgr.GetClient(), noncachedClient, mgr.GetScheme(), watchNamespace) if err = cheReconciler.SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to set up controller", "controller", "CheCluster")