diff --git a/pkg/util/gameserver.go b/pkg/util/gameserver.go index 6ee146b..56c7bf1 100644 --- a/pkg/util/gameserver.go +++ b/pkg/util/gameserver.go @@ -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(), diff --git a/pkg/webhook/mutating_pod.go b/pkg/webhook/mutating_pod.go index a2c1750..0f8e0da 100644 --- a/pkg/webhook/mutating_pod.go +++ b/pkg/webhook/mutating_pod.go @@ -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 } diff --git a/pkg/webhook/mutating_pod_test.go b/pkg/webhook/mutating_pod_test.go index c2bf355..34cdd3a 100644 --- a/pkg/webhook/mutating_pod_test.go +++ b/pkg/webhook/mutating_pod_test.go @@ -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 {