From d5d7befcfd659566cd5214c961aca95b79a5ab69 Mon Sep 17 00:00:00 2001 From: "wangzhe.21" Date: Fri, 12 Jul 2024 11:16:04 +0800 Subject: [PATCH] feat(overcommit): add TimeBounds for cron overcommit --- ...st.kubewharf.io_nodeovercommitconfigs.yaml | 48 +++++++++++++ pkg/apis/overcommit/v1alpha1/types.go | 36 ++++++++++ .../v1alpha1/zz_generated.deepcopy.go | 70 +++++++++++++++++++ 3 files changed, 154 insertions(+) diff --git a/config/crd/bases/overcommit.katalyst.kubewharf.io_nodeovercommitconfigs.yaml b/config/crd/bases/overcommit.katalyst.kubewharf.io_nodeovercommitconfigs.yaml index 1a4e26a..67f8f74 100644 --- a/config/crd/bases/overcommit.katalyst.kubewharf.io_nodeovercommitconfigs.yaml +++ b/config/crd/bases/overcommit.katalyst.kubewharf.io_nodeovercommitconfigs.yaml @@ -45,6 +45,16 @@ spec: spec: description: NodeOvercommitConfigSpec is a description of a NodeOvercommitConfig properties: + CronConsistency: + description: If CronConsistency is true, controller will ensure ResourceOvercommitRatio + is consistent with the configuration of the TimeBound that should + have been executed last time + type: boolean + StartingDeadlineSeconds: + description: controller is not going to schedule anything below now + - StartingDeadlineSeconds + format: int64 + type: integer nodeOvercommitSelectorVal: description: NodeOvercommitSelectorVal is the value of node label selector with key consts.NodeOvercommitSelectorKey, it decides whether @@ -57,9 +67,47 @@ spec: ratio that needs to inject into Node.Annotations cpu,memory are supported. type: object + timeBounds: + description: TimeBounds supports dynamically adjusting ResourceOvercommitRatio + items: + properties: + bounds: + items: + properties: + cronTab: + description: 'CronTab support standardSpec, requires 5 + entries representing: minute, hour, day of month, month + and day of week' + type: string + resourceOvercommitRatio: + additionalProperties: + type: string + description: Node overcommit ratio will be set as ResourceOvercommitRatio + when CronTab is triggered cpu,memory are supported. + type: object + required: + - cronTab + type: object + type: array + end: + format: date-time + type: string + start: + description: TimeBound is valid between Start and End + format: date-time + type: string + type: object + type: array + required: + - CronConsistency type: object status: properties: + lastScheduleTime: + description: LastScheduleTime recorded the time when the cronTab was + triggered last time + format: date-time + type: string matchedNodeList: description: NodeList which the nodeOvercommitConfig rules matched items: diff --git a/pkg/apis/overcommit/v1alpha1/types.go b/pkg/apis/overcommit/v1alpha1/types.go index 33da6d8..40a34c2 100644 --- a/pkg/apis/overcommit/v1alpha1/types.go +++ b/pkg/apis/overcommit/v1alpha1/types.go @@ -32,11 +32,47 @@ type NodeOvercommitConfigSpec struct { // cpu,memory are supported. // +optional ResourceOvercommitRatio map[v1.ResourceName]string `json:"resourceOvercommitRatio,omitempty"` + + // TimeBounds supports dynamically adjusting ResourceOvercommitRatio + // +optional + TimeBounds []TimeBound `json:"timeBounds,omitempty"` + + // If CronConsistency is true, controller will ensure ResourceOvercommitRatio is consistent with the configuration of the TimeBound that should have been executed last time + CronConsistency bool `json:"CronConsistency"` + + // controller is not going to schedule anything below now - StartingDeadlineSeconds + StartingDeadlineSeconds *int64 `json:"StartingDeadlineSeconds,omitempty"` } type NodeOvercommitConfigStatus struct { // NodeList which the nodeOvercommitConfig rules matched MatchedNodeList []string `json:"matchedNodeList,omitempty"` + + // LastScheduleTime recorded the time when the cronTab was triggered last time + LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"` +} + +type TimeBound struct { + // TimeBound is valid between Start and End + // +optional + Start *metav1.Time `json:"start,omitempty"` + + // +optional + End *metav1.Time `json:"end,omitempty"` + + // +optional + Bounds []Bound `json:"bounds,omitempty"` +} + +type Bound struct { + // CronTab support standardSpec, requires 5 entries + // representing: minute, hour, day of month, month and day of week + CronTab string `json:"cronTab"` + + // Node overcommit ratio will be set as ResourceOvercommitRatio when CronTab is triggered + // cpu,memory are supported. + // +optional + ResourceOvercommitRatio map[v1.ResourceName]string `json:"resourceOvercommitRatio,omitempty"` } // +genclient diff --git a/pkg/apis/overcommit/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/overcommit/v1alpha1/zz_generated.deepcopy.go index 3ae3a9b..e64912b 100644 --- a/pkg/apis/overcommit/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/overcommit/v1alpha1/zz_generated.deepcopy.go @@ -26,6 +26,29 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Bound) DeepCopyInto(out *Bound) { + *out = *in + if in.ResourceOvercommitRatio != nil { + in, out := &in.ResourceOvercommitRatio, &out.ResourceOvercommitRatio + *out = make(map[v1.ResourceName]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Bound. +func (in *Bound) DeepCopy() *Bound { + if in == nil { + return nil + } + out := new(Bound) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NodeOvercommitConfig) DeepCopyInto(out *NodeOvercommitConfig) { *out = *in @@ -97,6 +120,18 @@ func (in *NodeOvercommitConfigSpec) DeepCopyInto(out *NodeOvercommitConfigSpec) (*out)[key] = val } } + if in.TimeBounds != nil { + in, out := &in.TimeBounds, &out.TimeBounds + *out = make([]TimeBound, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.StartingDeadlineSeconds != nil { + in, out := &in.StartingDeadlineSeconds, &out.StartingDeadlineSeconds + *out = new(int64) + **out = **in + } return } @@ -118,6 +153,10 @@ func (in *NodeOvercommitConfigStatus) DeepCopyInto(out *NodeOvercommitConfigStat *out = make([]string, len(*in)) copy(*out, *in) } + if in.LastScheduleTime != nil { + in, out := &in.LastScheduleTime, &out.LastScheduleTime + *out = (*in).DeepCopy() + } return } @@ -130,3 +169,34 @@ func (in *NodeOvercommitConfigStatus) DeepCopy() *NodeOvercommitConfigStatus { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TimeBound) DeepCopyInto(out *TimeBound) { + *out = *in + if in.Start != nil { + in, out := &in.Start, &out.Start + *out = (*in).DeepCopy() + } + if in.End != nil { + in, out := &in.End, &out.End + *out = (*in).DeepCopy() + } + if in.Bounds != nil { + in, out := &in.Bounds, &out.Bounds + *out = make([]Bound, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TimeBound. +func (in *TimeBound) DeepCopy() *TimeBound { + if in == nil { + return nil + } + out := new(TimeBound) + in.DeepCopyInto(out) + return out +}