From d81fb17a72e75bfea35521f10c2466b6a03247c1 Mon Sep 17 00:00:00 2001 From: Ronny Baturov Date: Tue, 1 Oct 2024 11:50:33 +0300 Subject: [PATCH] RTE metrics enablement * Integrating RTE metrics manifests to be deployed by the operator * This adds unit test for metrics components creation Signed-off-by: Ronny Baturov --- .../numaresourcesoperator_controller.go | 25 ++++++++++++++++ .../numaresourcesoperator_controller_test.go | 30 ++++++++++++++----- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/controllers/numaresourcesoperator_controller.go b/controllers/numaresourcesoperator_controller.go index aaf844212..e76f5ff88 100644 --- a/controllers/numaresourcesoperator_controller.go +++ b/controllers/numaresourcesoperator_controller.go @@ -581,6 +581,31 @@ func (r *NUMAResourcesOperatorReconciler) syncNUMAResourcesOperatorResources(ctx return nil, fmt.Errorf("failed to apply (%s) %s/%s: %w", objState.Desired.GetObjectKind().GroupVersionKind(), objState.Desired.GetNamespace(), objState.Desired.GetName(), err) } } + + 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, fmt.Errorf("failed to get %s/%s: %w", obj.GetNamespace(), obj.GetName(), err) + } + if apierrors.IsNotFound(err) { + err := controllerutil.SetControllerReference(instance, obj, r.Scheme) + if err != nil { + return nil, fmt.Errorf("failed to set controller reference to %s %s: %w", obj.GetNamespace(), obj.GetName(), err) + } + err = r.Client.Create(ctx, obj) + if err != nil { + return nil, fmt.Errorf("failed to create %s/%s: %w", obj.GetNamespace(), obj.GetName(), err) + } + } else { + err = r.Client.Update(ctx, obj) + if err != nil { + return nil, fmt.Errorf("failed to update %s/%s: %w", obj.GetNamespace(), obj.GetName(), err) + } + } + } + if len(dsPoolPairs) < len(trees) { klog.Warningf("daemonset and tree size mismatch: expected %d got in daemonsets %d", len(trees), len(dsPoolPairs)) } diff --git a/controllers/numaresourcesoperator_controller_test.go b/controllers/numaresourcesoperator_controller_test.go index ed26ac8eb..0559e014c 100644 --- a/controllers/numaresourcesoperator_controller_test.go +++ b/controllers/numaresourcesoperator_controller_test.go @@ -23,6 +23,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + rtemetricsmanifests "github.com/openshift-kni/numaresources-operator/pkg/metrics/manifests/monitor" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -70,16 +71,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, }, @@ -1475,6 +1480,17 @@ 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 *corev1.Service: + service := &corev1.Service{} + Expect(reconciler.Client.Get(context.TODO(), objectKey, service)).ToNot(HaveOccurred()) + default: + } + } }) When("daemonsets are ready", func() { var dsDesiredNumberScheduled int32