1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-24 08:36:46 +00:00
kyverno/hack/api-group-resources/main.go
Charles-Edouard Brétéché 705ced765d
chore: add policy api unit tests (#12315)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2025-03-06 16:31:14 +00:00

39 lines
1,000 B
Go

package main
import (
"encoding/json"
"flag"
"fmt"
"path/filepath"
// "k8s.io/apimachinery/pkg/util/json"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/restmapper"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
)
func main() {
var kubeconfig *string
if home := homedir.HomeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.Parse()
// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err.Error())
}
client := kubernetes.NewForConfigOrDie(config)
groupResources, err := restmapper.GetAPIGroupResources(client.Discovery())
if err != nil {
panic(err)
}
bytes, err := json.MarshalIndent(groupResources, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(bytes))
}