From d67e28e50e5462b762dce467586aabb253898f40 Mon Sep 17 00:00:00 2001 From: Chuck Ha Date: Wed, 19 Jun 2019 14:17:43 -0400 Subject: [PATCH] clean ups Signed-off-by: Chuck Ha --- actuators/machine.go | 28 ---------------------------- cmd/capdctl/main.go | 24 ++++++++---------------- 2 files changed, 8 insertions(+), 44 deletions(-) diff --git a/actuators/machine.go b/actuators/machine.go index cf11219..e80b572 100644 --- a/actuators/machine.go +++ b/actuators/machine.go @@ -22,8 +22,6 @@ import ( "fmt" "time" - v1 "k8s.io/api/core/v1" - "github.com/chuckha/cluster-api-provider-docker/kind/actions" "k8s.io/apimachinery/pkg/types" corev1 "k8s.io/client-go/kubernetes/typed/core/v1" @@ -197,32 +195,6 @@ func (m *Machine) save(old, new *clusterv1.Machine) error { return nil } -// This should be the cloud-provider for docker, but that doesn't exist. -func (m *Machine) setProviderID(node *v1.Node, kindName string) error { - old := node.DeepCopy() - node.Spec.ProviderID = providerID(kindName) - p, err := patch.NewJSONPatch(old, node) - if err != nil { - fmt.Printf("%+v\n", err) - return err - } - fmt.Println("Patches for node", p) - if len(p) != 0 { - pb, err := json.MarshalIndent(p, "", " ") - if err != nil { - fmt.Printf("%+v\n", err) - return err - } - if _, err := m.Core.Nodes().Patch(node.Name, types.JSONPatchType, pb); err != nil { - fmt.Printf("%+v\n", err) - return err - } - fmt.Println("updated node") - } - return nil - -} - func providerNameToLookupID(providerName string) string { return providerName[len("docker://"):] } diff --git a/cmd/capdctl/main.go b/cmd/capdctl/main.go index cc8af10..16006d5 100644 --- a/cmd/capdctl/main.go +++ b/cmd/capdctl/main.go @@ -22,13 +22,17 @@ import ( "fmt" "io/ioutil" "os" - "strings" "github.com/chuckha/cluster-api-provider-docker/execer" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1" ) +const ( + // Important to keep this consistent. + controlPlaneSet = "controlplane" +) + type machineOptions struct { name, namespace, clusterName, set, version *string } @@ -54,7 +58,7 @@ func main() { controlPlane := flag.NewFlagSet("control-plane", flag.ExitOnError) controlPlaneOpts := new(machineOptions) controlPlaneOpts.initFlags(controlPlane) - *controlPlaneOpts.set = "controlplane" + *controlPlaneOpts.set = controlPlaneSet worker := flag.NewFlagSet("worker", flag.ExitOnError) workerOpts := new(machineOptions) @@ -149,7 +153,7 @@ func machineYAML(opts *machineOptions) string { Namespace: *opts.namespace, Labels: map[string]string{ "cluster.k8s.io/cluster-name": *opts.clusterName, - "set": *opts.set, + "set": *opts.set, }, }, Spec: v1alpha1.MachineSpec{ @@ -157,7 +161,7 @@ func machineYAML(opts *machineOptions) string { }, } // TODO: 🤔 - if *opts.set == "control-plane" { + if *opts.set == controlPlaneSet { machine.Spec.Versions.ControlPlane = *opts.version } if *opts.set == "worker" { @@ -173,18 +177,6 @@ func machineYAML(opts *machineOptions) string { func makeManagementCluster(clusterName string) { kind := execer.NewClient("kind") - // if a cluster named kind already exists then we assume we're good to go: - clusters, err := kind.RunCommandReturnOutput("get", "clusters") - if err != nil { - panic(err) - } - for _, cluster := range strings.Split(clusters, "\n") { - if strings.TrimSpace(cluster) == "kind" { - fmt.Println("Management cluster detected") - return - } - } - // start kind with docker mount kindConfig, err := kindConfigFile() if err != nil {