Невозможно создать CRD с помощью клиента Python Kubernetes

Что случилось

Я пытаюсь создать собственное определение ресурса в kubernetes, используя клиент kubernetes python, но я не могу этого сделать, было бы полезно, если бы кто-нибудь мог объяснить, что я делаю здесь не так

Traceback (most recent call last):
  File "/home/talha/python/examples/custom_object.py", line 239, in <module>
    main()
  File "/home/talha/python/examples/custom_object.py", line 191, in main
    api.create_custom_resource_definition(body=crd)
  File "/home/talha/python/kubernetes/client/api/apiextensions_v1beta1_api.py", line 65, in create_custom_resource_definition
    return self.create_custom_resource_definition_with_http_info(body, **kwargs)  # noqa: E501
  File "/home/talha/python/kubernetes/client/api/apiextensions_v1beta1_api.py", line 166, in create_custom_resource_definition_with_http_info
    collection_formats=collection_formats)
  File "/home/talha/python/kubernetes/client/api_client.py", line 353, in call_api
    _preload_content, _request_timeout, _host)
  File "/home/talha/python/kubernetes/client/api_client.py", line 184, in __call_api
    _request_timeout=_request_timeout)
  File "/home/talha/python/kubernetes/client/api_client.py", line 397, in request
    body=body)
  File "/home/talha/python/kubernetes/client/rest.py", line 280, in POST
    body=body)
  File "/home/talha/python/kubernetes/client/rest.py", line 233, in request
    raise ApiException(http_resp=r)
kubernetes.client.exceptions.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Cache-Control': 'no-cache, private', 'Content-Type': 'application/json', 'Date': 'Mon, 31 Aug 2020 09:51:19 GMT', 'Content-Length': '610'})
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"CustomResourceDefinition in version \"v1beta1\" cannot be handled as a CustomResourceDefinition: v1beta1.CustomResourceDefinition.ObjectMeta: v1.ObjectMeta.Labels: CreationTimestamp: unmarshalerDecoder: parsing time \"null\" as \"2006-01-02T15:04:05Z07:00\": cannot parse \"null\" as \"2006\", error found in #10 byte of ...|p\": \"null\", \"labels\"|..., bigger context ...|o/version\": \"v0.2.4\"}, \"creationTimestamp\": \"null\", \"labels\": {\"component\": \"velero\"}, \"name\": \"back|...","reason":"BadRequest","code":400}

Что вы ожидали?: создайте CRD.

Как это воспроизвести (максимально минимально и точно):

    config.load_kube_config()
    api = client.ApiextensionsV1beta1Api()
    crd = {
         "apiVersion":"apiextensions.k8s.io/v1beta1",
         "kind":"CustomResourceDefinition",
         "metadata":{
            "annotations":{
               "controller-gen.kubebuilder.io/version":"v0.2.4"
            },
            "creationTimestamp":"null",
            "labels":{
               "component":"velero"
            },
            "name":"backupstoragelocations.velero.io"
         },
         "spec":{
            "group":"velero.io",
            "names":{
               "kind":"BackupStorageLocation",
               "listKind":"BackupStorageLocationList",
               "plural":"backupstoragelocations",
               "singular":"backupstoragelocation"
            },
            "preserveUnknownFields":"false",
            "scope":"Namespaced",
            "validation":{
               "openAPIV3Schema":{
                  "description":"BackupStorageLocation is a location where Velero stores backup objects.",
                  "properties":{
                     "apiVersion":{
                        "description":"APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
                        "type":"string"
                     },
                     "kind":{
                        "description":"Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
                        "type":"string"
                     },
                     "metadata":{
                        "type":"object"
                     },
                     "spec":{
                        "description":"BackupStorageLocationSpec defines the specification for a Velero BackupStorageLocation.",
                        "properties":{
                           "accessMode":{
                              "description":"AccessMode defines the permissions for the backup storage location.",
                              "enum":[
                                 "ReadOnly",
                                 "ReadWrite"
                              ],
                              "type":"string"
                           },
                           "backupSyncPeriod":{
                              "description":"BackupSyncPeriod defines how frequently to sync backup API objects from object storage. A value of 0 disables sync.",
                              "nullable":"true",
                              "type":"string"
                           },
                           "config":{
                              "additionalProperties":{
                                 "type":"string"
                              },
                              "description":"Config is for provider-specific configuration fields.",
                              "type":"object"
                           },
                           "objectStorage":{
                              "description":"ObjectStorageLocation specifies the settings necessary to connect to a provider's object storage.",
                              "properties":{
                                 "bucket":{
                                    "description":"Bucket is the bucket to use for object storage.",
                                    "type":"string"
                                 },
                                 "caCert":{
                                    "description":"CACert defines a CA bundle to use when verifying TLS connections to the provider.",
                                    "format":"byte",
                                    "type":"string"
                                 },
                                 "prefix":{
                                    "description":"Prefix is the path inside a bucket to use for Velero storage. Optional.",
                                    "type":"string"
                                 }
                              },
                              "required":[
                                 "bucket"
                              ],
                              "type":"object"
                           },
                           "provider":{
                              "description":"Provider is the provider of the backup storage.",
                              "type":"string"
                           }
                        },
                        "required":[
                           "objectStorage",
                           "provider"
                        ],
                        "type":"object"
                     },
                     "status":{
                        "description":"BackupStorageLocationStatus describes the current status of a Velero BackupStorageLocation.",
                        "properties":{
                           "accessMode":{
                              "description":"AccessMode is an unused field. \n Deprecated: there is now an AccessMode field on the Spec and this field will be removed entirely as of v2.0.",
                              "enum":[
                                 "ReadOnly",
                                 "ReadWrite"
                              ],
                              "type":"string"
                           },
                           "lastSyncedRevision":{
                              "description":"LastSyncedRevision is the value of the `metadata/revision` file in the backup storage location the last time the BSL's contents were synced into the cluster. \n Deprecated: this field is no longer updated or used for detecting changes to the location's contents and will be removed entirely in v2.0.",
                              "type":"string"
                           },
                           "lastSyncedTime":{
                              "description":"LastSyncedTime is the last time the contents of the location were synced into the cluster.",
                              "format":"date-time",
                              "nullable":"true",
                              "type":"string"
                           },
                           "phase":{
                              "description":"Phase is the current state of the BackupStorageLocation.",
                              "enum":[
                                 "Available",
                                 "Unavailable"
                              ],
                              "type":"string"
                           }
                        },
                        "type":"object"
                     }
                  },
                  "type":"object"
               }
            },
            "version":"v1",
            "versions":[
               {
                  "name":"v1",
                  "served":"true",
                  "storage":"true"
               }
            ]
         }
      }
    api.create_custom_resource_definition(body=crd)

Что еще нам нужно знать?:

Окружающая среда:

  • Версия Kubernetes (v1.18.6):
  • ОС (ubuntu 20.04):
  • Версия Python (3.8.2)
  • Версия клиента Python (11.0.0)

person Talha Latif    schedule 31.08.2020    source источник


Ответы (1)


Давайте посмотрим на сообщение об ошибке:

CustomResourceDefinition в версии v1beta1 не может обрабатываться как CustomResourceDefinition: v1beta1.CustomResourceDefinition.ObjectMeta: v1.ObjectMeta.Labels: CreationTimestamp: unmarshalerDecoder: время синтаксического анализа null, поскольку 2006-01-02Zse07: 04: 0

Итак, как следует из сообщения об ошибке, проблема связана с CreationTimeStamp. Теперь вопрос, что не так с вашим CreationTimestamp?

Ваша CreationTimestamp должна быть:

{
"creationTimestamp":null, // creationTimestamp is actually defined, but the value is null
}

вместо того:

{
"creationTimestamp":"null", // setting creationTimestamp equal to a string value "null"
}
person Kamol Hasan    schedule 31.08.2020
comment
чем ты, я только что узнал, что createTimestamp создается автоматически, я удалил это и теперь он работает - person Talha Latif; 01.09.2020