volcano.sh/volcano@v1.9.0/pkg/cli/queue/get.go (about) 1 /* 2 Copyright 2019 The Volcano Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package queue 18 19 import ( 20 "context" 21 "fmt" 22 "io" 23 "os" 24 25 "github.com/spf13/cobra" 26 27 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 28 29 "volcano.sh/apis/pkg/apis/scheduling/v1beta1" 30 "volcano.sh/apis/pkg/client/clientset/versioned" 31 ) 32 33 type getFlags struct { 34 commonFlags 35 36 Name string 37 } 38 39 var getQueueFlags = &getFlags{} 40 41 // InitGetFlags is used to init all flags. 42 func InitGetFlags(cmd *cobra.Command) { 43 initFlags(cmd, &getQueueFlags.commonFlags) 44 45 cmd.Flags().StringVarP(&getQueueFlags.Name, "name", "n", "", "the name of queue") 46 } 47 48 // GetQueue gets a queue. 49 func GetQueue() error { 50 config, err := buildConfig(getQueueFlags.Master, getQueueFlags.Kubeconfig) 51 if err != nil { 52 return err 53 } 54 55 if getQueueFlags.Name == "" { 56 err := fmt.Errorf("name is mandatory to get the particular queue details") 57 return err 58 } 59 60 queueClient := versioned.NewForConfigOrDie(config) 61 queue, err := queueClient.SchedulingV1beta1().Queues().Get(context.TODO(), getQueueFlags.Name, metav1.GetOptions{}) 62 if err != nil { 63 return err 64 } 65 66 PrintQueue(queue, os.Stdout) 67 68 return nil 69 } 70 71 // PrintQueue prints queue information. 72 func PrintQueue(queue *v1beta1.Queue, writer io.Writer) { 73 _, err := fmt.Fprintf(writer, "%-25s%-8s%-8s%-8s%-8s%-8s%-8s\n", 74 Name, Weight, State, Inqueue, Pending, Running, Unknown) 75 if err != nil { 76 fmt.Printf("Failed to print queue command result: %s.\n", err) 77 } 78 _, err = fmt.Fprintf(writer, "%-25s%-8d%-8s%-8d%-8d%-8d%-8d\n", 79 queue.Name, queue.Spec.Weight, queue.Status.State, queue.Status.Inqueue, 80 queue.Status.Pending, queue.Status.Running, queue.Status.Unknown) 81 if err != nil { 82 fmt.Printf("Failed to print queue command result: %s.\n", err) 83 } 84 }