-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding ComponentConfig type and Options parsing
Signed-off-by: Chris Hein <me@chrishein.com>
- Loading branch information
1 parent
a11a908
commit 1c8edc7
Showing
11 changed files
with
581 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,5 @@ linters-settings: | |
|
||
run: | ||
timeout: 5m | ||
skip-files: | ||
- pkg/api/config/v1alpha1/zz_generated.deepcopy.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: controller-runtime.config.sigs.k8s.io/v1alpha1 | ||
kind: DefaultControllerConfiguration | ||
spec: | ||
port: 9443 | ||
metricsBindAddress: ":8080" | ||
leaderElection: | ||
leaderElect: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
/* | ||
The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"reflect" | ||
"time" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
configv1alpha1 "k8s.io/component-base/config/v1alpha1" | ||
) | ||
|
||
// Getters | ||
|
||
// GetSyncPeriod returns the sync period in time.Duration | ||
func (in *DefaultControllerConfiguration) GetSyncPeriod() *time.Duration { | ||
if in.Spec.SyncPeriod != nil { | ||
return &in.Spec.SyncPeriod.Duration | ||
} | ||
return nil | ||
} | ||
|
||
// GetLeaderElection returns the LeaderElection | ||
func (in *DefaultControllerConfiguration) GetLeaderElection() *bool { | ||
return in.Spec.LeaderElection.LeaderElect | ||
} | ||
|
||
// GetLeaderElectionNamespace returns the LeaderElectionNamespace | ||
func (in *DefaultControllerConfiguration) GetLeaderElectionNamespace() string { | ||
return in.Spec.LeaderElection.ResourceNamespace | ||
} | ||
|
||
// GetLeaderElectionID returns the LeaderElectionID | ||
func (in *DefaultControllerConfiguration) GetLeaderElectionID() string { | ||
return in.Spec.LeaderElection.ResourceName | ||
} | ||
|
||
// GetLeaseDuration returns the LeaseDuration | ||
func (in *DefaultControllerConfiguration) GetLeaseDuration() *time.Duration { | ||
return &in.Spec.LeaderElection.LeaseDuration.Duration | ||
} | ||
|
||
// GetRenewDeadline returns the RenewDeadline | ||
func (in *DefaultControllerConfiguration) GetRenewDeadline() *time.Duration { | ||
return &in.Spec.LeaderElection.RenewDeadline.Duration | ||
} | ||
|
||
// GetRetryPeriod returns the RetryPeriod | ||
func (in *DefaultControllerConfiguration) GetRetryPeriod() *time.Duration { | ||
return &in.Spec.LeaderElection.RetryPeriod.Duration | ||
} | ||
|
||
// GetNamespace returns the Namespace | ||
func (in *DefaultControllerConfiguration) GetNamespace() string { | ||
return in.Spec.Namespace | ||
} | ||
|
||
// GetMetricsBindAddress returns the MetricsBindAddress | ||
func (in *DefaultControllerConfiguration) GetMetricsBindAddress() string { | ||
return in.Spec.MetricsBindAddress | ||
} | ||
|
||
// GetHealthProbeBindAddress returns the HealthProbeBindAddress | ||
func (in *DefaultControllerConfiguration) GetHealthProbeBindAddress() string { | ||
return in.Spec.Health.HealthProbeBindAddress | ||
} | ||
|
||
// GetReadinessEndpointName returns the ReadinessEndpointName | ||
func (in *DefaultControllerConfiguration) GetReadinessEndpointName() string { | ||
return in.Spec.Health.ReadinessEndpointName | ||
} | ||
|
||
// GetLivenessEndpointName returns the LivenessEndpointName | ||
func (in *DefaultControllerConfiguration) GetLivenessEndpointName() string { | ||
return in.Spec.Health.LivenessEndpointName | ||
} | ||
|
||
// GetPort returns the Port | ||
func (in *DefaultControllerConfiguration) GetPort() *int { | ||
return in.Spec.Port | ||
} | ||
|
||
// GetHost returns the Host | ||
func (in *DefaultControllerConfiguration) GetHost() string { | ||
return in.Spec.Host | ||
} | ||
|
||
// GetCertDir returns the CertDir | ||
func (in *DefaultControllerConfiguration) GetCertDir() string { | ||
return in.Spec.CertDir | ||
} | ||
|
||
// Setters | ||
|
||
// SetSyncPeriod sets the sync period in time.Duration | ||
func (in *DefaultControllerConfiguration) SetSyncPeriod(syncPeriod *metav1.Duration) { | ||
in.Spec.SyncPeriod = syncPeriod | ||
} | ||
|
||
// SetLeaderElectionConfiguration sets the leader election configuration | ||
func (in *DefaultControllerConfiguration) SetLeaderElectionConfiguration(leaderElection configv1alpha1.LeaderElectionConfiguration) { | ||
in.Spec.LeaderElection = leaderElection | ||
} | ||
|
||
// SetLeaderElection sets the LeaderElection config | ||
func (in *DefaultControllerConfiguration) SetLeaderElection(leaderElection bool) { | ||
if reflect.DeepEqual(in.Spec.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { | ||
in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) | ||
} | ||
in.Spec.LeaderElection.LeaderElect = &leaderElection | ||
} | ||
|
||
// SetLeaderElectionNamespace returns the LeaderElectionNamespace | ||
func (in *DefaultControllerConfiguration) SetLeaderElectionNamespace(resourceNamespace string) { | ||
if reflect.DeepEqual(in.Spec.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { | ||
in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) | ||
} | ||
in.Spec.LeaderElection.ResourceNamespace = resourceNamespace | ||
} | ||
|
||
// SetLeaderElectionID returns the LeaderElectionID | ||
func (in *DefaultControllerConfiguration) SetLeaderElectionID(resourceName string) { | ||
if reflect.DeepEqual(in.Spec.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { | ||
in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) | ||
} | ||
in.Spec.LeaderElection.ResourceName = resourceName | ||
} | ||
|
||
// SetLeaseDuration returns the LeaseDuration | ||
func (in *DefaultControllerConfiguration) SetLeaseDuration(leaseDuration metav1.Duration) { | ||
if reflect.DeepEqual(in.Spec.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { | ||
in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) | ||
} | ||
in.Spec.LeaderElection.LeaseDuration = leaseDuration | ||
} | ||
|
||
// SetRenewDeadline returns the RenewDeadline | ||
func (in *DefaultControllerConfiguration) SetRenewDeadline(renewDeadline metav1.Duration) { | ||
if reflect.DeepEqual(in.Spec.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { | ||
in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) | ||
} | ||
in.Spec.LeaderElection.RenewDeadline = renewDeadline | ||
} | ||
|
||
// SetRetryPeriod returns the RetryPeriod | ||
func (in *DefaultControllerConfiguration) SetRetryPeriod(retryPeriod metav1.Duration) { | ||
if reflect.DeepEqual(in.Spec.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { | ||
in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) | ||
} | ||
in.Spec.LeaderElection.RetryPeriod = retryPeriod | ||
} | ||
|
||
// SetNamespace returns the Namespace | ||
func (in *DefaultControllerConfiguration) SetNamespace(namespace string) { | ||
in.Spec.Namespace = namespace | ||
} | ||
|
||
// SetMetricsBindAddress returns the MetricsBindAddress | ||
func (in *DefaultControllerConfiguration) SetMetricsBindAddress(metricsBindAddress string) { | ||
in.Spec.MetricsBindAddress = metricsBindAddress | ||
} | ||
|
||
// SetHealthProbeBindAddress returns the HealthProbeBindAddress | ||
func (in *DefaultControllerConfiguration) SetHealthProbeBindAddress(healthProbeBindAddress string) { | ||
in.Spec.Health.HealthProbeBindAddress = healthProbeBindAddress | ||
} | ||
|
||
// SetReadinessEndpointName returns the ReadinessEndpointName | ||
func (in *DefaultControllerConfiguration) SetReadinessEndpointName(readinessEndpointName string) { | ||
in.Spec.Health.ReadinessEndpointName = readinessEndpointName | ||
} | ||
|
||
// SetLivenessEndpointName returns the LivenessEndpointName | ||
func (in *DefaultControllerConfiguration) SetLivenessEndpointName(livenessEndpointName string) { | ||
in.Spec.Health.LivenessEndpointName = livenessEndpointName | ||
} | ||
|
||
// SetPort returns the Port | ||
func (in *DefaultControllerConfiguration) SetPort(port *int) { | ||
in.Spec.Port = port | ||
} | ||
|
||
// SetHost returns the Host | ||
func (in *DefaultControllerConfiguration) SetHost(host string) { | ||
in.Spec.Host = host | ||
} | ||
|
||
// SetCertDir returns the CertDir | ||
func (in *DefaultControllerConfiguration) SetCertDir(certDir string) { | ||
in.Spec.CertDir = certDir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package v1alpha1 provides a default ComponentConfig type for configuring | ||
// controller-runtime Options. | ||
// +kubebuilder:object:generate=true | ||
package v1alpha1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/scheme" | ||
) | ||
|
||
var ( | ||
// GroupVersion is group version used to register these objects | ||
GroupVersion = schema.GroupVersion{Group: "controller-runtime.sigs.k8s.io", Version: "v1alpha1"} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} | ||
|
||
// AddToScheme adds the types in this group-version to the given scheme. | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) |
Oops, something went wrong.