@@ -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+
4752func 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}
0 commit comments