Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Commit

Permalink
Move creating kind control plane into public function
Browse files Browse the repository at this point in the history
  • Loading branch information
liztio committed Jul 15, 2019
1 parent bc3c292 commit da3b509
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
30 changes: 6 additions & 24 deletions cmd/capdctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ import (
"net/http"
"os"
"strings"
"time"

"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/cluster-api-provider-docker/kind/actions"
"sigs.k8s.io/cluster-api-provider-docker/kind/controlplane"
_ "sigs.k8s.io/cluster-api-provider-docker/objects"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
"sigs.k8s.io/kind/pkg/cluster/nodes"
"sigs.k8s.io/kind/pkg/container/cri"
"sigs.k8s.io/kind/pkg/exec"
)

Expand Down Expand Up @@ -251,27 +249,11 @@ func makeManagementCluster(clusterName, capiVersion, capdImage, capiImageOverrid
if capiImageOverride != "" {
capiImage = capiImageOverride
}
elb, err := actions.SetUpLoadBalancer(clusterName)
if err != nil {
panic(err)
}
lbipv4, _, err := elb.IP()
if err != nil {
panic(err)
}
cpMounts := []cri.Mount{
{
ContainerPath: "/var/run/docker.sock",
HostPath: "/var/run/docker.sock",
},
}
cp, err := actions.CreateControlPlane(clusterName, fmt.Sprintf("%s-control-plane", clusterName), lbipv4, "v1.14.2", cpMounts)
if err != nil {

if err := controlplane.CreateKindCluster(capiImage, clusterName); err != nil {
panic(err)
}
if !nodes.WaitForReady(cp, time.Now().Add(5*time.Minute)) {
panic(errors.New("control plane was not ready in 5 minutes"))
}

f, err := ioutil.TempFile("", "crds")
if err != nil {
panic(err)
Expand Down Expand Up @@ -500,5 +482,5 @@ roleRef:
subjects:
- kind: ServiceAccount
name: default
namespace: docker-provider-system
namespace: docker-provider-syste
`
41 changes: 41 additions & 0 deletions kind/controlplane/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package controlplane

import (
"fmt"
"time"

"github.com/pkg/errors"
"sigs.k8s.io/cluster-api-provider-docker/kind/actions"
"sigs.k8s.io/kind/pkg/cluster/nodes"
"sigs.k8s.io/kind/pkg/container/cri"
)

func CreateKindCluster(image, clusterName string) error {
lb, err := actions.SetUpLoadBalancer(clusterName)
if err != nil {
return errors.Wrap(err, "failed to create load balancer")
}

lbipv4, _, err := lb.IP()
if err != nil {
return errors.Wrap(err, "failed to get ELB IP")
}

cpMounts := []cri.Mount{
{
ContainerPath: "/var/run/docker.sock",
HostPath: "/var/run/docker.sock",
},
}

cp, err := actions.CreateControlPlane(clusterName, fmt.Sprintf("%s-control-plane", clusterName), lbipv4, "v1.14.2", cpMounts)
if err != nil {
return errors.Wrap(err, "couldn't create control plane")
}

if !nodes.WaitForReady(cp, time.Now().Add(5*time.Minute)) {
return errors.New("control plane was not ready in 5 minutes")
}

return nil
}

0 comments on commit da3b509

Please sign in to comment.