99 "path/filepath"
1010 "strings"
1111 "syscall"
12+ "time"
1213
1314 "github.com/coreos/go-systemd/daemon"
1415 "github.com/golang/glog"
@@ -18,11 +19,11 @@ import (
1819 kerrors "k8s.io/apimachinery/pkg/api/errors"
1920 utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2021 "k8s.io/apimachinery/pkg/util/sets"
21- "k8s.io/apimachinery/pkg/util/wait"
2222 kubeletapp "k8s.io/kubernetes/cmd/kubelet/app"
2323 "k8s.io/kubernetes/pkg/kubectl/cmd/templates"
2424 kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
2525 "k8s.io/kubernetes/pkg/master/ports"
26+ "k8s.io/kubernetes/pkg/util/interrupt"
2627
2728 "github.com/openshift/library-go/pkg/crypto"
2829 "github.com/openshift/origin/pkg/cmd/server/admin"
@@ -115,14 +116,26 @@ var networkLong = templates.LongDesc(`
115116
116117// NewCommandStartNetwork provides a CLI handler for 'start network' command
117118func 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+ }
119123
120124 cmd := & cobra.Command {
121125 Use : "network" ,
122126 Short : "Launch node network" ,
123127 Long : fmt .Sprintf (networkLong , basename ),
124128 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+ })
126139 },
127140 }
128141
@@ -209,7 +222,7 @@ func (o NodeOptions) Complete(cmd *cobra.Command) error {
209222
210223// StartNode calls RunNode and then waits forever
211224func (o NodeOptions ) StartNode (stopCh <- chan struct {}) error {
212- if err := o .RunNode (); err != nil {
225+ if err := o .RunNode (stopCh ); err != nil {
213226 return err
214227 }
215228
@@ -227,7 +240,7 @@ func (o NodeOptions) StartNode(stopCh <-chan struct{}) error {
227240// 2. Reads fully specified node config OR builds a fully specified node config from the args
228241// 3. Writes the fully specified node config and exits if needed
229242// 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 {
231244 nodeConfig , configFile , err := o .resolveNodeConfig ()
232245 if err != nil {
233246 return err
@@ -277,7 +290,7 @@ func (o NodeOptions) RunNode() error {
277290 return originnode .WriteKubeletFlags (* nodeConfig )
278291 }
279292
280- return StartNode (* nodeConfig , o .NodeArgs .Components )
293+ return StartNode (* nodeConfig , o .NodeArgs .Components , stopCh )
281294}
282295
283296// resolveNodeConfig creates a new configuration on disk by reading from the master, reads
@@ -421,7 +434,7 @@ func execKubelet(kubeletArgs []string) error {
421434}
422435
423436// 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 {
425438 kubeletArgs , err := nodeoptions .ComputeKubeletFlags (nodeConfig .KubeletArguments , nodeConfig )
426439 if err != nil {
427440 return fmt .Errorf ("cannot create kubelet args: %v" , err )
@@ -476,12 +489,12 @@ func StartNode(nodeConfig configapi.NodeConfig, components *utilflags.ComponentF
476489 networkConfig .RunProxy ()
477490 }
478491 if components .Enabled (ComponentDNS ) && networkConfig .DNSServer != nil {
479- networkConfig .RunDNS ()
492+ networkConfig .RunDNS (stopCh )
480493 }
481494
482- networkConfig .InternalKubeInformers .Start (wait . NeverStop )
495+ networkConfig .InternalKubeInformers .Start (stopCh )
483496 if networkConfig .InternalNetworkInformers != nil {
484- networkConfig .InternalNetworkInformers .Start (wait . NeverStop )
497+ networkConfig .InternalNetworkInformers .Start (stopCh )
485498 }
486499
487500 return nil
0 commit comments