Skip to content

Commit

Permalink
test/e2e/livirt: allow prop file overwrite cluster name
Browse files Browse the repository at this point in the history
Creates a cluster_name property that can be added to the libvirt
properties file and corresponding LibvirtProvisioner struct.

Before createCluster executes kcli_cluster.sh, it adds the cluster name,
network, and storage pool to the environment.

Fixes: #1163

Signed-off-by: Derek Lee <derlee@redhat.com>
  • Loading branch information
Derek Lee committed Jul 17, 2023
1 parent 5997d81 commit 959be76
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libvirt/kcli_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ create () {
-P disk_size="$CLUSTER_DISK_SIZE" \
"$CLUSTER_NAME"

export KUBECONFIG=$HOME/.kcli/clusters/peer-pods/auth/kubeconfig
export KUBECONFIG=$HOME/.kcli/clusters/$CLUSTER_NAME/auth/kubeconfig

local cmd="kubectl get nodes | grep '\<Ready\>.*worker'"
echo "Wait at least one worker be Ready"
Expand Down
1 change: 1 addition & 0 deletions test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Use the properties on the table below for Libvirt:
|libvirt_ssh_key_file|Path to SSH private key||
|pause_image|k8s pause image||
|vxlan_port| VXLAN port number||
|cluster_name|Cluster Name| "peer-pods"|

# Adding support for a new cloud provider

Expand Down
15 changes: 13 additions & 2 deletions test/provisioner/provision_libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type LibvirtProvisioner struct {
uri string // Libvirt URI
wd string // libvirt's directory path on this repository
volumeName string // Podvm volume name
clusterName string // Cluster name
}

// LibvirtInstallOverlay implements the InstallOverlay interface
Expand Down Expand Up @@ -76,6 +77,11 @@ func NewLibvirtProvisioner(properties map[string]string) (CloudProvisioner, erro
return nil, err
}

clusterName := "peer-pods"
if properties["cluster_name"] != "" {
clusterName = properties["cluster_name"]
}

// TODO: Check network and storage are not nil?
return &LibvirtProvisioner{
conn: conn,
Expand All @@ -85,22 +91,27 @@ func NewLibvirtProvisioner(properties map[string]string) (CloudProvisioner, erro
uri: uri,
wd: wd,
volumeName: vol_name,
clusterName: clusterName,
}, nil
}

func (l *LibvirtProvisioner) CreateCluster(ctx context.Context, cfg *envconf.Config) error {

cmd := exec.Command("/bin/bash", "-c", "./kcli_cluster.sh create")
cmd.Dir = l.wd
cmd.Stdout = os.Stdout
// TODO: better handle stderr. Messages getting out of order.
cmd.Stderr = os.Stderr
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "CLUSTER_NAME="+l.clusterName)
cmd.Env = append(cmd.Env, "LIBVIRT_NETWORK="+l.network)
cmd.Env = append(cmd.Env, "LIBVIRT_POOL="+l.storage)
err := cmd.Run()
if err != nil {
return err
}

// TODO: cluster name should be customized.
clusterName := "peer-pods"
clusterName := l.clusterName
home, _ := os.UserHomeDir()
kubeconfig := path.Join(home, ".kcli/clusters", clusterName, "auth/kubeconfig")
cfg.WithKubeconfigFile(kubeconfig)
Expand Down

0 comments on commit 959be76

Please sign in to comment.