Questions tagged [client-go]

208 questions
2
votes
0 answers

How to make a workqueue consistent across replicas in kubernetes custom controllers?

In the k8s.io/client-go package, we have a workqueue that is used for adding items to whenever informers detect changes to resources. I'm trying to figure out if there is a way, in the case we have multiple pods running the controllers, that the…
2
votes
0 answers

How to unit test a function that uses leaderelection.RunOrDie

Here's a (somewhat simplified) bit of code that exposes a boolean if we've become leader via K8s leader election and false otherwise: type SimpleLeader struct { amLeader atomic.Value } func (s *SimpleLeader) run(ctx context.Context, client…
d80tb7
  • 863
  • 2
  • 9
  • 20
2
votes
1 answer

Continuously Watch Pods in Kubernetes using golang SDK

I want to watch changes to Pods continuously using the client-go Kubernetes SDK. I am using the below code to watch the changes: func (c *Client) watchPods(namespace string, restartLimit int) { fmt.Println("Watch Kubernetes Pods") watcher,…
Faizan
  • 181
  • 1
  • 1
  • 11
2
votes
0 answers

Why does Replica status value not get reflected while using mock client-go?

Background Objective is to write a unit test in golang to check whether given deployment in a namespace is up or not. I am using the library "k8s.io/client-go/kubernetes/fake" to do the same. These are the steps I plan to execute: Creata mock…
ayivaak
  • 67
  • 8
2
votes
2 answers

Client-Go, How to watch for newly created Pods in Kubernetes

I need to write a golang application with the help of client-go which will listen/watch a particular namespace for any of these events: A new pod has been created A pod has been deleted A new container has been added to existing pods Image for…
Jananath Banuka
  • 2,951
  • 8
  • 57
  • 105
2
votes
1 answer

Undefined error in go-client when listing the nodes

I am new to golang and I am trying to list the nodes in my minikube cluster with the client-go. And I encounter the following issue: nodeList.Items undefined (type *invalid type has no field or method Items)compilerMissingFieldOrMethod And here's…
Jananath Banuka
  • 2,951
  • 8
  • 57
  • 105
2
votes
0 answers

Kubectl exec with client-go does not stream output in GitLab CI pipeline

I'm trying to execute a command (e.g. curl) in a pod and evaluate the stdout of that command on my client. This works perfectly fine on my machine, however not when executed in a GitLab pipeline. The command itself is executed in both cases, however…
Sirea
  • 53
  • 4
2
votes
0 answers

Tests fail when trying to list kubernetes CRD objects using ListOptions' Limit

I'm trying to list CRD objects using Limit as follows: ... someObjList := v1alpha1.SomeObjList{} _ = cl.List(ctx, &someObjList, client.InNamespace(lib.Namespace), &listOptions) When testing, I add 25 objects to a fake client then call the list…
2
votes
1 answer

How to get the latest change time of StatefulSet in k8s

I know, for example, that you can get the lastUpdateTime of a Deployment with kubectl: kubectl get deploy -o jsonpath={.status.conditions[1].lastUpdateTime} Or via client-go: func deploymentCheck(namespace string, clientset…
2
votes
1 answer

What type of edits will change a ReplicaSet and StatefulSet AGE?

What type of edits will change a ReplicaSet and StatefulSet AGE(CreationTimeStamp)? I'm asking this because I noticed that If I change a Deployment image, a new ReplicaSet will be created. The old ReplicaSet continues to exist with DESIRED set to…
2
votes
0 answers

List Events for Pod using client-go in readable format

I am using the below client-go function to list the events for a particular pod in a specified namespace. events, _ := clientset.CoreV1().Events("namespaceName").List(context.TODO(), metav1.ListOptions{FieldSelector: "involvedObject.name=podName",…
Akash
  • 73
  • 7
2
votes
1 answer

Retrieve kubernetes nodes that do not contain label using apimachinery/client-go

I want to fetch the list (if any) of kubernetes nodes that do not contain a label. I have managed to do the opposite using client-go labelSelector := metav1.LabelSelector{ MatchLabels: map[string]string{ "somelabel":…
pkaramol
  • 16,451
  • 43
  • 149
  • 324
2
votes
2 answers

SharedInformerFactoryWithOptions - Not able to filter based on labels

I want to watch Kubernetes pod events for a certain application. I went with NewSharedInformerFactoryWithOptions. I have added appropriate labels selector, But it is not getting filtered out. As I want to filter it using the label:…
ankit
  • 324
  • 1
  • 4
  • 11
2
votes
1 answer

How can I get events messages from a pod from Kubernetes using client-go API?

How can I get events messages from a pod, like this command using client-go Kubernetes API: kubectl describe pod spark-t2f59 -n spark Events: Type Reason Age From Message ---- ------ ---- ---- …
javier_orta
  • 457
  • 4
  • 15
2
votes
0 answers

kubernetes go-client: How to refresh token, using kubeconfig file

While trying to connect to kubernetes cluster using kubeconfig file I am getting below mentioned error Response: {"error":"invalid_request","error_description":"Refresh token is invalid or has already been claimed by another client."} Following is…