Skip to content

Commit

Permalink
test(scorecard): preserve CR when retrying on conflict (#912)
Browse files Browse the repository at this point in the history
* test(scorecard): preserve CR when retrying on conflict

* Don't initialize return value
  • Loading branch information
ebaron authored Jul 10, 2024
1 parent f84caf0 commit e10f18d
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions internal/test/scorecard/common_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,29 +453,8 @@ func (r *TestResources) sendHealthRequest(base *url.URL, healthCheck func(resp *
func (r *TestResources) updateAndWaitTillCryostatAvailable(cr *operatorv1beta2.Cryostat) (*operatorv1beta2.Cryostat, error) {
ctx := context.Background()

err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
var err error
cr, err = r.Client.OperatorCRDs().Cryostats(cr.Namespace).Get(ctx, cr.Name)
if err != nil {
return fmt.Errorf("failed to get Cryostat CR \"%s\": %s", cr.Name, err.Error())
}

cr.Spec.StorageOptions = &operatorv1beta2.StorageConfiguration{
PVC: &operatorv1beta2.PersistentVolumeClaimConfig{
Spec: &corev1.PersistentVolumeClaimSpec{
StorageClassName: nil,
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("1Gi"),
},
},
},
},
}

cr, err = r.Client.OperatorCRDs().Cryostats(cr.Namespace).Update(context.Background(), cr)
return err
})
// Change the CR's storage options in order to trigger a redeployment
cr, err := r.updateStorageOptions(ctx, cr)
if err != nil {
return nil, fmt.Errorf("failed to update Cryostat CR \"%s\": %s", cr.Name, err.Error())
}
Expand Down Expand Up @@ -536,6 +515,33 @@ func (r *TestResources) updateAndWaitTillCryostatAvailable(cr *operatorv1beta2.C
return cr, err
}

func (r *TestResources) updateStorageOptions(ctx context.Context, cr *operatorv1beta2.Cryostat) (*operatorv1beta2.Cryostat, error) {
var result *operatorv1beta2.Cryostat
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
cr, err := r.Client.OperatorCRDs().Cryostats(cr.Namespace).Get(ctx, cr.Name)
if err != nil {
return fmt.Errorf("failed to get Cryostat CR \"%s\": %s", cr.Name, err.Error())
}

cr.Spec.StorageOptions = &operatorv1beta2.StorageConfiguration{
PVC: &operatorv1beta2.PersistentVolumeClaimConfig{
Spec: &corev1.PersistentVolumeClaimSpec{
StorageClassName: nil,
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("1Gi"),
},
},
},
},
}

result, err = r.Client.OperatorCRDs().Cryostats(cr.Namespace).Update(ctx, cr)
return err
})
return result, err
}

func (r *TestResources) cleanupAndLogs() {
r.LogWorkloadEventsOnError()

Expand Down

0 comments on commit e10f18d

Please sign in to comment.