Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/prometheus/common v0.44.0
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.10.0
k8s.io/api v0.30.3
k8s.io/apimachinery v0.30.3
k8s.io/apiserver v0.30.3
Expand Down Expand Up @@ -69,6 +70,7 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/profile v1.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
Expand Down
4 changes: 1 addition & 3 deletions pkg/cmd/infra/router/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,7 @@ func (o *TemplateRouterOptions) Run(stopCh <-chan struct{}) error {
if o.UpgradeValidation {
plugin = controller.NewUpgradeValidation(plugin, recorder, o.UpgradeValidationForceAddCondition, o.UpgradeValidationForceRemoveCondition)
}
if o.ExtendedValidation {
plugin = controller.NewExtendedValidator(plugin, recorder)
}
plugin = controller.NewExtendedValidator(plugin, recorder, o.ExtendedValidation)
if o.AllowExternalCertificates {
plugin = controller.NewRouteSecretManager(plugin, recorder, secretManager, kc.CoreV1(), authorizationClient.SubjectAccessReviews())
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/router/controller/endpointsubset/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ package endpointsubset
import (
corev1 "k8s.io/api/core/v1"
discoveryv1 "k8s.io/api/discovery/v1"

logf "github.com/openshift/router/log"
)

var log = logf.Logger.WithName("endpointsubset")

// ConvertEndpointSlice converts items to a slice of EndpointSubset's.
func ConvertEndpointSlice(items []discoveryv1.EndpointSlice, addressOrderByFuncs []EndpointAddressLessFunc, portOrderByFuncs []EndpointPortLessFunc) []corev1.EndpointSubset {
var subsets []corev1.EndpointSubset

for i := range items {
if items[i].AddressType != discoveryv1.AddressTypeIPv4 && items[i].AddressType != discoveryv1.AddressTypeIPv6 {
log.Info("Skipping EndpointSlice with unsupported address type", "namespace", items[i].Namespace, "name", items[i].Name, "addressType", items[i].AddressType)
continue
}

var ports []corev1.EndpointPort
var addresses []corev1.EndpointAddress
var notReadyAddresses []corev1.EndpointAddress
Expand Down
188 changes: 188 additions & 0 deletions pkg/router/controller/endpointsubset/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,191 @@ func TestConvertEndpointSlice(t *testing.T) {
})
}
}

func TestConvertEndpointSlice_addressTypes(t *testing.T) {
serviceLabels := map[string]string{
discoveryv1.LabelServiceName: "service-a",
}
sliceMeta := metav1.TypeMeta{
Kind: "EndpointSlice",
APIVersion: "discovery.k8s.io/v1",
}

tests := []struct {
name string
items []discoveryv1.EndpointSlice
want []v1.EndpointSubset
}{{
name: "FQDN AddressType is skipped",
items: []discoveryv1.EndpointSlice{{
TypeMeta: sliceMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "slice-fqdn",
Namespace: "namespace-a",
Labels: serviceLabels,
},
AddressType: discoveryv1.AddressTypeFQDN,
Endpoints: []discoveryv1.Endpoint{{
Addresses: []string{"metadata.google.internal"},
}},
Ports: []discoveryv1.EndpointPort{{
Port: int32Ptr(8080),
}},
}},
}, {
name: "unknown AddressType is skipped",
items: []discoveryv1.EndpointSlice{{
TypeMeta: sliceMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "slice-unknown",
Namespace: "namespace-a",
Labels: serviceLabels,
},
AddressType: discoveryv1.AddressType("Unknown"),
Endpoints: []discoveryv1.Endpoint{{
Addresses: []string{"10.0.0.2"},
}},
}},
}, {
name: "empty AddressType is skipped",
items: []discoveryv1.EndpointSlice{{
TypeMeta: sliceMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "slice-empty-type",
Namespace: "namespace-a",
Labels: serviceLabels,
},
Endpoints: []discoveryv1.Endpoint{{
Addresses: []string{"10.0.0.3"},
}},
}},
}, {
name: "IPv6 AddressType is converted",
items: []discoveryv1.EndpointSlice{{
TypeMeta: sliceMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "slice-ipv6",
Namespace: "namespace-a",
Labels: serviceLabels,
},
AddressType: discoveryv1.AddressTypeIPv6,
Endpoints: []discoveryv1.Endpoint{{
Addresses: []string{"2001:db8::1"},
}},
Ports: []discoveryv1.EndpointPort{{
Port: int32Ptr(443),
}},
}},
want: []v1.EndpointSubset{{
Addresses: []v1.EndpointAddress{{IP: "2001:db8::1"}},
Ports: []v1.EndpointPort{{Port: 443}},
}},
}, {
name: "IPv4 slice with hostname in addresses passes through conversion",
items: []discoveryv1.EndpointSlice{{
TypeMeta: sliceMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "slice-ipv4-hostname",
Namespace: "namespace-a",
Labels: serviceLabels,
},
AddressType: discoveryv1.AddressTypeIPv4,
Endpoints: []discoveryv1.Endpoint{{
Addresses: []string{"10.0.0.1", "metadata.google.internal"},
}},
Ports: []discoveryv1.EndpointPort{{
Port: int32Ptr(8080),
}},
}},
want: []v1.EndpointSubset{{
Addresses: []v1.EndpointAddress{
{IP: "metadata.google.internal"},
{IP: "10.0.0.1"},
},
Ports: []v1.EndpointPort{{Port: 8080}},
}},
}, {
name: "mixed supported and unsupported slices",
items: []discoveryv1.EndpointSlice{{
TypeMeta: sliceMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "slice-fqdn",
Namespace: "namespace-a",
Labels: serviceLabels,
},
AddressType: discoveryv1.AddressTypeFQDN,
Endpoints: []discoveryv1.Endpoint{{
Addresses: []string{"metadata.google.internal"},
}},
}, {
TypeMeta: sliceMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "slice-unknown",
Namespace: "namespace-a",
Labels: serviceLabels,
},
AddressType: discoveryv1.AddressType("Unknown"),
Endpoints: []discoveryv1.Endpoint{{
Addresses: []string{"10.0.0.2"},
}},
}, {
TypeMeta: sliceMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "slice-empty-type",
Namespace: "namespace-a",
Labels: serviceLabels,
},
Endpoints: []discoveryv1.Endpoint{{
Addresses: []string{"10.0.0.3"},
}},
}, {
TypeMeta: sliceMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "slice-ipv4",
Namespace: "namespace-a",
Labels: serviceLabels,
},
AddressType: discoveryv1.AddressTypeIPv4,
Endpoints: []discoveryv1.Endpoint{{
Addresses: []string{"10.0.0.1"},
}},
Ports: []discoveryv1.EndpointPort{{
Port: int32Ptr(80),
}},
}, {
TypeMeta: sliceMeta,
ObjectMeta: metav1.ObjectMeta{
Name: "slice-ipv6",
Namespace: "namespace-a",
Labels: serviceLabels,
},
AddressType: discoveryv1.AddressTypeIPv6,
Endpoints: []discoveryv1.Endpoint{{
Addresses: []string{"2001:db8::1"},
}},
Ports: []discoveryv1.EndpointPort{{
Port: int32Ptr(443),
}},
}},
want: []v1.EndpointSubset{{
Addresses: []v1.EndpointAddress{{IP: "10.0.0.1"}},
Ports: []v1.EndpointPort{{Port: 80}},
}, {
Addresses: []v1.EndpointAddress{{IP: "2001:db8::1"}},
Ports: []v1.EndpointPort{{Port: 443}},
}},
}}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := endpointsubset.ConvertEndpointSlice(
tc.items,
endpointsubset.DefaultEndpointAddressOrderByFuncs(),
endpointsubset.DefaultEndpointPortOrderByFuncs(),
)
if diff := cmp.Diff(tc.want, got); len(diff) != 0 {
t.Errorf("ConvertEndpointSlice() failed (-want +got):\n%s", diff)
}
})
}
}
Loading