diff --git a/pkg/envtest/ginkgo.go b/pkg/envtest/ginkgo.go index ea793b52ca..8995687f98 100644 --- a/pkg/envtest/ginkgo.go +++ b/pkg/envtest/ginkgo.go @@ -1,51 +1,11 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - package envtest import ( - "fmt" - - "github.com/onsi/ginkgo" - "github.com/onsi/ginkgo/config" - "github.com/onsi/ginkgo/types" + "sigs.k8s.io/controller-runtime/pkg/envtest/printer" ) -var _ ginkgo.Reporter = NewlineReporter{} - // NewlineReporter is Reporter that Prints a newline after the default Reporter output so that the results // are correctly parsed by test automation. // See issue https://github.com/jstemmer/go-junit-report/issues/31 -type NewlineReporter struct{} - -// SpecSuiteWillBegin implements ginkgo.Reporter -func (NewlineReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) { -} - -// BeforeSuiteDidRun implements ginkgo.Reporter -func (NewlineReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {} - -// AfterSuiteDidRun implements ginkgo.Reporter -func (NewlineReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {} - -// SpecWillRun implements ginkgo.Reporter -func (NewlineReporter) SpecWillRun(specSummary *types.SpecSummary) {} - -// SpecDidComplete implements ginkgo.Reporter -func (NewlineReporter) SpecDidComplete(specSummary *types.SpecSummary) {} - -// SpecSuiteDidEnd Prints a newline between "35 Passed | 0 Failed | 0 Pending | 0 Skipped" and "--- PASS:" -func (NewlineReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) { fmt.Printf("\n") } +// It's re-exported here to avoid compatibility breakage/mass rewrites. +type NewlineReporter = printer.NewlineReporter diff --git a/pkg/envtest/printer/ginkgo.go b/pkg/envtest/printer/ginkgo.go new file mode 100644 index 0000000000..7487172f13 --- /dev/null +++ b/pkg/envtest/printer/ginkgo.go @@ -0,0 +1,51 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package printer + +import ( + "fmt" + + "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo/config" + "github.com/onsi/ginkgo/types" +) + +var _ ginkgo.Reporter = NewlineReporter{} + +// NewlineReporter is Reporter that Prints a newline after the default Reporter output so that the results +// are correctly parsed by test automation. +// See issue https://github.com/jstemmer/go-junit-report/issues/31 +type NewlineReporter struct{} + +// SpecSuiteWillBegin implements ginkgo.Reporter +func (NewlineReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) { +} + +// BeforeSuiteDidRun implements ginkgo.Reporter +func (NewlineReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {} + +// AfterSuiteDidRun implements ginkgo.Reporter +func (NewlineReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {} + +// SpecWillRun implements ginkgo.Reporter +func (NewlineReporter) SpecWillRun(specSummary *types.SpecSummary) {} + +// SpecDidComplete implements ginkgo.Reporter +func (NewlineReporter) SpecDidComplete(specSummary *types.SpecSummary) {} + +// SpecSuiteDidEnd Prints a newline between "35 Passed | 0 Failed | 0 Pending | 0 Skipped" and "--- PASS:" +func (NewlineReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) { fmt.Printf("\n") } diff --git a/pkg/envtest/server.go b/pkg/envtest/server.go index a96c41bf1b..0d7da68855 100644 --- a/pkg/envtest/server.go +++ b/pkg/envtest/server.go @@ -22,6 +22,7 @@ import ( apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client/config" "sigs.k8s.io/testing_frameworks/integration" ) @@ -70,38 +71,59 @@ type Environment struct { // CRDDirectoryPaths is a list of paths containing CRD yaml or json configs. CRDDirectoryPaths []string + + // UseExisting indicates that this environments should use an + // existing kubeconfig, instead of trying to stand up a new control plane. + // This is useful in cases that need aggregated API servers and the like. + UseExistingCluster bool } // Stop stops a running server func (te *Environment) Stop() error { + if te.UseExistingCluster { + return nil + } return te.ControlPlane.Stop() } // Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on func (te *Environment) Start() (*rest.Config, error) { - te.ControlPlane = integration.ControlPlane{} - te.ControlPlane.APIServer = &integration.APIServer{Args: defaultKubeAPIServerFlags} - if os.Getenv(envKubeAPIServerBin) == "" { - te.ControlPlane.APIServer.Path = defaultAssetPath("kube-apiserver") - } - if os.Getenv(envEtcdBin) == "" { - te.ControlPlane.Etcd = &integration.Etcd{Path: defaultAssetPath("etcd")} - } - if os.Getenv(envKubectlBin) == "" { - // we can't just set the path manually (it's behind a function), so set the environment variable instead - if err := os.Setenv(envKubectlBin, defaultAssetPath("kubectl")); err != nil { - return nil, err + if te.UseExistingCluster { + if te.Config == nil { + // we want to allow people to pass in their own config, so + // only load a config if it hasn't already been set. + + var err error + te.Config, err = config.GetConfig() + if err != nil { + return nil, err + } + } + } else { + te.ControlPlane = integration.ControlPlane{} + te.ControlPlane.APIServer = &integration.APIServer{Args: defaultKubeAPIServerFlags} + if os.Getenv(envKubeAPIServerBin) == "" { + te.ControlPlane.APIServer.Path = defaultAssetPath("kube-apiserver") + } + if os.Getenv(envEtcdBin) == "" { + te.ControlPlane.Etcd = &integration.Etcd{Path: defaultAssetPath("etcd")} + } + if os.Getenv(envKubectlBin) == "" { + // we can't just set the path manually (it's behind a function), so set the environment variable instead + if err := os.Setenv(envKubectlBin, defaultAssetPath("kubectl")); err != nil { + return nil, err + } } - } - // Start the control plane - retry if it fails - if err := te.ControlPlane.Start(); err != nil { - return nil, err - } + // Start the control plane - retry if it fails + if err := te.ControlPlane.Start(); err != nil { + return nil, err + } - // Create the *rest.Config for creating new clients - te.Config = &rest.Config{ - Host: te.ControlPlane.APIURL().Host, + // Create the *rest.Config for creating new clients + te.Config = &rest.Config{ + Host: te.ControlPlane.APIURL().Host, + } } _, err := InstallCRDs(te.Config, CRDInstallOptions{ diff --git a/pkg/runtime/log/log_suite_test.go b/pkg/runtime/log/log_suite_test.go index 4e2fdf64eb..a78b451060 100644 --- a/pkg/runtime/log/log_suite_test.go +++ b/pkg/runtime/log/log_suite_test.go @@ -21,10 +21,10 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "sigs.k8s.io/controller-runtime/pkg/envtest" + "sigs.k8s.io/controller-runtime/pkg/envtest/printer" ) func TestSource(t *testing.T) { RegisterFailHandler(Fail) - RunSpecsWithDefaultAndCustomReporters(t, "Runtime Log Suite", []Reporter{envtest.NewlineReporter{}}) + RunSpecsWithDefaultAndCustomReporters(t, "Runtime Log Suite", []Reporter{printer.NewlineReporter{}}) }