|
| 1 | +// Copyright 2026 Red Hat, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package e2e |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + |
| 20 | + . "github.com/onsi/ginkgo/v2" |
| 21 | + . "github.com/onsi/gomega" |
| 22 | + |
| 23 | + appsv1 "k8s.io/api/apps/v1" |
| 24 | + corev1 "k8s.io/api/core/v1" |
| 25 | + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" |
| 26 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 27 | + "sigs.k8s.io/controller-runtime/pkg/envtest/komega" |
| 28 | + |
| 29 | + configv1 "github.com/openshift/api/config/v1" |
| 30 | + "github.com/openshift/api/features" |
| 31 | + "github.com/openshift/cluster-capi-operator/e2e/framework" |
| 32 | +) |
| 33 | + |
| 34 | +var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:ClusterAPIMachineManagement] Cluster API Machine Management", func() { |
| 35 | + BeforeEach(func() { |
| 36 | + if !framework.IsFeatureGateEnabled(ctx, cl, features.FeatureGateClusterAPIMachineManagement) { |
| 37 | + Skip("Feature gate ClusterAPIMachineManagement is not enabled.") |
| 38 | + } |
| 39 | + }) |
| 40 | + |
| 41 | + Context("Operator & controller deployments", func() { |
| 42 | + It("should have the capi-operator deployment available", func() { |
| 43 | + assertDeploymentAvailable("capi-operator", framework.CAPIOperatorNamespace) |
| 44 | + }) |
| 45 | + |
| 46 | + It("should have the cluster-api ClusterOperator reporting healthy", func() { |
| 47 | + co := &configv1.ClusterOperator{ObjectMeta: metav1.ObjectMeta{Name: framework.CAPIClusterOperatorName}} |
| 48 | + Eventually(komega.Object(co)).WithTimeout(framework.WaitMedium).WithPolling(framework.RetryMedium).Should(SatisfyAll( |
| 49 | + HaveField("Status.Conditions", ContainElement(SatisfyAll( |
| 50 | + HaveField("Type", Equal(configv1.OperatorAvailable)), |
| 51 | + HaveField("Status", Equal(configv1.ConditionTrue)), |
| 52 | + ))), |
| 53 | + HaveField("Status.Conditions", ContainElement(SatisfyAll( |
| 54 | + HaveField("Type", Equal(configv1.OperatorDegraded)), |
| 55 | + HaveField("Status", Equal(configv1.ConditionFalse)), |
| 56 | + ))), |
| 57 | + HaveField("Status.Conditions", ContainElement(SatisfyAll( |
| 58 | + HaveField("Type", Equal(configv1.OperatorProgressing)), |
| 59 | + HaveField("Status", Equal(configv1.ConditionFalse)), |
| 60 | + ))), |
| 61 | + )) |
| 62 | + }) |
| 63 | + |
| 64 | + It("should have the capi-controllers deployment available", func() { |
| 65 | + assertDeploymentAvailable("capi-controllers", framework.CAPINamespace) |
| 66 | + }) |
| 67 | + |
| 68 | + It("should have the capi-installer deployment available", func() { |
| 69 | + assertDeploymentAvailable("capi-installer", framework.CAPIOperatorNamespace) |
| 70 | + }) |
| 71 | + }) |
| 72 | + |
| 73 | + Context("CRD & API readiness", func() { |
| 74 | + It("should have core Cluster API CRDs installed and established", func() { |
| 75 | + for _, name := range []string{ |
| 76 | + "clusters.cluster.x-k8s.io", |
| 77 | + "machines.cluster.x-k8s.io", |
| 78 | + "machinesets.cluster.x-k8s.io", |
| 79 | + } { |
| 80 | + crd := &apiextensionsv1.CustomResourceDefinition{ObjectMeta: metav1.ObjectMeta{Name: name}} |
| 81 | + Eventually(komega.Object(crd)).WithTimeout(framework.WaitMedium).WithPolling(framework.RetryMedium).Should( |
| 82 | + HaveField("Status.Conditions", ContainElement(SatisfyAll( |
| 83 | + HaveField("Type", Equal(apiextensionsv1.Established)), |
| 84 | + HaveField("Status", Equal(apiextensionsv1.ConditionTrue)), |
| 85 | + ))), |
| 86 | + "CRD %s should be established", name, |
| 87 | + ) |
| 88 | + } |
| 89 | + }) |
| 90 | + }) |
| 91 | + |
| 92 | + Context("Management cluster resources", func() { |
| 93 | + It("should have the management cluster kubeconfig Secret present", func() { |
| 94 | + secret := &corev1.Secret{ObjectMeta: metav1.ObjectMeta{ |
| 95 | + Name: fmt.Sprintf("%s-kubeconfig", clusterName), |
| 96 | + Namespace: framework.CAPINamespace, |
| 97 | + }} |
| 98 | + Eventually(komega.Object(secret)).WithTimeout(framework.WaitMedium).WithPolling(framework.RetryMedium).Should( |
| 99 | + HaveField("Data", HaveKey("value")), |
| 100 | + ) |
| 101 | + }) |
| 102 | + }) |
| 103 | + |
| 104 | +}) |
| 105 | + |
| 106 | +func assertDeploymentAvailable(name, namespace string) { |
| 107 | + GinkgoHelper() |
| 108 | + deployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace}} |
| 109 | + Eventually(komega.Object(deployment)).WithTimeout(framework.WaitMedium).WithPolling(framework.RetryMedium).Should( |
| 110 | + HaveField("Status.Conditions", ContainElement(SatisfyAll( |
| 111 | + HaveField("Type", Equal(appsv1.DeploymentAvailable)), |
| 112 | + HaveField("Status", Equal(corev1.ConditionTrue)), |
| 113 | + ))), |
| 114 | + ) |
| 115 | +} |
0 commit comments