9
9
"path/filepath"
10
10
"strings"
11
11
"syscall"
12
+ "time"
12
13
13
14
"github.com/coreos/go-systemd/daemon"
14
15
"github.com/golang/glog"
@@ -18,11 +19,11 @@ import (
18
19
kerrors "k8s.io/apimachinery/pkg/api/errors"
19
20
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
20
21
"k8s.io/apimachinery/pkg/util/sets"
21
- "k8s.io/apimachinery/pkg/util/wait"
22
22
kubeletapp "k8s.io/kubernetes/cmd/kubelet/app"
23
23
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
24
24
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
25
25
"k8s.io/kubernetes/pkg/master/ports"
26
+ "k8s.io/kubernetes/pkg/util/interrupt"
26
27
27
28
"github.com/openshift/library-go/pkg/crypto"
28
29
"github.com/openshift/origin/pkg/cmd/server/admin"
@@ -115,14 +116,26 @@ var networkLong = templates.LongDesc(`
115
116
116
117
// NewCommandStartNetwork provides a CLI handler for 'start network' command
117
118
func NewCommandStartNetwork (basename string , out , errout io.Writer ) (* cobra.Command , * NodeOptions ) {
118
- options := & NodeOptions {Output : out }
119
+ options := & NodeOptions {
120
+ ExpireDays : crypto .DefaultCertificateLifetimeInDays ,
121
+ Output : out ,
122
+ }
119
123
120
124
cmd := & cobra.Command {
121
125
Use : "network" ,
122
126
Short : "Launch node network" ,
123
127
Long : fmt .Sprintf (networkLong , basename ),
124
128
Run : func (c * cobra.Command , args []string ) {
125
- options .Run (c , errout , args , wait .NeverStop )
129
+ ch := make (chan struct {})
130
+ interrupt .New (func (s os.Signal ) {
131
+ close (ch )
132
+ fmt .Fprintf (errout , "interrupt: Gracefully shutting down ...\n " )
133
+ time .Sleep (200 * time .Millisecond )
134
+ os .Exit (1 )
135
+ }).Run (func () error {
136
+ options .Run (c , errout , args , ch )
137
+ return nil
138
+ })
126
139
},
127
140
}
128
141
@@ -209,7 +222,7 @@ func (o NodeOptions) Complete(cmd *cobra.Command) error {
209
222
210
223
// StartNode calls RunNode and then waits forever
211
224
func (o NodeOptions ) StartNode (stopCh <- chan struct {}) error {
212
- if err := o .RunNode (); err != nil {
225
+ if err := o .RunNode (stopCh ); err != nil {
213
226
return err
214
227
}
215
228
@@ -227,7 +240,7 @@ func (o NodeOptions) StartNode(stopCh <-chan struct{}) error {
227
240
// 2. Reads fully specified node config OR builds a fully specified node config from the args
228
241
// 3. Writes the fully specified node config and exits if needed
229
242
// 4. Starts the node based on the fully specified config
230
- func (o NodeOptions ) RunNode () error {
243
+ func (o NodeOptions ) RunNode (stopCh <- chan struct {} ) error {
231
244
nodeConfig , configFile , err := o .resolveNodeConfig ()
232
245
if err != nil {
233
246
return err
@@ -277,7 +290,7 @@ func (o NodeOptions) RunNode() error {
277
290
return originnode .WriteKubeletFlags (* nodeConfig )
278
291
}
279
292
280
- return StartNode (* nodeConfig , o .NodeArgs .Components )
293
+ return StartNode (* nodeConfig , o .NodeArgs .Components , stopCh )
281
294
}
282
295
283
296
// resolveNodeConfig creates a new configuration on disk by reading from the master, reads
@@ -421,7 +434,7 @@ func execKubelet(kubeletArgs []string) error {
421
434
}
422
435
423
436
// StartNode launches the node processes.
424
- func StartNode (nodeConfig configapi.NodeConfig , components * utilflags.ComponentFlag ) error {
437
+ func StartNode (nodeConfig configapi.NodeConfig , components * utilflags.ComponentFlag , stopCh <- chan struct {} ) error {
425
438
kubeletArgs , err := nodeoptions .ComputeKubeletFlags (nodeConfig .KubeletArguments , nodeConfig )
426
439
if err != nil {
427
440
return fmt .Errorf ("cannot create kubelet args: %v" , err )
@@ -476,12 +489,12 @@ func StartNode(nodeConfig configapi.NodeConfig, components *utilflags.ComponentF
476
489
networkConfig .RunProxy ()
477
490
}
478
491
if components .Enabled (ComponentDNS ) && networkConfig .DNSServer != nil {
479
- networkConfig .RunDNS ()
492
+ networkConfig .RunDNS (stopCh )
480
493
}
481
494
482
- networkConfig .InternalKubeInformers .Start (wait . NeverStop )
495
+ networkConfig .InternalKubeInformers .Start (stopCh )
483
496
if networkConfig .InternalNetworkInformers != nil {
484
- networkConfig .InternalNetworkInformers .Start (wait . NeverStop )
497
+ networkConfig .InternalNetworkInformers .Start (stopCh )
485
498
}
486
499
487
500
return nil
0 commit comments