Skip to content

Commit

Permalink
Add E2E test and fix UT
Browse files Browse the repository at this point in the history
  • Loading branch information
Dyanngg committed Apr 5, 2021
1 parent 0c229da commit 322b9a2
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 223 deletions.
2 changes: 1 addition & 1 deletion pkg/apiserver/certificate/cacert_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var (
"labelsmutator.antrea.io",
}
conversionWebhooks = []string{
"clustergroups.core.antrea.tanzu.vmware.com",
"clustergroups.crd.antrea.io",
}
)

Expand Down
17 changes: 6 additions & 11 deletions pkg/controller/grouping/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func ConvertClusterGroupCRD(Object *unstructured.Unstructured, toVersion string)
return nil, statusErrorWithMessage("conversion from a version to itself should not call the webhook: %s", toVersion)
}
switch Object.GetAPIVersion() {
case "core.antrea.tanzu.vmware.com/v1alpha2":
case "crd.antrea.io/v1alpha2":
switch toVersion {
case "core.antrea.tanzu.vmware.com/v1alpha3":
case "crd.antrea.io/v1alpha3":
ipb, found, err := unstructured.NestedMap(convertedObject.Object, "spec", "ipBlock")
if err == nil && found {
unstructured.RemoveNestedField(convertedObject.Object, "spec", "ipBlock")
Expand All @@ -51,16 +51,11 @@ func ConvertClusterGroupCRD(Object *unstructured.Unstructured, toVersion string)
default:
return nil, statusErrorWithMessage("unexpected conversion version %q", toVersion)
}
case "core.antrea.tanzu.vmware.com/v1alpha3":
case "crd.antrea.io/v1alpha3":
switch toVersion {
case "core.antrea.tanzu.vmware.com/v1alpha2":
ipbs, found, err := unstructured.NestedSlice(convertedObject.Object, "spec", "ipBlocks")
if err == nil && found {
if len(ipbs) > 1 {
return nil, statusErrorWithMessage("canont convert a v1alpha3 ClusterGroup that has more than one ipBlock to v1alpha2 ClusterGroup", toVersion)
}
unstructured.RemoveNestedField(convertedObject.Object, "spec", "ipBlocks")
unstructured.SetNestedField(convertedObject.Object, ipbs[0], "spec", "ipBlock")
case "crd.antrea.io/v1alpha2":
return convertedObject, metav1.Status{
Status: metav1.StatusSuccess,
}
default:
return nil, statusErrorWithMessage("unexpected conversion version %q", toVersion)
Expand Down
42 changes: 23 additions & 19 deletions pkg/controller/networkpolicy/clusternetworkpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/vmware-tanzu/antrea/pkg/apis/controlplane"
crdv1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/crd/v1alpha1"
crdv1alpha2 "github.com/vmware-tanzu/antrea/pkg/apis/crd/v1alpha2"
crdv1alpha3 "github.com/vmware-tanzu/antrea/pkg/apis/crd/v1alpha3"
antreatypes "github.com/vmware-tanzu/antrea/pkg/controller/types"
)

Expand All @@ -42,9 +42,9 @@ func TestProcessClusterNetworkPolicy(t *testing.T) {
selectorA := metav1.LabelSelector{MatchLabels: map[string]string{"foo1": "bar1"}}
selectorB := metav1.LabelSelector{MatchLabels: map[string]string{"foo2": "bar2"}}
selectorC := metav1.LabelSelector{MatchLabels: map[string]string{"foo3": "bar3"}}
cgA := crdv1alpha2.ClusterGroup{
cgA := crdv1alpha3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgA", UID: "uidA"},
Spec: crdv1alpha2.GroupSpec{
Spec: crdv1alpha3.GroupSpec{
NamespaceSelector: &selectorA,
},
}
Expand Down Expand Up @@ -1249,25 +1249,27 @@ func TestProcessRefCG(t *testing.T) {
cidr := "10.0.0.0/24"
cidrIPNet, _ := cidrStrToIPNet(cidr)
// cgA with selector present in cache
cgA := crdv1alpha2.ClusterGroup{
cgA := crdv1alpha3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgA", UID: "uidA"},
Spec: crdv1alpha2.GroupSpec{
Spec: crdv1alpha3.GroupSpec{
NamespaceSelector: &selectorA,
},
}
// cgB with IPBlock present in cache
cgB := crdv1alpha2.ClusterGroup{
cgB := crdv1alpha3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgB", UID: "uidB"},
Spec: crdv1alpha2.GroupSpec{
IPBlock: &crdv1alpha1.IPBlock{
CIDR: cidr,
Spec: crdv1alpha3.GroupSpec{
IPBlocks: []crdv1alpha1.IPBlock{
{
CIDR: cidr,
},
},
},
}
// cgC not found in cache
cgC := crdv1alpha2.ClusterGroup{
cgC := crdv1alpha3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgC", UID: "uidC"},
Spec: crdv1alpha2.GroupSpec{
Spec: crdv1alpha3.GroupSpec{
NamespaceSelector: &selectorA,
},
}
Expand Down Expand Up @@ -1325,25 +1327,27 @@ func TestProcessAppliedToGroupsForCGs(t *testing.T) {
selectorA := metav1.LabelSelector{MatchLabels: map[string]string{"foo1": "bar1"}}
cidr := "10.0.0.0/24"
// cgA with selector present in cache
cgA := crdv1alpha2.ClusterGroup{
cgA := crdv1alpha3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgA", UID: "uidA"},
Spec: crdv1alpha2.GroupSpec{
Spec: crdv1alpha3.GroupSpec{
NamespaceSelector: &selectorA,
},
}
// cgB with IPBlock present in cache
cgB := crdv1alpha2.ClusterGroup{
cgB := crdv1alpha3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgB", UID: "uidB"},
Spec: crdv1alpha2.GroupSpec{
IPBlock: &crdv1alpha1.IPBlock{
CIDR: cidr,
Spec: crdv1alpha3.GroupSpec{
IPBlocks: []crdv1alpha1.IPBlock{
{
CIDR: cidr,
},
},
},
}
// cgC not found in cache
cgC := crdv1alpha2.ClusterGroup{
cgC := crdv1alpha3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgC", UID: "uidC"},
Spec: crdv1alpha2.GroupSpec{
Spec: crdv1alpha3.GroupSpec{
NamespaceSelector: &selectorA,
},
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/networkpolicy/crd_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"github.com/vmware-tanzu/antrea/pkg/apis/controlplane"
crdv1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/crd/v1alpha1"
crdv1alpha2 "github.com/vmware-tanzu/antrea/pkg/apis/crd/v1alpha2"
crdv1alpha3 "github.com/vmware-tanzu/antrea/pkg/apis/crd/v1alpha3"
)

func TestToAntreaServicesForCRD(t *testing.T) {
Expand Down Expand Up @@ -152,9 +152,9 @@ func TestToAntreaPeerForCRD(t *testing.T) {
matchAllPodsPeer := matchAllPeer
matchAllPodsPeer.AddressGroups = []string{getNormalizedUID(toGroupSelector("", nil, &selectorAll, nil).NormalizedName)}
// cgA with selector present in cache
cgA := crdv1alpha2.ClusterGroup{
cgA := crdv1alpha3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgA", UID: "uidA"},
Spec: crdv1alpha2.GroupSpec{
Spec: crdv1alpha3.GroupSpec{
NamespaceSelector: &selectorA,
},
}
Expand Down
Loading

0 comments on commit 322b9a2

Please sign in to comment.