Support NativeLB option in GatewayAPI provider
Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
This commit is contained in:
parent
d317cd90fc
commit
373095f1a8
17 changed files with 734 additions and 19 deletions
89
pkg/provider/kubernetes/gateway/annotations_test.go
Normal file
89
pkg/provider/kubernetes/gateway/annotations_test.go
Normal 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)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue