|
| 1 | +/* |
| 2 | +Copyright 2025 Tim Ebert. |
| 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_test |
| 18 | + |
| 19 | +import ( |
| 20 | + "time" |
| 21 | + |
| 22 | + . "github.com/onsi/ginkgo/v2" |
| 23 | + . "github.com/onsi/gomega" |
| 24 | + admissionregistrationv1 "k8s.io/api/admissionregistration/v1" |
| 25 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 26 | + componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1" |
| 27 | + "k8s.io/utils/ptr" |
| 28 | + |
| 29 | + . "github.com/timebertt/kubernetes-controller-sharding/pkg/apis/config/v1alpha1" |
| 30 | +) |
| 31 | + |
| 32 | +var _ = Describe("SharderConfig defaulting", func() { |
| 33 | + var obj *SharderConfig |
| 34 | + |
| 35 | + BeforeEach(func() { |
| 36 | + obj = &SharderConfig{} |
| 37 | + }) |
| 38 | + |
| 39 | + Context("ClientConnectionConfiguration", func() { |
| 40 | + It("should set default values", func() { |
| 41 | + SetObjectDefaults_SharderConfig(obj) |
| 42 | + |
| 43 | + Expect(obj.ClientConnection).To(Equal(&componentbaseconfigv1alpha1.ClientConnectionConfiguration{ |
| 44 | + QPS: 100, |
| 45 | + Burst: 150, |
| 46 | + })) |
| 47 | + }) |
| 48 | + }) |
| 49 | + |
| 50 | + Context("LeaderElectionConfiguration", func() { |
| 51 | + It("should set default values", func() { |
| 52 | + SetObjectDefaults_SharderConfig(obj) |
| 53 | + |
| 54 | + Expect(obj.LeaderElection).To(Equal(&componentbaseconfigv1alpha1.LeaderElectionConfiguration{ |
| 55 | + LeaderElect: ptr.To(true), |
| 56 | + LeaseDuration: metav1.Duration{Duration: 15 * time.Second}, |
| 57 | + RenewDeadline: metav1.Duration{Duration: 10 * time.Second}, |
| 58 | + RetryPeriod: metav1.Duration{Duration: 2 * time.Second}, |
| 59 | + ResourceLock: "leases", |
| 60 | + ResourceName: "sharder", |
| 61 | + ResourceNamespace: "sharding-system", |
| 62 | + })) |
| 63 | + }) |
| 64 | + }) |
| 65 | + |
| 66 | + Context("DebuggingConfiguration", func() { |
| 67 | + It("should set default values", func() { |
| 68 | + SetObjectDefaults_SharderConfig(obj) |
| 69 | + |
| 70 | + Expect(obj.Debugging).To(Equal(&componentbaseconfigv1alpha1.DebuggingConfiguration{ |
| 71 | + EnableProfiling: ptr.To(true), |
| 72 | + EnableContentionProfiling: ptr.To(false), |
| 73 | + })) |
| 74 | + }) |
| 75 | + }) |
| 76 | + |
| 77 | + Context("manager settings", func() { |
| 78 | + It("should set default values", func() { |
| 79 | + SetObjectDefaults_SharderConfig(obj) |
| 80 | + |
| 81 | + Expect(obj.Health).To(Equal(HealthEndpoint{ |
| 82 | + BindAddress: ":8081", |
| 83 | + })) |
| 84 | + Expect(obj.Metrics).To(Equal(MetricsEndpoint{ |
| 85 | + BindAddress: ":8080", |
| 86 | + })) |
| 87 | + Expect(obj.GracefulShutdownTimeout).To(Equal(&metav1.Duration{Duration: 15 * time.Second})) |
| 88 | + }) |
| 89 | + }) |
| 90 | + |
| 91 | + Context("controller config", func() { |
| 92 | + It("should set default values", func() { |
| 93 | + SetObjectDefaults_SharderConfig(obj) |
| 94 | + |
| 95 | + Expect(obj.Controller).To(Equal(Controller{ |
| 96 | + Sharder: &SharderController{ |
| 97 | + SyncPeriod: &metav1.Duration{Duration: 5 * time.Minute}, |
| 98 | + }, |
| 99 | + })) |
| 100 | + }) |
| 101 | + }) |
| 102 | + |
| 103 | + Context("webhook config", func() { |
| 104 | + It("should set default values", func() { |
| 105 | + SetObjectDefaults_SharderConfig(obj) |
| 106 | + |
| 107 | + Expect(obj.Webhook).To(Equal(Webhook{ |
| 108 | + Server: &WebhookServer{}, |
| 109 | + Config: &WebhookConfig{ |
| 110 | + ClientConfig: &admissionregistrationv1.WebhookClientConfig{ |
| 111 | + Service: &admissionregistrationv1.ServiceReference{ |
| 112 | + Namespace: "sharding-system", |
| 113 | + Name: "sharder", |
| 114 | + }, |
| 115 | + }, |
| 116 | + NamespaceSelector: &metav1.LabelSelector{ |
| 117 | + MatchExpressions: []metav1.LabelSelectorRequirement{{ |
| 118 | + Key: "kubernetes.io/metadata.name", |
| 119 | + Operator: "NotIn", |
| 120 | + Values: []string{"kube-system", "sharding-system"}, |
| 121 | + }}, |
| 122 | + }, |
| 123 | + }, |
| 124 | + })) |
| 125 | + }) |
| 126 | + }) |
| 127 | +}) |
0 commit comments