From 74de5e1b70df9c83ce7e61b17e94b5800c88d1a9 Mon Sep 17 00:00:00 2001 From: willise Date: Thu, 24 Nov 2022 15:51:39 +0800 Subject: [PATCH] enable cloneset deleting pvc when pod hanging Signed-off-by: willise --- apis/apps/v1alpha1/cloneset_types.go | 4 + .../crd/bases/apps.kruise.io_clonesets.yaml | 4 + .../apps.kruise.io_uniteddeployments.yaml | 4 + .../cloneset/sync/cloneset_scale.go | 115 +++++++++++++ .../cloneset/sync/cloneset_scale_test.go | 162 ++++++++++++++++++ .../cloneset/utils/cloneset_utils.go | 29 +++- pkg/util/ownerref.go | 66 +++++++ pkg/util/ownerref_test.go | 154 +++++++++++++++++ pkg/util/pods.go | 9 + 9 files changed, 541 insertions(+), 6 deletions(-) create mode 100644 pkg/util/ownerref.go create mode 100644 pkg/util/ownerref_test.go diff --git a/apis/apps/v1alpha1/cloneset_types.go b/apis/apps/v1alpha1/cloneset_types.go index 4d95dd224e..7ccfcec652 100644 --- a/apis/apps/v1alpha1/cloneset_types.go +++ b/apis/apps/v1alpha1/cloneset_types.go @@ -93,6 +93,10 @@ type CloneSetScaleStrategy struct { // The scale will fail if the number of unavailable pods were greater than this MaxUnavailable at scaling up. // MaxUnavailable works only when scaling up. MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"` + + // Indicate if cloneset will reuse aleady existed pvc to + // rebuild a new pod + DisablePVCReuse bool `json:"disablePVCReuse,omitempty"` } // CloneSetUpdateStrategy defines strategies for pods update. diff --git a/config/crd/bases/apps.kruise.io_clonesets.yaml b/config/crd/bases/apps.kruise.io_clonesets.yaml index da2fb66cdc..00d0151b88 100644 --- a/config/crd/bases/apps.kruise.io_clonesets.yaml +++ b/config/crd/bases/apps.kruise.io_clonesets.yaml @@ -149,6 +149,10 @@ spec: description: ScaleStrategy indicates the ScaleStrategy that will be employed to create and delete Pods in the CloneSet. properties: + disablePVCReuse: + description: Indicate if cloneset will reuse aleady existed pvc + to rebuild a new pod + type: boolean maxUnavailable: anyOf: - type: integer diff --git a/config/crd/bases/apps.kruise.io_uniteddeployments.yaml b/config/crd/bases/apps.kruise.io_uniteddeployments.yaml index a274937b18..ef037cfc73 100644 --- a/config/crd/bases/apps.kruise.io_uniteddeployments.yaml +++ b/config/crd/bases/apps.kruise.io_uniteddeployments.yaml @@ -617,6 +617,10 @@ spec: that will be employed to create and delete Pods in the CloneSet. properties: + disablePVCReuse: + description: Indicate if cloneset will reuse aleady + existed pvc to rebuild a new pod + type: boolean maxUnavailable: anyOf: - type: integer diff --git a/pkg/controller/cloneset/sync/cloneset_scale.go b/pkg/controller/cloneset/sync/cloneset_scale.go index 69ca12c685..ae62497509 100644 --- a/pkg/controller/cloneset/sync/cloneset_scale.go +++ b/pkg/controller/cloneset/sync/cloneset_scale.go @@ -29,11 +29,15 @@ import ( clonesetutils "github.com/openkruise/kruise/pkg/controller/cloneset/utils" "github.com/openkruise/kruise/pkg/util" "github.com/openkruise/kruise/pkg/util/expectations" + "github.com/openkruise/kruise/pkg/util/fieldindex" "github.com/openkruise/kruise/pkg/util/lifecycle" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/util/rand" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" + "sigs.k8s.io/controller-runtime/pkg/client" ) const ( @@ -60,6 +64,19 @@ func (r *realControl) Scale( return false, nil } + // If cloneset doesn't want to reuse pvc, clean up + // the existing pvc first. Then it looks like the pod + // is deleted by controller, new pod can be created. + if updateCS.Spec.ScaleStrategy.DisablePVCReuse { + uselessPVCs := getUselessPVCs(pods, pvcs) + if len(uselessPVCs) > 0 { + klog.V(3).Infof("Begin to clean up cloneset %s useless PVCs", controllerKey) + if modified, err := r.cleanupPVCs(updateCS, uselessPVCs); err != nil || modified { + return modified, err + } + } + } + // 1. manage pods to delete and in preDelete podsSpecifiedToDelete, podsInPreDelete, numToDelete := getPlannedDeletedPods(updateCS, pods) if modified, err := r.managePreparingDelete(updateCS, pods, podsInPreDelete, numToDelete); err != nil || modified { @@ -403,3 +420,101 @@ func (r *realControl) choosePodsToDelete(cs *appsv1alpha1.CloneSet, totalDiff in return podsToDelete } + +func getInstanceIDsFromPods(pods []*v1.Pod) sets.String { + ins := sets.NewString() + for _, pod := range pods { + if id := clonesetutils.GetInstanceID(pod); id != "" { + ins.Insert(id) + } + } + return ins +} + +func getUselessPVCs(pods []*v1.Pod, pvcs []*v1.PersistentVolumeClaim) map[string]*v1.PersistentVolumeClaim { + activeIDs := getInstanceIDsFromPods(pods) + + useless := map[string]*v1.PersistentVolumeClaim{} + for _, pvc := range pvcs { + id := clonesetutils.GetInstanceID(pvc) + if id != "" && !activeIDs.Has(id) { + useless[id] = pvc + } + } + return useless +} + +func (r *realControl) cleanupPVCs(cs *appsv1alpha1.CloneSet, uselessPVCs map[string]*v1.PersistentVolumeClaim) (bool, error) { + var modified bool + + pods, err := getAllPods(r.Client, cs) + if err != nil { + klog.Errorf("Could not get cloneset %s owned pods", clonesetutils.GetControllerKey(cs)) + return modified, err + } + + // If useless pvc owner pod does not exist, the pvc can be deleted directly, + // else update pvc's ownerreference to pod. + for _, pod := range pods { + instanceID := clonesetutils.GetInstanceID(pod) + if pvc, ok := uselessPVCs[instanceID]; ok { + if updateClaimOwnerRefToPod(pvc, cs, pod) { + if modified, err := r.updatePVC(cs, pvc); err != nil && !errors.IsNotFound(err) { + return modified, err + } + modified = true + } + // Left pvcs will be deleted directly. + delete(uselessPVCs, instanceID) + } + } + + for _, pvc := range uselessPVCs { + // It's safe to delete pvc that has no pod found. + if modified, err := r.deletePVC(cs, pvc); err != nil && !errors.IsNotFound(err) { + return modified, err + } + modified = true + } + return modified, err +} + +func getAllPods(reader client.Reader, cs *appsv1alpha1.CloneSet) ([]*v1.Pod, error) { + opts := &client.ListOptions{ + Namespace: cs.Namespace, + FieldSelector: fields.SelectorFromSet(fields.Set{fieldindex.IndexNameForOwnerRefUID: string(cs.UID)}), + } + pods, err := clonesetutils.GetAllPods(reader, opts) + if err != nil { + return nil, err + } + return pods, nil +} + +func (r *realControl) updatePVC(cs *appsv1alpha1.CloneSet, pvc *v1.PersistentVolumeClaim) (bool, error) { + var modified bool + if err := r.Client.Update(context.TODO(), pvc); err != nil { + r.recorder.Eventf(cs, v1.EventTypeWarning, "FailedUpdate", "failed to update PVC %s: %v", pvc.Name, err) + return modified, err + } + return true, nil +} + +func (r *realControl) deletePVC(cs *appsv1alpha1.CloneSet, pvc *v1.PersistentVolumeClaim) (bool, error) { + var modified bool + clonesetutils.ScaleExpectations.ExpectScale(clonesetutils.GetControllerKey(cs), expectations.Delete, pvc.Name) + if err := r.Delete(context.TODO(), pvc); err != nil { + clonesetutils.ScaleExpectations.ObserveScale(clonesetutils.GetControllerKey(cs), expectations.Delete, pvc.Name) + r.recorder.Eventf(cs, v1.EventTypeWarning, "FailedDelete", "failed to clean up PVC %s: %v", pvc.Name, err) + return modified, err + } + return true, nil +} + +func updateClaimOwnerRefToPod(pvc *v1.PersistentVolumeClaim, cs *appsv1alpha1.CloneSet, pod *v1.Pod) bool { + needsUpdate := false + needsUpdate = util.RemoveOwnerRef(pvc, cs) + podMeta := &pod.TypeMeta + util.UpdatePodMeta(podMeta) + return util.SetOwnerRef(pvc, pod, podMeta) || needsUpdate +} diff --git a/pkg/controller/cloneset/sync/cloneset_scale_test.go b/pkg/controller/cloneset/sync/cloneset_scale_test.go index 3f4ef7b430..5c58ac1522 100644 --- a/pkg/controller/cloneset/sync/cloneset_scale_test.go +++ b/pkg/controller/cloneset/sync/cloneset_scale_test.go @@ -32,6 +32,7 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" @@ -527,3 +528,164 @@ func TestGetOrGenAvailableIDs(t *testing.T) { t.Fatalf("expected got random id, but actually %v", id) } } + +func TestDisablePVCReuse(t *testing.T) { + cs := &appsv1alpha1.CloneSet{ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "foo", + UID: "test"}} + + podsToDelete := []*v1.Pod{ + { + ObjectMeta: metav1.ObjectMeta{ + Finalizers: []string{"a/b"}, + Namespace: "default", + Name: "foo-id1", + GenerateName: "foo-", + Labels: map[string]string{ + appsv1alpha1.CloneSetInstanceID: "id1", + "foo": "bar", + }, + OwnerReferences: []metav1.OwnerReference{ + { + APIVersion: "apps.kruise.io/v1alpha1", + Kind: "CloneSet", + Name: "foo", + UID: "test", + Controller: func() *bool { a := true; return &a }(), + BlockOwnerDeletion: func() *bool { a := true; return &a }(), + }, + }, + UID: "foo-id1", + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "foo-id3", + GenerateName: "foo-", + Labels: map[string]string{ + appsv1alpha1.CloneSetInstanceID: "id3", + "foo": "bar", + }, + OwnerReferences: []metav1.OwnerReference{ + { + APIVersion: "apps.kruise.io/v1alpha1", + Kind: "CloneSet", + Name: "foo", + UID: "test", + Controller: func() *bool { a := true; return &a }(), + BlockOwnerDeletion: func() *bool { a := true; return &a }(), + }, + }, + UID: "foo-id3", + }, + }, + } + + pvcs := map[string]*v1.PersistentVolumeClaim{ + "id1": { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "datadir-foo-id1", + Labels: map[string]string{ + appsv1alpha1.CloneSetInstanceID: "id1", + "foo": "bar", + }, + OwnerReferences: []metav1.OwnerReference{ + { + APIVersion: "apps.kruise.io/v1alpha1", + Kind: "CloneSet", + Name: "foo", + UID: "test", + Controller: func() *bool { a := true; return &a }(), + BlockOwnerDeletion: func() *bool { a := true; return &a }(), + }, + }, + }, + }, + "id2": { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "datadir-foo-id2", + Labels: map[string]string{ + appsv1alpha1.CloneSetInstanceID: "id2", + "foo": "bar", + }, + OwnerReferences: []metav1.OwnerReference{ + { + APIVersion: "apps.kruise.io/v1alpha1", + Kind: "CloneSet", + Name: "foo", + UID: "test", + Controller: func() *bool { a := true; return &a }(), + BlockOwnerDeletion: func() *bool { a := true; return &a }(), + }, + }, + }, + }, + "id3": { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "datadir-foo-id3", + Labels: map[string]string{ + appsv1alpha1.CloneSetInstanceID: "id3", + "foo": "bar", + }, + OwnerReferences: []metav1.OwnerReference{ + { + APIVersion: "apps.kruise.io/v1alpha1", + Kind: "CloneSet", + Name: "foo", + UID: "test", + Controller: func() *bool { a := true; return &a }(), + BlockOwnerDeletion: func() *bool { a := true; return &a }(), + }, + }, + }, + }, + } + + ctrl := newFakeControl() + for _, p := range podsToDelete { + _ = ctrl.Create(context.TODO(), p) + } + for _, p := range pvcs { + _ = ctrl.Create(context.TODO(), p) + } + + for _, p := range podsToDelete { + _ = ctrl.Delete(context.TODO(), p) + } + + deleted, err := ctrl.cleanupPVCs(cs, pvcs) + if err != nil { + t.Fatalf("failed to delete got pvcs: %v", err) + } else if !deleted { + gotPods := v1.PodList{} + ctrl.List(context.TODO(), &gotPods, client.InNamespace("default")) + t.Fatalf("failed to delete got pvcs: not deleted") + } + + gotPods := v1.PodList{} + if err := ctrl.List(context.TODO(), &gotPods, client.InNamespace("default")); err != nil { + t.Fatalf("failed to list pods: %v", err) + } + if len(gotPods.Items) != 1 || reflect.DeepEqual(gotPods.Items[0], podsToDelete[0]) { + t.Fatalf("upexpected pods: %v", util.DumpJSON(gotPods.Items)) + } + + gotPVCs := v1.PersistentVolumeClaimList{} + if err := ctrl.List(context.TODO(), &gotPVCs, client.InNamespace("default")); err != nil { + t.Fatalf("failed to list pvcs: %v", err) + } + if len(gotPVCs.Items) != 1 || reflect.DeepEqual(gotPVCs.Items[0], pvcs["id1"]) { + t.Fatalf("unexpected pvcs: %v", util.DumpJSON(gotPVCs.Items)) + } + + ref := gotPVCs.Items[0].OwnerReferences[0] + refGV, _ := schema.ParseGroupVersion(ref.APIVersion) + if ref.UID != podsToDelete[0].UID || ref.Kind != "Pod" || refGV.Group != v1.SchemeGroupVersion.Group { + t.Fatalf("unexpected ownerReferences groud version: %v", ref) + } +} diff --git a/pkg/controller/cloneset/utils/cloneset_utils.go b/pkg/controller/cloneset/utils/cloneset_utils.go index 9b0cc0a332..ec6bb64a41 100644 --- a/pkg/controller/cloneset/utils/cloneset_utils.go +++ b/pkg/controller/cloneset/utils/cloneset_utils.go @@ -24,7 +24,6 @@ import ( appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1" "github.com/openkruise/kruise/pkg/features" - utilclient "github.com/openkruise/kruise/pkg/util/client" "github.com/openkruise/kruise/pkg/util/expectations" utilfeature "github.com/openkruise/kruise/pkg/util/feature" "github.com/openkruise/kruise/pkg/util/requeueduration" @@ -93,22 +92,36 @@ func GetControllerKey(cs *appsv1alpha1.CloneSet) string { // GetActivePods returns all active pods in this namespace. func GetActivePods(reader client.Reader, opts *client.ListOptions) ([]*v1.Pod, error) { - podList := &v1.PodList{} - if err := reader.List(context.TODO(), podList, opts, utilclient.DisableDeepCopy); err != nil { + podList, err := GetAllPods(reader, opts) + if err != nil { return nil, err } // Ignore inactive pods var activePods []*v1.Pod - for i, pod := range podList.Items { + for i, pod := range podList { // Consider all rebuild pod as active pod, should not recreate - if kubecontroller.IsPodActive(&pod) { - activePods = append(activePods, &podList.Items[i]) + if kubecontroller.IsPodActive(pod) { + activePods = append(activePods, podList[i]) } } return activePods, nil } +// GetAllPods returns all pods in this namespace. +func GetAllPods(reader client.Reader, opts *client.ListOptions) ([]*v1.Pod, error) { + podList := &v1.PodList{} + if err := reader.List(context.TODO(), podList, opts); err != nil { + return nil, err + } + + var pods []*v1.Pod + for i := range podList.Items { + pods = append(pods, &podList.Items[i]) + } + return pods, nil +} + // NextRevision finds the next valid revision number based on revisions. If the length of revisions // is 0 this is 1. Otherwise, it is 1 greater than the largest revision's Revision. This method // assumes that revisions has been sorted by Revision. @@ -166,6 +179,10 @@ func UpdateStorage(cs *appsv1alpha1.CloneSet, pod *v1.Pod) { pod.Spec.Volumes = newVolumes } +func GetInstanceID(obj metav1.Object) string { + return obj.GetLabels()[appsv1alpha1.CloneSetInstanceID] +} + // GetPersistentVolumeClaims gets a map of PersistentVolumeClaims to their template names, as defined in set. The // returned PersistentVolumeClaims are each constructed with a the name specific to the Pod. This name is determined // by getPersistentVolumeClaimName. diff --git a/pkg/util/ownerref.go b/pkg/util/ownerref.go new file mode 100644 index 0000000000..5d0fea2bd1 --- /dev/null +++ b/pkg/util/ownerref.go @@ -0,0 +1,66 @@ +/* +Copyright 2021 The Kruise Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func HasOwnerRef(target, owner metav1.Object) bool { + ownerUID := owner.GetUID() + for _, ownerRef := range target.GetOwnerReferences() { + if ownerRef.UID == ownerUID { + return true + } + } + return false +} + +func RemoveOwnerRef(target, owner metav1.Object) bool { + if !HasOwnerRef(target, owner) { + return false + } + ownerUID := owner.GetUID() + oldRefs := target.GetOwnerReferences() + newRefs := make([]metav1.OwnerReference, len(oldRefs)-1) + skip := 0 + for i := range oldRefs { + if oldRefs[i].UID == ownerUID { + skip = -1 + } else { + newRefs[i+skip] = oldRefs[i] + } + } + target.SetOwnerReferences(newRefs) + return true +} + +func SetOwnerRef(target, owner metav1.Object, ownerType *metav1.TypeMeta) bool { + if HasOwnerRef(target, owner) { + return false + } + ownerRefs := append( + target.GetOwnerReferences(), + metav1.OwnerReference{ + APIVersion: ownerType.APIVersion, + Kind: ownerType.Kind, + Name: owner.GetName(), + UID: owner.GetUID(), + }) + target.SetOwnerReferences(ownerRefs) + return true +} diff --git a/pkg/util/ownerref_test.go b/pkg/util/ownerref_test.go new file mode 100644 index 0000000000..5b6b7b1fc9 --- /dev/null +++ b/pkg/util/ownerref_test.go @@ -0,0 +1,154 @@ +/* +Copyright 2020 The Kruise Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "testing" + + v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1" +) + +func TestHasOwnerRef(t *testing.T) { + pvc := &v1.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "datadir-foo-id1", + Labels: map[string]string{ + appsv1alpha1.CloneSetInstanceID: "id1", + "foo": "bar", + }, + OwnerReferences: []metav1.OwnerReference{ + { + APIVersion: "v1", + Kind: "Pod", + Name: "foo", + UID: "test", + Controller: func() *bool { a := true; return &a }(), + BlockOwnerDeletion: func() *bool { a := true; return &a }(), + }, + }, + ResourceVersion: "1", + }, + Spec: v1.PersistentVolumeClaimSpec{ + Resources: v1.ResourceRequirements{ + Requests: v1.ResourceList{ + v1.ResourceStorage: resource.MustParse("10"), + }, + }, + }, + } + pod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "foo", + UID: "test", + }, + } + + if !HasOwnerRef(pvc, pod) { + t.Fatalf("expect pvc %v has pod %v ownerref", pvc, pod) + } +} + +func TestRemoveOnwer(t *testing.T) { + pvc := &v1.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "datadir-foo-id1", + Labels: map[string]string{ + appsv1alpha1.CloneSetInstanceID: "id1", + "foo": "bar", + }, + OwnerReferences: []metav1.OwnerReference{ + { + APIVersion: "v1", + Kind: "Pod", + Name: "foo", + UID: "test", + Controller: func() *bool { a := true; return &a }(), + BlockOwnerDeletion: func() *bool { a := true; return &a }(), + }, + }, + ResourceVersion: "1", + }, + Spec: v1.PersistentVolumeClaimSpec{ + Resources: v1.ResourceRequirements{ + Requests: v1.ResourceList{ + v1.ResourceStorage: resource.MustParse("10"), + }, + }, + }, + } + pod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "foo", + UID: "test", + }, + } + + if !RemoveOwnerRef(pvc, pod) { + t.Fatalf("expect pvc %v to remove pod %v ownerref", pvc, pod) + } + + if HasOwnerRef(pvc, pod) { + t.Fatalf("expect pvc %v has no pod %v ownerref", pvc, pod) + } +} + +func TestSetOwnerRef(t *testing.T) { + pvc := &v1.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "datadir-foo-id1", + Labels: map[string]string{ + appsv1alpha1.CloneSetInstanceID: "id1", + "foo": "bar", + }, + ResourceVersion: "1", + }, + Spec: v1.PersistentVolumeClaimSpec{ + Resources: v1.ResourceRequirements{ + Requests: v1.ResourceList{ + v1.ResourceStorage: resource.MustParse("10"), + }, + }, + }, + } + pod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "foo", + UID: "test", + }, + } + + podMeta := &pod.TypeMeta + UpdatePodMeta(podMeta) + + if !SetOwnerRef(pvc, pod, podMeta) { + t.Fatalf("expect pvc %v has no pod %v ownerref", pvc, pod) + } + + if !HasOwnerRef(pvc, pod) { + t.Fatalf("expect pvc %s has pod %v ownerref", pvc, pod) + } +} diff --git a/pkg/util/pods.go b/pkg/util/pods.go index 9c873ed59f..c3e5c41d7d 100644 --- a/pkg/util/pods.go +++ b/pkg/util/pods.go @@ -343,3 +343,12 @@ func SetPodReadyCondition(pod *v1.Pod) { SetPodCondition(pod, newPodReady) } + +func UpdatePodMeta(tm *metav1.TypeMeta) { + if tm.APIVersion == "" { + tm.APIVersion = "v1" + } + if tm.Kind == "" { + tm.Kind = "Pod" + } +}