move last openshift-controller-manager to staging
@@ -2,23 +2,25 @@ package openshift_network_controller
import (
"context"
+ "fmt"
+ "net/http"
"os"
-
- "k8s.io/klog"
+ "time"
"k8s.io/api/core/v1"
+ "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
"k8s.io/client-go/tools/record"
+ "k8s.io/klog"
"k8s.io/kubernetes/pkg/api/legacyscheme"
configv1 "github.com/openshift/api/config/v1"
leaderelectionconverter "github.com/openshift/library-go/pkg/config/leaderelection"
"github.com/openshift/library-go/pkg/serviceability"
- "github.com/openshift/origin/pkg/cmd/openshift-controller-manager"
sdnmaster "github.com/openshift/origin/pkg/network/master"
// for metrics
@@ -39,7 +41,7 @@ func RunOpenShiftNetworkController() error {
}
originControllerManager := func(ctx context.Context) {
- if err := openshift_controller_manager.WaitForHealthyAPIServer(kubeClient.Discovery().RESTClient()); err != nil {
+ if err := WaitForHealthyAPIServer(kubeClient.Discovery().RESTClient()); err != nil {
klog.Fatal(err)
}
@@ -98,3 +100,26 @@ func RunOpenShiftNetworkController() error {
return nil
}
+
+func WaitForHealthyAPIServer(client rest.Interface) error {
+ var healthzContent string
+ // If apiserver is not running we should wait for some time and fail only then. This is particularly
+ // important when we start apiserver and controller manager at the same time.
+ err := wait.PollImmediate(time.Second, 5*time.Minute, func() (bool, error) {
+ healthStatus := 0
+ resp := client.Get().AbsPath("/healthz").Do().StatusCode(&healthStatus)
+ if healthStatus != http.StatusOK {
+ klog.Errorf("Server isn't healthy yet. Waiting a little while.")
+ return false, nil
+ }
+ content, _ := resp.Raw()
+ healthzContent = string(content)
+
+ return true, nil
+ })
+ if err != nil {
+ return fmt.Errorf("server unhealthy: %v: %v", healthzContent, err)
+ }
+
+ return nil
+}
