Skip to content

Commit

Permalink
[multikueue] Add garbage collector.
Browse files Browse the repository at this point in the history
  • Loading branch information
trasc committed Jan 29, 2024
1 parent 248255d commit f2cf51b
Show file tree
Hide file tree
Showing 21 changed files with 564 additions and 27 deletions.
10 changes: 10 additions & 0 deletions apis/config/v1beta1/configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ type Configuration struct {
// QueueVisibility is configuration to expose the information about the top
// pending workloads.
QueueVisibility *QueueVisibility `json:"queueVisibility,omitempty"`

// MultiKueue controls the behaviour of the MultiKueue AdmissionCheck Controller.
MultiKueue *MultiKueue `json:"multiKueue,omitempty"`
}

type ControllerManager struct {
Expand Down Expand Up @@ -199,6 +202,13 @@ type WaitForPodsReady struct {
RequeuingTimestamp *RequeuingTimestamp `json:"requeuingTimestamp,omitempty"`
}

type MultiKueue struct {
// GCTimeout defines the timeout between two consecutive garbage collection runs.
// Defaults to 1min. If 0, the garbage collection is disabled.
// +optional
GCTimeout *metav1.Duration `json:"gcTimeout,omitempty"`
}

type RequeuingTimestamp string

const (
Expand Down
8 changes: 8 additions & 0 deletions apis/config/v1beta1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
DefaultQueueVisibilityUpdateIntervalSeconds int32 = 5
DefaultClusterQueuesMaxCount int32 = 10
defaultJobFrameworkName = "batch/job"
DefaultMultiKueueGCTimeout = time.Minute
)

func getOperatorNamespace() string {
Expand Down Expand Up @@ -161,4 +162,11 @@ func SetDefaults_Configuration(cfg *Configuration) {
if cfg.Integrations.PodOptions.PodSelector == nil {
cfg.Integrations.PodOptions.PodSelector = &metav1.LabelSelector{}
}

if cfg.MultiKueue == nil {
cfg.MultiKueue = &MultiKueue{}
}
if cfg.MultiKueue.GCTimeout == nil {
cfg.MultiKueue.GCTimeout = &metav1.Duration{Duration: DefaultMultiKueueGCTimeout}
}
}
34 changes: 34 additions & 0 deletions apis/config/v1beta1/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func TestSetDefaults_Configuration(t *testing.T) {
},
}

defaultMultiKueue := &MultiKueue{GCTimeout: &metav1.Duration{Duration: DefaultMultiKueueGCTimeout}}

podsReadyTimeoutTimeout := metav1.Duration{Duration: defaultPodsReadyTimeout}
podsReadyTimeoutOverwrite := metav1.Duration{Duration: time.Minute}

Expand All @@ -118,6 +120,7 @@ func TestSetDefaults_Configuration(t *testing.T) {
ClientConnection: defaultClientConnection,
Integrations: defaultIntegrations,
QueueVisibility: defaultQueueVisibility,
MultiKueue: defaultMultiKueue,
},
},
"defaulting ControllerManager": {
Expand Down Expand Up @@ -158,6 +161,7 @@ func TestSetDefaults_Configuration(t *testing.T) {
ClientConnection: defaultClientConnection,
Integrations: defaultIntegrations,
QueueVisibility: defaultQueueVisibility,
MultiKueue: defaultMultiKueue,
},
},
"should not default ControllerManager": {
Expand Down Expand Up @@ -214,6 +218,7 @@ func TestSetDefaults_Configuration(t *testing.T) {
ClientConnection: defaultClientConnection,
Integrations: defaultIntegrations,
QueueVisibility: defaultQueueVisibility,
MultiKueue: defaultMultiKueue,
},
},
"should not set LeaderElectionID": {
Expand Down Expand Up @@ -254,6 +259,7 @@ func TestSetDefaults_Configuration(t *testing.T) {
ClientConnection: defaultClientConnection,
Integrations: defaultIntegrations,
QueueVisibility: defaultQueueVisibility,
MultiKueue: defaultMultiKueue,
},
},
"defaulting InternalCertManagement": {
Expand All @@ -271,6 +277,7 @@ func TestSetDefaults_Configuration(t *testing.T) {
ClientConnection: defaultClientConnection,
Integrations: overwriteNamespaceIntegrations,
QueueVisibility: defaultQueueVisibility,
MultiKueue: defaultMultiKueue,
},
},
"should not default InternalCertManagement": {
Expand All @@ -289,6 +296,7 @@ func TestSetDefaults_Configuration(t *testing.T) {
ClientConnection: defaultClientConnection,
Integrations: overwriteNamespaceIntegrations,
QueueVisibility: defaultQueueVisibility,
MultiKueue: defaultMultiKueue,
},
},
"should not default values in custom ClientConnection": {
Expand All @@ -314,6 +322,7 @@ func TestSetDefaults_Configuration(t *testing.T) {
},
Integrations: overwriteNamespaceIntegrations,
QueueVisibility: defaultQueueVisibility,
MultiKueue: defaultMultiKueue,
},
},
"should default empty custom ClientConnection": {
Expand All @@ -333,6 +342,7 @@ func TestSetDefaults_Configuration(t *testing.T) {
ClientConnection: defaultClientConnection,
Integrations: overwriteNamespaceIntegrations,
QueueVisibility: defaultQueueVisibility,
MultiKueue: defaultMultiKueue,
},
},
"defaulting waitForPodsReady values": {
Expand All @@ -359,6 +369,7 @@ func TestSetDefaults_Configuration(t *testing.T) {
ClientConnection: defaultClientConnection,
Integrations: defaultIntegrations,
QueueVisibility: defaultQueueVisibility,
MultiKueue: defaultMultiKueue,
},
},
"set waitForPodsReady.blockAdmission to false when enable is false": {
Expand All @@ -385,6 +396,7 @@ func TestSetDefaults_Configuration(t *testing.T) {
ClientConnection: defaultClientConnection,
Integrations: defaultIntegrations,
QueueVisibility: defaultQueueVisibility,
MultiKueue: defaultMultiKueue,
},
},
"respecting provided waitForPodsReady values": {
Expand Down Expand Up @@ -413,6 +425,7 @@ func TestSetDefaults_Configuration(t *testing.T) {
ClientConnection: defaultClientConnection,
Integrations: defaultIntegrations,
QueueVisibility: defaultQueueVisibility,
MultiKueue: defaultMultiKueue,
},
},
"integrations": {
Expand All @@ -436,6 +449,7 @@ func TestSetDefaults_Configuration(t *testing.T) {
PodOptions: defaultIntegrations.PodOptions,
},
QueueVisibility: defaultQueueVisibility,
MultiKueue: defaultMultiKueue,
},
},
"queue visibility": {
Expand Down Expand Up @@ -464,6 +478,26 @@ func TestSetDefaults_Configuration(t *testing.T) {
MaxCount: 0,
},
},
MultiKueue: defaultMultiKueue,
},
},
"multiKueue": {
original: &Configuration{
InternalCertManagement: &InternalCertManagement{
Enable: ptr.To(false),
},
MultiKueue: &MultiKueue{GCTimeout: &metav1.Duration{Duration: time.Second}},
},
want: &Configuration{
Namespace: ptr.To(DefaultNamespace),
ControllerManager: defaultCtrlManagerConfigurationSpec,
InternalCertManagement: &InternalCertManagement{
Enable: ptr.To(false),
},
ClientConnection: defaultClientConnection,
Integrations: defaultIntegrations,
QueueVisibility: defaultQueueVisibility,
MultiKueue: &MultiKueue{GCTimeout: &metav1.Duration{Duration: time.Second}},
},
},
}
Expand Down
25 changes: 25 additions & 0 deletions apis/config/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions apis/kueue/v1alpha1/multikueue_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ type KubeConfig struct {
type MultiKueueClusterSpec struct {
// Information how to connect to the cluster.
KubeConfig KubeConfig `json:"kubeConfig"`

// A label value used to track the creator of workloads in the worker cluster.
//
// +kubebuilder:validation:Optional
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:default=multikueue
Origin string `json:"origin,omitempty"`
}

type MultiKueueClusterStatus struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ spec:
- location
- locationType
type: object
origin:
default: multikueue
description: A label value used to track the creator of workloads
in the worker cluster.
maxLength: 63
type: string
x-kubernetes-validations:
- message: Value is immutable
rule: self == oldSelf
required:
- kubeConfig
type: object
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/kueue/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func setupControllers(mgr ctrl.Manager, cCache *cache.Cache, queues *queue.Manag
}

if features.Enabled(features.MultiKueue) {
if err := multikueue.SetupControllers(mgr, *cfg.Namespace); err != nil {
if err := multikueue.SetupControllers(mgr, *cfg.Namespace, multikueue.WithGCInterval(cfg.MultiKueue.GCTimeout.Duration)); err != nil {
setupLog.Error(err, "Could not setup MultiKueue controller")
os.Exit(1)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/kueue/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ integrations:
MaxCount: config.DefaultClusterQueuesMaxCount,
},
},
MultiKueue: &config.MultiKueue{GCTimeout: &metav1.Duration{Duration: config.DefaultMultiKueueGCTimeout}},
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ spec:
- location
- locationType
type: object
origin:
default: multikueue
description: A label value used to track the creator of workloads
in the worker cluster.
maxLength: 63
type: string
x-kubernetes-validations:
- message: Value is immutable
rule: self == oldSelf
required:
- kubeConfig
type: object
Expand Down
Loading

0 comments on commit f2cf51b

Please sign in to comment.