99// GetKubeconfig is a phase to get and dump the admin kubeconfig
1010type GetKubeconfig struct {
1111 GenericPhase
12+ APIAddress string
1213}
1314
1415// Title for the phase
@@ -24,19 +25,23 @@ func (p *GetKubeconfig) Run() error {
2425 return err
2526 }
2627
27- // the controller admin.conf is aways pointing to localhost, thus we need to change the address
28- // something usable from outside
29- address := h .Address ()
30- if a , ok := p .Config .Spec .K0s .Config .Dig ("spec" , "api" , "externalAddress" ).(string ); ok {
31- address = a
32- }
28+ if p .APIAddress == "" {
29+ // the controller admin.conf is aways pointing to localhost, thus we need to change the address
30+ // something usable from outside
31+ address := h .Address ()
32+ if a , ok := p .Config .Spec .K0s .Config .Dig ("spec" , "api" , "externalAddress" ).(string ); ok {
33+ address = a
34+ }
35+
36+ port := 6443
37+ if p , ok := p .Config .Spec .K0s .Config .Dig ("spec" , "api" , "port" ).(int ); ok {
38+ port = p
39+ }
3340
34- port := 6443
35- if p , ok := p .Config .Spec .K0s .Config .Dig ("spec" , "api" , "port" ).(int ); ok {
36- port = p
41+ p .APIAddress = fmt .Sprintf ("https://%s:%d" , address , port )
3742 }
3843
39- cfgString , err := kubeConfig (output , p .Config .Metadata .Name , address , port )
44+ cfgString , err := kubeConfig (output , p .Config .Metadata .Name , p . APIAddress )
4045 if err != nil {
4146 return err
4247 }
@@ -46,15 +51,15 @@ func (p *GetKubeconfig) Run() error {
4651
4752// kubeConfig reads in the raw kubeconfig and changes the given address
4853// and cluster name into it
49- func kubeConfig (raw string , name string , address string , port int ) (string , error ) {
54+ func kubeConfig (raw string , name string , address string ) (string , error ) {
5055 cfg , err := clientcmd .Load ([]byte (raw ))
5156 if err != nil {
5257 return "" , err
5358 }
5459
5560 cfg .Clusters [name ] = cfg .Clusters ["local" ]
5661 delete (cfg .Clusters , "local" )
57- cfg .Clusters [name ].Server = fmt . Sprintf ( "https://%s:%d" , address , port )
62+ cfg .Clusters [name ].Server = address
5863
5964 cfg .Contexts [name ] = cfg .Contexts ["Default" ]
6065 delete (cfg .Contexts , "Default" )
0 commit comments