@@ -27,7 +27,6 @@ import (
2727 "path"
2828 "path/filepath"
2929 "runtime/debug"
30- "strconv"
3130 "strings"
3231 "sync"
3332 "syscall"
@@ -41,7 +40,6 @@ import (
4140 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4241 "k8s.io/apimachinery/pkg/runtime"
4342 "k8s.io/apimachinery/pkg/util/wait"
44- utilfeature "k8s.io/apiserver/pkg/util/feature"
4543 kubernetesscheme "k8s.io/client-go/kubernetes/scheme"
4644 "k8s.io/client-go/rest"
4745 "k8s.io/client-go/tools/clientcmd"
@@ -190,37 +188,6 @@ func newKcpServer(t TestingT, cfg Config) (*kcpServer, error) {
190188 return nil , fmt .Errorf ("could not create data dir: %w" , err )
191189 }
192190
193- kcpListenPort , err := GetFreePort (t )
194- if err != nil {
195- return nil , err
196- }
197- etcdClientPort , err := GetFreePort (t )
198- if err != nil {
199- return nil , err
200- }
201- etcdPeerPort , err := GetFreePort (t )
202- if err != nil {
203- return nil , err
204- }
205-
206- args := []string {
207- "--root-directory" , s .cfg .DataDir ,
208- "--secure-port=" + kcpListenPort ,
209- "--embedded-etcd-client-port=" + etcdClientPort ,
210- "--embedded-etcd-peer-port=" + etcdPeerPort ,
211- "--embedded-etcd-wal-size-bytes=" + strconv .Itoa (5 * 1000 ), // 5KB
212- "--kubeconfig-path=" + s .KubeconfigPath (),
213- "--feature-gates=" + fmt .Sprintf ("%s" , utilfeature .DefaultFeatureGate ),
214- "--audit-log-path" , filepath .Join (s .cfg .ArtifactDir , "kcp.audit" ),
215- "--v=4" ,
216- }
217-
218- if cfg .BindAddress != "" {
219- args = append (args , "--bind-address=" + cfg .BindAddress )
220- }
221-
222- s .cfg .Args = append (args , s .cfg .Args ... )
223-
224191 return s , nil
225192}
226193
@@ -278,7 +245,11 @@ func (c *kcpServer) Run(t TestingT) error {
278245 runner = func (ctx context.Context , t TestingT , cfg Config ) (<- chan struct {}, error ) {
279246 t .Log ("RunInProcessFunc is deprecated, please migrate to ContextRunInProcessFunc" )
280247 t .Log ("RunInProcessFunc is deprecated, stopping the server will not work" )
281- return RunInProcessFunc (t , cfg .DataDir , cfg .Args )
248+ args , err := cfg .BuildArgs (t )
249+ if err != nil {
250+ return nil , err
251+ }
252+ return RunInProcessFunc (t , cfg .DataDir , args )
282253 }
283254 }
284255 }
@@ -325,7 +296,12 @@ func (c *kcpServer) Stopped() bool {
325296}
326297
327298func runExternal (ctx context.Context , t TestingT , cfg Config ) (<- chan struct {}, error ) {
328- commandLine := append (StartKcpCommand ("KCP" ), cfg .Args ... )
299+ args , err := cfg .BuildArgs (t )
300+ if err != nil {
301+ return nil , fmt .Errorf ("failed to build kcp args: %w" , err )
302+ }
303+
304+ commandLine := append (StartKcpCommand ("KCP" ), args ... )
329305
330306 t .Logf ("running: %v" , strings .Join (commandLine , " " ))
331307
@@ -438,7 +414,7 @@ func (c *kcpServer) Name() string {
438414
439415// KubeconfigPath exposes the path of the kubeconfig file of this kcp server.
440416func (c * kcpServer ) KubeconfigPath () string {
441- return filepath . Join ( c .cfg .DataDir , "admin.kubeconfig" )
417+ return c .cfg .KubeconfigPath ( )
442418}
443419
444420// Config exposes a copy of the base client config for this server. Client-side throttling is disabled (QPS=-1).
@@ -515,35 +491,13 @@ func (c *kcpServer) RawConfig() (clientcmdapi.Config, error) {
515491}
516492
517493func (c * kcpServer ) loadCfg (ctx context.Context ) error {
518- var lastError error
519- if err := wait .PollUntilContextTimeout (ctx , 100 * time .Millisecond , 2 * time .Minute , true , func (ctx context.Context ) (bool , error ) {
520- if c .Stopped () {
521- return false , fmt .Errorf ("failed to load admin kubeconfig: server has stopped" )
522- }
523-
524- config , err := loadKubeConfig (c .KubeconfigPath (), "base" )
525- if err != nil {
526- // A missing file is likely caused by the server not
527- // having started up yet. Ignore these errors for the
528- // purposes of logging.
529- if ! os .IsNotExist (err ) {
530- lastError = err
531- }
532-
533- return false , nil
534- }
535-
536- c .lock .Lock ()
537- c .clientCfg = config
538- c .lock .Unlock ()
539-
540- return true , nil
541- }); err != nil && lastError != nil {
542- return fmt .Errorf ("failed to load admin kubeconfig: %w" , lastError )
543- } else if err != nil {
544- // should never happen
545- return fmt .Errorf ("failed to load admin kubeconfig: %w" , err )
494+ config , err := WaitLoadKubeConfig (ctx , c .KubeconfigPath (), "base" )
495+ if err != nil {
496+ return err
546497 }
498+ c .lock .Lock ()
499+ c .clientCfg = config
500+ c .lock .Unlock ()
547501 return nil
548502}
549503
0 commit comments