Skip to content

Commit

Permalink
Merge pull request #278 from njucjc/e2e-test
Browse files Browse the repository at this point in the history
add node affinity
  • Loading branch information
l1b0k authored Nov 12, 2021
2 parents 99f0e6b + 6136030 commit fd6d612
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tests/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

var enableTrunk bool
var enablePolicy bool
var testNamespace = "network-test" + strconv.FormatInt(time.Now().Unix(), 10)
var testNamespace = "network-test-" + strconv.FormatInt(time.Now().Unix(), 10)

func init() {
flag.BoolVar(&enableTrunk, "trunk", false, "install trunk policy")
Expand Down
19 changes: 9 additions & 10 deletions tests/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,10 @@ func (s *ConnectionTestSuite) SetupSuite() {
func (s *ConnectionTestSuite) TearDownSuite() {

if s.err != nil {
s.T().Errorf("skip tear down resource in namespace %s, because of an error occurred.", testNamespace)
s.T().Error(errors.Wrapf(s.err, "skip tear down resource in namespace %s, because of an error occurred.", testNamespace))
return
}

ctx := context.Background()
if enablePolicy {
s.T().Logf("delete %s", networkPolicy.Name)
Expand Down Expand Up @@ -374,9 +375,8 @@ func (s *ConnectionTestSuite) TestPod2Pod() {
for _, ip := range podIPs(&dst) {
addr := net.JoinHostPort(ip, "80")
l := fmt.Sprintf("src %s -> dst %s", podInfo(&src), addr)
var stdErrOut []byte
_, stdErrOut, s.err = s.ExecHTTPGet(src.Namespace, src.Name, curlAddr(addr))
s.Expected(c.Status, stdErrOut, s.err, l)
_, stdErrOut, err := s.ExecHTTPGet(src.Namespace, src.Name, curlAddr(addr))
s.Expected(c.Status, stdErrOut, err, l)
}
}
}
Expand Down Expand Up @@ -443,9 +443,8 @@ func (s *ConnectionTestSuite) TestPod2ServiceIP() {

for _, addr := range addrs {
l := fmt.Sprintf("src %s -> dst svc name %s, addr %s", podInfo(&src), svc.Name, addr)
var stdErrOut []byte
_, stdErrOut, s.err = s.ExecHTTPGet(src.Namespace, src.Name, curlAddr(addr))
s.Expected(c.Status, stdErrOut, s.err, l)
_, stdErrOut, err := s.ExecHTTPGet(src.Namespace, src.Name, curlAddr(addr))
s.Expected(c.Status, stdErrOut, err, l)
}
}
}
Expand Down Expand Up @@ -473,9 +472,8 @@ func (s *ConnectionTestSuite) TestPod2ServiceName() {
for _, src := range srcPods {
for _, svc := range dstServices {
l := fmt.Sprintf("src %s -> dst svc name %s", podInfo(&src), svc.Name)
var stdErrOut []byte
_, stdErrOut, s.err = s.ExecHTTPGet(src.Namespace, src.Name, svc.Name)
s.Expected(c.Status, stdErrOut, s.err, l)
_, stdErrOut, err := s.ExecHTTPGet(src.Namespace, src.Name, svc.Name)
s.Expected(c.Status, stdErrOut, err, l)
}
}
}
Expand All @@ -486,6 +484,7 @@ func (s *ConnectionTestSuite) Expected(status bool, stdErrOut []byte, err error,
if assert.NoError(s.T(), err, msg) && assert.Equal(s.T(), 0, len(stdErrOut), msg) {
s.T().Logf(msg + ", test pass")
} else {
s.err = err
s.T().Error(errors.Wrapf(err, "%s, test failed, expected connection success, but connection failure", msg))
}
} else {
Expand Down
57 changes: 57 additions & 0 deletions tests/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,25 @@ func EnsureDaemonSet(ctx context.Context, cs kubernetes.Interface, cfg PodResCon
ImagePullPolicy: corev1.PullAlways,
},
},
Affinity: &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
NodeSelectorTerms: []corev1.NodeSelectorTerm{
{
MatchExpressions: []corev1.NodeSelectorRequirement{
{
Key: "type",
Operator: corev1.NodeSelectorOpNotIn,
Values: []string{
"virtual-kubelet",
},
},
},
},
},
},
},
},
},
},
},
Expand Down Expand Up @@ -204,6 +223,25 @@ func EnsureDeployment(ctx context.Context, cs kubernetes.Interface, cfg PodResCo
ImagePullPolicy: corev1.PullAlways,
},
},
Affinity: &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
NodeSelectorTerms: []corev1.NodeSelectorTerm{
{
MatchExpressions: []corev1.NodeSelectorRequirement{
{
Key: "type",
Operator: corev1.NodeSelectorOpNotIn,
Values: []string{
"virtual-kubelet",
},
},
},
},
},
},
},
},
},
},
},
Expand Down Expand Up @@ -256,6 +294,25 @@ func EnsureStatefulSet(ctx context.Context, cs kubernetes.Interface, cfg PodResC
ImagePullPolicy: corev1.PullAlways,
},
},
Affinity: &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
NodeSelectorTerms: []corev1.NodeSelectorTerm{
{
MatchExpressions: []corev1.NodeSelectorRequirement{
{
Key: "type",
Operator: corev1.NodeSelectorOpNotIn,
Values: []string{
"virtual-kubelet",
},
},
},
},
},
},
},
},
},
},
},
Expand Down

0 comments on commit fd6d612

Please sign in to comment.