Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait_till option : normal #4139

Merged
merged 15 commits into from
Nov 9, 2022
48 changes: 44 additions & 4 deletions ibm/service/kubernetes/resource_ibm_container_vpc_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ func ResourceIBMContainerVpcCluster() *schema.Resource {
Optional: true,
Default: ingressReady,
DiffSuppressFunc: flex.ApplyOnce,
ValidateFunc: validation.StringInSlice([]string{masterNodeReady, oneWorkerNodeReady, ingressReady}, true),
Description: "wait_till can be configured for Master Ready, One worker Ready or Ingress Ready",
ValidateFunc: validation.StringInSlice([]string{masterNodeReady, oneWorkerNodeReady, ingressReady, normal}, true),
Description: "wait_till can be configured for Master Ready, One worker Ready or Ingress Ready or normal",
attilatabori marked this conversation as resolved.
Show resolved Hide resolved
},

"entitlement": {
Expand Down Expand Up @@ -482,7 +482,7 @@ func resourceIBMContainerVpcClusterCreate(d *schema.ResourceData, meta interface
// timeoutStage will define the timeout stage
var timeoutStage string
if v, ok := d.GetOk("wait_till"); ok {
timeoutStage = v.(string)
timeoutStage = strings.ToLower(v.(string))
}

var zonesList = make([]v2.Zone, 0)
Expand Down Expand Up @@ -572,7 +572,13 @@ func resourceIBMContainerVpcClusterCreate(d *schema.ResourceData, meta interface
}
}

switch strings.ToLower(timeoutStage) {
switch timeoutStage {

case strings.ToLower(clusterNormal):
_, err = waitForVpcClusterState(d, meta, clusterNormal)
if err != nil {
return err
}

case strings.ToLower(masterNodeReady):
_, err = waitForVpcClusterMasterAvailable(d, meta)
Expand Down Expand Up @@ -1216,6 +1222,40 @@ func waitForVpcClusterOneWorkerAvailable(d *schema.ResourceData, meta interface{
return createStateConf.WaitForState()
}

func waitForVpcClusterState(d *schema.ResourceData, meta interface{}, waitForState string) (interface{}, error) {
targetEnv, err := getVpcClusterTargetHeader(d, meta)
if err != nil {
return nil, err
}
csClient, err := meta.(conns.ClientSession).VpcContainerAPI()
if err != nil {
return nil, err
}
clusterID := d.Id()
createStateConf := &resource.StateChangeConf{
Pending: []string{deployRequested, deployInProgress},
attilatabori marked this conversation as resolved.
Show resolved Hide resolved
Target: []string{normal},
attilatabori marked this conversation as resolved.
Show resolved Hide resolved
Refresh: func() (interface{}, string, error) {
clusterInfo, clusterInfoErr := csClient.Clusters().GetCluster(clusterID, targetEnv)

if err != nil || clusterInfoErr != nil {
attilatabori marked this conversation as resolved.
Show resolved Hide resolved
return clusterInfo, deployInProgress, clusterInfoErr
}

if clusterInfo.State == strings.ToLower(waitForState) {
return clusterInfo, waitForState, nil
}
return clusterInfo, deployInProgress, nil
attilatabori marked this conversation as resolved.
Show resolved Hide resolved

},
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 10 * time.Second,
MinTimeout: 5 * time.Second,
ContinuousTargetOccurence: 5,
}
return createStateConf.WaitForState()
}

func waitForVpcClusterMasterAvailable(d *schema.ResourceData, meta interface{}) (interface{}, error) {
targetEnv, err := getVpcClusterTargetHeader(d, meta)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,10 @@ func testAccCheckIBMContainerVpcClusterEnvvar(name string) string {
subnet_id = "%[4]s"
name = "us-south-1"
}
kms_instance_id = "%[5]s"
crk = "%[6]s"
kms_account_id = "%[7]s"
wait_till = "normal"
# kms_instance_id = "%[5]s"
attilatabori marked this conversation as resolved.
Show resolved Hide resolved
# crk = "%[6]s"
# kms_account_id = "%[7]s"
}
`, name, acc.IksClusterVpcID, acc.IksClusterResourceGroupID, acc.IksClusterSubnetID, acc.KmsInstanceID, acc.CrkID, acc.KmsAccountID)
fmt.Println(config)
Expand Down