Skip to content

Commit

Permalink
test(scorecard): multi-namespace scorecard test (cryostatio#763)
Browse files Browse the repository at this point in the history
* multi-namespace scorecard test

* kubernetes client makes and removes namespaces

* reviews

---------

Co-authored-by: Elliott Baron <[email protected]>
  • Loading branch information
mwangggg and ebaron authored Apr 5, 2024
1 parent 8aa43a8 commit 6b63e3f
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 78 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-03-27T17:54:03Z"
createdAt: "2024-04-04T17:17:25Z"
description: JVM monitoring and profiling tool
operatorframework.io/initialization-resource: |-
{
Expand Down
20 changes: 15 additions & 5 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:2.5.0-20240326210241
image: quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171629
labels:
suite: cryostat
test: operator-install
Expand All @@ -80,17 +80,27 @@ stages:
- entrypoint:
- cryostat-scorecard-tests
- cryostat-cr
image: quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240326210241
image: quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171629
labels:
suite: cryostat
test: cryostat-cr
storage:
spec:
mountPath: {}
- entrypoint:
- cryostat-scorecard-tests
- cryostat-multi-namespace
image: quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171629
labels:
suite: cryostat
test: cryostat-multi-namespace
storage:
spec:
mountPath: {}
- entrypoint:
- cryostat-scorecard-tests
- cryostat-recording
image: quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240326210241
image: quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171629
labels:
suite: cryostat
test: cryostat-recording
Expand All @@ -100,7 +110,7 @@ stages:
- entrypoint:
- cryostat-scorecard-tests
- cryostat-config-change
image: quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240326210241
image: quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171629
labels:
suite: cryostat
test: cryostat-config-change
Expand All @@ -110,7 +120,7 @@ stages:
- entrypoint:
- cryostat-scorecard-tests
- cryostat-report
image: quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240326210241
image: quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171629
labels:
suite: cryostat
test: cryostat-report
Expand Down
20 changes: 15 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-20240327175405"
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171725"
labels:
suite: cryostat
test: operator-install
Expand All @@ -18,17 +18,27 @@
entrypoint:
- cryostat-scorecard-tests
- cryostat-cr
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240327175405"
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171725"
labels:
suite: cryostat
test: cryostat-cr
- op: add
path: /stages/1/tests/-
value:
entrypoint:
- cryostat-scorecard-tests
- cryostat-multi-namespace
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171725"
labels:
suite: cryostat
test: cryostat-multi-namespace
- op: add
path: /stages/1/tests/-
value:
entrypoint:
- cryostat-scorecard-tests
- cryostat-recording
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240327175405"
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171725"
labels:
suite: cryostat
test: cryostat-recording
Expand All @@ -38,7 +48,7 @@
entrypoint:
- cryostat-scorecard-tests
- cryostat-config-change
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240327175405"
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171725"
labels:
suite: cryostat
test: cryostat-config-change
Expand All @@ -48,7 +58,7 @@
entrypoint:
- cryostat-scorecard-tests
- cryostat-report
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240327175405"
image: "quay.io/cryostat/cryostat-operator-scorecard:2.5.0-20240404171725"
labels:
suite: cryostat
test: cryostat-report
10 changes: 10 additions & 0 deletions hack/custom.config.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
labels:
suite: cryostat
test: cryostat-cr
- op: add
path: /stages/1/tests/-
value:
entrypoint:
- cryostat-scorecard-tests
- cryostat-multi-namespace
image: "${CUSTOM_SCORECARD_IMG}"
labels:
suite: cryostat
test: cryostat-multi-namespace
- op: add
path: /stages/1/tests/-
value:
Expand Down
4 changes: 4 additions & 0 deletions internal/images/custom-scorecard-tests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func printValidTests() []scapiv1alpha3.TestResult {
str := fmt.Sprintf("valid tests for this image include: %s", strings.Join([]string{
tests.OperatorInstallTestName,
tests.CryostatCRTestName,
tests.CryostatMultiNamespaceTestName,
tests.CryostatRecordingTestName,
tests.CryostatConfigChangeTestName,
tests.CryostatReportTestName,
Expand All @@ -93,6 +94,7 @@ func validateTests(testNames []string) bool {
switch testName {
case tests.OperatorInstallTestName:
case tests.CryostatCRTestName:
case tests.CryostatMultiNamespaceTestName:
case tests.CryostatRecordingTestName:
case tests.CryostatConfigChangeTestName:
case tests.CryostatReportTestName:
Expand All @@ -114,6 +116,8 @@ func runTests(testNames []string, bundle *apimanifests.Bundle, namespace string,
results = append(results, *tests.OperatorInstallTest(bundle, namespace, openShiftCertManager))
case tests.CryostatCRTestName:
results = append(results, *tests.CryostatCRTest(bundle, namespace, openShiftCertManager))
case tests.CryostatMultiNamespaceTestName:
results = append(results, *tests.CryostatMultiNamespaceTest(bundle, namespace, openShiftCertManager))
case tests.CryostatRecordingTestName:
results = append(results, *tests.CryostatRecordingTest(bundle, namespace, openShiftCertManager))
case tests.CryostatConfigChangeTestName:
Expand Down
15 changes: 15 additions & 0 deletions internal/images/custom-scorecard-tests/rbac/scorecard_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,18 @@ rules:
- namespaces
verbs:
- create
- delete
- apiGroups:
- operator.cryostat.io
resources:
- clustercryostats
verbs:
- create
- get
- delete
- apiGroups:
- operator.cryostat.io
resources:
- clustercryostats/status
verbs:
- get
56 changes: 43 additions & 13 deletions internal/test/scorecard/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ func (c *OperatorCRDClient) Cryostats(namespace string) *CryostatClient {
}
}

// ClusterCryostats returns a ClusterCryostatClient
func (c *OperatorCRDClient) ClusterCryostats() *CryostatClient {
return &CryostatClient{
restClient: c.client,
resource: "clustercryostats",
}
}

func newOperatorCRDClient(config *rest.Config) (*OperatorCRDClient, error) {
client, err := newCRDClient(config)
if err != nil {
Expand Down Expand Up @@ -124,6 +132,21 @@ type CryostatClient struct {
resource string
}

// Get returns a Cryostat CR for the given name
func (c *CryostatClient) GetNonNamespaced(ctx context.Context, name string) (*operatorv1beta1.ClusterCryostat, error) {
return get(ctx, c.restClient, c.resource, c.namespace, name, &operatorv1beta1.ClusterCryostat{})
}

// Create creates the provided ClusterCryostat CR
func (c *CryostatClient) CreateNonNamespaced(ctx context.Context, obj *operatorv1beta1.ClusterCryostat) (*operatorv1beta1.ClusterCryostat, error) {
return create(ctx, c.restClient, c.resource, c.namespace, obj, &operatorv1beta1.ClusterCryostat{})
}

// Delete deletes the Cryostat CR with the given name
func (c *CryostatClient) DeleteNonNamespaced(ctx context.Context, name string, options *metav1.DeleteOptions) error {
return delete(ctx, c.restClient, c.resource, c.namespace, name, options)
}

// Get returns a Cryostat CR for the given name
func (c *CryostatClient) Get(ctx context.Context, name string) (*operatorv1beta1.Cryostat, error) {
return get(ctx, c.restClient, c.resource, c.namespace, name, &operatorv1beta1.Cryostat{})
Expand All @@ -145,31 +168,38 @@ func (c *CryostatClient) Delete(ctx context.Context, name string, options *metav
}

func get[r runtime.Object](ctx context.Context, c rest.Interface, res string, ns string, name string, result r) (r, error) {
err := c.Get().
Namespace(ns).Resource(res).
Name(name).Do(ctx).Into(result)
rq := c.Get().Resource(res).Name(name)
if len(ns) > 0 {
rq = rq.Namespace(ns)
}
err := rq.Do(ctx).Into(result)
return result, err
}

func create[r runtime.Object](ctx context.Context, c rest.Interface, res string, ns string, obj r, result r) (r, error) {
err := c.Post().
Namespace(ns).Resource(res).
Body(obj).Do(ctx).Into(result)
rq := c.Post().Resource(res).Body(obj)
if len(ns) > 0 {
rq = rq.Namespace(ns)
}
err := rq.Do(ctx).Into(result)
return result, err
}

func update[r runtime.Object](ctx context.Context, c rest.Interface, res string, ns string, obj r, result r, name string) (r, error) {
err := c.Put().
Namespace(ns).Resource(res).Name(name).
Body(obj).Do(ctx).Into(result)
rq := c.Put().Resource(res).Name(name).Body(obj)
if len(ns) > 0 {
rq = rq.Namespace(ns)
}
err := rq.Do(ctx).Into(result)
return result, err
}

func delete(ctx context.Context, c rest.Interface, res string, ns string, name string, opts *metav1.DeleteOptions) error {
return c.Delete().
Namespace(ns).Resource(res).
Name(name).Body(opts).Do(ctx).
Error()
rq := c.Delete().Resource(res).Name(name).Body(opts)
if len(ns) > 0 {
rq = rq.Namespace(ns)
}
return rq.Do(ctx).Error()
}

// CryostatRESTClientset contains methods to interact with
Expand Down
Loading

0 comments on commit 6b63e3f

Please sign in to comment.