Skip to content

Commit 3ec13c5

Browse files
committed
remove HashWithoutResources field
1 parent f6b6504 commit 3ec13c5

File tree

8 files changed

+31
-56
lines changed

8 files changed

+31
-56
lines changed

pkg/kubelet/container/helpers.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,14 @@ func ConvertPodStatusToRunningPod(runtimeName string, podStatus *PodStatus) Pod
261261
continue
262262
}
263263
container := &Container{
264-
ID: containerStatus.ID,
265-
Name: containerStatus.Name,
266-
Image: containerStatus.Image,
267-
ImageID: containerStatus.ImageID,
268-
ImageRef: containerStatus.ImageRef,
269-
ImageRuntimeHandler: containerStatus.ImageRuntimeHandler,
270-
Hash: containerStatus.Hash,
271-
HashWithoutResources: containerStatus.HashWithoutResources,
272-
State: containerStatus.State,
264+
ID: containerStatus.ID,
265+
Name: containerStatus.Name,
266+
Image: containerStatus.Image,
267+
ImageID: containerStatus.ImageID,
268+
ImageRef: containerStatus.ImageRef,
269+
ImageRuntimeHandler: containerStatus.ImageRuntimeHandler,
270+
Hash: containerStatus.Hash,
271+
State: containerStatus.State,
273272
}
274273
runningPod.Containers = append(runningPod.Containers, container)
275274
}

pkg/kubelet/container/runtime.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,6 @@ type Container struct {
295295
// Hash of the container, used for comparison. Optional for containers
296296
// not managed by kubelet.
297297
Hash uint64
298-
// Hash of the container over fields with Resources field zero'd out.
299-
// NOTE: This is needed during alpha and beta so that containers using Resources are
300-
// not unexpectedly restarted when InPlacePodVerticalScaling feature-gate is toggled.
301-
//TODO(vinaykul,InPlacePodVerticalScaling): Remove this in GA+1 and make HashWithoutResources to become Hash.
302-
HashWithoutResources uint64
303298
// State is the state of the container.
304299
State State
305300
}
@@ -365,8 +360,6 @@ type Status struct {
365360
ImageRuntimeHandler string
366361
// Hash of the container, used for comparison.
367362
Hash uint64
368-
// Hash of the container over fields with Resources field zero'd out.
369-
HashWithoutResources uint64
370363
// Number of times that the container has been restarted.
371364
RestartCount int
372365
// A string explains why container is in such a status.

pkg/kubelet/kuberuntime/helpers.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,14 @@ func (m *kubeGenericRuntimeManager) toKubeContainer(c *runtimeapi.Container) (*k
102102

103103
annotatedInfo := getContainerInfoFromAnnotations(c.Annotations)
104104
return &kubecontainer.Container{
105-
ID: kubecontainer.ContainerID{Type: m.runtimeName, ID: c.Id},
106-
Name: c.GetMetadata().GetName(),
107-
ImageID: imageID,
108-
ImageRef: c.ImageRef,
109-
ImageRuntimeHandler: c.Image.RuntimeHandler,
110-
Image: c.Image.Image,
111-
Hash: annotatedInfo.Hash,
112-
HashWithoutResources: annotatedInfo.HashWithoutResources,
113-
State: toKubeContainerState(c.State),
105+
ID: kubecontainer.ContainerID{Type: m.runtimeName, ID: c.Id},
106+
Name: c.GetMetadata().GetName(),
107+
ImageID: imageID,
108+
ImageRef: c.ImageRef,
109+
ImageRuntimeHandler: c.Image.RuntimeHandler,
110+
Image: c.Image.Image,
111+
Hash: annotatedInfo.Hash,
112+
State: toKubeContainerState(c.State),
114113
}, nil
115114
}
116115

pkg/kubelet/kuberuntime/kuberuntime_container.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -622,17 +622,16 @@ func toKubeContainerStatus(status *runtimeapi.ContainerStatus, runtimeName strin
622622
Type: runtimeName,
623623
ID: status.Id,
624624
},
625-
Name: labeledInfo.ContainerName,
626-
Image: status.Image.Image,
627-
ImageID: imageID,
628-
ImageRef: status.ImageRef,
629-
ImageRuntimeHandler: status.Image.RuntimeHandler,
630-
Hash: annotatedInfo.Hash,
631-
HashWithoutResources: annotatedInfo.HashWithoutResources,
632-
RestartCount: annotatedInfo.RestartCount,
633-
State: toKubeContainerState(status.State),
634-
CreatedAt: time.Unix(0, status.CreatedAt),
635-
Resources: cStatusResources,
625+
Name: labeledInfo.ContainerName,
626+
Image: status.Image.Image,
627+
ImageID: imageID,
628+
ImageRef: status.ImageRef,
629+
ImageRuntimeHandler: status.Image.RuntimeHandler,
630+
Hash: annotatedInfo.Hash,
631+
RestartCount: annotatedInfo.RestartCount,
632+
State: toKubeContainerState(status.State),
633+
CreatedAt: time.Unix(0, status.CreatedAt),
634+
Resources: cStatusResources,
636635
}
637636

638637
if status.State != runtimeapi.ContainerState_CONTAINER_CREATED {

pkg/kubelet/kuberuntime/kuberuntime_manager.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ func (p podActions) String() string {
518518
p.KillPod, p.CreateSandbox, p.UpdatePodResources, p.Attempt, p.InitContainersToStart, p.ContainersToStart, p.EphemeralContainersToStart, p.ContainersToUpdate, p.ContainersToKill)
519519
}
520520

521+
// containerChanged will determine whether the container has changed based on the fields that will affect the running of the container.
522+
// Currently, there are only `image` and `name` fields.
523+
// we don't need to consider the pod UID here, because we find the containerStatus through the pod UID.
524+
// If the pod UID changes, we will not be able to find the containerStatus to compare against.
521525
func containerChanged(container *v1.Container, containerStatus *kubecontainer.Status) (uint64, uint64, bool) {
522526
expectedHash := kubecontainer.HashContainer(container)
523527
return expectedHash, containerStatus.Hash, containerStatus.Hash != expectedHash
@@ -981,10 +985,7 @@ func (m *kubeGenericRuntimeManager) computePodActions(ctx context.Context, pod *
981985
var message string
982986
var reason containerKillReason
983987
restart := shouldRestartOnFailure(pod)
984-
// Do not restart if only the Resources field has changed with InPlacePodVerticalScaling enabled
985-
if _, _, changed := containerChanged(&container, containerStatus); changed &&
986-
(!isInPlacePodVerticalScalingAllowed(pod) ||
987-
kubecontainer.HashContainer(&container) != containerStatus.HashWithoutResources) {
988+
if _, _, changed := containerChanged(&container, containerStatus); changed {
988989
message = fmt.Sprintf("Container %s definition changed", container.Name)
989990
// Restart regardless of the restart policy because the container
990991
// spec changed.

pkg/kubelet/kuberuntime/kuberuntime_manager_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,7 +2436,6 @@ func TestComputePodActionsForPodResize(t *testing.T) {
24362436
// compute hash
24372437
if kcs := kps.FindContainerStatusByName(pod.Spec.Containers[idx].Name); kcs != nil {
24382438
kcs.Hash = kubecontainer.HashContainer(&pod.Spec.Containers[idx])
2439-
kcs.HashWithoutResources = kubecontainer.HashContainer(&pod.Spec.Containers[idx])
24402439
}
24412440
}
24422441
makeAndSetFakePod(t, m, fakeRuntime, pod)
@@ -2452,7 +2451,6 @@ func TestComputePodActionsForPodResize(t *testing.T) {
24522451
for idx := range pod.Spec.Containers {
24532452
if kcs := kps.FindContainerStatusByName(pod.Spec.Containers[idx].Name); kcs != nil {
24542453
kcs.Hash = kubecontainer.HashContainer(&pod.Spec.Containers[idx])
2455-
kcs.HashWithoutResources = kubecontainer.HashContainer(&pod.Spec.Containers[idx])
24562454
}
24572455
}
24582456
if test.mutatePodFn != nil {

pkg/kubelet/kuberuntime/labels.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ import (
2222

2323
v1 "k8s.io/api/core/v1"
2424
kubetypes "k8s.io/apimachinery/pkg/types"
25-
utilfeature "k8s.io/apiserver/pkg/util/feature"
2625
"k8s.io/klog/v2"
2726
"k8s.io/kubelet/pkg/types"
28-
"k8s.io/kubernetes/pkg/features"
2927
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
3028
)
3129

@@ -35,7 +33,6 @@ const (
3533
podTerminationGracePeriodLabel = "io.kubernetes.pod.terminationGracePeriod"
3634

3735
containerHashLabel = "io.kubernetes.container.hash"
38-
containerHashWithoutResourcesLabel = "io.kubernetes.container.hashWithoutResources"
3936
containerRestartCountLabel = "io.kubernetes.container.restartCount"
4037
containerTerminationMessagePathLabel = "io.kubernetes.container.terminationMessagePath"
4138
containerTerminationMessagePolicyLabel = "io.kubernetes.container.terminationMessagePolicy"
@@ -65,7 +62,6 @@ type labeledContainerInfo struct {
6562

6663
type annotatedContainerInfo struct {
6764
Hash uint64
68-
HashWithoutResources uint64
6965
RestartCount int
7066
PodDeletionGracePeriod *int64
7167
PodTerminationGracePeriod *int64
@@ -117,9 +113,6 @@ func newContainerAnnotations(container *v1.Container, pod *v1.Pod, restartCount
117113
}
118114

119115
annotations[containerHashLabel] = strconv.FormatUint(kubecontainer.HashContainer(container), 16)
120-
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) {
121-
annotations[containerHashWithoutResourcesLabel] = strconv.FormatUint(kubecontainer.HashContainer(container), 16)
122-
}
123116
annotations[containerRestartCountLabel] = strconv.Itoa(restartCount)
124117
annotations[containerTerminationMessagePathLabel] = container.TerminationMessagePath
125118
annotations[containerTerminationMessagePolicyLabel] = string(container.TerminationMessagePolicy)
@@ -200,11 +193,6 @@ func getContainerInfoFromAnnotations(annotations map[string]string) *annotatedCo
200193
if containerInfo.Hash, err = getUint64ValueFromLabel(annotations, containerHashLabel); err != nil {
201194
klog.ErrorS(err, "Unable to get label value from annotations", "label", containerHashLabel, "annotations", annotations)
202195
}
203-
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) {
204-
if containerInfo.HashWithoutResources, err = getUint64ValueFromLabel(annotations, containerHashWithoutResourcesLabel); err != nil {
205-
klog.ErrorS(err, "Unable to get label value from annotations", "label", containerHashWithoutResourcesLabel, "annotations", annotations)
206-
}
207-
}
208196
if containerInfo.RestartCount, err = getIntValueFromLabel(annotations, containerRestartCountLabel); err != nil {
209197
klog.ErrorS(err, "Unable to get label value from annotations", "label", containerRestartCountLabel, "annotations", annotations)
210198
}

pkg/kubelet/kuberuntime/labels_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ func TestContainerAnnotations(t *testing.T) {
155155
PodDeletionGracePeriod: pod.DeletionGracePeriodSeconds,
156156
PodTerminationGracePeriod: pod.Spec.TerminationGracePeriodSeconds,
157157
Hash: kubecontainer.HashContainer(container),
158-
HashWithoutResources: kubecontainer.HashContainer(container),
159158
RestartCount: restartCount,
160159
TerminationMessagePath: container.TerminationMessagePath,
161160
PreStopHandler: container.Lifecycle.PreStop,
@@ -182,7 +181,6 @@ func TestContainerAnnotations(t *testing.T) {
182181
expected.PreStopHandler = nil
183182
// Because container is changed, the Hash should be updated
184183
expected.Hash = kubecontainer.HashContainer(container)
185-
expected.HashWithoutResources = kubecontainer.HashContainer(container)
186184
annotations = newContainerAnnotations(container, pod, restartCount, opts)
187185
containerInfo = getContainerInfoFromAnnotations(annotations)
188186
if !reflect.DeepEqual(containerInfo, expected) {

0 commit comments

Comments
 (0)