volcano.sh/volcano@v1.9.0/pkg/cli/queue/util.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 "os" 23 "strings" 24 25 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 // Initialize client auth plugin. 27 _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" 28 "k8s.io/client-go/rest" 29 "k8s.io/client-go/tools/clientcmd" 30 31 busv1alpha1 "volcano.sh/apis/pkg/apis/bus/v1alpha1" 32 "volcano.sh/apis/pkg/apis/helpers" 33 "volcano.sh/apis/pkg/client/clientset/versioned" 34 ) 35 36 func homeDir() string { 37 if h := os.Getenv("HOME"); h != "" { 38 return h 39 } 40 return os.Getenv("USERPROFILE") // windows 41 } 42 43 func buildConfig(master, kubeconfig string) (*rest.Config, error) { 44 return clientcmd.BuildConfigFromFlags(master, kubeconfig) 45 } 46 47 func createQueueCommand(config *rest.Config, action busv1alpha1.Action) error { 48 queueClient := versioned.NewForConfigOrDie(config) 49 queue, err := queueClient.SchedulingV1beta1().Queues().Get(context.TODO(), operateQueueFlags.Name, metav1.GetOptions{}) 50 if err != nil { 51 return err 52 } 53 54 ctrlRef := metav1.NewControllerRef(queue, helpers.V1beta1QueueKind) 55 cmd := &busv1alpha1.Command{ 56 ObjectMeta: metav1.ObjectMeta{ 57 GenerateName: fmt.Sprintf("%s-%s-", 58 queue.Name, strings.ToLower(string(action))), 59 OwnerReferences: []metav1.OwnerReference{ 60 *ctrlRef, 61 }, 62 }, 63 TargetObject: ctrlRef, 64 Action: string(action), 65 } 66 67 if _, err := queueClient.BusV1alpha1().Commands("default").Create(context.TODO(), cmd, metav1.CreateOptions{}); err != nil { 68 return err 69 } 70 71 return nil 72 }