Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tmpfs for etcd in e2e test clusters #180

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion e2e/cluster/cluster_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions pkg/testutils/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
30 changes: 21 additions & 9 deletions pkg/testutils/e2e/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -116,6 +117,7 @@ func DefaultE2eClusterConfig() E2eClusterConfig {
PostInstall: []PostInstall{
InstallContourIngress,
},
UseEtcdRAMDisk: true,
}
}

Expand Down Expand Up @@ -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
Expand All @@ -199,6 +209,7 @@ func createE2eCluster(e2eConfig E2eClusterConfig) (*e2eCluster, error) {
NodePort: 80,
},
},
UseEtcdRAMDisk: e2eConfig.UseEtcdRAMDisk,
},
)
if err != nil {
Expand Down Expand Up @@ -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
}

Expand Down