-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from Rajadeepan/vkctlqueue
Moving vkctrl queue to Volcano from kube-batch
- Loading branch information
Showing
6 changed files
with
283 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2019 The Volcano Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"volcano.sh/volcano/pkg/cli/queue" | ||
) | ||
|
||
func buildQueueCmd() *cobra.Command { | ||
jobCmd := &cobra.Command{ | ||
Use: "queue", | ||
Short: "Queue Operations", | ||
} | ||
|
||
jobRunCmd := &cobra.Command{ | ||
Use: "create", | ||
Short: "creates queue", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
checkError(cmd, queue.CreateQueue()) | ||
}, | ||
} | ||
queue.InitRunFlags(jobRunCmd) | ||
jobCmd.AddCommand(jobRunCmd) | ||
|
||
queueListCmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "lists all the queue", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
checkError(cmd, queue.ListQueue()) | ||
}, | ||
} | ||
queue.InitListFlags(queueListCmd) | ||
jobCmd.AddCommand(queueListCmd) | ||
|
||
return jobCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright 2019 The Volcano Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package queue | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
type commonFlags struct { | ||
Master string | ||
Kubeconfig string | ||
SchedulerName string | ||
} | ||
|
||
func initFlags(cmd *cobra.Command, cf *commonFlags) { | ||
cmd.Flags().StringVarP(&cf.SchedulerName, "scheduler", "", "kube-batch", "the scheduler for this job") | ||
cmd.Flags().StringVarP(&cf.Master, "master", "s", "", "the address of apiserver") | ||
|
||
if home := homeDir(); home != "" { | ||
cmd.Flags().StringVarP(&cf.Kubeconfig, "kubeconfig", "", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file") | ||
} else { | ||
cmd.Flags().StringVarP(&cf.Kubeconfig, "kubeconfig", "", "", "(optional) absolute path to the kubeconfig file") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright 2019 The Volcano Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package queue | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
vkapi "github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1" | ||
"github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned" | ||
) | ||
|
||
type createFlags struct { | ||
commonFlags | ||
|
||
Name string | ||
Weight int32 | ||
} | ||
|
||
var createQueueFlags = &createFlags{} | ||
|
||
// InitRunFlags is used to init all run flags | ||
func InitRunFlags(cmd *cobra.Command) { | ||
initFlags(cmd, &createQueueFlags.commonFlags) | ||
|
||
cmd.Flags().StringVarP(&createQueueFlags.Name, "name", "n", "test", "the name of queue") | ||
cmd.Flags().Int32VarP(&createQueueFlags.Weight, "weight", "w", 1, "the weight of the queue") | ||
|
||
} | ||
|
||
// CreateQueue creates queue | ||
func CreateQueue() error { | ||
config, err := buildConfig(createQueueFlags.Master, createQueueFlags.Kubeconfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
queue := &vkapi.Queue{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: createQueueFlags.Name, | ||
}, | ||
Spec: vkapi.QueueSpec{ | ||
Weight: int32(createQueueFlags.Weight), | ||
}, | ||
} | ||
|
||
queueClient := versioned.NewForConfigOrDie(config) | ||
if _, err := queueClient.SchedulingV1alpha1().Queues().Create(queue); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
Copyright 2019 The Volcano Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package queue | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1" | ||
"github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type listFlags struct { | ||
commonFlags | ||
} | ||
|
||
const ( | ||
// Weight of the queue | ||
Weight string = "Weight" | ||
|
||
// Name of queue | ||
Name string = "Name" | ||
) | ||
|
||
var listQueueFlags = &listFlags{} | ||
|
||
// InitListFlags inits all flags | ||
func InitListFlags(cmd *cobra.Command) { | ||
initFlags(cmd, &listQueueFlags.commonFlags) | ||
} | ||
|
||
// ListQueue lists all the queue | ||
func ListQueue() error { | ||
config, err := buildConfig(listQueueFlags.Master, listQueueFlags.Kubeconfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
jobClient := versioned.NewForConfigOrDie(config) | ||
queues, err := jobClient.SchedulingV1alpha1().Queues().List(metav1.ListOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(queues.Items) == 0 { | ||
fmt.Printf("No resources found\n") | ||
return nil | ||
} | ||
PrintQueues(queues, os.Stdout) | ||
|
||
return nil | ||
} | ||
|
||
// PrintQueues prints queue information | ||
func PrintQueues(queues *v1alpha1.QueueList, writer io.Writer) { | ||
_, err := fmt.Fprintf(writer, "%-25s%-8s\n", | ||
Name, Weight) | ||
if err != nil { | ||
fmt.Printf("Failed to print queue command result: %s.\n", err) | ||
} | ||
for _, queue := range queues.Items { | ||
_, err = fmt.Fprintf(writer, "%-25s%-8d\n", | ||
queue.Name, queue.Spec.Weight) | ||
if err != nil { | ||
fmt.Printf("Failed to print queue command result: %s.\n", err) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright 2019 The Volcano Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package queue | ||
|
||
import ( | ||
"os" | ||
|
||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
func homeDir() string { | ||
if h := os.Getenv("HOME"); h != "" { | ||
return h | ||
} | ||
return os.Getenv("USERPROFILE") // windows | ||
} | ||
|
||
func buildConfig(master, kubeconfig string) (*rest.Config, error) { | ||
return clientcmd.BuildConfigFromFlags(master, kubeconfig) | ||
} |