|
| 1 | +/* |
| 2 | +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 v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + "reflect" |
| 21 | + "time" |
| 22 | + |
| 23 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 24 | + configv1alpha1 "k8s.io/component-base/config/v1alpha1" |
| 25 | +) |
| 26 | + |
| 27 | +// Getters |
| 28 | + |
| 29 | +// GetSyncPeriod returns the sync period in time.Duration |
| 30 | +func (in *DefaultControllerConfiguration) GetSyncPeriod() *time.Duration { |
| 31 | + if in.Spec.SyncPeriod != nil { |
| 32 | + return &in.Spec.SyncPeriod.Duration |
| 33 | + } |
| 34 | + return nil |
| 35 | +} |
| 36 | + |
| 37 | +// GetLeaderElection returns the LeaderElection |
| 38 | +func (in *DefaultControllerConfiguration) GetLeaderElection() *bool { |
| 39 | + return in.Spec.LeaderElection.LeaderElect |
| 40 | +} |
| 41 | + |
| 42 | +// GetLeaderElectionNamespace returns the LeaderElectionNamespace |
| 43 | +func (in *DefaultControllerConfiguration) GetLeaderElectionNamespace() string { |
| 44 | + return in.Spec.LeaderElection.ResourceNamespace |
| 45 | +} |
| 46 | + |
| 47 | +// GetLeaderElectionID returns the LeaderElectionID |
| 48 | +func (in *DefaultControllerConfiguration) GetLeaderElectionID() string { |
| 49 | + return in.Spec.LeaderElection.ResourceName |
| 50 | +} |
| 51 | + |
| 52 | +// GetLeaseDuration returns the LeaseDuration |
| 53 | +func (in *DefaultControllerConfiguration) GetLeaseDuration() *time.Duration { |
| 54 | + return &in.Spec.LeaderElection.LeaseDuration.Duration |
| 55 | +} |
| 56 | + |
| 57 | +// GetRenewDeadline returns the RenewDeadline |
| 58 | +func (in *DefaultControllerConfiguration) GetRenewDeadline() *time.Duration { |
| 59 | + return &in.Spec.LeaderElection.RenewDeadline.Duration |
| 60 | +} |
| 61 | + |
| 62 | +// GetRetryPeriod returns the RetryPeriod |
| 63 | +func (in *DefaultControllerConfiguration) GetRetryPeriod() *time.Duration { |
| 64 | + return &in.Spec.LeaderElection.RetryPeriod.Duration |
| 65 | +} |
| 66 | + |
| 67 | +// GetNamespace returns the Namespace |
| 68 | +func (in *DefaultControllerConfiguration) GetNamespace() string { |
| 69 | + return in.Spec.Namespace |
| 70 | +} |
| 71 | + |
| 72 | +// GetMetricsBindAddress returns the MetricsBindAddress |
| 73 | +func (in *DefaultControllerConfiguration) GetMetricsBindAddress() string { |
| 74 | + return in.Spec.MetricsBindAddress |
| 75 | +} |
| 76 | + |
| 77 | +// GetHealthProbeBindAddress returns the HealthProbeBindAddress |
| 78 | +func (in *DefaultControllerConfiguration) GetHealthProbeBindAddress() string { |
| 79 | + return in.Spec.Health.HealthProbeBindAddress |
| 80 | +} |
| 81 | + |
| 82 | +// GetReadinessEndpointName returns the ReadinessEndpointName |
| 83 | +func (in *DefaultControllerConfiguration) GetReadinessEndpointName() string { |
| 84 | + return in.Spec.Health.ReadinessEndpointName |
| 85 | +} |
| 86 | + |
| 87 | +// GetLivenessEndpointName returns the LivenessEndpointName |
| 88 | +func (in *DefaultControllerConfiguration) GetLivenessEndpointName() string { |
| 89 | + return in.Spec.Health.LivenessEndpointName |
| 90 | +} |
| 91 | + |
| 92 | +// GetPort returns the Port |
| 93 | +func (in *DefaultControllerConfiguration) GetPort() *int { |
| 94 | + return in.Spec.Port |
| 95 | +} |
| 96 | + |
| 97 | +// GetHost returns the Host |
| 98 | +func (in *DefaultControllerConfiguration) GetHost() string { |
| 99 | + return in.Spec.Host |
| 100 | +} |
| 101 | + |
| 102 | +// GetCertDir returns the CertDir |
| 103 | +func (in *DefaultControllerConfiguration) GetCertDir() string { |
| 104 | + return in.Spec.CertDir |
| 105 | +} |
| 106 | + |
| 107 | +// Setters |
| 108 | + |
| 109 | +// SetSyncPeriod sets the sync period in time.Duration |
| 110 | +func (in *DefaultControllerConfiguration) SetSyncPeriod(syncPeriod *metav1.Duration) { |
| 111 | + in.Spec.SyncPeriod = syncPeriod |
| 112 | +} |
| 113 | + |
| 114 | +// SetLeaderElectionConfiguration sets the leader election configuration |
| 115 | +func (in *DefaultControllerConfiguration) SetLeaderElectionConfiguration(leaderElection configv1alpha1.LeaderElectionConfiguration) { |
| 116 | + in.Spec.LeaderElection = leaderElection |
| 117 | +} |
| 118 | + |
| 119 | +// SetLeaderElection sets the LeaderElection config |
| 120 | +func (in *DefaultControllerConfiguration) SetLeaderElection(leaderElection bool) { |
| 121 | + if reflect.DeepEqual(in.Spec.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { |
| 122 | + in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) |
| 123 | + } |
| 124 | + in.Spec.LeaderElection.LeaderElect = &leaderElection |
| 125 | +} |
| 126 | + |
| 127 | +// SetLeaderElectionNamespace returns the LeaderElectionNamespace |
| 128 | +func (in *DefaultControllerConfiguration) SetLeaderElectionNamespace(resourceNamespace string) { |
| 129 | + if reflect.DeepEqual(in.Spec.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { |
| 130 | + in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) |
| 131 | + } |
| 132 | + in.Spec.LeaderElection.ResourceNamespace = resourceNamespace |
| 133 | +} |
| 134 | + |
| 135 | +// SetLeaderElectionID returns the LeaderElectionID |
| 136 | +func (in *DefaultControllerConfiguration) SetLeaderElectionID(resourceName string) { |
| 137 | + if reflect.DeepEqual(in.Spec.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { |
| 138 | + in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) |
| 139 | + } |
| 140 | + in.Spec.LeaderElection.ResourceName = resourceName |
| 141 | +} |
| 142 | + |
| 143 | +// SetLeaseDuration returns the LeaseDuration |
| 144 | +func (in *DefaultControllerConfiguration) SetLeaseDuration(leaseDuration metav1.Duration) { |
| 145 | + if reflect.DeepEqual(in.Spec.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { |
| 146 | + in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) |
| 147 | + } |
| 148 | + in.Spec.LeaderElection.LeaseDuration = leaseDuration |
| 149 | +} |
| 150 | + |
| 151 | +// SetRenewDeadline returns the RenewDeadline |
| 152 | +func (in *DefaultControllerConfiguration) SetRenewDeadline(renewDeadline metav1.Duration) { |
| 153 | + if reflect.DeepEqual(in.Spec.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { |
| 154 | + in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) |
| 155 | + } |
| 156 | + in.Spec.LeaderElection.RenewDeadline = renewDeadline |
| 157 | +} |
| 158 | + |
| 159 | +// SetRetryPeriod returns the RetryPeriod |
| 160 | +func (in *DefaultControllerConfiguration) SetRetryPeriod(retryPeriod metav1.Duration) { |
| 161 | + if reflect.DeepEqual(in.Spec.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { |
| 162 | + in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) |
| 163 | + } |
| 164 | + in.Spec.LeaderElection.RetryPeriod = retryPeriod |
| 165 | +} |
| 166 | + |
| 167 | +// SetNamespace returns the Namespace |
| 168 | +func (in *DefaultControllerConfiguration) SetNamespace(namespace string) { |
| 169 | + in.Spec.Namespace = namespace |
| 170 | +} |
| 171 | + |
| 172 | +// SetMetricsBindAddress returns the MetricsBindAddress |
| 173 | +func (in *DefaultControllerConfiguration) SetMetricsBindAddress(metricsBindAddress string) { |
| 174 | + in.Spec.MetricsBindAddress = metricsBindAddress |
| 175 | +} |
| 176 | + |
| 177 | +// SetHealthProbeBindAddress returns the HealthProbeBindAddress |
| 178 | +func (in *DefaultControllerConfiguration) SetHealthProbeBindAddress(healthProbeBindAddress string) { |
| 179 | + in.Spec.Health.HealthProbeBindAddress = healthProbeBindAddress |
| 180 | +} |
| 181 | + |
| 182 | +// SetReadinessEndpointName returns the ReadinessEndpointName |
| 183 | +func (in *DefaultControllerConfiguration) SetReadinessEndpointName(readinessEndpointName string) { |
| 184 | + in.Spec.Health.ReadinessEndpointName = readinessEndpointName |
| 185 | +} |
| 186 | + |
| 187 | +// SetLivenessEndpointName returns the LivenessEndpointName |
| 188 | +func (in *DefaultControllerConfiguration) SetLivenessEndpointName(livenessEndpointName string) { |
| 189 | + in.Spec.Health.LivenessEndpointName = livenessEndpointName |
| 190 | +} |
| 191 | + |
| 192 | +// SetPort returns the Port |
| 193 | +func (in *DefaultControllerConfiguration) SetPort(port *int) { |
| 194 | + in.Spec.Port = port |
| 195 | +} |
| 196 | + |
| 197 | +// SetHost returns the Host |
| 198 | +func (in *DefaultControllerConfiguration) SetHost(host string) { |
| 199 | + in.Spec.Host = host |
| 200 | +} |
| 201 | + |
| 202 | +// SetCertDir returns the CertDir |
| 203 | +func (in *DefaultControllerConfiguration) SetCertDir(certDir string) { |
| 204 | + in.Spec.CertDir = certDir |
| 205 | +} |
0 commit comments