e2e-framework icon indicating copy to clipboard operation
e2e-framework copied to clipboard

Start multi clusters during the tests

Open helayoty opened this issue 2 years ago • 13 comments

Are we able to use the e2e-framework to start more than one cluster in the setup?

helayoty avatar May 26 '22 01:05 helayoty

I was able to create 2 kind clusters in the Setup main_test. How I can switch context between them? @vladimirvivien

helayoty avatar May 26 '22 23:05 helayoty

Not sure you can switch context now. But that sounds like it's the ask: ability to switch kind context.

vladimirvivien avatar May 27 '22 01:05 vladimirvivien

I'd love if we can have this feature as soon as we can.

helayoty avatar May 27 '22 02:05 helayoty

@helayoty can you drop in a code snippet that shows exactly where/how this would be useful. Or, at least elaborate on the user story a bit? That way anyone of us can pick it up and run with an implementation (maybe if I have cycle I can do something with it). Thanks again for bringing this upl.

vladimirvivien avatar May 28 '22 14:05 vladimirvivien

@vladimirvivien Something like

func TestMain(m *testing.M) {
	testEnv = env.NewWithConfig(envconf.New())
	// Create kind clusters
	testEnv.Setup(
		envfuncs.CreateKindClusterWithConfig("cluster1", "kindest/node:v1.23.5", "kind-config.yaml"),
		envfuncs.LoadDockerImageToCluster("cluster1", "image"),
		deployChart("cluster1","helm_chart_path"),
		envfuncs.CreateKindClusterWithConfig("cluster2", "kindest/node:v1.23.5", "kind-config.yaml"),
		envfuncs.LoadDockerImageToCluster("cluster2", "image"),
	).Finish( // Cleanup KinD Cluster
		envfuncs.DestroyKindCluster("cluster1"),
		envfuncs.DestroyKindCluster("cluster2"),
	)

	os.Exit(testEnv.Run(m))
}

func TestSucessScenairo(t *testing.T) {
	successFlow := features.New("Test happy flow").
		Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
			kubeConfig1 := cfg.GetContext("cluster1")
			//deploy something in cluster1
                        kubeConfig2 := cfg.GetContext("cluster2")
                        // deploy something else in cluster2
			return ctx
		}).Assess(" something is happening", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
		//TODO
	}).Feature()

	testEnv.Test(t, successFlow)
}

helayoty avatar Jun 01 '22 02:06 helayoty

This seems doable. But Might need add a few new API to support this with backward compatibility. Especially for things such as cfg.NewClient() and cfg.Client which can take a cluster name context and then use the right kube-config from there. Also some of the current behavior of how the cfg.NewClient works needs a bit of tuning. It does a whole lot to optimize creation of new client.

I for sure like the idea of being able to support multiple clusters at the same time and switch between them using a context during the test execution. However, can the same not be achieved by running the same test binary twice by setting different env variables that you can use to define your Setup and then under Assess accordingly ?

harshanarayana avatar Jun 03 '22 07:06 harshanarayana

However, can the same not be achieved by running the same test binary twice by setting different env variables that you can use to define your Setup and then under Assess accordingly ?

@harshanarayana I tried to do so but it seems if something went wrong the shutdown/destroy test env is not working correctly.

helayoty avatar Jun 03 '22 17:06 helayoty

@helayoty interesting. Does that leave traces of test cluster behind? What kind of issue did you run into?

harshanarayana avatar Jun 03 '22 17:06 harshanarayana

I think we should start a bit more details Design doc if we really want to tackle this. I tested a few things for quick check and there is a considerable amount of places where this will spread into. Retaining backward compatibility should also be accounted for.

harshanarayana avatar Jun 06 '22 16:06 harshanarayana

Maybe solution/design is the following:

  • Start 1 or more cluster in env.Setup, each having its respective context
  • In assessment, have the ability to set the cluster context like cfg.WithClusterContext(...).Resources().ClusterOperation(...)
  • Then delete clusters in env.Finish

Essentially, have the ability to set cluster context name and the ability to specify the cluster context during cluster operation.

vladimirvivien avatar Jun 07 '22 22:06 vladimirvivien

This was the similar thing i had in mind.. I was thinking of extending the context to the NewClient calls as well though.. Let me draft a design and open a PR to discuss further

/assign

harshanarayana avatar Jun 08 '22 04:06 harshanarayana

/assign

harshanarayana avatar Jun 08 '22 04:06 harshanarayana

@helayoty @vladimirvivien This was always possible without actually adding a new API. Turns out there was a small change required to get it working. I am opening a draft PR with the example of how to run multi kind cluster test with the small change required to get it working. Let me know what you think about it. Do we still need to add a new API or document the current one ? I am kind of inclined towards document with example.

harshanarayana avatar Jul 08 '22 17:07 harshanarayana