Giter Site home page Giter Site logo

client-go's Introduction

OpenShift Client in Go

Go clients for speaking to an OpenShift cluster.

Versions track OpenShift releases.

See INSTALL.md for detailed installation instructions.

Table of Contents

Updating Dependencies and Code Generation

To pull in updates from openshift/api, run the following:

$ go get github.com/openshift/api@<commit or branch>
$ go mod tidy
$ go mod vendor
$ go mod verify

To update the code generation, run the following: Note: GOFLAGS=-mod=vendor needs to be set in the environment.

$ make generate

NOTE: When adding entirely new package make sure to force import it before invoking go get..., go mod tidy and go mod vendor. This will ensure that this new package will be properly picked up in the vendor tree. Only then make generate will be able to correctly create the necessary clients.

How to use it

See examples.

Compatibility

openshift/client-go is backwards compatible with prior server versions back to v3.6 when we switched to API groups. It is not compatible before that.

Keep in mind that using a newer client is generally safe, but the server will strip newer fields it doesn't understand from objects. That means that if you're trying to use a new feature on an old server, the server will do the best it can, but you still won't have the new feature.

Using an older client can be risky if you issue updates (not patches) to existing resources. The older client will remove newer fields on updates. You will not have this problem if you issue patches instead of updates.

client-go's People

Contributors

alexanderconstantinescu avatar bertinatto avatar bparees avatar coreydaley avatar damemi avatar deads2k avatar dinhxuanvu avatar emilienm avatar gnufied avatar hexfusion avatar jhadvig avatar jkyros avatar joelspeed avatar liggitt avatar marun avatar mfojtik avatar mkowalski avatar openshift-ci[bot] avatar openshift-merge-bot[bot] avatar openshift-merge-robot avatar qiwang19 avatar ricardomaraschini avatar rvanderp3 avatar sairameshv avatar sanchezl avatar simo5 avatar smarterclayton avatar soltysh avatar tremes avatar umohnani8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

client-go's Issues

Creating a clientset for (egress)network policy throw error

What do I need to create a client for OpenShift added resource(s)? I encounter a problem when import the openshift/client-go/network package and create a clientset from it. The client-go/kubernetes resource(networkpolicy) works fine.

`package main

import (
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
egressnetv1 "github.com/openshift/client-go/network/informers/externalversions/network/v1"
egressnetclient "github.com/openshift/client-go/network/clientset/versioned/typed/network/v1"
)
var logger *zap.Logger

func main() {
logger, _ = zap.NewProduction()
defer logger.Sync()
logger.Info("The pod watcher/logger started")
kubeconfig := os.Getenv("KUBECONFIG")
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
logger.Panic(err.Error())
os.Exit(1)
}
// clientset for NetworkPolicy
clientset, err := kubernetes.NewForConfig(config)
// clientset for EgressNetworkPolicy
egressclientset, err := egressnetclient.NewForConfig(config)
if err != nil {
panic(err)
}

`

I get the following error:

github.com/user/podwatcher/vendor/github.com/openshift/client-go/network/clientset/versioned/typed/network/v1
vendor/github.com/openshift/client-go/network/clientset/versioned/typed/network/v1/clusternetwork.go:54:5: not enough arguments in call to c.client.Get().Resource("clusternetworks").Name(name).VersionedParams(&options, scheme.ParameterCodec).Do
have ()
want (context.Context)

Support which OpenShift version

Hi ,

Which latest version of OpenShift does this client supports ?
It is advised to use which one Java Client or Go Client for calling OpenShift API's

Thanks and Regards
Abhijit

support for older openshift?

Hi,
I'm currently using openshift 1.5 , now I need client-go to interact with openshift, there is no release for openshift 1.5, is this client-go backward compatible?

what's the right place for a new API group and how to organize it

I'm trying to create a new API group and generate code for it:

  1. copy an api group directory(e.g, user) in vendor/github.com/openshift/api, to a new group(e.g, leuser), and edit the doc.go/types.go correspondingly.

  2. generate code for the new API group
    #bash ./vendor/k8s.io/code-generator/generate-groups.sh client,lister,informer github.com/openshift/client-go/leuser github.com/openshift/api leuser:v1

, and encounter the following error:

Generating clientset for leuser:v1 at github.com/openshift/client-go/userxx/clientset F0805 13:46:33.584349 13008 main.go:64] Error: Failed making a parser: unable to add directory "github.com/openshift/api/leuser/v1": unable to import "github.com/openshift/api/leuser/v1": go/build: importGo github.com/openshift/api/leuser/v1: exit status 1 go: finding github.com/openshift/api latest can't load package: package github.com/openshift/api/leuser/v1: module github.com/openshift/api@latest found (v0.0.0-20200803131051-87466835fcc0), but does not contain package github.com/openshift/api/leuser/v1

I'm puzzled, and want to know the right place for a new API group and the way to organize it.

Thanks for your help.

Not able to build using the client-go package

When trying to build a small go program that uses client-go, I am getting the following build error:

$ go build
# github.com/anjannath/sample/vendor/k8s.io/client-go/rest
vendor/k8s.io/client-go/rest/request.go:598:31: not enough arguments in call to watch.NewStreamWatcher
	have (*versioned.Decoder)
	want (watch.Decoder, watch.Reporter)

I am using Go Modules

$ cat go.mod 
module github.com/anjannath/sample

go 1.12

require (
	github.com/imdario/mergo v0.3.7 // indirect
	github.com/openshift/api v3.9.0+incompatible // indirect
	github.com/openshift/client-go v3.9.0+incompatible
	golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 // indirect
	golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
	golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
	k8s.io/api v0.0.0-20190615205754-1d1b8b084b30 // indirect
	k8s.io/apimachinery v0.0.0-20190612125636-6a5db36e93ad
	k8s.io/client-go v11.0.0+incompatible
	k8s.io/utils v0.0.0-20190607212802-c55fbcfc754a // indirect
)

Here's the code from main.go

package main

import (
	"fmt"

	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/tools/clientcmd"

	imagesv1 "github.com/openshift/client-go/image/clientset/versioned/typed/image/v1"
)

func GetImages(kubeconfig string) error {
	config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
	if err != nil {
		return err
	}

	imagesV1Client, err := imagesv1.NewForConfig(config)
	if err != nil {
		return err
	}
	// get all images
	images, err := imagesV1Client.Images().List(metav1.ListOptions{})
	if err != nil {
		return err
	}
	fmt.Printf("No of Images: %d\n", len(authentications.Items))
	for i, img := range authentications.Items {
		fmt.Printf("index %d: Name of the images: %s", i, img.Name)
	}
}

func main() {
	kubeconfigPath := filepath.Join(".kube", "config")
	GetImages(kubeconfigPath)
}

How to list the deployments in openshift using client-go ?

I can list and delete a pod in openshift but I am unable to list the deployments in a namespace. I have used the example form kubernetes client-go

deploymentsClient := clientset.AppsV1().Deployments(project)
list, err := deploymentsClient.List(metav1.ListOptions{})

It is giving me and error : the server could not find the requested resource

Any Help ?

make update-deps asking for passphrase that can't be provided

make update-deps fails to me:

$ make update-deps
hack/update-deps.sh
[INFO]	Downloading dependencies. Please wait...
[INFO]	--> Fetching updates for golang.org/x/tools
[INFO]	--> Fetching updates for k8s.io/client-go
[INFO]	--> Fetching k8s.io/gengo
[INFO]	--> Fetching k8s.io/code-generator
[INFO]	--> Fetching updates for k8s.io/apimachinery
[INFO]	--> Fetching updates for github.com/golang/glog
[INFO]	--> Fetching k8s.io/api
[INFO]	--> Fetching updates for github.com/openshift/api
[INFO]	--> Fetching updates for github.com/spf13/pflag
Enter passphrase for key '/home/coder/.ssh/id_rsa': Enter passphrase for key '/home/coder/.ssh/id_rsa': 

Makefile:32: recipe for target 'update-deps' failed
make: *** [update-deps] Error 130

Here is a fix from @mfojtik that works to me:

--- glide.yaml
+++ glide.yaml
@@ -1,10 +1,10 @@
 package: github.com/openshift/client-go
 import:
 - package: k8s.io/gengo
-  repo:    [email protected]:openshift/kubernetes-gengo
+  repo:    https://github.com/openshift/kubernetes-gengo
   version: openshift-3.10
 - package: k8s.io/code-generator
-  repo:    [email protected]:openshift/kubernetes-code-generator
+  repo:    http://github.com/openshift/kubernetes-code-generator
   version: origin-3.10-kubernetes-1.10.0
 - package: k8s.io/apimachinery
   version: kubernetes-1.10.2

Why we use ssh for these repositories? Could we change URLs to https?

Fake Clientset cannot be initialized with Security Context Constraints

When initializing a NewSimpleClientset for the security client api fake, any security context constraints objects passed into the constructor do not get initialized correctly.

The NewSimpleClientset used in the security client api does not have any checks for securitycontextconstraints kinds which get changed to securitycontextconstraintes in the function UnsafeGuessKindToResource.

Steps to reproduce:

  1. Create a NewSimpleClientset passing in a securitycontextconstraints kind in the initializer.
  2. Attempt to 'Get' the securitycontextconstraints object that you initialized the clientset with.
  3. Verify that the Get function call cannot find the securitycontextconstraints.

Missing Documentation

I'm interested in writing my own tool which interacts with an OpenShift server in Go. This project looks like a good library to use, but it seems to only have a single example on how to use it. Are there plans for adding any documentation at all? It seems pretty important and I have to say I'm disappointed it's lacking.

Can not authenticated with basic auth method

Hi, I am trying to initialize a client outside openshift cluster. But I don't want to maintain a kubeconfig

So i have referenced examples in kubernetes/client-go, Authenticated with ClientCertificate and Bearer Token that's work fine.

But when I define the username and password to request the resources, i got this response:

User "system:anonymous" cannot list deploymentconfigs.apps.openshift.io in the namespace "testproject": User "system:anonymous" cannot list deploymentconfigs.apps.openshift.io in project "testproject"(get deploymentconfigs.apps.openshift.io)

Here is my code snippets:

import (
	appsv1 "github.com/openshift/client-go/apps/clientset/versioned/typed/apps/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/tools/clientcmd"
	clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)

func somefunc() {
...
        config := clientcmdapi.NewConfig()
	config.Clusters["master-example-com:8443"] = &clientcmdapi.Cluster{
		InsecureSkipTLSVerify: true,
		Server:                "https://master.example.com:8443",
	}
	config.AuthInfos["[email protected]/master-example-com:8443"] = &clientcmdapi.AuthInfo{
		Username: "[email protected]",
		Password: "password",
	}
	config.Contexts["/master-example-com:8443/[email protected]"] = &clientcmdapi.Context{
		Cluster:  "master-example-com:8443",
		AuthInfo: "[email protected]/master-example-com:8443",
	}
	config.CurrentContext = "/master-example-com:8443/[email protected]"

        clientConfig := clientcmd.NewNonInteractiveClientConfig(*config, "/master-example-
        com:8443/[email protected]", &clientcmd.ConfigOverrides{}, nil)

        restClientConfig, err := clientConfig.ClientConfig()

        appsV1Client := appsv1.NewForConfigOrDie(restClientConfig)
	namespace := "testproject"

	dcs, err := appsV1Client.DeploymentConfigs(namespace).List(metav1.ListOptions{})
	if err != nil {
		panic(err.Error())
	}

	for _, dc := range dcs.Items {
		fmt.Printf("Found name of the dc: %s\n", dc.Name)
	}
...
}
Server Version:

openshift v3.7.0+7ed6862
kubernetes v1.7.6+a08f5eeb62

Any suggestions?

Glide 0.13 minimum is required

To be able to get proper results out of make update-deps a version of glide no lower than 0.13.0 is needed.
This should probably be enforce by the make target via a version check.
Otherwise the tools pulls in garbage.

template processing

Hello,

Is there a way to load and process a template (as its string representation) on the fly (without importing it in an openshift namespace)?

Thanks.

github.com/openshift/client-go is non-gettable

Hi,

We are trying to use client-go as a vendored dependency in a kubernetes operators project that uses the 'dep' tool and needs to interact with Openshift-specific elements, but our current attempts have not been successful at getting openshifft client-go because it seems it is not go-gettable.

In our Gopkg.toml file we have tried to put (among other elements):

[[override]]
  name = "github.com/openshift/client-go"
  branch = "release-3.11"

However, when executing dep ensure -v nothing happens.

We have also tried to include the same name ("github.com/openshift/client-go") directly in the 'required' section of Gopkg.toml (without constraining the branch) and the following error is received when dep ensure -v is executed:

Solving failure: No versions of github.com/openshift/client-go met constraints:
	v3.9.0: Could not introduce github.com/openshift/[email protected], as its subpackage github.com/openshift/client-go does not contain usable Go code (*build.NoGoError).. (Package is required by (root).)
	master: Could not introduce github.com/openshift/client-go@master, as its subpackage github.com/openshift/client-go does not contain usable Go code (*build.NoGoError).. (Package is required by (root).)
	release-3.10: Could not introduce github.com/openshift/[email protected], as its subpackage github.com/openshift/client-go does not contain usable Go code (*build.NoGoError).. (Package is required by (root).)
	release-3.11: Could not introduce github.com/openshift/[email protected], as its subpackage github.com/openshift/client-go does not contain usable Go code (*build.NoGoError).. (Package is required by (root).)
	release-3.8: Could not introduce github.com/openshift/[email protected], as its subpackage github.com/openshift/client-go does not contain usable Go code (*build.NoGoError).. (Package is required by (root).)
	release-3.9: Could not introduce github.com/openshift/[email protected], as its subpackage github.com/openshift/client-go does not contain usable Go code (*build.NoGoError).. (Package is required by (root).)

A way for being able to vendor openshift/client-go on projects that use 'dep' would be great.

How could we use openshift/client-go given that 'dep' is the vendoring tool that is being used?

Thank you,

Miguel.

Not able to Scale DeploymentConfigs using the UpdateScale() function

The UpdateScale() function for DeploymentConfigs is not working.

I am using the following code snippet to call the function.

func ScaleDeploymentConfig(client *v1.AppsV1Client, name, namespace string, replica int32) {
    fmt.Printf("Scaling DeploymentConfig: %s in namespace %s to %d\n", name, namespace, replica)
    deploymentConfig := client.DeploymentConfigs(namespace)
    fmt.Printf("%T\n", deploymentConfig)
    scaleObj, err := deploymentConfig.GetScale(context.Background(), name, metav1.GetOptions{})
    if err != nil {
        fmt.Printf("error getting scale object: %v\n", err)
        os.Exit(1)
    }
    sd := *scaleObj
    sd.Spec.Replicas = replica
    fmt.Printf("%+v\n", &sd)
    scaleDeploymentConfigs, err := deploymentConfig.UpdateScale(context.Background(), name, &sd, metav1.UpdateOptions{})
    if err != nil {
        fmt.Printf("error updating scale object: %v\n", err)
        os.Exit(1)
    }
    fmt.Printf("Successfully scaled %+v", scaleDeploymentConfigs)
}

The GetScale() function is working fine, although it throws a warning. Thereafter I am passing the scale object which I am getting from the GetScale() to the update scale function, but it's not working.

Getting the below error

W1214 11:44:07.290708   49036 warnings.go:70] extensions/v1beta1 Scale is deprecated in v1.2+, unavailable in v1.16+
&Scale{ObjectMeta:{example  podkiller  557aa7f3-e5ec-4e93-bbab-ba4f5b598658 1270748657 0 2022-12-11 21:23:30 +0530 IST <nil> <nil> map[] map[] [] [] []},Spec:ScaleSpec{Replicas:2,},Status:ScaleStatus{Replicas:1,Selector:map[string]string{app: busybox,deploymentconfig: example,},TargetSelector:app=busybox,deploymentconfig=example,},}
W1214 11:44:07.653487   49036 warnings.go:70] extensions/v1beta1 Scale is deprecated in v1.2+, unavailable in v1.16+
error updating scale object: the API version in the data (apps.openshift.io/v1) does not match the expected API version (extensions/v1beta1)

Points to consider:

  1. I am using the code in the master branch of the repo. github.com/openshift/api v0.0.0-20221103085154-ea838af1820e
  2. I can scale the deployment configs using the Patch() function defined in the same interface as the UpdateScale(). I have documented it in my blog post.
  3. Running the openshift version command returns the below result:
Client Version: 4.12.0-202208031327
Kustomize Version: v4.5.4
Kubernetes Version: v1.22.8+9e95cb9

Export of Resources

Hi,

I am looking for a way to export OpenShift resources, like deploymentconfigs and rolebindings, with the golang client. Using the CLI, I perform the following command:

oc get dc -o yaml --export=true > /tmp/example.yaml

How can I perform this action with the golang client? It seems that I cannot pass ExportOptions to the Get() function of, for instance, RoleBindings.

Can you give a short example on how to do this?

Thanks!

3.10 tag is missing

I want to vendor and pin client-go to a 3.10 tag but I cannot see any in the repo.

@openshift/sig-master

releases?

I noticed you have very few tags. Wouldn't it make sense to create tags/releases?

Error while deleting services

I am trying to delete bunch of services using following line,

err = c.kubeClient.CoreV1().Services(c.namespace).DeleteCollection(&metav1.DeleteOptions{},metav1.ListOptions{LabelSelector: selector})

I am getting following error,

the server does not allow this method on the requested resource

Unable to install using glide

Here is a snippet of my glide.yaml file:

- package: github.com/openshift/client-go
  version: release-3.11

When I run glide up -v I'm getting the following error (along with a bunch of warning lines relating to the same error):

[WARN]	The reference 'origin-3.11-kubernetes-1.11.1' is not valid
[WARN]	Unable to set version on k8s.io/client-go to origin-3.11-kubernetes-1.11.1. Err: improper constraint: origin-3.11-kubernetes-1.11.1
...
[WARN]	The reference 'origin-3.11-kubernetes-1.11.1' is not valid
[ERROR]	Failed to set version on k8s.io/client-go to origin-3.11-kubernetes-1.11.1: improper constraint: origin-3.11-kubernetes-1.11.1
[ERROR]	Failed to set references: improper constraint: origin-3.11-kubernetes-1.11.1 (Skip to cleanup)

Up until yesterday, I was using release-3.10 which was downloading perfectly, but starting today, even that version started throwing the same error so I thought it might've been something related to 3.10, but 3.11 throws the same errors.

Any idea(s) why glide isn't able to download the package?

Thank you!

Add k8s dependencies tracking step and start proper tag management

we are using go.mod file from this repo as a referene to "which versions of k8s packages would we use" in our go.mod/sum files

its very good, that with reecnt releases you started to track and bump the versions of k8s, and i want to kindly ask you to improve it a little bit.

so here, in a new 4.15 go mod you bumped only 2 of 4 packages; it led to having:

	k8s.io/api v0.26.3
	k8s.io/apimachinery v0.26.3
	k8s.io/client-go v0.26.1
	k8s.io/code-generator v0.26.1

whicch doesnt look "consistent". what i am offering - is to add extra step and extra bit of attention - before creating new release tag - can you please check for fresh versions of all 4 repos, bump them in your go.mod as a single piece (imagine that old code-generator potentially may be incompatible with newer api, or vice versa) and make them same version? i would thank you in advane

also, theres a side issue. go get has 2 ways bumping things - 1 way is thay you arent using tags at all, but get repo@commit only, and there are no tags - then go get will fetch you latest commit from master
Or, second way - is you start track tags. Even go pakages x/text, /sys, /net, and so on - switched to tags tracking! Here it looks like you are switched to do tags, because creating first tag switches go package management system into "tagged" operation mode.
go get doesnt pull latest commit from main, but pulls latest tag.
So having v3.9.0 tag forces it to use tags instead of latest commit. hovewer you dont provide v4.13.0, v4.14.0 tags, which makes latest to freeze to v3.9.0 - this solution is not friendly with go get github.com/openshift/client-go
image

Can you please elaborate abit, on request, in order of importance:

  • make k8s.io packages be single version in your go.mod
  • evaluate for fresh versions of k8s.io before doing release
  • start releases taging for your project on github, because you already have v3.9.0 tag - to be aligned and friendly with tag system that everyone is using. as a developer i know that branches are convenient for providers ability to support and send fixes, but tags are extremely important for package users. you can create v4.15.1, v4.15.2 tags with minor fixes inside release-4.15 branch

that will allow easy and consistent update of ocp/k8s clients with single simple call go get github.com/openshift/client-go

sincerely, golang developers.

How to list deployments?

The aim is to check whether pods are up and running. Basically I want to check whether the replicationcontrollers/replicasets are OK. In other words, if 2 replicas are desired I would like to know whether 2 are running and return 1 id true.

oc adm policy command outdated manual

Client version

oc version
Client Version: 4.7.19
Server Version: 4.7.29
Kubernetes Version: v1.20.0+9689d22

Issue

oc adm policy
Manage policy on the cluster
 These commands allow you to assign and manage the roles and policies that apply to users. The reconcile commands allow
you to reset and upgrade your system policies to the latest default policies.
 To see more information on roles and policies, use the 'get' and 'describe' commands on the following resources:
'clusterroles', 'clusterpolicy', 'clusterrolebindings', 'roles', 'policy', 'rolebindings', and 'scc'.

The API 'clusterpolicy' and 'policy' have been removed from openshift 4 but are still referenced in the client so. trying to use one or the other results in

oc get clusterpolicy
error: the server doesn't have a resource type "clusterpolicy"

Cannot Create route

When attempting to create a Route, I get the following error
encoding is not allowed for this codec: *versioning.codec
I cannot figure out what is wrong, or what the error actually means.
I'm targeting minishift running 3.11 locally, I can create routes via yaml oc create -f and through the console but using the client-go api based more or less off this example https://docs.okd.io/latest/go_client/serializing_and_deserializing.html
I just get the error above. Any help is appreciated.

I would also love to know about any sample code or docs that are more helpful, the single build example included in the repo is not very encompassing.

Create Security Context using the openshift golang Client

I am trying to create SCC using OC client in golang. I see that the documentation is very sparse for it. I am trying to consume "github.com/openshift/client go/security/clientset/versioned/typed/security/v1" amd creating a scc using this like scclient.SecurityContextConstraints().Create(). Is there a way I can pass yaml to it ?

Can we have some examples regarding this in the docs ?

unknown revision v0.0.0

when I use the commad "go mod tidy" to resolve dependencies,the following error occurred.Can you telll me how to deal it?

go: finding module for package kubevirt.io/kubevirt
go: found kubevirt.io/kubevirt in kubevirt.io/kubevirt v0.39.1
go: kubevirt.io/[email protected] requires
github.com/openshift/[email protected]: reading github.com/openshift/api/go.mod at revision v0.0.0: unknown revision v0.0.0

(type *"k8s.io/client-go/rest".Config) as type *"github.com/openshift/client-go/vendor/k8s.io/client-go/rest"

code :

import (
	"fmt"
	"log"

	buildv1 "github.com/openshift/client-go/build/clientset/versioned/typed/build/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/rest"
)

func main() {

	c := &rest.Config{}
	c.Host = "https://xxxx"
	c.CAData = []byte("xxxx")
	c.CertData = []byte("xxxx")
	c.KeyData = []byte("xxxx")

	buildV1Client, err := buildv1.NewForConfig(c)
	if err != nil {
		log.Fatal(err.Error())
	}

go run main.go

./main.go:25:44: cannot use c (type *"k8s.io/client-go/rest".Config) as type *"github.com/openshift/client-go/vendor/k8s.io/client-go/rest".Config in argument to "github.com/openshift/client-go/build/clientset/versioned/typed/build/v1".NewForConfig

How to solve this?

Cannot get Openshift object with Operator SDK reconciler

When using the operator sdk, we can easily use the recondiler function to get, update or delete kubernetes resources.

But it do not work with openshift resources

Example:

deploymentConfigs := &projectv1.ProjectList{}
reconciler.List(ctx, deploymentConfigs)
reconcileLog.Info(fmt.Sprintf("%+v", deploymentConfigs))

This returns an empty ObjectList.
Tested with deployment config as well.

Doing the same with a ServiceList for example works fine.

How stable is this repo?

Hi,
I was considering using this repo as my client instead of shelling out to oc.
Just wanted a quick heads up about how stable and maintained is this library?
There is no documentation, releases, etc, so would really help some pointers here.

Contribution Guide

I want contribute with this repository, and others also will want!

Let's define tasks and the contribution guideline!

I have golang projects needing consume the Openshift Origin API!

The Glide was a great choice!

Client go compatible with openshift < 3.5

Hello,

I'm currently working with openshift v3.5 and unfortunately for me, I can't upgrade the version.

I was looking in the code client-go to see if I can use it even if I don't have the correct version of openshift. And what a disappointment I had when I seen that the APIPath and the GroupVersion was hardcoding in each package.

It will be nice if we can have the APIPath and the GroupVersion in the parameter of the method of setConfigDefaults for each endpoints. (Well as this method as package private, maybe we can another method like setLegacyConfig)

As far I can see, it seems that all the code has been developed in order to be retro compatible. For example in github.com/openshift/api/{endpoint like route}/v1/register provides a const LegacyGroupName that could be used in the client-go.

Is it something that can interest you ?

How to get list of `DeploymentConfig` in a controller

Hey, I am looking for a way to get a list of all DeploymentConfigs in my operator.
I ended up with something like the following but I am kind of unsure how I am supposed to instantiate an AppsV1Client.

import (
    openshiftApiv1 "github.com/openshift/api/apps/v1"
)

openshiftClient := openshiftCLientv1.New() // what do i have to pass to New?
if err := openshiftClient.List(context.TODO(), goCli.MatchingLabels(labels), webEosDeploymentConfigList); err != nil {
    return nil, err
}

Getting undefined error message after changes in `route/clientset/versioned/scheme/register.go`

While creating the custom controller using Kubernetes go-client and OpenShift go-client, I'm getting the issue

/go/src/github.com/openshift/client-go/route/clientset/versioned/scheme/register.go:39:2: undefined: "k8s.io/apimachinery/pkg/util/runtime".Must

This error seems to be an impact after the changes being done here: https://github.com/openshift/client-go/blob/master/route/clientset/versioned/scheme/register.go

I'm just importing the route package from the OpenShift go-client in my custom controller as:


	"k8s.io/apimachinery/pkg/fields"
	"k8s.io/apimachinery/pkg/util/runtime"
	"k8s.io/apimachinery/pkg/util/wait"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/rest"
	"k8s.io/client-go/tools/cache"
	"k8s.io/client-go/util/workqueue"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

	v1 "github.com/openshift/api/route/v1"
	routev1 "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"

Any help would be highly appreciated.

CC/ @deads2k

Install OpenShift operators

Looking to install OpenShift operators using OpenShift client-go. Goal is to install any specific operator that is available when executing oc get packagemanifests.

When tried with a kubernetes client-go, I did hit an error as below

"Server could not find the resource" when specifying a group "operators.coreos.com", version "v1" and resource "operators".

Would like to know if it is even possible to install Operators using client-go.

OAuthClient does not get deleted intermittently.

Hi Folks,

We are using OpenShift OAuth ClientSet to delete the OAuthClient instances on our cluster. We noticed that delete does not work well occasionally.

Please find the reference code that we are using to delete the OAuthClient.

oauth, err := oauthclient.NewForConfig(cfg)
if err != nil {
 return err
}

foreground := metav1.DeletePropagationForeground
deleteOptions := metav1.DeleteOptions{PropagationPolicy: &foreground}

err = oauth.OAuthClients().Delete(context.TODO(), oa, deleteOptions)
if err != nil {
  return err
}

Please let me know if you would require any further details.

Can not "go get github.com/openshift/client-go/build/clientset/versioned/typed/build/v1"

$ go get github.com/openshift/client-go/build/clientset/versioned/typed/build/v1                                                                             
# github.com/openshift/client-go/build/clientset/versioned/typed/build/v1
../../go/pkg/mod/github.com/openshift/[email protected]+incompatible/build/clientset/versioned/typed/build/v1/build.go:57:5: not enough arguments in call to c.client.Get().Namespace(c.ns).Resource("builds").Name(name).VersionedParams(&options, scheme.ParameterCodec).Do
	have ()
	want (context.Context)
../../go/pkg/mod/github.com/openshift/[email protected]+incompatible/build/clientset/versioned/typed/build/v1/build.go:69:5: not enough arguments in call to c.client.Get().Namespace(c.ns).Resource("builds").VersionedParams(&opts, scheme.ParameterCodec).Do
	have ()
	want (context.Context)
../../go/pkg/mod/github.com/openshift/[email protected]+incompatible/build/clientset/versioned/typed/build/v1/build.go:81:8: not enough arguments in call to c.client.Get().Namespace(c.ns).Resource("builds").VersionedParams(&opts, scheme.ParameterCodec).Watch
	have ()
	want (context.Context)
../../go/pkg/mod/github.com/openshift/[email protected]+incompatible/build/clientset/versioned/typed/build/v1/build.go:91:5: not enough arguments in call to c.client.Post().Namespace(c.ns).Resource("builds").Body(build).Do
	have ()
	want (context.Context)
../../go/pkg/mod/github.com/openshift/[email protected]+incompatible/build/clientset/versioned/typed/build/v1/build.go:104:5: not enough arguments in call to c.client.Put().Namespace(c.ns).Resource("builds").Name(build.ObjectMeta.Name).Body(build).Do
	have ()
	want (context.Context)
../../go/pkg/mod/github.com/openshift/[email protected]+incompatible/build/clientset/versioned/typed/build/v1/build.go:120:5: not enough arguments in call to c.client.Put().Namespace(c.ns).Resource("builds").Name(build.ObjectMeta.Name).SubResource("status").Body(build).Do
	have ()
	want (context.Context)
../../go/pkg/mod/github.com/openshift/[email protected]+incompatible/build/clientset/versioned/typed/build/v1/build.go:132:5: not enough arguments in call to c.client.Delete().Namespace(c.ns).Resource("builds").Name(name).Body(options).Do
	have ()
	want (context.Context)
../../go/pkg/mod/github.com/openshift/[email protected]+incompatible/build/clientset/versioned/typed/build/v1/build.go:143:5: not enough arguments in call to c.client.Delete().Namespace(c.ns).Resource("builds").VersionedParams(&listOptions, scheme.ParameterCodec).Body(options).Do
	have ()
	want (context.Context)
../../go/pkg/mod/github.com/openshift/[email protected]+incompatible/build/clientset/versioned/typed/build/v1/build.go:156:5: not enough arguments in call to c.client.Patch(pt).Namespace(c.ns).Resource("builds").SubResource(subresources...).Name(name).Body(data).Do
	have ()
	want (context.Context)
../../go/pkg/mod/github.com/openshift/[email protected]+incompatible/build/clientset/versioned/typed/build/v1/build.go:170:5: not enough arguments in call to c.client.Put().Namespace(c.ns).Resource("builds").Name(buildName).SubResource("details").Body(build).Do
	have ()
	want (context.Context)
../../go/pkg/mod/github.com/openshift/[email protected]+incompatible/build/clientset/versioned/typed/build/v1/build.go:170:5: too many errors

Thanks a lot!

Issue while running the example present in this repository

While running the builds example as present in this repository, I'm facing the below issue:

./main.go:46:72: cannot use "k8s.io/apimachinery/pkg/apis/meta/v1".ListOptions literal (type "k8s.io/apimachinery/pkg/apis/meta/v1".ListOptions) as type "github.com/openshift/client-go/vendor/k8s.io/apimachinery/pkg/apis/meta/v1".ListOptions in argument to buildV1Client.Builds(namespace).List
./main.go:58:78: cannot use "k8s.io/apimachinery/pkg/apis/meta/v1".GetOptions literal (type "k8s.io/apimachinery/pkg/apis/meta/v1".GetOptions) as type "github.com/openshift/client-go/vendor/k8s.io/apimachinery/pkg/apis/meta/v1".GetOptions in argument to buildV1Client.Builds(namespace).Get
./main.go:71:96: cannot use "k8s.io/apimachinery/pkg/apis/meta/v1".GetOptions literal (type "k8s.io/apimachinery/pkg/apis/meta/v1".GetOptions) as type "github.com/openshift/client-go/vendor/k8s.io/apimachinery/pkg/apis/meta/v1".GetOptions in argument to buildV1Client.BuildConfigs(namespace).Get
./main.go:81:26: cannot use objectMeta (type "k8s.io/apimachinery/pkg/apis/meta/v1".ObjectMeta) as type "github.com/openshift/api/vendor/k8s.io/apimachinery/pkg/apis/meta/v1".ObjectMeta in assignment
./main.go:85:80: cannot use &buildRequest (type *"github.com/openshift/api/build/v1".BuildRequest) as type *"github.com/openshift/client-go/vendor/github.com/openshift/api/build/v1".BuildRequest in argument to buildV1Client.BuildConfigs(namespace).Instantiate```

Not sure how to resolve this issue. Looks like the Kubernetes Api is not being able to reference or use as type of OpenShift API.

Any suggestions on how to resolve this, would be highly appreciated.

How to use oc rsync command ?

I want to copy files from a docker container to local file system using oc rsync <container_filename> <destination_local_directory>. Is it possible to do, if yes then how?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.