From d48e1e42ad7e99a0fd5f29eefed65220fca2ed95 Mon Sep 17 00:00:00 2001 From: Ken Sipe Date: Thu, 8 Dec 2022 09:22:48 -0600 Subject: [PATCH] Remove use of APIServerArgs for testenv Signed-off-by: Ken Sipe --- pkg/apis/testharness/v1beta1/test_types.go | 2 ++ pkg/kuttlctl/cmd/test.go | 11 +++------- pkg/test/case_integration_test.go | 4 ++-- pkg/test/harness.go | 2 +- pkg/test/harness_integration_test.go | 2 +- pkg/test/step_integration_test.go | 2 +- pkg/test/utils/kubernetes.go | 2 +- pkg/test/utils/kubernetes_integration_test.go | 2 +- pkg/test/utils/mock_control_plane.go | 22 ------------------- 9 files changed, 12 insertions(+), 37 deletions(-) delete mode 100644 pkg/test/utils/mock_control_plane.go diff --git a/pkg/apis/testharness/v1beta1/test_types.go b/pkg/apis/testharness/v1beta1/test_types.go index 00e688d6..92981426 100644 --- a/pkg/apis/testharness/v1beta1/test_types.go +++ b/pkg/apis/testharness/v1beta1/test_types.go @@ -30,6 +30,8 @@ type TestSuite struct { StartControlPlane bool `json:"startControlPlane"` // ControlPlaneArgs defaults to APIServerDefaultArgs from controller-runtime pkg/internal/testing/integration/internal/apiserver.go // this allows for control over the args, however these are not serialized from a TestSuite.yaml + // deprecated and is no longer used! + // TODO: remove after v0.16.0 (provide warning message until then) ControlPlaneArgs []string `json:"controlPlaneArgs"` // AttachControlPlaneOutput if true, attaches control plane logs (api-server, etcd) into stdout. This is useful for debugging. // defaults to false diff --git a/pkg/kuttlctl/cmd/test.go b/pkg/kuttlctl/cmd/test.go index 513bcdd8..b9654121 100644 --- a/pkg/kuttlctl/cmd/test.go +++ b/pkg/kuttlctl/cmd/test.go @@ -54,6 +54,7 @@ func newTestCmd() *cobra.Command { //nolint:gocyclo skipClusterDelete := false parallel := 0 artifactsDir := "" + // TODO: remove after v0.16.0 deprecated mockControllerFile := "" timeout := 30 reportFormat := "" @@ -209,17 +210,10 @@ For more detailed documentation, visit: https://kuttl.dev`, if len(options.TestDirs) == 0 { return errors.New("no test directories provided, please provide either --config or test directories on the command line") } - var APIServerArgs []string - var err error if mockControllerFile != "" { - APIServerArgs, err = testutils.ReadMockControllerConfig(mockControllerFile) + log.Println("use of --control-plane-config is deprecated and no longer functions") } - if err != nil { - return err - } - options.ControlPlaneArgs = APIServerArgs - return nil }, Run: func(cmd *cobra.Command, args []string) { @@ -240,6 +234,7 @@ For more detailed documentation, visit: https://kuttl.dev`, testCmd.Flags().StringVar(&testToRun, "test", "", "If set, the specific test case to run.") testCmd.Flags().BoolVar(&startControlPlane, "start-control-plane", false, "Start a local Kubernetes control plane for the tests (requires etcd and kube-apiserver binaries, cannot be used with --start-kind).") testCmd.Flags().BoolVar(&attachControlPlaneOutput, "attach-control-plane-output", false, "Attaches control plane to stdout when using --start-control-plane.") + // TODO: remove after v0.16.0 deprecated mockControllerFile is not supported in the latest testenv testCmd.Flags().StringVar(&mockControllerFile, "control-plane-config", "", "Path to file to load controller-runtime APIServer configuration arguments (only useful when --startControlPlane).") testCmd.Flags().BoolVar(&startKIND, "start-kind", false, "Start a KIND cluster for the tests (cannot be used with --start-control-plane).") testCmd.Flags().StringVar(&kindConfig, "kind-config", "", "Specify the KIND configuration file path (implies --start-kind, cannot be used with --start-control-plane).") diff --git a/pkg/test/case_integration_test.go b/pkg/test/case_integration_test.go index c0926cf5..acaa88a5 100644 --- a/pkg/test/case_integration_test.go +++ b/pkg/test/case_integration_test.go @@ -16,7 +16,7 @@ import ( // Create two test environments, ensure that the second environment is used when // Kubeconfig is set on a Step. func TestMultiClusterCase(t *testing.T) { - testenv, err := testutils.StartTestEnvironment(nil, false) + testenv, err := testutils.StartTestEnvironment(false) if err != nil { t.Error(err) return @@ -27,7 +27,7 @@ func TestMultiClusterCase(t *testing.T) { } }) - testenv2, err := testutils.StartTestEnvironment(nil, false) + testenv2, err := testutils.StartTestEnvironment(false) if err != nil { t.Error(err) return diff --git a/pkg/test/harness.go b/pkg/test/harness.go index f1756922..8a84fc10 100644 --- a/pkg/test/harness.go +++ b/pkg/test/harness.go @@ -212,7 +212,7 @@ func (h *Harness) addNodeCaches(dockerClient testutils.DockerClient, kindCfg *ki func (h *Harness) RunTestEnv() (*rest.Config, error) { started := time.Now() - testenv, err := testutils.StartTestEnvironment(h.TestSuite.ControlPlaneArgs, h.TestSuite.AttachControlPlaneOutput) + testenv, err := testutils.StartTestEnvironment(h.TestSuite.AttachControlPlaneOutput) if err != nil { return nil, err } diff --git a/pkg/test/harness_integration_test.go b/pkg/test/harness_integration_test.go index 341f7b44..4ac3581f 100644 --- a/pkg/test/harness_integration_test.go +++ b/pkg/test/harness_integration_test.go @@ -27,7 +27,7 @@ func TestHarnessRunIntegration(t *testing.T) { } func TestHarnessRunIntegrationWithConfig(t *testing.T) { - testenv, err := testutils.StartTestEnvironment(nil, false) + testenv, err := testutils.StartTestEnvironment(false) if err != nil { t.Fatalf("fatal error starting environment: %s", err) } diff --git a/pkg/test/step_integration_test.go b/pkg/test/step_integration_test.go index 369a61bb..cdd38284 100644 --- a/pkg/test/step_integration_test.go +++ b/pkg/test/step_integration_test.go @@ -28,7 +28,7 @@ var testenv testutils.TestEnvironment func TestMain(m *testing.M) { var err error - testenv, err = testutils.StartTestEnvironment(nil, false) + testenv, err = testutils.StartTestEnvironment(false) if err != nil { log.Fatal(err) } diff --git a/pkg/test/utils/kubernetes.go b/pkg/test/utils/kubernetes.go index 53ef6d3a..d661e470 100644 --- a/pkg/test/utils/kubernetes.go +++ b/pkg/test/utils/kubernetes.go @@ -947,7 +947,7 @@ type TestEnvironment struct { // StartTestEnvironment is a wrapper for controller-runtime's envtest that creates a Kubernetes API server and etcd // suitable for use in tests. -func StartTestEnvironment(kubeAPIServerFlags []string, attachControlPlaneOutput bool) (env TestEnvironment, err error) { +func StartTestEnvironment(attachControlPlaneOutput bool) (env TestEnvironment, err error) { env.Environment = &envtest.Environment{ AttachControlPlaneOutput: attachControlPlaneOutput, } diff --git a/pkg/test/utils/kubernetes_integration_test.go b/pkg/test/utils/kubernetes_integration_test.go index 9e322740..b8784890 100644 --- a/pkg/test/utils/kubernetes_integration_test.go +++ b/pkg/test/utils/kubernetes_integration_test.go @@ -24,7 +24,7 @@ var testenv TestEnvironment func TestMain(m *testing.M) { var err error - testenv, err = StartTestEnvironment(nil, false) + testenv, err = StartTestEnvironment(false) if err != nil { log.Fatal(err) } diff --git a/pkg/test/utils/mock_control_plane.go b/pkg/test/utils/mock_control_plane.go deleted file mode 100644 index 2ea66992..00000000 --- a/pkg/test/utils/mock_control_plane.go +++ /dev/null @@ -1,22 +0,0 @@ -package utils - -import ( - "bufio" - "os" -) - -// ReadMockControllerConfig reads the mock control plane config file -func ReadMockControllerConfig(filename string) (config []string, err error) { - file, err := os.Open(filename) - if err != nil { - return - } - defer file.Close() - - scanner := bufio.NewScanner(file) - for scanner.Scan() { - config = append(config, scanner.Text()) - } - err = scanner.Err() - return -}