@@ -110,28 +110,20 @@ func ShouldContainerBeRestarted(container *v1.Container, pod *v1.Pod, podStatus
110
110
// Note: remember to update hashValues in container_hash_test.go as well.
111
111
func HashContainer (container * v1.Container ) uint64 {
112
112
hash := fnv .New32a ()
113
- // Omit nil or empty field when calculating hash value
114
- // Please see https://github.com/kubernetes/kubernetes/issues/53644
115
- containerJSON , _ := json .Marshal (container )
113
+ containerJSON , _ := json .Marshal (pickFieldsToHash (container ))
116
114
hashutil .DeepHashObject (hash , containerJSON )
117
115
return uint64 (hash .Sum32 ())
118
116
}
119
117
120
- // HashContainerWithoutResources returns the hash of the container with Resources field zero'd out.
121
- func HashContainerWithoutResources (container * v1.Container ) uint64 {
122
- // InPlacePodVerticalScaling enables mutable Resources field.
123
- // Changes to this field may not require container restart depending on policy.
124
- // Compute hash over fields besides the Resources field
125
- // NOTE: This is needed during alpha and beta so that containers using Resources but
126
- // not subject to In-place resize are not unexpectedly restarted when
127
- // InPlacePodVerticalScaling feature-gate is toggled.
128
- //TODO(vinaykul,InPlacePodVerticalScaling): Remove this in GA+1 and make HashContainerWithoutResources to become Hash.
129
- hashWithoutResources := fnv .New32a ()
130
- containerCopy := container .DeepCopy ()
131
- containerCopy .Resources = v1.ResourceRequirements {}
132
- containerJSON , _ := json .Marshal (containerCopy )
133
- hashutil .DeepHashObject (hashWithoutResources , containerJSON )
134
- return uint64 (hashWithoutResources .Sum32 ())
118
+ // pickFieldsToHash pick fields that will affect the running status of the container for hash,
119
+ // currently this field range only contains `image` and `name`.
120
+ // Note: this list must be updated if ever kubelet wants to allow mutations to other fields.
121
+ func pickFieldsToHash (container * v1.Container ) map [string ]string {
122
+ retval := map [string ]string {
123
+ "name" : container .Name ,
124
+ "image" : container .Image ,
125
+ }
126
+ return retval
135
127
}
136
128
137
129
// envVarsToMap constructs a map of environment name to value from a slice
@@ -269,15 +261,14 @@ func ConvertPodStatusToRunningPod(runtimeName string, podStatus *PodStatus) Pod
269
261
continue
270
262
}
271
263
container := & Container {
272
- ID : containerStatus .ID ,
273
- Name : containerStatus .Name ,
274
- Image : containerStatus .Image ,
275
- ImageID : containerStatus .ImageID ,
276
- ImageRef : containerStatus .ImageRef ,
277
- ImageRuntimeHandler : containerStatus .ImageRuntimeHandler ,
278
- Hash : containerStatus .Hash ,
279
- HashWithoutResources : containerStatus .HashWithoutResources ,
280
- 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 ,
281
272
}
282
273
runningPod .Containers = append (runningPod .Containers , container )
283
274
}
0 commit comments