Skip to content

Commit

Permalink
Merge pull request #511 from wangyuqing4/cleanup
Browse files Browse the repository at this point in the history
Umbrealla cleanups
  • Loading branch information
volcano-sh-bot authored Nov 7, 2019
2 parents 2d80438 + b9ea002 commit 8c29a3e
Show file tree
Hide file tree
Showing 53 changed files with 548 additions and 563 deletions.
3 changes: 0 additions & 3 deletions installer/helm/chart/volcano/templates/scheduler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ rules:
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["list", "watch"]
- apiGroups: ["scheduling.incubator.k8s.io", "scheduling.sigs.dev"]
resources: ["podgroups"]
verbs: ["list", "watch", "update"]
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["list", "watch"]
Expand Down
3 changes: 0 additions & 3 deletions installer/volcano-development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ rules:
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["list", "watch"]
- apiGroups: ["scheduling.incubator.k8s.io", "scheduling.sigs.dev"]
resources: ["podgroups"]
verbs: ["list", "watch", "update"]
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["list", "watch"]
Expand Down
2 changes: 1 addition & 1 deletion pkg/admission/admission_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/util/validation/field"

"k8s.io/kubernetes/pkg/apis/core/validation"

batchv1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
vcclientset "volcano.sh/volcano/pkg/client/clientset/versioned"
)
Expand Down
15 changes: 7 additions & 8 deletions pkg/apis/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ import (
"k8s.io/apiserver/pkg/server/mux"
"k8s.io/client-go/kubernetes"

vkbatchv1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
vkv1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
vkcorev1 "volcano.sh/volcano/pkg/apis/bus/v1alpha1"
vcbatch "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
vcbus "volcano.sh/volcano/pkg/apis/bus/v1alpha1"
)

// JobKind creates job GroupVersionKind
var JobKind = vkbatchv1.SchemeGroupVersion.WithKind("Job")
var JobKind = vcbatch.SchemeGroupVersion.WithKind("Job")

// CommandKind creates command GroupVersionKind
var CommandKind = vkcorev1.SchemeGroupVersion.WithKind("Command")
var CommandKind = vcbus.SchemeGroupVersion.WithKind("Command")

// GetController returns the controller uid
func GetController(obj interface{}) types.UID {
Expand Down Expand Up @@ -81,7 +80,7 @@ func ControlledBy(obj interface{}, gvk schema.GroupVersionKind) bool {
}

// CreateConfigMapIfNotExist creates config map resource if not present
func CreateConfigMapIfNotExist(job *vkv1.Job, kubeClients kubernetes.Interface, data map[string]string, cmName string) error {
func CreateConfigMapIfNotExist(job *vcbatch.Job, kubeClients kubernetes.Interface, data map[string]string, cmName string) error {
// If ConfigMap does not exist, create one for Job.
cmOld, err := kubeClients.CoreV1().ConfigMaps(job.Namespace).Get(cmName, metav1.GetOptions{})
if err != nil {
Expand Down Expand Up @@ -121,7 +120,7 @@ func CreateConfigMapIfNotExist(job *vkv1.Job, kubeClients kubernetes.Interface,
}

// DeleteConfigmap deletes the config map resource
func DeleteConfigmap(job *vkv1.Job, kubeClients kubernetes.Interface, cmName string) error {
func DeleteConfigmap(job *vcbatch.Job, kubeClients kubernetes.Interface, cmName string) error {
if _, err := kubeClients.CoreV1().ConfigMaps(job.Namespace).Get(cmName, metav1.GetOptions{}); err != nil {
if !apierrors.IsNotFound(err) {
glog.V(3).Infof("Failed to get Configmap for Job <%s/%s>: %v",
Expand All @@ -145,7 +144,7 @@ func DeleteConfigmap(job *vkv1.Job, kubeClients kubernetes.Interface, cmName str

// GeneratePodgroupName generate podgroup name of normal pod
func GeneratePodgroupName(pod *v1.Pod) string {
pgName := vkbatchv1.PodgroupNamePrefix
pgName := vcbatch.PodgroupNamePrefix

if len(pod.OwnerReferences) != 0 {
for _, ownerReference := range pod.OwnerReferences {
Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/job/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package job

import (
"encoding/json"
"github.com/spf13/cobra"
"net/http"
"net/http/httptest"
"testing"

"github.com/spf13/cobra"

"volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/job/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package job

import (
"encoding/json"
"github.com/spf13/cobra"
"net/http"
"net/http/httptest"
"testing"

"github.com/spf13/cobra"

v1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/job/resume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ package job

import (
"encoding/json"
"github.com/spf13/cobra"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/spf13/cobra"

v1alpha1batch "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
v1alpha1 "volcano.sh/volcano/pkg/apis/bus/v1alpha1"
)
Expand Down
14 changes: 7 additions & 7 deletions pkg/cli/job/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"

vkapi "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
vcbatch "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
"volcano.sh/volcano/pkg/client/clientset/versioned"
)

Expand Down Expand Up @@ -93,7 +93,7 @@ func RunJob() error {
return nil
}

func readFile(filename string) (*vkapi.Job, error) {
func readFile(filename string) (*vcbatch.Job, error) {
if filename == "" {
return nil, nil
}
Expand All @@ -107,24 +107,24 @@ func readFile(filename string) (*vkapi.Job, error) {
return nil, fmt.Errorf("failed to read file, err: %v", err)
}

var job vkapi.Job
var job vcbatch.Job
if err := yaml.Unmarshal(file, &job); err != nil {
return nil, fmt.Errorf("Failed to unmarshal file, err: %v", err)
}

return &job, nil
}

func constructLaunchJobFlagsJob(launchJobFlags *runFlags, req, limit v1.ResourceList) *vkapi.Job {
return &vkapi.Job{
func constructLaunchJobFlagsJob(launchJobFlags *runFlags, req, limit v1.ResourceList) *vcbatch.Job {
return &vcbatch.Job{
ObjectMeta: metav1.ObjectMeta{
Name: launchJobFlags.Name,
Namespace: launchJobFlags.Namespace,
},
Spec: vkapi.JobSpec{
Spec: vcbatch.JobSpec{
MinAvailable: int32(launchJobFlags.MinAvailable),
SchedulerName: launchJobFlags.SchedulerName,
Tasks: []vkapi.TaskSpec{
Tasks: []vcbatch.TaskSpec{
{
Replicas: int32(launchJobFlags.Replicas),

Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/job/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ package job

import (
"encoding/json"
"github.com/spf13/cobra"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"

"github.com/spf13/cobra"

v1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

Expand Down
1 change: 1 addition & 0 deletions pkg/cli/job/suspend.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package job

import (
"fmt"

"github.com/spf13/cobra"

"volcano.sh/volcano/pkg/apis/batch/v1alpha1"
Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/job/suspend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ package job

import (
"encoding/json"
"github.com/spf13/cobra"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/spf13/cobra"

v1alpha1batch "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
v1alpha1 "volcano.sh/volcano/pkg/apis/bus/v1alpha1"
)
Expand Down
8 changes: 4 additions & 4 deletions pkg/cli/job/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

vkbatchv1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
vkbusv1 "volcano.sh/volcano/pkg/apis/bus/v1alpha1"
vcbatch "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
vcbus "volcano.sh/volcano/pkg/apis/bus/v1alpha1"
"volcano.sh/volcano/pkg/apis/helpers"
"volcano.sh/volcano/pkg/client/clientset/versioned"
)
Expand Down Expand Up @@ -71,15 +71,15 @@ func populateResourceListV1(spec string) (v1.ResourceList, error) {
return result, nil
}

func createJobCommand(config *rest.Config, ns, name string, action vkbatchv1.Action) error {
func createJobCommand(config *rest.Config, ns, name string, action vcbatch.Action) error {
jobClient := versioned.NewForConfigOrDie(config)
job, err := jobClient.BatchV1alpha1().Jobs(ns).Get(name, metav1.GetOptions{})
if err != nil {
return err
}

ctrlRef := metav1.NewControllerRef(job, helpers.JobKind)
cmd := &vkbusv1.Command{
cmd := &vcbus.Command{
ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("%s-%s-",
job.Name, strings.ToLower(string(action))),
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/job/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

Expand Down
1 change: 1 addition & 0 deletions pkg/cli/queue/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/spf13/cobra"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"volcano.sh/volcano/pkg/apis/scheduling/v1alpha2"
"volcano.sh/volcano/pkg/client/clientset/versioned"
)
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/queue/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/spf13/cobra"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"volcano.sh/volcano/pkg/apis/scheduling/v1alpha2"
"volcano.sh/volcano/pkg/client/clientset/versioned"
)
Expand Down
6 changes: 4 additions & 2 deletions pkg/cli/queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import (
"net/http"
"net/http/httptest"
"testing"
"volcano.sh/volcano/pkg/apis/scheduling/v1alpha1"
"volcano.sh/volcano/pkg/apis/scheduling/v1alpha2"

"github.com/spf13/cobra"

"k8s.io/apimachinery/pkg/apis/meta/v1"

"volcano.sh/volcano/pkg/apis/scheduling/v1alpha1"
"volcano.sh/volcano/pkg/apis/scheduling/v1alpha2"
)

func getTestQueueHTTPServer(t *testing.T) *httptest.Server {
Expand Down
35 changes: 18 additions & 17 deletions pkg/controllers/apis/job_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
batch "volcano.sh/volcano/pkg/apis/batch/v1alpha1"

vcbatchv1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

func TestAddPod(t *testing.T) {
Expand All @@ -45,9 +46,9 @@ func TestAddPod(t *testing.T) {
Name: name,
Namespace: namespace,
Labels: nil,
Annotations: map[string]string{batch.JobNameKey: "job1",
batch.JobVersion: "0",
batch.TaskSpecKey: "task1"},
Annotations: map[string]string{vcbatchv1.JobNameKey: "job1",
vcbatchv1.JobVersion: "0",
vcbatchv1.TaskSpecKey: "task1"},
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
Expand Down Expand Up @@ -106,9 +107,9 @@ func TestDeletePod(t *testing.T) {
Name: name,
Namespace: namespace,
Labels: nil,
Annotations: map[string]string{batch.JobNameKey: "job1",
batch.JobVersion: "0",
batch.TaskSpecKey: "task1"},
Annotations: map[string]string{vcbatchv1.JobNameKey: "job1",
vcbatchv1.JobVersion: "0",
vcbatchv1.TaskSpecKey: "task1"},
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
Expand Down Expand Up @@ -163,9 +164,9 @@ func TestUpdatePod(t *testing.T) {
Name: name,
Namespace: namespace,
Labels: nil,
Annotations: map[string]string{batch.JobNameKey: "job1",
batch.JobVersion: "0",
batch.TaskSpecKey: "task1"},
Annotations: map[string]string{vcbatchv1.JobNameKey: "job1",
vcbatchv1.JobVersion: "0",
vcbatchv1.TaskSpecKey: "task1"},
},
Status: v1.PodStatus{
Phase: v1.PodRunning,
Expand All @@ -185,9 +186,9 @@ func TestUpdatePod(t *testing.T) {
Name: name,
Namespace: namespace,
Labels: nil,
Annotations: map[string]string{batch.JobNameKey: "job1",
batch.JobVersion: "0",
batch.TaskSpecKey: "task1"},
Annotations: map[string]string{vcbatchv1.JobNameKey: "job1",
vcbatchv1.JobVersion: "0",
vcbatchv1.TaskSpecKey: "task1"},
},
Status: v1.PodStatus{
Phase: v1.PodSucceeded,
Expand Down Expand Up @@ -255,7 +256,7 @@ func TestSetJob(t *testing.T) {

testCases := []struct {
Name string
job batch.Job
job vcbatchv1.Job
jobinfo JobInfo

ExpectValue v1.PodPhase
Expand All @@ -266,7 +267,7 @@ func TestSetJob(t *testing.T) {
Name: "testjobInfo",
Pods: make(map[string]map[string]*v1.Pod),
},
job: batch.Job{
job: vcbatchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: "testjob",
},
Expand Down Expand Up @@ -295,9 +296,9 @@ func TestRequest_String(t *testing.T) {
Namespace: "testnamespace",
JobName: "testjobname",
TaskName: "testtaskname",
Event: batch.AnyEvent,
Event: vcbatchv1.AnyEvent,
ExitCode: 0,
Action: batch.SyncJobAction,
Action: vcbatchv1.SyncJobAction,
JobVersion: 0,
},
ExpectedValue: "Job: testnamespace/testjobname, Task:testtaskname, Event:*, ExitCode:0, Action:SyncJob, JobVersion: 0",
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/job/job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type Controller struct {
// NewJobController create new Job Controller
func NewJobController(
kubeClient kubernetes.Interface,
vkClient vcclientset.Interface,
vcClient vcclientset.Interface,
sharedInformers informers.SharedInformerFactory,
workers uint32,
) *Controller {
Expand All @@ -130,7 +130,7 @@ func NewJobController(

cc := &Controller{
kubeClient: kubeClient,
vcClient: vkClient,
vcClient: vcClient,
queueList: make([]workqueue.RateLimitingInterface, workers, workers),
commandQueue: workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()),
cache: jobcache.New(),
Expand Down
Loading

0 comments on commit 8c29a3e

Please sign in to comment.