bugfix: patch pod image fail when gs image is nil (#121)
Signed-off-by: ChrisLiu <chrisliu1995@163.com>
This commit is contained in:
parent
5a15888804
commit
b399cd104b
|
|
@ -19,7 +19,6 @@ package util
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
appspub "github.com/openkruise/kruise-api/apps/pub"
|
||||
kruiseV1beta1 "github.com/openkruise/kruise-api/apps/v1beta1"
|
||||
gameKruiseV1alpha1 "github.com/openkruise/kruise-game/apis/v1alpha1"
|
||||
|
|
@ -200,9 +199,6 @@ func GetAstsHash(gss *gameKruiseV1alpha1.GameServerSet) string {
|
|||
}
|
||||
|
||||
func GetGsTemplateMetadataHash(gss *gameKruiseV1alpha1.GameServerSet) string {
|
||||
fmt.Println(gss.Spec.GameServerTemplate.GetLabels())
|
||||
fmt.Println(gss.Spec.GameServerTemplate.GetAnnotations())
|
||||
|
||||
return GetHash(metav1.ObjectMeta{
|
||||
Labels: gss.Spec.GameServerTemplate.GetLabels(),
|
||||
Annotations: gss.Spec.GameServerTemplate.GetAnnotations(),
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ func patchContainers(client client.Client, pod *corev1.Pod, ctx context.Context)
|
|||
for _, gsContainer := range gs.Spec.Containers {
|
||||
if gsContainer.Name == podContainer.Name {
|
||||
// patch Image
|
||||
if gsContainer.Image != podContainer.Image {
|
||||
if gsContainer.Image != podContainer.Image && gsContainer.Image != "" {
|
||||
container.Image = gsContainer.Image
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -118,6 +118,51 @@ func TestPatchContainers(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
|
||||
// case 2
|
||||
{
|
||||
gs: &gameKruiseV1alpha1.GameServer{
|
||||
Spec: gameKruiseV1alpha1.GameServerSpec{
|
||||
Containers: []gameKruiseV1alpha1.GameServerContainer{
|
||||
{
|
||||
Name: "A",
|
||||
Resources: corev1.ResourceRequirements{
|
||||
Requests: map[corev1.ResourceName]resource.Quantity{
|
||||
corev1.ResourceCPU: resource.MustParse("1"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
oldPod: &corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
gameKruiseV1alpha1.GameServerOwnerGssKey: "xxx",
|
||||
},
|
||||
},
|
||||
Spec: corev1.PodSpec{
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Name: "A",
|
||||
Image: "A-v1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
newContainers: []corev1.Container{
|
||||
{
|
||||
Name: "A",
|
||||
Image: "A-v1",
|
||||
Resources: corev1.ResourceRequirements{
|
||||
Requests: map[corev1.ResourceName]resource.Quantity{
|
||||
corev1.ResourceCPU: resource.MustParse("1"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
|
|
|
|||
Loading…
Reference in New Issue