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

add node affinity #278

Merged
merged 1 commit into from
Nov 12, 2021
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
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