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

fix: restore destroy script functionality #2274

Merged
merged 3 commits into from
Jan 31, 2024
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 packages/distros/k3s/common/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ components:
before:
- cmd: /opt/zarf/zarf-clean-k3s.sh
description: Remove 'k3s' from the system
- cmd: rm /opt/zarf/zarf-clean-k3s.sh
description: Remove the cleanup script
files:
# K3s removal script
- source: zarf-clean-k3s.sh
Expand Down
5 changes: 5 additions & 0 deletions src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ func (p *Packager) deployInitComponent(component types.ZarfComponent) (charts []
isRegistry := component.Name == "zarf-registry"
isInjector := component.Name == "zarf-injector"
isAgent := component.Name == "zarf-agent"
isK3s := component.Name == "k3s"

if isK3s {
p.cfg.InitOpts.ApplianceMode = true
}

// Always init the state before the first component that requires the cluster (on most deployments, the zarf-seed-registry)
if requiresCluster(component) && p.cfg.State == nil {
Expand Down
15 changes: 14 additions & 1 deletion src/test/e2e/99_appliance_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,24 @@ func TestApplianceRemove(t *testing.T) {

path := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", e2e.Arch, initPackageVersion)

// Destroy the cluster to test Zarf cleaning up after itself
// Package remove the cluster to test Zarf cleaning up after itself
stdOut, stdErr, err := e2e.Zarf("package", "remove", path, "--confirm")
require.NoError(t, err, stdOut, stdErr)

// Check that the cluster is now gone
_, _, err = e2e.Kubectl("get", "nodes")
require.Error(t, err)

// TODO (@WSTARR) - This needs to be refactored to use the remove logic instead of reaching into a magic directory
// Re-init the cluster so that we can test if the destroy scripts run
stdOut, stdErr, err = e2e.Zarf("init", "--components=k3s", "--confirm")
require.NoError(t, err, stdOut, stdErr)

// Destroy the cluster to test Zarf cleaning up after itself
stdOut, stdErr, err = e2e.Zarf("destroy", "--confirm")
require.NoError(t, err, stdOut, stdErr)

// Check that the cluster gone again
_, _, err = e2e.Kubectl("get", "nodes")
require.Error(t, err)
}
Loading