Skip to content

Commit

Permalink
Wip of commands refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
knabben committed Apr 7, 2024
1 parent 46257fd commit 16a4b1d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 81 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and

.PHONY: test
test:
go test ./... -v 2
go test -cover ./... -v 2

.PHONY: build
build:
Expand Down
5 changes: 2 additions & 3 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/spf13/cobra"
"swdt/apis/config/v1alpha1"
"swdt/pkg/drivers"
"swdt/pkg/exec"
)

// destroyCmd represents the destroy command
Expand Down Expand Up @@ -48,9 +47,9 @@ func RunDestroy(cmd *cobra.Command, args []string) error {

if config.Spec.ControlPlane.Minikube {
// Delete minikube
if _, err = exec.Execute(exec.RunCommand, "minikube", "delete", "--purge"); err != nil {
/*if _, err = exec.Execute(exec.RunCommand, "minikube", "delete", "--purge"); err != nil {
return err
}
}*/
}
return nil
}
Expand Down
41 changes: 20 additions & 21 deletions cmd/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ limitations under the License.
package cmd

import (
"log"
"swdt/apis/config/v1alpha1"
"swdt/pkg/pwsh/executor"
"swdt/pkg/pwsh/kubernetes"

"github.com/spf13/cobra"
)

Expand All @@ -35,23 +30,27 @@ var kubernetesCmd = &cobra.Command{

func RunKubernetes(cmd *cobra.Command, args []string) error {
var (
err error
config *v1alpha1.Cluster
//err error
//config *v1alpha1.Cluster
)
if config, err = loadConfiguration(cmd); err != nil {
return err
}

// Starting the executor
runner, err := executor.NewRunner(config.Spec.Workload.Virtualization.SSH, &kubernetes.KubernetesRunner{})
if err != nil {
return err
}
defer func(runner *executor.Runner[*kubernetes.KubernetesRunner]) {
if err := runner.CloseConnection(); err != nil {
log.Fatalf("error to close the connection: %v\n", err)
/*
if config, err = loadConfiguration(cmd); err != nil {
return err
}
// Starting the executor
runner, err := executor.NewRunner(config.Spec.Workload.Virtualization.SSH, &kubernetes.KubernetesRunner{})
if err != nil {
return err
}
}(runner)
defer func(runner *executor.Runner[*kubernetes.KubernetesRunner]) {
if err := runner.CloseConnection(); err != nil {
log.Fatalf("error to close the connection: %v\n", err)
}
}(runner)
return runner.Inner.InstallProvisioners(config.Spec.Workload.Provisioners)
return runner.Inner.InstallProvisioners(config.Spec.Workload.Provisioners)
*/
return nil
}
71 changes: 30 additions & 41 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ limitations under the License.
package cmd

import (
"k8s.io/klog/v2"
"log"

"github.com/spf13/cobra"
"k8s.io/klog/v2"
"swdt/apis/config/v1alpha1"
"swdt/pkg/drivers"
"swdt/pkg/pwsh/executor"
ifacer "swdt/pkg/pwsh/iface"
"swdt/pkg/pwsh/setup"
)

Expand Down Expand Up @@ -59,63 +57,54 @@ func RunSetup(cmd *cobra.Command, args []string) error {
config.Spec.Workload.Virtualization.SSH.Hostname = leases[windowsHost] + ":22"
}
// Find the control plane IP
_ = leases[controlPlaneHost]
controlPlaneIP := leases[controlPlaneHost]
klog.Info(resc.Sprintf("Found DHCP leases: %v", leases))

// Starting the SSH executor
runner, err := executor.NewRunner(config, &setup.SetupRunner{})
if err != nil {
return err
}
defer func(runner *executor.Runner[*setup.SetupRunner]) {
if err := runner.CloseConnection(); err != nil {
log.Printf("error to close the connection: %v\n", err)
}
}(runner)
ssh := config.Spec.Workload.Virtualization.SSH
r, err := ifacer.NewRunner(ssh, &setup.Runner{Logging: true})

/*
// Install choco binary and packages if a list of packages exists
if len(*config.Spec.Workload.Auxiliary.ChocoPackages) > 0 {
if err = runner.Inner.InstallChoco(); err != nil {
return err
}
// Install Choco packages from the input list
if err = runner.Inner.InstallChocoPackages(*config.Spec.Workload.Auxiliary.ChocoPackages); err != nil {
return err
}
// Install choco binary and packages if a list of packages exists
if len(*config.Spec.Workload.Auxiliary.ChocoPackages) > 0 {
if err = r.Inner.InstallChoco(); err != nil {
return err
}
*/
// Install Choco packages from the input list
if err = r.Inner.InstallChocoPackages(*config.Spec.Workload.Auxiliary.ChocoPackages); err != nil {
return err
}
}

// Enable RDP if option is true
rdp := config.Spec.Workload.Auxiliary.EnableRDP
if err = runner.Inner.EnableRDP(*rdp); err != nil {
if err = r.Inner.EnableRDP(*rdp); err != nil {
return err
}

/*
// Installing Containerd with predefined version
containerd := config.Spec.Workload.ContainerdVersion
if err = runner.Inner.InstallContainerd(containerd); err != nil {
if err = setupRunner.InstallContainerd(containerd); err != nil {
return err
}
// Installing Kubeadm and Kubelet binaries in the host
kubernetes := config.Spec.Workload.KubernetesVersion
if err = runner.Inner.InstallKubernetes(kubernetes); err != nil {
return err
}
// Installing Kubeadm and Kubelet binaries in the host
kubernetes := config.Spec.Workload.KubernetesVersion
if err = runner.Inner.InstallKubernetes(kubernetes); err != nil {
return err
}
// Joining the Windows node in the control plane.
cpKubernetes := config.Spec.ControlPlane.KubernetesVersion
if err = runner.Inner.JoinNode(exec.RunCommand, cpKubernetes, controlPlaneIP); err != nil {
return err
}
*/
// Install Calico CNI operator and CR
// NOTE: Only Calico is supported for now on HPC
if err = runner.Inner.InstallCNI(config.Spec.CalicoVersion); err != nil {
// Joining the Windows node in the control plane.
cpKubernetes := config.Spec.ControlPlane.KubernetesVersion
if err = r.Inner.JoinNode(cpKubernetes, controlPlaneIP); err != nil {
return err
}
/*
// Install Calico CNI operator and CR
// NOTE: Only Calico is supported for now on HPC
/*if err = runner.Inner.InstallCNI(config.Spec.CalicoVersion); err != nil {
return err
}*/

return nil
}
Expand Down
27 changes: 13 additions & 14 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ import (
"strings"
"swdt/apis/config/v1alpha1"

"swdt/pkg/drivers"
"swdt/pkg/exec"

"github.com/spf13/cobra"
"libvirt.org/go/libvirt"
"swdt/pkg/drivers"
)

var (
Expand Down Expand Up @@ -55,11 +53,11 @@ func RunStart(cmd *cobra.Command, args []string) error {

// Start the minikube if the flag is enabled.
if config.Spec.ControlPlane.Minikube {
version := config.Spec.ControlPlane.KubernetesVersion
//version := config.Spec.ControlPlane.KubernetesVersion
klog.Info(resc.Sprintf("Starting a Minikube control plane, this operation can take a while..."))
if err := startMinikube(exec.RunCommand, version); err != nil {
/*if err := startMinikube(exec.RunCommand, version); err != nil {
return err
}
}*/
}

// Start the Windows VM on LibVirt
Expand Down Expand Up @@ -107,14 +105,15 @@ func startWindowsVM(config *v1alpha1.Cluster) error {
// startMinikube initialize a minikube control plane.
func startMinikube(executor interface{}, version string) (err error) {
// Start minikube with KVM2 machine
cmd := []string{
"minikube", "start", "--driver", "kvm2",
"--container-runtime", "containerd",
"--kubernetes-version", version,
}
if _, err = exec.Execute(executor, cmd...); err != nil {
return err
}
/*
cmd := []string{
"minikube", "start", "--driver", "kvm2",
"--container-runtime", "containerd",
"--kubernetes-version", version,
}
if _, err = exec.Execute(executor, cmd...); err != nil {
return err
}*/
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion samples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
username: "Administrator"
privateKey: "/home/aknabben/.ssh/id_rsa"
auxiliary:
enableRDP: true
enableRDP: false
chocoPackages:
provisioners:
- name: containerd
Expand Down

0 comments on commit 16a4b1d

Please sign in to comment.