import ( "github.com/openshift/origin/pkg/client" "k8s.io/client-go/rest" ) func main() { // create a new OpenShift cluster client config, _ := rest.InClusterConfig() cli, _ := client.New(config) // get a list of all projects projects, _ := cli.Projects().List() for _, project := range projects.Items { fmt.Println(project.Name) } // get information about a specific project project, _ := cli.Projects().Get("my-project") fmt.Println(project.DisplayName) }
import ( "github.com/openshift/origin/pkg/client" "k8s.io/client-go/rest" ) func main() { // create a new OpenShift cluster client config, _ := rest.InClusterConfig() cli, _ := client.New(config) // create a new service svc := &api.Service{ ObjectMeta: api.ObjectMeta{ Name: "my-service", }, Spec: api.ServiceSpec{ Selector: map[string]string{ "app": "my-app", }, Ports: []api.ServicePort{ { Name: "http", Protocol: "TCP", Port: 80, TargetPort: intstr.IntOrString{ Type: intstr.String, StrVal: "http", }, }, }, }, } // create the service in the "my-project" project svc, _ = cli.Services("my-project").Create(svc) fmt.Println(svc.ObjectMeta.Name) }In this example, we again create a new OpenShift cluster client. We then define a new service object, which will create a service for an existing app running in the cluster. We set the service's name, selector (to identify the app it will connect to), and port configuration. Finally, we use the client to create the service in a specific project ("my-project"). We print out the name of the service that was created. Both of these examples use the `github.com/openshift/origin/pkg/client` package library. This library provides a Go client for interacting with an OpenShift cluster API. It uses the Kubernetes client library (`k8s.io/client-go`) under the hood, but with additional functionality specific to OpenShift's APIs.