diff --git a/Makefile b/Makefile index 825b466..987cf3a 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/cmd/destroy.go b/cmd/destroy.go index 61e2d96..a797a3d 100644 --- a/cmd/destroy.go +++ b/cmd/destroy.go @@ -20,7 +20,6 @@ import ( "github.com/spf13/cobra" "swdt/apis/config/v1alpha1" "swdt/pkg/drivers" - "swdt/pkg/exec" ) // destroyCmd represents the destroy command @@ -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 } diff --git a/cmd/kubernetes.go b/cmd/kubernetes.go index 62cdba4..30036ef 100644 --- a/cmd/kubernetes.go +++ b/cmd/kubernetes.go @@ -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" ) @@ -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 } diff --git a/cmd/setup.go b/cmd/setup.go index e24efad..fab7de5 100644 --- a/cmd/setup.go +++ b/cmd/setup.go @@ -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" ) @@ -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 } diff --git a/cmd/start.go b/cmd/start.go index ca53443..04e607c 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -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 ( @@ -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 @@ -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 } diff --git a/samples/config.yaml b/samples/config.yaml index b012c96..b608c41 100644 --- a/samples/config.yaml +++ b/samples/config.yaml @@ -17,7 +17,7 @@ spec: username: "Administrator" privateKey: "/home/aknabben/.ssh/id_rsa" auxiliary: - enableRDP: true + enableRDP: false chocoPackages: provisioners: - name: containerd