From a529ff05d282fedc5654e4774560e4a4a03eb982 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Fri, 14 Oct 2022 22:41:24 +1300 Subject: [PATCH] minikube_node -> minikube_cluster --- hack/main.go | 2 +- minikube/resource_cluster.go | 4 +- .../{minikube_node.go => minikube_cluster.go} | 38 +++++++++++-------- 3 files changed, 25 insertions(+), 19 deletions(-) rename minikube/service/{minikube_node.go => minikube_cluster.go} (72%) diff --git a/hack/main.go b/hack/main.go index 549bf6c..5ebecd7 100644 --- a/hack/main.go +++ b/hack/main.go @@ -115,7 +115,7 @@ func main() { IsoUrls: []string{"https://github.com/kubernetes/minikube/releases/download/v1.26.1/minikube-v1.26.1-amd64.iso"}, DeleteOnFailure: true}, service.MinikubeClientDeps{ - Node: service.NewMinikubeNode(), + Node: service.NewMinikubeCluster(), Downloader: service.NewMinikubeDownloader(), }) diff --git a/minikube/resource_cluster.go b/minikube/resource_cluster.go index 915b2a2..6b0e902 100644 --- a/minikube/resource_cluster.go +++ b/minikube/resource_cluster.go @@ -172,7 +172,7 @@ func setClusterState(d *schema.ResourceData, config *config.ClusterConfig, ports d.Set("vm_driver", config.VMDriver) } -//getClusterOutputs return the cluster key, certificate and certificate authority from the provided kubeconfig +// getClusterOutputs return the cluster key, certificate and certificate authority from the provided kubeconfig func getClusterOutputs(kc *kubeconfig.Settings) (string, string, string, string, error) { key, err := state_utils.ReadContents(kc.ClientKey) if err != nil { @@ -325,7 +325,7 @@ func initialiseMinikubeClient(d *schema.ResourceData, m interface{}) (service.Cl }) clusterClient.SetDependencies(service.MinikubeClientDeps{ - Node: service.NewMinikubeNode(), + Node: service.NewMinikubeCluster(), Downloader: service.NewMinikubeDownloader(), }) diff --git a/minikube/service/minikube_node.go b/minikube/service/minikube_cluster.go similarity index 72% rename from minikube/service/minikube_node.go rename to minikube/service/minikube_cluster.go index 7bfcef4..37d7a8c 100644 --- a/minikube/service/minikube_node.go +++ b/minikube/service/minikube_cluster.go @@ -7,6 +7,7 @@ import ( "github.com/docker/machine/libmachine" "github.com/docker/machine/libmachine/host" + delete "k8s.io/minikube/cmd/minikube/cmd" "k8s.io/minikube/pkg/minikube/command" "k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/exit" @@ -25,15 +26,15 @@ type Node interface { Add(cc *config.ClusterConfig, starter node.Starter) error } -type MinikubeNode struct { +type MinikubeCluster struct { workerNodes int } -func NewMinikubeNode() *MinikubeNode { - return &MinikubeNode{workerNodes: 0} +func NewMinikubeCluster() *MinikubeCluster { + return &MinikubeCluster{workerNodes: 0} } -func (m *MinikubeNode) Provision(cc *config.ClusterConfig, n *config.Node, apiServer bool, delOnFail bool) (command.Runner, bool, libmachine.API, *host.Host, error) { +func (m *MinikubeCluster) Provision(cc *config.ClusterConfig, n *config.Node, apiServer bool, delOnFail bool) (command.Runner, bool, libmachine.API, *host.Host, error) { makeAllMinikubeDirectories() _, err := node.CacheKubectlBinary(cc.KubernetesConfig.KubernetesVersion, cc.BinaryMirror) if err != nil { @@ -43,13 +44,13 @@ func (m *MinikubeNode) Provision(cc *config.ClusterConfig, n *config.Node, apiSe return node.Provision(cc, n, apiServer, delOnFail) } -func (m *MinikubeNode) Start(starter node.Starter, apiServer bool) (*kubeconfig.Settings, error) { +func (m *MinikubeCluster) Start(starter node.Starter, apiServer bool) (*kubeconfig.Settings, error) { return node.Start(starter, apiServer) } -//Add adds nodes to the clusters node pool -func (m *MinikubeNode) Add(cc *config.ClusterConfig, starter node.Starter) error { +// Add adds nodes to the clusters node pool +func (m *MinikubeCluster) Add(cc *config.ClusterConfig, starter node.Starter) error { n := config.Node{ Name: node.Name(m.workerNodes), Worker: true, @@ -61,28 +62,33 @@ func (m *MinikubeNode) Add(cc *config.ClusterConfig, starter node.Starter) error return node.Add(cc, n, true) } -func (m *MinikubeNode) Delete(cc config.ClusterConfig, name string) (*config.Node, error) { - node, err := node.Delete(cc, name) - if err != nil { - return node, err +func (m *MinikubeCluster) Delete(cc config.ClusterConfig, name string) (*config.Node, error) { + errs := delete.DeleteProfiles([]*config.Profile{ + { + Name: name, + Config: &cc, + }, + }) + if len(errs) > 0 { + return nil, errs[0] } machineDir := filepath.Join(localpath.MiniPath(), "machines", name) profilesDir := filepath.Join(localpath.MiniPath(), "profiles", name) - err = rmdir(machineDir) + err := rmdir(machineDir) if err != nil { - return node, err + return nil, err } err = rmdir(profilesDir) if err != nil { - return node, err + return nil, err } - return node, err + return nil, err } -func (m *MinikubeNode) Get(name string) mustload.ClusterController { +func (m *MinikubeCluster) Get(name string) mustload.ClusterController { return mustload.Running(name) }