Skip to content

Commit

Permalink
cluster up: use rslave propagation mode with nsenter mounter
Browse files Browse the repository at this point in the history
  • Loading branch information
csrwng committed Aug 23, 2016
1 parent b81f65c commit 5630015
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 60 deletions.
23 changes: 17 additions & 6 deletions pkg/bootstrap/docker/dockerhelper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net"
"net/url"
"regexp"
"strconv"
"time"

Expand Down Expand Up @@ -76,26 +77,36 @@ func (h *Helper) HasInsecureRegistryArg() (bool, error) {
return hasCIDR(openShiftInsecureCIDR, registryConfig.InsecureRegistryCIDRs), nil
}

// Version returns the Docker version
func (h *Helper) Version() (*semver.Version, error) {
var (
fedoraPackage = regexp.MustCompile("\\.fc[0-9_]*\\.")
rhelPackage = regexp.MustCompile("\\.el[0-9_]*\\.")
)

// Version returns the Docker version and whether it is a Red Hat distro version
func (h *Helper) Version() (*semver.Version, bool, error) {
glog.V(5).Infof("Retrieving Docker version")
env, err := h.client.Version()
if err != nil {
glog.V(2).Infof("Error retrieving version: %v", err)
return nil, err
return nil, false, err
}
glog.V(5).Infof("Docker version results: %#v", env)
versionStr := env.Get("Version")
if len(versionStr) == 0 {
return nil, errors.New("did not get a version")
return nil, false, errors.New("did not get a version")
}
glog.V(5).Infof("Version: %s", versionStr)
dockerVersion, err := semver.Parse(versionStr)
if err != nil {
glog.V(2).Infof("Error parsing Docker version %q", versionStr)
return nil, err
return nil, false, err
}
isRedHat := false
packageVersion := env.Get("PkgVersion")
if len(packageVersion) > 0 {
isRedHat = fedoraPackage.MatchString(packageVersion) || rhelPackage.MatchString(packageVersion)
}
return &dockerVersion, nil
return &dockerVersion, isRedHat, nil
}

// CheckAndPull checks whether a Docker image exists. If not, it pulls it.
Expand Down
7 changes: 0 additions & 7 deletions pkg/bootstrap/docker/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"strings"

docker "github.com/fsouza/go-dockerclient"
Expand Down Expand Up @@ -55,12 +54,6 @@ func NewHostHelper(client *docker.Client, image, volumesDir, configDir, dataDir

// CanUseNsenterMounter returns true if the Docker host machine can execute findmnt through nsenter
func (h *HostHelper) CanUseNsenterMounter() (bool, error) {
// For now, use a shared mount on Windows/Mac
// Eventually it also needs to be used on Linux, but nsenter
// is still needed for Docker 1.9
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
return false, nil
}
rc, err := h.runner().
Image(h.image).
DiscardContainer().
Expand Down
31 changes: 18 additions & 13 deletions pkg/bootstrap/docker/openshift/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,19 @@ type Helper struct {

// StartOptions represent the parameters sent to the start command
type StartOptions struct {
ServerIP string
DNSPort int
UseSharedVolume bool
Images string
HostVolumesDir string
HostConfigDir string
HostDataDir string
UseExistingConfig bool
Environment []string
LogLevel int
MetricsHost string
PortForwarding bool
ServerIP string
DNSPort int
UseSharedVolume bool
SetPropagationMode bool
Images string
HostVolumesDir string
HostConfigDir string
HostDataDir string
UseExistingConfig bool
Environment []string
LogLevel int
MetricsHost string
PortForwarding bool
}

// NewHelper creates a new OpenShift helper
Expand Down Expand Up @@ -218,7 +219,11 @@ func (h *Helper) Start(opt *StartOptions, out io.Writer) (string, error) {
env = append(env, "OPENSHIFT_CONTAINERIZED=false")
} else {
binds = append(binds, "/:/rootfs:ro")
binds = append(binds, fmt.Sprintf("%[1]s:%[1]s", opt.HostVolumesDir))
propagationMode := ""
if opt.SetPropagationMode {
propagationMode = ":rslave"
}
binds = append(binds, fmt.Sprintf("%[1]s:%[1]s%[2]s", opt.HostVolumesDir, propagationMode))
}
env = append(env, opt.Environment...)
binds = append(binds, fmt.Sprintf("%s:/var/lib/origin/openshift.local.config:z", opt.HostConfigDir))
Expand Down
71 changes: 37 additions & 34 deletions pkg/bootstrap/docker/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ var (
"jenkins pipeline persistent": "examples/jenkins/jenkins-persistent-template.json",
"sample pipeline": "examples/jenkins/pipeline/samplepipeline.json",
}
dockerVersion19 = semver.MustParse("1.9.0")
dockerVersion110 = semver.MustParse("1.10.0")
)

// NewCmdUp creates a command that starts openshift on Docker with reasonable defaults
Expand Down Expand Up @@ -158,16 +160,17 @@ type ClientStartConfig struct {
ShouldInstallMetrics bool
PortForwarding bool

UseNsenterMount bool
Out io.Writer
TaskPrinter *TaskPrinter
Tasks []task
HostName string
ServerIP string
CACert string
PublicHostname string
RoutingSuffix string
DNSPort int
UseNsenterMount bool
SetPropagationMode bool
Out io.Writer
TaskPrinter *TaskPrinter
Tasks []task
HostName string
ServerIP string
CACert string
PublicHostname string
RoutingSuffix string
DNSPort int

LocalConfigDir string
HostVolumesDir string
Expand Down Expand Up @@ -216,6 +219,9 @@ func (c *ClientStartConfig) Complete(f *osclientcmd.Factory, cmd *cobra.Command)
// running. Otherwise, use environment variables.
c.addTask("Checking Docker client", c.GetDockerClient)

// Check that we have the minimum Docker version available to run OpenShift
c.addTask("Checking Docker version", c.CheckDockerVersion)

// Check for an OpenShift container. If one exists and is running, exit.
// If one exists but not running, delete it.
c.addTask("Checking for existing OpenShift container", c.CheckExistingOpenShiftContainer)
Expand All @@ -237,9 +243,6 @@ func (c *ClientStartConfig) Complete(f *osclientcmd.Factory, cmd *cobra.Command)
// If not, use a shared volume to mount volumes on OpenShift
c.addTask("Checking type of volume mount", c.CheckNsenterMounter)

// Check that we have the minimum Docker version available to run OpenShift
c.addTask("Checking Docker version", c.CheckDockerVersion)

// Ensure that host directories exist.
// If not using the nsenter mounter, create a volume share on the host machine to
// mount OpenShift volumes.
Expand Down Expand Up @@ -479,20 +482,19 @@ func (c *ClientStartConfig) CheckNsenterMounter(out io.Writer) error {
// CheckDockerVersion checks that the appropriate Docker version is installed based on whether we are using the nsenter mounter
// or shared volumes for OpenShift
func (c *ClientStartConfig) CheckDockerVersion(io.Writer) error {
var minDockerVersion semver.Version
if c.UseNsenterMount {
minDockerVersion = semver.MustParse("1.8.1")
} else {
minDockerVersion = semver.MustParse("1.10.0")
}
ver, err := c.DockerHelper().Version()
ver, rh, err := c.DockerHelper().Version()
if err != nil {
return err
}
glog.V(5).Infof("Checking that docker version is at least %v", minDockerVersion)
if ver.LT(minDockerVersion) {
return fmt.Errorf("Docker version is %v, it needs to be %v", ver, minDockerVersion)
needVersion := dockerVersion19
if !rh {
needVersion = dockerVersion110
}
glog.V(5).Infof("Checking that docker version is at least %v", needVersion)
if ver.LT(needVersion) {
return fmt.Errorf("Docker version is %v, it needs to be %v", ver, needVersion)
}
c.SetPropagationMode = ver.GTE(dockerVersion110)
return nil
}

Expand Down Expand Up @@ -546,17 +548,18 @@ func (c *ClientStartConfig) DetermineServerIP(out io.Writer) error {
func (c *ClientStartConfig) StartOpenShift(out io.Writer) error {
var err error
opt := &openshift.StartOptions{
ServerIP: c.ServerIP,
UseSharedVolume: !c.UseNsenterMount,
Images: c.imageFormat(),
HostVolumesDir: c.HostVolumesDir,
HostConfigDir: c.HostConfigDir,
HostDataDir: c.HostDataDir,
UseExistingConfig: c.UseExistingConfig,
Environment: c.Environment,
LogLevel: c.ServerLogLevel,
DNSPort: c.DNSPort,
PortForwarding: c.PortForwarding,
ServerIP: c.ServerIP,
UseSharedVolume: !c.UseNsenterMount,
SetPropagationMode: c.SetPropagationMode,
Images: c.imageFormat(),
HostVolumesDir: c.HostVolumesDir,
HostConfigDir: c.HostConfigDir,
HostDataDir: c.HostDataDir,
UseExistingConfig: c.UseExistingConfig,
Environment: c.Environment,
LogLevel: c.ServerLogLevel,
DNSPort: c.DNSPort,
PortForwarding: c.PortForwarding,
}
if c.ShouldInstallMetrics {
opt.MetricsHost = openshift.MetricsHost(c.RoutingSuffix, c.ServerIP)
Expand Down

0 comments on commit 5630015

Please sign in to comment.