Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Commit

Permalink
Wait for ready (#15)
Browse files Browse the repository at this point in the history
* add wait_for_ready

* Update resource_kind.go
  • Loading branch information
tehcyx authored Jul 16, 2020
1 parent d24caf6 commit cc37ab9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ provider "kind" {}
resource "kind" "my-cluster" {
name = "test-cluster"
node_image = "kindest/node:v1.18.4"
wait_for_ready = true
kind_config =<<KIONF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
Expand Down
6 changes: 3 additions & 3 deletions kind/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

const (
defaultCreateTimeout = time.Minute * 30
defaultUpdateTimeout = time.Minute * 30
defaultDeleteTimeout = time.Minute * 20
defaultCreateTimeout = time.Minute * 5
defaultUpdateTimeout = time.Minute * 5
defaultDeleteTimeout = time.Minute * 5
)

func Provider() terraform.ResourceProvider {
Expand Down
13 changes: 13 additions & 0 deletions kind/resource_kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ func resourceKind() *schema.Resource {
ForceNew: true,
Computed: true,
},
"wait_for_ready": &schema.Schema{
Type: schema.TypeBool,
Description: `Defines wether or not the provider will wait for the control plane to be ready. Defaults to false`,
Default: false,
ForceNew: true, // TODO remove this once we have the update method defined.
Optional: true,
},
"kind_config": &schema.Schema{
Type: schema.TypeString,
Description: `The kind_config that kind will use.`,
Expand Down Expand Up @@ -88,6 +95,7 @@ func resourceKindCreate(d *schema.ResourceData, meta interface{}) error {
name := d.Get("name").(string)
nodeImage := d.Get("node_image").(string)
config := d.Get("kind_config").(string)
waitForReady := d.Get("wait_for_ready").(bool)

var copts []cluster.CreateOption
if config != "" {
Expand All @@ -102,6 +110,11 @@ func resourceKindCreate(d *schema.ResourceData, meta interface{}) error {
nodeImage = kindDefaults.Image
}

if waitForReady {
copts = append(copts, cluster.CreateWithWaitForReady(defaultCreateTimeout))
log.Printf("Will wait for cluster nodes to report ready: %t\n", waitForReady)
}

log.Println("=================== Creating Kind Cluster ==================")
provider := cluster.NewProvider(cluster.ProviderWithLogger(cmd.NewLogger()))
err := provider.Create(name, copts...)
Expand Down

0 comments on commit cc37ab9

Please sign in to comment.