mirror of https://github.com/openkruise/kruise.git
Optimization to determine whether the pod state is consistent logic (#854)
Signed-off-by: dafu-wu <wuchengyi2006@163.com> Co-authored-by: dafu-wu <wuchengyi2006@163.comL>
This commit is contained in:
parent
21254ca425
commit
3ba6f4ab20
|
|
@ -155,6 +155,7 @@ func (c *commonControl) IsPodStateConsistent(pod *v1.Pod, sidecarContainers sets
|
|||
}
|
||||
|
||||
allDigestImage := true
|
||||
cImageIDs := util.GetPodContainerImageIDs(pod)
|
||||
for _, container := range pod.Spec.Containers {
|
||||
// only check whether sidecar container is consistent
|
||||
if !sidecarContainers.Has(container.Name) {
|
||||
|
|
@ -165,10 +166,14 @@ func (c *commonControl) IsPodStateConsistent(pod *v1.Pod, sidecarContainers sets
|
|||
//for example: docker.io/busybox@sha256:a9286defaba7b3a519d585ba0e37d0b2cbee74ebfe590960b0b1d6a5e97d1e1d
|
||||
if !util.IsImageDigest(container.Image) {
|
||||
allDigestImage = false
|
||||
continue
|
||||
break
|
||||
}
|
||||
|
||||
if !util.IsPodContainerDigestEqual(sets.NewString(container.Name), pod) {
|
||||
imageID, ok := cImageIDs[container.Name]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if !util.IsContainerImageEqual(container.Image, imageID) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,8 +203,8 @@ func IsRunningAndReady(pod *v1.Pod) bool {
|
|||
return pod.Status.Phase == v1.PodRunning && podutil.IsPodReady(pod)
|
||||
}
|
||||
|
||||
func IsPodContainerDigestEqual(containers sets.String, pod *v1.Pod) bool {
|
||||
cStatus := make(map[string]string, len(pod.Status.ContainerStatuses))
|
||||
func GetPodContainerImageIDs(pod *v1.Pod) map[string]string {
|
||||
cImageIDs := make(map[string]string, len(pod.Status.ContainerStatuses))
|
||||
for i := range pod.Status.ContainerStatuses {
|
||||
c := &pod.Status.ContainerStatuses[i]
|
||||
//ImageID format: docker-pullable://busybox@sha256:a9286defaba7b3a519d585ba0e37d0b2cbee74ebfe590960b0b1d6a5e97d1e1d
|
||||
|
|
@ -212,8 +212,13 @@ func IsPodContainerDigestEqual(containers sets.String, pod *v1.Pod) bool {
|
|||
if strings.Contains(imageID, "://") {
|
||||
imageID = strings.Split(imageID, "://")[1]
|
||||
}
|
||||
cStatus[c.Name] = imageID
|
||||
cImageIDs[c.Name] = imageID
|
||||
}
|
||||
return cImageIDs
|
||||
}
|
||||
|
||||
func IsPodContainerDigestEqual(containers sets.String, pod *v1.Pod) bool {
|
||||
cImageIDs := GetPodContainerImageIDs(pod)
|
||||
|
||||
for _, container := range pod.Spec.Containers {
|
||||
if !containers.Has(container.Name) {
|
||||
|
|
@ -223,7 +228,7 @@ func IsPodContainerDigestEqual(containers sets.String, pod *v1.Pod) bool {
|
|||
if !IsImageDigest(container.Image) {
|
||||
return false
|
||||
}
|
||||
imageID, ok := cStatus[container.Name]
|
||||
imageID, ok := cImageIDs[container.Name]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue