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 #2302: Fix MarshalJSON error caused by incorrect conversion function #2312

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
14 changes: 1 addition & 13 deletions pkg/apis/controlplane/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"

"github.com/vmware-tanzu/antrea/pkg/apis/controlplane"
"github.com/vmware-tanzu/antrea/pkg/apis/security/v1alpha1"
)

func init() {
Expand Down Expand Up @@ -402,18 +401,7 @@ func Convert_controlplane_NetworkPolicy_To_v1beta1_NetworkPolicy(in *controlplan
}

func Convert_controlplane_NetworkPolicyRule_To_v1beta1_NetworkPolicyRule(in *controlplane.NetworkPolicyRule, out *NetworkPolicyRule, s conversion.Scope) error {
out.Direction = Direction(in.Direction)
if err := Convert_controlplane_NetworkPolicyPeer_To_v1beta1_NetworkPolicyPeer(&in.From, &out.From, s); err != nil {
return err
}
if err := Convert_controlplane_NetworkPolicyPeer_To_v1beta1_NetworkPolicyPeer(&in.To, &out.To, s); err != nil {
return err
}
out.Services = *(*[]Service)(unsafe.Pointer(&in.Services))
out.Priority = in.Priority
out.Action = (*v1alpha1.RuleAction)(unsafe.Pointer(in.Action))
out.EnableLogging = in.EnableLogging
return nil
return autoConvert_controlplane_NetworkPolicyRule_To_v1beta1_NetworkPolicyRule(in, out, s)
}

func Convert_v1beta1_Service_To_controlplane_Service(in *Service, out *controlplane.Service, s conversion.Scope) error {
Expand Down
24 changes: 24 additions & 0 deletions pkg/apis/controlplane/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ var (
v1b1TCP = ProtocolTCP
cpTCP = controlplane.ProtocolTCP
int80 = intstr.FromInt(80)
int81 = intstr.FromInt(81)
v1b1Service = Service{
Protocol: &v1b1TCP,
Port: &int80,
Expand Down Expand Up @@ -282,3 +283,26 @@ func TestConvertBetweenV1beta1AndControlplaneService(t *testing.T) {
Convert_v1beta1_Service_To_controlplane_Service(&v1b1Service, &convertedCPService, nil))
assert.Equal(t, cpService, convertedCPService, "v1beta1.GroupMember -> controlplane.GroupMember")
}

func TestConvertBetweenV1beta1NetworkPolicyRuleAndControlplaneNetworkPolicyRule(t *testing.T) {
scheme := runtime.NewScheme()
assert.NoError(t, RegisterConversions(scheme))

cpRule := controlplane.NetworkPolicyRule{
Direction: controlplane.DirectionIn,
Services: []controlplane.Service{
{Protocol: &cpTCP, Port: &int80},
{Protocol: &cpTCP, Port: &int81},
},
From: controlplane.NetworkPolicyPeer{
AddressGroups: []string{"abc", "bcd"},
},
}
var convertedCPRule controlplane.NetworkPolicyRule
var convertedV1beta1Rule NetworkPolicyRule
require.NoError(t,
Convert_controlplane_NetworkPolicyRule_To_v1beta1_NetworkPolicyRule(&cpRule, &convertedV1beta1Rule, nil))
require.NoError(t,
Convert_v1beta1_NetworkPolicyRule_To_controlplane_NetworkPolicyRule(&convertedV1beta1Rule, &convertedCPRule, nil))
assert.Equal(t, cpRule, convertedCPRule)
}