diff --git a/controllers/numaresourcesoperator_controller.go b/controllers/numaresourcesoperator_controller.go index 7e93b6f21..6370a95ba 100644 --- a/controllers/numaresourcesoperator_controller.go +++ b/controllers/numaresourcesoperator_controller.go @@ -489,6 +489,26 @@ func (r *NUMAResourcesOperatorReconciler) syncNUMAResourcesOperatorResources(ctx daemonSetsNName = append(daemonSetsNName, nname) } } + + for _, obj := range r.RTEMetricsManifests.ToObjects() { + // Check if the object already exists + existingObj := obj.DeepCopyObject().(client.Object) + err := r.Client.Get(ctx, client.ObjectKeyFromObject(obj), existingObj) + if err != nil && !apierrors.IsNotFound(err) { + return nil, errors.Wrapf(err, "failed to get %s/%s", obj.GetNamespace(), obj.GetName()) + } + if apierrors.IsNotFound(err) { + err := controllerutil.SetControllerReference(instance, obj, r.Scheme) + if err != nil { + return nil, errors.Wrapf(err, "failed to set controller reference to %s %s", obj.GetNamespace(), obj.GetName()) + } + err = r.Client.Create(ctx, obj) + if err != nil { + return nil, errors.Wrapf(err, "failed to create %s/%s", obj.GetNamespace(), obj.GetName()) + } + } + } + return daemonSetsNName, nil } diff --git a/controllers/numaresourcesoperator_controller_test.go b/controllers/numaresourcesoperator_controller_test.go index c07ac6534..792c6bdd7 100644 --- a/controllers/numaresourcesoperator_controller_test.go +++ b/controllers/numaresourcesoperator_controller_test.go @@ -33,6 +33,7 @@ import ( rtemanifests "github.com/k8stopologyawareschedwg/deployer/pkg/manifests/rte" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + rtemetricsmanifests "github.com/openshift-kni/numaresources-operator/pkg/metrics/manifests/monitor" machineconfigv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" corev1 "k8s.io/api/core/v1" @@ -71,16 +72,20 @@ func NewFakeNUMAResourcesOperatorReconciler(plat platform.Platform, platVersion if err != nil { return nil, err } - + rtemetricsmanifests, err := rtemetricsmanifests.GetManifests(testNamespace) + if err != nil { + return nil, err + } recorder := record.NewFakeRecorder(bufferSize) return &NUMAResourcesOperatorReconciler{ - Client: fakeClient, - Scheme: scheme.Scheme, - Platform: plat, - APIManifests: apiManifests, - RTEManifests: rteManifests, - Namespace: testNamespace, + Client: fakeClient, + Scheme: scheme.Scheme, + Platform: plat, + APIManifests: apiManifests, + RTEManifests: rteManifests, + RTEMetricsManifests: rtemetricsmanifests, + Namespace: testNamespace, Images: images.Data{ Builtin: testImageSpec, }, @@ -471,6 +476,20 @@ var _ = Describe("Test NUMAResourcesOperator Reconcile", func() { Namespace: testNamespace, } Expect(reconciler.Client.Get(context.TODO(), mcp2DSKey, ds)).ToNot(HaveOccurred()) + + By("Check All RTE metrics components are created") + for _, obj := range reconciler.RTEMetricsManifests.ToObjects() { + objectKey := client.ObjectKeyFromObject(obj) + switch obj.(type) { + case *rbacv1.ClusterRoleBinding: + clusterRoleBinding := &rbacv1.ClusterRoleBinding{} + Expect(reconciler.Client.Get(context.TODO(), objectKey, clusterRoleBinding)).ToNot(HaveOccurred()) + case *corev1.Service: + service := &corev1.Service{} + Expect(reconciler.Client.Get(context.TODO(), objectKey, service)).ToNot(HaveOccurred()) + default: + } + } }) When(" daemonsets are ready", func() { var dsDesiredNumberScheduled int32