Skip to content

Commit

Permalink
fix(discovery) update non-terminating instances
Browse files Browse the repository at this point in the history
Use not terminating instead of ready condition to determine which Kong
instances are available for configuration updates. This provides
compatibility with Kong instances that use the 3.3+ /status/ready
endpoint instead of /status.
  • Loading branch information
rainest committed Aug 15, 2023
1 parent 72cd759 commit 2f420a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/adminapi/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func AdminAPIsFromEndpointSlice(
}

for _, e := range endpoints.Endpoints {
if e.Conditions.Ready == nil || !*e.Conditions.Ready {
if e.Conditions.Terminating != nil && *e.Conditions.Terminating {
continue
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestKongAdminAPIController(t *testing.T) {
)
})

t.Run("not Ready Endpoints are not matched", func(t *testing.T) {
t.Run("terminating Endpoints are not matched", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
adminService, adminPod, n := startKongAdminAPIServiceReconciler(ctx, t, client, cfg)
Expand All @@ -216,7 +216,7 @@ func TestKongAdminAPIController(t *testing.T) {
{
Addresses: []string{"10.0.0.1"},
Conditions: discoveryv1.EndpointConditions{
Ready: lo.ToPtr(false),
Terminating: lo.ToPtr(true),
},
TargetRef: &corev1.ObjectReference{
Kind: "Pod",
Expand Down Expand Up @@ -457,16 +457,16 @@ func TestKongAdminAPIController(t *testing.T) {
n.LastNotified(),
)

// Update all endpoints so that they are not Ready.
// Update all endpoints so that they are Terminating.
for i := range endpoints.Endpoints {
endpoints.Endpoints[i].Conditions.Ready = lo.ToPtr(false)
endpoints.Endpoints[i].Conditions.Terminating = lo.ToPtr(true)
}
require.NoError(t, client.Update(ctx, &endpoints, &ctrlclient.UpdateOptions{}))
require.NoError(t, client.Get(ctx, k8stypes.NamespacedName{Name: endpoints.Name, Namespace: endpoints.Namespace}, &endpoints, &ctrlclient.GetOptions{}))
assert.Eventually(t, func() bool { return len(n.LastNotified()) == 0 }, 3*time.Second, time.Millisecond)

// Update 1 endpoint so that that it's Ready.
endpoints.Endpoints[0].Conditions.Ready = lo.ToPtr(true)
// Update 1 endpoint so that it's not Terminating.
endpoints.Endpoints[0].Conditions.Terminating = nil

require.NoError(t, client.Update(ctx, &endpoints, &ctrlclient.UpdateOptions{}))
require.NoError(t, client.Get(ctx, k8stypes.NamespacedName{Name: endpoints.Name, Namespace: endpoints.Namespace}, &endpoints, &ctrlclient.GetOptions{}))
Expand Down

0 comments on commit 2f420a9

Please sign in to comment.