From 3f7c172b66bd0e7c7ed373538c51639b699e2b36 Mon Sep 17 00:00:00 2001 From: theloneexplorerquest <150489859+theloneexplorerquest@users.noreply.github.com> Date: Thu, 25 Jul 2024 13:05:05 +1000 Subject: [PATCH] Support persistent volume last phase transition time feature gate field last phase transition time in persistent volume status (#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 <65101411+BBBmau@users.noreply.github.com> Co-authored-by: BBBmau --- .changelog/2417.txt | 1 + ...esource_kubernetes_persistent_volume_v1.go | 29 ++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 .changelog/2417.txt diff --git a/.changelog/2417.txt b/.changelog/2417.txt new file mode 100644 index 0000000000..67d1908e50 --- /dev/null +++ b/.changelog/2417.txt @@ -0,0 +1 @@ +`persistent_volume_v1`: Support PersistentVolumeLastPhaseTransitionTime feature gate in persistent volume status. \ No newline at end of file diff --git a/kubernetes/resource_kubernetes_persistent_volume_v1.go b/kubernetes/resource_kubernetes_persistent_volume_v1.go index ec7ce7abec..e42ef277d1 100644 --- a/kubernetes/resource_kubernetes_persistent_volume_v1.go +++ b/kubernetes/resource_kubernetes_persistent_volume_v1.go @@ -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 }, } @@ -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) @@ -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) }) @@ -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 }