@@ -2,10 +2,12 @@ package controlplane
2
2
3
3
import (
4
4
"io"
5
- "time"
6
-
5
+ "net"
7
6
"net/url"
7
+ "strconv"
8
+ "time"
8
9
10
+ "sigs.k8s.io/controller-runtime/pkg/internal/testing/addr"
9
11
"sigs.k8s.io/controller-runtime/pkg/internal/testing/process"
10
12
)
11
13
@@ -55,40 +57,50 @@ type Etcd struct {
55
57
Out io.Writer
56
58
Err io.Writer
57
59
58
- processState * process.ProcessState
60
+ // processState contains the actual details about this running process
61
+ processState * process.State
59
62
}
60
63
61
64
// Start starts the etcd, waits for it to come up, and returns an error, if one
62
65
// occoured.
63
66
func (e * Etcd ) Start () error {
64
67
if e .processState == nil {
65
- if err := e .setProcessState (); err != nil {
68
+ if err := e .setState (); err != nil {
66
69
return err
67
70
}
68
71
}
69
72
return e .processState .Start (e .Out , e .Err )
70
73
}
71
74
72
- func (e * Etcd ) setProcessState () error {
75
+ func (e * Etcd ) setState () error {
73
76
var err error
74
77
75
- e .processState = & process.ProcessState {}
76
-
77
- e .processState .DefaultedProcessInput , err = process .DoDefaulting (
78
- "etcd" ,
79
- e .URL ,
80
- e .DataDir ,
81
- e .Path ,
82
- e .StartTimeout ,
83
- e .StopTimeout ,
84
- )
85
- if err != nil {
78
+ e .processState = & process.State {
79
+ Dir : e .DataDir ,
80
+ Path : e .Path ,
81
+ StartTimeout : e .StartTimeout ,
82
+ StopTimeout : e .StopTimeout ,
83
+ }
84
+
85
+ if err := e .processState .Init ("etcd" ); err != nil {
86
86
return err
87
87
}
88
88
89
- e .processState .StartMessage = getEtcdStartMessage (e .processState .URL )
89
+ if e .URL == nil {
90
+ port , host , err := addr .Suggest ("" )
91
+ if err != nil {
92
+ return err
93
+ }
94
+ e .URL = & url.URL {
95
+ Scheme : "http" ,
96
+ Host : net .JoinHostPort (host , strconv .Itoa (port )),
97
+ }
98
+ }
99
+
100
+ // can use /health as of etcd 3.3.0
101
+ e .processState .HealthCheck .URL = * e .URL
102
+ e .processState .HealthCheck .Path = "/health"
90
103
91
- e .URL = & e .processState .URL
92
104
e .DataDir = e .processState .Dir
93
105
e .Path = e .processState .Path
94
106
e .StartTimeout = e .processState .StartTimeout
@@ -117,24 +129,3 @@ var EtcdDefaultArgs = []string{
117
129
"--listen-client-urls={{ if .URL }}{{ .URL.String }}{{ end }}" ,
118
130
"--data-dir={{ .DataDir }}" ,
119
131
}
120
-
121
- // isSecureScheme returns false when the schema is insecure.
122
- func isSecureScheme (scheme string ) bool {
123
- // https://github.com/coreos/etcd/blob/d9deeff49a080a88c982d328ad9d33f26d1ad7b6/pkg/transport/listener.go#L53
124
- if scheme == "https" || scheme == "unixs" {
125
- return true
126
- }
127
- return false
128
- }
129
-
130
- // getEtcdStartMessage returns an start message to inform if the client is or not insecure.
131
- // It will return true when the URL informed has the scheme == "https" || scheme == "unixs"
132
- func getEtcdStartMessage (listenURL url.URL ) string {
133
- if isSecureScheme (listenURL .Scheme ) {
134
- // https://github.com/coreos/etcd/blob/a7f1fbe00ec216fcb3a1919397a103b41dca8413/embed/serve.go#L167
135
- return "serving client requests on "
136
- }
137
-
138
- // https://github.com/coreos/etcd/blob/a7f1fbe00ec216fcb3a1919397a103b41dca8413/embed/serve.go#L124
139
- return "serving insecure client requests on "
140
- }
0 commit comments