Skip to content

Commit

Permalink
Support persistent volume last phase transition time feature gate fie…
Browse files Browse the repository at this point in the history
…ld last phase transition time in persistent volume status (hashicorp#2417)

* include message and PersistentVolume Last Phase Transition Time

* update to include feature gate feature

* update to include feature gate feature

* update to include feature gate feature

* update job spec

* update job spec

* update pv

* update pv

* update pv resource to include persistent volume last transition time

* add changelog

---------

Co-authored-by: Mauricio Alvarez Leon <[email protected]>
Co-authored-by: BBBmau <[email protected]>
  • Loading branch information
3 people authored Jul 25, 2024
1 parent 4f44a9a commit 3f7c172
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions .changelog/2417.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`persistent_volume_v1`: Support PersistentVolumeLastPhaseTransitionTime feature gate in persistent volume status.
29 changes: 25 additions & 4 deletions kubernetes/resource_kubernetes_persistent_volume_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,15 @@ func resourceKubernetesPersistentVolumeV1Create(ctx context.Context, d *schema.R
}

statusPhase := fmt.Sprintf("%v", out.Status.Phase)
log.Printf("[DEBUG] Persistent volume %s status received: %#v", out.Name, statusPhase)
statusMessage := fmt.Sprintf("%v", out.Status.Message)
if statusMessage == "" {
log.Printf("[DEBUG] Persistent volume %s status received: %#v", out.Name, statusPhase)
} else {
log.Printf("[DEBUG] Persistent volume %s status received: %#v, message received: %#v", out.Name, statusPhase, statusMessage)
}
if out.Status.LastPhaseTransitionTime != nil {
log.Printf("[DEBUG] Persistent volume last phrase transition time: %v", out.Status.LastPhaseTransitionTime)
}
return out, statusPhase, nil
},
}
Expand Down Expand Up @@ -279,6 +287,9 @@ func resourceKubernetesPersistentVolumeV1Read(ctx context.Context, d *schema.Res
return diag.FromErr(err)
}
log.Printf("[INFO] Received persistent volume: %#v", volume)
if volume.Status.LastPhaseTransitionTime != nil {
log.Printf("[DEBUG] Persistent volume last phrase transition time: %v", volume.Status.LastPhaseTransitionTime)
}
err = d.Set("metadata", flattenMetadata(volume.ObjectMeta, d, meta))
if err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -345,8 +356,15 @@ func resourceKubernetesPersistentVolumeV1Delete(ctx context.Context, d *schema.R
}
return retry.NonRetryableError(err)
}

log.Printf("[DEBUG] Current state of persistent volume: %#v", out.Status.Phase)
statusMessage := fmt.Sprintf("%v", out.Status.Message)
if statusMessage == "" {
log.Printf("[DEBUG] Current state of persistent volume: %#v", out.Status.Phase)
} else {
log.Printf("[DEBUG] Current state of persistent volume: %#v, message received: %#v", out.Status.Phase, out.Status.Message)
}
if out.Status.LastPhaseTransitionTime != nil {
log.Printf("[DEBUG] Persistent volume last phrase transition time: %v", out.Status.LastPhaseTransitionTime)
}
e := fmt.Errorf("Persistent volume %s still exists (%s)", name, out.Status.Phase)
return retry.RetryableError(e)
})
Expand All @@ -368,12 +386,15 @@ func resourceKubernetesPersistentVolumeV1Exists(ctx context.Context, d *schema.R

name := d.Id()
log.Printf("[INFO] Checking persistent volume %s", name)
_, err = conn.CoreV1().PersistentVolumes().Get(ctx, name, metav1.GetOptions{})
out, err := conn.CoreV1().PersistentVolumes().Get(ctx, name, metav1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
return false, nil
}
log.Printf("[DEBUG] Received error: %#v", err)
}
if out.Status.LastPhaseTransitionTime != nil {
log.Printf("[DEBUG] Persistent volume last phrase transition time: %v", out.Status.LastPhaseTransitionTime)
}
return true, err
}

0 comments on commit 3f7c172

Please sign in to comment.