Skip to content

Commit

Permalink
Merge pull request #722 from EDGsheryl/master
Browse files Browse the repository at this point in the history
Figure TODO item: add a flag to disable Network Policy
  • Loading branch information
volcano-sh-bot authored Feb 28, 2020
2 parents 7219f84 + 6c4c98c commit ed6b56b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
10 changes: 7 additions & 3 deletions pkg/controllers/job/plugins/svc/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type servicePlugin struct {

// flag parse args
publishNotReadyAddresses bool
disableNetworkPolicy bool
}

// New creates service plugin
Expand All @@ -63,6 +64,8 @@ func (sp *servicePlugin) addFlags() {
flagSet := flag.NewFlagSet(sp.Name(), flag.ContinueOnError)
flagSet.BoolVar(&sp.publishNotReadyAddresses, "publish-not-ready-addresses", sp.publishNotReadyAddresses,
"set publishNotReadyAddresses of svc to true")
flagSet.BoolVar(&sp.disableNetworkPolicy, "disable-network-policy", sp.disableNetworkPolicy,
"set disableNetworkPolicy of svc to true")

if err := flagSet.Parse(sp.pluginArguments); err != nil {
klog.Errorf("plugin %s flagset parse failed, err: %v", sp.Name(), err)
Expand Down Expand Up @@ -138,9 +141,10 @@ func (sp *servicePlugin) OnJobAdd(job *batch.Job) error {
return err
}

// TODO: maybe add a flag
if err := sp.createNetworkPolicyIfNotExist(job); err != nil {
return err
if !sp.disableNetworkPolicy {
if err := sp.createNetworkPolicyIfNotExist(job); err != nil {
return err
}
}

job.Status.ControlledResources["plugin-"+sp.Name()] = sp.Name()
Expand Down
41 changes: 39 additions & 2 deletions test/e2e/job_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

var _ = Describe("Job E2E Test: Test Job Plugins", func() {
It("SVC Plugin with Node Affinity", func() {
It("Test SVC Plugin with Node Affinity", func() {
jobName := "job-with-svc-plugin"
namespace := "test"
taskName := "task"
Expand Down Expand Up @@ -105,7 +105,7 @@ var _ = Describe("Job E2E Test: Test Job Plugins", func() {
}
})

It("SSh Plugin with Pod Affinity", func() {
It("Test SSh Plugin with Pod Affinity", func() {
jobName := "job-with-ssh-plugin"
namespace := "test"
taskName := "task"
Expand Down Expand Up @@ -177,6 +177,43 @@ var _ = Describe("Job E2E Test: Test Job Plugins", func() {
}
})

It("Test SVC Plugin with disableNetworkPolicy", func() {
jobName := "svc-with-disable-network-policy"
namespace := "test"
taskName := "task"
context := initTestContext(options{})
defer cleanupTestContext(context)

_, rep := computeNode(context, oneCPU)
Expect(rep).NotTo(Equal(0))

job := createJob(context, &jobSpec{
namespace: namespace,
name: jobName,
plugins: map[string][]string{
"svc": {"--disable-network-policy=true"},
},
tasks: []taskSpec{
{
img: defaultNginxImage,
req: oneCPU,
min: 1,
rep: rep,
name: taskName,
},
},
})

err := waitJobReady(context, job)
Expect(err).NotTo(HaveOccurred())

// Check whether network policy is created with job name
networkPolicyName := fmt.Sprintf("%s", jobName)
_, err = context.kubeclient.NetworkingV1().NetworkPolicies(namespace).Get(networkPolicyName, v1.GetOptions{})
// Error will occur because there is no policy should be created
Expect(err).To(HaveOccurred())
})

It("Check Functionality of all plugins", func() {
jobName := "job-with-all-plugin"
namespace := "test"
Expand Down

0 comments on commit ed6b56b

Please sign in to comment.