forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocker.go
170 lines (137 loc) · 5.28 KB
/
docker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package errors
import (
"fmt"
"os/exec"
"runtime"
)
// ErrNoDockerClient is thrown when a Docker client cannot be obtained or cannot be pinged
func ErrNoDockerClient(err error) error {
return NewError("cannot obtain a Docker client").WithCause(err).WithSolution(noDockerClientSolution())
}
// ErrNoDockerMachineClient is returned when a Docker client cannot be obtained from the given Docker machine
func ErrNoDockerMachineClient(name string, err error) error {
return NewError("cannot obtain a client for Docker machine %q", name).WithCause(err).WithSolution(noDockerMachineClientSolution())
}
// ErrCannotPingDocker is returned when a ping to Docker with the Docker client fails
func ErrCannotPingDocker(err error) error {
return NewError("cannot communicate with Docker").WithCause(err).WithSolution(noDockerClientSolution())
}
// ErrKubeConfigNotWriteable is returned when the file pointed to by KUBECONFIG cannot be created or written to
func ErrKubeConfigNotWriteable(file string, err error) error {
return NewError("KUBECONFIG is set to a file that cannot be created or modified: %s", file).WithCause(err).WithSolution(kubeConfigSolution())
}
// ErrNoInsecureRegistryArgument is thrown when an --insecure-registry argument cannot be detected
// on the Docker daemon process
func ErrNoInsecureRegistryArgument() error {
return NewError("did not detect an --insecure-registry argument on the Docker daemon").WithSolution(invalidInsecureRegistryArgSolution())
}
// ErrInvalidInsecureRegistryArgument is thrown when an --insecure-registry argument is found, but does not allow sufficient access
// for our services to operate
func ErrInvalidInsecureRegistryArgument() error {
return NewError("did not detect a sufficient --insecure-registry argument on the Docker daemon").WithSolution(invalidInsecureRegistryArgSolution())
}
const (
NoDockerMacSolution = `
Please install Docker tools by following instructions at:
https://docs.docker.com/mac/
Once installed, run this command with the --create-machine
argument to create a new Docker machine that will run OpenShift.
`
NoDockerMachineMacSolution = `
To create a new Docker machine to run OpenShift, run this command again with
the --create-machine argument. This will create a Docker machine named
'openshift'.
To use a different machine name, specify the --machine-name=NAME argument.
If you wish to use an existing Docker machine, enable it before running this
command by executing:
eval $(docker-machine env NAME)
where NAME is the name of your Docker machine.
`
NoDockerWindowsSolution = `
Please install Docker tools by following instructions at:
https://docs.docker.com/windows/
Once installed, run this command with the --create-machine argument to create a
new Docker machine that will run OpenShift.
`
NoDockerMachineWindowsSolution = `
To create a new Docker machine to run OpenShift, run this command again with
the --create-machine argument. This will create a Docker machine named
'openshift'.
To use a different machine name, specify the --machine-name=NAME argument.
If you wish to use an existing Docker machine, enable it before running this
command by executing:
docker-machine env
where NAME is the name of your Docker machine.
`
NoDockerLinuxSolution = `
Ensure that Docker is installed and accessible in your environment.
Use your package manager or follow instructions at:
https://docs.docker.com/linux/
`
NoDockerMachineClientSolution = `
Ensure that the Docker machine is available and running. You can also create a
new Docker machine by specifying the --create-machine flag.
`
InvalidInsecureRegistryArgSolution = `
Ensure that the Docker daemon is running with the following argument:
--insecure-registry 172.30.0.0/16
`
InvalidInsecureRegistryArgSolutionDockerMachine = InvalidInsecureRegistryArgSolution + `
You can run this command with --create-machine to create a machine with the
right argument.
`
KubeConfigSolutionUnix = `
You can unset the KUBECONFIG variable to use the default location for it:
unset KUBECONFIG
Or you can set its value to a file that can be written to:
export KUBECONFIG=/path/to/file
`
KubeConfigSolutionWindows = `
You can clear the KUBECONFIG variable to use the default location for it:
set KUBECONFIG=
Or you can set its value to a file that can be written to:
set KUBECONFIG=c:\path\to\file
`
)
func hasDockerMachine() bool {
binary := "docker-machine"
if runtime.GOOS == "windows" {
binary += ".exe"
}
_, err := exec.LookPath(binary)
return err == nil
}
func noDockerClientSolution() string {
switch runtime.GOOS {
case "darwin":
if hasDockerMachine() {
return NoDockerMachineMacSolution
}
return NoDockerMacSolution
case "windows":
if hasDockerMachine() {
return NoDockerMachineWindowsSolution
}
return NoDockerWindowsSolution
case "linux":
return NoDockerLinuxSolution
}
return fmt.Sprintf("Platform %s is not supported by this command", runtime.GOOS)
}
func noDockerMachineClientSolution() string {
return NoDockerMachineClientSolution
}
func kubeConfigSolution() string {
switch runtime.GOOS {
case "windows":
return KubeConfigSolutionWindows
default:
return KubeConfigSolutionUnix
}
}
func invalidInsecureRegistryArgSolution() string {
if hasDockerMachine() {
return InvalidInsecureRegistryArgSolutionDockerMachine
}
return InvalidInsecureRegistryArgSolution
}