Skip to content

Commit 3674c93

Browse files
authored
v1beta2: graduate Config API (#7375)
* Copy v1beta1 to v1beta2. * v1beta2: graduate Config API * Add conversion logic. * Keep one test with v1beta1 version.
1 parent 47c65c7 commit 3674c93

File tree

137 files changed

+3254
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+3254
-364
lines changed

apis/config/v1beta1/doc.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright The Kubernetes 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+
// +kubebuilder:object:generate=true
18+
// +groupName=config.kueue.x-k8s.io
19+
// +k8s:conversion-gen=sigs.k8s.io/kueue/apis/config/v1beta2
20+
21+
package v1beta1

apis/config/v1beta1/zz_generated.conversion.go

Lines changed: 855 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/config/v1beta2/configuration_types.go

Lines changed: 590 additions & 0 deletions
Large diffs are not rendered by default.

apis/config/v1beta2/defaults.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
Copyright The Kubernetes 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 v1beta2
18+
19+
import (
20+
"cmp"
21+
"os"
22+
"strings"
23+
"time"
24+
25+
corev1 "k8s.io/api/core/v1"
26+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
"k8s.io/client-go/tools/leaderelection/resourcelock"
28+
configv1alpha1 "k8s.io/component-base/config/v1alpha1"
29+
"k8s.io/utils/ptr"
30+
)
31+
32+
const (
33+
DefaultNamespace = "kueue-system"
34+
DefaultWebhookServiceName = "kueue-webhook-service"
35+
DefaultWebhookSecretName = "kueue-webhook-server-cert"
36+
DefaultWebhookPort = 9443
37+
DefaultWebhookCertDir = "/tmp/k8s-webhook-server/serving-certs"
38+
DefaultHealthProbeBindAddress = ":8081"
39+
DefaultMetricsBindAddress = ":8443"
40+
DefaultLeaderElectionID = "c1f6bfd2.kueue.x-k8s.io"
41+
DefaultLeaderElectionLeaseDuration = 15 * time.Second
42+
DefaultLeaderElectionRenewDeadline = 10 * time.Second
43+
DefaultLeaderElectionRetryPeriod = 2 * time.Second
44+
DefaultClientConnectionQPS float32 = 20.0
45+
DefaultClientConnectionBurst int32 = 30
46+
defaultPodsReadyTimeout = 5 * time.Minute
47+
defaultJobFrameworkName = "batch/job"
48+
DefaultMultiKueueGCInterval = time.Minute
49+
DefaultMultiKueueOrigin = "multikueue"
50+
DefaultMultiKueueWorkerLostTimeout = 15 * time.Minute
51+
DefaultRequeuingBackoffBaseSeconds = 60
52+
DefaultRequeuingBackoffMaxSeconds = 3600
53+
DefaultResourceTransformationStrategy = Retain
54+
)
55+
56+
func getOperatorNamespace() string {
57+
if data, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err == nil {
58+
if ns := strings.TrimSpace(string(data)); len(ns) > 0 {
59+
return ns
60+
}
61+
}
62+
return DefaultNamespace
63+
}
64+
65+
// SetDefaults_Configuration sets default values for ComponentConfig.
66+
//
67+
//nolint:revive // format required by generated code for defaulting
68+
func SetDefaults_Configuration(cfg *Configuration) {
69+
cfg.Namespace = cmp.Or(cfg.Namespace, ptr.To(getOperatorNamespace()))
70+
cfg.Webhook.Port = cmp.Or(cfg.Webhook.Port, ptr.To(DefaultWebhookPort))
71+
cfg.Webhook.CertDir = cmp.Or(cfg.Webhook.CertDir, DefaultWebhookCertDir)
72+
cfg.Metrics.BindAddress = cmp.Or(cfg.Metrics.BindAddress, DefaultMetricsBindAddress)
73+
cfg.Health.HealthProbeBindAddress = cmp.Or(cfg.Health.HealthProbeBindAddress, DefaultHealthProbeBindAddress)
74+
cfg.LeaderElection = cmp.Or(cfg.LeaderElection, &configv1alpha1.LeaderElectionConfiguration{})
75+
cfg.LeaderElection.ResourceName = cmp.Or(cfg.LeaderElection.ResourceName, DefaultLeaderElectionID)
76+
77+
// Default to Lease as component-base still defaults to endpoint resources
78+
// until core components migrate to using Leases. See k/k #80289 for more details.
79+
cfg.LeaderElection.ResourceLock = cmp.Or(cfg.LeaderElection.ResourceLock, resourcelock.LeasesResourceLock)
80+
81+
// Use the default LeaderElectionConfiguration options
82+
configv1alpha1.RecommendedDefaultLeaderElectionConfiguration(cfg.LeaderElection)
83+
84+
cfg.InternalCertManagement = cmp.Or(cfg.InternalCertManagement, &InternalCertManagement{})
85+
cfg.InternalCertManagement.Enable = cmp.Or(cfg.InternalCertManagement.Enable, ptr.To(true))
86+
if *cfg.InternalCertManagement.Enable {
87+
cfg.InternalCertManagement.WebhookServiceName = cmp.Or(cfg.InternalCertManagement.WebhookServiceName, ptr.To(DefaultWebhookServiceName))
88+
cfg.InternalCertManagement.WebhookSecretName = cmp.Or(cfg.InternalCertManagement.WebhookSecretName, ptr.To(DefaultWebhookSecretName))
89+
}
90+
91+
cfg.ClientConnection = cmp.Or(cfg.ClientConnection, &ClientConnection{})
92+
cfg.ClientConnection.QPS = cmp.Or(cfg.ClientConnection.QPS, ptr.To(DefaultClientConnectionQPS))
93+
cfg.ClientConnection.Burst = cmp.Or(cfg.ClientConnection.Burst, ptr.To(DefaultClientConnectionBurst))
94+
95+
cfg.WaitForPodsReady = cmp.Or(cfg.WaitForPodsReady, &WaitForPodsReady{Enable: false})
96+
if cfg.WaitForPodsReady.Enable {
97+
cfg.WaitForPodsReady.Timeout = cmp.Or(cfg.WaitForPodsReady.Timeout, &metav1.Duration{Duration: defaultPodsReadyTimeout})
98+
cfg.WaitForPodsReady.BlockAdmission = cmp.Or(cfg.WaitForPodsReady.BlockAdmission, &cfg.WaitForPodsReady.Enable)
99+
cfg.WaitForPodsReady.RequeuingStrategy = cmp.Or(cfg.WaitForPodsReady.RequeuingStrategy, &RequeuingStrategy{})
100+
cfg.WaitForPodsReady.RequeuingStrategy.Timestamp = cmp.Or(cfg.WaitForPodsReady.RequeuingStrategy.Timestamp, ptr.To(EvictionTimestamp))
101+
cfg.WaitForPodsReady.RequeuingStrategy.BackoffBaseSeconds = cmp.Or(cfg.WaitForPodsReady.RequeuingStrategy.BackoffBaseSeconds, ptr.To[int32](DefaultRequeuingBackoffBaseSeconds))
102+
cfg.WaitForPodsReady.RequeuingStrategy.BackoffMaxSeconds = cmp.Or(cfg.WaitForPodsReady.RequeuingStrategy.BackoffMaxSeconds, ptr.To[int32](DefaultRequeuingBackoffMaxSeconds))
103+
}
104+
105+
cfg.Integrations = cmp.Or(cfg.Integrations, &Integrations{})
106+
if len(cfg.Integrations.Frameworks) == 0 {
107+
cfg.Integrations.Frameworks = []string{defaultJobFrameworkName}
108+
}
109+
110+
cfg.ManagedJobsNamespaceSelector = cmp.Or(cfg.ManagedJobsNamespaceSelector, &metav1.LabelSelector{
111+
MatchExpressions: []metav1.LabelSelectorRequirement{
112+
{
113+
Key: corev1.LabelMetadataName,
114+
Operator: metav1.LabelSelectorOpNotIn,
115+
Values: []string{"kube-system", *cfg.Namespace},
116+
},
117+
},
118+
})
119+
120+
cfg.MultiKueue = cmp.Or(cfg.MultiKueue, &MultiKueue{})
121+
cfg.MultiKueue.GCInterval = cmp.Or(cfg.MultiKueue.GCInterval, &metav1.Duration{Duration: DefaultMultiKueueGCInterval})
122+
cfg.MultiKueue.Origin = ptr.To(cmp.Or(ptr.Deref(cfg.MultiKueue.Origin, ""), DefaultMultiKueueOrigin))
123+
cfg.MultiKueue.WorkerLostTimeout = cmp.Or(cfg.MultiKueue.WorkerLostTimeout, &metav1.Duration{Duration: DefaultMultiKueueWorkerLostTimeout})
124+
cfg.MultiKueue.DispatcherName = cmp.Or(cfg.MultiKueue.DispatcherName, ptr.To(MultiKueueDispatcherModeAllAtOnce))
125+
126+
if fs := cfg.FairSharing; fs != nil && fs.Enable && len(fs.PreemptionStrategies) == 0 {
127+
fs.PreemptionStrategies = []PreemptionStrategy{LessThanOrEqualToFinalShare, LessThanInitialShare}
128+
}
129+
if afs := cfg.AdmissionFairSharing; afs != nil {
130+
afs.UsageSamplingInterval.Duration = cmp.Or(afs.UsageSamplingInterval.Duration, 5*time.Minute)
131+
}
132+
133+
if cfg.Resources != nil {
134+
for idx := range cfg.Resources.Transformations {
135+
cfg.Resources.Transformations[idx].Strategy = ptr.To(cmp.Or(ptr.Deref(cfg.Resources.Transformations[idx].Strategy, ""), DefaultResourceTransformationStrategy))
136+
}
137+
}
138+
}

0 commit comments

Comments
 (0)