Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
97be082f
Commit
97be082f
authored
Feb 26, 2018
by
hzxuzhonghu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cloud-controller-manager get /healthz instead of calling…
cloud-controller-manager get /healthz instead of calling restclient.ServerAPIVersions to wait for apiserver being healthy
parent
6a7656b6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
38 deletions
+65
-38
controllermanager.go
cmd/cloud-controller-manager/app/controllermanager.go
+2
-8
helper.go
cmd/controller-manager/app/helper.go
+55
-0
controllermanager.go
cmd/kube-controller-manager/app/controllermanager.go
+8
-30
No files found.
cmd/cloud-controller-manager/app/controllermanager.go
View file @
97be082f
...
@@ -260,15 +260,9 @@ func startControllers(c *cloudcontrollerconfig.CompletedConfig, kubeconfig *rest
...
@@ -260,15 +260,9 @@ func startControllers(c *cloudcontrollerconfig.CompletedConfig, kubeconfig *rest
// If apiserver is not running we should wait for some time and fail only then. This is particularly
// 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.
// important when we start apiserver and controller manager at the same time.
err
=
wait
.
PollImmediate
(
time
.
Second
,
10
*
time
.
Second
,
func
()
(
bool
,
error
)
{
err
=
genericcontrollermanager
.
WaitForAPIServer
(
versionedClient
,
10
*
time
.
Second
)
if
_
,
err
=
restclient
.
ServerAPIVersions
(
kubeconfig
);
err
==
nil
{
return
true
,
nil
}
glog
.
Errorf
(
"Failed to get api versions from server: %v"
,
err
)
return
false
,
nil
})
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"Failed to
get api versions from server
: %v"
,
err
)
glog
.
Fatalf
(
"Failed to
wait for apiserver being healthy
: %v"
,
err
)
}
}
sharedInformers
.
Start
(
stop
)
sharedInformers
.
Start
(
stop
)
...
...
cmd/controller-manager/app/helper.go
0 → 100644
View file @
97be082f
/*
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
(
"fmt"
"net/http"
"time"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/wait"
clientset
"k8s.io/client-go/kubernetes"
)
// 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
()
.
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
))
glog
.
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
}
cmd/kube-controller-manager/app/controllermanager.go
View file @
97be082f
...
@@ -24,7 +24,6 @@ import (
...
@@ -24,7 +24,6 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"math/rand"
"math/rand"
"net/http"
"os"
"os"
"time"
"time"
...
@@ -36,7 +35,6 @@ import (
...
@@ -36,7 +35,6 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/discovery"
"k8s.io/client-go/informers"
"k8s.io/client-go/informers"
restclient
"k8s.io/client-go/rest"
restclient
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection"
...
@@ -350,34 +348,8 @@ func NewControllerInitializers(loopMode ControllerLoopMode) map[string]InitFunc
...
@@ -350,34 +348,8 @@ func NewControllerInitializers(loopMode ControllerLoopMode) map[string]InitFunc
// users don't have to restart their controller manager if they change the apiserver.
// users don't have to restart their controller manager if they change the apiserver.
// Until we get there, the structure here needs to be exposed for the construction of a proper ControllerContext.
// Until we get there, the structure here needs to be exposed for the construction of a proper ControllerContext.
func
GetAvailableResources
(
clientBuilder
controller
.
ControllerClientBuilder
)
(
map
[
schema
.
GroupVersionResource
]
bool
,
error
)
{
func
GetAvailableResources
(
clientBuilder
controller
.
ControllerClientBuilder
)
(
map
[
schema
.
GroupVersionResource
]
bool
,
error
)
{
var
discoveryClient
discovery
.
DiscoveryInterface
client
:=
clientBuilder
.
ClientOrDie
(
"controller-discovery"
)
discoveryClient
:=
client
.
Discovery
()
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
,
10
*
time
.
Second
,
func
()
(
bool
,
error
)
{
client
,
err
:=
clientBuilder
.
Client
(
"controller-discovery"
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to get api versions from server: %v"
,
err
)
return
false
,
nil
}
healthStatus
:=
0
resp
:=
client
.
Discovery
()
.
RESTClient
()
.
Get
()
.
AbsPath
(
"/healthz"
)
.
Do
()
.
StatusCode
(
&
healthStatus
)
if
healthStatus
!=
http
.
StatusOK
{
glog
.
Errorf
(
"Server isn't healthy yet. Waiting a little while."
)
return
false
,
nil
}
content
,
_
:=
resp
.
Raw
()
healthzContent
=
string
(
content
)
discoveryClient
=
client
.
Discovery
()
return
true
,
nil
})
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to get api versions from server: %v: %v"
,
healthzContent
,
err
)
}
resourceMap
,
err
:=
discoveryClient
.
ServerResources
()
resourceMap
,
err
:=
discoveryClient
.
ServerResources
()
if
err
!=
nil
{
if
err
!=
nil
{
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"unable to get all supported resources from server: %v"
,
err
))
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"unable to get all supported resources from server: %v"
,
err
))
...
@@ -407,6 +379,12 @@ func CreateControllerContext(s *config.CompletedConfig, rootClientBuilder, clien
...
@@ -407,6 +379,12 @@ func CreateControllerContext(s *config.CompletedConfig, rootClientBuilder, clien
versionedClient
:=
rootClientBuilder
.
ClientOrDie
(
"shared-informers"
)
versionedClient
:=
rootClientBuilder
.
ClientOrDie
(
"shared-informers"
)
sharedInformers
:=
informers
.
NewSharedInformerFactory
(
versionedClient
,
ResyncPeriod
(
s
)())
sharedInformers
:=
informers
.
NewSharedInformerFactory
(
versionedClient
,
ResyncPeriod
(
s
)())
// 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.
if
err
:=
genericcontrollerconfig
.
WaitForAPIServer
(
versionedClient
,
10
*
time
.
Second
);
err
!=
nil
{
return
ControllerContext
{},
fmt
.
Errorf
(
"failed to wait for apiserver being healthy: %v"
,
err
)
}
availableResources
,
err
:=
GetAvailableResources
(
rootClientBuilder
)
availableResources
,
err
:=
GetAvailableResources
(
rootClientBuilder
)
if
err
!=
nil
{
if
err
!=
nil
{
return
ControllerContext
{},
err
return
ControllerContext
{},
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment