in kinder/pkg/cluster/manager/create.go [99:156]
func CreateCluster(clusterName string, options ...CreateOption) error {
flags := &CreateOptions{}
for _, o := range options {
o(flags)
}
// Check if the cluster name already exists
known, err := status.IsKnown(clusterName)
if err != nil {
return err
}
if known {
return errors.Errorf("a cluster with the name %q already exists", clusterName)
}
fmt.Printf("Creating cluster %q ...\n", clusterName)
// attempt to explicitly pull the required node image if it doesn't exist locally
// we don't care if this errors, we'll still try to run which also pulls
ensureNodeImage(flags.image)
handleErr := func(err error) error {
// In case of errors nodes are deleted (except if retain is explicitly set)
if !flags.retain {
if c, err := status.FromDocker(clusterName); err != nil {
log.Error(err)
} else {
for _, n := range c.AllNodes() {
if err := exec.NewHostCmd(
"docker",
"rm",
"-f", // force the container to be deleted now
"-v", // delete volumes
n.Name(),
).Run(); err != nil {
return errors.Wrapf(err, "failed to delete node %s", n.Name())
}
}
}
}
log.Error(err)
return err
}
// Create node containers as defined in the kind config
if err := createNodes(
clusterName,
flags,
); err != nil {
return handleErr(err)
}
fmt.Println()
fmt.Printf("Nodes creation complete. You can now continue creating a Kubernetes cluster using\n")
fmt.Printf("kinder do, the kinder swiss knife 🚀!\n")
return nil
}