Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pkg/controller/instanceset/in_place_update_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"slices"
"strings"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/utils/ptr"
Expand All @@ -44,6 +45,10 @@ const (
inPlaceUpdatePolicy podUpdatePolicy = "inPlaceUpdate"
)

var (
errTemplateNotFound = fmt.Errorf("no template found for pod")
)

func supportPodVerticalScaling() bool {
return viper.GetBool(constant.FeatureGateInPlacePodVerticalScaling)
}
Expand Down Expand Up @@ -314,7 +319,7 @@ func getPodUpdatePolicy(its *workloads.InstanceSet, pod *corev1.Pod) (podUpdateP
return templateName == templateExt.Name
})
if index < 0 {
return noOpsPolicy, "", fmt.Errorf("no corresponding template found for instance %s", pod.Name)
return noOpsPolicy, "", errors.Wrapf(errTemplateNotFound, "pod: %s/%s", pod.Namespace, pod.Name)
}
newPod, err := buildInstancePodByTemplate(pod.Name, templateList[index], its, getPodRevision(pod))
if err != nil {
Expand Down Expand Up @@ -371,13 +376,19 @@ func getTemplateNameByPod(itsExt *instancetemplate.InstanceSetExt, pod *corev1.P
if ok {
return tplExt.Name, nil
}
return "", fmt.Errorf("no template found for pod %s/%s", pod.Namespace, pod.Name)
return "", errors.Wrapf(errTemplateNotFound, "pod: %s/%s", pod.Namespace, pod.Name)
}

// IsPodUpdated tells whether the pod's spec is as expected in the InstanceSet.
// isPodUpdated tells whether the pod's spec is as expected in the InstanceSet.
// This function is meant to replace the old fashion `GetPodRevision(pod) == updateRevision`,
// as the pod template revision has been redefined in instanceset.
func IsPodUpdated(its *workloads.InstanceSet, pod *corev1.Pod) (bool, error) {
func isPodUpdated(its *workloads.InstanceSet, pod *corev1.Pod) (bool, error) {
policy, _, err := getPodUpdatePolicy(its, pod)
if err != nil {
if errors.Is(err, errTemplateNotFound) {
return true, nil
}
return false, err
}
return policy == noOpsPolicy, err
}
2 changes: 1 addition & 1 deletion pkg/controller/instanceset/reconciler_revision_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func calculateUpdatedReplicas(its *workloads.InstanceSet, pods []client.Object)
updatedReplicas := int32(0)
for i := range pods {
pod, _ := pods[i].(*corev1.Pod)
updated, err := IsPodUpdated(its, pod)
updated, err := isPodUpdated(its, pod)
if err != nil {
return 0, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/instanceset/reconciler_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (r *statusReconciler) Reconcile(tree *kubebuilderx.ObjectTree) (kubebuilder
}
}
if isCreated(pod) && !isTerminating(pod) {
isPodUpdated, err := IsPodUpdated(its, pod)
isPodUpdated, err := isPodUpdated(its, pod)
if err != nil {
return kubebuilderx.Continue, err
}
Expand Down
Loading