Skip to content

Commit

Permalink
Testing move control plane components
Browse files Browse the repository at this point in the history
This moves control plane components to a new internal/testing/controlplane
directory, unifying the first and second levels of internal packages.
  • Loading branch information
DirectXMan12 committed Apr 20, 2021
1 parent 2227561 commit 481f7b9
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 186 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration
package controlplane

import (
"fmt"
Expand All @@ -11,7 +11,6 @@ import (

"sigs.k8s.io/controller-runtime/pkg/internal/testing/addr"
"sigs.k8s.io/controller-runtime/pkg/internal/testing/certs"
"sigs.k8s.io/controller-runtime/pkg/internal/testing/integration/internal"
"sigs.k8s.io/controller-runtime/pkg/internal/testing/process"
)

Expand Down Expand Up @@ -125,9 +124,12 @@ func (s *APIServer) setProcessState() error {
return err
}

s.processState.Args, err = process.RenderTemplates(
internal.DoAPIServerArgDefaulting(s.Args), s,
)
args := s.Args
if len(args) == 0 {
args = APIServerDefaultArgs
}

s.processState.Args, err = process.RenderTemplates(args, s)
return err
}

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

// APIServerDefaultArgs exposes the default args for the APIServer so that you
// can use those to append your own additional arguments.
//
// The internal default arguments are explicitly copied here, we don't want to
// allow users to change the internal ones.
var APIServerDefaultArgs = append([]string{}, internal.APIServerDefaultArgs...)
var APIServerDefaultArgs = []string{
"--advertise-address=127.0.0.1",
"--etcd-servers={{ if .EtcdURL }}{{ .EtcdURL.String }}{{ end }}",
"--cert-dir={{ .CertDir }}",
"--insecure-port={{ if .URL }}{{ .URL.Port }}{{ end }}",
"--insecure-bind-address={{ if .URL }}{{ .URL.Hostname }}{{ end }}",
"--secure-port={{ if .SecurePort }}{{ .SecurePort }}{{ end }}",
// we're keeping this disabled because if enabled, default SA is missing which would force all tests to create one
// in normal apiserver operation this SA is created by controller, but that is not run in integration environment
"--disable-admission-plugins=ServiceAccount",
"--service-cluster-ip-range=10.0.0.0/24",
"--allow-privileged=true",
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration_test
package controlplane_test

import (
"testing"
Expand All @@ -12,6 +12,6 @@ import (
func TestIntegration(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
suiteName := "Integration Framework Unit Tests"
suiteName := "Control Plane Standup Unit Tests"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package integration
package controlplane

import (
"io"
"time"

"net/url"

"sigs.k8s.io/controller-runtime/pkg/internal/testing/integration/internal"
"sigs.k8s.io/controller-runtime/pkg/internal/testing/process"
)

Expand Down Expand Up @@ -87,17 +86,20 @@ func (e *Etcd) setProcessState() error {
return err
}

e.processState.StartMessage = internal.GetEtcdStartMessage(e.processState.URL)
e.processState.StartMessage = getEtcdStartMessage(e.processState.URL)

e.URL = &e.processState.URL
e.DataDir = e.processState.Dir
e.Path = e.processState.Path
e.StartTimeout = e.processState.StartTimeout
e.StopTimeout = e.processState.StopTimeout

e.processState.Args, err = process.RenderTemplates(
internal.DoEtcdArgDefaulting(e.Args), e,
)
args := e.Args
if len(args) == 0 {
args = EtcdDefaultArgs
}

e.processState.Args, err = process.RenderTemplates(args, e)
return err
}

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

// EtcdDefaultArgs exposes the default args for Etcd so that you
// can use those to append your own additional arguments.
//
// The internal default arguments are explicitly copied here, we don't want to
// allow users to change the internal ones.
var EtcdDefaultArgs = append([]string{}, internal.EtcdDefaultArgs...)
var EtcdDefaultArgs = []string{
"--listen-peer-urls=http://localhost:0",
"--advertise-client-urls={{ if .URL }}{{ .URL.String }}{{ end }}",
"--listen-client-urls={{ if .URL }}{{ .URL.String }}{{ end }}",
"--data-dir={{ .DataDir }}",
}

// isSecureScheme returns false when the schema is insecure.
func isSecureScheme(scheme string) bool {
// https://github.com/coreos/etcd/blob/d9deeff49a080a88c982d328ad9d33f26d1ad7b6/pkg/transport/listener.go#L53
if scheme == "https" || scheme == "unixs" {
return true
}
return false
}

// getEtcdStartMessage returns an start message to inform if the client is or not insecure.
// It will return true when the URL informed has the scheme == "https" || scheme == "unixs"
func getEtcdStartMessage(listenURL url.URL) string {
if isSecureScheme(listenURL.Scheme) {
// https://github.com/coreos/etcd/blob/a7f1fbe00ec216fcb3a1919397a103b41dca8413/embed/serve.go#L167
return "serving client requests on "
}

// https://github.com/coreos/etcd/blob/a7f1fbe00ec216fcb3a1919397a103b41dca8413/embed/serve.go#L124
return "serving insecure client requests on "
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration
package controlplane

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package integration_test
package controlplane_test

import (
"io/ioutil"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

. "sigs.k8s.io/controller-runtime/pkg/internal/testing/integration"
. "sigs.k8s.io/controller-runtime/pkg/internal/testing/controlplane"
)

var _ = Describe("Kubectl", func() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration
package controlplane

import (
"fmt"
Expand Down
27 changes: 0 additions & 27 deletions pkg/internal/testing/integration/internal/apiserver.go

This file was deleted.

23 changes: 0 additions & 23 deletions pkg/internal/testing/integration/internal/apiserver_test.go

This file was deleted.

45 changes: 0 additions & 45 deletions pkg/internal/testing/integration/internal/etcd.go

This file was deleted.

49 changes: 0 additions & 49 deletions pkg/internal/testing/integration/internal/etcd_test.go

This file was deleted.

17 changes: 0 additions & 17 deletions pkg/internal/testing/integration/internal/internal_suite_test.go

This file was deleted.

0 comments on commit 481f7b9

Please sign in to comment.