volcano.sh/volcano@v1.9.0/pkg/cli/job/suspend.go (about)

     1  /*
     2  Copyright 2018 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 job
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"github.com/spf13/cobra"
    23  
    24  	"volcano.sh/apis/pkg/apis/bus/v1alpha1"
    25  	"volcano.sh/volcano/pkg/cli/util"
    26  )
    27  
    28  type suspendFlags struct {
    29  	commonFlags
    30  
    31  	Namespace string
    32  	JobName   string
    33  }
    34  
    35  var suspendJobFlags = &suspendFlags{}
    36  
    37  // InitSuspendFlags init suspend related flags.
    38  func InitSuspendFlags(cmd *cobra.Command) {
    39  	initFlags(cmd, &suspendJobFlags.commonFlags)
    40  
    41  	cmd.Flags().StringVarP(&suspendJobFlags.Namespace, "namespace", "n", "default", "the namespace of job")
    42  	cmd.Flags().StringVarP(&suspendJobFlags.JobName, "name", "N", "", "the name of job")
    43  }
    44  
    45  // SuspendJob suspends the job.
    46  func SuspendJob() error {
    47  	config, err := util.BuildConfig(suspendJobFlags.Master, suspendJobFlags.Kubeconfig)
    48  	if err != nil {
    49  		return err
    50  	}
    51  
    52  	if suspendJobFlags.JobName == "" {
    53  		err := fmt.Errorf("job name is mandatory to suspend a particular job")
    54  		return err
    55  	}
    56  
    57  	return createJobCommand(config,
    58  		suspendJobFlags.Namespace, suspendJobFlags.JobName,
    59  		v1alpha1.AbortJobAction)
    60  }