Skip to content

Commit

Permalink
Comment update
Browse files Browse the repository at this point in the history
  • Loading branch information
srahul3 committed Jun 8, 2023
1 parent dc3e24e commit 3dad9a0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 0 additions & 2 deletions control-plane/catalog/to-consul/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,6 @@ func (t *ServiceResource) generateRegistrations(key string) {
r.Service.Address = ip
// Adding information about service weight.
// Overrides the existing weight if present
// Adding information about service weight.
// Overrides the existing weight if present
if weight, ok := svc.Annotations[annotationServiceWeight]; ok && weight != "" {
weightI, err := getServiceWeight(weight)
if err == nil {
Expand Down
35 changes: 35 additions & 0 deletions control-plane/catalog/to-consul/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,41 @@ func TestServiceWeight_externalIP(t *testing.T) {
})
}

// Test that Loadbalancer service weight is set from service annotation.
func TestServiceWeight_invalidValue(t *testing.T) {
t.Parallel()
client := fake.NewSimpleClientset()
syncer := newTestSyncer()
serviceResource := defaultServiceResource(client, syncer)

// Start the controller
closer := controller.TestControllerRun(&serviceResource)
defer closer()

// Insert an LB service
svc := lbService("foo", metav1.NamespaceDefault, "1.2.3.4")
svc.Annotations[annotationServiceWeight] = "1"
svc.Spec.ExternalIPs = []string{"3.3.3.3", "4.4.4.4"}

_, err := client.CoreV1().Services(metav1.NamespaceDefault).Create(context.Background(), svc, metav1.CreateOptions{})
require.NoError(t, err)

// Verify what we got
retry.Run(t, func(r *retry.R) {
syncer.Lock()
defer syncer.Unlock()
actual := syncer.Registrations
require.Len(r, actual, 2)
require.Equal(r, "foo", actual[0].Service.Service)
require.Equal(r, "3.3.3.3", actual[0].Service.Address)
require.Equal(r, 0, actual[0].Service.Weights.Passing)
require.Equal(r, "foo", actual[1].Service.Service)
require.Equal(r, "4.4.4.4", actual[1].Service.Address)
require.Equal(r, 0, actual[1].Service.Weights.Passing)
require.NotEqual(r, actual[0].Service.ID, actual[1].Service.ID)
})
}

func TestServiceWeight_nonIntWeight(t *testing.T) {
t.Parallel()
client := fake.NewSimpleClientset()
Expand Down

0 comments on commit 3dad9a0

Please sign in to comment.