kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
141 stars 45 forks source link

Creating Deployment Patch using the AppsV1API_patchNamespacedDeployment #212

Closed KabilanMA closed 6 months ago

KabilanMA commented 6 months ago

I'm trying to create a patch for the existing Kubernetes deployment in my local minikube cluster. I have successfully implemented a function to create a new deployment.

For the deployment patch, I think I have to use the following function in the api\AppsV1API.c:

v1_deployment_t *
AppsV1API_patchNamespacedDeployment(apiClient_t *apiClient, char *name, char *_namespace, object_t *body, char *pretty, char *dryRun, char *fieldManager, char *fieldValidation, int force)

I don't understand the function's correct argument for the object_t *body.

Deployment configuration file:

{
    "apiVersion": "apps/v1",
    "kind": "Deployment",
    "metadata": {
      "name": "busybox-deployment"
    },
    "spec": {
      "replicas": 1,
      "selector": {
        "matchLabels": {
          "app": "busybox"
        }
      },
      "template": {
        "metadata": {
          "labels": {
            "app": "busybox"
          }
        },
        "spec": {
          "containers": [
            {
              "name": "busybox-container",
              "image": "busybox",
              "command": ["sleep", "3600"]
            }
          ]
        }
      }
    }
  }

I want to change the replicas from 1 to 3.

I have tried giving {'spec': {'replicas': 2}} and [{'op': 'replace', 'path': '/spec/replicas', 'value': 2}], nothing seems to work.

ityuhui commented 6 months ago

FYI https://github.com/kubernetes-client/c/issues/196

And the last parameter force has been changed from int to int * in this API:

AppsV1API_patchNamespacedDeployment(apiClient_t *apiClient, char *name, char *_namespace, object_t *body, char *pretty, char *dryRun, char *fieldManager, char *fieldValidation, int *force)
KabilanMA commented 6 months ago

Generic client seems to solve the problem. https://github.com/kubernetes-client/c/issues/196#issuecomment-1595573290

ityuhui commented 6 months ago

Yes. the generic client can solve the problem. But after #210 merges, I think the API AppsV1API_patchNamespacedDeployment should work too. So if you don't want to use generic client, try this please.