Skip to content

Commit

Permalink
fix: retry
Browse files Browse the repository at this point in the history
Signed-off-by: sbhat14 <[email protected]>
  • Loading branch information
sbhat14 authored and sbhat14 committed Nov 7, 2024
1 parent a0c20e2 commit 5cf0d3c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
30 changes: 19 additions & 11 deletions pkg/kube/structured/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/http"
"os"
"strconv"
"strings"
"time"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -236,17 +237,24 @@ func PersistentVolExists(kubeClientset kubernetes.Interface, name, expectedPhase
}

func PersistentVolClaimExists(kubeClientset kubernetes.Interface, name, expectedPhase string, namespace string) error {
vol, err := util.RetryOnError(&util.DefaultRetry, util.IsRetriable, func() (interface{}, error) {
return GetPersistentVolumeClaim(kubeClientset, name, namespace)
})
if err != nil {
return err
}
phase := string(vol.(*corev1.PersistentVolumeClaim).Status.Phase)
if phase != expectedPhase {
return fmt.Errorf("persistentvolumeclaim had unexpected phase %v, expected phase %v", phase, expectedPhase)
}
return nil
_, err := util.RetryOnError(
&util.DefaultRetry,
func(err error) bool {
msg := fmt.Sprintf("persistentvolumeclaim had unexpected phase")

Check failure on line 243 in pkg/kube/structured/structured.go

View workflow job for this annotation

GitHub Actions / golangci-lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
return util.IsRetriable(err) || strings.Contains(err.Error(), msg)
},
func() (interface{}, error) {
vol, err := GetPersistentVolumeClaim(kubeClientset, name, namespace)
if err != nil {
return nil, err
}
phase := string(vol.Status.Phase)
if phase != expectedPhase {
return nil, fmt.Errorf("persistentvolumeclaim had unexpected phase %v, expected phase %v", phase, expectedPhase)
}
return nil, nil
})
return err
}

func ValidatePrometheusVolumeClaimTemplatesName(kubeClientset kubernetes.Interface, statefulsetName, namespace, volumeClaimTemplatesName string) error {
Expand Down
10 changes: 10 additions & 0 deletions pkg/kube/structured/structured_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,16 @@ func TestPersistentVolClaimExists(t *testing.T) {
},
wantErr: false,
},
{
name: "pvc found with wrong phase",
args: args{
kubeClientset: fake.NewSimpleClientset(getResource(t, persistentVolumeClaimType, persistentvolumeClaimName)),
name: persistentvolumeClaimName,
namespace: "",
expectedPhase: "Released",
},
wantErr: true,
},
{
name: "pvc not found Test",
args: args{
Expand Down

0 comments on commit 5cf0d3c

Please sign in to comment.