From a1dccd1bd8e46a86f9110a052b0cdee84ad32ae9 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Sat, 3 Jun 2023 12:08:23 +0200 Subject: [PATCH 1/2] Add option for using ramdisk for etcd Signed-off-by: Pablo Chacin --- e2e/cluster/cluster_e2e_test.go | 25 ++++++++++++++++++++++++- pkg/testutils/cluster/cluster.go | 14 ++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/e2e/cluster/cluster_e2e_test.go b/e2e/cluster/cluster_e2e_test.go index bb4475cc..c8a32a77 100644 --- a/e2e/cluster/cluster_e2e_test.go +++ b/e2e/cluster/cluster_e2e_test.go @@ -41,6 +41,30 @@ func Test_DefaultConfig(t *testing.T) { cluster.Delete() } +func Test_UseEtcdRamDisk(t *testing.T) { + // create cluster with default configuration + config, err := cluster.NewConfig( + "e2e-etcdramdisk-cluster", + cluster.Options{ + Wait: time.Second * 60, + UseEtcdRAMDisk: true, + }, + ) + if err != nil { + t.Errorf("failed creating cluster configuration: %v", err) + return + } + + cluster, err := config.Create() + if err != nil { + t.Errorf("failed to create cluster: %v", err) + return + } + + // delete cluster + cluster.Delete() +} + func getKubernetesClient(kubeconfig string) (kubernetes.Interface, error) { config, err := clientcmd.BuildConfigFromFlags("", kubeconfig) if err != nil { @@ -126,7 +150,6 @@ func Test_PreloadImages(t *testing.T) { } } - func Test_KubernetesVersion(t *testing.T) { // create cluster with default configuration config, err := cluster.NewConfig( diff --git a/pkg/testutils/cluster/cluster.go b/pkg/testutils/cluster/cluster.go index 556a7344..b861e448 100644 --- a/pkg/testutils/cluster/cluster.go +++ b/pkg/testutils/cluster/cluster.go @@ -31,6 +31,14 @@ apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane` +const etcdPatch = ` +kubeadmConfigPatches: +- | + kind: ClusterConfiguration + etcd: + local: + dataDir: /tmp/etcd` + const kindPortMapping = ` - containerPort: %d hostPort: %d @@ -62,6 +70,8 @@ type Options struct { Version string // Path to Kubeconfig Kubeconfig string + // UseEtcdRAMDisk + UseEtcdRAMDisk bool } // Config contains the configuration for creating a cluster @@ -117,6 +127,10 @@ func (c *Config) Render() (string, error) { fmt.Fprintf(&config, "\n- role: worker") } + if c.options.UseEtcdRAMDisk { + fmt.Fprintf(&config, "\n%s", etcdPatch) + } + return config.String(), nil } From 4da5d7c69e5c07fcce5eb618fde76f5532f9e565 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Fri, 21 Jul 2023 15:07:09 +0200 Subject: [PATCH 2/2] Use Etcd RAM disk in e2e tests Signed-off-by: Pablo Chacin --- pkg/testutils/e2e/cluster/cluster.go | 30 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/pkg/testutils/e2e/cluster/cluster.go b/pkg/testutils/e2e/cluster/cluster.go index a7cf002b..c5c1d5b7 100644 --- a/pkg/testutils/e2e/cluster/cluster.go +++ b/pkg/testutils/e2e/cluster/cluster.go @@ -21,15 +21,16 @@ type PostInstall func(ctx context.Context, cluster E2eCluster) error // E2eClusterConfig defines the configuration of a e2e test cluster type E2eClusterConfig struct { - Name string - Images []string - IngressAddr string - IngressPort int32 - PostInstall []PostInstall - Reuse bool - Wait time.Duration - AutoCleanup bool - Kubeconfig string + Name string + Images []string + IngressAddr string + IngressPort int32 + PostInstall []PostInstall + Reuse bool + Wait time.Duration + AutoCleanup bool + Kubeconfig string + UseEtcdRAMDisk bool } // E2eCluster defines the interface for accessing an e2e cluster @@ -116,6 +117,7 @@ func DefaultE2eClusterConfig() E2eClusterConfig { PostInstall: []PostInstall{ InstallContourIngress, }, + UseEtcdRAMDisk: true, } } @@ -178,6 +180,14 @@ func WithReuse(reuse bool) E2eClusterOption { } } +// WithEtcdRAMDisk specifies if the cluster must be configured to use a RAM disk for Etcd +func WithEtcdRAMDisk(ramdisk bool) E2eClusterOption { + return func(c E2eClusterConfig) (E2eClusterConfig, error) { + c.UseEtcdRAMDisk = ramdisk + return c, nil + } +} + // e2eCluster maintains the status of a cluster type e2eCluster struct { cluster *cluster.Cluster @@ -199,6 +209,7 @@ func createE2eCluster(e2eConfig E2eClusterConfig) (*e2eCluster, error) { NodePort: 80, }, }, + UseEtcdRAMDisk: e2eConfig.UseEtcdRAMDisk, }, ) if err != nil { @@ -236,6 +247,7 @@ func createE2eCluster(e2eConfig E2eClusterConfig) (*e2eCluster, error) { func mergeEnvVariables(config E2eClusterConfig) E2eClusterConfig { config.AutoCleanup = utils.GetBooleanEnvVar("E2E_AUTOCLEANUP", config.AutoCleanup) config.Reuse = utils.GetBooleanEnvVar("E2E_REUSE", config.Reuse) + config.UseEtcdRAMDisk = utils.GetBooleanEnvVar("E2E_ETCD_RAMDISK", config.UseEtcdRAMDisk) return config }