Skip to content

Commit

Permalink
Add E2E tests and fix UT
Browse files Browse the repository at this point in the history
  • Loading branch information
Dyanngg committed Mar 29, 2021
1 parent eb38cfe commit 6e2ce92
Show file tree
Hide file tree
Showing 10 changed files with 311 additions and 127 deletions.
2 changes: 0 additions & 2 deletions pkg/apis/core/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

"github.com/vmware-tanzu/antrea/pkg/apis/core"
"github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha2"
"github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha3"
)

// Install registers the API group and adds types to a scheme
func Install(scheme *runtime.Scheme) {
utilruntime.Must(core.AddToScheme(scheme))
utilruntime.Must(v1alpha2.AddToScheme(scheme))
utilruntime.Must(v1alpha3.AddToScheme(scheme))
utilruntime.Must(scheme.SetVersionPriority(v1alpha3.SchemeGroupVersion, v1alpha2.SchemeGroupVersion))
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/core/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions pkg/controller/grouping/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ func ConvertClusterGroupCRD(Object *unstructured.Unstructured, toVersion string)
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")
}
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 @@ -21,7 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/vmware-tanzu/antrea/pkg/apis/controlplane"
corev1a2 "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha2"
corev1a3 "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha3"
secv1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/security/v1alpha1"
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 := corev1a2.ClusterGroup{
cgA := corev1a3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgA", UID: "uidA"},
Spec: corev1a2.GroupSpec{
Spec: corev1a3.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 := corev1a2.ClusterGroup{
cgA := corev1a3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgA", UID: "uidA"},
Spec: corev1a2.GroupSpec{
Spec: corev1a3.GroupSpec{
NamespaceSelector: &selectorA,
},
}
// cgB with IPBlock present in cache
cgB := corev1a2.ClusterGroup{
cgB := corev1a3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgB", UID: "uidB"},
Spec: corev1a2.GroupSpec{
IPBlock: &secv1alpha1.IPBlock{
CIDR: cidr,
Spec: corev1a3.GroupSpec{
IPBlocks: []secv1alpha1.IPBlock{
{
CIDR: cidr,
},
},
},
}
// cgC not found in cache
cgC := corev1a2.ClusterGroup{
cgC := corev1a3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgC", UID: "uidC"},
Spec: corev1a2.GroupSpec{
Spec: corev1a3.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 := corev1a2.ClusterGroup{
cgA := corev1a3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgA", UID: "uidA"},
Spec: corev1a2.GroupSpec{
Spec: corev1a3.GroupSpec{
NamespaceSelector: &selectorA,
},
}
// cgB with IPBlock present in cache
cgB := corev1a2.ClusterGroup{
cgB := corev1a3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgB", UID: "uidB"},
Spec: corev1a2.GroupSpec{
IPBlock: &secv1alpha1.IPBlock{
CIDR: cidr,
Spec: corev1a3.GroupSpec{
IPBlocks: []secv1alpha1.IPBlock{
{
CIDR: cidr,
},
},
},
}
// cgC not found in cache
cgC := corev1a2.ClusterGroup{
cgC := corev1a3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgC", UID: "uidC"},
Spec: corev1a2.GroupSpec{
Spec: corev1a3.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 @@ -24,7 +24,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/vmware-tanzu/antrea/pkg/apis/controlplane"
corev1a2 "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha2"
corev1a3 "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha3"
secv1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/security/v1alpha1"
)

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 := corev1a2.ClusterGroup{
cgA := corev1a3.ClusterGroup{
ObjectMeta: metav1.ObjectMeta{Name: "cgA", UID: "uidA"},
Spec: corev1a2.GroupSpec{
Spec: corev1a3.GroupSpec{
NamespaceSelector: &selectorA,
},
}
Expand Down
Loading

0 comments on commit 6e2ce92

Please sign in to comment.