Skip to content

Commit eee644c

Browse files
committed
Add MultiCluster Scheduler config
1 parent 7a8054f commit eee644c

File tree

25 files changed

+1714
-1
lines changed

25 files changed

+1714
-1
lines changed

pkg/apis/operator/v1alpha1/register.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ const (
6464

6565
// KindTektonPruner is the Kind of TektonPruner in a GVK context.
6666
KindTektonPruner = "TektonPruner"
67+
68+
// KindTektonScheduler is the Kind of TektonScheduler in a GVK context.
69+
KindTektonScheduler = "TektonScheduler"
6770
)
6871

6972
// Resource takes an unqualified resource and returns a Group qualified GroupResource

pkg/apis/operator/v1alpha1/tektonconfig_defaults.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func (tc *TektonConfig) SetDefaults(ctx context.Context) {
3333
tc.Spec.Chain.setDefaults()
3434
tc.Spec.Result.setDefaults()
3535
tc.Spec.TektonPruner.SetDefaults()
36+
tc.Spec.Scheduler.SetDefaults()
3637

3738
if IsOpenShiftPlatform() {
3839
if tc.Spec.Platforms.OpenShift.PipelinesAsCode == nil {

pkg/apis/operator/v1alpha1/tektonconfig_types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ type TektonConfigSpec struct {
9191
Pruner Prune `json:"pruner,omitempty"`
9292
// New EventBasedPruner which provides more granular control over TaskRun and PipelineRuns
9393
TektonPruner Pruner `json:"tektonpruner,omitempty"`
94-
CommonSpec `json:",inline"`
94+
// To enable Pipeline Scheduling on Single Cluster or Multiple Clusters
95+
// +optional
96+
Scheduler Scheduler `json:"scheduler,omitempty"`
97+
CommonSpec `json:",inline"`
9598
// Addon holds the addons config
9699
// +optional
97100
Addon Addon `json:"addon,omitempty"`
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2026 The Tekton 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 v1alpha1
18+
19+
import (
20+
"context"
21+
22+
"k8s.io/utils/ptr"
23+
)
24+
25+
const (
26+
DefaultMultiClusterDisabled = true
27+
DefaultSchedulerDisabled = true
28+
MultiClusterRoleSpoke MultiClusterRole = "Spoke"
29+
MultiClusterRoleHub MultiClusterRole = "Hub"
30+
)
31+
32+
func (tp *TektonScheduler) SetDefaults(_ context.Context) {
33+
tp.Spec.Scheduler.SetDefaults()
34+
}
35+
36+
func (s *Scheduler) SetDefaults() {
37+
if s.Disabled == nil {
38+
s.Disabled = ptr.To(DefaultSchedulerDisabled)
39+
s.MultiClusterDisabled = DefaultMultiClusterDisabled
40+
}
41+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
Copyright 2026 The Tekton 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 v1alpha1
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/runtime/schema"
21+
"knative.dev/pkg/apis"
22+
)
23+
24+
var (
25+
_ TektonComponentStatus = (*TektonSchedulerStatus)(nil)
26+
)
27+
28+
// GroupVersionKind returns SchemeGroupVersion of a TektonScheduler
29+
func (Scheduler *TektonScheduler) GroupVersionKind() schema.GroupVersionKind {
30+
return SchemeGroupVersion.WithKind(KindTektonScheduler)
31+
}
32+
33+
func (Scheduler *TektonScheduler) GetGroupVersionKind() schema.GroupVersionKind {
34+
return SchemeGroupVersion.WithKind(KindTektonScheduler)
35+
}
36+
37+
// GetCondition returns the current condition of a given condition type
38+
func (Scheduler *TektonSchedulerStatus) GetCondition(t apis.ConditionType) *apis.Condition {
39+
return condSet.Manage(Scheduler).GetCondition(t)
40+
}
41+
42+
// InitializeConditions initializes conditions of an TektonSchedulerStatus
43+
func (Scheduler *TektonSchedulerStatus) InitializeConditions() {
44+
condSet.Manage(Scheduler).InitializeConditions()
45+
}
46+
47+
// IsReady looks at the conditions returns true if they are all true.
48+
func (Scheduler *TektonSchedulerStatus) IsReady() bool {
49+
return condSet.Manage(Scheduler).IsHappy()
50+
}
51+
52+
func (Scheduler *TektonSchedulerStatus) MarkPreReconcilerComplete() {
53+
condSet.Manage(Scheduler).MarkTrue(PreReconciler)
54+
}
55+
56+
func (Scheduler *TektonSchedulerStatus) MarkInstallerSetAvailable() {
57+
condSet.Manage(Scheduler).MarkTrue(InstallerSetAvailable)
58+
}
59+
60+
func (Scheduler *TektonSchedulerStatus) MarkInstallerSetReady() {
61+
condSet.Manage(Scheduler).MarkTrue(InstallerSetReady)
62+
}
63+
64+
func (Scheduler *TektonSchedulerStatus) MarkPostReconcilerComplete() {
65+
condSet.Manage(Scheduler).MarkTrue(PostReconciler)
66+
}
67+
68+
// MarkDependenciesInstalled marks the DependenciesInstalled status as true.
69+
func (Scheduler *TektonSchedulerStatus) MarkDependenciesInstalled() {
70+
condSet.Manage(Scheduler).MarkTrue(DependenciesInstalled)
71+
}
72+
73+
func (Scheduler *TektonSchedulerStatus) MarkNotReady(msg string) {
74+
condSet.Manage(Scheduler).MarkFalse(
75+
apis.ConditionReady,
76+
"Error",
77+
"Ready: %s", msg)
78+
}
79+
80+
func (Scheduler *TektonSchedulerStatus) MarkPreReconcilerFailed(msg string) {
81+
Scheduler.MarkNotReady("PreReconciliation failed")
82+
condSet.Manage(Scheduler).MarkFalse(
83+
PreReconciler,
84+
"Error",
85+
"PreReconciliation failed with message: %s", msg)
86+
}
87+
88+
func (Scheduler *TektonSchedulerStatus) MarkInstallerSetNotAvailable(msg string) {
89+
Scheduler.MarkNotReady("TektonScheduler not ready")
90+
condSet.Manage(Scheduler).MarkFalse(
91+
InstallerSetAvailable,
92+
"Error",
93+
"Installer set not ready: %s", msg)
94+
}
95+
96+
func (Scheduler *TektonSchedulerStatus) MarkInstallerSetNotReady(msg string) {
97+
Scheduler.MarkNotReady("TektonScheduler not ready")
98+
condSet.Manage(Scheduler).MarkFalse(
99+
InstallerSetReady,
100+
"Error",
101+
"Installer set not ready: %s", msg)
102+
}
103+
104+
func (Scheduler *TektonSchedulerStatus) MarkPostReconcilerFailed(msg string) {
105+
Scheduler.MarkNotReady("PostReconciliation failed")
106+
condSet.Manage(Scheduler).MarkFalse(
107+
PostReconciler,
108+
"Error",
109+
"PostReconciliation failed with message: %s", msg)
110+
}
111+
112+
// MarkDependencyInstalling marks the DependenciesInstalled status as false with the
113+
// given message.
114+
func (Scheduler *TektonSchedulerStatus) MarkDependencyInstalling(msg string) {
115+
Scheduler.MarkNotReady("Dependencies installing")
116+
condSet.Manage(Scheduler).MarkFalse(
117+
DependenciesInstalled,
118+
"Error",
119+
"Dependency installing: %s", msg)
120+
}
121+
122+
// MarkDependencyMissing marks the DependenciesInstalled status as false with the
123+
// given message.
124+
func (Scheduler *TektonSchedulerStatus) MarkDependencyMissing(msg string) {
125+
Scheduler.MarkNotReady("Missing Dependencies for TektonScheduler")
126+
condSet.Manage(Scheduler).MarkFalse(
127+
DependenciesInstalled,
128+
"Error",
129+
"Dependency missing: %s", msg)
130+
}
131+
132+
func (Scheduler *TektonSchedulerStatus) GetTektonScheduler() string {
133+
return Scheduler.TektonScheduler
134+
}
135+
136+
func (Scheduler *TektonSchedulerStatus) SetTektonScheduler(installerSet string) {
137+
Scheduler.TektonScheduler = installerSet
138+
}
139+
140+
// GetVersion gets the currently installed version of the component.
141+
func (Scheduler *TektonSchedulerStatus) GetVersion() string {
142+
return Scheduler.Version
143+
}
144+
145+
// SetVersion sets the currently installed version of the component.
146+
func (Scheduler *TektonSchedulerStatus) SetVersion(version string) {
147+
Scheduler.Version = version
148+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
Copyright 2026 The Tekton 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 v1alpha1
18+
19+
import (
20+
"testing"
21+
22+
"knative.dev/pkg/apis"
23+
apistest "knative.dev/pkg/apis/testing"
24+
)
25+
26+
func TestTektonSchedulerStatus_SuccessConditions(t *testing.T) {
27+
tt := &TektonSchedulerStatus{}
28+
tt.InitializeConditions()
29+
30+
apistest.CheckConditionOngoing(tt, DependenciesInstalled, t)
31+
apistest.CheckConditionOngoing(tt, PreReconciler, t)
32+
apistest.CheckConditionOngoing(tt, InstallerSetAvailable, t)
33+
apistest.CheckConditionOngoing(tt, InstallerSetReady, t)
34+
apistest.CheckConditionOngoing(tt, PostReconciler, t)
35+
36+
// Dependencies installed
37+
tt.MarkDependenciesInstalled()
38+
apistest.CheckConditionSucceeded(tt, DependenciesInstalled, t)
39+
40+
// Pre reconciler completes execution
41+
tt.MarkPreReconcilerComplete()
42+
apistest.CheckConditionSucceeded(tt, PreReconciler, t)
43+
44+
// Installer set created
45+
tt.MarkInstallerSetAvailable()
46+
apistest.CheckConditionSucceeded(tt, InstallerSetAvailable, t)
47+
48+
// InstallerSet and then PostReconciler become ready and we're good.
49+
tt.MarkInstallerSetReady()
50+
apistest.CheckConditionSucceeded(tt, InstallerSetReady, t)
51+
52+
tt.MarkPostReconcilerComplete()
53+
apistest.CheckConditionSucceeded(tt, PostReconciler, t)
54+
55+
if ready := tt.IsReady(); !ready {
56+
t.Errorf("tt.IsReady() = %v, want true", ready)
57+
}
58+
}
59+
60+
func TestTektonSchedulerStatus_ErrorConditions(t *testing.T) {
61+
// Given
62+
tps := &TektonSchedulerStatus{}
63+
64+
tps.MarkPreReconcilerFailed("Reconciliation Failed for Scheduler")
65+
apistest.CheckConditionFailed(tps, PreReconciler, t)
66+
67+
// Not Ready Condition
68+
tps.MarkNotReady("Scheduler Not Ready")
69+
apistest.CheckConditionFailed(tps, apis.ConditionReady, t)
70+
71+
// PostReconciler Failed Condition
72+
tps.MarkPostReconcilerFailed("Scheduler PostReconciler Failed")
73+
apistest.CheckConditionFailed(tps, PostReconciler, t)
74+
75+
// InstallerSetNotAvailable Condition
76+
tps.MarkInstallerSetNotAvailable("Scheduler InstallerSetNotAvailable ")
77+
apistest.CheckConditionFailed(tps, InstallerSetAvailable, t)
78+
79+
// InstallerSetNotAvailable Condition
80+
tps.MarkInstallerSetNotReady("Scheduler InstallerSetNotReady ")
81+
apistest.CheckConditionFailed(tps, InstallerSetReady, t)
82+
83+
// DependencyInstalling Condition
84+
tps.MarkDependencyInstalling("Scheduler Dependencies are installing ")
85+
apistest.CheckConditionFailed(tps, DependenciesInstalled, t)
86+
87+
// DependencyMissing Condition
88+
tps.MarkDependencyMissing("Scheduler Dependencies are Missing ")
89+
apistest.CheckConditionFailed(tps, DependenciesInstalled, t)
90+
}

0 commit comments

Comments
 (0)