From e303165d09918591d0d05b9d8800e931e7e34d42 Mon Sep 17 00:00:00 2001 From: Dong Beiqing <350758787@qq.com> Date: Fri, 19 Jan 2024 15:52:32 +0800 Subject: [PATCH] move ResourceRequirement to another file --- operator/v1/type_resourcerequirement.go | 36 +++++++++++++++++++++++++ operator/v1/types_klusterlet.go | 22 --------------- 2 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 operator/v1/type_resourcerequirement.go diff --git a/operator/v1/type_resourcerequirement.go b/operator/v1/type_resourcerequirement.go new file mode 100644 index 000000000..ad3e9e5eb --- /dev/null +++ b/operator/v1/type_resourcerequirement.go @@ -0,0 +1,36 @@ +package v1 + +import corev1 "k8s.io/api/core/v1" + +type ResourceRequirementRequire interface { + GetResourceRequirement() *ResourceRequirement +} + +// ResourceRequirement allow user override the default pod QoS classes +type ResourceRequirement struct { + // +kubebuilder:validation:Enum=Default;BestEffort;ResourceRequirement + // +kubebuilder:default:=Default + Type ResourceQosClass `json:"type"` + // ResourceRequirements defines resource requests and limits when Type is ResourceQosClassResourceRequirement + // +optional + ResourceRequirements *corev1.ResourceRequirements `json:"resourceRequirements,omitempty"` +} + +type ResourceQosClass string + +const ( + // Default use resource setting in the template file (with requests but no limits in the resources) + ResourceQosClassDefault ResourceQosClass = "Default" + // If all containers in the pod don't set resource request and limits, the pod is treated as BestEffort. + ResourceQosClassBestEffort ResourceQosClass = "BestEffort" + // Configurable resource requirements with requests and limits + ResourceQosClassResourceRequirement ResourceQosClass = "ResourceRequirement" +) + +func (k *Klusterlet) GetResourceRequirement() *ResourceRequirement { + return k.Spec.ResourceRequirement +} + +func (cm *ClusterManager) GetResourceRequirement() *ResourceRequirement { + return cm.Spec.ResourceRequirement +} diff --git a/operator/v1/types_klusterlet.go b/operator/v1/types_klusterlet.go index 28bf07c04..bef65984f 100644 --- a/operator/v1/types_klusterlet.go +++ b/operator/v1/types_klusterlet.go @@ -1,7 +1,6 @@ package v1 import ( - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -96,27 +95,6 @@ type KlusterletSpec struct { ResourceRequirement *ResourceRequirement `json:"resourceRequirement,omitempty"` } -type ResourceQosClass string - -const ( - // Default use resource setting in the template file (with requests but no limits in the resources) - ResourceQosClassDefault ResourceQosClass = "Default" - // If all containers in the pod don't set resource request and limits, the pod is treated as BestEffort. - ResourceQosClassBestEffort ResourceQosClass = "BestEffort" - // Configurable resource requirements with requests and limits - ResourceQosClassResourceRequirement ResourceQosClass = "ResourceRequirement" -) - -// ResourceRequirement allow user override the default pod QoS classes -type ResourceRequirement struct { - // +kubebuilder:validation:Enum=Default;BestEffort;ResourceRequirement - // +kubebuilder:default:=Default - Type ResourceQosClass `json:"type"` - // ResourceRequirements defines resource requests and limits when Type is ResourceQosClassResourceRequirement - // +optional - ResourceRequirements *corev1.ResourceRequirements `json:"resourceRequirements,omitempty"` -} - // ServerURL represents the apiserver url and ca bundle that is accessible externally type ServerURL struct { // URL is the url of apiserver endpoint of the managed cluster.