cluster-templates-operator icon indicating copy to clipboard operation
cluster-templates-operator copied to clipboard

Add clientset generation for ClusterTemplate CRD

Open machacekondra opened this issue 1 year ago • 5 comments

This PR add code for generating the clientset and the generated client set the example usage is:

package handlers

import (
	"context"
	"fmt"
	"net/http"
	"os"

	"github.com/gin-gonic/gin"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/rest"

	"github.com/stolostron/cluster-templates-operator/generated/clientset/versioned"
)

func main() {
	config := &rest.Config{
		BearerToken: os.Getenv("OCP_TOKEN"),
		Host:        os.Getenv("OCP_URL"),
		TLSClientConfig: rest.TLSClientConfig{
			Insecure: true,
		},
	}
	clientset, err := versioned.NewForConfig(config)
	if err != nil {
		os.Exit(1)
	}

	ctemplates, err := clientset.V1alpha1().ClusterTemplates("").List(context.TODO(), metav1.ListOptions{})
	if err != nil {
		fmt.Printf("Error listing templates: %v\n", err)
		os.Exit(1)
	}

	for _, ct := range ctemplates.Items {
                fmt.Prinln("Template: %v\n", ct.GetName())
	}
}

machacekondra avatar Aug 23 '23 12:08 machacekondra