From 5a31481926de75dc89cb3634adc2c546c4cf8cff Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Mon, 29 Jan 2024 16:27:15 +0100 Subject: [PATCH 01/26] Fixed HPA deletion Signed-off-by: Yuri Sa --- .chloggen/fix-hpa-delete.yaml | 16 ++++++++++++++++ .../collector/horizontalpodautoscaler.go | 5 ++--- .../collector/horizontalpodautoscaler_test.go | 5 +---- tests/e2e-autoscale/autoscale/04-delete.yaml | 11 +++++++++++ tests/e2e-autoscale/autoscale/04-error.yaml | 10 ++++++++++ 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100755 .chloggen/fix-hpa-delete.yaml create mode 100644 tests/e2e-autoscale/autoscale/04-delete.yaml create mode 100644 tests/e2e-autoscale/autoscale/04-error.yaml diff --git a/.chloggen/fix-hpa-delete.yaml b/.chloggen/fix-hpa-delete.yaml new file mode 100755 index 0000000000..d8629577e2 --- /dev/null +++ b/.chloggen/fix-hpa-delete.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'bug_fix' + +# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action) +component: operator + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fixed HPA deletion + +# One or more tracking issues related to the change +issues: [2568] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/internal/manifests/collector/horizontalpodautoscaler.go b/internal/manifests/collector/horizontalpodautoscaler.go index 0a4bdefccd..adf5b64cb2 100644 --- a/internal/manifests/collector/horizontalpodautoscaler.go +++ b/internal/manifests/collector/horizontalpodautoscaler.go @@ -18,7 +18,6 @@ import ( autoscalingv2 "k8s.io/api/autoscaling/v2" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/controller-runtime/pkg/client" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" @@ -26,11 +25,11 @@ import ( "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) -func HorizontalPodAutoscaler(params manifests.Params) client.Object { +func HorizontalPodAutoscaler(params manifests.Params) *autoscalingv2.HorizontalPodAutoscaler { name := naming.Collector(params.OtelCol.Name) labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter()) annotations := Annotations(params.OtelCol) - var result client.Object + var result *autoscalingv2.HorizontalPodAutoscaler objectMeta := metav1.ObjectMeta{ Name: naming.HorizontalPodAutoscaler(params.OtelCol.Name), diff --git a/internal/manifests/collector/horizontalpodautoscaler_test.go b/internal/manifests/collector/horizontalpodautoscaler_test.go index 8e92360687..2c90309337 100644 --- a/internal/manifests/collector/horizontalpodautoscaler_test.go +++ b/internal/manifests/collector/horizontalpodautoscaler_test.go @@ -18,7 +18,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - autoscalingv2 "k8s.io/api/autoscaling/v2" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -78,9 +77,7 @@ func TestHPA(t *testing.T) { OtelCol: otelcol, Log: logger, } - raw := HorizontalPodAutoscaler(params) - - hpa := raw.(*autoscalingv2.HorizontalPodAutoscaler) + hpa := HorizontalPodAutoscaler(params) // verify assert.Equal(t, "my-instance-collector", hpa.Name) diff --git a/tests/e2e-autoscale/autoscale/04-delete.yaml b/tests/e2e-autoscale/autoscale/04-delete.yaml new file mode 100644 index 0000000000..319b3a0578 --- /dev/null +++ b/tests/e2e-autoscale/autoscale/04-delete.yaml @@ -0,0 +1,11 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +delete: + - apiVersion: opentelemetry.io/v1alpha1 + kind: OpenTelemetryCollector + metadata: + name: simplest + - apiVersion: opentelemetry.io/v1alpha1 + kind: OpenTelemetryCollector + metadata: + name: simplest-set-utilization diff --git a/tests/e2e-autoscale/autoscale/04-error.yaml b/tests/e2e-autoscale/autoscale/04-error.yaml new file mode 100644 index 0000000000..38d382bb72 --- /dev/null +++ b/tests/e2e-autoscale/autoscale/04-error.yaml @@ -0,0 +1,10 @@ +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: simplest-collector +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: simplest-set-utilization-collector From bd9bd933a8f05f00fe79869e9909c5e1f8232ca8 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Mon, 29 Jan 2024 17:19:14 +0100 Subject: [PATCH 02/26] Fix e2e tests Signed-off-by: Yuri Sa --- tests/e2e-autoscale/autoscale/04-error.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/e2e-autoscale/autoscale/04-error.yaml b/tests/e2e-autoscale/autoscale/04-error.yaml index 38d382bb72..04900e76a9 100644 --- a/tests/e2e-autoscale/autoscale/04-error.yaml +++ b/tests/e2e-autoscale/autoscale/04-error.yaml @@ -3,8 +3,26 @@ apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: simplest-collector +spec: + maxReplicas: 2 + scaleTargetRef: + apiVersion: opentelemetry.io/v1alpha1 + kind: OpenTelemetryCollector + name: simplest +status: + currentMetrics: null + currentReplicas: 1 --- apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: simplest-set-utilization-collector +spec: + maxReplicas: 2 + scaleTargetRef: + apiVersion: opentelemetry.io/v1alpha1 + kind: OpenTelemetryCollector + name: simplest-set-utilization +status: + currentMetrics: null + currentReplicas: 1 From 10f82b0cf62ebc42af80851625105b88bcdfeb63 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Mon, 12 Feb 2024 12:13:47 +0100 Subject: [PATCH 03/26] Added reconciliation test Signed-off-by: Yuri Sa --- controllers/reconcile_test.go | 40 +++++++++++++++++++ controllers/suite_test.go | 6 +++ tests/e2e-autoscale/autoscale/00-install.yaml | 30 +++++++------- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/controllers/reconcile_test.go b/controllers/reconcile_test.go index 803425f448..f23958d545 100644 --- a/controllers/reconcile_test.go +++ b/controllers/reconcile_test.go @@ -104,6 +104,7 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { deletedParams := paramsWithMode(v1alpha1.ModeDeployment) now := metav1.NewTime(time.Now()) deletedParams.OtelCol.DeletionTimestamp = &now + deploymentWithoutHPA := paramsWithModeAndReplicas(v1alpha1.ModeDeployment, 1) type args struct { params manifests.Params @@ -329,6 +330,45 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { }, }, }, + { + name: "hpa v2 deployment collector deletion process", + args: args{ + params: paramsWithHPA(3, 5), + updates: []manifests.Params{deploymentWithoutHPA}, + }, + want: []want{ + { + result: controllerruntime.Result{}, + checks: []check{ + func(t *testing.T, params manifests.Params) { + actual := autoscalingv2.HorizontalPodAutoscaler{} + exists, hpaErr := populateObjectIfExists(t, &actual, namespacedObjectName(naming.HorizontalPodAutoscaler(params.OtelCol.Name), params.OtelCol.Namespace)) + assert.NoError(t, hpaErr) + require.Len(t, actual.Spec.Metrics, 1) + assert.Equal(t, int32(90), *actual.Spec.Metrics[0].Resource.Target.AverageUtilization) + assert.Equal(t, int32(3), *actual.Spec.MinReplicas) + assert.Equal(t, int32(5), actual.Spec.MaxReplicas) + assert.True(t, exists) + }, + }, + wantErr: assert.NoError, + validateErr: assert.NoError, + }, + { + result: controllerruntime.Result{}, + checks: []check{ + func(t *testing.T, params manifests.Params) { + hpa := autoscalingv2.HorizontalPodAutoscaler{} + exists, err := populateObjectIfExists(t, &hpa, namespacedObjectName(naming.HorizontalPodAutoscaler(params.OtelCol.Name), params.OtelCol.Namespace)) + assert.NoError(t, err) + assert.False(t, exists) // There should be no hpa anymore + }, + }, + wantErr: assert.NoError, + validateErr: assert.NoError, + }, + }, + }, { name: "policy v1 deployment collector", args: args{ diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 86e5cc02e5..36910a64eb 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -26,6 +26,7 @@ import ( "time" routev1 "github.com/openshift/api/route/v1" + autoscalingv2 "k8s.io/api/autoscaling/v2" v1 "k8s.io/api/core/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -119,6 +120,11 @@ func TestMain(m *testing.M) { os.Exit(1) } + if err = autoscalingv2.AddToScheme(testScheme); err != nil { + fmt.Printf("failed to register scheme: %v", err) + os.Exit(1) + } + if err = v1alpha1.AddToScheme(testScheme); err != nil { fmt.Printf("failed to register scheme: %v", err) os.Exit(1) diff --git a/tests/e2e-autoscale/autoscale/00-install.yaml b/tests/e2e-autoscale/autoscale/00-install.yaml index 8f5f5fa92d..3662005784 100644 --- a/tests/e2e-autoscale/autoscale/00-install.yaml +++ b/tests/e2e-autoscale/autoscale/00-install.yaml @@ -12,14 +12,14 @@ spec: # TODO: these tests use .Spec.MaxReplicas and .Spec.MinReplicas. These fields are # deprecated and moved to .Spec.Autoscaler. Fine to use these fields to test that old CRD is # still supported but should eventually be updated. - minReplicas: 1 - maxReplicas: 2 - autoscaler: - behavior: - scaleUp: - stabilizationWindowSeconds: 10 - scaleDown: - stabilizationWindowSeconds: 15 + # minReplicas: 1 + # maxReplicas: 2 + # autoscaler: + # behavior: + # scaleUp: + # stabilizationWindowSeconds: 10 + # scaleDown: + # stabilizationWindowSeconds: 15 resources: limits: cpu: 500m @@ -51,13 +51,13 @@ kind: OpenTelemetryCollector metadata: name: simplest-set-utilization spec: - minReplicas: 1 - maxReplicas: 2 - autoscaler: - targetCPUUtilization: 99 - behavior: - scaleUp: - stabilizationWindowSeconds: 300 + # minReplicas: 1 + # maxReplicas: 2 + # autoscaler: + # targetCPUUtilization: 99 + # behavior: + # scaleUp: + # stabilizationWindowSeconds: 300 resources: limits: cpu: 250m From 2ac2af769c958e24f34b3f4cfb456d2346263e21 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Mon, 12 Feb 2024 21:06:11 +0100 Subject: [PATCH 04/26] Added owned objects function Signed-off-by: Yuri Sa --- controllers/builder_test.go | 12 +++ controllers/common.go | 93 ++++++++++++++++++- controllers/opampbridge_controller.go | 2 +- .../opentelemetrycollector_controller.go | 15 ++- tests/e2e-autoscale/autoscale/00-install.yaml | 30 +++--- 5 files changed, 134 insertions(+), 18 deletions(-) diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 054981cd6e..326a7fd32b 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -22,6 +22,7 @@ import ( monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" + autoscalingv2 "k8s.io/api/autoscaling/v2" corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -85,6 +86,8 @@ service: exporters: [logging] ` one := int32(1) + maxReplicas := int32(2) + stabilizationWindowSeconds := int32(300) type args struct { instance v1alpha1.OpenTelemetryCollector } @@ -103,6 +106,15 @@ service: Namespace: "test", }, Spec: v1alpha1.OpenTelemetryCollectorSpec{ + MinReplicas: &one, + MaxReplicas: &maxReplicas, + Autoscaler: &v1alpha1.AutoscalerSpec{ + Behavior: &autoscalingv2.HorizontalPodAutoscalerBehavior{ + ScaleUp: &autoscalingv2.HPAScalingRules{ + StabilizationWindowSeconds: &stabilizationWindowSeconds, + }, + }, + }, Replicas: &one, Mode: "deployment", Image: "test", diff --git a/controllers/common.go b/controllers/common.go index 2a7ff1d751..2aa09b2d2e 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -20,18 +20,28 @@ import ( "fmt" "github.com/go-logr/logr" + "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift" + routev1 "github.com/openshift/api/route/v1" + monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + autoscalingv2 "k8s.io/api/autoscaling/v2" + networkingv1 "k8s.io/api/networking/v1" rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/util/retry" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "github.com/open-telemetry/opentelemetry-operator/internal/api/convert" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/opampbridge" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator" + "github.com/open-telemetry/opentelemetry-operator/pkg/featuregate" ) func isNamespaceScoped(obj client.Object) bool { @@ -76,9 +86,71 @@ func BuildOpAMPBridge(params manifests.Params) ([]client.Object, error) { return resources, nil } +func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Context, params manifests.Params) (map[types.UID]client.Object, error) { + ownedObjects := map[types.UID]client.Object{} + otelCol, err := convert.V1Alpha1to2(params.OtelCol) + if err != nil { + return nil, err + } + listOps := &client.ListOptions{ + Namespace: otelCol.Namespace, + LabelSelector: labels.SelectorFromSet(manifestutils.Labels(otelCol.ObjectMeta, otelCol.Name, otelCol.Spec.Image, collector.ComponentOpenTelemetryCollector, []string{})), + } + + hpaList := &autoscalingv2.HorizontalPodAutoscalerList{} + err = r.List(ctx, hpaList, listOps) + if err != nil { + return nil, fmt.Errorf("Error listing HorizontalPodAutoscalers: %w", err) + } + for i := range hpaList.Items { + ownedObjects[hpaList.Items[i].GetUID()] = &hpaList.Items[i] + } + + if otelCol.Spec.Observability.Metrics.EnableMetrics && featuregate.PrometheusOperatorIsAvailable.IsEnabled() { + servicemonitorList := &monitoringv1.ServiceMonitorList{} + err := r.List(ctx, servicemonitorList, listOps) + if err != nil { + return nil, fmt.Errorf("Error listing ServiceMonitors: %w", err) + } + for i := range servicemonitorList.Items { + ownedObjects[servicemonitorList.Items[i].GetUID()] = servicemonitorList.Items[i] + } + + podMonitorList := &monitoringv1.ServiceMonitorList{} + err = r.List(ctx, podMonitorList, listOps) + if err != nil { + return nil, fmt.Errorf("Error listing PodMonitors: %w", err) + } + for i := range podMonitorList.Items { + ownedObjects[podMonitorList.Items[i].GetUID()] = podMonitorList.Items[i] + } + } + ingressList := &networkingv1.IngressList{} + err = r.List(ctx, ingressList, listOps) + if err != nil { + return nil, fmt.Errorf("Error listing Ingresses: %w", err) + } + for i := range ingressList.Items { + ownedObjects[ingressList.Items[i].GetUID()] = &ingressList.Items[i] + } + + if params.Config.OpenShiftRoutesAvailability() == openshift.RoutesAvailable { + routesList := &routev1.RouteList{} + err := r.List(ctx, routesList, listOps) + if err != nil { + return nil, fmt.Errorf("Error listing Routes: %w", err) + } + for i := range routesList.Items { + ownedObjects[routesList.Items[i].GetUID()] = &routesList.Items[i] + } + } + return ownedObjects, nil +} + // reconcileDesiredObjects runs the reconcile process using the mutateFn over the given list of objects. -func reconcileDesiredObjects(ctx context.Context, kubeClient client.Client, logger logr.Logger, owner metav1.Object, scheme *runtime.Scheme, desiredObjects ...client.Object) error { +func reconcileDesiredObjects(ctx context.Context, kubeClient client.Client, logger logr.Logger, owner metav1.Object, scheme *runtime.Scheme, desiredObjects []client.Object, ownedObjects map[types.UID]client.Object) error { var errs []error + pruneObjects := ownedObjects for _, desired := range desiredObjects { l := logger.WithValues( "object_name", desired.GetName(), @@ -120,5 +192,24 @@ func reconcileDesiredObjects(ctx context.Context, kubeClient client.Client, logg if len(errs) > 0 { return fmt.Errorf("failed to create objects for %s: %w", owner.GetName(), errors.Join(errs...)) } + // Pruning owned objects in the cluster which are not should not be present after the reconciliation. + pruneErrs := []error{} + fmt.Printf("Part of prune - %d - ", len(pruneObjects)) + for _, obj := range pruneObjects { + l := logger.WithValues( + "object_name", obj.GetName(), + "object_kind", obj.GetObjectKind().GroupVersionKind(), + ) + + l.Info("pruning unmanaged resource") + err := kubeClient.Delete(ctx, obj) + if err != nil { + l.Error(err, "failed to delete resource") + pruneErrs = append(pruneErrs, err) + } + } + if len(pruneErrs) > 0 { + return fmt.Errorf("failed to prune objects for %s: %w", owner.GetName(), errors.Join(pruneErrs...)) + } return nil } diff --git a/controllers/opampbridge_controller.go b/controllers/opampbridge_controller.go index 670418ad5c..50e6ffa130 100644 --- a/controllers/opampbridge_controller.go +++ b/controllers/opampbridge_controller.go @@ -103,7 +103,7 @@ func (r *OpAMPBridgeReconciler) Reconcile(ctx context.Context, req ctrl.Request) if buildErr != nil { return ctrl.Result{}, buildErr } - err := reconcileDesiredObjects(ctx, r.Client, log, ¶ms.OpAMPBridge, params.Scheme, desiredObjects...) + err := reconcileDesiredObjects(ctx, r.Client, log, ¶ms.OpAMPBridge, params.Scheme, desiredObjects, nil) return opampbridgeStatus.HandleReconcileStatus(ctx, log, params, err) } diff --git a/controllers/opentelemetrycollector_controller.go b/controllers/opentelemetrycollector_controller.go index f5fc4ceb2f..b0cda52a4e 100644 --- a/controllers/opentelemetrycollector_controller.go +++ b/controllers/opentelemetrycollector_controller.go @@ -19,10 +19,12 @@ import ( "context" "github.com/go-logr/logr" + routev1 "github.com/openshift/api/route/v1" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" appsv1 "k8s.io/api/apps/v1" autoscalingv2 "k8s.io/api/autoscaling/v2" corev1 "k8s.io/api/core/v1" + networkingv1 "k8s.io/api/networking/v1" policyV1 "k8s.io/api/policy/v1" rbacv1 "k8s.io/api/rbac/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -32,6 +34,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" + "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" collectorStatus "github.com/open-telemetry/opentelemetry-operator/internal/status/collector" @@ -125,7 +128,13 @@ func (r *OpenTelemetryCollectorReconciler) Reconcile(ctx context.Context, req ct if buildErr != nil { return ctrl.Result{}, buildErr } - err := reconcileDesiredObjects(ctx, r.Client, log, ¶ms.OtelCol, params.Scheme, desiredObjects...) + + ownedObjects, err := r.findOtelOwnedObjects(ctx, params) + if err != nil { + return ctrl.Result{}, err + } + + err = reconcileDesiredObjects(ctx, r.Client, log, ¶ms.OtelCol, params.Scheme, desiredObjects, ownedObjects) return collectorStatus.HandleReconcileStatus(ctx, log, params, err) } @@ -139,6 +148,7 @@ func (r *OpenTelemetryCollectorReconciler) SetupWithManager(mgr ctrl.Manager) er Owns(&appsv1.Deployment{}). Owns(&appsv1.DaemonSet{}). Owns(&appsv1.StatefulSet{}). + Owns(&networkingv1.Ingress{}). Owns(&autoscalingv2.HorizontalPodAutoscaler{}). Owns(&policyV1.PodDisruptionBudget{}) @@ -151,6 +161,9 @@ func (r *OpenTelemetryCollectorReconciler) SetupWithManager(mgr ctrl.Manager) er builder.Owns(&monitoringv1.ServiceMonitor{}) builder.Owns(&monitoringv1.PodMonitor{}) } + if r.config.OpenShiftRoutesAvailability() == openshift.RoutesAvailable { + builder.Owns(&routev1.Route{}) + } return builder.Complete(r) } diff --git a/tests/e2e-autoscale/autoscale/00-install.yaml b/tests/e2e-autoscale/autoscale/00-install.yaml index 3662005784..8f5f5fa92d 100644 --- a/tests/e2e-autoscale/autoscale/00-install.yaml +++ b/tests/e2e-autoscale/autoscale/00-install.yaml @@ -12,14 +12,14 @@ spec: # TODO: these tests use .Spec.MaxReplicas and .Spec.MinReplicas. These fields are # deprecated and moved to .Spec.Autoscaler. Fine to use these fields to test that old CRD is # still supported but should eventually be updated. - # minReplicas: 1 - # maxReplicas: 2 - # autoscaler: - # behavior: - # scaleUp: - # stabilizationWindowSeconds: 10 - # scaleDown: - # stabilizationWindowSeconds: 15 + minReplicas: 1 + maxReplicas: 2 + autoscaler: + behavior: + scaleUp: + stabilizationWindowSeconds: 10 + scaleDown: + stabilizationWindowSeconds: 15 resources: limits: cpu: 500m @@ -51,13 +51,13 @@ kind: OpenTelemetryCollector metadata: name: simplest-set-utilization spec: - # minReplicas: 1 - # maxReplicas: 2 - # autoscaler: - # targetCPUUtilization: 99 - # behavior: - # scaleUp: - # stabilizationWindowSeconds: 300 + minReplicas: 1 + maxReplicas: 2 + autoscaler: + targetCPUUtilization: 99 + behavior: + scaleUp: + stabilizationWindowSeconds: 300 resources: limits: cpu: 250m From a61de02667831c2eac3a86987b2f81e47838ed09 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 13 Feb 2024 16:32:53 +0100 Subject: [PATCH 05/26] Fixed controller test Signed-off-by: Yuri Sa --- controllers/common.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/controllers/common.go b/controllers/common.go index 2aa09b2d2e..03e242e504 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -21,6 +21,7 @@ import ( "github.com/go-logr/logr" "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift" + "github.com/open-telemetry/opentelemetry-operator/internal/naming" routev1 "github.com/openshift/api/route/v1" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" autoscalingv2 "k8s.io/api/autoscaling/v2" @@ -92,11 +93,11 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont if err != nil { return nil, err } + listOps := &client.ListOptions{ Namespace: otelCol.Namespace, - LabelSelector: labels.SelectorFromSet(manifestutils.Labels(otelCol.ObjectMeta, otelCol.Name, otelCol.Spec.Image, collector.ComponentOpenTelemetryCollector, []string{})), + LabelSelector: labels.SelectorFromSet(manifestutils.Labels(otelCol.ObjectMeta, naming.Collector(otelCol.Name), otelCol.Spec.Image, collector.ComponentOpenTelemetryCollector, params.Config.LabelsFilter())), } - hpaList := &autoscalingv2.HorizontalPodAutoscalerList{} err = r.List(ctx, hpaList, listOps) if err != nil { @@ -163,7 +164,6 @@ func reconcileDesiredObjects(ctx context.Context, kubeClient client.Client, logg continue } } - // existing is an object the controller runtime will hydrate for us // we obtain the existing object by deep copying the desired object because it's the most convenient way existing := desired.DeepCopyObject().(client.Object) @@ -188,13 +188,14 @@ func reconcileDesiredObjects(ctx context.Context, kubeClient client.Client, logg } l.V(1).Info(fmt.Sprintf("desired has been %s", op)) + // This object is still managed by the operator, remove it from the list of objects to prune + delete(pruneObjects, existing.GetUID()) } if len(errs) > 0 { return fmt.Errorf("failed to create objects for %s: %w", owner.GetName(), errors.Join(errs...)) } // Pruning owned objects in the cluster which are not should not be present after the reconciliation. pruneErrs := []error{} - fmt.Printf("Part of prune - %d - ", len(pruneObjects)) for _, obj := range pruneObjects { l := logger.WithValues( "object_name", obj.GetName(), From 20c7bf67d53b98bf838aa45027c050e0bf339e11 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 13 Feb 2024 16:34:07 +0100 Subject: [PATCH 06/26] Fixed controller test Signed-off-by: Yuri Sa --- controllers/builder_test.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 326a7fd32b..0bd052027f 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -86,8 +86,6 @@ service: exporters: [logging] ` one := int32(1) - maxReplicas := int32(2) - stabilizationWindowSeconds := int32(300) type args struct { instance v1alpha1.OpenTelemetryCollector } @@ -106,15 +104,6 @@ service: Namespace: "test", }, Spec: v1alpha1.OpenTelemetryCollectorSpec{ - MinReplicas: &one, - MaxReplicas: &maxReplicas, - Autoscaler: &v1alpha1.AutoscalerSpec{ - Behavior: &autoscalingv2.HorizontalPodAutoscalerBehavior{ - ScaleUp: &autoscalingv2.HPAScalingRules{ - StabilizationWindowSeconds: &stabilizationWindowSeconds, - }, - }, - }, Replicas: &one, Mode: "deployment", Image: "test", From 29135cdd2a6b9ee685023929ae865e2e74dbf5de Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 13 Feb 2024 16:42:39 +0100 Subject: [PATCH 07/26] Fixed controller test Signed-off-by: Yuri Sa --- controllers/builder_test.go | 1 - controllers/common.go | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 0bd052027f..054981cd6e 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -22,7 +22,6 @@ import ( monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" - autoscalingv2 "k8s.io/api/autoscaling/v2" corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/controllers/common.go b/controllers/common.go index 03e242e504..309cf52324 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -20,8 +20,6 @@ import ( "fmt" "github.com/go-logr/logr" - "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift" - "github.com/open-telemetry/opentelemetry-operator/internal/naming" routev1 "github.com/openshift/api/route/v1" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" autoscalingv2 "k8s.io/api/autoscaling/v2" @@ -37,11 +35,13 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "github.com/open-telemetry/opentelemetry-operator/internal/api/convert" + "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/opampbridge" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator" + "github.com/open-telemetry/opentelemetry-operator/internal/naming" "github.com/open-telemetry/opentelemetry-operator/pkg/featuregate" ) @@ -109,7 +109,7 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont if otelCol.Spec.Observability.Metrics.EnableMetrics && featuregate.PrometheusOperatorIsAvailable.IsEnabled() { servicemonitorList := &monitoringv1.ServiceMonitorList{} - err := r.List(ctx, servicemonitorList, listOps) + err = r.List(ctx, servicemonitorList, listOps) if err != nil { return nil, fmt.Errorf("Error listing ServiceMonitors: %w", err) } From dacc99a95bf114c0fcd7664f1cbf7690b01b9f5e Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Thu, 15 Feb 2024 16:34:37 +0100 Subject: [PATCH 08/26] Add PodDisruptionBudget Signed-off-by: Yuri Sa --- controllers/opentelemetrycollector_controller.go | 2 +- internal/api/convert/v1alpha.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/controllers/opentelemetrycollector_controller.go b/controllers/opentelemetrycollector_controller.go index 357f574442..f1f595f6a7 100644 --- a/controllers/opentelemetrycollector_controller.go +++ b/controllers/opentelemetrycollector_controller.go @@ -143,7 +143,7 @@ func (r *OpenTelemetryCollectorReconciler) Reconcile(ctx context.Context, req ct return ctrl.Result{}, err } - err = reconcileDesiredObjects(ctx, r.Client, log, ¶ms.OtelCol, params.Scheme, desiredObjects, ownedObjects) + err = reconcileDesiredObjects(ctx, r.Client, log, &instance, params.Scheme, desiredObjects, ownedObjects) return collectorStatus.HandleReconcileStatus(ctx, log, params, instance, err) } diff --git a/internal/api/convert/v1alpha.go b/internal/api/convert/v1alpha.go index 1a6ed18313..148524be1e 100644 --- a/internal/api/convert/v1alpha.go +++ b/internal/api/convert/v1alpha.go @@ -50,6 +50,12 @@ func V1Alpha1to2(in v1alpha1.OpenTelemetryCollector) (v1alpha2.OpenTelemetryColl Pods: m.Pods, } } + if copy.Spec.MaxReplicas != nil && copy.Spec.Autoscaler.MaxReplicas == nil { + copy.Spec.Autoscaler.MaxReplicas = copy.Spec.MaxReplicas + } + if copy.Spec.MinReplicas != nil && copy.Spec.Autoscaler.MinReplicas == nil { + copy.Spec.Autoscaler.MinReplicas = copy.Spec.MinReplicas + } out.Spec.OpenTelemetryCommonFields.Autoscaler = &v1alpha2.AutoscalerSpec{ MinReplicas: copy.Spec.Autoscaler.MinReplicas, MaxReplicas: copy.Spec.Autoscaler.MaxReplicas, From a0a30dab1734eb0b82a6957532927069ce546979 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Fri, 16 Feb 2024 13:37:33 +0100 Subject: [PATCH 09/26] Change vars setting Signed-off-by: Yuri Sa --- controllers/common.go | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/controllers/common.go b/controllers/common.go index ae35b85123..dc8b588e53 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -97,7 +97,7 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont hpaList := &autoscalingv2.HorizontalPodAutoscalerList{} err := r.List(ctx, hpaList, listOps) if err != nil { - return nil, fmt.Errorf("Error listing HorizontalPodAutoscalers: %w", err) + return nil, fmt.Errorf("error listing HorizontalPodAutoscalers: %w", err) } for i := range hpaList.Items { ownedObjects[hpaList.Items[i].GetUID()] = &hpaList.Items[i] @@ -107,7 +107,7 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont servicemonitorList := &monitoringv1.ServiceMonitorList{} err = r.List(ctx, servicemonitorList, listOps) if err != nil { - return nil, fmt.Errorf("Error listing ServiceMonitors: %w", err) + return nil, fmt.Errorf("error listing ServiceMonitors: %w", err) } for i := range servicemonitorList.Items { ownedObjects[servicemonitorList.Items[i].GetUID()] = servicemonitorList.Items[i] @@ -116,7 +116,7 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont podMonitorList := &monitoringv1.PodMonitorList{} err = r.List(ctx, podMonitorList, listOps) if err != nil { - return nil, fmt.Errorf("Error listing PodMonitors: %w", err) + return nil, fmt.Errorf("error listing PodMonitors: %w", err) } for i := range podMonitorList.Items { ownedObjects[podMonitorList.Items[i].GetUID()] = podMonitorList.Items[i] @@ -125,7 +125,7 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont ingressList := &networkingv1.IngressList{} err = r.List(ctx, ingressList, listOps) if err != nil { - return nil, fmt.Errorf("Error listing Ingresses: %w", err) + return nil, fmt.Errorf("error listing Ingresses: %w", err) } for i := range ingressList.Items { ownedObjects[ingressList.Items[i].GetUID()] = &ingressList.Items[i] @@ -135,21 +135,20 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont routesList := &routev1.RouteList{} err := r.List(ctx, routesList, listOps) if err != nil { - return nil, fmt.Errorf("Error listing Routes: %w", err) + return nil, fmt.Errorf("error listing Routes: %w", err) } for i := range routesList.Items { ownedObjects[routesList.Items[i].GetUID()] = &routesList.Items[i] } } - if params.OtelCol.Spec.PodDisruptionBudget != nil { - pdbList := &policyV1.PodDisruptionBudgetList{} - err := r.List(ctx, pdbList, listOps) - if err != nil { - return nil, fmt.Errorf("Error listing PodDisruptionBudgets: %w", err) - } - for i := range pdbList.Items { - ownedObjects[pdbList.Items[i].GetUID()] = &pdbList.Items[i] - } + + pdbList := &policyV1.PodDisruptionBudgetList{} + err = r.List(ctx, pdbList, listOps) + if err != nil { + return nil, fmt.Errorf("error listing PodDisruptionBudgets: %w", err) + } + for i := range pdbList.Items { + ownedObjects[pdbList.Items[i].GetUID()] = &pdbList.Items[i] } return ownedObjects, nil @@ -158,7 +157,6 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont // reconcileDesiredObjects runs the reconcile process using the mutateFn over the given list of objects. func reconcileDesiredObjects(ctx context.Context, kubeClient client.Client, logger logr.Logger, owner metav1.Object, scheme *runtime.Scheme, desiredObjects []client.Object, ownedObjects map[types.UID]client.Object) error { var errs []error - pruneObjects := ownedObjects for _, desired := range desiredObjects { l := logger.WithValues( "object_name", desired.GetName(), @@ -196,14 +194,14 @@ func reconcileDesiredObjects(ctx context.Context, kubeClient client.Client, logg l.V(1).Info(fmt.Sprintf("desired has been %s", op)) // This object is still managed by the operator, remove it from the list of objects to prune - delete(pruneObjects, existing.GetUID()) + delete(ownedObjects, existing.GetUID()) } if len(errs) > 0 { return fmt.Errorf("failed to create objects for %s: %w", owner.GetName(), errors.Join(errs...)) } // Pruning owned objects in the cluster which are not should not be present after the reconciliation. pruneErrs := []error{} - for _, obj := range pruneObjects { + for _, obj := range ownedObjects { l := logger.WithValues( "object_name", obj.GetName(), "object_kind", obj.GetObjectKind().GroupVersionKind(), From 1edd7213b1ff5d437503cd847fc0da6e72ea1215 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Fri, 16 Feb 2024 21:44:24 +0100 Subject: [PATCH 10/26] Change vars setting Signed-off-by: Yuri Sa --- controllers/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/common.go b/controllers/common.go index dc8b588e53..58736888c6 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -133,7 +133,7 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont if params.Config.OpenShiftRoutesAvailability() == openshift.RoutesAvailable { routesList := &routev1.RouteList{} - err := r.List(ctx, routesList, listOps) + err = r.List(ctx, routesList, listOps) if err != nil { return nil, fmt.Errorf("error listing Routes: %w", err) } From 2f1b576f128c4d1c111e4b200844c7a95e46d4cb Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 20 Feb 2024 17:44:37 +0100 Subject: [PATCH 11/26] Update e2e tests to chainsaw Signed-off-by: Yuri Sa --- tests/e2e-autoscale/autoscale/04-delete.yaml | 11 --- tests/e2e-autoscale/autoscale/04-install.yaml | 74 +++++++++++++++++++ .../autoscale/chainsaw-test.yaml | 6 ++ 3 files changed, 80 insertions(+), 11 deletions(-) delete mode 100644 tests/e2e-autoscale/autoscale/04-delete.yaml create mode 100644 tests/e2e-autoscale/autoscale/04-install.yaml diff --git a/tests/e2e-autoscale/autoscale/04-delete.yaml b/tests/e2e-autoscale/autoscale/04-delete.yaml deleted file mode 100644 index 319b3a0578..0000000000 --- a/tests/e2e-autoscale/autoscale/04-delete.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -delete: - - apiVersion: opentelemetry.io/v1alpha1 - kind: OpenTelemetryCollector - metadata: - name: simplest - - apiVersion: opentelemetry.io/v1alpha1 - kind: OpenTelemetryCollector - metadata: - name: simplest-set-utilization diff --git a/tests/e2e-autoscale/autoscale/04-install.yaml b/tests/e2e-autoscale/autoscale/04-install.yaml new file mode 100644 index 0000000000..8f32f16d37 --- /dev/null +++ b/tests/e2e-autoscale/autoscale/04-install.yaml @@ -0,0 +1,74 @@ +# This creates two different deployments: +# * The first one is to ensure an autoscaler is created without +# setting any metrics in the Spec. +# * The second is to check that scaling works properly and that +# spec updates are working as expected. +# +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: simplest +spec: +# TODO: these tests use .Spec.MaxReplicas and .Spec.MinReplicas. These fields are +# deprecated and moved to .Spec.Autoscaler. Fine to use these fields to test that old CRD is +# still supported but should eventually be updated. + minReplicas: 1 + maxReplicas: 2 + resources: + limits: + cpu: 500m + memory: 128Mi + requests: + cpu: 5m + memory: 64Mi + + config: | + receivers: + otlp: + protocols: + grpc: + http: + processors: + + exporters: + debug: + + service: + pipelines: + traces: + receivers: [otlp] + processors: [] + exporters: [debug] +--- +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: simplest-set-utilization +spec: + minReplicas: 1 + maxReplicas: 2 + resources: + limits: + cpu: 250m + memory: 128Mi + requests: + cpu: 5m + memory: 64Mi + + config: | + receivers: + otlp: + protocols: + grpc: + http: + processors: + + exporters: + debug: + + service: + pipelines: + traces: + receivers: [otlp] + processors: [] + exporters: [debug] diff --git a/tests/e2e-autoscale/autoscale/chainsaw-test.yaml b/tests/e2e-autoscale/autoscale/chainsaw-test.yaml index d61acf4643..29b94237c9 100755 --- a/tests/e2e-autoscale/autoscale/chainsaw-test.yaml +++ b/tests/e2e-autoscale/autoscale/chainsaw-test.yaml @@ -33,3 +33,9 @@ spec: name: telemetrygen-set-utilization - assert: file: 03-assert.yaml + - name: step-04 + try: + - apply: + file: 04-install.yaml + - error: + file: 04-error.yaml From 9a669d09562254aa9a2fe08c13bc2a7d6c9f665e Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 21 Feb 2024 10:00:50 +0100 Subject: [PATCH 12/26] Added ingress e2e tests Signed-off-by: Yuri Sa --- controllers/suite_test.go | 6 ---- .../autoscale/chainsaw-test.yaml | 9 ++--- tests/e2e/ingress/01-error.yaml | 35 +++++++++++++++++++ tests/e2e/ingress/01-install.yaml | 23 ++++++++++++ tests/e2e/ingress/chainsaw-test.yaml | 19 ++++++---- 5 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 tests/e2e/ingress/01-error.yaml create mode 100644 tests/e2e/ingress/01-install.yaml diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 33bd27fce4..00176baf4c 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -27,7 +27,6 @@ import ( routev1 "github.com/openshift/api/route/v1" "github.com/stretchr/testify/assert" - autoscalingv2 "k8s.io/api/autoscaling/v2" v1 "k8s.io/api/core/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -121,11 +120,6 @@ func TestMain(m *testing.M) { os.Exit(1) } - if err = autoscalingv2.AddToScheme(testScheme); err != nil { - fmt.Printf("failed to register scheme: %v", err) - os.Exit(1) - } - if err = v1alpha1.AddToScheme(testScheme); err != nil { fmt.Printf("failed to register scheme: %v", err) os.Exit(1) diff --git a/tests/e2e-autoscale/autoscale/chainsaw-test.yaml b/tests/e2e-autoscale/autoscale/chainsaw-test.yaml index 29b94237c9..6f19ced46a 100755 --- a/tests/e2e-autoscale/autoscale/chainsaw-test.yaml +++ b/tests/e2e-autoscale/autoscale/chainsaw-test.yaml @@ -33,9 +33,10 @@ spec: name: telemetrygen-set-utilization - assert: file: 03-assert.yaml + # applying the same OpenTelemetryCollector from the 00-step, but this time without the spec.autoscaler, which should inform the controller to delete the HPAs resources. So, we should get an error checking if the HPAs still exist - name: step-04 try: - - apply: - file: 04-install.yaml - - error: - file: 04-error.yaml + - apply: + file: 04-install.yaml + - error: + file: 04-error.yaml diff --git a/tests/e2e/ingress/01-error.yaml b/tests/e2e/ingress/01-error.yaml new file mode 100644 index 0000000000..74e912b97a --- /dev/null +++ b/tests/e2e/ingress/01-error.yaml @@ -0,0 +1,35 @@ +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + something.com: "true" + labels: + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: simplest-ingress + name: simplest-ingress + ownerReferences: + - apiVersion: opentelemetry.io/v1alpha1 + blockOwnerDeletion: true + controller: true + kind: OpenTelemetryCollector + name: simplest +spec: + rules: + - host: example.com + http: + paths: + - backend: + service: + name: simplest-collector + port: + name: otlp-grpc + path: /otlp-grpc + pathType: Prefix + - backend: + service: + name: simplest-collector + port: + name: otlp-http + path: /otlp-http + pathType: Prefix diff --git a/tests/e2e/ingress/01-install.yaml b/tests/e2e/ingress/01-install.yaml new file mode 100644 index 0000000000..32416b43bd --- /dev/null +++ b/tests/e2e/ingress/01-install.yaml @@ -0,0 +1,23 @@ +--- +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: simplest +spec: + mode: "deployment" + config: | + receivers: + otlp: + protocols: + grpc: + http: + + exporters: + debug: + + service: + pipelines: + traces: + receivers: [otlp] + processors: [] + exporters: [debug] diff --git a/tests/e2e/ingress/chainsaw-test.yaml b/tests/e2e/ingress/chainsaw-test.yaml index 72a7fa61e6..6afd2724d2 100755 --- a/tests/e2e/ingress/chainsaw-test.yaml +++ b/tests/e2e/ingress/chainsaw-test.yaml @@ -6,9 +6,16 @@ metadata: name: ingress spec: steps: - - name: step-00 - try: - - apply: - file: 00-install.yaml - - assert: - file: 00-assert.yaml + - name: step-00 + try: + - apply: + file: 00-install.yaml + - assert: + file: 00-assert.yaml + # Applying the same OpenTelemetryCollector from the previous step, but this time without the spec.ingress, which should inform the controller to delete the ingress resource. So, we should get an error checking if the ingress still exists. + - name: step-01 + try: + - apply: + file: 01-install.yaml + - error: + file: 01-error.yaml From ebbb447d4c88ec5d189e2b5af4f65ee05b38f2ba Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Mon, 26 Feb 2024 12:30:09 +0100 Subject: [PATCH 13/26] Added Volumes, changed function's place Signed-off-by: Yuri Sa --- .chloggen/fix-hpa-delete.yaml | 2 +- controllers/common.go | 77 ------------------- .../opentelemetrycollector_controller.go | 75 ++++++++++++++++++ tests/e2e/statefulset-features/02-assert.yaml | 53 +++++++++++++ ...ml => 02-update-volume-claim-storage.yaml} | 4 +- .../statefulset-features/chainsaw-test.yaml | 30 +++++--- 6 files changed, 149 insertions(+), 92 deletions(-) create mode 100644 tests/e2e/statefulset-features/02-assert.yaml rename tests/e2e/statefulset-features/{01-update-volume-claim-templates.yaml => 02-update-volume-claim-storage.yaml} (94%) diff --git a/.chloggen/fix-hpa-delete.yaml b/.chloggen/fix-hpa-delete.yaml index d8629577e2..e9cfd3c894 100755 --- a/.chloggen/fix-hpa-delete.yaml +++ b/.chloggen/fix-hpa-delete.yaml @@ -8,7 +8,7 @@ component: operator note: Fixed HPA deletion # One or more tracking issues related to the change -issues: [2568] +issues: [2568, 2587, 2651] # (Optional) One or more lines of additional information to render under the primary note. # These lines will be padded with 2 spaces and then inserted directly into the document. diff --git a/controllers/common.go b/controllers/common.go index 58736888c6..7885fa8a3a 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -20,14 +20,8 @@ import ( "fmt" "github.com/go-logr/logr" - routev1 "github.com/openshift/api/route/v1" - monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" - autoscalingv2 "k8s.io/api/autoscaling/v2" - networkingv1 "k8s.io/api/networking/v1" - policyV1 "k8s.io/api/policy/v1" rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/util/retry" @@ -35,14 +29,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector" - "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/opampbridge" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator" - "github.com/open-telemetry/opentelemetry-operator/internal/naming" - "github.com/open-telemetry/opentelemetry-operator/pkg/featuregate" ) func isNamespaceScoped(obj client.Object) bool { @@ -87,73 +77,6 @@ func BuildOpAMPBridge(params manifests.Params) ([]client.Object, error) { return resources, nil } -func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Context, params manifests.Params) (map[types.UID]client.Object, error) { - ownedObjects := map[types.UID]client.Object{} - - listOps := &client.ListOptions{ - Namespace: params.OtelCol.Namespace, - LabelSelector: labels.SelectorFromSet(manifestutils.Labels(params.OtelCol.ObjectMeta, naming.Collector(params.OtelCol.Name), params.OtelCol.Spec.Image, collector.ComponentOpenTelemetryCollector, params.Config.LabelsFilter())), - } - hpaList := &autoscalingv2.HorizontalPodAutoscalerList{} - err := r.List(ctx, hpaList, listOps) - if err != nil { - return nil, fmt.Errorf("error listing HorizontalPodAutoscalers: %w", err) - } - for i := range hpaList.Items { - ownedObjects[hpaList.Items[i].GetUID()] = &hpaList.Items[i] - } - - if params.OtelCol.Spec.Observability.Metrics.EnableMetrics && featuregate.PrometheusOperatorIsAvailable.IsEnabled() { - servicemonitorList := &monitoringv1.ServiceMonitorList{} - err = r.List(ctx, servicemonitorList, listOps) - if err != nil { - return nil, fmt.Errorf("error listing ServiceMonitors: %w", err) - } - for i := range servicemonitorList.Items { - ownedObjects[servicemonitorList.Items[i].GetUID()] = servicemonitorList.Items[i] - } - - podMonitorList := &monitoringv1.PodMonitorList{} - err = r.List(ctx, podMonitorList, listOps) - if err != nil { - return nil, fmt.Errorf("error listing PodMonitors: %w", err) - } - for i := range podMonitorList.Items { - ownedObjects[podMonitorList.Items[i].GetUID()] = podMonitorList.Items[i] - } - } - ingressList := &networkingv1.IngressList{} - err = r.List(ctx, ingressList, listOps) - if err != nil { - return nil, fmt.Errorf("error listing Ingresses: %w", err) - } - for i := range ingressList.Items { - ownedObjects[ingressList.Items[i].GetUID()] = &ingressList.Items[i] - } - - if params.Config.OpenShiftRoutesAvailability() == openshift.RoutesAvailable { - routesList := &routev1.RouteList{} - err = r.List(ctx, routesList, listOps) - if err != nil { - return nil, fmt.Errorf("error listing Routes: %w", err) - } - for i := range routesList.Items { - ownedObjects[routesList.Items[i].GetUID()] = &routesList.Items[i] - } - } - - pdbList := &policyV1.PodDisruptionBudgetList{} - err = r.List(ctx, pdbList, listOps) - if err != nil { - return nil, fmt.Errorf("error listing PodDisruptionBudgets: %w", err) - } - for i := range pdbList.Items { - ownedObjects[pdbList.Items[i].GetUID()] = &pdbList.Items[i] - } - - return ownedObjects, nil -} - // reconcileDesiredObjects runs the reconcile process using the mutateFn over the given list of objects. func reconcileDesiredObjects(ctx context.Context, kubeClient client.Client, logger logr.Logger, owner metav1.Object, scheme *runtime.Scheme, desiredObjects []client.Object, ownedObjects map[types.UID]client.Object) error { var errs []error diff --git a/controllers/opentelemetrycollector_controller.go b/controllers/opentelemetrycollector_controller.go index f1f595f6a7..1a8f6a4d4a 100644 --- a/controllers/opentelemetrycollector_controller.go +++ b/controllers/opentelemetrycollector_controller.go @@ -17,6 +17,7 @@ package controllers import ( "context" + "fmt" "github.com/go-logr/logr" routev1 "github.com/openshift/api/route/v1" @@ -28,7 +29,9 @@ import ( policyV1 "k8s.io/api/policy/v1" rbacv1 "k8s.io/api/rbac/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -38,6 +41,9 @@ import ( "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" + "github.com/open-telemetry/opentelemetry-operator/internal/naming" collectorStatus "github.com/open-telemetry/opentelemetry-operator/internal/status/collector" "github.com/open-telemetry/opentelemetry-operator/pkg/featuregate" ) @@ -60,6 +66,73 @@ type Params struct { Config config.Config } +func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Context, params manifests.Params) (map[types.UID]client.Object, error) { + ownedObjects := map[types.UID]client.Object{} + + listOps := &client.ListOptions{ + Namespace: params.OtelCol.Namespace, + LabelSelector: labels.SelectorFromSet(manifestutils.Labels(params.OtelCol.ObjectMeta, naming.Collector(params.OtelCol.Name), params.OtelCol.Spec.Image, collector.ComponentOpenTelemetryCollector, params.Config.LabelsFilter())), + } + hpaList := &autoscalingv2.HorizontalPodAutoscalerList{} + err := r.List(ctx, hpaList, listOps) + if err != nil { + return nil, fmt.Errorf("error listing HorizontalPodAutoscalers: %w", err) + } + for i := range hpaList.Items { + ownedObjects[hpaList.Items[i].GetUID()] = &hpaList.Items[i] + } + + if featuregate.PrometheusOperatorIsAvailable.IsEnabled() { + servicemonitorList := &monitoringv1.ServiceMonitorList{} + err = r.List(ctx, servicemonitorList, listOps) + if err != nil { + return nil, fmt.Errorf("error listing ServiceMonitors: %w", err) + } + for i := range servicemonitorList.Items { + ownedObjects[servicemonitorList.Items[i].GetUID()] = servicemonitorList.Items[i] + } + + podMonitorList := &monitoringv1.PodMonitorList{} + err = r.List(ctx, podMonitorList, listOps) + if err != nil { + return nil, fmt.Errorf("error listing PodMonitors: %w", err) + } + for i := range podMonitorList.Items { + ownedObjects[podMonitorList.Items[i].GetUID()] = podMonitorList.Items[i] + } + } + ingressList := &networkingv1.IngressList{} + err = r.List(ctx, ingressList, listOps) + if err != nil { + return nil, fmt.Errorf("error listing Ingresses: %w", err) + } + for i := range ingressList.Items { + ownedObjects[ingressList.Items[i].GetUID()] = &ingressList.Items[i] + } + + if params.Config.OpenShiftRoutesAvailability() == openshift.RoutesAvailable { + routesList := &routev1.RouteList{} + err = r.List(ctx, routesList, listOps) + if err != nil { + return nil, fmt.Errorf("error listing Routes: %w", err) + } + for i := range routesList.Items { + ownedObjects[routesList.Items[i].GetUID()] = &routesList.Items[i] + } + } + + pdbList := &policyV1.PodDisruptionBudgetList{} + err = r.List(ctx, pdbList, listOps) + if err != nil { + return nil, fmt.Errorf("error listing PodDisruptionBudgets: %w", err) + } + for i := range pdbList.Items { + ownedObjects[pdbList.Items[i].GetUID()] = &pdbList.Items[i] + } + + return ownedObjects, nil +} + func (r *OpenTelemetryCollectorReconciler) getParams(instance v1alpha1.OpenTelemetryCollector) (manifests.Params, error) { otelCol, err := convert.V1Alpha1to2(instance) if err != nil { @@ -157,6 +230,8 @@ func (r *OpenTelemetryCollectorReconciler) SetupWithManager(mgr ctrl.Manager) er Owns(&appsv1.Deployment{}). Owns(&appsv1.DaemonSet{}). Owns(&appsv1.StatefulSet{}). + Owns(&corev1.PersistentVolume{}). + Owns(&corev1.PersistentVolumeClaim{}). Owns(&networkingv1.Ingress{}). Owns(&autoscalingv2.HorizontalPodAutoscaler{}). Owns(&policyV1.PodDisruptionBudget{}) diff --git a/tests/e2e/statefulset-features/02-assert.yaml b/tests/e2e/statefulset-features/02-assert.yaml new file mode 100644 index 0000000000..4614618f57 --- /dev/null +++ b/tests/e2e/statefulset-features/02-assert.yaml @@ -0,0 +1,53 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: stateful-collector +spec: + podManagementPolicy: Parallel + template: + spec: + containers: + - args: + - --config=/conf/collector.yaml + name: otc-container + volumeMounts: + - mountPath: /conf + name: otc-internal + - mountPath: /usr/share/testvolume + name: testvolume + volumes: + - configMap: + items: + - key: collector.yaml + path: collector.yaml + name: stateful-collector + name: otc-internal + - emptyDir: {} + name: testvolume + volumeClaimTemplates: + - apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + name: testvolume + spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 2Gi + volumeMode: Filesystem +status: + replicas: 2 + readyReplicas: 2 +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: testvolume +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 2Gi + volumeMode: Filesystem diff --git a/tests/e2e/statefulset-features/01-update-volume-claim-templates.yaml b/tests/e2e/statefulset-features/02-update-volume-claim-storage.yaml similarity index 94% rename from tests/e2e/statefulset-features/01-update-volume-claim-templates.yaml rename to tests/e2e/statefulset-features/02-update-volume-claim-storage.yaml index bed1ca77c3..d9ca9a374b 100644 --- a/tests/e2e/statefulset-features/01-update-volume-claim-templates.yaml +++ b/tests/e2e/statefulset-features/02-update-volume-claim-storage.yaml @@ -4,7 +4,7 @@ metadata: name: stateful spec: mode: statefulset - replicas: 3 + replicas: 2 volumes: - name: testvolume volumeMounts: @@ -17,7 +17,7 @@ spec: accessModes: [ "ReadWriteMany" ] # change accessMode to trigger statefulset recreation. resources: requests: - storage: 1Gi + storage: 2Gi config: | receivers: jaeger: diff --git a/tests/e2e/statefulset-features/chainsaw-test.yaml b/tests/e2e/statefulset-features/chainsaw-test.yaml index c73d8ae7d2..59278b9cd8 100755 --- a/tests/e2e/statefulset-features/chainsaw-test.yaml +++ b/tests/e2e/statefulset-features/chainsaw-test.yaml @@ -6,15 +6,21 @@ metadata: name: statefulset-features spec: steps: - - name: step-00 - try: - - apply: - file: 00-install.yaml - - assert: - file: 00-assert.yaml - - name: step-01 - try: - - apply: - file: 01-update-volume-claim-templates.yaml - - assert: - file: 01-assert.yaml + - name: step-00 + try: + - apply: + file: 00-install.yaml + - assert: + file: 00-assert.yaml + - name: step-01 + try: + - apply: + file: 01-update-volume-claim-templates.yaml + - assert: + file: 01-assert.yaml + - name: step-02 + try: + - apply: + file: 02-update-volume-claim-storage.yaml + - assert: + file: 02-assert.yaml From 55240bafca6523c48761a8b07532ba79fd9d600f Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Mon, 26 Feb 2024 19:37:22 +0100 Subject: [PATCH 14/26] Added Volumes, changed function's place Signed-off-by: Yuri Sa --- controllers/opentelemetrycollector_controller.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/controllers/opentelemetrycollector_controller.go b/controllers/opentelemetrycollector_controller.go index 1a8f6a4d4a..7ff8f0ff42 100644 --- a/controllers/opentelemetrycollector_controller.go +++ b/controllers/opentelemetrycollector_controller.go @@ -81,8 +81,7 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont for i := range hpaList.Items { ownedObjects[hpaList.Items[i].GetUID()] = &hpaList.Items[i] } - - if featuregate.PrometheusOperatorIsAvailable.IsEnabled() { + if params.OtelCol.Spec.Observability.Metrics.EnableMetrics && featuregate.PrometheusOperatorIsAvailable.IsEnabled() { servicemonitorList := &monitoringv1.ServiceMonitorList{} err = r.List(ctx, servicemonitorList, listOps) if err != nil { From 4350a5605ed8880da23c3ae4726d91a5c1251598 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 27 Feb 2024 08:13:42 +0100 Subject: [PATCH 15/26] Added Volumes, changed function's place Signed-off-by: Yuri Sa --- controllers/opentelemetrycollector_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/opentelemetrycollector_controller.go b/controllers/opentelemetrycollector_controller.go index 7ff8f0ff42..8c0b5e6f1a 100644 --- a/controllers/opentelemetrycollector_controller.go +++ b/controllers/opentelemetrycollector_controller.go @@ -81,7 +81,7 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont for i := range hpaList.Items { ownedObjects[hpaList.Items[i].GetUID()] = &hpaList.Items[i] } - if params.OtelCol.Spec.Observability.Metrics.EnableMetrics && featuregate.PrometheusOperatorIsAvailable.IsEnabled() { + if featuregate.PrometheusOperatorIsAvailable.IsEnabled() { servicemonitorList := &monitoringv1.ServiceMonitorList{} err = r.List(ctx, servicemonitorList, listOps) if err != nil { From 18395040db0799b565ee58e4c3198dea005a2387 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 27 Feb 2024 11:59:29 +0100 Subject: [PATCH 16/26] Fixed Suite Test Signed-off-by: Yuri Sa --- Makefile | 2 +- controllers/suite_test.go | 9 +++-- .../manifests/collector/testdata/pm_crd.go | 38 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 internal/manifests/collector/testdata/pm_crd.go diff --git a/Makefile b/Makefile index ff2016a972..929a1b707c 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ endif START_KIND_CLUSTER ?= true -KUBE_VERSION ?= 1.24 +KUBE_VERSION ?= 1.29 KIND_CONFIG ?= kind-$(KUBE_VERSION).yaml KIND_CLUSTER_NAME ?= "otel-operator" diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 00176baf4c..c612b368e0 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -26,6 +26,7 @@ import ( "time" routev1 "github.com/openshift/api/route/v1" + monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" @@ -104,7 +105,7 @@ func TestMain(m *testing.M) { testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, - CRDs: []*apiextensionsv1.CustomResourceDefinition{testdata.OpenShiftRouteCRD}, + CRDs: []*apiextensionsv1.CustomResourceDefinition{testdata.OpenShiftRouteCRD, testdata.ServiceMonitorCRD, testdata.PodMonitorCRD}, WebhookInstallOptions: envtest.WebhookInstallOptions{ Paths: []string{filepath.Join("..", "config", "webhook")}, }, @@ -114,12 +115,14 @@ func TestMain(m *testing.M) { fmt.Printf("failed to start testEnv: %v", err) os.Exit(1) } - + if err = monitoringv1.AddToScheme(testScheme); err != nil { + fmt.Printf("failed to register scheme: %v", err) + os.Exit(1) + } if err = routev1.AddToScheme(testScheme); err != nil { fmt.Printf("failed to register scheme: %v", err) os.Exit(1) } - if err = v1alpha1.AddToScheme(testScheme); err != nil { fmt.Printf("failed to register scheme: %v", err) os.Exit(1) diff --git a/internal/manifests/collector/testdata/pm_crd.go b/internal/manifests/collector/testdata/pm_crd.go new file mode 100644 index 0000000000..6ab4d494da --- /dev/null +++ b/internal/manifests/collector/testdata/pm_crd.go @@ -0,0 +1,38 @@ +package testdata + +import ( + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// PodMonitorCRD as go structure. +var PodMonitorCRD = &apiextensionsv1.CustomResourceDefinition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "podmonitors.monitoring.coreos.com", + }, + Spec: apiextensionsv1.CustomResourceDefinitionSpec{ + Group: "monitoring.coreos.com", + Versions: []apiextensionsv1.CustomResourceDefinitionVersion{ + { + Name: "v1", + Served: true, + Storage: true, + Schema: &apiextensionsv1.CustomResourceValidation{ + OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{ + Type: "object", + XPreserveUnknownFields: func(v bool) *bool { return &v }(true), + }, + }, + Subresources: &apiextensionsv1.CustomResourceSubresources{ + Status: &apiextensionsv1.CustomResourceSubresourceStatus{}, + }, + }, + }, + Scope: apiextensionsv1.NamespaceScoped, + Names: apiextensionsv1.CustomResourceDefinitionNames{ + Plural: "podmonitors", + Singular: "podmonitor", + Kind: "PodMonitor", + }, + }, +} From 88b30ef800a87d004b64295db10a4f4f114ea4a7 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 27 Feb 2024 12:18:23 +0100 Subject: [PATCH 17/26] Added RBAC for Volumes Signed-off-by: Yuri Sa --- ...emetry-operator.clusterserviceversion.yaml | 4 ++- config/rbac/role.yaml | 2 ++ .../opentelemetrycollector_controller.go | 2 +- .../statefulset-features/chainsaw-test.yaml | 36 +++++++++---------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml index 0357e2f701..316060a979 100644 --- a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -65,7 +65,7 @@ metadata: categories: Logging & Tracing,Monitoring certified: "false" containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator - createdAt: "2024-02-15T18:18:46Z" + createdAt: "2024-02-27T11:16:56Z" description: Provides the OpenTelemetry components, including the Collector operators.operatorframework.io/builder: operator-sdk-v1.29.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 @@ -175,6 +175,8 @@ spec: - "" resources: - configmaps + - persistentvolumeclaims + - persistentvolumes - pods - serviceaccounts - services diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index c2b96f80a7..56318be008 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -8,6 +8,8 @@ rules: - "" resources: - configmaps + - persistentvolumeclaims + - persistentvolumes - pods - serviceaccounts - services diff --git a/controllers/opentelemetrycollector_controller.go b/controllers/opentelemetrycollector_controller.go index 8c0b5e6f1a..96cb435a14 100644 --- a/controllers/opentelemetrycollector_controller.go +++ b/controllers/opentelemetrycollector_controller.go @@ -159,7 +159,7 @@ func NewReconciler(p Params) *OpenTelemetryCollectorReconciler { return r } -// +kubebuilder:rbac:groups="",resources=pods;configmaps;services;serviceaccounts,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups="",resources=pods;configmaps;services;serviceaccounts;persistentvolumeclaims;persistentvolumes,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups="",resources=events,verbs=create;patch // +kubebuilder:rbac:groups=apps,resources=daemonsets;deployments;statefulsets,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=autoscaling,resources=horizontalpodautoscalers,verbs=get;list;watch;create;update;patch;delete diff --git a/tests/e2e/statefulset-features/chainsaw-test.yaml b/tests/e2e/statefulset-features/chainsaw-test.yaml index 59278b9cd8..78ae2314af 100755 --- a/tests/e2e/statefulset-features/chainsaw-test.yaml +++ b/tests/e2e/statefulset-features/chainsaw-test.yaml @@ -6,21 +6,21 @@ metadata: name: statefulset-features spec: steps: - - name: step-00 - try: - - apply: - file: 00-install.yaml - - assert: - file: 00-assert.yaml - - name: step-01 - try: - - apply: - file: 01-update-volume-claim-templates.yaml - - assert: - file: 01-assert.yaml - - name: step-02 - try: - - apply: - file: 02-update-volume-claim-storage.yaml - - assert: - file: 02-assert.yaml + - name: step-00 + try: + - apply: + file: 00-install.yaml + - assert: + file: 00-assert.yaml + - name: step-01 + try: + - apply: + file: 01-update-volume-claim-templates.yaml + - assert: + file: 01-assert.yaml + - name: step-02 + try: + - apply: + file: 02-update-volume-claim-storage.yaml + - assert: + file: 02-assert.yaml From 7e1b010e2a6a1b57b074bf9dbf94c9b252d9a4e1 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 27 Feb 2024 12:27:58 +0100 Subject: [PATCH 18/26] Added RBAC for Volumes Signed-off-by: Yuri Sa --- .../01-update-volume-claim-templates.yaml | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/e2e/statefulset-features/01-update-volume-claim-templates.yaml diff --git a/tests/e2e/statefulset-features/01-update-volume-claim-templates.yaml b/tests/e2e/statefulset-features/01-update-volume-claim-templates.yaml new file mode 100644 index 0000000000..633d10b911 --- /dev/null +++ b/tests/e2e/statefulset-features/01-update-volume-claim-templates.yaml @@ -0,0 +1,34 @@ +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: stateful +spec: + mode: statefulset + replicas: 3 + volumes: + - name: testvolume + volumeMounts: + - name: testvolume + mountPath: /usr/share/testvolume + volumeClaimTemplates: + - metadata: + name: testvolume + spec: + accessModes: [ "ReadWriteMany" ] # change accessMode to trigger statefulset recreation. + resources: + requests: + storage: 1Gi + config: | + receivers: + jaeger: + protocols: + grpc: + processors: + exporters: + debug: + service: + pipelines: + traces: + receivers: [jaeger] + processors: [] + exporters: [debug] \ No newline at end of file From 18c8385f91f83f7a70aba9328e83d4f383e2f7c5 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 27 Feb 2024 19:13:47 +0100 Subject: [PATCH 19/26] Fixed Suite Test Signed-off-by: Yuri Sa --- .../opentelemetrycollector_controller.go | 4 +- controllers/suite_test.go | 5 ++ internal/manifests/collector/ingress_test.go | 16 ++++++ main.go | 2 + tests/e2e/statefulset-features/02-assert.yaml | 53 ------------------- .../02-update-volume-claim-storage.yaml | 34 ------------ .../statefulset-features/chainsaw-test.yaml | 6 --- 7 files changed, 24 insertions(+), 96 deletions(-) delete mode 100644 tests/e2e/statefulset-features/02-assert.yaml delete mode 100644 tests/e2e/statefulset-features/02-update-volume-claim-storage.yaml diff --git a/controllers/opentelemetrycollector_controller.go b/controllers/opentelemetrycollector_controller.go index 96cb435a14..ce7c3f9185 100644 --- a/controllers/opentelemetrycollector_controller.go +++ b/controllers/opentelemetrycollector_controller.go @@ -43,7 +43,6 @@ import ( "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" - "github.com/open-telemetry/opentelemetry-operator/internal/naming" collectorStatus "github.com/open-telemetry/opentelemetry-operator/internal/status/collector" "github.com/open-telemetry/opentelemetry-operator/pkg/featuregate" ) @@ -71,7 +70,7 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont listOps := &client.ListOptions{ Namespace: params.OtelCol.Namespace, - LabelSelector: labels.SelectorFromSet(manifestutils.Labels(params.OtelCol.ObjectMeta, naming.Collector(params.OtelCol.Name), params.OtelCol.Spec.Image, collector.ComponentOpenTelemetryCollector, params.Config.LabelsFilter())), + LabelSelector: labels.SelectorFromSet(manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, collector.ComponentOpenTelemetryCollector)), } hpaList := &autoscalingv2.HorizontalPodAutoscalerList{} err := r.List(ctx, hpaList, listOps) @@ -119,7 +118,6 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont ownedObjects[routesList.Items[i].GetUID()] = &routesList.Items[i] } } - pdbList := &policyV1.PodDisruptionBudgetList{} err = r.List(ctx, pdbList, listOps) if err != nil { diff --git a/controllers/suite_test.go b/controllers/suite_test.go index c612b368e0..f289cf1c75 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -29,6 +29,7 @@ import ( monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" + networkingv1 "k8s.io/api/networking/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -119,6 +120,10 @@ func TestMain(m *testing.M) { fmt.Printf("failed to register scheme: %v", err) os.Exit(1) } + if err = networkingv1.AddToScheme(testScheme); err != nil { + fmt.Printf("failed to register scheme: %v", err) + os.Exit(1) + } if err = routev1.AddToScheme(testScheme); err != nil { fmt.Printf("failed to register scheme: %v", err) os.Exit(1) diff --git a/internal/manifests/collector/ingress_test.go b/internal/manifests/collector/ingress_test.go index 9a7ae7ff10..6713472138 100644 --- a/internal/manifests/collector/ingress_test.go +++ b/internal/manifests/collector/ingress_test.go @@ -51,6 +51,22 @@ func TestDesiredIngresses(t *testing.T) { assert.NoError(t, err) }) + t.Run("should return nil, no ingress set", func(t *testing.T) { + params := manifests.Params{ + Config: config.Config{}, + Log: logger, + OtelCol: v1beta1.OpenTelemetryCollector{ + Spec: v1beta1.OpenTelemetryCollectorSpec{ + Mode: "Deployment", + }, + }, + } + + actual, err := Ingress(params) + assert.Nil(t, actual) + assert.NoError(t, err) + }) + t.Run("should return nil unable to parse receiver ports", func(t *testing.T) { params := manifests.Params{ Config: config.Config{}, diff --git a/main.go b/main.go index 074e3905d2..fec2e9be99 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,7 @@ import ( monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "github.com/spf13/pflag" colfeaturegate "go.opentelemetry.io/collector/featuregate" + networkingv1 "k8s.io/api/networking/v1" k8sruntime "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/kubernetes" @@ -74,6 +75,7 @@ func init() { utilruntime.Must(otelv1alpha1.AddToScheme(scheme)) utilruntime.Must(routev1.AddToScheme(scheme)) utilruntime.Must(monitoringv1.AddToScheme(scheme)) + utilruntime.Must(networkingv1.AddToScheme(scheme)) // +kubebuilder:scaffold:scheme } diff --git a/tests/e2e/statefulset-features/02-assert.yaml b/tests/e2e/statefulset-features/02-assert.yaml deleted file mode 100644 index 4614618f57..0000000000 --- a/tests/e2e/statefulset-features/02-assert.yaml +++ /dev/null @@ -1,53 +0,0 @@ -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: stateful-collector -spec: - podManagementPolicy: Parallel - template: - spec: - containers: - - args: - - --config=/conf/collector.yaml - name: otc-container - volumeMounts: - - mountPath: /conf - name: otc-internal - - mountPath: /usr/share/testvolume - name: testvolume - volumes: - - configMap: - items: - - key: collector.yaml - path: collector.yaml - name: stateful-collector - name: otc-internal - - emptyDir: {} - name: testvolume - volumeClaimTemplates: - - apiVersion: v1 - kind: PersistentVolumeClaim - metadata: - name: testvolume - spec: - accessModes: - - ReadWriteMany - resources: - requests: - storage: 2Gi - volumeMode: Filesystem -status: - replicas: 2 - readyReplicas: 2 ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: testvolume -spec: - accessModes: - - ReadWriteMany - resources: - requests: - storage: 2Gi - volumeMode: Filesystem diff --git a/tests/e2e/statefulset-features/02-update-volume-claim-storage.yaml b/tests/e2e/statefulset-features/02-update-volume-claim-storage.yaml deleted file mode 100644 index d9ca9a374b..0000000000 --- a/tests/e2e/statefulset-features/02-update-volume-claim-storage.yaml +++ /dev/null @@ -1,34 +0,0 @@ -apiVersion: opentelemetry.io/v1alpha1 -kind: OpenTelemetryCollector -metadata: - name: stateful -spec: - mode: statefulset - replicas: 2 - volumes: - - name: testvolume - volumeMounts: - - name: testvolume - mountPath: /usr/share/testvolume - volumeClaimTemplates: - - metadata: - name: testvolume - spec: - accessModes: [ "ReadWriteMany" ] # change accessMode to trigger statefulset recreation. - resources: - requests: - storage: 2Gi - config: | - receivers: - jaeger: - protocols: - grpc: - processors: - exporters: - debug: - service: - pipelines: - traces: - receivers: [jaeger] - processors: [] - exporters: [debug] diff --git a/tests/e2e/statefulset-features/chainsaw-test.yaml b/tests/e2e/statefulset-features/chainsaw-test.yaml index 78ae2314af..c73d8ae7d2 100755 --- a/tests/e2e/statefulset-features/chainsaw-test.yaml +++ b/tests/e2e/statefulset-features/chainsaw-test.yaml @@ -18,9 +18,3 @@ spec: file: 01-update-volume-claim-templates.yaml - assert: file: 01-assert.yaml - - name: step-02 - try: - - apply: - file: 02-update-volume-claim-storage.yaml - - assert: - file: 02-assert.yaml From 3e77e7285a1617e25bd027286218b782557279a1 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 27 Feb 2024 19:48:19 +0100 Subject: [PATCH 20/26] Fixed Suite Test Signed-off-by: Yuri Sa --- config/manager/kustomization.yaml | 6 ++++++ controllers/builder_test.go | 5 ++++- internal/manifests/collector/ingress.go | 9 ++++----- internal/manifests/collector/ingress_test.go | 3 +++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 5c5f0b84cb..4109813bd5 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,2 +1,8 @@ resources: - manager.yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +images: +- name: controller + newName: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator + newTag: 0.94.0 diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 8dd0bcfa21..624d93176f 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -589,7 +589,10 @@ service: Labels: map[string]string{ "app.kubernetes.io/instance": "test.test", "app.kubernetes.io/managed-by": "opentelemetry-operator", - "app.kubernetes.io/name": "test-ingress", + "app.kubernetes.io/name": "test-collector", + "app.kubernetes.io/component": "opentelemetry-collector", + "app.kubernetes.io/part-of": "opentelemetry", + "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ "something": "true", diff --git a/internal/manifests/collector/ingress.go b/internal/manifests/collector/ingress.go index fecd6d6a92..d46a1e47c2 100644 --- a/internal/manifests/collector/ingress.go +++ b/internal/manifests/collector/ingress.go @@ -25,10 +25,13 @@ import ( "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/adapters" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) func Ingress(params manifests.Params) (*networkingv1.Ingress, error) { + name := naming.Collector(params.OtelCol.Name) + labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter()) if params.OtelCol.Spec.Ingress.Type != v1beta1.IngressTypeNginx { return nil, nil } @@ -58,11 +61,7 @@ func Ingress(params manifests.Params) (*networkingv1.Ingress, error) { Name: naming.Ingress(params.OtelCol.Name), Namespace: params.OtelCol.Namespace, Annotations: params.OtelCol.Spec.Ingress.Annotations, - Labels: map[string]string{ - "app.kubernetes.io/name": naming.Ingress(params.OtelCol.Name), - "app.kubernetes.io/instance": fmt.Sprintf("%s.%s", params.OtelCol.Namespace, params.OtelCol.Name), - "app.kubernetes.io/managed-by": "opentelemetry-operator", - }, + Labels: labels, }, Spec: networkingv1.IngressSpec{ TLS: params.OtelCol.Spec.Ingress.TLS, diff --git a/internal/manifests/collector/ingress_test.go b/internal/manifests/collector/ingress_test.go index 6713472138..374d97c939 100644 --- a/internal/manifests/collector/ingress_test.go +++ b/internal/manifests/collector/ingress_test.go @@ -120,6 +120,9 @@ func TestDesiredIngresses(t *testing.T) { "app.kubernetes.io/name": naming.Ingress(params.OtelCol.Name), "app.kubernetes.io/instance": fmt.Sprintf("%s.%s", params.OtelCol.Namespace, params.OtelCol.Name), "app.kubernetes.io/managed-by": "opentelemetry-operator", + "app.kubernetes.io/component": "opentelemetry-collector", + "app.kubernetes.io/part-of": "opentelemetry", + "app.kubernetes.io/version": "latest", }, }, Spec: networkingv1.IngressSpec{ From 8bd21d58c10b8fb8e4dc1845a73c4902c97526fa Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 27 Feb 2024 20:04:32 +0100 Subject: [PATCH 21/26] Fixed Suite Test Signed-off-by: Yuri Sa --- controllers/builder_test.go | 2 +- internal/manifests/collector/ingress.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 624d93176f..4076ccd463 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -589,7 +589,7 @@ service: Labels: map[string]string{ "app.kubernetes.io/instance": "test.test", "app.kubernetes.io/managed-by": "opentelemetry-operator", - "app.kubernetes.io/name": "test-collector", + "app.kubernetes.io/name": "test-ingress", "app.kubernetes.io/component": "opentelemetry-collector", "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", diff --git a/internal/manifests/collector/ingress.go b/internal/manifests/collector/ingress.go index d46a1e47c2..18c6d0cb6c 100644 --- a/internal/manifests/collector/ingress.go +++ b/internal/manifests/collector/ingress.go @@ -30,7 +30,7 @@ import ( ) func Ingress(params manifests.Params) (*networkingv1.Ingress, error) { - name := naming.Collector(params.OtelCol.Name) + name := naming.Ingress(params.OtelCol.Name) labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter()) if params.OtelCol.Spec.Ingress.Type != v1beta1.IngressTypeNginx { return nil, nil From 20873663b7309eab36b3a33320c5c6f6a2545511 Mon Sep 17 00:00:00 2001 From: Jacob Aronoff Date: Tue, 27 Feb 2024 15:06:20 -0500 Subject: [PATCH 22/26] Add a sleep --- tests/e2e/ingress/chainsaw-test.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/e2e/ingress/chainsaw-test.yaml b/tests/e2e/ingress/chainsaw-test.yaml index 6afd2724d2..8687e36190 100755 --- a/tests/e2e/ingress/chainsaw-test.yaml +++ b/tests/e2e/ingress/chainsaw-test.yaml @@ -17,5 +17,8 @@ spec: try: - apply: file: 01-install.yaml + - try: + - sleep: + duration: 3s - error: file: 01-error.yaml From 7d09dd023d7f8a77996391e3c19fe85ee1b0ff8a Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 28 Feb 2024 10:12:05 +0100 Subject: [PATCH 23/26] Fixed Chainsaw test Signed-off-by: Yuri Sa --- tests/e2e/ingress/chainsaw-test.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/e2e/ingress/chainsaw-test.yaml b/tests/e2e/ingress/chainsaw-test.yaml index 8687e36190..0b99ca7e13 100755 --- a/tests/e2e/ingress/chainsaw-test.yaml +++ b/tests/e2e/ingress/chainsaw-test.yaml @@ -17,8 +17,7 @@ spec: try: - apply: file: 01-install.yaml - - try: - - sleep: - duration: 3s + - sleep: + duration: 5s - error: file: 01-error.yaml From 42469b4b8a8e8db28b8c6d3e3d7d1f729c282410 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 28 Feb 2024 17:42:08 +0100 Subject: [PATCH 24/26] Fixed Chainsaw test Signed-off-by: Yuri Sa --- Makefile | 4 ++-- tests/e2e/ingress/00-assert.yaml | 12 ++++++------ tests/e2e/ingress/00-install.yaml | 4 ++-- tests/e2e/ingress/01-error.yaml | 10 +++++----- ...{01-install.yaml => 01-remove-ingress.yaml} | 5 +++-- tests/e2e/ingress/chainsaw-test.yaml | 18 +++++++++++------- 6 files changed, 29 insertions(+), 24 deletions(-) rename tests/e2e/ingress/{01-install.yaml => 01-remove-ingress.yaml} (86%) diff --git a/Makefile b/Makefile index 929a1b707c..e55295ad22 100644 --- a/Makefile +++ b/Makefile @@ -198,7 +198,7 @@ generate: controller-gen # end-to-tests .PHONY: e2e e2e: chainsaw - $(CHAINSAW) test --test-dir ./tests/e2e + $(CHAINSAW) test --test-dir ./tests/e2e/ingress # end-to-end-test for testing autoscale .PHONY: e2e-autoscale @@ -367,7 +367,7 @@ KUSTOMIZE_VERSION ?= v5.0.3 CONTROLLER_TOOLS_VERSION ?= v0.12.0 GOLANGCI_LINT_VERSION ?= v1.54.0 KIND_VERSION ?= v0.20.0 -CHAINSAW_VERSION ?= v0.1.4 +CHAINSAW_VERSION ?= v0.1.7 .PHONY: install-tools install-tools: kustomize golangci-lint kind controller-gen envtest crdoc kind operator-sdk chainsaw diff --git a/tests/e2e/ingress/00-assert.yaml b/tests/e2e/ingress/00-assert.yaml index 5604513d10..79f736ee79 100644 --- a/tests/e2e/ingress/00-assert.yaml +++ b/tests/e2e/ingress/00-assert.yaml @@ -2,7 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: simplest-collector + name: otel-simplest-collector status: readyReplicas: 1 --- @@ -13,14 +13,14 @@ metadata: something.com: "true" labels: app.kubernetes.io/managed-by: opentelemetry-operator - app.kubernetes.io/name: simplest-ingress - name: simplest-ingress + app.kubernetes.io/name: otel-simplest-ingress + name: otel-simplest-ingress ownerReferences: - apiVersion: opentelemetry.io/v1alpha1 blockOwnerDeletion: true controller: true kind: OpenTelemetryCollector - name: simplest + name: otel-simplest spec: rules: - host: example.com @@ -28,14 +28,14 @@ spec: paths: - backend: service: - name: simplest-collector + name: otel-simplest-collector port: name: otlp-grpc path: /otlp-grpc pathType: Prefix - backend: service: - name: simplest-collector + name: otel-simplest-collector port: name: otlp-http path: /otlp-http diff --git a/tests/e2e/ingress/00-install.yaml b/tests/e2e/ingress/00-install.yaml index a94b434a6c..ce10c55a73 100644 --- a/tests/e2e/ingress/00-install.yaml +++ b/tests/e2e/ingress/00-install.yaml @@ -2,9 +2,9 @@ apiVersion: opentelemetry.io/v1alpha1 kind: OpenTelemetryCollector metadata: - name: simplest + name: otel-simplest spec: - mode: "deployment" + mode: deployment ingress: type: ingress hostname: "example.com" diff --git a/tests/e2e/ingress/01-error.yaml b/tests/e2e/ingress/01-error.yaml index 74e912b97a..e7db9b4f03 100644 --- a/tests/e2e/ingress/01-error.yaml +++ b/tests/e2e/ingress/01-error.yaml @@ -6,14 +6,14 @@ metadata: something.com: "true" labels: app.kubernetes.io/managed-by: opentelemetry-operator - app.kubernetes.io/name: simplest-ingress - name: simplest-ingress + app.kubernetes.io/name: otel-simplest-ingress + name: otel-simplest-ingress ownerReferences: - apiVersion: opentelemetry.io/v1alpha1 blockOwnerDeletion: true controller: true kind: OpenTelemetryCollector - name: simplest + name: otel-simplest spec: rules: - host: example.com @@ -21,14 +21,14 @@ spec: paths: - backend: service: - name: simplest-collector + name: otel-simplest-collector port: name: otlp-grpc path: /otlp-grpc pathType: Prefix - backend: service: - name: simplest-collector + name: otel-simplest-collector port: name: otlp-http path: /otlp-http diff --git a/tests/e2e/ingress/01-install.yaml b/tests/e2e/ingress/01-remove-ingress.yaml similarity index 86% rename from tests/e2e/ingress/01-install.yaml rename to tests/e2e/ingress/01-remove-ingress.yaml index 32416b43bd..4a6f3f637e 100644 --- a/tests/e2e/ingress/01-install.yaml +++ b/tests/e2e/ingress/01-remove-ingress.yaml @@ -2,9 +2,10 @@ apiVersion: opentelemetry.io/v1alpha1 kind: OpenTelemetryCollector metadata: - name: simplest + name: otel-simplest spec: - mode: "deployment" + mode: deployment + ingress: ~ config: | receivers: otlp: diff --git a/tests/e2e/ingress/chainsaw-test.yaml b/tests/e2e/ingress/chainsaw-test.yaml index 0b99ca7e13..e81b82d921 100755 --- a/tests/e2e/ingress/chainsaw-test.yaml +++ b/tests/e2e/ingress/chainsaw-test.yaml @@ -2,9 +2,15 @@ apiVersion: chainsaw.kyverno.io/v1alpha1 kind: Test metadata: - creationTimestamp: null name: ingress spec: + skip: false + concurrent: false + skipDelete: false + timeouts: + apply: 10s + assert: 10s + error: 10s steps: - name: step-00 try: @@ -15,9 +21,7 @@ spec: # Applying the same OpenTelemetryCollector from the previous step, but this time without the spec.ingress, which should inform the controller to delete the ingress resource. So, we should get an error checking if the ingress still exists. - name: step-01 try: - - apply: - file: 01-install.yaml - - sleep: - duration: 5s - - error: - file: 01-error.yaml + - patch: + file: 01-remove-ingress.yaml + - error: + file: 01-error.yaml From 1ffc7ebe8cdcd8b08c0e86e2a354d44954259a60 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 28 Feb 2024 17:45:25 +0100 Subject: [PATCH 25/26] Fixed Chainsaw test Signed-off-by: Yuri Sa --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0526bdbe99..e59b2e571a 100644 --- a/Makefile +++ b/Makefile @@ -198,7 +198,7 @@ generate: controller-gen # end-to-tests .PHONY: e2e e2e: chainsaw - $(CHAINSAW) test --test-dir ./tests/e2e/ingress + $(CHAINSAW) test --test-dir ./tests/e2e # end-to-end-test for testing autoscale .PHONY: e2e-autoscale From ba7c3b2ebd8edeab0e2dda10042e101a8adb70c7 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 28 Feb 2024 17:46:58 +0100 Subject: [PATCH 26/26] Fixed Chainsaw test Signed-off-by: Yuri Sa --- config/manager/kustomization.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 4109813bd5..5c5f0b84cb 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,8 +1,2 @@ resources: - manager.yaml -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -images: -- name: controller - newName: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator - newTag: 0.94.0