Skip to content

Commit

Permalink
fix: prevent reinstallation of CRDs when module disabled (kyma-projec…
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilos77 authored Sep 25, 2024
1 parent 86c67e1 commit 901e436
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions pkg/skr/runtime/looper/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type checker struct {
}

func (c *checker) IsReady(ctx context.Context, skrCluster cluster.Cluster) bool {
timeout := time.Now().Add(time.Second * 3)
timeout := time.Now().Add(time.Millisecond * 3500)
interval := time.Second
for {
select {
Expand All @@ -40,11 +40,42 @@ func (c *checker) IsReady(ctx context.Context, skrCluster cluster.Cluster) bool
}
}

// singleCheck returns true if it is ok to proceed with SKR connection that implies installation of CRDs and
// running controllers. It is important to consider both provisioning and deprovisioning phase:
// * Provisioning
// - CloudResources CRD is not yet installed by KLM
// - CloudResources default instance is not yet created by KLM
//
// * Deprovisioning
// - There are no CloudResources instances since they all have been deleted - KLM marked for deletion,
// CloudManager connected to SKR and uninstalled CRDs and removed finalized, K8S deleted CloudResources.
// If CloudManager connects again before the KCP Scope is reconciled and this SKR removed from active
// we must ensure connection does not proceed and installs CRDs again.
// - There is CloudResources instance, but it's marked for deletion and has no finalizer since CloudManager
// already have connected, deleted CRDs and removed finalizer, and now K8S API should delete this resource.
// Not sure if practically possible, but implementing it just in case.
func (c *checker) singleCheck(ctx context.Context, skrCluster cluster.Cluster) bool {
list := &cloudresourcesv1beta1.CloudResourcesList{}
err := skrCluster.GetAPIReader().List(ctx, list)
if err != nil {
c.logger.Error(err, "SKR readiness failed")
c.logger.Error(err, "SKR readiness failed - CloudResources CRD not installed")
return false
}
if len(list.Items) == 0 {
c.logger.Error(err, "SKR readiness failed - no CloudResources created")
return false
}
allDeletedAndNoFinalizer := true
for _, item := range list.Items {
// has deletion timestamp and has no finalizers
if !item.DeletionTimestamp.IsZero() && len(item.Finalizers) == 0 {
continue
}
allDeletedAndNoFinalizer = false
break
}
if allDeletedAndNoFinalizer {
c.logger.Error(err, "SKR readiness failed - all CloudResources instances are being deleted and have no finalizer")
return false
}
return true
Expand Down

0 comments on commit 901e436

Please sign in to comment.