@@ -44,6 +44,11 @@ type APIServer struct {
44
44
//
45
45
// If not specified, the minimal set of arguments to run the APIServer will
46
46
// be used.
47
+ //
48
+ // They will be loaded into the same argument set as Configure. Each flag
49
+ // will be Append-ed to the configured arguments just before launch.
50
+ //
51
+ // Deprecated: use Configure instead.
47
52
Args []string
48
53
49
54
// CertDir is a path to a directory containing whatever certificates the
@@ -72,20 +77,34 @@ type APIServer struct {
72
77
Err io.Writer
73
78
74
79
processState * process.State
80
+
81
+ // args contains the structured arguments to use for running the API server
82
+ // Lazily initialized by .Configure(), Defaulted eventually with .defaultArgs()
83
+ args * process.Arguments
84
+ }
85
+
86
+ // Configure returns Arguments that may be used to customize the
87
+ // flags used to launch the API server. A set of defaults will
88
+ // be applied underneath.
89
+ func (s * APIServer ) Configure () * process.Arguments {
90
+ if s .args == nil {
91
+ s .args = process .EmptyArguments ()
92
+ }
93
+ return s .args
75
94
}
76
95
77
96
// Start starts the apiserver, waits for it to come up, and returns an error,
78
97
// if occurred.
79
98
func (s * APIServer ) Start () error {
80
99
if s .processState == nil {
81
- if err := s .setState (); err != nil {
100
+ if err := s .setProcessState (); err != nil {
82
101
return err
83
102
}
84
103
}
85
104
return s .processState .Start (s .Out , s .Err )
86
105
}
87
106
88
- func (s * APIServer ) setState () error {
107
+ func (s * APIServer ) setProcessState () error {
89
108
if s .EtcdURL == nil {
90
109
return fmt .Errorf ("expected EtcdURL to be configured" )
91
110
}
@@ -133,15 +152,42 @@ func (s *APIServer) setState() error {
133
152
return err
134
153
}
135
154
136
- args := s .Args
137
- if len (args ) == 0 {
138
- args = APIServerDefaultArgs
139
- }
140
-
141
- s .processState .Args , err = process .RenderTemplates (args , s )
155
+ s .processState .Args , err = process .TemplateAndArguments (s .Args , s .Configure (), process.TemplateDefaults {
156
+ Data : s ,
157
+ Defaults : s .defaultArgs (),
158
+ // as per kubernetes-sigs/controller-runtime#641, we need this (we
159
+ // probably need other stuff too, but this is the only thing that was
160
+ // previously considered a "minimal default")
161
+ MinimalDefaults : map [string ][]string {
162
+ "service-cluster-ip-range" : []string {"10.0.0.0/24" },
163
+ },
164
+ })
142
165
return err
143
166
}
144
167
168
+ func (s * APIServer ) defaultArgs () map [string ][]string {
169
+ args := map [string ][]string {
170
+ "advertise-address" : []string {"127.0.0.1" },
171
+ "service-cluster-ip-range" : []string {"10.0.0.0/24" },
172
+ "allow-privileged" : []string {"true" },
173
+ // we're keeping this disabled because if enabled, default SA is
174
+ // missing which would force all tests to create one in normal
175
+ // apiserver operation this SA is created by controller, but that is
176
+ // not run in integration environment
177
+ "disable-admission-plugins" : []string {"ServiceAccount" },
178
+ "cert-dir" : []string {s .CertDir },
179
+ "secure-port" : []string {strconv .Itoa (s .SecurePort )},
180
+ }
181
+ if s .EtcdURL != nil {
182
+ args ["etcd-servers" ] = []string {s .EtcdURL .String ()}
183
+ }
184
+ if s .URL != nil {
185
+ args ["insecure-port" ] = []string {s .URL .Port ()}
186
+ args ["insecure-bind-address" ] = []string {s .URL .Hostname ()}
187
+ }
188
+ return args
189
+ }
190
+
145
191
func (s * APIServer ) populateAPIServerCerts () error {
146
192
_ , statErr := os .Stat (filepath .Join (s .CertDir , "apiserver.crt" ))
147
193
if ! os .IsNotExist (statErr ) {
0 commit comments