diff --git a/api/v1alpha1/cluster_types.go b/api/v1alpha1/cluster_types.go index d3e73bcb..08259d84 100644 --- a/api/v1alpha1/cluster_types.go +++ b/api/v1alpha1/cluster_types.go @@ -93,16 +93,46 @@ type MessageBus struct { ETOSMessageBus RabbitMQ `json:"logs"` } -// Etcd describes the deployment of an ETCD database. +// Etcd describes the deployment of an ETCD database. Ignored if Deploy is set to false. type Etcd struct { - // Parameter is ignored if Deploy is set to true. + // Host specifies the ETCD server hostname. // +kubebuilder:default="etcd-client" // +optional Host string `json:"host"` - // Parameter is ignored if Deploy is set to true. + // Port specifies the ETCD port number. // +kubebuilder:default="2379" // +optional Port string `json:"port"` + // Resources describes compute resource requirements per etcd pod which are three in a cluster. + // +kubebuilder:default={"limits": {"cpu": "300m", "memory": "768Mi"}, "requests": {"cpu": "300m", "memory": "768Mi"}} + // +optional + Resources EtcdResources `json:"resources"` +} + +// EtcdResources describes compute resource requirements for Etcd. +type EtcdResources struct { + // Limits describes the maximum amount of compute resources allowed. + // +kubebuilder:default={"cpu": "300m", "memory": "768Mi"} + // +optional + Limits EtcdResourceList `json:"limits"` + + // Requests describes the minimum amount of compute resources required. + // +kubebuilder:default={"cpu": "300m", "memory": "768Mi"} + // +optional + Requests EtcdResourceList `json:"requests"` +} + +// EtcdResourceList describes CPU and memory resources. +type EtcdResourceList struct { + // CPU resource. + // +kubebuilder:default="300m" + // +optional + CPU string `json:"cpu"` + + // Memory resource. + // +kubebuilder:default="768Mi" + // +optional + Memory string `json:"memory"` } // Database describes the deployment of a database for ETOS. diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 7bd3f571..15bbfbcf 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -647,6 +647,7 @@ func (in *EnvironmentStatus) DeepCopy() *EnvironmentStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Etcd) DeepCopyInto(out *Etcd) { *out = *in + out.Resources = in.Resources } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Etcd. @@ -659,6 +660,38 @@ func (in *Etcd) DeepCopy() *Etcd { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *EtcdResourceList) DeepCopyInto(out *EtcdResourceList) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EtcdResourceList. +func (in *EtcdResourceList) DeepCopy() *EtcdResourceList { + if in == nil { + return nil + } + out := new(EtcdResourceList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *EtcdResources) DeepCopyInto(out *EtcdResources) { + *out = *in + out.Limits = in.Limits + out.Requests = in.Requests +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EtcdResources. +func (in *EtcdResources) DeepCopy() *EtcdResources { + if in == nil { + return nil + } + out := new(EtcdResources) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *EventRepository) DeepCopyInto(out *EventRepository) { *out = *in diff --git a/config/crd/bases/etos.eiffel-community.github.io_clusters.yaml b/config/crd/bases/etos.eiffel-community.github.io_clusters.yaml index 2a755e94..ab84bb32 100644 --- a/config/crd/bases/etos.eiffel-community.github.io_clusters.yaml +++ b/config/crd/bases/etos.eiffel-community.github.io_clusters.yaml @@ -56,15 +56,60 @@ spec: etcd: default: {} description: Etcd describes the deployment of an ETCD database. + Ignored if Deploy is set to false. properties: host: default: etcd-client - description: Parameter is ignored if Deploy is set to true. + description: Host specifies the ETCD server hostname. type: string port: default: "2379" - description: Parameter is ignored if Deploy is set to true. + description: Port specifies the ETCD port number. type: string + resources: + default: + limits: + cpu: 300m + memory: 768Mi + requests: + cpu: 300m + memory: 768Mi + description: Resources describes compute resource requirements + per etcd pod which are three in a cluster. + properties: + limits: + default: + cpu: 300m + memory: 768Mi + description: Limits describes the maximum amount of compute + resources allowed. + properties: + cpu: + default: 300m + description: CPU resource. + type: string + memory: + default: 768Mi + description: Memory resource. + type: string + type: object + requests: + default: + cpu: 300m + memory: 768Mi + description: Requests describes the minimum amount of + compute resources required. + properties: + cpu: + default: 300m + description: CPU resource. + type: string + memory: + default: 768Mi + description: Memory resource. + type: string + type: object + type: object type: object type: object etos: diff --git a/internal/etos/database.go b/internal/etos/database.go index 85e389ad..362ed5ae 100644 --- a/internal/etos/database.go +++ b/internal/etos/database.go @@ -154,6 +154,7 @@ func (r *ETCDDeployment) reconcileClientService(ctx context.Context, name types. // statefulset creates a statefulset resource definition for ETCD. func (r *ETCDDeployment) statefulset(name types.NamespacedName) *appsv1.StatefulSet { + return &appsv1.StatefulSet{ ObjectMeta: r.meta(name), Spec: appsv1.StatefulSetSpec{ @@ -264,12 +265,12 @@ func (r *ETCDDeployment) container(name types.NamespacedName) corev1.Container { Image: "quay.io/coreos/etcd:v3.5.19", Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ - corev1.ResourceMemory: resource.MustParse("512Mi"), - corev1.ResourceCPU: resource.MustParse("200m"), + corev1.ResourceMemory: resource.MustParse(r.Etcd.Resources.Limits.Memory), + corev1.ResourceCPU: resource.MustParse(r.Etcd.Resources.Limits.CPU), }, Requests: corev1.ResourceList{ - corev1.ResourceMemory: resource.MustParse("512Mi"), - corev1.ResourceCPU: resource.MustParse("200m"), + corev1.ResourceMemory: resource.MustParse(r.Etcd.Resources.Requests.Memory), + corev1.ResourceCPU: resource.MustParse(r.Etcd.Resources.Requests.CPU), }, }, VolumeMounts: []corev1.VolumeMount{