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

Cleans up k8s-dqlite state dir and stops it on remove hook #908

Merged
merged 1 commit into from
Jan 10, 2025
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
18 changes: 0 additions & 18 deletions src/k8s/pkg/k8sd/app/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,6 @@ func startControlPlaneServices(ctx context.Context, snap snap.Snap, datastore st
return nil
}

func stopControlPlaneServices(ctx context.Context, snap snap.Snap, datastore string) error {
// Stop services
switch datastore {
case "k8s-dqlite":
if err := snaputil.StopK8sDqliteServices(ctx, snap); err != nil {
return fmt.Errorf("failed to stop k8s-dqlite service: %w", err)
}
case "external":
default:
return fmt.Errorf("unsupported datastore %s, must be one of %v", datastore, setup.SupportedDatastores)
}

if err := snaputil.StopControlPlaneServices(ctx, snap); err != nil {
return fmt.Errorf("failed to stop control plane services: %w", err)
}
return nil
}

func waitApiServerReady(ctx context.Context, snap snap.Snap) error {
// Wait for API server to come up
client, err := snap.KubernetesClient("")
Expand Down
13 changes: 9 additions & 4 deletions src/k8s/pkg/k8sd/app/hooks_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ func (a *App) onPreRemove(ctx context.Context, s state.State, force bool) (rerr
log.Error(err, "Failed to create k8s-dqlite client: %w")
}

log.Info("Cleaning up k8s-dqlite directory")
if err := os.RemoveAll(snap.K8sDqliteStateDir()); err != nil {
return fmt.Errorf("failed to cleanup k8s-dqlite state directory: %w", err)
}
case "external":
log.Info("Cleaning up external datastore certificates")
if _, err := setup.EnsureExtDatastorePKI(snap, &pki.ExternalDatastorePKI{}); err != nil {
Expand All @@ -107,6 +103,10 @@ func (a *App) onPreRemove(ctx context.Context, s state.State, force bool) (rerr
log.Error(err, "Failed to retrieve cluster config")
}

log.Info("Cleaning up k8s-dqlite directory")
if err := os.RemoveAll(snap.K8sDqliteStateDir()); err != nil {
log.Error(err, "failed to cleanup k8s-dqlite state directory")
}
for _, dir := range []string{snap.ServiceArgumentsDir()} {
log.WithValues("directory", dir).Info("Cleaning up config files", dir)
if err := os.RemoveAll(dir); err != nil {
Expand Down Expand Up @@ -144,6 +144,11 @@ func (a *App) onPreRemove(ctx context.Context, s state.State, force bool) (rerr
if err := snaputil.StopControlPlaneServices(ctx, snap); err != nil {
log.Error(err, "Failed to stop control-plane services")
}

log.Info("Stopping k8s-dqlite")
if err := snaputil.StopK8sDqliteServices(ctx, snap); err != nil {
bschimke95 marked this conversation as resolved.
Show resolved Hide resolved
log.Error(err, "Failed to stop k8s-dqlite service")
}
}

tryCleanupContainerdPaths(log, snap)
Expand Down
Loading