Skip to content

Commit 57be060

Browse files
committed
init
1 parent 1ea5eb0 commit 57be060

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

pkg/controller/instanceset/in_place_update_util.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"slices"
2626
"strings"
2727

28+
"github.com/pkg/errors"
2829
corev1 "k8s.io/api/core/v1"
2930
"k8s.io/apimachinery/pkg/api/resource"
3031
"k8s.io/utils/ptr"
@@ -44,6 +45,10 @@ const (
4445
inPlaceUpdatePolicy podUpdatePolicy = "inPlaceUpdate"
4546
)
4647

48+
var (
49+
templateNotFoundError = fmt.Errorf("no template found for pod")
50+
)
51+
4752
func supportPodVerticalScaling() bool {
4853
return viper.GetBool(constant.FeatureGateInPlacePodVerticalScaling)
4954
}
@@ -314,7 +319,7 @@ func getPodUpdatePolicy(its *workloads.InstanceSet, pod *corev1.Pod) (podUpdateP
314319
return templateName == templateExt.Name
315320
})
316321
if index < 0 {
317-
return noOpsPolicy, "", fmt.Errorf("no corresponding template found for instance %s", pod.Name)
322+
return noOpsPolicy, "", errors.Wrapf(templateNotFoundError, "pod: %s/%s", pod.Namespace, pod.Name)
318323
}
319324
newPod, err := buildInstancePodByTemplate(pod.Name, templateList[index], its, getPodRevision(pod))
320325
if err != nil {
@@ -371,13 +376,19 @@ func getTemplateNameByPod(itsExt *instancetemplate.InstanceSetExt, pod *corev1.P
371376
if ok {
372377
return tplExt.Name, nil
373378
}
374-
return "", fmt.Errorf("no template found for pod %s/%s", pod.Namespace, pod.Name)
379+
return "", errors.Wrapf(templateNotFoundError, "pod: %s/%s", pod.Namespace, pod.Name)
375380
}
376381

377-
// IsPodUpdated tells whether the pod's spec is as expected in the InstanceSet.
382+
// isPodUpdated tells whether the pod's spec is as expected in the InstanceSet.
378383
// This function is meant to replace the old fashion `GetPodRevision(pod) == updateRevision`,
379384
// as the pod template revision has been redefined in instanceset.
380-
func IsPodUpdated(its *workloads.InstanceSet, pod *corev1.Pod) (bool, error) {
385+
func isPodUpdated(its *workloads.InstanceSet, pod *corev1.Pod) (bool, error) {
381386
policy, _, err := getPodUpdatePolicy(its, pod)
387+
if err != nil {
388+
if errors.Is(err, templateNotFoundError) {
389+
return true, nil
390+
}
391+
return false, err
392+
}
382393
return policy == noOpsPolicy, err
383394
}

pkg/controller/instanceset/reconciler_revision_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func calculateUpdatedReplicas(its *workloads.InstanceSet, pods []client.Object)
106106
updatedReplicas := int32(0)
107107
for i := range pods {
108108
pod, _ := pods[i].(*corev1.Pod)
109-
updated, err := IsPodUpdated(its, pod)
109+
updated, err := isPodUpdated(its, pod)
110110
if err != nil {
111111
return 0, nil
112112
}

pkg/controller/instanceset/reconciler_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (r *statusReconciler) Reconcile(tree *kubebuilderx.ObjectTree) (kubebuilder
124124
}
125125
}
126126
if isCreated(pod) && !isTerminating(pod) {
127-
isPodUpdated, err := IsPodUpdated(its, pod)
127+
isPodUpdated, err := isPodUpdated(its, pod)
128128
if err != nil {
129129
return kubebuilderx.Continue, err
130130
}

0 commit comments

Comments
 (0)