Skip to content

Commit 69dcbb2

Browse files
authoredJan 31, 2018
Merge pull request #17942 from wtrocki/oc-up-socat-warning
Automatic merge from submit-queue (batch tested with PRs 17942, 18370). Display warning when socat cmd is missing ## Motivation I have been troubleshooting couple openshift installations done using `oc cluster up` recently and found one common pattern. MacOS users who used `oc cluster up` for the first time almost always experienced problems with reaching running cluster. Example: ``` curl 127.0.0.1:8443 curl: (7) Failed connect to 127.0.0.1:8442; Connection refused ``` Problem related with missing or improperly installed `socat` command. Following [documentation](https://github.com/openshift/origin/blob/master/docs/cluster_up_down.md#macos-with-docker-for-mac) is often not enough. Users who install this command using brew may miss some additional libraries and this is really hard to debug and track cause of the issue when looking into logs. Example output: ``` > socat dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib Referenced from: /usr/local/bin/socat Reason: image not found [1] 13015 abort socat ``` Problem is not easy to investigate as currently installer provides no useful message back to the user. Example issue that was caused by problem #17931 ## Proposed solution Validate if socat is available when executing `oc cluster up` to inform users about possible problems that may occur. Validation will happen only when `PortForwarding` option will be used. Implementation using non disruptive aproach - server will still start without `socat` and only warning will be displayed. ## Dev notes Changes will be squashed after review. To properly unit test changes I will need to create fake structure for `localcmd` package in order to mock execution of the command. Something like [wrappers for os/exec](https://github.com/kubernetes/contrib/tree/master/exec-healthz/vendor/k8s.io/kubernetes/pkg/util/exec) in kubernetes dependencies. I wasn't sure if this is worth doing for such small change. ## Verification ``` brew uninstall socat oc cluster up | grep "Port forwarding requires socat" ```
2 parents c2aed8d + b7e091b commit 69dcbb2

File tree

1 file changed

+16
-0
lines changed
  • pkg/oc/bootstrap/docker

1 file changed

+16
-0
lines changed
 

Diff for: ‎pkg/oc/bootstrap/docker/up.go

+16
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/openshift/origin/pkg/oc/bootstrap/docker/dockermachine"
3434
"github.com/openshift/origin/pkg/oc/bootstrap/docker/errors"
3535
"github.com/openshift/origin/pkg/oc/bootstrap/docker/host"
36+
"github.com/openshift/origin/pkg/oc/bootstrap/docker/localcmd"
3637
"github.com/openshift/origin/pkg/oc/bootstrap/docker/openshift"
3738
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
3839
osclientcmd "github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
@@ -334,6 +335,7 @@ func (c *CommonStartConfig) Complete(f *osclientcmd.Factory, cmd *cobra.Command)
334335
c.addTask(simpleTask("Checking OpenShift client", c.CheckOpenShiftClient))
335336

336337
c.addTask(conditionalTask("Create Docker machine", c.CreateDockerMachine, func() bool { return c.ShouldCreateDockerMachine }))
338+
337339
// Get a Docker client.
338340
// If a Docker machine was specified, make sure that the machine is running.
339341
// Otherwise, use environment variables.
@@ -342,6 +344,8 @@ func (c *CommonStartConfig) Complete(f *osclientcmd.Factory, cmd *cobra.Command)
342344
// Check that we have the minimum Docker version available to run OpenShift
343345
c.addTask(simpleTask("Checking Docker version", c.CheckDockerVersion))
344346

347+
c.addTask(conditionalTask("Checking prerequisites for port forwarding", c.CheckPortForwardingPrerequisites, func() bool { return c.PortForwarding }))
348+
345349
// Check for an OpenShift container. If one exists and is running, exit.
346350
// If one exists but not running, delete it.
347351
c.addTask(simpleTask("Checking for existing OpenShift container", c.CheckExistingOpenShiftContainer))
@@ -739,6 +743,18 @@ func (c *CommonStartConfig) CheckDockerVersion(out io.Writer) error {
739743
return nil
740744
}
741745

746+
// CheckPortForwardingPrerequisites checks that socat is installed when port forwarding is enabled
747+
// Socat needs to be installed manually on MacOS
748+
func (c *CommonStartConfig) CheckPortForwardingPrerequisites(out io.Writer) error {
749+
err := localcmd.New("socat").Args("-V").Run()
750+
if err != nil {
751+
glog.V(2).Infof("Error from socat command execution: %v", err)
752+
fmt.Fprintf(out, "WARNING: Port forwarding requires socat command line utility."+
753+
"Cluster public ip may not be reachable. Please make sure socat installed in your operating system \n")
754+
}
755+
return nil
756+
}
757+
742758
func (c *CommonStartConfig) EnsureHostDirectories(io.Writer) error {
743759
return c.HostHelper().EnsureHostDirectories(!c.UseNsenterMount)
744760
}

0 commit comments

Comments
 (0)
Please sign in to comment.