Skip to content

Commit 481f7b9

Browse files
committed
Testing move control plane components
This moves control plane components to a new internal/testing/controlplane directory, unifying the first and second levels of internal packages.
1 parent 2227561 commit 481f7b9

File tree

11 files changed

+61
-186
lines changed

11 files changed

+61
-186
lines changed

pkg/internal/testing/integration/apiserver.go renamed to pkg/internal/testing/controlplane/apiserver.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package integration
1+
package controlplane
22

33
import (
44
"fmt"
@@ -11,7 +11,6 @@ import (
1111

1212
"sigs.k8s.io/controller-runtime/pkg/internal/testing/addr"
1313
"sigs.k8s.io/controller-runtime/pkg/internal/testing/certs"
14-
"sigs.k8s.io/controller-runtime/pkg/internal/testing/integration/internal"
1514
"sigs.k8s.io/controller-runtime/pkg/internal/testing/process"
1615
)
1716

@@ -125,9 +124,12 @@ func (s *APIServer) setProcessState() error {
125124
return err
126125
}
127126

128-
s.processState.Args, err = process.RenderTemplates(
129-
internal.DoAPIServerArgDefaulting(s.Args), s,
130-
)
127+
args := s.Args
128+
if len(args) == 0 {
129+
args = APIServerDefaultArgs
130+
}
131+
132+
s.processState.Args, err = process.RenderTemplates(args, s)
131133
return err
132134
}
133135

@@ -173,7 +175,16 @@ func (s *APIServer) Stop() error {
173175

174176
// APIServerDefaultArgs exposes the default args for the APIServer so that you
175177
// can use those to append your own additional arguments.
176-
//
177-
// The internal default arguments are explicitly copied here, we don't want to
178-
// allow users to change the internal ones.
179-
var APIServerDefaultArgs = append([]string{}, internal.APIServerDefaultArgs...)
178+
var APIServerDefaultArgs = []string{
179+
"--advertise-address=127.0.0.1",
180+
"--etcd-servers={{ if .EtcdURL }}{{ .EtcdURL.String }}{{ end }}",
181+
"--cert-dir={{ .CertDir }}",
182+
"--insecure-port={{ if .URL }}{{ .URL.Port }}{{ end }}",
183+
"--insecure-bind-address={{ if .URL }}{{ .URL.Hostname }}{{ end }}",
184+
"--secure-port={{ if .SecurePort }}{{ .SecurePort }}{{ end }}",
185+
// we're keeping this disabled because if enabled, default SA is missing which would force all tests to create one
186+
// in normal apiserver operation this SA is created by controller, but that is not run in integration environment
187+
"--disable-admission-plugins=ServiceAccount",
188+
"--service-cluster-ip-range=10.0.0.0/24",
189+
"--allow-privileged=true",
190+
}

pkg/internal/testing/integration/integration_suite_test.go renamed to pkg/internal/testing/controlplane/controlplane_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package integration_test
1+
package controlplane_test
22

33
import (
44
"testing"
@@ -12,6 +12,6 @@ import (
1212
func TestIntegration(t *testing.T) {
1313
t.Parallel()
1414
RegisterFailHandler(Fail)
15-
suiteName := "Integration Framework Unit Tests"
15+
suiteName := "Control Plane Standup Unit Tests"
1616
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
1717
}

pkg/internal/testing/integration/etcd.go renamed to pkg/internal/testing/controlplane/etcd.go

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
package integration
1+
package controlplane
22

33
import (
44
"io"
55
"time"
66

77
"net/url"
88

9-
"sigs.k8s.io/controller-runtime/pkg/internal/testing/integration/internal"
109
"sigs.k8s.io/controller-runtime/pkg/internal/testing/process"
1110
)
1211

@@ -87,17 +86,20 @@ func (e *Etcd) setProcessState() error {
8786
return err
8887
}
8988

90-
e.processState.StartMessage = internal.GetEtcdStartMessage(e.processState.URL)
89+
e.processState.StartMessage = getEtcdStartMessage(e.processState.URL)
9190

9291
e.URL = &e.processState.URL
9392
e.DataDir = e.processState.Dir
9493
e.Path = e.processState.Path
9594
e.StartTimeout = e.processState.StartTimeout
9695
e.StopTimeout = e.processState.StopTimeout
9796

98-
e.processState.Args, err = process.RenderTemplates(
99-
internal.DoEtcdArgDefaulting(e.Args), e,
100-
)
97+
args := e.Args
98+
if len(args) == 0 {
99+
args = EtcdDefaultArgs
100+
}
101+
102+
e.processState.Args, err = process.RenderTemplates(args, e)
101103
return err
102104
}
103105

@@ -109,7 +111,30 @@ func (e *Etcd) Stop() error {
109111

110112
// EtcdDefaultArgs exposes the default args for Etcd so that you
111113
// can use those to append your own additional arguments.
112-
//
113-
// The internal default arguments are explicitly copied here, we don't want to
114-
// allow users to change the internal ones.
115-
var EtcdDefaultArgs = append([]string{}, internal.EtcdDefaultArgs...)
114+
var EtcdDefaultArgs = []string{
115+
"--listen-peer-urls=http://localhost:0",
116+
"--advertise-client-urls={{ if .URL }}{{ .URL.String }}{{ end }}",
117+
"--listen-client-urls={{ if .URL }}{{ .URL.String }}{{ end }}",
118+
"--data-dir={{ .DataDir }}",
119+
}
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+
}

pkg/internal/testing/integration/kubectl.go renamed to pkg/internal/testing/controlplane/kubectl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package integration
1+
package controlplane
22

33
import (
44
"bytes"

pkg/internal/testing/integration/kubectl_test.go renamed to pkg/internal/testing/controlplane/kubectl_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package integration_test
1+
package controlplane_test
22

33
import (
44
"io/ioutil"
55

66
. "github.com/onsi/ginkgo"
77
. "github.com/onsi/gomega"
88

9-
. "sigs.k8s.io/controller-runtime/pkg/internal/testing/integration"
9+
. "sigs.k8s.io/controller-runtime/pkg/internal/testing/controlplane"
1010
)
1111

1212
var _ = Describe("Kubectl", func() {

pkg/internal/testing/integration/control_plane.go renamed to pkg/internal/testing/controlplane/plane.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package integration
1+
package controlplane
22

33
import (
44
"fmt"

pkg/internal/testing/integration/internal/apiserver.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

pkg/internal/testing/integration/internal/apiserver_test.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

pkg/internal/testing/integration/internal/etcd.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

pkg/internal/testing/integration/internal/etcd_test.go

Lines changed: 0 additions & 49 deletions
This file was deleted.

pkg/internal/testing/integration/internal/internal_suite_test.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)