Skip to content

Commit

Permalink
Client cache invalidation when remote cluster is unreachable (kyma-pr…
Browse files Browse the repository at this point in the history
…oject#806)

* invalidate client cache on remote cluster connection failure

* Add E2E test

* fix typo

* fix test

* fix test

* fix test

* Empty commit

* debug test

* Empty commit

* Empty commit

* debug test

* debug test

* Empty commit

* Empty commit

* debug test

* debug test

* debug test

* Empty commit

* Empty commit

* debug test

* debug test

* debug test

* Empty commit

* Empty commit

* debug test

* Empty commit

* Empty commit

* debug test

* debug test

* Empty commit

* remove merge command

* remove rewriting the skr config to github env file

* code review

* code review

* code review

* code review

* code review

* Empty commit

* code review

* code review

* fix

* fix

* fix
  • Loading branch information
nesmabadr authored Aug 17, 2023
1 parent e76fb55 commit af8099f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
29 changes: 13 additions & 16 deletions controllers/kyma_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,42 +121,39 @@ func (r *KymaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
return r.reconcile(ctx, kyma)
}

func (r *KymaReconciler) handleRemoteClusterConnectionErrorOnDeletion(
ctx context.Context, kyma *v1beta2.Kyma, err error) (
ctrl.Result, error,
) {
func (r *KymaReconciler) handleRemoteClusterConnectionError(
ctx context.Context, kyma *v1beta2.Kyma, err error,
) error {
if util.IsConnectionRefused(err) {
r.RemoteClientCache.Del(client.ObjectKeyFromObject(kyma))
return err
}

if !kyma.DeletionTimestamp.IsZero() {
if util.IsConnectionRefused(err) {
r.RemoteClientCache.Del(client.ObjectKeyFromObject(kyma))
return r.requeueWithError(ctx, kyma, err)
}
if util.IsNotFound(err) {
if err = r.removeFinalizerAndUpdateKyma(ctx, kyma); err != nil {
return r.requeueWithError(ctx, kyma, err)
}
return ctrl.Result{}, nil
return r.removeFinalizerAndUpdateKyma(ctx, kyma)
}
}

r.enqueueWarningEvent(kyma, syncContextError, err)
return r.requeueWithError(ctx, kyma, err)
return err
}

func (r *KymaReconciler) reconcile(ctx context.Context, kyma *v1beta2.Kyma) (ctrl.Result, error) {
if r.SyncKymaEnabled(kyma) {
var err error
remoteClient := remote.NewClientWithConfig(r.Client, r.KcpRestConfig)
if ctx, err = remote.InitializeSyncContext(ctx, kyma,
r.RemoteSyncNamespace, remoteClient, r.RemoteClientCache); err != nil {
return r.handleRemoteClusterConnectionErrorOnDeletion(ctx, kyma, err)
r.RemoteSyncNamespace, remoteClient, r.RemoteClientCache); err != nil &&
r.handleRemoteClusterConnectionError(ctx, kyma, err) != nil {
return r.requeueWithError(ctx, kyma, err)
}
}

if !kyma.DeletionTimestamp.IsZero() && kyma.Status.State != v1beta2.StateDeleting {
if err := r.deleteRemoteKyma(ctx, kyma); err != nil {
return r.requeueWithError(ctx, kyma, err)
}

if err := r.updateStatus(ctx, kyma, v1beta2.StateDeleting, "waiting for modules to be deleted"); err != nil {
return r.requeueWithError(ctx, kyma, fmt.Errorf("could not update kyma status after triggering deletion: %w", err))
}
Expand Down
34 changes: 32 additions & 2 deletions tests/e2e_test/kyma_deletion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,45 @@ var _ = Describe("KCP Kyma CR should be deleted successfully when SKR cluster ge
WithContext(ctx).
WithArguments(kyma.GetName(), kyma.GetNamespace(), controlPlaneClient).
Should(Succeed())
})

It("Should delete KCP Kyma", func() {
By("Kyma should be in Error state")
Eventually(CheckKymaIsInState, readyTimeout, interval).
WithContext(ctx).
WithArguments(kyma.GetName(), kyma.GetNamespace(), controlPlaneClient, v1beta2.StateError).
Should(Succeed())
})

It("Should recreate SKR cluster and its secret", func() {
By("Creating SKR cluster")
cmd := exec.Command("k3d", "cluster", "create", "skr")
out, err := cmd.CombinedOutput()
Expect(err).NotTo(HaveOccurred())
GinkgoWriter.Printf(string(out))

cmd = exec.Command("k3d", "kubeconfig", "write", "skr")
out, err = cmd.CombinedOutput()
Expect(err).NotTo(HaveOccurred())
GinkgoWriter.Printf(string(out))

controlPlaneConfig, runtimeConfig, err = getKubeConfigs()
Expect(err).ToNot(HaveOccurred())

By("Creating Kyma secret")
Eventually(CreateKymaSecret, timeout, interval).
WithContext(ctx).
WithArguments(kyma.GetName(), kyma.GetNamespace(), controlPlaneClient).
Should(Succeed())
})

It("Kyma should be in Ready state after secret is re-fetched", func() {
By("Kyma should be in Ready state")
Eventually(CheckKymaIsInState, readyTimeout, interval).
WithContext(ctx).
WithArguments(kyma.GetName(), kyma.GetNamespace(), controlPlaneClient, v1beta2.StateReady).
Should(Succeed())
})

It("Should delete KCP Kyma", func() {
By("Deleting KCP Kyma")
Eventually(controlPlaneClient.Delete, readyTimeout, interval).
WithContext(ctx).
Expand Down

0 comments on commit af8099f

Please sign in to comment.