-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove k8s.io/kubernetes dependency for yurt-controller-manager
- Loading branch information
Showing
23 changed files
with
2,492 additions
and
63 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
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
52 changes: 52 additions & 0 deletions
52
pkg/controller/kubernetes/client/leaderelectionconfig/config.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2017 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 leaderelectionconfig | ||
|
||
import ( | ||
"github.com/spf13/pflag" | ||
componentbaseconfig "k8s.io/component-base/config" | ||
) | ||
|
||
// BindFlags binds the LeaderElectionConfiguration struct fields to a flagset | ||
func BindFlags(l *componentbaseconfig.LeaderElectionConfiguration, fs *pflag.FlagSet) { | ||
fs.BoolVar(&l.LeaderElect, "leader-elect", l.LeaderElect, ""+ | ||
"Start a leader election client and gain leadership before "+ | ||
"executing the main loop. Enable this when running replicated "+ | ||
"components for high availability.") | ||
fs.DurationVar(&l.LeaseDuration.Duration, "leader-elect-lease-duration", l.LeaseDuration.Duration, ""+ | ||
"The duration that non-leader candidates will wait after observing a leadership "+ | ||
"renewal until attempting to acquire leadership of a led but unrenewed leader "+ | ||
"slot. This is effectively the maximum duration that a leader can be stopped "+ | ||
"before it is replaced by another candidate. This is only applicable if leader "+ | ||
"election is enabled.") | ||
fs.DurationVar(&l.RenewDeadline.Duration, "leader-elect-renew-deadline", l.RenewDeadline.Duration, ""+ | ||
"The interval between attempts by the acting master to renew a leadership slot "+ | ||
"before it stops leading. This must be less than or equal to the lease duration. "+ | ||
"This is only applicable if leader election is enabled.") | ||
fs.DurationVar(&l.RetryPeriod.Duration, "leader-elect-retry-period", l.RetryPeriod.Duration, ""+ | ||
"The duration the clients should wait between attempting acquisition and renewal "+ | ||
"of a leadership. This is only applicable if leader election is enabled.") | ||
fs.StringVar(&l.ResourceLock, "leader-elect-resource-lock", l.ResourceLock, ""+ | ||
"The type of resource object that is used for locking during "+ | ||
"leader election. Supported options are `endpoints` (default) and `configmaps`.") | ||
fs.StringVar(&l.ResourceName, "leader-elect-resource-name", l.ResourceName, ""+ | ||
"The name of resource object that is used for locking during "+ | ||
"leader election.") | ||
fs.StringVar(&l.ResourceNamespace, "leader-elect-resource-namespace", l.ResourceNamespace, ""+ | ||
"The namespace of resource object that is used for locking during "+ | ||
"leader election.") | ||
} |
80 changes: 80 additions & 0 deletions
80
pkg/controller/kubernetes/cmd/controller-manager/app/helper.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
Copyright 2018 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 app | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
"k8s.io/apimachinery/pkg/util/sets" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
clientset "k8s.io/client-go/kubernetes" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
// WaitForAPIServer waits for the API Server's /healthz endpoint to report "ok" with timeout. | ||
func WaitForAPIServer(client clientset.Interface, timeout time.Duration) error { | ||
var lastErr error | ||
|
||
err := wait.PollImmediate(time.Second, timeout, func() (bool, error) { | ||
healthStatus := 0 | ||
result := client.Discovery().RESTClient().Get().AbsPath("/healthz").Do(context.TODO()).StatusCode(&healthStatus) | ||
if result.Error() != nil { | ||
lastErr = fmt.Errorf("failed to get apiserver /healthz status: %v", result.Error()) | ||
return false, nil | ||
} | ||
if healthStatus != http.StatusOK { | ||
content, _ := result.Raw() | ||
lastErr = fmt.Errorf("APIServer isn't healthy: %v", string(content)) | ||
klog.Warningf("APIServer isn't healthy yet: %v. Waiting a little while.", string(content)) | ||
return false, nil | ||
} | ||
|
||
return true, nil | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("%v: %v", err, lastErr) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// IsControllerEnabled check if a specified controller enabled or not. | ||
func IsControllerEnabled(name string, disabledByDefaultControllers sets.String, controllers []string) bool { | ||
hasStar := false | ||
for _, ctrl := range controllers { | ||
if ctrl == name { | ||
return true | ||
} | ||
if ctrl == "-"+name { | ||
return false | ||
} | ||
if ctrl == "*" { | ||
hasStar = true | ||
} | ||
} | ||
// if we get here, there was no explicit choice | ||
if !hasStar { | ||
// nothing on by default | ||
return false | ||
} | ||
|
||
return !disabledByDefaultControllers.Has(name) | ||
} |
Oops, something went wrong.