I am using the fake
clientset to perform some mocking in a k8s
cli tool I am creating.
Therefore I am creating a Job
resource
jobs := clientset.BatchV1().Jobs(mynamespace)
_, err = jobs.Create(context.TODO(), job, metav1.CreateOptions{})
The clienset has been created as follows:
clientset := testclient.NewSimpleClientset()
where
testclient "k8s.io/client-go/kubernetes/fake"
The job seems to be created, ie err
is nil
on the call above.
I then (from another function call) try to list the corresponding pods (using the exact same clientset
)
podList, err = clientset.CoreV1().Pods(myNamespace).List(context.TODO(), labelOptions)
However the length of the corresponding list is always zero
len(podList.Items) = 0
Shouldn't the call using the fake
clienset create all related mock resources? (such as the job's pod)
Shouldn't the call using the fake clienset create all related mock resources? (such as the job's pod)
No, the fake clientset does nothing except put objects into cache. In a real kube.netes cluster, JobController
reconciles jobs and creates pods.
I suggest you testing in a real kube.netes cluster, such as K3s .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.