How to delete all custom resources of a kind in k8s cluster (all namespaces) using client-go

Viewed 743

I'm trying to delete resources of a particular kind in a k8s cluster using client-go.

I'm using this code but it requires a specific namespace to be declared, but i want to delete this resource in all namespaces.

    u.SetName("test")
    u.SetNamespace(v1.NamespaceAll)
    u.SetGroupVersionKind(schema.GroupVersionKind{
        Group:   "group",
        Kind:    "kind",
        Version: "v1",
    })
    err := k8sClient.Delete(context.TODO(), u)

    if err != nil {
        fmt.Println(err.Error())
        return err
    }

Found the example here - https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client but it doesn't mention anything about all namespaces. Could someone plz provide a way to figure this out.

NOTE: This is custom resource. not default kind such as pod or deployment etc

0 Answers
Related