diff --git a/go.mod b/go.mod index 03888a82b..e18868932 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/onsi/ginkgo/v2 v2.26.0 github.com/onsi/gomega v1.38.2 github.com/openshift/api v3.9.0+incompatible + github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87 github.com/openstack-k8s-operators/barbican-operator/api v0.6.1-0.20251004061941-fc4a6b62f14f github.com/openstack-k8s-operators/cinder-operator/api v0.6.1-0.20251002160033-d2a363bddc32 github.com/openstack-k8s-operators/designate-operator/api v0.6.1-0.20251002063410-b6cf1b1e0e23 diff --git a/go.sum b/go.sum index 6a70b2e22..2fc6faec9 100644 --- a/go.sum +++ b/go.sum @@ -118,6 +118,8 @@ github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A= github.com/onsi/gomega v1.38.2/go.mod h1:W2MJcYxRGV63b418Ai34Ud0hEdTVXq9NW9+Sx6uXf3k= github.com/openshift/api v0.0.0-20250711200046-c86d80652a9e h1:E1OdwSpqWuDPCedyUt0GEdoAE+r5TXy7YS21yNEo+2U= github.com/openshift/api v0.0.0-20250711200046-c86d80652a9e/go.mod h1:Shkl4HanLwDiiBzakv+con/aMGnVE2MAGvoKp5oyYUo= +github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87 h1:JtLhaGpSEconE+1IKmIgCOof/Len5ceG6H1pk43yv5U= +github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87/go.mod h1:3IPD4U0qyovZS4EFady2kqY32m8lGcbs/Wx+yprg9z8= github.com/openstack-k8s-operators/barbican-operator/api v0.6.1-0.20251004061941-fc4a6b62f14f h1:x+5NGi9zVckLt4bWi1mv7sABcHjInev3BgTOhBMcOCg= github.com/openstack-k8s-operators/barbican-operator/api v0.6.1-0.20251004061941-fc4a6b62f14f/go.mod h1:8ANa5p+Iv4lhYVTOVzRYF7usutis46e3v70ljCAmKQI= github.com/openstack-k8s-operators/cinder-operator/api v0.6.1-0.20251002160033-d2a363bddc32 h1:COOGq+Dq2SXj5LD8W00iyE2lmn3bFt2b+wjJyTmS94I= diff --git a/pkg/dataplane/inventory.go b/pkg/dataplane/inventory.go index fd2f14442..bc9bb1416 100644 --- a/pkg/dataplane/inventory.go +++ b/pkg/dataplane/inventory.go @@ -136,6 +136,13 @@ func GenerateNodeSetInventory(ctx context.Context, helper *helper.Helper, // add the NodeSet name variable nodeSetGroup.Vars["edpm_nodeset_name"] = instance.Name + // add ID of the RHOSO cluster to the ansible variables + nodeSetGroup.Vars["edpm_rhoso_cluster_id"], err = util.GetRhosoClusterID(ctx, instance.Namespace) + if err != nil { + utils.LogErrorForObject(helper, err, "could not get OpenShift Cluster ID", instance) + return "", err + } + isDisconnected, err := util.IsDisconnectedOCP(ctx, helper) if err != nil { return "", err diff --git a/pkg/dataplane/util/cluster.go b/pkg/dataplane/util/cluster.go new file mode 100644 index 000000000..8e48b7415 --- /dev/null +++ b/pkg/dataplane/util/cluster.go @@ -0,0 +1,40 @@ +/* +Copyright 2025. + +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 util //nolint:revive // util is an acceptable package name in this context + +import ( + "context" + "fmt" + + configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + ctrl "sigs.k8s.io/controller-runtime" +) + +// GetRhosoClusterID - retrieves the RHOSO cluster ID +func GetRhosoClusterID(ctx context.Context, namespace string) (string, error) { + configClient, err := configv1client.NewForConfig(ctrl.GetConfigOrDie()) + if err != nil { + return "", err + } + clusterVersion, err := configClient.ClusterVersions().Get(ctx, "version", metav1.GetOptions{}) + if err != nil { + return "", err + } + return fmt.Sprintf("%s:%s", clusterVersion.Spec.ClusterID, namespace), nil +} diff --git a/tests/functional/dataplane/openstackdataplanenodeset_controller_test.go b/tests/functional/dataplane/openstackdataplanenodeset_controller_test.go index 22ca5b8a6..d1024e897 100644 --- a/tests/functional/dataplane/openstackdataplanenodeset_controller_test.go +++ b/tests/functional/dataplane/openstackdataplanenodeset_controller_test.go @@ -285,6 +285,24 @@ var _ = Describe("Dataplane NodeSet Test", func() { }) }) + When("A Dataplane nodeset is created", func() { + BeforeEach(func() { + DeferCleanup(th.DeleteInstance, CreateNetConfig(dataplaneNetConfigName, DefaultNetConfigSpec())) + DeferCleanup(th.DeleteInstance, CreateDNSMasq(dnsMasqName, DefaultDNSMasqSpec())) + DeferCleanup(th.DeleteInstance, CreateDataplaneNodeSet(dataplaneNodeSetName, DefaultDataPlaneNoNodeSetSpec(false))) + CreateSSHSecret(dataplaneSSHSecretName) + CreateCABundleSecret(caBundleSecretName) + SimulateDNSMasqComplete(dnsMasqName) + SimulateIPSetComplete(dataplaneNodeName) + SimulateDNSDataComplete(dataplaneNodeSetName) + }) + It("should have the RHOSO cluster ID set in the Ansible inventory", func() { + secret := th.GetSecret(dataplaneSecretName) + Expect(secret.Data["inventory"]).Should( + ContainSubstring("edpm_rhoso_cluster_id")) + }) + }) + When("TLS is enabled", func() { tlsEnabled := true When("A Dataplane resource is created with PreProvisioned nodes, no deployment", func() {