Make toKubeContainerImageSpec deterministic

This commit is contained in:
Jordan Liggitt 2020-07-31 14:39:26 -04:00
parent 6324c137ea
commit 7335770670

View File

@ -17,6 +17,8 @@ limitations under the License.
package kuberuntime package kuberuntime
import ( import (
"sort"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
) )
@ -26,11 +28,16 @@ import (
func toKubeContainerImageSpec(image *runtimeapi.Image) kubecontainer.ImageSpec { func toKubeContainerImageSpec(image *runtimeapi.Image) kubecontainer.ImageSpec {
var annotations []kubecontainer.Annotation var annotations []kubecontainer.Annotation
if image.Spec != nil && image.Spec.Annotations != nil { if image.Spec != nil && len(image.Spec.Annotations) > 0 {
for k, v := range image.Spec.Annotations { annotationKeys := make([]string, 0, len(image.Spec.Annotations))
for k := range image.Spec.Annotations {
annotationKeys = append(annotationKeys, k)
}
sort.Strings(annotationKeys)
for _, k := range annotationKeys {
annotations = append(annotations, kubecontainer.Annotation{ annotations = append(annotations, kubecontainer.Annotation{
Name: k, Name: k,
Value: v, Value: image.Spec.Annotations[k],
}) })
} }
} }