import ( "context" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/googlecloudplatform/k8s-cluster-bundle/pkg/k8sclient" "google.golang.org/api/option" "k8s.io/client-go/rest" "testing" ) func TestK8sclient_ConfigForPod(t *testing.T) { ctx := context.TODO() restConf := &rest.Config{ Host: "http://127.0.0.1:8080", APIPath: "/api/v1/namespaces/default/pods/test-pod", Insecure: true, } k8sClient, err := k8sclient.NewForConfig(ctx, restConf, option.WithoutAuthentication()) if err != nil { t.Fatal(err) } expected := restConf actual := k8sClient.ConfigForPod(ctx, "default", "test-pod") if diff := cmp.Diff(expected, actual, cmpopts.IgnoreFields(rest.Config{}, "Timeout"), cmpopts.EquateEmpty()); diff != "" { t.Errorf("diff(-want, +got):\n%s", diff) } }
import ( "context" "github.com/googlecloudplatform/k8s-cluster-bundle/pkg/k8sclient" "google.golang.org/api/option" "k8s.io/client-go/rest" ) func main() { ctx := context.TODO() restConf := &rest.Config{ Host: "http://127.0.0.1:8080", Insecure: true, } k8sClient, err := k8sclient.NewForConfig(ctx, restConf, option.WithoutAuthentication()) if err != nil { panic(err) } // Use k8sClient to interact with the Kubernetes API }In this example, we create a new client connection using the `NewForConfig` function. We pass in a `rest.Config` object with the necessary information to connect to the Kubernetes cluster, and an `option` object if we want to add any additional options to the connection. Once the connection is established, we can use the `k8sClient` variable to interact with the Kubernetes API.