-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
318 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package e2e | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terratest/modules/helm" | ||
"github.com/gruntwork-io/terratest/modules/k8s" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
appsv1 "k8s.io/api/apps/v1" | ||
) | ||
|
||
func init() { | ||
addTestsToTestSuite(TestUpgrade) | ||
} | ||
|
||
func TestUpgrade(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
// createEnvironment will queue up environment cleanup if necessary | ||
// and dumping diagnostics if the test fails. | ||
e := CreateEnvironment(t, ctx) | ||
|
||
const ( | ||
// https://github.com/Kong/charts/tree/main/charts/gateway-operator | ||
chart = "kong/gateway-operator" | ||
namespace = "kong" | ||
) | ||
|
||
testcases := []struct { | ||
name string | ||
from string | ||
to string | ||
upgradeToCurrent bool | ||
baseValues map[string]string | ||
}{ | ||
{ | ||
name: "upgrade from 1.1.0 to 1.2.1", | ||
from: "1.1.0", | ||
to: "1.2.1", | ||
// Disable ControlPlane and Gateway controllers to avoid ControlPlane | ||
// and GatewayConfiguration CRD upgrade issues. | ||
// 1.2.0 introduced a breaking change (moving both of those CRDs | ||
// from v1alpha1 to v1beta1) that would cause the upgrade to fail. | ||
baseValues: map[string]string{ | ||
"args": "{--enable-controller-gateway=false,--enable-controller-controlplane=false}", | ||
}, | ||
}, | ||
{ | ||
name: "upgrade from 1.2.1 to latest", | ||
from: "1.2.1", | ||
upgradeToCurrent: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
var imageTo string | ||
if tc.upgradeToCurrent { | ||
if imageLoad == "" && imageOverride == "" { | ||
t.Skipf("No KONG_TEST_GATEWAY_OPERATOR_IMAGE_OVERRIDE nor KONG_TEST_GATEWAY_OPERATOR_IMAGE_LOAD" + | ||
" env specified. Please specify the image to upgrade to in order to run this test.") | ||
} | ||
if imageLoad != "" { | ||
t.Logf("KONG_TEST_GATEWAY_OPERATOR_IMAGE_LOAD set to %q, using it to upgrade", imageLoad) | ||
imageTo = imageLoad | ||
} else { | ||
t.Logf("KONG_TEST_GATEWAY_OPERATOR_IMAGE_OVERRIDE set to %q, using it to upgrade", imageOverride) | ||
imageTo = imageOverride | ||
} | ||
} | ||
|
||
releaseName := strings.ReplaceAll(fmt.Sprintf("kgo-%s-to-%s", tc.from, tc.to), ".", "-") | ||
values := make(map[string]string) | ||
if tc.baseValues != nil { | ||
values = tc.baseValues | ||
} | ||
values["image.tag"] = tc.from | ||
|
||
opts := &helm.Options{ | ||
KubectlOptions: &k8s.KubectlOptions{ | ||
Namespace: e.Namespace.Name, | ||
RestConfig: e.Environment.Cluster().Config(), | ||
}, | ||
SetValues: values, | ||
} | ||
|
||
require.NoError(t, helm.AddRepoE(t, opts, "kong", "https://charts.konghq.com")) | ||
require.NoError(t, helm.InstallE(t, opts, chart, releaseName)) | ||
t.Cleanup(func() { | ||
out, err := helm.RunHelmCommandAndGetOutputE(t, opts, "uninstall", releaseName) | ||
if !assert.NoError(t, err) { | ||
t.Logf("output: %s", out) | ||
} | ||
}) | ||
|
||
require.NoError(t, waitForOperatorDeployment(ctx, e.Namespace.Name, e.Clients.K8sClient, | ||
deploymentAssertConditions(deploymentReadyConditions()...), | ||
)) | ||
|
||
opts.SetValues["image.tag"] = tc.to | ||
if tc.upgradeToCurrent { | ||
opts.SetValues["image.tag"] = imageTo | ||
} | ||
|
||
require.NoError(t, helm.UpgradeE(t, opts, chart, releaseName)) | ||
require.NoError(t, waitForOperatorDeployment(ctx, e.Namespace.Name, e.Clients.K8sClient, | ||
deploymentAssertConditions(deploymentReadyConditions()...), | ||
)) | ||
|
||
// TODO: Add preconditions checks | ||
// time.Sleep(30 * time.Second) | ||
}) | ||
} | ||
} | ||
|
||
func deploymentReadyConditions() []appsv1.DeploymentCondition { | ||
return []appsv1.DeploymentCondition{ | ||
{ | ||
Reason: "NewReplicaSetAvailable", | ||
Status: "True", | ||
Type: "Progressing", | ||
}, | ||
{ | ||
Reason: "MinimumReplicasAvailable", | ||
Status: "True", | ||
Type: "Available", | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters