Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion hack/test-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,23 @@ start_etcd
trap cleanup EXIT SIGINT

function exectest() {
echo "running $1..."

out=$("${testexec}" -test.run="^$1$" "${@:2}" 2>&1)

tput cuu 1 # Move up one line
tput el # Clear "running" line

res=$?
if [[ ${res} -eq 0 ]]; then
echo ok $1
tput setaf 2 # green
echo "ok $1"
tput sgr0 # reset
exit 0
else
tput setaf 1 # red
echo "failed $1"
tput sgr0 # reset
echo "${out}"
exit 1
fi
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/server/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ type NodeConfig struct {
// MasterKubeConfig is a filename for the .kubeconfig file that describes how to connect this node to the master
MasterKubeConfig string

// domain suffix
DNSDomain string
// ip:port
DNSAddress string
// ip
DNSIP string

// VolumeDir is the directory that volumes will be stored under
VolumeDirectory string
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/server/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ type NodeConfig struct {
// MasterKubeConfig is a filename for the .kubeconfig file that describes how to connect this node to the master
MasterKubeConfig string `json:"masterKubeConfig"`

// domain suffix
DNSDomain string `json:"dnsDomain"`
// ip:port
DNSAddress string `json:"dnsAddress"`
// ip
DNSIP string `json:"dnsIP"`

// VolumeDir is the directory that volumes will be stored under
VolumeDirectory string `json:"volumeDirectory"`
Expand Down
11 changes: 10 additions & 1 deletion pkg/cmd/server/kubernetes/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kubernetes

import (
"crypto/x509"
"fmt"
"net"

"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
Expand Down Expand Up @@ -54,12 +55,20 @@ func BuildKubernetesNodeConfig(options configapi.NodeConfig) (*NodeConfig, error
return nil, err
}

var dnsIP net.IP
if len(options.DNSIP) > 0 {
dnsIP = net.ParseIP(options.DNSIP)
if dnsIP == nil {
return nil, fmt.Errorf("Invalid DNS IP: %s", options.DNSIP)
}
}

config := &NodeConfig{
NodeHost: options.NodeName,
BindAddress: options.ServingInfo.BindAddress,

ClusterDomain: options.DNSDomain,
ClusterDNS: net.ParseIP(options.DNSAddress),
ClusterDNS: dnsIP,

VolumeDir: options.VolumeDirectory,
NetworkContainerImage: options.NetworkContainerImage,
Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/server/origin/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,11 @@ func (c *MasterConfig) RunDNSServer() {
glog.Warningf("Binding DNS on port %v instead of 53 (you may need to run as root and update your config), using %s which will not resolve from all locations", port, c.Options.DNSConfig.BindAddress)
}

if ok, err := cmdutil.TryListen(c.Options.DNSConfig.BindAddress); !ok {
glog.Warningf("Could not start DNS: %v", err)
return
}

go func() {
err := dns.ListenAndServe(config, c.DNSServerClient(), c.EtcdHelper.Client.(*etcdclient.Client))
glog.Fatalf("Could not start DNS: %v", err)
Expand Down
18 changes: 10 additions & 8 deletions pkg/cmd/server/start/master_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ type MasterArgs struct {
EtcdAddr flagtypes.Addr
PortalNet flagtypes.IPNet
// addresses for external clients
MasterPublicAddr flagtypes.Addr
// addresses for asset server
AssetBindAddr flagtypes.Addr
MasterPublicAddr flagtypes.Addr
AssetPublicAddr flagtypes.Addr
KubernetesPublicAddr flagtypes.Addr

// AssetBindAddr exposed for integration tests to set
AssetBindAddr flagtypes.Addr
// DNSBindAddr exposed for integration tests to set
DNSBindAddr flagtypes.Addr

EtcdDir string

NodeList util.StringList
Expand Down Expand Up @@ -69,6 +72,7 @@ func NewDefaultMasterArgs() *MasterArgs {
KubernetesPublicAddr: flagtypes.Addr{Value: "localhost:8443", DefaultScheme: "https", DefaultPort: 8443, AllowPrefix: true}.Default(),
AssetPublicAddr: flagtypes.Addr{Value: "localhost:8444", DefaultScheme: "https", DefaultPort: 8444, AllowPrefix: true}.Default(),
AssetBindAddr: flagtypes.Addr{Value: "0.0.0.0:8444", DefaultScheme: "https", DefaultPort: 8444, AllowPrefix: true}.Default(),
DNSBindAddr: flagtypes.Addr{Value: "0.0.0.0:53", DefaultScheme: "http", DefaultPort: 53, AllowPrefix: true}.Default(),

BindAddrArg: NewDefaultBindAddrArg(),
ImageFormatArgs: NewDefaultImageFormatArgs(),
Expand Down Expand Up @@ -293,12 +297,10 @@ func (args MasterArgs) GetMasterAddress() (*url.URL, error) {
}

func (args MasterArgs) GetDNSBindAddress() (flagtypes.Addr, error) {
dnsAddr := flagtypes.Addr{Value: args.BindAddrArg.BindAddr.Host, DefaultPort: 53}.Default()
if !cmdutil.TryListen(dnsAddr.URL.Host) {
dnsAddr.DefaultPort = 8053
dnsAddr = dnsAddr.Default()
if args.DNSBindAddr.Provided {
return args.DNSBindAddr, nil
}

dnsAddr := flagtypes.Addr{Value: args.BindAddrArg.BindAddr.Host, DefaultPort: 53}.Default()
return dnsAddr, nil
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/server/start/node_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ func NewDefaultNodeArgs() *NodeArgs {
// BuildSerializeableNodeConfig takes the NodeArgs (partially complete config) and uses them along with defaulting behavior to create the fully specified
// config object for starting the node
func (args NodeArgs) BuildSerializeableNodeConfig() (*configapi.NodeConfig, error) {
var dnsIP string
if len(args.ClusterDNS) > 0 {
dnsIP = args.ClusterDNS.String()
}

config := &configapi.NodeConfig{
NodeName: args.NodeName,

Expand All @@ -88,6 +93,7 @@ func (args NodeArgs) BuildSerializeableNodeConfig() (*configapi.NodeConfig, erro
AllowDisabledDocker: args.AllowDisabledDocker,

DNSDomain: args.ClusterDomain,
DNSIP: dnsIP,

MasterKubeConfig: certs.DefaultKubeConfigFilename(args.CertArgs.CertDir, "node-"+args.NodeName),
}
Expand Down
22 changes: 17 additions & 5 deletions pkg/cmd/server/start/start_allinone.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package start
import (
"errors"
"fmt"
"net"
"strings"

"github.com/coreos/go-systemd/daemon"
Expand Down Expand Up @@ -47,8 +48,9 @@ Note: starting OpenShift without passing the --master address will attempt to fi
address that will be visible inside running Docker containers. This is not always successful,
so if you have problems tell OpenShift what public address it will be via --master=<ip>.

You may also pass --etcd=<address> to connect to an external etcd server instead of running an
integrated instance or --kubeconfig=<path> to connect to an existing Kubernetes cluster.
You may also pass --etcd=<address> to connect to an external etcd server.

You may also pass --kubeconfig=<path> to connect to an external Kubernetes cluster.
`

// NewCommandStartMaster provides a CLI handler for 'start' command
Expand Down Expand Up @@ -79,9 +81,9 @@ func NewCommandStartAllInOne() (*cobra.Command, *AllInOneOptions) {

flags := cmd.Flags()

flags.BoolVar(&options.WriteConfigOnly, "write-config", false, "Indicates that the command should build the config that would be used to start OpenShift and do nothing else.")
flags.StringVar(&options.MasterConfigFile, "master-config", "", "Indicates that the command use the config file from a certain location. If this is specified, all other options are ignored except --write-config.")
flags.StringVar(&options.NodeConfigFile, "node-config", "", "Indicates that the command use the config file from a certain location. If this is specified, all other options are ignored except --write-config.")
flags.BoolVar(&options.WriteConfigOnly, "write-config", false, "Indicates that the command should build the configuration from command-line arguments, write it to the locations specified by --master-config and --node-config, and exit.")
flags.StringVar(&options.MasterConfigFile, "master-config", "", "Location of the master configuration file to run from, or write to (when used with --write-config). When running from configuration files, all other command-line arguments are ignored.")
flags.StringVar(&options.NodeConfigFile, "node-config", "", "Location of the node configuration file to run from, or write to (when used with --write-config). When running from configuration files, all other command-line arguments are ignored.")

masterArgs, nodeArgs, bindAddrArg, imageFormatArgs, kubeConnectionArgs, certArgs := GetAllInOneArgs()
options.MasterArgs, options.NodeArgs = masterArgs, nodeArgs
Expand Down Expand Up @@ -188,7 +190,17 @@ func (o AllInOneOptions) StartAllInOne() error {
if err != nil {
return nil
}

// in the all-in-one, default kubernetes URL to the master's address
o.NodeArgs.DefaultKubernetesURL = *masterAddr

// in the all-in-one, default ClusterDNS to the master's address
if host, _, err := net.SplitHostPort(masterAddr.Host); err == nil {
if ip := net.ParseIP(host); ip != nil {
o.NodeArgs.ClusterDNS = ip
}
}

nodeOptions := NodeOptions{o.NodeArgs, o.WriteConfigOnly, o.NodeConfigFile}

if err := masterOptions.RunMaster(); err != nil {
Expand Down
17 changes: 11 additions & 6 deletions pkg/cmd/server/start/start_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ following roles:
Launches the server and control plane for OpenShift. You may pass a list of the node
hostnames you want to use, or create nodes via the REST API or 'openshift kube'.

You may also pass --etcd=<address> to connect to an external etcd server instead of running an
integrated instance or --kubeconfig=<path> to connect to an existing Kubernetes cluster.
You may also pass --etcd=<address> to connect to an external etcd server.

You may also pass --kubeconfig=<path> to connect to an external Kubernetes cluster.
`

// NewCommandStartMaster provides a CLI handler for 'start' command
Expand Down Expand Up @@ -89,8 +90,8 @@ func NewCommandStartMaster() (*cobra.Command, *MasterOptions) {

flags := cmd.Flags()

flags.BoolVar(&options.WriteConfigOnly, "write-config", false, "Indicates that the command should build the config that would be used to start OpenShift and do nothing else.")
flags.StringVar(&options.ConfigFile, "config", "", "Indicates that the command use the config file from a certain location. If this is specified, all other options are ignored except --write-config.")
flags.BoolVar(&options.WriteConfigOnly, "write-config", false, "Indicates that the command should build the configuration from command-line arguments, write it to the location specified by --config, and exit.")
flags.StringVar(&options.ConfigFile, "config", "", "Location of the master configuration file to run from, or write to (when used with --write-config). When running from a configuration file, all other command-line arguments are ignored.")

options.MasterArgs = NewDefaultMasterArgs()
// make sure that KubeConnectionArgs and MasterArgs use the same CertArgs for this command
Expand Down Expand Up @@ -326,8 +327,12 @@ func StartMaster(openshiftMasterConfig *configapi.MasterConfig) error {

glog.Infof("Using images from %q", openshiftConfig.ImageFor("<component>"))

openshiftConfig.RunDNSServer()
openshiftConfig.RunAssetServer()
if openshiftMasterConfig.DNSConfig != nil {
openshiftConfig.RunDNSServer()
}
if openshiftMasterConfig.AssetConfig != nil {
openshiftConfig.RunAssetServer()
}
openshiftConfig.RunBuildController()
openshiftConfig.RunBuildPodController()
openshiftConfig.RunBuildImageChangeTriggerController()
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/server/start/start_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func NewCommandStartNode() (*cobra.Command, *NodeOptions) {

flags := cmd.Flags()

flags.BoolVar(&options.WriteConfigOnly, "write-config", false, "Indicates that the command should build the config that would be used to start OpenShift and do nothing else.")
flags.StringVar(&options.ConfigFile, "config", "", "Indicates that the command use the config file from a certain location. If this is specified, all other options are ignored except --write-config.")
flags.BoolVar(&options.WriteConfigOnly, "write-config", false, "Indicates that the command should build the configuration from command-line arguments, write it to the location specified by --config, and exit.")
flags.StringVar(&options.ConfigFile, "config", "", "Location of the node configuration file to run from, or write to (when used with --write-config). When running from a configuration file, all other command-line arguments are ignored.")

options.NodeArgs = NewDefaultNodeArgs()
// make sure that KubeConnectionArgs and NodeArgs use the same CertArgs for this command
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
)

// TryListen tries to open a connection on the given port and returns true if it succeeded.
func TryListen(hostPort string) bool {
func TryListen(hostPort string) (bool, error) {
l, err := net.Listen("tcp", hostPort)
if err != nil {
glog.V(5).Infof("Failure while checking listen on %s: %v", err)
return false
return false, err
}
defer l.Close()
return true
return true, nil
}

// WaitForDial attempts to connect to the given address, closing and returning nil on the first successful connection.
Expand Down
8 changes: 4 additions & 4 deletions test/integration/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func init() {
}

func TestLogin(t *testing.T) {
startConfig, err := StartTestMaster()
_, clusterAdminKubeConfig, err := StartTestMaster()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

openshiftClient, openshiftClientConfig, err := startConfig.GetOpenshiftClient()
clusterAdminClient, _, clusterAdminClientConfig, err := GetClusterAdminClient(clusterAdminKubeConfig)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand All @@ -40,7 +40,7 @@ func TestLogin(t *testing.T) {
username := "joe"
password := "pass"
project := "the-singularity-is-near"
server := openshiftClientConfig.Host
server := clusterAdminClientConfig.Host

loginOptions = newLoginOptions(server, username, password, "", true)

Expand All @@ -61,7 +61,7 @@ func TestLogin(t *testing.T) {
}

newProjectOptions := &newproject.NewProjectOptions{
Client: openshiftClient,
Client: clusterAdminClient,
ProjectName: project,
AdminRole: "admin",
MasterPolicyNamespace: "master",
Expand Down
7 changes: 4 additions & 3 deletions test/integration/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ func init() {
func setupStartOptions() (*start.MasterArgs, *start.NodeArgs, *start.BindAddrArg, *start.ImageFormatArgs, *start.KubeConnectionArgs, *start.CertArgs) {
masterArgs, nodeArgs, bindAddrArg, imageFormatArgs, kubeConnectionArgs, certArgs := start.GetAllInOneArgs()

// masterArgs.DNSConfig.BindAddress = "127.0.0.1:8053"
// nodeArgs.DNSAddress = "127.0.0.1:8053"

basedir := path.Join(os.TempDir(), "openshift-integration-tests")
nodeArgs.VolumeDir = path.Join(basedir, "volume")
masterArgs.EtcdDir = path.Join(basedir, "etcd")
Expand All @@ -49,6 +46,10 @@ func setupStartOptions() (*start.MasterArgs, *start.NodeArgs, *start.BindAddrArg
masterArgs.AssetBindAddr.Set(assetAddr)
masterArgs.AssetPublicAddr.Set(assetAddr)

dnsAddr := httptest.NewUnstartedServer(nil).Listener.Addr().String()
fmt.Printf("dnsAddr: %#v\n", dnsAddr)
masterArgs.DNSBindAddr.Set(dnsAddr)

return masterArgs, nodeArgs, bindAddrArg, imageFormatArgs, kubeConnectionArgs, certArgs
}

Expand Down