import ( "github.com/openshift-origin/pkg/cmd/util/clientcmd" "k8s.io/client-go/rest" ) // create an OpenShift API client using OAuth bearer token authentication config := &rest.Config{ Host: "https://api.openshift.example.com", BearerToken: "my-oauth-token", } client, _ := clientcmd.NewOpenShiftAPIClient(config)
import ( "github.com/openshift-origin/pkg/cmd/util/clientcmd" "k8s.io/client-go/tools/clientcmd/api" ) // load an OpenShift configuration file from disk loader, _ := clientcmd.NewOpenShiftKubeConfigLoader("/path/to/config") // use the loader to get the current context config, _ := loader.Load() context := config.CurrentContext // get the API server endpoint for the current context endpoint := config.Clusters[context].Server // get the OAuth token for the current context token := config.AuthInfos[context].TokenIn both cases, we are using factory clients from the `github.com.openshift.origin.pkg.cmd.util.clientcmd` package library to create authenticated connections to an OpenShift cluster.