volcano.sh/volcano@v1.9.0/pkg/scheduler/api/namespace_info.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 api 18 19 import ( 20 v1 "k8s.io/api/core/v1" 21 ) 22 23 // NamespaceName is name of namespace 24 type NamespaceName string 25 26 // NamespaceInfo records information of namespace 27 type NamespaceInfo struct { 28 // Name is the name of this namespace 29 Name NamespaceName 30 // QuotaStatus stores the ResourceQuotaStatus of all ResourceQuotas in this namespace 31 QuotaStatus map[string]v1.ResourceQuotaStatus 32 } 33 34 // NamespaceCollection will record all details about namespace 35 type NamespaceCollection struct { 36 Name string 37 QuotaStatus map[string]v1.ResourceQuotaStatus 38 } 39 40 // NewNamespaceCollection creates new NamespaceCollection object to record all information about a namespace 41 func NewNamespaceCollection(name string) *NamespaceCollection { 42 n := &NamespaceCollection{ 43 Name: name, 44 QuotaStatus: make(map[string]v1.ResourceQuotaStatus), 45 } 46 return n 47 } 48 49 // Update modify the registered information according quota object 50 func (n *NamespaceCollection) Update(quota *v1.ResourceQuota) { 51 n.QuotaStatus[quota.Name] = quota.Status 52 } 53 54 // Delete remove the registered information according quota object 55 func (n *NamespaceCollection) Delete(quota *v1.ResourceQuota) { 56 delete(n.QuotaStatus, quota.Name) 57 } 58 59 // Snapshot will clone a NamespaceInfo without Heap according NamespaceCollection 60 func (n *NamespaceCollection) Snapshot() *NamespaceInfo { 61 return &NamespaceInfo{ 62 Name: NamespaceName(n.Name), 63 QuotaStatus: n.QuotaStatus, 64 } 65 }