Support NativeLB option in GatewayAPI provider

Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
This commit is contained in:
Romain 2024-10-02 10:34:04 +02:00 committed by GitHub
parent d317cd90fc
commit 373095f1a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 734 additions and 19 deletions

View file

@ -0,0 +1,89 @@
package gateway
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_parseServiceConfig(t *testing.T) {
testCases := []struct {
desc string
annotations map[string]string
expected ServiceConfig
}{
{
desc: "service annotations",
annotations: map[string]string{
"ingress.kubernetes.io/foo": "bar",
"traefik.io/foo": "bar",
"traefik.io/service.nativelb": "true",
},
expected: ServiceConfig{
Service: Service{
NativeLB: true,
},
},
},
{
desc: "empty map",
annotations: map[string]string{},
expected: ServiceConfig{},
},
{
desc: "nil map",
annotations: nil,
expected: ServiceConfig{},
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
cfg, err := parseServiceAnnotations(test.annotations)
require.NoError(t, err)
assert.Equal(t, test.expected, cfg)
})
}
}
func Test_convertAnnotations(t *testing.T) {
testCases := []struct {
desc string
annotations map[string]string
expected map[string]string
}{
{
desc: "service annotations",
annotations: map[string]string{
"traefik.io/service.nativelb": "true",
},
expected: map[string]string{
"traefik.service.nativelb": "true",
},
},
{
desc: "empty map",
annotations: map[string]string{},
expected: nil,
},
{
desc: "nil map",
annotations: nil,
expected: nil,
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
labels := convertAnnotations(test.annotations)
assert.Equal(t, test.expected, labels)
})
}
}