sigs.k8s.io/kueue@v0.6.2/pkg/queue/dumper.go (about)

     1  /*
     2  Copyright 2023 The Kubernetes 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  	"github.com/go-logr/logr"
    21  	"k8s.io/klog/v2"
    22  )
    23  
    24  // LogDump dumps the pending and inadmissible workloads for each ClusterQueue into the log,
    25  // one line per ClusterQueue.
    26  func (m *Manager) LogDump(log logr.Logger) {
    27  	m.Lock()
    28  	defer m.Unlock()
    29  	for name, cq := range m.clusterQueues {
    30  		pending, _ := cq.Dump()
    31  		inadmissible, _ := cq.DumpInadmissible()
    32  		log.Info("Found pending and inadmissible workloads in ClusterQueue",
    33  			"clusterQueue", klog.KRef("", name),
    34  			"pending", pending,
    35  			"inadmissible", inadmissible)
    36  	}
    37  }
    38  
    39  // Dump is a dump of the queues and it's elements (unordered).
    40  // Only use for testing purposes.
    41  func (m *Manager) Dump() map[string][]string {
    42  	m.Lock()
    43  	defer m.Unlock()
    44  	if len(m.clusterQueues) == 0 {
    45  		return nil
    46  	}
    47  	dump := make(map[string][]string, len(m.clusterQueues))
    48  	for key, cq := range m.clusterQueues {
    49  		if elements, ok := cq.Dump(); ok {
    50  			dump[key] = elements
    51  		}
    52  	}
    53  	if len(dump) == 0 {
    54  		return nil
    55  	}
    56  	return dump
    57  }
    58  
    59  // DumpInadmissible is a dump of the inadmissible workloads list.
    60  // Only use for testing purposes.
    61  func (m *Manager) DumpInadmissible() map[string][]string {
    62  	m.Lock()
    63  	defer m.Unlock()
    64  	if len(m.clusterQueues) == 0 {
    65  		return nil
    66  	}
    67  	dump := make(map[string][]string, len(m.clusterQueues))
    68  	for key, cq := range m.clusterQueues {
    69  		if elements, ok := cq.DumpInadmissible(); ok {
    70  			dump[key] = elements
    71  		}
    72  	}
    73  	if len(dump) == 0 {
    74  		return nil
    75  	}
    76  	return dump
    77  }