Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 207 additions & 0 deletions e2e/cluster_api_machine_management.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
// Copyright 2026 Red Hat, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package e2e

import (
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/controller-runtime/pkg/client"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
"github.com/openshift/cluster-capi-operator/e2e/framework"
)


var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:ClusterAPIMachineManagement] Cluster API Machine Management", Ordered, func() {
BeforeAll(func() {
if !framework.IsFeatureGateEnabled(ctx, cl, features.FeatureGateClusterAPIMachineManagement) {
Skip("Feature gate ClusterAPIMachineManagement is not enabled.")
}
})

Context("Operator & controller deployments", func() {
It("should have the capi-operator deployment available", func() {
deployment := &appsv1.Deployment{}
Eventually(func(g Gomega) {
g.Expect(cl.Get(ctx, client.ObjectKey{
Name: "capi-operator",
Namespace: framework.CAPIOperatorNamespace,
}, deployment)).To(Succeed())
g.Expect(deployment.Status.Conditions).To(ContainElement(SatisfyAll(
HaveField("Type", Equal(appsv1.DeploymentAvailable)),
HaveField("Status", Equal(corev1.ConditionTrue)),
)))
}).WithTimeout(framework.WaitMedium).WithPolling(framework.RetryMedium).Should(Succeed())
})

It("should have the cluster-api ClusterOperator reporting healthy", func() {
co := &configv1.ClusterOperator{}
Eventually(func(g Gomega) {
g.Expect(cl.Get(ctx, client.ObjectKey{Name: framework.CAPIClusterOperatorName}, co)).To(Succeed())

By("Checking Available=True, Degraded=False, Progressing=False")
g.Expect(co.Status.Conditions).To(SatisfyAll(
ContainElement(SatisfyAll(
HaveField("Type", Equal(configv1.OperatorAvailable)),
HaveField("Status", Equal(configv1.ConditionTrue)),
)),
ContainElement(SatisfyAll(
HaveField("Type", Equal(configv1.OperatorDegraded)),
HaveField("Status", Equal(configv1.ConditionFalse)),
)),
ContainElement(SatisfyAll(
HaveField("Type", Equal(configv1.OperatorProgressing)),
HaveField("Status", Equal(configv1.ConditionFalse)),
)),
))
}).WithTimeout(framework.WaitMedium).WithPolling(framework.RetryMedium).Should(Succeed())
})

It("should have the capi-controllers deployment available", func() {
deployment := &appsv1.Deployment{}
Eventually(func(g Gomega) {
g.Expect(cl.Get(ctx, client.ObjectKey{
Name: "capi-controllers",
Namespace: framework.CAPINamespace,
}, deployment)).To(Succeed())
g.Expect(deployment.Status.Conditions).To(ContainElement(SatisfyAll(
HaveField("Type", Equal(appsv1.DeploymentAvailable)),
HaveField("Status", Equal(corev1.ConditionTrue)),
)))
}).WithTimeout(framework.WaitMedium).WithPolling(framework.RetryMedium).Should(Succeed())
})

It("should have the capi-installer deployment available", func() {
deployment := &appsv1.Deployment{}
Eventually(func(g Gomega) {
g.Expect(cl.Get(ctx, client.ObjectKey{
Name: "capi-installer",
Namespace: framework.CAPIOperatorNamespace,
}, deployment)).To(Succeed())
g.Expect(deployment.Status.Conditions).To(ContainElement(SatisfyAll(
HaveField("Type", Equal(appsv1.DeploymentAvailable)),
HaveField("Status", Equal(corev1.ConditionTrue)),
)))
}).WithTimeout(framework.WaitMedium).WithPolling(framework.RetryMedium).Should(Succeed())
})

})

Context("Provider images & initialization", func() {
It("should have the capi-installer-images ConfigMap present", func() {
cm := &corev1.ConfigMap{}
Expect(cl.Get(ctx, client.ObjectKey{
Name: framework.CAPIInstallerImagesConfigMapName,
Namespace: framework.CAPIOperatorNamespace,
}, cm)).To(Succeed())
Expect(cm.Data).NotTo(BeEmpty())
})
})

Context("CRD & API readiness", func() {
It("should have core Cluster API CRDs installed and established", func() {
for _, name := range []string{
"clusters.cluster.x-k8s.io",
"machines.cluster.x-k8s.io",
"machinesets.cluster.x-k8s.io",
} {
crd := &apiextensionsv1.CustomResourceDefinition{}

By("Fetching CRD " + name)
Expect(cl.Get(ctx, client.ObjectKey{Name: name}, crd)).To(Succeed())

By("Verifying CRD " + name + " is established")
Expect(crd.Status.Conditions).To(ContainElement(SatisfyAll(
HaveField("Type", Equal(apiextensionsv1.Established)),
HaveField("Status", Equal(apiextensionsv1.ConditionTrue)),
)))
}
})

It("should have platform-specific infrastructure CRDs installed", func() {
cluster := &clusterv1.Cluster{}
Expect(cl.Get(ctx, client.ObjectKey{Name: clusterName, Namespace: framework.CAPINamespace}, cluster)).To(Succeed())

mapping, err := cl.RESTMapper().RESTMapping(cluster.Spec.InfrastructureRef.GroupKind())
Expect(err).NotTo(HaveOccurred())

crdName := mapping.Resource.Resource + "." + mapping.Resource.Group
crd := &apiextensionsv1.CustomResourceDefinition{}

By("Fetching the infrastructure CRD " + crdName)
Expect(cl.Get(ctx, client.ObjectKey{Name: crdName}, crd)).To(Succeed())

By("Verifying the infrastructure CRD is established")
Expect(crd.Status.Conditions).To(ContainElement(SatisfyAll(
HaveField("Type", Equal(apiextensionsv1.Established)),
HaveField("Status", Equal(apiextensionsv1.ConditionTrue)),
)))
})
})

Context("Management cluster resources", func() {
It("should have the management Cluster object present and infrastructure ready", func() {
cluster := &clusterv1.Cluster{}
Eventually(func(g Gomega) {
g.Expect(cl.Get(ctx, client.ObjectKey{
Name: clusterName,
Namespace: framework.CAPINamespace,
}, cluster)).To(Succeed())

By("Checking InfrastructureReady=True")
g.Expect(cluster.Status.Conditions).To(ContainElement(SatisfyAll(
HaveField("Type", Equal(string(clusterv1.ClusterInfrastructureReadyCondition))),
HaveField("Status", Equal(metav1.ConditionStatus("True"))),
)))
}).WithTimeout(framework.WaitLong).WithPolling(framework.RetryMedium).Should(Succeed())
})

It("should have the platform-specific infrastructure cluster object present", func() {
cluster := &clusterv1.Cluster{}
Expect(cl.Get(ctx, client.ObjectKey{Name: clusterName, Namespace: framework.CAPINamespace}, cluster)).To(Succeed())

Eventually(func(g Gomega) {
mapping, err := cl.RESTMapper().RESTMapping(cluster.Spec.InfrastructureRef.GroupKind())
g.Expect(err).NotTo(HaveOccurred())

infraCluster := &unstructured.Unstructured{}
infraCluster.SetGroupVersionKind(mapping.GroupVersionKind)
g.Expect(cl.Get(ctx, client.ObjectKey{
Name: cluster.Spec.InfrastructureRef.Name,
Namespace: framework.CAPINamespace,
}, infraCluster)).To(Succeed())
}).WithTimeout(framework.WaitMedium).WithPolling(framework.RetryMedium).Should(Succeed())
})

It("should have the management cluster kubeconfig Secret present", func() {
secret := &corev1.Secret{}
Expect(cl.Get(ctx, client.ObjectKey{
Name: fmt.Sprintf("%s-kubeconfig", clusterName),
Namespace: framework.CAPINamespace,
}, secret)).To(Succeed())
Expect(secret.Data).To(HaveKey("value"))
})
})
})
3 changes: 3 additions & 0 deletions e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const (
CompatibilityRequirementsNamespace = "openshift-compatibility-requirements-operator"
MAPINamespace = "openshift-machine-api"

CAPIClusterOperatorName = "cluster-api"
CAPIInstallerImagesConfigMapName = "capi-installer-images"

RetryShort = 1 * time.Second
RetryMedium = 5 * time.Second
RetryLong = 10 * time.Second
Expand Down