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
0f851bfa
Commit
0f851bfa
authored
Feb 28, 2017
by
Jonathan MacMillan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Federation] Improve the logging and user feedback in 'kubefed init'.
parent
76889118
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
20 deletions
+35
-20
init.go
federation/pkg/kubefed/init/init.go
+35
-20
No files found.
federation/pkg/kubefed/init/init.go
View file @
0f851bfa
...
...
@@ -284,20 +284,25 @@ func (i *initFederation) Run(cmdOut io.Writer, config util.AdminConfig) error {
}
}
fmt
.
Fprint
(
cmdOut
,
"Creating a namespace for federation system components"
)
fmt
.
Fprintf
(
cmdOut
,
"Creating a namespace %s for federation system components..."
,
i
.
commonOptions
.
FederationSystemNamespace
)
glog
.
V
(
4
)
.
Infof
(
"Creating a namespace %s for federation system components"
,
i
.
commonOptions
.
FederationSystemNamespace
)
_
,
err
=
createNamespace
(
hostClientset
,
i
.
commonOptions
.
Name
,
i
.
commonOptions
.
FederationSystemNamespace
,
i
.
options
.
dryRun
)
if
err
!=
nil
{
return
err
}
fmt
.
Fprint
(
cmdOut
,
" done
\n
"
)
fmt
.
Fprint
(
cmdOut
,
"Creating federation control plane objects (service, credentials, persistent volume claim)"
)
svc
,
ips
,
hostnames
,
err
:=
createService
(
hostClientset
,
i
.
commonOptions
.
FederationSystemNamespace
,
serverName
,
i
.
commonOptions
.
Name
,
i
.
options
.
apiServerAdvertiseAddress
,
i
.
options
.
apiServerServiceType
,
i
.
options
.
dryRun
)
fmt
.
Fprintln
(
cmdOut
,
" done"
)
fmt
.
Fprint
(
cmdOut
,
"Creating federation control plane service..."
)
glog
.
V
(
4
)
.
Info
(
"Creating federation control plane service"
)
svc
,
ips
,
hostnames
,
err
:=
createService
(
cmdOut
,
hostClientset
,
i
.
commonOptions
.
FederationSystemNamespace
,
serverName
,
i
.
commonOptions
.
Name
,
i
.
options
.
apiServerAdvertiseAddress
,
i
.
options
.
apiServerServiceType
,
i
.
options
.
dryRun
)
if
err
!=
nil
{
return
err
}
fmt
.
Fprintln
(
cmdOut
,
" done"
)
glog
.
V
(
4
)
.
Infof
(
"Created service named %s with IP addresses %v, hostnames %v"
,
svc
.
Name
,
ips
,
hostnames
)
fmt
.
Fprint
(
cmdOut
,
"Creating federation control plane objects (credentials, persistent volume claim)..."
)
glog
.
V
(
4
)
.
Info
(
"Generating TLS certificates and credentials for communicating with the federation API server"
)
credentials
,
err
:=
generateCredentials
(
i
.
commonOptions
.
FederationSystemNamespace
,
i
.
commonOptions
.
Name
,
svc
.
Name
,
HostClusterLocalDNSZoneName
,
serverCredName
,
ips
,
hostnames
,
i
.
options
.
apiServerEnableHTTPBasicAuth
,
i
.
options
.
apiServerEnableTokenAuth
,
i
.
options
.
dryRun
)
if
err
!=
nil
{
...
...
@@ -316,7 +321,7 @@ func (i *initFederation) Run(cmdOut io.Writer, config util.AdminConfig) error {
if
err
!=
nil
{
return
err
}
glog
.
V
(
4
)
.
Info
(
"
kubeconfig successfully upd
ated"
)
glog
.
V
(
4
)
.
Info
(
"
Credentials secret successfully cre
ated"
)
glog
.
V
(
4
)
.
Info
(
"Creating a persistent volume and a claim to store the federation API server's state, including etcd data"
)
var
pvc
*
api
.
PersistentVolumeClaim
...
...
@@ -327,7 +332,7 @@ func (i *initFederation) Run(cmdOut io.Writer, config util.AdminConfig) error {
}
}
glog
.
V
(
4
)
.
Info
(
"Persistent volume and claim created"
)
fmt
.
Fprint
(
cmdOut
,
" done
\n
"
)
fmt
.
Fprint
ln
(
cmdOut
,
" done
"
)
// Since only one IP address can be specified as advertise address,
// we arbitrarily pick the first available IP address
...
...
@@ -337,7 +342,8 @@ func (i *initFederation) Run(cmdOut io.Writer, config util.AdminConfig) error {
advertiseAddress
=
ips
[
0
]
}
fmt
.
Fprint
(
cmdOut
,
"Creating federation component deployments"
)
fmt
.
Fprint
(
cmdOut
,
"Creating federation component deployments..."
)
glog
.
V
(
4
)
.
Info
(
"Creating federation control plane components"
)
_
,
err
=
createAPIServer
(
hostClientset
,
i
.
commonOptions
.
FederationSystemNamespace
,
serverName
,
i
.
commonOptions
.
Name
,
i
.
options
.
image
,
advertiseAddress
,
serverCredName
,
i
.
options
.
apiServerEnableHTTPBasicAuth
,
i
.
options
.
apiServerEnableTokenAuth
,
i
.
options
.
apiServerOverrides
,
pvc
,
i
.
options
.
dryRun
)
if
err
!=
nil
{
return
err
...
...
@@ -378,9 +384,10 @@ func (i *initFederation) Run(cmdOut io.Writer, config util.AdminConfig) error {
return
err
}
glog
.
V
(
4
)
.
Info
(
"Successfully created federation controller manager deployment"
)
fmt
.
Fprint
(
cmdOut
,
" done
\n
"
)
fmt
.
Println
(
cmdOut
,
" done
"
)
fmt
.
Fprint
(
cmdOut
,
"Updating kubeconfig "
)
fmt
.
Fprint
(
cmdOut
,
"Updating kubeconfig..."
)
glog
.
V
(
4
)
.
Info
(
"Updating kubeconfig"
)
// Pick the first ip/hostname to update the api server endpoint in kubeconfig and also to give information to user
// In case of NodePort Service for api server, ips are node external ips.
endpoint
:=
""
...
...
@@ -396,25 +403,30 @@ func (i *initFederation) Run(cmdOut io.Writer, config util.AdminConfig) error {
err
=
updateKubeconfig
(
config
,
i
.
commonOptions
.
Name
,
endpoint
,
i
.
commonOptions
.
Kubeconfig
,
credentials
,
i
.
options
.
dryRun
)
if
err
!=
nil
{
glog
.
V
(
4
)
.
Infof
(
"Failed to update kubeconfig: %v"
,
err
)
return
err
}
fmt
.
Fprint
(
cmdOut
,
" done
\n
"
)
fmt
.
Fprintln
(
cmdOut
,
" done"
)
glog
.
V
(
4
)
.
Info
(
"Successfully updated kubeconfig"
)
if
!
i
.
options
.
dryRun
{
fmt
.
Fprint
(
cmdOut
,
"Waiting for federation control plane to come up "
)
fmt
.
Fprint
(
cmdOut
,
"Waiting for federation control plane to come up..."
)
glog
.
V
(
4
)
.
Info
(
"Waiting for federation control plane to come up"
)
fedPods
:=
[]
string
{
serverName
,
cmName
}
err
=
waitForPods
(
hostClientset
,
fedPods
,
i
.
commonOptions
.
FederationSystemNamespace
)
err
=
waitForPods
(
cmdOut
,
hostClientset
,
fedPods
,
i
.
commonOptions
.
FederationSystemNamespace
)
if
err
!=
nil
{
return
err
}
err
=
waitSrvHealthy
(
config
,
i
.
commonOptions
.
Name
,
i
.
commonOptions
.
Kubeconfig
)
fmt
.
Fprint
(
cmdOut
,
" done
\n
"
)
err
=
waitSrvHealthy
(
cmdOut
,
config
,
i
.
commonOptions
.
Name
,
i
.
commonOptions
.
Kubeconfig
)
if
err
!=
nil
{
return
err
}
glog
.
V
(
4
)
.
Info
(
"Federation control plane running"
)
fmt
.
Fprintln
(
cmdOut
,
" done"
)
return
printSuccess
(
cmdOut
,
ips
,
hostnames
,
svc
)
}
_
,
err
=
fmt
.
Fprintf
(
cmdOut
,
"Federation control plane runs (dry run)
\n
"
)
_
,
err
=
fmt
.
Fprintln
(
cmdOut
,
"Federation control plane runs (dry run)"
)
glog
.
V
(
4
)
.
Info
(
"Federation control plane runs (dry run)"
)
return
err
}
...
...
@@ -433,7 +445,7 @@ func createNamespace(clientset client.Interface, federationName, namespace strin
return
clientset
.
Core
()
.
Namespaces
()
.
Create
(
ns
)
}
func
createService
(
clientset
client
.
Interface
,
namespace
,
svcName
,
federationName
,
apiserverAdvertiseAddress
string
,
apiserverServiceType
v1
.
ServiceType
,
dryRun
bool
)
(
*
api
.
Service
,
[]
string
,
[]
string
,
error
)
{
func
createService
(
c
mdOut
io
.
Writer
,
c
lientset
client
.
Interface
,
namespace
,
svcName
,
federationName
,
apiserverAdvertiseAddress
string
,
apiserverServiceType
v1
.
ServiceType
,
dryRun
bool
)
(
*
api
.
Service
,
[]
string
,
[]
string
,
error
)
{
svc
:=
&
api
.
Service
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
svcName
,
...
...
@@ -465,7 +477,7 @@ func createService(clientset client.Interface, namespace, svcName, federationNam
ips
:=
[]
string
{}
hostnames
:=
[]
string
{}
if
apiserverServiceType
==
v1
.
ServiceTypeLoadBalancer
{
ips
,
hostnames
,
err
=
waitForLoadBalancerAddress
(
clientset
,
svc
,
dryRun
)
ips
,
hostnames
,
err
=
waitForLoadBalancerAddress
(
c
mdOut
,
c
lientset
,
svc
,
dryRun
)
}
else
{
if
apiserverAdvertiseAddress
!=
""
{
ips
=
append
(
ips
,
apiserverAdvertiseAddress
)
...
...
@@ -504,7 +516,7 @@ func getClusterNodeIPs(clientset client.Interface) ([]string, error) {
return
nodeAddresses
,
nil
}
func
waitForLoadBalancerAddress
(
clientset
client
.
Interface
,
svc
*
api
.
Service
,
dryRun
bool
)
([]
string
,
[]
string
,
error
)
{
func
waitForLoadBalancerAddress
(
c
mdOut
io
.
Writer
,
c
lientset
client
.
Interface
,
svc
*
api
.
Service
,
dryRun
bool
)
([]
string
,
[]
string
,
error
)
{
ips
:=
[]
string
{}
hostnames
:=
[]
string
{}
...
...
@@ -513,6 +525,7 @@ func waitForLoadBalancerAddress(clientset client.Interface, svc *api.Service, dr
}
err
:=
wait
.
PollImmediateInfinite
(
lbAddrRetryInterval
,
func
()
(
bool
,
error
)
{
fmt
.
Fprint
(
cmdOut
,
"."
)
pollSvc
,
err
:=
clientset
.
Core
()
.
Services
(
svc
.
Namespace
)
.
Get
(
svc
.
Name
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
false
,
nil
...
...
@@ -968,8 +981,9 @@ func argMapsToArgStrings(argsMap, overrides map[string]string) []string {
return
args
}
func
waitForPods
(
clientset
client
.
Interface
,
fedPods
[]
string
,
namespace
string
)
error
{
func
waitForPods
(
c
mdOut
io
.
Writer
,
c
lientset
client
.
Interface
,
fedPods
[]
string
,
namespace
string
)
error
{
err
:=
wait
.
PollInfinite
(
podWaitInterval
,
func
()
(
bool
,
error
)
{
fmt
.
Fprint
(
cmdOut
,
"."
)
podCheck
:=
len
(
fedPods
)
podList
,
err
:=
clientset
.
Core
()
.
Pods
(
namespace
)
.
List
(
metav1
.
ListOptions
{})
if
err
!=
nil
{
...
...
@@ -991,13 +1005,14 @@ func waitForPods(clientset client.Interface, fedPods []string, namespace string)
return
err
}
func
waitSrvHealthy
(
config
util
.
AdminConfig
,
context
,
kubeconfig
string
)
error
{
func
waitSrvHealthy
(
c
mdOut
io
.
Writer
,
c
onfig
util
.
AdminConfig
,
context
,
kubeconfig
string
)
error
{
fedClientSet
,
err
:=
config
.
FederationClientset
(
context
,
kubeconfig
)
if
err
!=
nil
{
return
err
}
fedDiscoveryClient
:=
fedClientSet
.
Discovery
()
err
=
wait
.
PollInfinite
(
podWaitInterval
,
func
()
(
bool
,
error
)
{
fmt
.
Fprint
(
cmdOut
,
"."
)
body
,
err
:=
fedDiscoveryClient
.
RESTClient
()
.
Get
()
.
AbsPath
(
"/healthz"
)
.
Do
()
.
Raw
()
if
err
!=
nil
{
return
false
,
nil
...
...
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