mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Generate warning for EndpointSlice AddressType FQDN
Change-Id: Ibc213acdffa741e630821f371ea25e2b5187a011
This commit is contained in:
parent
5cdec8f99e
commit
249f763c7e
@ -37,7 +37,7 @@ type EndpointSlice struct {
|
|||||||
// supported:
|
// supported:
|
||||||
// * IPv4: Represents an IPv4 Address.
|
// * IPv4: Represents an IPv4 Address.
|
||||||
// * IPv6: Represents an IPv6 Address.
|
// * IPv6: Represents an IPv6 Address.
|
||||||
// * FQDN: Represents a Fully Qualified Domain Name.
|
// * FQDN: Represents a Fully Qualified Domain Name. [DEPRECATED]
|
||||||
AddressType AddressType
|
AddressType AddressType
|
||||||
// endpoints is a list of unique endpoints in this slice. Each slice may
|
// endpoints is a list of unique endpoints in this slice. Each slice may
|
||||||
// include a maximum of 1000 endpoints.
|
// include a maximum of 1000 endpoints.
|
||||||
|
@ -18,6 +18,7 @@ package endpointslice
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
discoveryv1beta1 "k8s.io/api/discovery/v1beta1"
|
discoveryv1beta1 "k8s.io/api/discovery/v1beta1"
|
||||||
@ -92,7 +93,13 @@ func (endpointSliceStrategy) Validate(ctx context.Context, obj runtime.Object) f
|
|||||||
|
|
||||||
// WarningsOnCreate returns warnings for the creation of the given object.
|
// WarningsOnCreate returns warnings for the creation of the given object.
|
||||||
func (endpointSliceStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
func (endpointSliceStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||||
return nil
|
eps := obj.(*discovery.EndpointSlice)
|
||||||
|
if eps == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var warnings []string
|
||||||
|
warnings = append(warnings, warnOnDeprecatedAddressType(eps.AddressType)...)
|
||||||
|
return warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
// Canonicalize normalizes the object after validation.
|
// Canonicalize normalizes the object after validation.
|
||||||
@ -207,3 +214,11 @@ func getDeprecatedTopologyNodeNames(eps *discovery.EndpointSlice) sets.String {
|
|||||||
}
|
}
|
||||||
return names
|
return names
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// warnOnDeprecatedAddressType returns a warning for endpointslices with FQDN AddressType
|
||||||
|
func warnOnDeprecatedAddressType(addressType discovery.AddressType) []string {
|
||||||
|
if addressType == discovery.AddressTypeFQDN {
|
||||||
|
return []string{fmt.Sprintf("%s: FQDN endpoints are deprecated", field.NewPath("spec").Child("addressType"))}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -978,3 +978,39 @@ func Test_getDeprecatedTopologyNodeNames(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWarningsOnEndpointSliceAddressType(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
addressType discovery.AddressType
|
||||||
|
wantWarning bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "AddressType = FQDN",
|
||||||
|
addressType: discovery.AddressTypeFQDN,
|
||||||
|
wantWarning: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "AddressType = IPV4",
|
||||||
|
addressType: discovery.AddressTypeIPv4,
|
||||||
|
wantWarning: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "AddressType = IPV6",
|
||||||
|
addressType: discovery.AddressTypeIPv6,
|
||||||
|
wantWarning: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
ctx := genericapirequest.WithRequestInfo(genericapirequest.NewContext(), &genericapirequest.RequestInfo{APIGroup: "discovery.k8s.io", APIVersion: "v1", Resource: "endpointslices"})
|
||||||
|
edp := discovery.EndpointSlice{AddressType: tc.addressType}
|
||||||
|
got := Strategy.WarningsOnCreate(ctx, &edp)
|
||||||
|
if tc.wantWarning && len(got) == 0 {
|
||||||
|
t.Fatal("Failed warning was not returned")
|
||||||
|
} else if !tc.wantWarning && len(got) != 0 {
|
||||||
|
t.Fatalf("Failed warning was returned (%v)", got)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user