import ( "fmt" "github.com/openshift/origin/pkg/cmd/util/clientcmd" "k8s.io/client-go/kubernetes" ) func main() { // Create a new ClientConfig object config := clientcmd.NewDefaultClientConfigLoadingRules().Load() // Initialize a new Kubernetes API client using the ClientConfig object clientset, err := kubernetes.NewForConfig(config) if err != nil { panic(err.Error()) } // Print current Kubernetes namespace namespace, _, err := config.Namespace() if err != nil { panic(err.Error()) } fmt.Printf("Current namespace: %s\n", namespace) // Use Kubernetes API client to get list of pods in current namespace podList, err := clientset.CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{}) if err != nil { panic(err.Error()) } // Print name of each pod in current namespace for _, pod := range podList.Items { fmt.Println(pod.GetName()) } }
import ( "fmt" "github.com/openshift/origin/pkg/cmd/util/clientcmd" "github.com/openshift/origin/pkg/cmd/util/tokencmd" ) func main() { // Create a new ClientConfig object config := clientcmd.NewDefaultClientConfigLoadingRules().Load() // Use ClientConfig to generate a new authentication token token, err := tokencmd.RequestToken(config) if err != nil { panic(err.Error()) } // Print authentication token fmt.Println(token) }In this example, the Factory function `NewDefaultClientConfigLoadingRules().Load()` is used to create a new ClientConfig object, which is then passed to the `tokencmd.RequestToken()` function to generate a new authentication token.