Skip to content

Commit

Permalink
retry on cryostat update conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg committed Apr 9, 2024
1 parent 6b63e3f commit 38e4d6e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ metadata:
capabilities: Seamless Upgrades
categories: Monitoring, Developer Tools
containerImage: quay.io/cryostat/cryostat-operator:2.5.0-dev
createdAt: "2024-04-04T17:17:25Z"
createdAt: "2024-03-27T17:54:03Z"
description: JVM monitoring and profiling tool
operatorframework.io/initialization-resource: |-
{
Expand Down
10 changes: 5 additions & 5 deletions config/scorecard/patches/custom.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
entrypoint:
- cryostat-scorecard-tests
- operator-install
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171725"
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240327175405"
labels:
suite: cryostat
test: operator-install
Expand All @@ -18,7 +18,7 @@
entrypoint:
- cryostat-scorecard-tests
- cryostat-cr
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171725"
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240327175405"
labels:
suite: cryostat
test: cryostat-cr
Expand All @@ -38,7 +38,7 @@
entrypoint:
- cryostat-scorecard-tests
- cryostat-recording
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171725"
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240327175405"
labels:
suite: cryostat
test: cryostat-recording
Expand All @@ -48,7 +48,7 @@
entrypoint:
- cryostat-scorecard-tests
- cryostat-config-change
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171725"
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240327175405"
labels:
suite: cryostat
test: cryostat-config-change
Expand All @@ -58,7 +58,7 @@
entrypoint:
- cryostat-scorecard-tests
- cryostat-report
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171725"
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240327175405"
labels:
suite: cryostat
test: cryostat-report
30 changes: 27 additions & 3 deletions internal/test/scorecard/common_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ import (
corev1 "k8s.io/api/core/v1"
netv1 "k8s.io/api/networking/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/util/retry"
)

const (
Expand Down Expand Up @@ -512,10 +514,32 @@ func (r *TestResources) sendHealthRequest(base *url.URL, healthCheck func(resp *
}

func (r *TestResources) updateAndWaitTillCryostatAvailable(cr *operatorv1beta1.Cryostat) error {
cr, err := r.Client.OperatorCRDs().Cryostats(cr.Namespace).Update(context.Background(), cr)
if err != nil {
r.Log += fmt.Sprintf("failed to update Cryostat CR: %s", err.Error())
ctx := context.Background()

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

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

_, err = r.Client.OperatorCRDs().Cryostats(cr.Namespace).Update(context.Background(), cr)
return err
})
if err != nil {
return fmt.Errorf("failed to update Cryostat CR: %s", err.Error())
}

// Poll the deployment until it becomes available or we timeout
Expand Down
23 changes: 0 additions & 23 deletions internal/test/scorecard/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
operatorv1beta1 "github.com/cryostatio/cryostat-operator/api/v1beta1"
scapiv1alpha3 "github.com/operator-framework/api/pkg/apis/scorecard/v1alpha3"
apimanifests "github.com/operator-framework/api/pkg/manifests"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -128,27 +126,6 @@ func CryostatConfigChangeTest(bundle *apimanifests.Bundle, namespace string, ope
}

// Switch Cryostat CR to PVC for redeployment
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()

cr, err = r.Client.OperatorCRDs().Cryostats(namespace).Get(ctx, CryostatConfigChangeTestName)
if err != nil {
return r.fail(fmt.Sprintf("failed to get Cryostat CR: %s", err.Error()))
}
cr.Spec.StorageOptions = &operatorv1beta1.StorageConfiguration{
PVC: &operatorv1beta1.PersistentVolumeClaimConfig{
Spec: &corev1.PersistentVolumeClaimSpec{
StorageClassName: nil,
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("1Gi"),
},
},
},
},
}

// Wait for redeployment of Cryostat CR
err = r.updateAndWaitTillCryostatAvailable(cr)
if err != nil {
return r.fail(fmt.Sprintf("Cryostat redeployment did not become available: %s", err.Error()))
Expand Down

0 comments on commit 38e4d6e

Please sign in to comment.