package main import ( "fmt" "github.com/openshift/origin/test/extended/util/cli" "github.com/openshift/origin/test/extended/util/parsers" ) func main() { k8sConfig := cli.CreateK8sConfigOrDie() path := "/api/v1/namespaces" response, err := cli.Get(k8sConfig, path) if err != nil { panic(err) } namespaces := parsers.ParseNamespaceList(response) for _, ns := range namespaces.Items { fmt.Println(ns.Metadata.Name) } }
package main import ( "fmt" "encoding/json" "github.com/openshift/origin/test/extended/util/cli" "github.com/openshift/origin/test/extended/util/parsers" ) func main() { k8sConfig := cli.CreateK8sConfigOrDie() deployment := createDeploymentSpec() path := "/apis/apps/v1/namespaces/default/deployments" body, err := json.Marshal(deployment) if err != nil { panic(err) } response, err := cli.Post(k8sConfig, path, body) if err != nil { panic(err) } newDeployment := parsers.ParseDeployment(response) fmt.Printf("Created deployment with name %s in namespace %s\n", newDeployment.Metadata.Name, newDeployment.Metadata.Namespace) } func createDeploymentSpec() Deployment { return Deployment{ ApiVersion: "apps/v1", Kind: "Deployment", Metadata: Metadata{ Name: "my-deployment", Namespace: "default", }, Spec: DeploymentSpec{ Replicas: 3, Template: PodTemplateSpec{ Spec: PodSpec{ Containers: []Container{ { Name: "my-container", Image: "nginx:latest", }, }, }, }, }, } }This code uses the KubeREST package to create a new deployment in the default namespace. It constructs a JSON payload that describes the deployment, and then sends an HTTP POST request to the API server using the `Post()` function. Finally, it parses the response using the `parsers.ParseDeployment()` function. Package library: github.com.openshift.origin.test.extended.util.cli.KubeREST