Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #5367: Remove NetworkPolicyStats dependency of of MulticastGroup API #5396

Merged
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
6 changes: 0 additions & 6 deletions pkg/apiserver/registry/stats/multicastgroup/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ func (r *REST) NewList() runtime.Object {
}

func (r *REST) List(ctx context.Context, options *internalversion.ListOptions) (runtime.Object, error) {
if !features.DefaultFeatureGate.Enabled(features.NetworkPolicyStats) {
return &statsv1alpha1.MulticastGroupList{}, nil
}
if !features.DefaultFeatureGate.Enabled(features.Multicast) {
return &statsv1alpha1.MulticastGroupList{}, nil
}
Expand All @@ -85,9 +82,6 @@ func (r *REST) List(ctx context.Context, options *internalversion.ListOptions) (
}

func (r *REST) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
if !features.DefaultFeatureGate.Enabled(features.NetworkPolicyStats) {
return &statsv1alpha1.MulticastGroup{}, nil
}
if !features.DefaultFeatureGate.Enabled(features.Multicast) {
return &statsv1alpha1.MulticastGroup{}, nil
}
Expand Down
82 changes: 38 additions & 44 deletions pkg/apiserver/registry/stats/multicastgroup/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,28 @@ func TestREST(t *testing.T) {

func TestRESTList(t *testing.T) {
tests := []struct {
name string
networkPolicyStatsEnabled bool
multicastEnabled bool
stats map[string]*statsv1alpha1.MulticastGroup
groupName string
expectedObj runtime.Object
name string
multicastEnabled bool
stats map[string]*statsv1alpha1.MulticastGroup
expectedObj runtime.Object
}{
{
name: "NetworkPolicyStats feature disabled",
networkPolicyStatsEnabled: false,
groupName: group1.Name,
expectedObj: &statsv1alpha1.MulticastGroupList{},
},
{
name: "Multicast feature disabled",
multicastEnabled: false,
groupName: group1.Name,
expectedObj: &statsv1alpha1.MulticastGroupList{},
stats: map[string]*statsv1alpha1.MulticastGroup{
group1.Name: group1,
group2.Name: group2,
},
expectedObj: &statsv1alpha1.MulticastGroupList{},
},
{
name: "empty group",
networkPolicyStatsEnabled: true,
multicastEnabled: true,
expectedObj: &statsv1alpha1.MulticastGroupList{},
name: "empty group",
multicastEnabled: true,
expectedObj: &statsv1alpha1.MulticastGroupList{},
},
{
name: "multiple groups",
networkPolicyStatsEnabled: true,
multicastEnabled: true,
name: "multiple groups",
multicastEnabled: true,
stats: map[string]*statsv1alpha1.MulticastGroup{
group1.Name: group1,
group2.Name: group2,
Expand All @@ -127,7 +120,6 @@ func TestRESTList(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, features.DefaultFeatureGate, features.NetworkPolicyStats, tt.networkPolicyStatsEnabled)()
defer featuregatetesting.SetFeatureGateDuringTest(t, features.DefaultFeatureGate, features.Multicast, tt.multicastEnabled)()

r := &REST{
Expand All @@ -142,38 +134,41 @@ func TestRESTList(t *testing.T) {

func TestRESTGet(t *testing.T) {
tests := []struct {
name string
networkPolicyStatsEnabled bool
multicastEnabled bool
groups map[string]*statsv1alpha1.MulticastGroup
groupName string
expectedObj runtime.Object
expectedErr error
name string
multicastEnabled bool
groups map[string]*statsv1alpha1.MulticastGroup
groupName string
expectedObj runtime.Object
expectedErr error
}{
{
name: "NetworkPolicyStats feature disabled",
networkPolicyStatsEnabled: false,
groupName: group1.Name,
expectedObj: &statsv1alpha1.MulticastGroup{},
name: "NetworkPolicyStats feature disabled",
multicastEnabled: true,
groupName: group1.Name,
groups: map[string]*statsv1alpha1.MulticastGroup{
group1.Name: group1,
},
expectedObj: group1,
},
{
name: "Multicast feature disabled",
multicastEnabled: false,
groupName: group1.Name,
expectedObj: &statsv1alpha1.MulticastGroup{},
groups: map[string]*statsv1alpha1.MulticastGroup{
group1.Name: group1,
},
expectedObj: &statsv1alpha1.MulticastGroup{},
},
{
name: "group not found",
networkPolicyStatsEnabled: true,
multicastEnabled: true,
groups: nil,
groupName: group1.Name,
expectedErr: errors.NewNotFound(statsv1alpha1.Resource("multicastgroup"), "224.0.0.10"),
name: "group not found",
multicastEnabled: true,
groups: nil,
groupName: group1.Name,
expectedErr: errors.NewNotFound(statsv1alpha1.Resource("multicastgroup"), "224.0.0.10"),
},
{
name: "group found",
networkPolicyStatsEnabled: true,
multicastEnabled: true,
name: "group found",
multicastEnabled: true,
groups: map[string]*statsv1alpha1.MulticastGroup{
group1.Name: group1,
},
Expand All @@ -183,7 +178,6 @@ func TestRESTGet(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, features.DefaultFeatureGate, features.NetworkPolicyStats, tt.networkPolicyStatsEnabled)()
defer featuregatetesting.SetFeatureGateDuringTest(t, features.DefaultFeatureGate, features.Multicast, tt.multicastEnabled)()

r := &REST{
Expand Down