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

feat: Add a cleanup script that can delete all resources (running the… #30

Closed
wants to merge 1 commit into from
Closed
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
57 changes: 0 additions & 57 deletions pkg/cleanup/cleanup.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"context"
"fmt"

"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
Expand Down Expand Up @@ -76,6 +78,23 @@ func (r *SecurityIntentBindingReconciler) Reconcile(ctx context.Context, req ctr
log.Info("SecurityIntentBinding resource found", "Name", req.Name, "Namespace", req.Namespace)
} else {
log.Info("SecurityIntentBinding resource not found", "Name", req.Name, "Namespace", req.Namespace)

// Delete associated NimbusPolicy if exists
nimbusPolicy := &v1.NimbusPolicy{}
err := r.Get(ctx, types.NamespacedName{Name: req.Name, Namespace: req.Namespace}, nimbusPolicy)
if err != nil && !errors.IsNotFound(err) {
log.Error(err, "Failed to get NimbusPolicy for deletion")
return ctrl.Result{}, err
}
if err == nil {
// NimbusPolicy exists, delete it
if err := r.Delete(ctx, nimbusPolicy); err != nil {
log.Error(err, "Failed to delete NimbusPolicy")
return ctrl.Result{}, err
}
log.Info("Deleted NimbusPolicy due to SecurityIntentBinding deletion", "NimbusPolicy", req.NamespacedName)
}
return ctrl.Result{}, nil
}

// Call the MatchAndBindIntents function to generate the binding information.
Expand Down
15 changes: 15 additions & 0 deletions scripts/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2023 Authors of Nimbus

#!/bin/bash

# Delete all SecurityIntent resources
kubectl delete securityintents --all --all-namespaces

# Delete all SecurityIntentBinding resources
kubectl delete securityintentbindings --all --all-namespaces

# Delete all NimbusPolicy resources
kubectl delete nimbuspolicies --all --all-namespaces

echo "All resources have been successfully deleted."
Loading