diff --git a/test/e2e/test_helm_install_upgrade.go b/test/e2e/test_helm_install_upgrade.go index fc1c68123..beb473502 100644 --- a/test/e2e/test_helm_install_upgrade.go +++ b/test/e2e/test_helm_install_upgrade.go @@ -25,6 +25,7 @@ import ( k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes" testutils "github.com/kong/gateway-operator/pkg/utils/test" "github.com/kong/gateway-operator/pkg/vars" + "github.com/kong/gateway-operator/test/helpers" ) func init() { @@ -47,13 +48,13 @@ func TestHelmUpgrade(t *testing.T) { // and dumping diagnostics if the test fails. e := CreateEnvironment(t, ctx) - // assertion is run after the upgrade to assert the state of the resources in the cluster. + // Assertion is run after the upgrade to assert the state of the resources in the cluster. type assertion struct { Name string Func func(*assert.CollectT, *testutils.K8sClients) } - testcases := []struct { + testCases := []struct { name string fromVersion string toVersion string @@ -113,6 +114,20 @@ func TestHelmUpgrade(t *testing.T) { Name: "Gateway is programmed", Func: func(c *assert.CollectT, cl *testutils.K8sClients) { gatewayAndItsListenersAreProgrammedAssertion("gw-upgrade-120-123=true")(ctx, c, cl.MgrClient) + + gw := getGatewayByLabelSelector("gw-upgrade-120-123=true", ctx, c, cl.MgrClient) + if !assert.NotNil(c, gw) { + return + } + deployments, err := listDataPlaneDeploymentsForGateway(c, ctx, cl.MgrClient, gw) + if err != nil { + return + } + d := &deployments[0] + + t.Logf(">>> Deployment dump %q:\n%# v", + client.ObjectKeyFromObject(d), pretty.Formatter(d), + ) }, }, }, @@ -191,10 +206,10 @@ func TestHelmUpgrade(t *testing.T) { }, }, { - Name: "DataPlane deployment is patched after operator upgrade (due to change in default Kong image version to 3.7)", + Name: fmt.Sprintf("DataPlane deployment is patched after operator upgrade (due to change in default Kong image version to %q)", helpers.GetDefaultDataPlaneImagePrevious()), Func: func(c *assert.CollectT, cl *testutils.K8sClients) { gatewayDataPlaneDeploymentIsPatched("gw-upgrade-123-130=true")(ctx, c, cl.MgrClient) - gatewayDataPlaneDeploymentHasImageSetTo("gw-upgrade-123-130=true", "kong:3.7")(ctx, c, cl.MgrClient) + gatewayDataPlaneDeploymentHasImageSetTo("gw-upgrade-123-130=true", helpers.GetDefaultDataPlaneImagePrevious())(ctx, c, cl.MgrClient) }, }, // NOTE: We do not check managed cluster wide resource labels because the fix for migrating @@ -260,10 +275,10 @@ func TestHelmUpgrade(t *testing.T) { }, }, { - Name: "DataPlane deployment is patched after operator upgrade (due to change in default Kong image version to 3.8)", + Name: fmt.Sprintf("DataPlane deployment is patched after operator upgrade (due to change in default Kong image version to %q)", helpers.GetDefaultDataPlaneImage()), Func: func(c *assert.CollectT, cl *testutils.K8sClients) { gatewayDataPlaneDeploymentIsPatched("gw-upgrade-130-current=true")(ctx, c, cl.MgrClient) - gatewayDataPlaneDeploymentHasImageSetTo("gw-upgrade-130-current=true", "kong:3.8")(ctx, c, cl.MgrClient) + gatewayDataPlaneDeploymentHasImageSetTo("gw-upgrade-130-current=true", helpers.GetDefaultDataPlaneImage())(ctx, c, cl.MgrClient) }, }, { @@ -359,7 +374,7 @@ func TestHelmUpgrade(t *testing.T) { currentRepository, currentTag = splitRepoVersionFromImage(t, imageOverride) } - for _, tc := range testcases { + for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { var ( tag string @@ -499,6 +514,7 @@ func baseGatewayConfigurationSpec() operatorv1beta1.GatewayConfigurationSpec { }, }, }, + ControlPlaneOptions: &operatorv1beta1.ControlPlaneOptions{ Deployment: operatorv1beta1.ControlPlaneDeploymentOptions{ PodTemplateSpec: &corev1.PodTemplateSpec{ @@ -540,7 +556,7 @@ func getGatewayByLabelSelector(gatewayLabelSelector string, ctx context.Context, } if len(gws.Items) != 1 { - c.Errorf("got %d gateways, expected 1", len(gws.Items)) + c.Errorf("expected 1 Gateway, got %d", len(gws.Items)) return nil } @@ -573,8 +589,8 @@ func gatewayDataPlaneDeploymentHasImageSetTo( } if container[0].Image != image { - return fmt.Errorf("Gateway's DataPlane Deployment %q expected image %s but got %s", - client.ObjectKeyFromObject(d), container[0].Image, image, + return fmt.Errorf("Gateway's DataPlane Deployment %q expected image %s got %s", + client.ObjectKeyFromObject(d), image, container[0].Image, ) } return nil diff --git a/test/e2e/test_webhook.go b/test/e2e/test_webhook.go index 669de3a18..3ec6ef738 100644 --- a/test/e2e/test_webhook.go +++ b/test/e2e/test_webhook.go @@ -11,6 +11,7 @@ import ( operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1" "github.com/kong/gateway-operator/pkg/consts" + "github.com/kong/gateway-operator/test/helpers" ) func init() { @@ -63,7 +64,7 @@ func TestDataPlaneValidatingWebhook(t *testing.T) { Value: "postgres", }, }, - Image: consts.DefaultDataPlaneImage, + Image: helpers.GetDefaultDataPlaneImage(), }, }, }, diff --git a/test/helpers/defaults.go b/test/helpers/defaults.go index 0c3331cdb..3d88c72e3 100644 --- a/test/helpers/defaults.go +++ b/test/helpers/defaults.go @@ -1,6 +1,9 @@ package helpers import ( + "fmt" + "strconv" + "strings" "sync" "github.com/kong/gateway-operator/pkg/consts" @@ -33,6 +36,27 @@ func GetDefaultDataPlaneImage() string { return _defaultDataPlaneImage } +// GetDefaultDataPlaneImagePrevious returns the default data plane image with the previous version. +func GetDefaultDataPlaneImagePrevious() string { + _defaultDataPlaneImageLock.RLock() + defer _defaultDataPlaneImageLock.RUnlock() + s := strings.Split(_defaultDataPlaneImage, ".") + if len(s) != 2 { + panic(fmt.Sprintf("invalid default data plane image (more than one '.' in version), %s", _defaultDataPlaneImage)) + } + v, err := strconv.Atoi(s[1]) + if err != nil { + panic(fmt.Sprintf("invalid default data plane image (after '.' not a number), %s", _defaultDataPlaneImage)) + } + // NOTICE: Kong Gateway 4.0 rather won't happen in foreseeable future, thus for now it's safe to have it hardcoded this way. + previous := v - 1 + if previous < 0 { + panic(fmt.Sprintf("invalid default data plane image (previous version is negative), %s", _defaultDataPlaneImage)) + } + s[1] = strconv.Itoa(previous) + return strings.Join(s, ".") +} + // SetDefaultDataPlaneImage sets the default data plane image. func SetDefaultDataPlaneImage(image string) { _defaultDataPlaneImageLock.Lock()