import ( "github.com/openshift/origin/pkg/cmd/util/clientcmd" "k8s.io/client-go/kubernetes" ) func main() { // Create a config object config := clientcmd.NewDefaultClientConfigLoadingRules().Load() // Create a Kubernetes client using the config object kubeClient, err := kubernetes.NewForConfig(config) if err != nil { panic(err) } // Use the client pods, err := kubeClient.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{}) if err != nil { panic(err) } for _, pod := range pods.Items { fmt.Println(pod.Name) } }
import ( "github.com/openshift/origin/pkg/cmd/util/clientcmd" "github.com/openshift/origin/pkg/cmd/util/factory" ) func main() { // Create a client config object config := clientcmd.NewDefaultClientConfigLoadingRules().Load() // Create a factory object f := factory.New() // Use the factory to create an OpenShift client ocClient, err := f.NewOpenShiftClient(config) if err != nil { panic(err) } // Use the client projects, err := ocClient.Projects().List(context.Background(), metav1.ListOptions{}) if err != nil { panic(err) } for _, project := range projects.Items { fmt.Println(project.Name) } }This code creates an OpenShift client using the `Factory`. The `factory.New()` method creates a new factory object. Then, the `f.NewOpenShiftClient(config)` method uses the factory to create an OpenShift client with the correct configuration. Finally, the `ocClient.Projects().List()` method is used to retrieve a list of projects in the current OpenShift cluster. In summary, the `github.com.openshift.origin.pkg.cmd.util.clientcmd` package is a Go library that provides a Factory for client configuration. The examples above show how to use the factory to create clients for Kubernetes and OpenShift clusters.