kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/quota/v1alpha2/types.go (about)

     1  /*
     2  Copyright 2020 The KubeSphere 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 v1alpha2
    18  
    19  import (
    20  	corev1 "k8s.io/api/core/v1"
    21  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    22  )
    23  
    24  const (
    25  	ResourceKindCluster      = "ResourceQuota"
    26  	ResourcesSingularCluster = "resourcequota"
    27  	ResourcesPluralCluster   = "resourcequotas"
    28  )
    29  
    30  func init() {
    31  	SchemeBuilder.Register(&ResourceQuota{}, &ResourceQuotaList{})
    32  }
    33  
    34  // +genclient
    35  // +genclient:nonNamespaced
    36  // +kubebuilder:object:root=true
    37  // +k8s:openapi-gen=true
    38  // +kubebuilder:object:root=true
    39  // +kubebuilder:resource:categories="quota",scope="Cluster",path=resourcequotas
    40  // +kubebuilder:subresource:status
    41  // +kubebuilder:object:root=true
    42  // WorkspaceResourceQuota sets aggregate quota restrictions enforced per workspace
    43  type ResourceQuota struct {
    44  	metav1.TypeMeta `json:",inline"`
    45  	// +optional
    46  	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    47  
    48  	// Spec defines the desired quota
    49  	Spec ResourceQuotaSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
    50  
    51  	// Status defines the actual enforced quota and its current usage
    52  	// +optional
    53  	Status ResourceQuotaStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
    54  }
    55  
    56  // ResourceQuotaSpec defines the desired quota restrictions
    57  type ResourceQuotaSpec struct {
    58  	// LabelSelector is used to select projects by label.
    59  	LabelSelector map[string]string `json:"selector" protobuf:"bytes,1,opt,name=selector"`
    60  
    61  	// Quota defines the desired quota
    62  	Quota corev1.ResourceQuotaSpec `json:"quota" protobuf:"bytes,2,opt,name=quota"`
    63  }
    64  
    65  // ResourceQuotaStatus defines the actual enforced quota and its current usage
    66  type ResourceQuotaStatus struct {
    67  	// Total defines the actual enforced quota and its current usage across all projects
    68  	Total corev1.ResourceQuotaStatus `json:"total" protobuf:"bytes,1,opt,name=total"`
    69  
    70  	// Namespaces slices the usage by project.
    71  	Namespaces ResourceQuotasStatusByNamespace `json:"namespaces" protobuf:"bytes,2,rep,name=namespaces"`
    72  }
    73  
    74  // ResourceQuotasStatusByNamespace bundles multiple ResourceQuotaStatusByNamespace
    75  type ResourceQuotasStatusByNamespace []ResourceQuotaStatusByNamespace
    76  
    77  // ResourceQuotaStatusByNamespace gives status for a particular project
    78  type ResourceQuotaStatusByNamespace struct {
    79  	corev1.ResourceQuotaStatus `json:",inline"`
    80  
    81  	// Namespace the project this status applies to
    82  	Namespace string `json:"namespace" protobuf:"bytes,1,opt,name=namespace"`
    83  }
    84  
    85  // +kubebuilder:object:root=true
    86  // +kubebuilder:object:root=true
    87  // ResourceQuotaList is a list of WorkspaceResourceQuota items.
    88  type ResourceQuotaList struct {
    89  	metav1.TypeMeta `json:",inline"`
    90  	// Standard list metadata.
    91  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
    92  	// +optional
    93  	metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    94  
    95  	// Items is a list of WorkspaceResourceQuota objects.
    96  	// More info: https://kubernetes.io/docs/concepts/policy/resource-quotas/
    97  	Items []ResourceQuota `json:"items" protobuf:"bytes,2,rep,name=items"`
    98  }