簡體   English   中英

如何在 Kubernetes 中創建自定義對象?

[英]How to create custom objects in Kubernetes?

我正在使用 Velero 創建、備份和恢復,Velero 有控制器,當我可以創建自定義對象時會觸發這些控制器。

import veleroApi "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"

restoreObj := veleroApi.Restore{
    TypeMeta:   metav1.TypeMeta{},
    ObjectMeta: metav1.ObjectMeta{
        DeletionGracePeriodSeconds: &gracePeriodSeconds,
    },
    Spec:       veleroApi.RestoreSpec{
        BackupName:              "backup-name-20211101",
        RestorePVs:              &restorePV,
    },
    Status:     veleroApi.RestoreStatus{},
}

但是如何將這個自定義 object 提交到 Kube API 服務器?

我使用 API 客戶端應用更改:

apiClient.CoreV1().RESTClient().Patch(types.ApplyPatchType).Body(restoreObj).Do(context)

但我得到:

unknown type used for body: {TypeMeta:{Kind:Restore APIVersion:velero.io/v1} ObjectMeta:{Name: GenerateName: Namespace:velero SelfLink: UID: ResourceVersion: Generation:0 CreationTimestamp:0001-01-01 00:00:00 +0000 UTC DeletionTimestamp:<nil> DeletionGracePeriodSeconds:0xc000256018 Labels:map[] Annotations:map[] OwnerReferences:[] Finalizers:[] ClusterName: ManagedFields:[]} Spec:{BackupName:backup-name-20211101 ScheduleName: IncludedNamespaces:[] ExcludedNamespaces:[] IncludedResources:[] ExcludedResources:[] NamespaceMapping:map[] LabelSelector:nil RestorePVs:0xc0007a9088 PreserveNodePorts:<nil> IncludeClusterResources:<nil> Hooks:{Resources:[]}} Status:{Phase: ValidationErrors:[] Warnings:0 Errors:0 FailureReason: StartTimestamp:<nil> CompletionTimestamp:<nil> Progress:<nil>}}

有一個 Velero 客戶端。

作為一個例子,看看這段代碼

restore, err := o.client.VeleroV1().Restores(restore.Namespace).Create(context.TODO(), restore, metav1.CreateOptions{})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM