|
| 1 | +//go:build e2e |
| 2 | +// +build e2e |
| 3 | + |
| 4 | +package e2e |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + "testing" |
| 9 | + |
| 10 | + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" |
| 11 | + |
| 12 | + configv1 "github.com/openshift/api/config/v1" |
| 13 | + "github.com/openshift/api/features" |
| 14 | + "github.com/openshift/cluster-ingress-operator/pkg/manifests" |
| 15 | + test_crds "github.com/openshift/cluster-ingress-operator/pkg/operator/controller/test/crds" |
| 16 | + |
| 17 | + "k8s.io/apimachinery/pkg/api/errors" |
| 18 | +) |
| 19 | + |
| 20 | +var expectedCRDs = []*apiextensionsv1.CustomResourceDefinition{ |
| 21 | + manifests.GatewayClassCRD_v1_2_1(), |
| 22 | + manifests.GatewayCRD_v1_2_1(), |
| 23 | + manifests.GRPCRouteCRD_v1_2_1(), |
| 24 | + manifests.HTTPRouteCRD_v1_2_1(), |
| 25 | + manifests.ReferenceGrantCRD_v1_2_1(), |
| 26 | +} |
| 27 | + |
| 28 | +var incompatibleCRDs = []*apiextensionsv1.CustomResourceDefinition{ |
| 29 | + test_crds.ListenerSetCRD_experimental_v1(), |
| 30 | + test_crds.TCPRouteCRD_experimental_v1(), |
| 31 | +} |
| 32 | + |
| 33 | +func TestGatewayAPIUpgradeable(t *testing.T) { |
| 34 | + if gatewayAPIEnabled, err := isFeatureGateEnabled(features.FeatureGateGatewayAPI); err != nil { |
| 35 | + t.Fatalf("error checking feature gate enabled status: %v", err) |
| 36 | + } else if gatewayAPIEnabled { |
| 37 | + t.Skip("Gateway API is enabled, skipping TestGatewayAPIUpgradeable") |
| 38 | + } |
| 39 | + |
| 40 | + t.Parallel() |
| 41 | + |
| 42 | + defer deleteExistingCRDs(t, append(expectedCRDs, incompatibleCRDs...)) |
| 43 | + |
| 44 | + createCRDs(t, expectedCRDs) |
| 45 | + testOperatorUpgradeableCondition(t, true) |
| 46 | + createCRDs(t, incompatibleCRDs) |
| 47 | + testOperatorUpgradeableCondition(t, false) |
| 48 | +} |
| 49 | + |
| 50 | +func testOperatorUpgradeableCondition(t *testing.T, expectUpgradeable bool) { |
| 51 | + expectedStatusCondition := configv1.ConditionFalse |
| 52 | + if expectUpgradeable { |
| 53 | + expectedStatusCondition = configv1.ConditionTrue |
| 54 | + } |
| 55 | + |
| 56 | + expected := []configv1.ClusterOperatorStatusCondition{ |
| 57 | + {Type: configv1.OperatorUpgradeable, Status: expectedStatusCondition}, |
| 58 | + } |
| 59 | + |
| 60 | + if err := waitForClusterOperatorConditions(t, kclient, expected...); err != nil { |
| 61 | + t.Errorf("did not get expected upgradeable condition: %v", err) |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +func createCRDs(t *testing.T, crds []*apiextensionsv1.CustomResourceDefinition) { |
| 66 | + t.Helper() |
| 67 | + for _, crd := range crds { |
| 68 | + if err := kclient.Create(context.TODO(), crd); err != nil { |
| 69 | + if !errors.IsAlreadyExists(err) { |
| 70 | + t.Fatalf("Failed to create CRD %s: %v", crd.Name, err) |
| 71 | + } |
| 72 | + continue |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +func deleteExistingCRDs(t *testing.T, crds []*apiextensionsv1.CustomResourceDefinition) { |
| 78 | + t.Helper() |
| 79 | + for _, crd := range crds { |
| 80 | + deleteExistingCRD(t, crd.Name) |
| 81 | + } |
| 82 | +} |
0 commit comments