-
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
dfb60c9
commit ed3029e
Showing
11 changed files
with
562 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
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,6 @@ | ||
apiVersion: controller-runtime.config.sigs.k8s.io/v1alpha1 | ||
kind: GenericControllerConfiguration | ||
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 *GenericControllerConfigurationSpec) GetSyncPeriod() *time.Duration { | ||
if in.SyncPeriod != nil { | ||
return &in.SyncPeriod.Duration | ||
} | ||
return nil | ||
} | ||
|
||
// GetLeaderElection returns the LeaderElection | ||
func (in *GenericControllerConfigurationSpec) GetLeaderElection() *bool { | ||
return in.LeaderElection.LeaderElect | ||
} | ||
|
||
// GetLeaderElectionNamespace returns the LeaderElectionNamespace | ||
func (in *GenericControllerConfigurationSpec) GetLeaderElectionNamespace() string { | ||
return in.LeaderElection.ResourceNamespace | ||
} | ||
|
||
// GetLeaderElectionID returns the LeaderElectionID | ||
func (in *GenericControllerConfigurationSpec) GetLeaderElectionID() string { | ||
return in.LeaderElection.ResourceName | ||
} | ||
|
||
// GetLeaseDuration returns the LeaseDuration | ||
func (in *GenericControllerConfigurationSpec) GetLeaseDuration() *time.Duration { | ||
return &in.LeaderElection.LeaseDuration.Duration | ||
} | ||
|
||
// GetRenewDeadline returns the RenewDeadline | ||
func (in *GenericControllerConfigurationSpec) GetRenewDeadline() *time.Duration { | ||
return &in.LeaderElection.RenewDeadline.Duration | ||
} | ||
|
||
// GetRetryPeriod returns the RetryPeriod | ||
func (in *GenericControllerConfigurationSpec) GetRetryPeriod() *time.Duration { | ||
return &in.LeaderElection.RetryPeriod.Duration | ||
} | ||
|
||
// GetNamespace returns the Namespace | ||
func (in *GenericControllerConfigurationSpec) GetNamespace() string { | ||
return in.Namespace | ||
} | ||
|
||
// GetMetricsBindAddress returns the MetricsBindAddress | ||
func (in *GenericControllerConfigurationSpec) GetMetricsBindAddress() string { | ||
return in.MetricsBindAddress | ||
} | ||
|
||
// GetHealthProbeBindAddress returns the HealthProbeBindAddress | ||
func (in *GenericControllerConfigurationSpec) GetHealthProbeBindAddress() string { | ||
return in.Health.HealthProbeBindAddress | ||
} | ||
|
||
// GetReadinessEndpointName returns the ReadinessEndpointName | ||
func (in *GenericControllerConfigurationSpec) GetReadinessEndpointName() string { | ||
return in.Health.ReadinessEndpointName | ||
} | ||
|
||
// GetLivenessEndpointName returns the LivenessEndpointName | ||
func (in *GenericControllerConfigurationSpec) GetLivenessEndpointName() string { | ||
return in.Health.LivenessEndpointName | ||
} | ||
|
||
// GetPort returns the Port | ||
func (in *GenericControllerConfigurationSpec) GetPort() *int { | ||
return in.Port | ||
} | ||
|
||
// GetHost returns the Host | ||
func (in *GenericControllerConfigurationSpec) GetHost() string { | ||
return in.Host | ||
} | ||
|
||
// GetCertDir returns the CertDir | ||
func (in *GenericControllerConfigurationSpec) GetCertDir() string { | ||
return in.CertDir | ||
} | ||
|
||
// Setters | ||
|
||
// SetSyncPeriod sets the sync period in time.Duration | ||
func (in *GenericControllerConfigurationSpec) SetSyncPeriod(syncPeriod *metav1.Duration) { | ||
in.SyncPeriod = syncPeriod | ||
} | ||
|
||
// SetLeaderElectionConfiguration sets the leader election configuration | ||
func (in *GenericControllerConfigurationSpec) SetLeaderElectionConfiguration(leaderElection configv1alpha1.LeaderElectionConfiguration) { | ||
in.LeaderElection = leaderElection | ||
} | ||
|
||
// SetLeaderElection sets the LeaderElection config | ||
func (in *GenericControllerConfigurationSpec) SetLeaderElection(leaderElection bool) { | ||
if reflect.DeepEqual(in.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { | ||
in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) | ||
} | ||
in.LeaderElection.LeaderElect = &leaderElection | ||
} | ||
|
||
// SetLeaderElectionNamespace sets the LeaderElectionNamespace | ||
func (in *GenericControllerConfigurationSpec) SetLeaderElectionNamespace(resourceNamespace string) { | ||
if reflect.DeepEqual(in.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { | ||
in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) | ||
} | ||
in.LeaderElection.ResourceNamespace = resourceNamespace | ||
} | ||
|
||
// SetLeaderElectionID sets the LeaderElectionID | ||
func (in *GenericControllerConfigurationSpec) SetLeaderElectionID(resourceName string) { | ||
if reflect.DeepEqual(in.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { | ||
in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) | ||
} | ||
in.LeaderElection.ResourceName = resourceName | ||
} | ||
|
||
// SetLeaseDuration sets the LeaseDuration | ||
func (in *GenericControllerConfigurationSpec) SetLeaseDuration(leaseDuration metav1.Duration) { | ||
if reflect.DeepEqual(in.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { | ||
in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) | ||
} | ||
in.LeaderElection.LeaseDuration = leaseDuration | ||
} | ||
|
||
// SetRenewDeadline sets the RenewDeadline | ||
func (in *GenericControllerConfigurationSpec) SetRenewDeadline(renewDeadline metav1.Duration) { | ||
if reflect.DeepEqual(in.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { | ||
in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) | ||
} | ||
in.LeaderElection.RenewDeadline = renewDeadline | ||
} | ||
|
||
// SetRetryPeriod sets the RetryPeriod | ||
func (in *GenericControllerConfigurationSpec) SetRetryPeriod(retryPeriod metav1.Duration) { | ||
if reflect.DeepEqual(in.LeaderElection, configv1alpha1.LeaderElectionConfiguration{}) { | ||
in.SetLeaderElectionConfiguration(configv1alpha1.LeaderElectionConfiguration{}) | ||
} | ||
in.LeaderElection.RetryPeriod = retryPeriod | ||
} | ||
|
||
// SetNamespace sets the Namespace | ||
func (in *GenericControllerConfigurationSpec) SetNamespace(namespace string) { | ||
in.Namespace = namespace | ||
} | ||
|
||
// SetMetricsBindAddress sets the MetricsBindAddress | ||
func (in *GenericControllerConfigurationSpec) SetMetricsBindAddress(metricsBindAddress string) { | ||
in.MetricsBindAddress = metricsBindAddress | ||
} | ||
|
||
// SetHealthProbeBindAddress sets the HealthProbeBindAddress | ||
func (in *GenericControllerConfigurationSpec) SetHealthProbeBindAddress(healthProbeBindAddress string) { | ||
in.Health.HealthProbeBindAddress = healthProbeBindAddress | ||
} | ||
|
||
// SetReadinessEndpointName sets the ReadinessEndpointName | ||
func (in *GenericControllerConfigurationSpec) SetReadinessEndpointName(readinessEndpointName string) { | ||
in.Health.ReadinessEndpointName = readinessEndpointName | ||
} | ||
|
||
// SetLivenessEndpointName sets the LivenessEndpointName | ||
func (in *GenericControllerConfigurationSpec) SetLivenessEndpointName(livenessEndpointName string) { | ||
in.Health.LivenessEndpointName = livenessEndpointName | ||
} | ||
|
||
// SetPort sets the Port | ||
func (in *GenericControllerConfigurationSpec) SetPort(port *int) { | ||
in.Port = port | ||
} | ||
|
||
// SetHost sets the Host | ||
func (in *GenericControllerConfigurationSpec) SetHost(host string) { | ||
in.Host = host | ||
} | ||
|
||
// SetCertDir sets the CertDir | ||
func (in *GenericControllerConfigurationSpec) SetCertDir(certDir string) { | ||
in.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 the ComponentConfig type for configuring | ||
// controller-runtime | ||
// +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.