Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: verify if Gateway's DataPlane Deployment is patched after upgrade #243

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ YQ_VERSION = 4.43.1
YQ = $(PROJECT_DIR)/bin/installs/yq/$(YQ_VERSION)/bin/yq
.PHONY: yq
yq: mise # Download yq locally if necessary.
$(MISE) plugin install --yes -q yq
$(MISE) install -q yq@$(YQ_VERSION)
@$(MISE) plugin install --yes -q yq
@$(MISE) install -q yq@$(YQ_VERSION)

CONTROLLER_GEN_VERSION = $(shell $(YQ) -r '.controller-tools' < $(TOOLS_VERSIONS_FILE))
CONTROLLER_GEN = $(PROJECT_DIR)/bin/installs/kube-controller-tools/$(CONTROLLER_GEN_VERSION)/bin/controller-gen
.PHONY: controller-gen
controller-gen: mise yq ## Download controller-gen locally if necessary.
$(MISE) plugin install --yes -q kube-controller-tools
$(MISE) install -q kube-controller-tools@$(CONTROLLER_GEN_VERSION)
@$(MISE) plugin install --yes -q kube-controller-tools
@$(MISE) install -q kube-controller-tools@$(CONTROLLER_GEN_VERSION)

KUSTOMIZE_VERSION = $(shell $(YQ) -r '.kustomize' < $(TOOLS_VERSIONS_FILE))
KUSTOMIZE = $(PROJECT_DIR)/bin/installs/kustomize/$(KUSTOMIZE_VERSION)/bin/kustomize
Expand Down
68 changes: 62 additions & 6 deletions test/e2e/test_helm_install_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,17 @@ func TestHelmUpgrade(t *testing.T) {
},
assertionsAfterUpgrade: []assertion{
{
Name: "gateway is programmed",
Name: "Gateway is programmed",
Func: func(c *assert.CollectT, cl *testutils.K8sClients) {
gatewayAndItsListenersAreProgrammedAssertion("gw-upgrade-120-123=true")(ctx, c, cl.MgrClient)
},
},
{
Name: "DataPlane deployment is not patched after operator upgrade",
Func: func(c *assert.CollectT, cl *testutils.K8sClients) {
gatewayDataPlaneDeploymentIsNotPatched("gw-upgrade-120-123=true")(ctx, c, cl.MgrClient)
},
},
},
},
{
Expand Down Expand Up @@ -161,11 +167,17 @@ func TestHelmUpgrade(t *testing.T) {
},
assertionsAfterUpgrade: []assertion{
{
Name: "gateway is programmed",
Name: "Gateway is programmed",
Func: func(c *assert.CollectT, cl *testutils.K8sClients) {
gatewayAndItsListenersAreProgrammedAssertion("gw-upgrade-123-current=true")(ctx, c, cl.MgrClient)
},
},
{
Name: "DataPlane deployment is not patched after operator upgrade",
Func: func(c *assert.CollectT, cl *testutils.K8sClients) {
gatewayDataPlaneDeploymentIsNotPatched("gw-upgrade-123-current=true")(ctx, c, cl.MgrClient)
},
},
},
},
{
Expand Down Expand Up @@ -212,11 +224,17 @@ func TestHelmUpgrade(t *testing.T) {
},
assertionsAfterUpgrade: []assertion{
{
Name: "gateway is programmed",
Name: "Gateway is programmed",
Func: func(c *assert.CollectT, cl *testutils.K8sClients) {
gatewayAndItsListenersAreProgrammedAssertion("gw-upgrade-nightly-to-current=true")(ctx, c, cl.MgrClient)
},
},
{
Name: "DataPlane deployment is not patched after operator upgrade",
Func: func(c *assert.CollectT, cl *testutils.K8sClients) {
gatewayDataPlaneDeploymentIsNotPatched("gw-upgrade-nightly-to-current=true")(ctx, c, cl.MgrClient)
},
},
},
},
}
Expand Down Expand Up @@ -386,12 +404,12 @@ func baseGatewayConfigurationSpec() operatorv1beta1.GatewayConfigurationSpec {

// gatewayAndItsListenersAreProgrammedAssertion returns a predicate that checks
// if the Gateway and its listeners are programmed.
func gatewayAndItsListenersAreProgrammedAssertion(labelSelector string) func(context.Context, *assert.CollectT, client.Client) {
func gatewayAndItsListenersAreProgrammedAssertion(gatewayLabelSelector string) func(context.Context, *assert.CollectT, client.Client) {
return func(ctx context.Context, c *assert.CollectT, cl client.Client) {
var gws gatewayv1.GatewayList
lReq, err := labels.ParseToRequirements(labelSelector)
lReq, err := labels.ParseToRequirements(gatewayLabelSelector)
if err != nil {
c.Errorf("failed to parse label selector %q: %v", labelSelector, err)
c.Errorf("failed to parse label selector %q: %v", gatewayLabelSelector, err)
c.FailNow()
}
lSel := labels.NewSelector()
Expand All @@ -410,3 +428,41 @@ func gatewayAndItsListenersAreProgrammedAssertion(labelSelector string) func(con
assert.True(c, gateway.AreListenersProgrammed(gw))
}
}

// gatewayDataPlaneDeploymentIsNotPatched returns a predicate that checks if the
// DataPlane deployment is not patched.
func gatewayDataPlaneDeploymentIsNotPatched(gatewayLabelSelector string) func(context.Context, *assert.CollectT, client.Client) {
return func(ctx context.Context, c *assert.CollectT, cl client.Client) {
// gateway-operator.konghq.com/managed-by: dataplane
var gws gatewayv1.GatewayList
lReq, err := labels.ParseToRequirements(gatewayLabelSelector)
if err != nil {
c.Errorf("failed to parse label selector %q: %v", gatewayLabelSelector, err)
c.FailNow()
}
lSel := labels.NewSelector()
for _, req := range lReq {
lSel = lSel.Add(req)
}

require.NoError(c,
cl.List(ctx, &gws, &client.ListOptions{
LabelSelector: lSel,
}),
)
require.Len(c, gws.Items, 1)
gw := &gws.Items[0]

dataplanes, err := gateway.ListDataPlanesForGateway(ctx, cl, gw)
if err != nil {
c.Errorf("failed to list DataPlanes for Gateway %q: %v", client.ObjectKeyFromObject(gw), err)
c.FailNow()
}
require.Len(c, dataplanes, 1)
dp := &dataplanes[0]
if dp.Generation != 1 {
c.Errorf("DataPlane %q got patched but it shouldn't: %v", client.ObjectKeyFromObject(dp), err)
c.FailNow()
}
}
}
Loading