Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execution controller deletes deploy items during delete without uninstall #810

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/deployer/lib/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ func (c *controller) delete(ctx context.Context, lsCtx *lsv1alpha1.Context, depl
rt *lsv1alpha1.ResolvedTarget) lserrors.LsError {
logger, ctx := logging.FromContextOrNew(ctx, nil)
if lsv1alpha1helper.HasDeleteWithoutUninstallAnnotation(deployItem.ObjectMeta) {
// this case is not required anymore because those items are removed by the execution controller
// but for security reasons not removed
logger.Info("Deleting deployitem %s without uninstall", deployItem.Name)
} else {
if err := c.deployer.Delete(ctx, lsCtx, deployItem, rt); err != nil {
Expand Down
12 changes: 12 additions & 0 deletions pkg/landscaper/execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"context"
"fmt"

lc "github.com/gardener/landscaper/controller-utils/pkg/logging/constants"

"github.com/gardener/landscaper/pkg/utils"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -65,6 +67,8 @@ func (o *Operation) UpdateDeployItems(ctx context.Context) lserrors.LsError {
}

func (o *Operation) TriggerDeployItems(ctx context.Context) (*DeployItemClassification, lserrors.LsError) {
logger, ctx := logging.FromContextOrNew(ctx, nil, lc.KeyMethod, "TriggerDeployItems")

items, orphaned, lsErr := o.getDeployItems(ctx)
if lsErr != nil {
return nil, lsErr
Expand All @@ -87,6 +91,7 @@ func (o *Operation) TriggerDeployItems(ctx context.Context) (*DeployItemClassifi
}

if skip {
logger.Info("Deleting deployitem %s without uninstall", item.DeployItem.Name)
if err := o.removeFinalizerFromDeployItem(ctx, item.DeployItem); err != nil {
return nil, err
}
Expand Down Expand Up @@ -121,6 +126,8 @@ func (o *Operation) TriggerDeployItems(ctx context.Context) (*DeployItemClassifi
}

func (o *Operation) TriggerDeployItemsForDelete(ctx context.Context) (*DeployItemClassification, lserrors.LsError) {
logger, ctx := logging.FromContextOrNew(ctx, nil, lc.KeyMethod, "TriggerDeployItemsForDelete")

op := "TriggerDeployItemsForDelete"

items, _, lsErr := o.getDeployItems(ctx)
Expand Down Expand Up @@ -153,6 +160,7 @@ func (o *Operation) TriggerDeployItemsForDelete(ctx context.Context) (*DeployIte
}

if skip {
logger.Info("Deleting deployitem %s without uninstall", item.DeployItem.Name)
if err := o.removeFinalizerFromDeployItem(ctx, item.DeployItem); err != nil {
return nil, err
}
Expand Down Expand Up @@ -189,6 +197,10 @@ func (o *Operation) triggerDeployItem(ctx context.Context, di *lsv1alpha1.Deploy
func (o *Operation) skipUninstall(ctx context.Context, di *lsv1alpha1.DeployItem) (bool, lserrors.LsError) {
op := "skipUninstall"

if lsv1alpha1helper.HasDeleteWithoutUninstallAnnotation(di.ObjectMeta) {
return true, nil
}

if di.Spec.OnDelete == nil || !di.Spec.OnDelete.SkipUninstallIfClusterRemoved || di.Spec.Target == nil {
return false, nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/utils/constants.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package utils

import (
"github.com/gardener/landscaper/controller-utils/pkg/logging"
"os"
"strconv"

"github.com/gardener/landscaper/controller-utils/pkg/logging"

lsv1alpha1 "github.com/gardener/landscaper/apis/core/v1alpha1"
)

Expand Down