Skip to content

Commit

Permalink
fix: properly cleanup tearing down exposed services
Browse files Browse the repository at this point in the history
The controller was missing to remove some `ExposedService`s, because the code path triggered by the `DestroyReady` phase input did not reach any cleanup code.

Rework the `ExposedService` cleanup code slightly to also remove the `DestroyReady` resources.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
  • Loading branch information
utkuozdemir committed Aug 14, 2024
1 parent 0bec3e4 commit dd510e9
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ func (ctrl *KubernetesStatusController) reconcileRunners(ctx context.Context, r
}
}

// cleanup exposed services for cluster which do not have secrets
// cleanup exposed services which are
// - either destroy ready
// - or clusters which do not have secrets
if err := ctrl.cleanupExposedServices(ctx, r, secretsPresent); err != nil {
return fmt.Errorf("error destroying exposed services: %w", err)
}
Expand All @@ -468,17 +470,40 @@ func (ctrl *KubernetesStatusController) cleanupExposedServices(ctx context.Conte
return fmt.Errorf("error listing exposed services: %w", err)
}

shouldDestroy := func(res *omni.ExposedService) bool {
if res.Metadata().Phase() == resource.PhaseTearingDown {
return res.Metadata().Finalizers().Empty()
}

exposedServiceCluster, ok := res.Metadata().Labels().Get(omni.LabelCluster)
if !ok {
return false
}

if _, ok = keepClustersSet[exposedServiceCluster]; ok {
return false
}

return true
}

var multiErr error

for iter := exposedServices.Iterator(); iter.Next(); {
exposedService := iter.Value()

exposedServiceCluster, ok := exposedService.Metadata().Labels().Get(omni.LabelCluster)
if !ok {
if !shouldDestroy(exposedService) {
continue
}

if _, ok = keepClustersSet[exposedServiceCluster]; ok {
destroyReady, teardownErr := r.Teardown(ctx, exposedService.Metadata())
if teardownErr != nil {
multiErr = multierror.Append(multiErr, fmt.Errorf("error tearing down exposed service: %w", teardownErr))

continue
}

if !destroyReady {
continue
}

Expand Down

0 comments on commit dd510e9

Please sign in to comment.