Graduate EndpointSliceNodeName feature gate to GA

- Feature gate can be removed when EndpointSlice v1beta1 is removed
  - Remove test cases where feature gate is disabled
This commit is contained in:
Swetha Repakula
2021-03-03 17:05:57 -08:00
parent afb1ee3c9a
commit be2ef551d1
6 changed files with 68 additions and 167 deletions

View File

@@ -27,11 +27,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/rand"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/kubernetes/fake"
k8stesting "k8s.io/client-go/testing"
featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/kubernetes/pkg/features"
utilpointer "k8s.io/utils/pointer"
)
@@ -81,83 +78,39 @@ func TestNewEndpointSlice(t *testing.T) {
}
func TestAddressToEndpoint(t *testing.T) {
testCases := []struct {
name string
epAddress v1.EndpointAddress
expectedEndpoint discovery.Endpoint
ready bool
nodeNameGateEnabled bool
}{{
name: "simple + gate enabled",
epAddress: v1.EndpointAddress{
IP: "10.1.2.3",
Hostname: "foo",
NodeName: utilpointer.StringPtr("node-abc"),
TargetRef: &v1.ObjectReference{
APIVersion: "v1",
Kind: "Pod",
Namespace: "default",
Name: "foo",
},
//name: "simple + gate enabled",
epAddress := v1.EndpointAddress{
IP: "10.1.2.3",
Hostname: "foo",
NodeName: utilpointer.StringPtr("node-abc"),
TargetRef: &v1.ObjectReference{
APIVersion: "v1",
Kind: "Pod",
Namespace: "default",
Name: "foo",
},
ready: true,
nodeNameGateEnabled: true,
expectedEndpoint: discovery.Endpoint{
Addresses: []string{"10.1.2.3"},
Hostname: utilpointer.StringPtr("foo"),
Conditions: discovery.EndpointConditions{
Ready: utilpointer.BoolPtr(true),
},
Topology: map[string]string{
"kubernetes.io/hostname": "node-abc",
},
TargetRef: &v1.ObjectReference{
APIVersion: "v1",
Kind: "Pod",
Namespace: "default",
Name: "foo",
},
NodeName: utilpointer.StringPtr("node-abc"),
},
}, {
name: "simple + gate disabled",
epAddress: v1.EndpointAddress{
IP: "10.1.2.3",
Hostname: "foo",
NodeName: utilpointer.StringPtr("node-abc"),
TargetRef: &v1.ObjectReference{
APIVersion: "v1",
Kind: "Pod",
Namespace: "default",
Name: "foo",
},
},
ready: true,
nodeNameGateEnabled: false,
expectedEndpoint: discovery.Endpoint{
Addresses: []string{"10.1.2.3"},
Hostname: utilpointer.StringPtr("foo"),
Conditions: discovery.EndpointConditions{
Ready: utilpointer.BoolPtr(true),
},
Topology: map[string]string{
"kubernetes.io/hostname": "node-abc",
},
TargetRef: &v1.ObjectReference{
APIVersion: "v1",
Kind: "Pod",
Namespace: "default",
Name: "foo",
},
},
}}
for _, tc := range testCases {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.EndpointSliceNodeName, tc.nodeNameGateEnabled)()
ep := addressToEndpoint(tc.epAddress, tc.ready)
assert.EqualValues(t, tc.expectedEndpoint, *ep)
}
ready := true
expectedEndpoint := discovery.Endpoint{
Addresses: []string{"10.1.2.3"},
Hostname: utilpointer.StringPtr("foo"),
Conditions: discovery.EndpointConditions{
Ready: utilpointer.BoolPtr(true),
},
Topology: map[string]string{
"kubernetes.io/hostname": "node-abc",
},
TargetRef: &v1.ObjectReference{
APIVersion: "v1",
Kind: "Pod",
Namespace: "default",
Name: "foo",
},
NodeName: utilpointer.StringPtr("node-abc"),
}
ep := addressToEndpoint(epAddress, ready)
assert.EqualValues(t, expectedEndpoint, *ep)
}
// Test helpers