Skip to content

Commit

Permalink
fix: better check and logging for k8s state (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiGuranIonos authored Jan 14, 2025
1 parent 189c17a commit bc2af33
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Add `auto_scaling` attribute to `ionoscloud_dataplatform_node_pool` resource.
### Fixes
- Omitting the `location` attribute for some resources no longer generates an error
- Better check and log for k8s resources polling

## 6.6.7
### Fix
Expand Down
7 changes: 5 additions & 2 deletions ionoscloud/resource_k8s_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"strings"
"time"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
Expand Down Expand Up @@ -262,7 +263,7 @@ func resourcek8sClusterCreate(ctx context.Context, d *schema.ResourceData, meta
log.Printf("[INFO] Created k8s cluster: %s", d.Id())

for {
log.Printf("[INFO] Waiting for cluster %s to be ready...", d.Id())
log.Printf("[INFO] Waiting for cluster %s to be ACTIVE ...", d.Id())

clusterReady, rsErr := k8sClusterReady(ctx, client, d)

Expand Down Expand Up @@ -632,7 +633,9 @@ func k8sClusterReady(ctx context.Context, client *ionoscloud.APIClient, d *schem
if utils.IsStateFailed(*resource.Metadata.State) {
return false, fmt.Errorf("error while checking if k8s cluster is ready %s, state %s", *resource.Id, *resource.Metadata.State)
}
return *resource.Metadata.State == "ACTIVE", nil
log.Printf("[INFO] k8s cluster state: %s", *resource.Metadata.State)
// k8s is the only resource that has a state of ACTIVE when it is ready
return strings.EqualFold(*resource.Metadata.State, ionoscloud.Active), nil
}

func k8sClusterDeleted(ctx context.Context, client *ionoscloud.APIClient, d *schema.ResourceData) (bool, error) {
Expand Down
4 changes: 3 additions & 1 deletion ionoscloud/resource_k8s_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,9 @@ func k8sNodepoolReady(ctx context.Context, client *ionoscloud.APIClient, d *sche
if utils.IsStateFailed(*resource.Metadata.State) {
return false, fmt.Errorf("error while checking if k8s nodepool is ready %s, state %s", *resource.Id, *resource.Metadata.State)
}
return *resource.Metadata.State == "ACTIVE", nil
log.Printf("[INFO] k8s nodepool state: %s", *resource.Metadata.State)
// k8s is the only resource that has a state of ACTIVE when it is ready
return strings.EqualFold(*resource.Metadata.State, ionoscloud.Active), nil
}

func k8sNodepoolDeleted(ctx context.Context, client *ionoscloud.APIClient, d *schema.ResourceData) (bool, error) {
Expand Down

0 comments on commit bc2af33

Please sign in to comment.