Skip to content

Commit

Permalink
Merge pull request #21009 from Miciah/restore-graceful-shutdown-of-dn…
Browse files Browse the repository at this point in the history
…s-server

Restore graceful shutdown of DNS server
  • Loading branch information
openshift-merge-robot authored Sep 18, 2018
2 parents d3559ef + 2229ac5 commit 256f7ea
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions pkg/cmd/server/start/network/start_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/coreos/go-systemd/daemon"
"github.com/golang/glog"
"github.com/spf13/cobra"

kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
"k8s.io/kubernetes/pkg/master/ports"
"k8s.io/kubernetes/pkg/util/interrupt"

"github.com/openshift/library-go/pkg/serviceability"
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
Expand Down Expand Up @@ -57,7 +58,16 @@ func NewCommandStartNetwork(basename string, out, errout io.Writer) (*cobra.Comm
Short: "Launch node network",
Long: fmt.Sprintf(networkLong, basename),
Run: func(c *cobra.Command, args []string) {
opts.Run(c, errout, args, wait.NeverStop)
ch := make(chan struct{})
interrupt.New(func(s os.Signal) {
close(ch)
fmt.Fprintf(errout, "interrupt: Gracefully shutting down ...\n")
time.Sleep(200 * time.Millisecond)
os.Exit(1)
}).Run(func() error {
opts.Run(c, errout, args, ch)
return nil
})
},
}

Expand Down Expand Up @@ -118,9 +128,10 @@ func (o NetworkOptions) Complete(cmd *cobra.Command) error {
return nil
}

// StartNode calls RunNode and then waits forever
// StartNetwork starts the networking processes and then waits until the stop
// channel receives a message or is closed.
func (o NetworkOptions) StartNetwork(stopCh <-chan struct{}) error {
if err := o.RunNetwork(); err != nil {
if err := o.RunNetwork(stopCh); err != nil {
return err
}

Expand All @@ -129,10 +140,10 @@ func (o NetworkOptions) StartNetwork(stopCh <-chan struct{}) error {
return nil
}

// RunNetwork takes the options and:
// 1. Reads fully specified node config
// 2. Starts the node based on the fully specified config
func (o NetworkOptions) RunNetwork() error {
// RunNetwork takes the network options and does the following:
// 1. Reads the fully specified node config.
// 2. Starts the node networking based on the fully specified config.
func (o NetworkOptions) RunNetwork(stopCh <-chan struct{}) error {
nodeConfig, configFile, err := o.resolveNodeConfig()
if err != nil {
return err
Expand Down Expand Up @@ -175,7 +186,7 @@ func (o NetworkOptions) RunNetwork() error {
return err
}

return StartNetwork(*nodeConfig, o.NodeArgs.Components)
return StartNetwork(*nodeConfig, o.NodeArgs.Components, stopCh)
}

// resolveNodeConfig creates a new configuration on disk by reading from the master, reads
Expand All @@ -191,8 +202,8 @@ func (o NetworkOptions) resolveNodeConfig() (*configapi.NodeConfig, string, erro
return cfg, o.ConfigFile, err
}

// StartNetwork launches the node processes.
func StartNetwork(nodeConfig configapi.NodeConfig, components *utilflags.ComponentFlag) error {
// StartNetwork launches the node networking processes.
func StartNetwork(nodeConfig configapi.NodeConfig, components *utilflags.ComponentFlag, stopCh <-chan struct{}) error {
glog.Infof("Starting node networking %s (%s)", nodeConfig.NodeName, version.Get().String())

proxyConfig, err := networkoptions.Build(nodeConfig)
Expand All @@ -217,12 +228,12 @@ func StartNetwork(nodeConfig configapi.NodeConfig, components *utilflags.Compone
networkConfig.RunProxy()
}
if components.Enabled(ComponentDNS) && networkConfig.DNSServer != nil {
networkConfig.RunDNS(wait.NeverStop)
networkConfig.RunDNS(stopCh)
}

networkConfig.InternalKubeInformers.Start(wait.NeverStop)
networkConfig.InternalKubeInformers.Start(stopCh)
if networkConfig.NetworkInformers != nil {
networkConfig.NetworkInformers.Start(wait.NeverStop)
networkConfig.NetworkInformers.Start(stopCh)
}

return nil
Expand Down

0 comments on commit 256f7ea

Please sign in to comment.