From 9bf70ef984cad46629aa8ae3eabc148aa435c49e Mon Sep 17 00:00:00 2001 From: Gabriele Gerbino Date: Wed, 3 Aug 2022 09:45:33 +0200 Subject: [PATCH] addressing more comments --- .../ws/config/compat/compatibility_table.go | 4 +- .../kong/ws/config/version_compatibility.go | 6 +-- .../ws/config/version_compatibility_test.go | 12 ++++-- internal/test/e2e/basic_test.go | 39 ++++++++++++++++++- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/internal/server/kong/ws/config/compat/compatibility_table.go b/internal/server/kong/ws/config/compat/compatibility_table.go index 026b0bb3e..8bec3c5fa 100644 --- a/internal/server/kong/ws/config/compat/compatibility_table.go +++ b/internal/server/kong/ws/config/compat/compatibility_table.go @@ -91,8 +91,8 @@ var ConfigTableUpdates = map[uint64][]config.ConfigTableUpdates{ }, }, { - Name: "services", - Type: config.CoreService, + Name: config.Service.String(), + Type: config.Service, RemoveFields: []string{ "enabled", }, diff --git a/internal/server/kong/ws/config/version_compatibility.go b/internal/server/kong/ws/config/version_compatibility.go index 2fa05e53a..eb9b4a71c 100644 --- a/internal/server/kong/ws/config/version_compatibility.go +++ b/internal/server/kong/ws/config/version_compatibility.go @@ -42,11 +42,11 @@ type UpdateType uint8 const ( Plugin UpdateType = iota - CoreService + Service ) func (u UpdateType) String() string { - return [...]string{"plugin", "services"}[u] + return [...]string{"plugins", "services"}[u] } //nolint: revive @@ -228,7 +228,7 @@ func (vc *WSVersionCompatibility) processConfigTableUpdates(uncompressedPayload case Plugin: processedPayload = vc.processPluginUpdates(processedPayload, configTableUpdate, dataPlaneVersion) - case CoreService: + case Service: processedPayload = vc.processCoreEntityUpdates(processedPayload, configTableUpdate, dataPlaneVersion) default: diff --git a/internal/server/kong/ws/config/version_compatibility_test.go b/internal/server/kong/ws/config/version_compatibility_test.go index 9e8fd0d42..1106c14f1 100644 --- a/internal/server/kong/ws/config/version_compatibility_test.go +++ b/internal/server/kong/ws/config/version_compatibility_test.go @@ -2223,7 +2223,8 @@ func TestVersionCompatibility_ProcessConfigTableUpdates(t *testing.T) { configTableUpdates: map[uint64][]ConfigTableUpdates{ 3000000000: { { - Type: CoreService, + Name: Service.String(), + Type: Service, RemoveFields: []string{ "service_field_1", }, @@ -2258,7 +2259,8 @@ func TestVersionCompatibility_ProcessConfigTableUpdates(t *testing.T) { configTableUpdates: map[uint64][]ConfigTableUpdates{ 3000000000: { { - Type: CoreService, + Name: Service.String(), + Type: Service, RemoveFields: []string{ "service_field_1", "service_field_2", @@ -2295,7 +2297,8 @@ func TestVersionCompatibility_ProcessConfigTableUpdates(t *testing.T) { configTableUpdates: map[uint64][]ConfigTableUpdates{ 3000000000: { { - Type: CoreService, + Name: Service.String(), + Type: Service, RemoveFields: []string{ "service_field_1", "service_field_2", @@ -2343,7 +2346,8 @@ func TestVersionCompatibility_ProcessConfigTableUpdates(t *testing.T) { configTableUpdates: map[uint64][]ConfigTableUpdates{ 3000000000: { { - Type: CoreService, + Name: Service.String(), + Type: Service, RemoveFields: []string{ "service_field_1", "service_field_2", diff --git a/internal/test/e2e/basic_test.go b/internal/test/e2e/basic_test.go index 165f3e2c4..6c3de8769 100644 --- a/internal/test/e2e/basic_test.go +++ b/internal/test/e2e/basic_test.go @@ -615,14 +615,14 @@ func TestServiceSync(t *testing.T) { disabledService := disabledService() disabled, err := json.ProtoJSONMarshal(disabledService) - require.Nil(t, err) + require.NoError(t, err) res = c.POST("/v1/services").WithBytes(disabled).Expect() res.Status(http.StatusCreated) dpCleanup := run.KongDP(kong.GetKongConfForShared()) defer dpCleanup() - require.Nil(t, util.WaitForKongPort(t, 8001)) + require.NoError(t, util.WaitForKongPort(t, 8001)) expectedConfig := &v1.TestingConfig{ Services: []*v1.Service{enabledService, { @@ -638,6 +638,41 @@ func TestServiceSync(t *testing.T) { }) } +func TestServiceWithEnabledFieldSync(t *testing.T) { + // ensure that services can be synced to Kong gateway + // and make sure the 'enabled' field is correctly set + kongClient.RunWhenKong(t, ">= 2.7.0") + cleanup := run.Koko(t) + defer cleanup() + + enabledService := goodService() + enabledService.Enabled = wrapperspb.Bool(true) + c := httpexpect.New(t, "http://localhost:3000") + res := c.POST("/v1/services").WithJSON(enabledService).Expect() + res.Status(http.StatusCreated) + + disabledService := disabledService() + enabledService.Enabled = wrapperspb.Bool(false) + disabled, err := json.ProtoJSONMarshal(disabledService) + require.NoError(t, err) + res = c.POST("/v1/services").WithBytes(disabled).Expect() + res.Status(http.StatusCreated) + + dpCleanup := run.KongDP(kong.GetKongConfForShared()) + defer dpCleanup() + + require.NoError(t, util.WaitForKongPort(t, 8001)) + + expectedConfig := &v1.TestingConfig{ + Services: []*v1.Service{enabledService, disabledService}, + } + util.WaitFunc(t, func() error { + err := util.EnsureConfig(expectedConfig) + t.Log("configuration mismatch", err) + return err + }) +} + func TestRouteHeader(t *testing.T) { // ensure that routes with headers can be synced to Kong gateway // this is done because the data-structures for headers in Koko and Kong