Skip to content

Commit

Permalink
update: add e2e test to mimic CRD API version
Browse files Browse the repository at this point in the history
Signed-off-by: Wen Zhou <[email protected]>
  • Loading branch information
zdtsw committed Feb 6, 2025
1 parent 8f3bfe1 commit c9054ac
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/e2e/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,34 @@ func ensureServicemeshOperators(t *testing.T, tc *testContext) error { //nolint:
func (tc *testContext) setUp(t *testing.T) error { //nolint: thelper
return ensureServicemeshOperators(t, tc)
}

func mockCRDcreation(group, version, kind, componentName string) *apiextv1.CustomResourceDefinition {
return &apiextv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: strings.ToLower(fmt.Sprintf("%ss.%s", kind, group)),
Labels: map[string]string{
labels.ODH.Component(componentName): labels.True,
},
},
Spec: apiextv1.CustomResourceDefinitionSpec{
Group: group,
Names: apiextv1.CustomResourceDefinitionNames{
Kind: kind,
Plural: strings.ToLower(kind) + "s",
},
Scope: apiextv1.ClusterScoped,
Versions: []apiextv1.CustomResourceDefinitionVersion{
{
Name: version,
Served: true,
Storage: true,
Schema: &apiextv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextv1.JSONSchemaProps{
Type: "object",
},
},
},
},
},
}
}
71 changes: 71 additions & 0 deletions tests/e2e/kueue_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package e2e_test

import (
"context"
"strings"
"testing"
"time"

"github.com/blang/semver/v4"
operatorv1 "github.com/openshift/api/operator/v1"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/utils/test/matchers/jq"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/utils/test/testf"

. "github.com/onsi/gomega"
)
Expand All @@ -32,6 +38,7 @@ func kueueTestSuite(t *testing.T) {
t.Run("Validate Kueue Dynamically create VAP and VAPB", componentCtx.validateKueueVAPReady)
t.Run("Validate CRDs reinstated", componentCtx.validateCRDReinstated)
t.Run("Validate component disabled", componentCtx.ValidateComponentDisabled)
t.Run("Validate pre check", componentCtx.validateKueuePreCheck)
t.Run("Validate component releases", componentCtx.ValidateComponentReleases)
}

Expand Down Expand Up @@ -74,3 +81,67 @@ func (tc *KueueTestCtx) validateCRDReinstated(t *testing.T) {
})
}
}

func (tc *KueueTestCtx) validateKueuePreCheck(t *testing.T) {
// validate precheck on CRD version:
// pre-req: skip kueue to removed (done by ValidateComponentDisabled)
// step: delete crd, install old crd, kueue to managed, result to error, delete crd, result to success

g := tc.NewWithT(t)
g.Delete(gvk.CustomResourceDefinition,
types.NamespacedName{Name: "multikueueclusters.kueue.x-k8s.io"},
client.PropagationPolicy(metav1.DeletePropagationForeground),
).Eventually().Should(
Succeed(),
)
g.Delete(gvk.CustomResourceDefinition,
types.NamespacedName{Name: "multikueueconfigs.kueue.x-k8s.io"},
client.PropagationPolicy(metav1.DeletePropagationForeground),
).Eventually().Should(
Succeed(),
)

c1 := mockCRDcreation("kueue.x-k8s.io", "v1alpha1", "multikueuecluster", "kueue")
e1 := tc.Client().Create(context.Background(), c1)
g.Expect(e1).ToNot(HaveOccurred())

c2 := mockCRDcreation("kueue.x-k8s.io", "v1alpha1", "multikueueconfig", "kueue")
e2 := tc.Client().Create(context.Background(), c2)
g.Expect(e2).ToNot(HaveOccurred())

g.Update(
gvk.DataScienceCluster,
tc.DSCName,
testf.Transform(`.spec.components.%s.managementState = "%s"`, strings.ToLower(tc.GVK.Kind), operatorv1.Managed),
).Eventually().Should(
jq.Match(`.spec.components.%s.managementState == "%s"`, strings.ToLower(tc.GVK.Kind), operatorv1.Managed),
)

g.List(gvk.DataScienceCluster).Eventually().Should(And(
HaveLen(1),
HaveEach(And(
jq.Match(`.spec.components.%s.managementState == "%s"`, strings.ToLower(tc.GVK.Kind), operatorv1.Managed),
jq.Match(`.status.conditions[] | select(.type == "%sReady") | .status == "%s"`, tc.GVK.Kind, metav1.ConditionFalse),
)),
))

g.Delete(gvk.CustomResourceDefinition,
types.NamespacedName{Name: "multikueueclusters.kueue.x-k8s.io"},
client.PropagationPolicy(metav1.DeletePropagationForeground),
).Eventually().Should(
Succeed(),
)
g.Delete(gvk.CustomResourceDefinition,
types.NamespacedName{Name: "multikueueconfigs.kueue.x-k8s.io"},
client.PropagationPolicy(metav1.DeletePropagationForeground),
).Eventually().Should(
Succeed(),
)

g.List(gvk.DataScienceCluster).Eventually().Should(And(
HaveLen(1),
HaveEach(
jq.Match(`.status.conditions[] | select(.type == "%sReady") | .status == "%s"`, tc.GVK.Kind, metav1.ConditionTrue),
),
))
}

0 comments on commit c9054ac

Please sign in to comment.