0

I'm trying to use the client-go to create pods and other resources on my cluster.

From what I understand the best way to create stuff on your cluster using client-go is to use the dynamic-create version (in the examples there is a dynamic-create-update-delete example). Because I can just take my yaml and make it into unstructured.Unstructured and then create the resource.

This is working fine for me while creating pods using kind: Deployment but when I try to create a pod with the kind: PersistentVolumeClaim I get an error:

panic: PersistentVolumeClaim in version "v1" cannot be handled as a Deployment: converting (v1.PersistentVolumeClaim).v1.PersistentVolumeClaimSpec to (apps.Deployment).apps.DeploymentSpec: Replicas not present in src

If I understand the error correctly this happen because I declare my deploymentRes with the resource: "deployments"

deploymentRes := schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}

And then create with the:

client.Resource(deploymentRes).Namespace(namespace).Create(context.TODO(), deployment, metav1.CreateOptions{})

The problem here is that I can't find what to put instead of Resource: "deployments" when I want to create a pvc. I have tried to put in persistentvolumeclaim but just get the err:

"panic: the server could not find the requested resource"

Please if you know anything that could help, or put me in the right direction would be super helpful!

Thanks!

4

1 回答 1

0

这里的问题是,当我想创建 pvc 时,我找不到放什么而不是 Resource: "deployments"

你的假设是正确的。你只错过了两点:

  • Group参数应该是(空""字符串)
  • Resource论点应该是("persistentvolumeclaims"复数形式)
pvcRes := schema.GroupVersionResource{Group: "", Version: "v1", Resource: "persistentvolumeclaims"}
于 2021-01-08T15:26:38.643 回答