当前位置: 首页 > 知识库问答 >
问题:

无法使用kubernetes python客户端创建CRD

莫宁
2023-03-14

怎么了

我试图使用kubernetes python客户机在kubernetes中创建自定义资源定义,但我无法这样做,如果有人能解释我在这里做错了什么,那将会很有帮助

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}

    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)
    null

共有1个答案

韦安顺
2023-03-14

让我们来看看错误消息:

版本“V1Beta1”中的CustomResourceDefinition不能作为CustomResourceDefinition:V1Beta1.CustomResourceDefinition.objectMeta:V1.ObjectMeta.Labels:CreationTimeStamp:UnmarshAlerDecoder:将“NULL”解析为“2006-01-02T15:04:05Z07:00”:不能将“NULL”解析为“2006”

因此,正如错误消息所示,CreationTimeStamp存在问题。现在的问题是,您的CreationTimeStamp出了什么问题?

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

而不是:

{
"creationTimestamp":"null", // setting creationTimestamp equal to a string value "null"
}
 类似资料:
  • 使用quarkiverse/Quarkus cxf在Quarkus中使用SOAP Web服务尝试使用此示例实现客户端 无法使用以下扩展名导入

  • 创建客户端有两种方式,一种是直接使用特化的构造器函数,另一种是使用工厂构造器函数。 第一种方式返回的是具体的客户端结构体指针对象,第二种方式返回的是客户端接口对象。 使用特化的构造器函数创建客户端 特化的构造器函数有下面几个: func NewHTTPClient(uri ...string) (client *HTTPClient) func NewTCPClient(uri ...string

  • 我正在使用java高级rest客户端在我的应用程序中集成elasticsearch,但无法创建索引 在某个地方,我发现要执行请求,我们需要使用index(请求)方法(我在代码中已注释),但它表明index(请求)方法已从RestHighLevelClient类型中弃用。 这是我的代码:

  • 我正在尝试使用enuncicate v1.26.2 ant任务创建java客户端库。问题是,每次我尝试这样做时,我都会收到以下警告信息: 我已经检查了java-客户端发音jar是否在类路径上,并且发音甚至说它已经在输出中找到了它。 所以我不确定到底该怎么做。我尝试在谷歌上搜索,发现SO只有几个问题需要阐明,似乎没有一个回答我的问题。这是我的蚂蚁脚本,其中包含相关行: 注意:docs export被

  • 问题内容: 我们正在通过电子邮件与之合作的公司向我们提供了wsdl和xsd模式。通过IPsec隧道访问与我们连接的Web服务。已发布的WSDL中有本地引用(末尾有本地引用),这意味着我们无法使用它。 第一个问题:这是常见设置吗?我认为拥有WSDL的意义不仅在于定义合同,而且还应将服务公开给消费者。 我可以使用wsimport,wsconsume等从提供的WSDL轻松生成客户端/服务器代码。我知道,

  • 我使用Jsch作为SFTP客户端从远程SFTP目录读取和写入XML文件。 我使用5秒钟的工作来检查新文件是否可用于草稿,在30或40分钟循环后,我得到以下错误 这是用于创建连接的源代码 我试图增加JVM线程栈的大小,并增加unix=允许的本地进程的限制。 我使用以下命令来执行此操作: 我试图创建一个jsch会话池,jsch会话当它没有断开时,它是不可用的= 我的作业被部署到jboss-as-7上的