Skip to content

Commit

Permalink
test(scorecard): retry on cryostat update conflict (backport #774) (#797
Browse files Browse the repository at this point in the history
)

* test(scorecard): retry on cryostat update conflict (#774)

* retry on cryostat update conflict

* review

* review

(cherry picked from commit d7b0379)

# Conflicts:
#	bundle/manifests/cryostat-operator.clusterserviceversion.yaml
#	bundle/tests/scorecard/config.yaml
#	config/scorecard/patches/custom.config.yaml
#	internal/test/scorecard/common_utils.go
#	internal/test/scorecard/tests.go

* Fix conflicts

---------

Co-authored-by: Ming Yu Wang <[email protected]>
Co-authored-by: Elliott Baron <[email protected]>
  • Loading branch information
3 people authored Apr 16, 2024
1 parent f799098 commit 8ed858b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ metadata:
capabilities: Seamless Upgrades
categories: Monitoring, Developer Tools
containerImage: quay.io/cryostat/cryostat-operator:3.0.0-dev
createdAt: "2024-04-16T19:14:19Z"
createdAt: "2024-04-16T21:08:10Z"
description: JVM monitoring and profiling tool
operatorframework.io/initialization-resource: |-
{
Expand Down
12 changes: 6 additions & 6 deletions bundle/tests/scorecard/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ stages:
- entrypoint:
- cryostat-scorecard-tests
- operator-install
image: quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416191245
image: quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416210645
labels:
suite: cryostat
test: operator-install
Expand All @@ -80,7 +80,7 @@ stages:
- entrypoint:
- cryostat-scorecard-tests
- cryostat-cr
image: quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416191245
image: quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416210645
labels:
suite: cryostat
test: cryostat-cr
Expand All @@ -90,7 +90,7 @@ stages:
- entrypoint:
- cryostat-scorecard-tests
- cryostat-multi-namespace
image: quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416191245
image: quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416210645
labels:
suite: cryostat
test: cryostat-multi-namespace
Expand All @@ -100,7 +100,7 @@ stages:
- entrypoint:
- cryostat-scorecard-tests
- cryostat-recording
image: quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416191245
image: quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416210645
labels:
suite: cryostat
test: cryostat-recording
Expand All @@ -110,7 +110,7 @@ stages:
- entrypoint:
- cryostat-scorecard-tests
- cryostat-config-change
image: quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416191245
image: quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416210645
labels:
suite: cryostat
test: cryostat-config-change
Expand All @@ -120,7 +120,7 @@ stages:
- entrypoint:
- cryostat-scorecard-tests
- cryostat-report
image: quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416191245
image: quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416210645
labels:
suite: cryostat
test: cryostat-report
Expand Down
12 changes: 6 additions & 6 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:3.0.0-20240416191245"
image: "quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416210645"
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:3.0.0-20240416191245"
image: "quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416210645"
labels:
suite: cryostat
test: cryostat-cr
Expand All @@ -28,7 +28,7 @@
entrypoint:
- cryostat-scorecard-tests
- cryostat-multi-namespace
image: "quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416191245"
image: "quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416210645"
labels:
suite: cryostat
test: cryostat-multi-namespace
Expand All @@ -38,7 +38,7 @@
entrypoint:
- cryostat-scorecard-tests
- cryostat-recording
image: "quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416191245"
image: "quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416210645"
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:3.0.0-20240416191245"
image: "quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416210645"
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:3.0.0-20240416191245"
image: "quay.io/cryostat/cryostat-operator-scorecard:3.0.0-20240416210645"
labels:
suite: cryostat
test: cryostat-report
37 changes: 31 additions & 6 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 @@ -479,11 +481,34 @@ func (r *TestResources) sendHealthRequest(base *url.URL, healthCheck func(resp *
return err
}

func (r *TestResources) updateAndWaitTillCryostatAvailable(cr *operatorv1beta2.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())
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", 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
})
if err != nil {
return nil, fmt.Errorf("failed to update Cryostat CR: %s", err.Error())
}

// Poll the deployment until it becomes available or we timeout
Expand Down Expand Up @@ -537,9 +562,9 @@ func (r *TestResources) updateAndWaitTillCryostatAvailable(cr *operatorv1beta2.C
return false, nil
})
if err != nil {
return fmt.Errorf("failed to look up deployment errors: %s", err.Error())
return nil, fmt.Errorf("failed to look up deployment errors: %s", err.Error())
}
return err
return cr, err
}

func (r *TestResources) cleanupAndLogs() {
Expand Down
26 changes: 2 additions & 24 deletions internal/test/scorecard/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
operatorv1beta2 "github.com/cryostatio/cryostat-operator/api/v1beta2"
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 @@ -125,34 +123,14 @@ 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 = &operatorv1beta2.StorageConfiguration{
PVC: &operatorv1beta2.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)
cr, err = r.updateAndWaitTillCryostatAvailable(cr)
if err != nil {
return r.fail(fmt.Sprintf("Cryostat redeployment did not become available: %s", err.Error()))
}
r.Log += "Cryostat deployment has successfully updated with new spec template\n"

base, err := url.Parse(cr.Status.ApplicationURL)
r.Log += fmt.Sprintf("base url: %s\n", base)
if err != nil {
return r.fail(fmt.Sprintf("application URL is invalid: %s", err.Error()))
}
Expand Down

0 comments on commit 8ed858b

Please sign in to comment.