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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: machacekondra

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

openshift-ci[bot] avatar Aug 23 '23 12:08 openshift-ci[bot]

/retest

machacekondra avatar Aug 23 '23 13:08 machacekondra

@rawagner PTAL

machacekondra avatar Aug 24 '23 11:08 machacekondra

/retest

machacekondra avatar Aug 25 '23 13:08 machacekondra

/retest

machacekondra avatar Aug 28 '23 08:08 machacekondra