volcano.sh/volcano@v1.9.0/pkg/controllers/queue/state/closing.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 state
    18  
    19  import (
    20  	"volcano.sh/apis/pkg/apis/bus/v1alpha1"
    21  	"volcano.sh/apis/pkg/apis/scheduling/v1beta1"
    22  )
    23  
    24  type closingState struct {
    25  	queue *v1beta1.Queue
    26  }
    27  
    28  func (cs *closingState) Execute(action v1alpha1.Action) error {
    29  	switch action {
    30  	case v1alpha1.OpenQueueAction:
    31  		return OpenQueue(cs.queue, func(status *v1beta1.QueueStatus, podGroupList []string) {
    32  			status.State = v1beta1.QueueStateOpen
    33  		})
    34  	case v1alpha1.CloseQueueAction:
    35  		return SyncQueue(cs.queue, func(status *v1beta1.QueueStatus, podGroupList []string) {
    36  			if len(podGroupList) == 0 {
    37  				status.State = v1beta1.QueueStateClosed
    38  				return
    39  			}
    40  			status.State = v1beta1.QueueStateClosing
    41  		})
    42  	default:
    43  		return SyncQueue(cs.queue, func(status *v1beta1.QueueStatus, podGroupList []string) {
    44  			specState := cs.queue.Status.State
    45  			if specState == v1beta1.QueueStateOpen {
    46  				status.State = v1beta1.QueueStateOpen
    47  				return
    48  			}
    49  
    50  			if specState == v1beta1.QueueStateClosing {
    51  				if len(podGroupList) == 0 {
    52  					status.State = v1beta1.QueueStateClosed
    53  					return
    54  				}
    55  
    56  				status.State = v1beta1.QueueStateClosing
    57  				return
    58  			}
    59  
    60  			status.State = v1beta1.QueueStateUnknown
    61  		})
    62  	}
    63  }