Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openshift-node-config: resolve cluster-ip when 0.0.0.0 is specified #19734

Merged
merged 1 commit into from May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/openshift-node-config/openshift-node-config.go
Expand Up @@ -47,6 +47,11 @@ func main() {
if err != nil {
return fmt.Errorf("unable to read node config: %v", err)
}

if err := node.FinalizeNodeConfig(nodeConfig); err != nil {
return err
}

if glog.V(2) {
out, _ := yaml.Marshal(nodeConfig)
glog.V(2).Infof("Node config:\n%s", out)
Expand Down
17 changes: 17 additions & 0 deletions pkg/cmd/server/origin/node/node.go
Expand Up @@ -6,8 +6,10 @@ import (
"strconv"
"strings"

"github.com/golang/glog"
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
nodeoptions "github.com/openshift/origin/pkg/cmd/server/kubernetes/node/options"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
)

// safeArgRegexp matches only characters that are known safe. DO NOT add to this list
Expand All @@ -24,6 +26,21 @@ func shellEscapeArg(s string) string {
return strconv.Quote(s)
}

// FinalizeNodeConfig controls the node configuration before it is used by the Kubelet
func FinalizeNodeConfig(nodeConfig *configapi.NodeConfig) error {
if nodeConfig.DNSIP == "0.0.0.0" {
glog.V(4).Infof("Defaulting to the DNSIP config to the node's IP")
nodeConfig.DNSIP = nodeConfig.NodeIP
// TODO: the Kubelet should do this defaulting (to the IP it recognizes)
if len(nodeConfig.DNSIP) == 0 {
if ip, err := cmdutil.DefaultLocalIP4(); err == nil {
nodeConfig.DNSIP = ip.String()
}
}
}
return nil
}

// WriteKubeletFlags writes the correct set of flags to start a Kubelet from the provided node config to
// stdout, instead of launching anything.
func WriteKubeletFlags(nodeConfig configapi.NodeConfig) error {
Expand Down
13 changes: 3 additions & 10 deletions pkg/cmd/server/start/start_node.go
Expand Up @@ -237,16 +237,9 @@ func (o NodeOptions) RunNode() error {
if addr := o.NodeArgs.ListenArg.ListenAddr; addr.Provided {
nodeConfig.ServingInfo.BindAddress = addr.HostPort(o.NodeArgs.ListenArg.ListenAddr.DefaultPort)
}
// do a local resolution of node config DNS IP, supports bootstrapping cases
if nodeConfig.DNSIP == "0.0.0.0" {
glog.V(4).Infof("Defaulting to the DNSIP config to the node's IP")
nodeConfig.DNSIP = nodeConfig.NodeIP
// TODO: the Kubelet should do this defaulting (to the IP it recognizes)
if len(nodeConfig.DNSIP) == 0 {
if ip, err := cmdutil.DefaultLocalIP4(); err == nil {
nodeConfig.DNSIP = ip.String()
}
}

if err := originnode.FinalizeNodeConfig(nodeConfig); err != nil {
return err
}

var validationResults common.ValidationResults
Expand Down