1
1
package start
2
2
3
3
import (
4
+ "fmt"
5
+ "net/http"
6
+ "time"
7
+
8
+ "github.com/golang/glog"
9
+
10
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
+ kutilerrors "k8s.io/apimachinery/pkg/util/errors"
12
+ "k8s.io/apimachinery/pkg/util/wait"
4
13
"k8s.io/client-go/rest"
5
- cmapp "k8s.io/kubernetes/cmd/kube-controller-manager/app"
6
14
cmappoptions "k8s.io/kubernetes/cmd/kube-controller-manager/app/options"
7
- "k8s.io/kubernetes/pkg/cloudprovider"
15
+ "k8s.io/kubernetes/pkg/apis/componentconfig"
16
+ kclientsetexternal "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
8
17
"k8s.io/kubernetes/pkg/controller"
9
18
10
- configapi "github.com/openshift/origin/pkg/cmd/server/api"
11
19
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
20
+ "github.com/openshift/origin/pkg/cmd/server/cm"
12
21
origincontrollers "github.com/openshift/origin/pkg/cmd/server/origin/controller"
22
+ cmdflags "github.com/openshift/origin/pkg/cmd/util/flags"
13
23
)
14
24
15
- func getControllerContext (options configapi.MasterConfig , controllerManagerOptions * cmappoptions.CMServer , cloudProvider cloudprovider.Interface , informers * informers , stopCh <- chan struct {}) (origincontrollers.ControllerContext , error ) {
16
- loopbackConfig , _ , kubeExternal , _ , err := getAllClients (options )
17
- if err != nil {
18
- return origincontrollers.ControllerContext {}, err
19
- }
25
+ func newControllerContext (
26
+ openshiftControllerOptions origincontrollers.OpenshiftControllerOptions ,
27
+ privilegedLoopbackConfig * rest.Config ,
28
+ kubeExternal kclientsetexternal.Interface ,
29
+ informers * informers ,
30
+ stopCh <- chan struct {},
31
+ ) origincontrollers.ControllerContext {
32
+
20
33
// divide up the QPS since it re-used separately for every client
21
34
// TODO, eventually make this configurable individually in some way.
22
- if loopbackConfig .QPS > 0 {
23
- loopbackConfig .QPS = loopbackConfig .QPS / 10 + 1
35
+ if privilegedLoopbackConfig .QPS > 0 {
36
+ privilegedLoopbackConfig .QPS = privilegedLoopbackConfig .QPS / 10 + 1
24
37
}
25
- if loopbackConfig .Burst > 0 {
26
- loopbackConfig .Burst = loopbackConfig .Burst / 10 + 1
27
- }
28
-
29
- rootClientBuilder := controller.SimpleControllerClientBuilder {
30
- ClientConfig : loopbackConfig ,
31
- }
32
-
33
- availableResources , err := cmapp .GetAvailableResources (rootClientBuilder )
34
- if err != nil {
35
- return origincontrollers.ControllerContext {}, err
38
+ if privilegedLoopbackConfig .Burst > 0 {
39
+ privilegedLoopbackConfig .Burst = privilegedLoopbackConfig .Burst / 10 + 1
36
40
}
37
41
38
42
openshiftControllerContext := origincontrollers.ControllerContext {
39
- KubeControllerContext : cmapp.ControllerContext {
40
- ClientBuilder : controller.SAControllerClientBuilder {
41
- ClientConfig : rest .AnonymousClientConfig (loopbackConfig ),
42
- CoreClient : kubeExternal .Core (),
43
- AuthenticationClient : kubeExternal .Authentication (),
44
- Namespace : "kube-system" ,
45
- },
46
- InformerFactory : newGenericInformers (informers ),
47
- Options : * controllerManagerOptions ,
48
- AvailableResources : availableResources ,
49
- Cloud : cloudProvider ,
50
- Stop : stopCh ,
51
- },
43
+ OpenshiftControllerOptions : openshiftControllerOptions ,
44
+
52
45
ClientBuilder : origincontrollers.OpenshiftControllerClientBuilder {
53
46
ControllerClientBuilder : controller.SAControllerClientBuilder {
54
- ClientConfig : rest .AnonymousClientConfig (loopbackConfig ),
47
+ ClientConfig : rest .AnonymousClientConfig (privilegedLoopbackConfig ),
55
48
CoreClient : kubeExternal .Core (),
56
49
AuthenticationClient : kubeExternal .Authentication (),
57
50
Namespace : bootstrappolicy .DefaultOpenShiftInfraNamespace ,
@@ -69,5 +62,68 @@ func getControllerContext(options configapi.MasterConfig, controllerManagerOptio
69
62
Stop : stopCh ,
70
63
}
71
64
72
- return openshiftControllerContext , nil
65
+ return openshiftControllerContext
66
+ }
67
+
68
+ // getOpenshiftControllerOptions parses the CLI args used by the kube-controllers (which control these options today), so that
69
+ // we can defer making the controller options structs until we have a better idea what they should look like.
70
+ // This does mean we pull in an upstream command that hopefully won't change much.
71
+ func getOpenshiftControllerOptions (args map [string ][]string ) (origincontrollers.OpenshiftControllerOptions , error ) {
72
+ cmserver := cmappoptions .NewCMServer ()
73
+ if err := cmdflags .Resolve (args , cm .OriginControllerManagerAddFlags (cmserver )); len (err ) > 0 {
74
+ return origincontrollers.OpenshiftControllerOptions {}, kutilerrors .NewAggregate (err )
75
+ }
76
+
77
+ return origincontrollers.OpenshiftControllerOptions {
78
+ HPAControllerOptions : origincontrollers.HPAControllerOptions {
79
+ SyncPeriod : cmserver .KubeControllerManagerConfiguration .HorizontalPodAutoscalerSyncPeriod ,
80
+ UpscaleForbiddenWindow : cmserver .KubeControllerManagerConfiguration .HorizontalPodAutoscalerUpscaleForbiddenWindow ,
81
+ DownscaleForbiddenWindow : cmserver .KubeControllerManagerConfiguration .HorizontalPodAutoscalerDownscaleForbiddenWindow ,
82
+ },
83
+ ResourceQuotaOptions : origincontrollers.ResourceQuotaOptions {
84
+ ConcurrentSyncs : cmserver .KubeControllerManagerConfiguration .ConcurrentResourceQuotaSyncs ,
85
+ SyncPeriod : cmserver .KubeControllerManagerConfiguration .ResourceQuotaSyncPeriod ,
86
+ MinResyncPeriod : cmserver .KubeControllerManagerConfiguration .MinResyncPeriod ,
87
+ },
88
+ ServiceAccountTokenOptions : origincontrollers.ServiceAccountTokenOptions {
89
+ ConcurrentSyncs : cmserver .KubeControllerManagerConfiguration .ConcurrentSATokenSyncs ,
90
+ },
91
+ }, nil
92
+ }
93
+
94
+ // getLeaderElectionOptions parses the CLI args used by the openshift controller leader election (which control these options today), so that
95
+ // we can defer making the options structs until we have a better idea what they should look like.
96
+ // This does mean we pull in an upstream command that hopefully won't change much.
97
+ func getLeaderElectionOptions (args map [string ][]string ) (componentconfig.LeaderElectionConfiguration , error ) {
98
+ cmserver := cmappoptions .NewCMServer ()
99
+ cmserver .LeaderElection .RetryPeriod = metav1.Duration {Duration : 3 * time .Second }
100
+
101
+ if err := cmdflags .Resolve (args , cm .OriginControllerManagerAddFlags (cmserver )); len (err ) > 0 {
102
+ return componentconfig.LeaderElectionConfiguration {}, kutilerrors .NewAggregate (err )
103
+ }
104
+
105
+ return cmserver .KubeControllerManagerConfiguration .LeaderElection , nil
106
+ }
107
+
108
+ func waitForHealthyAPIServer (client rest.Interface ) error {
109
+ var healthzContent string
110
+ // If apiserver is not running we should wait for some time and fail only then. This is particularly
111
+ // important when we start apiserver and controller manager at the same time.
112
+ err := wait .PollImmediate (time .Second , 5 * time .Minute , func () (bool , error ) {
113
+ healthStatus := 0
114
+ resp := client .Get ().AbsPath ("/healthz" ).Do ().StatusCode (& healthStatus )
115
+ if healthStatus != http .StatusOK {
116
+ glog .Errorf ("Server isn't healthy yet. Waiting a little while." )
117
+ return false , nil
118
+ }
119
+ content , _ := resp .Raw ()
120
+ healthzContent = string (content )
121
+
122
+ return true , nil
123
+ })
124
+ if err != nil {
125
+ return fmt .Errorf ("server unhealthy: %v: %v" , healthzContent , err )
126
+ }
127
+
128
+ return nil
73
129
}
0 commit comments