Skip to content

Commit

Permalink
add deletion of the namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Labarussias <issif+github@gadz.org>
  • Loading branch information
Issif committed Feb 15, 2024
1 parent fcd80b0 commit bc0e7b6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionners/actionners.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func GetDefaultActionners() *Actionners {
DefaultContinue: false,
Init: k8s.Init,
Checks: []checkActionner{
k8sChecks.CheckPodExist,
k8sChecks.CheckTargetExist,
},
CheckParameters: nil,
Action: k8sDelete.Action,
Expand Down
2 changes: 2 additions & 0 deletions actionners/kubernetes/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func Action(_ *rules.Action, event *events.Event) (utils.LogLine, error) {
var err error

switch resource {
case "namespaces":
err = client.Clientset.CoreV1().Namespaces().Delete(context.Background(), name, metav1.DeleteOptions{})
case "configmaps":
err = client.Clientset.CoreV1().ConfigMaps(namespace).Delete(context.Background(), name, metav1.DeleteOptions{})
case "secrets":
Expand Down
10 changes: 10 additions & 0 deletions internal/kubernetes/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ func (client Client) GetReplicasetFromPod(pod *corev1.Pod) (*appsv1.ReplicaSet,

func (client Client) GetTarget(resource, name, namespace string) (interface{}, error) {
switch resource {
case "namespaces":
return client.GetNamespace(name, namespace)
case "configmaps":
return client.GetConfigMap(name, namespace)
case "secrets":
Expand All @@ -175,6 +177,14 @@ func (client Client) GetTarget(resource, name, namespace string) (interface{}, e
return nil, errors.New("the resource doesn't exist or its type is not yet managed")
}

func (client Client) GetNamespace(name, namespace string) (*corev1.Namespace, error) {
p, err := client.Clientset.CoreV1().Namespaces().Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("the namespace '%v' doesn't exist", name, namespace)

Check failure on line 183 in internal/kubernetes/client/client.go

View workflow job for this annotation

GitHub Actions / lint / lint

printf: fmt.Errorf call needs 1 arg but has 2 args (govet)
}
return p, nil
}

func (client Client) GetConfigMap(name, namespace string) (*corev1.ConfigMap, error) {
p, err := client.Clientset.CoreV1().ConfigMaps(namespace).Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
Expand Down

0 comments on commit bc0e7b6

Please sign in to comment.