From 30d41c9c4b4451ef051962dd3e35d8f66103f615 Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Tue, 26 Sep 2023 09:25:44 +0200 Subject: [PATCH 1/9] feat: Bump lowest supported k8s version to 1.23 Signed-off-by: Jorge Turrado --- .chloggen/get-rid-of-autoscaling-v2beta2.yaml | 20 ++ .github/workflows/e2e.yaml | 72 ++--- .github/workflows/scorecard.yaml | 2 +- README.md | 1 + config/manager/kustomization.yaml | 5 + .../opentelemetrycollector_controller.go | 8 +- .../opentelemetrycollector_controller_test.go | 8 - controllers/reconcile_test.go | 48 +--- controllers/suite_test.go | 14 +- internal/config/main.go | 46 ---- internal/config/main_test.go | 14 - internal/config/options.go | 1 - .../collector/horizontalpodautoscaler.go | 248 +++--------------- .../collector/horizontalpodautoscaler_test.go | 174 ++---------- kind-1.19.yaml | 18 -- kind-1.20.yaml | 18 -- kind-1.21.yaml | 18 -- kind-1.22.yaml | 18 -- pkg/autodetect/main.go | 62 ----- pkg/autodetect/main_test.go | 12 - tests/e2e-autoscale/autoscale/00-assert.yaml | 73 ++++++ tests/e2e-autoscale/autoscale/01-assert.yaml | 36 +++ .../01-check-simplest-collector-hpa.yaml | 4 - tests/e2e-autoscale/autoscale/01-install.yaml | 44 ++++ .../{05-assert.yaml => 02-assert.yaml} | 2 +- ...implest-set-utilization-collector-hpa.yaml | 4 - tests/e2e-autoscale/autoscale/02-install.yaml | 61 ++--- tests/e2e-autoscale/autoscale/03-assert.yaml | 2 +- .../{04-delete.yaml => 03-delete.yaml} | 0 tests/e2e-autoscale/autoscale/03-install.yaml | 21 -- ...fy-simplest-set-collector-hpa-metrics.yaml | 4 - .../cmd/verify/wait-and-validate-metrics.go | 187 ------------- .../autoscale/wait-until-hpa-ready.go | 121 --------- 33 files changed, 300 insertions(+), 1066 deletions(-) create mode 100644 .chloggen/get-rid-of-autoscaling-v2beta2.yaml delete mode 100644 kind-1.19.yaml delete mode 100644 kind-1.20.yaml delete mode 100644 kind-1.21.yaml delete mode 100644 kind-1.22.yaml create mode 100644 tests/e2e-autoscale/autoscale/01-assert.yaml delete mode 100644 tests/e2e-autoscale/autoscale/01-check-simplest-collector-hpa.yaml create mode 100644 tests/e2e-autoscale/autoscale/01-install.yaml rename tests/e2e-autoscale/autoscale/{05-assert.yaml => 02-assert.yaml} (88%) delete mode 100644 tests/e2e-autoscale/autoscale/02-check-simplest-set-utilization-collector-hpa.yaml rename tests/e2e-autoscale/autoscale/{04-delete.yaml => 03-delete.yaml} (100%) delete mode 100644 tests/e2e-autoscale/autoscale/03-install.yaml delete mode 100644 tests/e2e-autoscale/autoscale/03-verify-simplest-set-collector-hpa-metrics.yaml delete mode 100644 tests/e2e-autoscale/autoscale/cmd/verify/wait-and-validate-metrics.go delete mode 100644 tests/e2e-autoscale/autoscale/wait-until-hpa-ready.go diff --git a/.chloggen/get-rid-of-autoscaling-v2beta2.yaml b/.chloggen/get-rid-of-autoscaling-v2beta2.yaml new file mode 100644 index 0000000000..554ccd15e4 --- /dev/null +++ b/.chloggen/get-rid-of-autoscaling-v2beta2.yaml @@ -0,0 +1,20 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# 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: Get rid of autoscaling/v2beta2 + +# One or more tracking issues related to the change +issues: + - 2145 + +# (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: | + Kubernetes 1.23 is the minimum available version everywhere after 1.22 deprecation, + due to it, the minimum required version has been updated to it, dropping support for + autoscaling/v2beta2 diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 0938393168..c9f87740f1 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -2,9 +2,9 @@ name: "End-to-end tests" on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -12,7 +12,7 @@ concurrency: env: CURRENT_KIND_VERSION: 0.20.0 - LEGACY_KIND_VERSION: 0.17.0 # for K8s versions latest kind doesn't support anymore + LEGACY_KIND_VERSION: 0.17.0 # for K8s versions latest kind doesn't support anymore jobs: e2e-tests: @@ -21,46 +21,46 @@ jobs: strategy: fail-fast: false matrix: - # The e2e tests are run on the lowest and highest supported k8s version. - # All Kubernetes version in between expose the same APIs, hence the operator - # should be compatible with them. - kube-version: - - "1.19" - - "1.28" - group: - - e2e - - e2e-instrumentation - - e2e-upgrade - - e2e-prometheuscr - - e2e-autoscale + # The e2e tests are run on the lowest and highest supported k8s version. + # All Kubernetes version in between expose the same APIs, hence the operator + # should be compatible with them. + kube-version: + - "1.23" + - "1.28" + group: + - e2e + - e2e-instrumentation + - e2e-upgrade + - e2e-prometheuscr + - e2e-autoscale steps: - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "~1.21.1" + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "~1.21.1" - - name: Setup kind - env: - KIND_VERSION: ${{ matrix.kube_version >= 1.21 && env.KIND_VERSION || env.LEGACY_KIND_VERSION }} - run: go install sigs.k8s.io/kind@v${KIND_VERSION} + - name: Setup kind + env: + KIND_VERSION: ${{ matrix.kube_version >= 1.21 && env.KIND_VERSION || env.LEGACY_KIND_VERSION }} + run: go install sigs.k8s.io/kind@v${KIND_VERSION} - - name: Check out code into the Go module directory - uses: actions/checkout@v4 + - name: Check out code into the Go module directory + uses: actions/checkout@v4 - - name: "install kuttl" - run: ./hack/install-kuttl.sh + - name: "install kuttl" + run: ./hack/install-kuttl.sh - - name: "run tests" - env: - KUBE_VERSION: ${{ matrix.kube-version }} - run: make prepare-e2e ${{ matrix.group }} KUBE_VERSION=$KUBE_VERSION VERSION=e2e + - name: "run tests" + env: + KUBE_VERSION: ${{ matrix.kube-version }} + run: make prepare-e2e ${{ matrix.group }} KUBE_VERSION=$KUBE_VERSION VERSION=e2e - - name: "log operator if failed" - if: ${{ failure() }} - env: - KUBE_VERSION: ${{ matrix.kube-version }} - run: make e2e-log-operator KUBE_VERSION=$KUBE_VERSION + - name: "log operator if failed" + if: ${{ failure() }} + env: + KUBE_VERSION: ${{ matrix.kube-version }} + run: make e2e-log-operator KUBE_VERSION=$KUBE_VERSION e2e-tests-check: runs-on: ubuntu-22.04 diff --git a/.github/workflows/scorecard.yaml b/.github/workflows/scorecard.yaml index 6090e640fa..19e2b124cf 100644 --- a/.github/workflows/scorecard.yaml +++ b/.github/workflows/scorecard.yaml @@ -21,7 +21,7 @@ jobs: strategy: matrix: kube-version: - - "1.19" + - "1.23" - "1.28" steps: diff --git a/README.md b/README.md index 13042200ad..ee101d2c5a 100644 --- a/README.md +++ b/README.md @@ -594,6 +594,7 @@ The OpenTelemetry Operator *might* work on versions outside of the given range, | OpenTelemetry Operator | Kubernetes | Cert-Manager | |------------------------|----------------------|---------------------| +| v0.86.0 | v1.23 to v1.28 | v1 | | v0.85.0 | v1.19 to v1.28 | v1 | | v0.84.0 | v1.19 to v1.28 | v1 | | v0.83.0 | v1.19 to v1.27 | v1 | diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 5c5f0b84cb..40c0846afa 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,2 +1,7 @@ resources: - manager.yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +images: +- name: controller + newName: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator diff --git a/controllers/opentelemetrycollector_controller.go b/controllers/opentelemetrycollector_controller.go index 65caeb303c..4cde37c461 100644 --- a/controllers/opentelemetrycollector_controller.go +++ b/controllers/opentelemetrycollector_controller.go @@ -25,7 +25,6 @@ import ( monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" appsv1 "k8s.io/api/apps/v1" autoscalingv2 "k8s.io/api/autoscaling/v2" - autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -304,12 +303,7 @@ func (r *OpenTelemetryCollectorReconciler) SetupWithManager(mgr ctrl.Manager) er builder.Owns(&monitoringv1.ServiceMonitor{}) } - autoscalingVersion := r.config.AutoscalingVersion() - if autoscalingVersion == autodetect.AutoscalingVersionV2 { - builder = builder.Owns(&autoscalingv2.HorizontalPodAutoscaler{}) - } else { - builder = builder.Owns(&autoscalingv2beta2.HorizontalPodAutoscaler{}) - } + builder = builder.Owns(&autoscalingv2.HorizontalPodAutoscaler{}) return builder.Complete(r) } diff --git a/controllers/opentelemetrycollector_controller_test.go b/controllers/opentelemetrycollector_controller_test.go index 27441d45f4..261115c088 100644 --- a/controllers/opentelemetrycollector_controller_test.go +++ b/controllers/opentelemetrycollector_controller_test.go @@ -44,9 +44,6 @@ import ( var logger = logf.Log.WithName("unit-tests") var mockAutoDetector = &mockAutoDetect{ - HPAVersionFunc: func() (autodetect.AutoscalingVersion, error) { - return autodetect.AutoscalingVersionV2Beta2, nil - }, OpenShiftRoutesAvailabilityFunc: func() (autodetect.OpenShiftRoutesAvailability, error) { return autodetect.OpenShiftRoutesAvailable, nil }, @@ -336,11 +333,6 @@ var _ autodetect.AutoDetect = (*mockAutoDetect)(nil) type mockAutoDetect struct { OpenShiftRoutesAvailabilityFunc func() (autodetect.OpenShiftRoutesAvailability, error) - HPAVersionFunc func() (autodetect.AutoscalingVersion, error) -} - -func (m *mockAutoDetect) HPAVersion() (autodetect.AutoscalingVersion, error) { - return m.HPAVersionFunc() } func (m *mockAutoDetect) OpenShiftRoutesAvailability() (autodetect.OpenShiftRoutesAvailability, error) { diff --git a/controllers/reconcile_test.go b/controllers/reconcile_test.go index 3a87607e45..03ca153b1d 100644 --- a/controllers/reconcile_test.go +++ b/controllers/reconcile_test.go @@ -38,7 +38,6 @@ import ( "github.com/open-telemetry/opentelemetry-operator/internal/manifests" ta "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters" "github.com/open-telemetry/opentelemetry-operator/internal/naming" - "github.com/open-telemetry/opentelemetry-operator/pkg/autodetect" ) const ( @@ -276,54 +275,11 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { }, }, }, - { - name: "hpa v2beta2 deployment collector", - args: args{ - params: paramsWithHPA(autodetect.AutoscalingVersionV2Beta2, 3, 5), - updates: []manifests.Params{paramsWithHPA(autodetect.AutoscalingVersionV2Beta2, 1, 9)}, - }, - want: []want{ - { - result: controllerruntime.Result{}, - checks: []check{ - func(t *testing.T, appliedInstance v1alpha1.OpenTelemetryCollector) { - actual := autoscalingv2beta2.HorizontalPodAutoscaler{} - exists, hpaErr := populateObjectIfExists(t, &actual, namespacedObjectName(appliedInstance, naming.HorizontalPodAutoscaler)) - 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, appliedInstance v1alpha1.OpenTelemetryCollector) { - actual := autoscalingv2beta2.HorizontalPodAutoscaler{} - exists, hpaErr := populateObjectIfExists(t, &actual, namespacedObjectName(appliedInstance, naming.HorizontalPodAutoscaler)) - 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(1), *actual.Spec.MinReplicas) - assert.Equal(t, int32(9), actual.Spec.MaxReplicas) - assert.True(t, exists) - }, - }, - wantErr: assert.NoError, - validateErr: assert.NoError, - }, - }, - }, { name: "hpa v2 deployment collector", args: args{ - params: paramsWithHPA(autodetect.AutoscalingVersionV2, 3, 5), - updates: []manifests.Params{paramsWithHPA(autodetect.AutoscalingVersionV2, 1, 9)}, + params: paramsWithHPA(3, 5), + updates: []manifests.Params{paramsWithHPA(1, 9)}, }, want: []want{ { diff --git a/controllers/suite_test.go b/controllers/suite_test.go index bf9bbc1efe..d44eb5f2bd 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -49,7 +49,6 @@ import ( "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/testdata" - "github.com/open-telemetry/opentelemetry-operator/pkg/autodetect" // +kubebuilder:scaffold:imports ) @@ -277,7 +276,7 @@ func newParams(taContainerImage string, file string) (manifests.Params, error) { }, nil } -func paramsWithHPA(autoscalingVersion autodetect.AutoscalingVersion, minReps, maxReps int32) manifests.Params { +func paramsWithHPA(minReps, maxReps int32) manifests.Params { configYAML, err := os.ReadFile("testdata/test.yaml") if err != nil { fmt.Printf("Error getting yaml file: %v", err) @@ -285,16 +284,7 @@ func paramsWithHPA(autoscalingVersion autodetect.AutoscalingVersion, minReps, ma cpuUtilization := int32(90) - mockAutoDetector := &mockAutoDetect{ - HPAVersionFunc: func() (autodetect.AutoscalingVersion, error) { - return autoscalingVersion, nil - }, - } - configuration := config.New(config.WithAutoDetect(mockAutoDetector), config.WithCollectorImage(defaultCollectorImage), config.WithTargetAllocatorImage(defaultTaAllocationImage)) - err = configuration.AutoDetect() - if err != nil { - logger.Error(err, "configuration.autodetect failed") - } + configuration := config.New(config.WithCollectorImage(defaultCollectorImage), config.WithTargetAllocatorImage(defaultTaAllocationImage)) return manifests.Params{ Config: configuration, diff --git a/internal/config/main.go b/internal/config/main.go index 225f590f69..64d2beec8a 100644 --- a/internal/config/main.go +++ b/internal/config/main.go @@ -51,7 +51,6 @@ type Config struct { labelsFilter []string openshiftRoutes openshiftRoutesStore autoDetectFrequency time.Duration - hpaVersion hpaVersionStore } // New constructs a new configuration based on the given options. @@ -63,7 +62,6 @@ func New(opts ...Option) Config { targetAllocatorConfigMapEntry: defaultTargetAllocatorConfigMapEntry, logger: logf.Log.WithName("config"), openshiftRoutes: newOpenShiftRoutesWrapper(), - hpaVersion: newHPAVersionWrapper(), version: version.Get(), onOpenShiftRoutesChange: newOnChange(), } @@ -81,7 +79,6 @@ func New(opts ...Option) Config { targetAllocatorConfigMapEntry: o.targetAllocatorConfigMapEntry, logger: o.logger, openshiftRoutes: o.openshiftRoutes, - hpaVersion: o.hpaVersion, onOpenShiftRoutesChange: o.onOpenShiftRoutesChange, autoInstrumentationJavaImage: o.autoInstrumentationJavaImage, autoInstrumentationNodeJSImage: o.autoInstrumentationNodeJSImage, @@ -129,15 +126,6 @@ func (c *Config) AutoDetect() error { } } - hpaV, err := c.autoDetect.HPAVersion() - if err != nil { - return err - } - if c.hpaVersion.Get() != hpaV { - c.logger.V(1).Info("HPA version detected", "version", hpaV) - c.hpaVersion.Set(hpaV) - } - return nil } @@ -166,11 +154,6 @@ func (c *Config) OpenShiftRoutes() autodetect.OpenShiftRoutesAvailability { return c.openshiftRoutes.Get() } -// AutoscalingVersion represents the preferred version of autoscaling. -func (c *Config) AutoscalingVersion() autodetect.AutoscalingVersion { - return c.hpaVersion.Get() -} - // AutoInstrumentationJavaImage returns OpenTelemetry Java auto-instrumentation container image. func (c *Config) AutoInstrumentationJavaImage() string { return c.autoInstrumentationJavaImage @@ -212,35 +195,6 @@ func (c *Config) RegisterOpenShiftRoutesChangeCallback(f func() error) { c.onOpenShiftRoutesChange.Register(f) } -type hpaVersionStore interface { - Set(hpaV autodetect.AutoscalingVersion) - Get() autodetect.AutoscalingVersion -} - -func newHPAVersionWrapper() hpaVersionStore { - return &hpaVersionWrapper{ - current: autodetect.AutoscalingVersionUnknown, - } -} - -type hpaVersionWrapper struct { - mu sync.Mutex - current autodetect.AutoscalingVersion -} - -func (p *hpaVersionWrapper) Set(hpaV autodetect.AutoscalingVersion) { - p.mu.Lock() - p.current = hpaV - p.mu.Unlock() -} - -func (p *hpaVersionWrapper) Get() autodetect.AutoscalingVersion { - p.mu.Lock() - hpaV := p.current - p.mu.Unlock() - return hpaV -} - type openshiftRoutesStore interface { Set(ora autodetect.OpenShiftRoutesAvailability) Get() autodetect.OpenShiftRoutesAvailability diff --git a/internal/config/main_test.go b/internal/config/main_test.go index e6085ead66..7bda3f64cd 100644 --- a/internal/config/main_test.go +++ b/internal/config/main_test.go @@ -38,7 +38,6 @@ func TestNewConfig(t *testing.T) { assert.Equal(t, "some-image", cfg.CollectorImage()) assert.Equal(t, "some-config.yaml", cfg.CollectorConfigMapEntry()) assert.Equal(t, autodetect.OpenShiftRoutesNotAvailable, cfg.OpenShiftRoutes()) - assert.Equal(t, autodetect.AutoscalingVersionUnknown, cfg.AutoscalingVersion()) } func TestOnPlatformChangeCallback(t *testing.T) { @@ -78,10 +77,6 @@ func TestAutoDetectInBackground(t *testing.T) { wg.Done() return autodetect.OpenShiftRoutesNotAvailable, nil }, - HPAVersionFunc: func() (autodetect.AutoscalingVersion, error) { - wg.Done() - return autodetect.AutoscalingVersionV2, nil - }, } cfg := config.New( config.WithAutoDetect(mock), @@ -90,7 +85,6 @@ func TestAutoDetectInBackground(t *testing.T) { // sanity check require.Equal(t, autodetect.OpenShiftRoutesNotAvailable, cfg.OpenShiftRoutes()) - require.Equal(t, autodetect.AutoscalingVersionUnknown, cfg.AutoscalingVersion()) // test err := cfg.StartAutoDetect() @@ -104,14 +98,6 @@ var _ autodetect.AutoDetect = (*mockAutoDetect)(nil) type mockAutoDetect struct { OpenShiftRoutesAvailabilityFunc func() (autodetect.OpenShiftRoutesAvailability, error) - HPAVersionFunc func() (autodetect.AutoscalingVersion, error) -} - -func (m *mockAutoDetect) HPAVersion() (autodetect.AutoscalingVersion, error) { - if m.HPAVersionFunc != nil { - return m.HPAVersionFunc() - } - return autodetect.DefaultAutoscalingVersion, nil } func (m *mockAutoDetect) OpenShiftRoutesAvailability() (autodetect.OpenShiftRoutesAvailability, error) { diff --git a/internal/config/options.go b/internal/config/options.go index 0219681414..13d88b508a 100644 --- a/internal/config/options.go +++ b/internal/config/options.go @@ -46,7 +46,6 @@ type options struct { onOpenShiftRoutesChange changeHandler labelsFilter []string openshiftRoutes openshiftRoutesStore - hpaVersion hpaVersionStore autoDetectFrequency time.Duration } diff --git a/internal/manifests/collector/horizontalpodautoscaler.go b/internal/manifests/collector/horizontalpodautoscaler.go index c06a16e22e..f809434141 100644 --- a/internal/manifests/collector/horizontalpodautoscaler.go +++ b/internal/manifests/collector/horizontalpodautoscaler.go @@ -17,7 +17,6 @@ package collector import ( "github.com/go-logr/logr" autoscalingv2 "k8s.io/api/autoscaling/v2" - autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -25,7 +24,6 @@ import ( "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/naming" - "github.com/open-telemetry/opentelemetry-operator/pkg/autodetect" ) func HorizontalPodAutoscaler(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemetryCollector) client.Object { @@ -46,7 +44,6 @@ func HorizontalPodAutoscaler(cfg config.Config, logger logr.Logger, otelcol v1al logger.Info("hpa field is unset in Spec, skipping autoscaler creation") return nil } - autoscalingVersion := cfg.AutoscalingVersion() if otelcol.Spec.Autoscaler.MaxReplicas == nil { otelcol.Spec.Autoscaler.MaxReplicas = otelcol.Spec.MaxReplicas @@ -60,225 +57,64 @@ func HorizontalPodAutoscaler(cfg config.Config, logger logr.Logger, otelcol v1al } } - if autoscalingVersion == autodetect.AutoscalingVersionV2Beta2 { - metrics := []autoscalingv2beta2.MetricSpec{} + metrics := []autoscalingv2.MetricSpec{} - if otelcol.Spec.Autoscaler.TargetMemoryUtilization != nil { - utilizationTarget := autoscalingv2beta2.MetricSpec{ - Type: autoscalingv2beta2.ResourceMetricSourceType, - Resource: &autoscalingv2beta2.ResourceMetricSource{ - Name: corev1.ResourceMemory, - Target: autoscalingv2beta2.MetricTarget{ - Type: autoscalingv2beta2.UtilizationMetricType, - AverageUtilization: otelcol.Spec.Autoscaler.TargetMemoryUtilization, - }, + if otelcol.Spec.Autoscaler.TargetMemoryUtilization != nil { + utilizationTarget := autoscalingv2.MetricSpec{ + Type: autoscalingv2.ResourceMetricSourceType, + Resource: &autoscalingv2.ResourceMetricSource{ + Name: corev1.ResourceMemory, + Target: autoscalingv2.MetricTarget{ + Type: autoscalingv2.UtilizationMetricType, + AverageUtilization: otelcol.Spec.Autoscaler.TargetMemoryUtilization, }, - } - metrics = append(metrics, utilizationTarget) + }, } + metrics = append(metrics, utilizationTarget) + } - targetCPUUtilization := autoscalingv2beta2.MetricSpec{ - Type: autoscalingv2beta2.ResourceMetricSourceType, - Resource: &autoscalingv2beta2.ResourceMetricSource{ + if otelcol.Spec.Autoscaler.TargetCPUUtilization != nil { + targetCPUUtilization := autoscalingv2.MetricSpec{ + Type: autoscalingv2.ResourceMetricSourceType, + Resource: &autoscalingv2.ResourceMetricSource{ Name: corev1.ResourceCPU, - Target: autoscalingv2beta2.MetricTarget{ - Type: autoscalingv2beta2.UtilizationMetricType, + Target: autoscalingv2.MetricTarget{ + Type: autoscalingv2.UtilizationMetricType, AverageUtilization: otelcol.Spec.Autoscaler.TargetCPUUtilization, }, }, } metrics = append(metrics, targetCPUUtilization) - - autoscaler := autoscalingv2beta2.HorizontalPodAutoscaler{ - ObjectMeta: objectMeta, - Spec: autoscalingv2beta2.HorizontalPodAutoscalerSpec{ - ScaleTargetRef: autoscalingv2beta2.CrossVersionObjectReference{ - APIVersion: v1alpha1.GroupVersion.String(), - Kind: "OpenTelemetryCollector", - Name: naming.OpenTelemetryCollector(otelcol.Name), - }, - MinReplicas: otelcol.Spec.Autoscaler.MinReplicas, - MaxReplicas: *otelcol.Spec.Autoscaler.MaxReplicas, - Metrics: metrics, - }, - } - - if otelcol.Spec.Autoscaler.Behavior != nil { - behavior := ConvertToV2beta2Behavior(*otelcol.Spec.Autoscaler.Behavior) - autoscaler.Spec.Behavior = &behavior - } - - // check for custom metrics - if len(otelcol.Spec.Autoscaler.Metrics) > 0 { - metrics := ConvertToV2Beta2PodMetrics(otelcol.Spec.Autoscaler.Metrics) - autoscaler.Spec.Metrics = append(autoscaler.Spec.Metrics, metrics...) - } - - result = &autoscaler - } else { - metrics := []autoscalingv2.MetricSpec{} - - if otelcol.Spec.Autoscaler.TargetMemoryUtilization != nil { - utilizationTarget := autoscalingv2.MetricSpec{ - Type: autoscalingv2.ResourceMetricSourceType, - Resource: &autoscalingv2.ResourceMetricSource{ - Name: corev1.ResourceMemory, - Target: autoscalingv2.MetricTarget{ - Type: autoscalingv2.UtilizationMetricType, - AverageUtilization: otelcol.Spec.Autoscaler.TargetMemoryUtilization, - }, - }, - } - metrics = append(metrics, utilizationTarget) - } - - if otelcol.Spec.Autoscaler.TargetCPUUtilization != nil { - targetCPUUtilization := autoscalingv2.MetricSpec{ - Type: autoscalingv2.ResourceMetricSourceType, - Resource: &autoscalingv2.ResourceMetricSource{ - Name: corev1.ResourceCPU, - Target: autoscalingv2.MetricTarget{ - Type: autoscalingv2.UtilizationMetricType, - AverageUtilization: otelcol.Spec.Autoscaler.TargetCPUUtilization, - }, - }, - } - metrics = append(metrics, targetCPUUtilization) - } - - autoscaler := autoscalingv2.HorizontalPodAutoscaler{ - ObjectMeta: objectMeta, - Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ - ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ - APIVersion: v1alpha1.GroupVersion.String(), - Kind: "OpenTelemetryCollector", - Name: naming.OpenTelemetryCollector(otelcol.Name), - }, - MinReplicas: otelcol.Spec.Autoscaler.MinReplicas, - MaxReplicas: *otelcol.Spec.Autoscaler.MaxReplicas, - Metrics: metrics, - }, - } - if otelcol.Spec.Autoscaler.Behavior != nil { - autoscaler.Spec.Behavior = otelcol.Spec.Autoscaler.Behavior - } - - // convert from v1alpha1.MetricSpec into a autoscalingv2.MetricSpec. - for _, metric := range otelcol.Spec.Autoscaler.Metrics { - if metric.Type == autoscalingv2.PodsMetricSourceType { - v2metric := autoscalingv2.MetricSpec{ - Type: metric.Type, - Pods: metric.Pods, - } - autoscaler.Spec.Metrics = append(autoscaler.Spec.Metrics, v2metric) - } // pod metrics - } - result = &autoscaler } - return result -} - -func ConvertToV2Beta2PodMetrics(v2metrics []v1alpha1.MetricSpec) []autoscalingv2beta2.MetricSpec { - metrics := make([]autoscalingv2beta2.MetricSpec, len(v2metrics)) - - for i, v2metric := range v2metrics { - metrics[i].Type = autoscalingv2beta2.MetricSourceType(v2metric.Type) - if v2metric.Pods != nil { - metrics[i].Pods = &autoscalingv2beta2.PodsMetricSource{ - Metric: autoscalingv2beta2.MetricIdentifier{ - Name: v2metric.Pods.Metric.Name, - Selector: v2metric.Pods.Metric.Selector, - }, - Target: autoscalingv2beta2.MetricTarget{ - Type: autoscalingv2beta2.MetricTargetType(v2metric.Pods.Target.Type), - AverageValue: v2metric.Pods.Target.AverageValue, - }, - } - } + autoscaler := autoscalingv2.HorizontalPodAutoscaler{ + ObjectMeta: objectMeta, + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ + APIVersion: v1alpha1.GroupVersion.String(), + Kind: "OpenTelemetryCollector", + Name: naming.OpenTelemetryCollector(otelcol.Name), + }, + MinReplicas: otelcol.Spec.Autoscaler.MinReplicas, + MaxReplicas: *otelcol.Spec.Autoscaler.MaxReplicas, + Metrics: metrics, + }, } - - return metrics -} - -// Create a v2beta2 HorizontalPodAutoscalerBehavior from a v2 instance. -func ConvertToV2beta2Behavior(v2behavior autoscalingv2.HorizontalPodAutoscalerBehavior) autoscalingv2beta2.HorizontalPodAutoscalerBehavior { - behavior := &autoscalingv2beta2.HorizontalPodAutoscalerBehavior{} - - if v2behavior.ScaleUp != nil { - scaleUpRules := &autoscalingv2beta2.HPAScalingRules{} - scaleUpTime := *v2behavior.ScaleUp.StabilizationWindowSeconds - scaleUpRules.StabilizationWindowSeconds = &scaleUpTime - - if v2behavior.ScaleUp.SelectPolicy != nil { - scaleUpSelectPolicy := ConvertToV2Beta2SelectPolicy(*v2behavior.ScaleUp.SelectPolicy) - scaleUpRules.SelectPolicy = &scaleUpSelectPolicy - } - if v2behavior.ScaleUp.Policies != nil { - scaleUpPolicies := []autoscalingv2beta2.HPAScalingPolicy{} - for _, policy := range v2behavior.ScaleUp.Policies { - v2beta2policy := ConvertToV2Beta2HPAScalingPolicy(policy) - scaleUpPolicies = append(scaleUpPolicies, v2beta2policy) - } - scaleUpRules.Policies = scaleUpPolicies - } - - behavior.ScaleUp = scaleUpRules + if otelcol.Spec.Autoscaler.Behavior != nil { + autoscaler.Spec.Behavior = otelcol.Spec.Autoscaler.Behavior } - if v2behavior.ScaleDown != nil { - scaleDownRules := &autoscalingv2beta2.HPAScalingRules{} - scaleDownTime := *v2behavior.ScaleDown.StabilizationWindowSeconds - scaleDownRules.StabilizationWindowSeconds = &scaleDownTime - - if v2behavior.ScaleDown.SelectPolicy != nil { - scaleDownSelectPolicy := ConvertToV2Beta2SelectPolicy(*v2behavior.ScaleDown.SelectPolicy) - scaleDownRules.SelectPolicy = &scaleDownSelectPolicy - } - if v2behavior.ScaleDown.Policies != nil { - ScaleDownPolicies := []autoscalingv2beta2.HPAScalingPolicy{} - for _, policy := range v2behavior.ScaleDown.Policies { - v2beta2policy := ConvertToV2Beta2HPAScalingPolicy(policy) - ScaleDownPolicies = append(ScaleDownPolicies, v2beta2policy) + // convert from v1alpha1.MetricSpec into a autoscalingv2.MetricSpec. + for _, metric := range otelcol.Spec.Autoscaler.Metrics { + if metric.Type == autoscalingv2.PodsMetricSourceType { + v2metric := autoscalingv2.MetricSpec{ + Type: metric.Type, + Pods: metric.Pods, } - scaleDownRules.Policies = ScaleDownPolicies - } - - behavior.ScaleDown = scaleDownRules - } - - return *behavior -} - -func ConvertToV2Beta2HPAScalingPolicy(v2policy autoscalingv2.HPAScalingPolicy) autoscalingv2beta2.HPAScalingPolicy { - v2beta2Policy := &autoscalingv2beta2.HPAScalingPolicy{ - Value: v2policy.Value, - PeriodSeconds: v2policy.PeriodSeconds, + autoscaler.Spec.Metrics = append(autoscaler.Spec.Metrics, v2metric) + } // pod metrics } + result = &autoscaler - switch v2policy.Type { - case autoscalingv2.PodsScalingPolicy: - v2beta2Policy.Type = autoscalingv2beta2.PodsScalingPolicy - case autoscalingv2.PercentScalingPolicy: - v2beta2Policy.Type = autoscalingv2beta2.PercentScalingPolicy - } - - return *v2beta2Policy -} - -func ConvertToV2Beta2SelectPolicy(scalingPolicy autoscalingv2.ScalingPolicySelect) autoscalingv2beta2.ScalingPolicySelect { - max := autoscalingv2beta2.MaxPolicySelect - min := autoscalingv2beta2.MinPolicySelect - disabled := autoscalingv2beta2.DisabledPolicySelect - - switch scalingPolicy { - case autoscalingv2.MaxChangePolicySelect: - return max - case autoscalingv2.MinChangePolicySelect: - return min - case autoscalingv2.DisabledPolicySelect: - return disabled - } - - return disabled + return result } diff --git a/internal/manifests/collector/horizontalpodautoscaler_test.go b/internal/manifests/collector/horizontalpodautoscaler_test.go index 294ab16a7b..282271c62f 100644 --- a/internal/manifests/collector/horizontalpodautoscaler_test.go +++ b/internal/manifests/collector/horizontalpodautoscaler_test.go @@ -19,25 +19,20 @@ import ( "github.com/stretchr/testify/assert" autoscalingv2 "k8s.io/api/autoscaling/v2" - autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2" corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/config" . "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector" - "github.com/open-telemetry/opentelemetry-operator/pkg/autodetect" ) func TestHPA(t *testing.T) { type test struct { - name string - autoscalingVersion autodetect.AutoscalingVersion + name string } - v2Test := test{autodetect.AutoscalingVersionV2.String(), autodetect.AutoscalingVersionV2} - v2beta2Test := test{autodetect.AutoscalingVersionV2Beta2.String(), autodetect.AutoscalingVersionV2Beta2} - tests := []test{v2Test, v2beta2Test} + v2Test := test{} + tests := []test{v2Test} var minReplicas int32 = 3 var maxReplicas int32 = 5 @@ -76,47 +71,23 @@ func TestHPA(t *testing.T) { for _, otelcol := range otelcols { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - mockAutoDetector := &mockAutoDetect{ - HPAVersionFunc: func() (autodetect.AutoscalingVersion, error) { - return test.autoscalingVersion, nil - }, - } - configuration := config.New(config.WithAutoDetect(mockAutoDetector)) - err := configuration.AutoDetect() - assert.NoError(t, err) + configuration := config.New() raw := HorizontalPodAutoscaler(configuration, logger, otelcol) - if configuration.AutoscalingVersion() == autodetect.AutoscalingVersionV2Beta2 { - hpa := raw.(*autoscalingv2beta2.HorizontalPodAutoscaler) - - // verify - assert.Equal(t, "my-instance-collector", hpa.Name) - assert.Equal(t, "my-instance-collector", hpa.Labels["app.kubernetes.io/name"]) - assert.Equal(t, int32(3), *hpa.Spec.MinReplicas) - assert.Equal(t, int32(5), hpa.Spec.MaxReplicas) - for _, metric := range hpa.Spec.Metrics { - if metric.Resource.Name == corev1.ResourceCPU { - assert.Equal(t, cpuUtilization, *metric.Resource.Target.AverageUtilization) - } else if metric.Resource.Name == corev1.ResourceMemory { - assert.Equal(t, memoryUtilization, *metric.Resource.Target.AverageUtilization) - } - } - } else { - hpa := raw.(*autoscalingv2.HorizontalPodAutoscaler) + hpa := raw.(*autoscalingv2.HorizontalPodAutoscaler) - // verify - assert.Equal(t, "my-instance-collector", hpa.Name) - assert.Equal(t, "my-instance-collector", hpa.Labels["app.kubernetes.io/name"]) - assert.Equal(t, int32(3), *hpa.Spec.MinReplicas) - assert.Equal(t, int32(5), hpa.Spec.MaxReplicas) - assert.Equal(t, 2, len(hpa.Spec.Metrics)) + // verify + assert.Equal(t, "my-instance-collector", hpa.Name) + assert.Equal(t, "my-instance-collector", hpa.Labels["app.kubernetes.io/name"]) + assert.Equal(t, int32(3), *hpa.Spec.MinReplicas) + assert.Equal(t, int32(5), hpa.Spec.MaxReplicas) + assert.Equal(t, 2, len(hpa.Spec.Metrics)) - for _, metric := range hpa.Spec.Metrics { - if metric.Resource.Name == corev1.ResourceCPU { - assert.Equal(t, cpuUtilization, *metric.Resource.Target.AverageUtilization) - } else if metric.Resource.Name == corev1.ResourceMemory { - assert.Equal(t, memoryUtilization, *metric.Resource.Target.AverageUtilization) - } + for _, metric := range hpa.Spec.Metrics { + if metric.Resource.Name == corev1.ResourceCPU { + assert.Equal(t, cpuUtilization, *metric.Resource.Target.AverageUtilization) + } else if metric.Resource.Name == corev1.ResourceMemory { + assert.Equal(t, memoryUtilization, *metric.Resource.Target.AverageUtilization) } } }) @@ -124,116 +95,3 @@ func TestHPA(t *testing.T) { } } - -func TestConvertToV2Beta2PodMetrics(t *testing.T) { - expectedValues := []int64{int64(10), int64(20)} - expectedNames := []string{"custom1", "custom2"} - - v2metrics := []v1alpha1.MetricSpec{ - { - Type: autoscalingv2.PodsMetricSourceType, - Pods: &autoscalingv2.PodsMetricSource{ - Metric: autoscalingv2.MetricIdentifier{ - Name: "custom1", - }, - Target: autoscalingv2.MetricTarget{ - Type: autoscalingv2.AverageValueMetricType, - AverageValue: resource.NewQuantity(int64(10), resource.DecimalSI), - }, - }, - }, - { - Type: autoscalingv2.PodsMetricSourceType, - Pods: &autoscalingv2.PodsMetricSource{ - Metric: autoscalingv2.MetricIdentifier{ - Name: "custom2", - }, - Target: autoscalingv2.MetricTarget{ - Type: autoscalingv2.AverageValueMetricType, - AverageValue: resource.NewQuantity(int64(20), resource.DecimalSI), - }, - }, - }, - } - - v2beta2metrics := ConvertToV2Beta2PodMetrics(v2metrics) - - for i, metric := range v2beta2metrics { - - assert.Equal(t, expectedNames[i], metric.Pods.Metric.Name) - val, ok := metric.Pods.Target.AverageValue.AsInt64() - assert.True(t, ok) - assert.Equal(t, expectedValues[i], val) - } -} - -func TestConvertToV2beta2Behavior(t *testing.T) { - ten := int32(10) - thirty := int32(30) - max := autoscalingv2.MaxChangePolicySelect - min := autoscalingv2.MinChangePolicySelect - - v2ScaleUp := &autoscalingv2.HPAScalingRules{ - StabilizationWindowSeconds: &thirty, - SelectPolicy: &max, - } - - v2ScaleDown := &autoscalingv2.HPAScalingRules{ - StabilizationWindowSeconds: &ten, - SelectPolicy: &min, - } - - v2Behavior := &autoscalingv2.HorizontalPodAutoscalerBehavior{ - ScaleUp: v2ScaleUp, - ScaleDown: v2ScaleDown, - } - - v2Beta2Behavior := ConvertToV2beta2Behavior(*v2Behavior) - - assert.Equal(t, thirty, *v2Beta2Behavior.ScaleUp.StabilizationWindowSeconds) - assert.Equal(t, ten, *v2Beta2Behavior.ScaleDown.StabilizationWindowSeconds) - assert.Equal(t, autoscalingv2beta2.MaxPolicySelect, *v2Beta2Behavior.ScaleUp.SelectPolicy) - assert.EqualValues(t, autoscalingv2beta2.MinPolicySelect, *v2Beta2Behavior.ScaleDown.SelectPolicy) -} - -func TestConvertToV2Beta2HPAScalingPolicy(t *testing.T) { - v2Policy := autoscalingv2.HPAScalingPolicy{ - Type: autoscalingv2.PodsScalingPolicy, - Value: 5, - PeriodSeconds: 10, - } - - v2Beta2Policy := ConvertToV2Beta2HPAScalingPolicy(v2Policy) - assert.Equal(t, autoscalingv2beta2.PodsScalingPolicy, v2Beta2Policy.Type) - assert.Equal(t, int32(5), v2Beta2Policy.Value) - assert.Equal(t, int32(10), v2Beta2Policy.PeriodSeconds) - -} - -func TestConvertToV2Beta2SelectPolicy(t *testing.T) { - min := autoscalingv2.MinChangePolicySelect - max := autoscalingv2.MaxChangePolicySelect - disabled := autoscalingv2.DisabledPolicySelect - - assert.Equal(t, autoscalingv2beta2.MinPolicySelect, ConvertToV2Beta2SelectPolicy(min)) - assert.Equal(t, autoscalingv2beta2.MaxPolicySelect, ConvertToV2Beta2SelectPolicy(max)) - assert.Equal(t, autoscalingv2beta2.DisabledPolicySelect, ConvertToV2Beta2SelectPolicy(disabled)) -} - -var _ autodetect.AutoDetect = (*mockAutoDetect)(nil) - -type mockAutoDetect struct { - OpenShiftRoutesAvailabilityFunc func() (autodetect.OpenShiftRoutesAvailability, error) - HPAVersionFunc func() (autodetect.AutoscalingVersion, error) -} - -func (m *mockAutoDetect) HPAVersion() (autodetect.AutoscalingVersion, error) { - return m.HPAVersionFunc() -} - -func (m *mockAutoDetect) OpenShiftRoutesAvailability() (autodetect.OpenShiftRoutesAvailability, error) { - if m.OpenShiftRoutesAvailabilityFunc != nil { - return m.OpenShiftRoutesAvailabilityFunc() - } - return autodetect.OpenShiftRoutesNotAvailable, nil -} diff --git a/kind-1.19.yaml b/kind-1.19.yaml deleted file mode 100644 index 6720d5f674..0000000000 --- a/kind-1.19.yaml +++ /dev/null @@ -1,18 +0,0 @@ -kind: Cluster -apiVersion: kind.x-k8s.io/v1alpha4 -nodes: -- role: control-plane - image: kindest/node:v1.19.16@sha256:476cb3269232888437b61deca013832fee41f9f074f9bed79f57e4280f7c48b7 - kubeadmConfigPatches: - - | - kind: InitConfiguration - nodeRegistration: - kubeletExtraArgs: - node-labels: "ingress-ready=true" - extraPortMappings: - - containerPort: 80 - hostPort: 80 - protocol: TCP - - containerPort: 443 - hostPort: 443 - protocol: TCP diff --git a/kind-1.20.yaml b/kind-1.20.yaml deleted file mode 100644 index cd05acf931..0000000000 --- a/kind-1.20.yaml +++ /dev/null @@ -1,18 +0,0 @@ -kind: Cluster -apiVersion: kind.x-k8s.io/v1alpha4 -nodes: -- role: control-plane - image: kindest/node:v1.20.15@sha256:a32bf55309294120616886b5338f95dd98a2f7231519c7dedcec32ba29699394 - kubeadmConfigPatches: - - | - kind: InitConfiguration - nodeRegistration: - kubeletExtraArgs: - node-labels: "ingress-ready=true" - extraPortMappings: - - containerPort: 80 - hostPort: 80 - protocol: TCP - - containerPort: 443 - hostPort: 443 - protocol: TCP diff --git a/kind-1.21.yaml b/kind-1.21.yaml deleted file mode 100644 index c6de06b575..0000000000 --- a/kind-1.21.yaml +++ /dev/null @@ -1,18 +0,0 @@ -kind: Cluster -apiVersion: kind.x-k8s.io/v1alpha4 -nodes: -- role: control-plane - image: kindest/node:v1.21.14@sha256:8a4e9bb3f415d2bb81629ce33ef9c76ba514c14d707f9797a01e3216376ba093 - kubeadmConfigPatches: - - | - kind: InitConfiguration - nodeRegistration: - kubeletExtraArgs: - node-labels: "ingress-ready=true" - extraPortMappings: - - containerPort: 80 - hostPort: 80 - protocol: TCP - - containerPort: 443 - hostPort: 443 - protocol: TCP diff --git a/kind-1.22.yaml b/kind-1.22.yaml deleted file mode 100644 index cde6274200..0000000000 --- a/kind-1.22.yaml +++ /dev/null @@ -1,18 +0,0 @@ -kind: Cluster -apiVersion: kind.x-k8s.io/v1alpha4 -nodes: -- role: control-plane - image: kindest/node:v1.22.17@sha256:f5b2e5698c6c9d6d0adc419c0deae21a425c07d81bbf3b6a6834042f25d4fba2 - kubeadmConfigPatches: - - | - kind: InitConfiguration - nodeRegistration: - kubeletExtraArgs: - node-labels: "ingress-ready=true" - extraPortMappings: - - containerPort: 80 - hostPort: 80 - protocol: TCP - - containerPort: 443 - hostPort: 443 - protocol: TCP diff --git a/pkg/autodetect/main.go b/pkg/autodetect/main.go index 8d1d295014..d12d19b297 100644 --- a/pkg/autodetect/main.go +++ b/pkg/autodetect/main.go @@ -16,9 +16,6 @@ package autodetect import ( - "errors" - "sort" - "k8s.io/client-go/discovery" "k8s.io/client-go/rest" ) @@ -28,23 +25,12 @@ var _ AutoDetect = (*autoDetect)(nil) // AutoDetect provides an assortment of routines that auto-detect traits based on the runtime. type AutoDetect interface { OpenShiftRoutesAvailability() (OpenShiftRoutesAvailability, error) - HPAVersion() (AutoscalingVersion, error) } type autoDetect struct { dcl discovery.DiscoveryInterface } -type AutoscalingVersion int - -const ( - AutoscalingVersionV2 AutoscalingVersion = iota - AutoscalingVersionV2Beta2 - AutoscalingVersionUnknown -) - -const DefaultAutoscalingVersion = AutoscalingVersionV2 - // New creates a new auto-detection worker, using the given client when talking to the current cluster. func New(restConfig *rest.Config) (AutoDetect, error) { dcl, err := discovery.NewDiscoveryClientForConfig(restConfig) @@ -76,51 +62,3 @@ func (a *autoDetect) OpenShiftRoutesAvailability() (OpenShiftRoutesAvailability, return OpenShiftRoutesNotAvailable, nil } - -func (a *autoDetect) HPAVersion() (AutoscalingVersion, error) { - apiList, err := a.dcl.ServerGroups() - if err != nil { - return AutoscalingVersionUnknown, err - } - - for _, apiGroup := range apiList.Groups { - if apiGroup.Name == "autoscaling" { - // Sort this so we can make sure to get v2 before v2beta2 - versions := apiGroup.Versions - sort.Slice(versions, func(i, j int) bool { - return versions[i].Version < versions[j].Version - }) - - for _, version := range versions { - if version.Version == "v2" || version.Version == "v2beta2" { - return ToAutoScalingVersion(version.Version), nil - } - } - return AutoscalingVersionUnknown, errors.New("Failed to find appropriate version of apiGroup autoscaling, only v2 and v2beta2 are supported") - } - } - - return AutoscalingVersionUnknown, errors.New("Failed to find apiGroup autoscaling") -} - -func (v AutoscalingVersion) String() string { - switch v { - case AutoscalingVersionV2: - return "v2" - case AutoscalingVersionV2Beta2: - return "v2beta2" - case AutoscalingVersionUnknown: - return "unknown" - } - return "unknown" -} - -func ToAutoScalingVersion(version string) AutoscalingVersion { - switch version { - case "v2": - return AutoscalingVersionV2 - case "v2beta2": - return AutoscalingVersionV2Beta2 - } - return AutoscalingVersionUnknown -} diff --git a/pkg/autodetect/main_test.go b/pkg/autodetect/main_test.go index e41cb1ee61..18a9640f0b 100644 --- a/pkg/autodetect/main_test.go +++ b/pkg/autodetect/main_test.go @@ -70,15 +70,3 @@ func TestDetectPlatformBasedOnAvailableAPIGroups(t *testing.T) { assert.Equal(t, tt.expected, ora) } } - -func TestAutoscalingVersionToString(t *testing.T) { - assert.Equal(t, "v2", autodetect.AutoscalingVersionV2.String()) - assert.Equal(t, "v2beta2", autodetect.AutoscalingVersionV2Beta2.String()) - assert.Equal(t, "unknown", autodetect.AutoscalingVersionUnknown.String()) -} - -func TestToAutoScalingVersion(t *testing.T) { - assert.Equal(t, autodetect.AutoscalingVersionV2, autodetect.ToAutoScalingVersion("v2")) - assert.Equal(t, autodetect.AutoscalingVersionV2Beta2, autodetect.ToAutoScalingVersion("v2beta2")) - assert.Equal(t, autodetect.AutoscalingVersionUnknown, autodetect.ToAutoScalingVersion("fred")) -} diff --git a/tests/e2e-autoscale/autoscale/00-assert.yaml b/tests/e2e-autoscale/autoscale/00-assert.yaml index a0edb12300..2546b5462d 100644 --- a/tests/e2e-autoscale/autoscale/00-assert.yaml +++ b/tests/e2e-autoscale/autoscale/00-assert.yaml @@ -11,3 +11,76 @@ metadata: name: simplest-set-utilization-collector status: readyReplicas: 1 +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: simplest-collector +spec: + scaleTargetRef: + kind: OpenTelemetryCollector + name: simplest + apiVersion: opentelemetry.io/v1alpha1 + minReplicas: 1 + maxReplicas: 2 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 90 + behavior: + scaleUp: + stabilizationWindowSeconds: 10 + selectPolicy: Max + policies: + - type: Pods + value: 4 + periodSeconds: 15 + - type: Percent + value: 100 + periodSeconds: 15 + scaleDown: + stabilizationWindowSeconds: 15 + selectPolicy: Max + policies: + - type: Percent + value: 100 + periodSeconds: 15 +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: simplest-set-utilization-collector +spec: + scaleTargetRef: + kind: OpenTelemetryCollector + name: simplest-set-utilization + apiVersion: opentelemetry.io/v1alpha1 + minReplicas: 1 + maxReplicas: 2 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 99 + behavior: + scaleUp: + stabilizationWindowSeconds: 300 + selectPolicy: Max + policies: + - type: Pods + value: 4 + periodSeconds: 15 + - type: Percent + value: 100 + periodSeconds: 15 + scaleDown: + selectPolicy: Max + policies: + - type: Percent + value: 100 + periodSeconds: 15 diff --git a/tests/e2e-autoscale/autoscale/01-assert.yaml b/tests/e2e-autoscale/autoscale/01-assert.yaml new file mode 100644 index 0000000000..faae4da95b --- /dev/null +++ b/tests/e2e-autoscale/autoscale/01-assert.yaml @@ -0,0 +1,36 @@ +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: simplest-set-utilization-collector +spec: + scaleTargetRef: + kind: OpenTelemetryCollector + name: simplest-set-utilization + apiVersion: opentelemetry.io/v1alpha1 + minReplicas: 1 + maxReplicas: 2 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 60 + behavior: + scaleUp: + stabilizationWindowSeconds: 1 + selectPolicy: Max + policies: + - type: Pods + value: 4 + periodSeconds: 15 + - type: Percent + value: 100 + periodSeconds: 15 + scaleDown: + stabilizationWindowSeconds: 15 + selectPolicy: Max + policies: + - type: Percent + value: 100 + periodSeconds: 15 diff --git a/tests/e2e-autoscale/autoscale/01-check-simplest-collector-hpa.yaml b/tests/e2e-autoscale/autoscale/01-check-simplest-collector-hpa.yaml deleted file mode 100644 index c01035210b..0000000000 --- a/tests/e2e-autoscale/autoscale/01-check-simplest-collector-hpa.yaml +++ /dev/null @@ -1,4 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: go run ./wait-until-hpa-ready.go --hpa simplest-collector diff --git a/tests/e2e-autoscale/autoscale/01-install.yaml b/tests/e2e-autoscale/autoscale/01-install.yaml new file mode 100644 index 0000000000..a9a6d549c2 --- /dev/null +++ b/tests/e2e-autoscale/autoscale/01-install.yaml @@ -0,0 +1,44 @@ +# This updates an existing deployment with a new Spec. +# Target memory utilization is now added. +# scaleDown and scaleUp behavior is now added. +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: simplest-set-utilization +spec: + minReplicas: 1 + maxReplicas: 2 + autoscaler: + targetCPUUtilization: 60 + # Without this behavior the HPA will default to a scaledown stabilization + # window of 300 seconds. Tests should fail if this update is not successful. + behavior: + scaleDown: + stabilizationWindowSeconds: 15 + scaleUp: + stabilizationWindowSeconds: 1 + resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 5m + memory: 64Mi + + config: | + receivers: + otlp: + protocols: + grpc: + http: + processors: + + exporters: + logging: + + service: + pipelines: + traces: + receivers: [otlp] + processors: [] + exporters: [logging] \ No newline at end of file diff --git a/tests/e2e-autoscale/autoscale/05-assert.yaml b/tests/e2e-autoscale/autoscale/02-assert.yaml similarity index 88% rename from tests/e2e-autoscale/autoscale/05-assert.yaml rename to tests/e2e-autoscale/autoscale/02-assert.yaml index d67919fa37..8dc83f76b8 100644 --- a/tests/e2e-autoscale/autoscale/05-assert.yaml +++ b/tests/e2e-autoscale/autoscale/02-assert.yaml @@ -4,4 +4,4 @@ metadata: name: simplest-set-utilization status: scale: - replicas: 1 + replicas: 2 diff --git a/tests/e2e-autoscale/autoscale/02-check-simplest-set-utilization-collector-hpa.yaml b/tests/e2e-autoscale/autoscale/02-check-simplest-set-utilization-collector-hpa.yaml deleted file mode 100644 index 21dad9ff4a..0000000000 --- a/tests/e2e-autoscale/autoscale/02-check-simplest-set-utilization-collector-hpa.yaml +++ /dev/null @@ -1,4 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: go run ./wait-until-hpa-ready.go --hpa simplest-set-utilization-collector diff --git a/tests/e2e-autoscale/autoscale/02-install.yaml b/tests/e2e-autoscale/autoscale/02-install.yaml index a9a6d549c2..d4401cae3d 100644 --- a/tests/e2e-autoscale/autoscale/02-install.yaml +++ b/tests/e2e-autoscale/autoscale/02-install.yaml @@ -1,44 +1,21 @@ -# This updates an existing deployment with a new Spec. -# Target memory utilization is now added. -# scaleDown and scaleUp behavior is now added. -apiVersion: opentelemetry.io/v1alpha1 -kind: OpenTelemetryCollector +apiVersion: batch/v1 +kind: Job metadata: - name: simplest-set-utilization + name: tracegen-set-utilization spec: - minReplicas: 1 - maxReplicas: 2 - autoscaler: - targetCPUUtilization: 60 - # Without this behavior the HPA will default to a scaledown stabilization - # window of 300 seconds. Tests should fail if this update is not successful. - behavior: - scaleDown: - stabilizationWindowSeconds: 15 - scaleUp: - stabilizationWindowSeconds: 1 - resources: - limits: - cpu: 100m - memory: 128Mi - requests: - cpu: 5m - memory: 64Mi - - config: | - receivers: - otlp: - protocols: - grpc: - http: - processors: - - exporters: - logging: - - service: - pipelines: - traces: - receivers: [otlp] - processors: [] - exporters: [logging] \ No newline at end of file + template: + spec: + containers: + - name: tracegen + image: ghcr.io/open-telemetry/opentelemetry-collector-contrib/tracegen:latest + command: + - "./tracegen" + args: + - -otlp-endpoint=simplest-set-utilization-collector-headless:4317 + - -otlp-insecure + # High duration to ensure the trace creation doesn't stop. + # It'll be stopped in step 4 + - -duration=1m + - -workers=20 + restartPolicy: Never + backoffLimit: 4 diff --git a/tests/e2e-autoscale/autoscale/03-assert.yaml b/tests/e2e-autoscale/autoscale/03-assert.yaml index 8dc83f76b8..d67919fa37 100644 --- a/tests/e2e-autoscale/autoscale/03-assert.yaml +++ b/tests/e2e-autoscale/autoscale/03-assert.yaml @@ -4,4 +4,4 @@ metadata: name: simplest-set-utilization status: scale: - replicas: 2 + replicas: 1 diff --git a/tests/e2e-autoscale/autoscale/04-delete.yaml b/tests/e2e-autoscale/autoscale/03-delete.yaml similarity index 100% rename from tests/e2e-autoscale/autoscale/04-delete.yaml rename to tests/e2e-autoscale/autoscale/03-delete.yaml diff --git a/tests/e2e-autoscale/autoscale/03-install.yaml b/tests/e2e-autoscale/autoscale/03-install.yaml deleted file mode 100644 index d4401cae3d..0000000000 --- a/tests/e2e-autoscale/autoscale/03-install.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: batch/v1 -kind: Job -metadata: - name: tracegen-set-utilization -spec: - template: - spec: - containers: - - name: tracegen - image: ghcr.io/open-telemetry/opentelemetry-collector-contrib/tracegen:latest - command: - - "./tracegen" - args: - - -otlp-endpoint=simplest-set-utilization-collector-headless:4317 - - -otlp-insecure - # High duration to ensure the trace creation doesn't stop. - # It'll be stopped in step 4 - - -duration=1m - - -workers=20 - restartPolicy: Never - backoffLimit: 4 diff --git a/tests/e2e-autoscale/autoscale/03-verify-simplest-set-collector-hpa-metrics.yaml b/tests/e2e-autoscale/autoscale/03-verify-simplest-set-collector-hpa-metrics.yaml deleted file mode 100644 index 6063958c8f..0000000000 --- a/tests/e2e-autoscale/autoscale/03-verify-simplest-set-collector-hpa-metrics.yaml +++ /dev/null @@ -1,4 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: go run ./cmd/verify/wait-and-validate-metrics.go --cpu-value 60 --scale-down 15 --scale-up 1 --hpa simplest-set-utilization-collector \ No newline at end of file diff --git a/tests/e2e-autoscale/autoscale/cmd/verify/wait-and-validate-metrics.go b/tests/e2e-autoscale/autoscale/cmd/verify/wait-and-validate-metrics.go deleted file mode 100644 index 9126b3295c..0000000000 --- a/tests/e2e-autoscale/autoscale/cmd/verify/wait-and-validate-metrics.go +++ /dev/null @@ -1,187 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -import ( - "context" - "fmt" - "os" - "path/filepath" - "time" - - "github.com/spf13/pflag" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/tools/clientcmd" - "k8s.io/client-go/util/homedir" -) - -func main() { - var hpaName string - var timeout time.Duration - var numMetrics int - var cpuValue int - var memoryValue int - var scaleDownWindow int - var scaleUpWindow int - - pflag.DurationVar(&timeout, "timeout", 5*time.Minute, "The timeout for the check.") - pflag.StringVar(&hpaName, "hpa", "", "HPA to check") - pflag.IntVar(&numMetrics, "num-metrics", 1, "number of expected metrics in Spec") - pflag.IntVar(&cpuValue, "cpu-value", -1, "value for target CPU utilization") - pflag.IntVar(&memoryValue, "memory-value", -1, "value for target memory utilization") - pflag.IntVar(&scaleDownWindow, "scale-down", -1, "value for scaleDown stabilization window") - pflag.IntVar(&scaleUpWindow, "scale-up", -1, "value for scaleUp stabilization window") - pflag.Parse() - - if len(hpaName) == 0 { - fmt.Println("hpa flag is mandatory") - os.Exit(1) - } - - kubeconfigPath := getKubeconfigPath() - - configLoader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( - &clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfigPath}, - &clientcmd.ConfigOverrides{}, - ) - - config, err := configLoader.ClientConfig() - if err != nil { - fmt.Printf("Error reading the kubeconfig: %s\n", err) - os.Exit(1) - } - - client, err := kubernetes.NewForConfig(config) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - namespace, err := client.CoreV1().Namespaces().Get(context.Background(), os.Getenv("NAMESPACE"), metav1.GetOptions{}) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - hpaClientV2 := client.AutoscalingV2().HorizontalPodAutoscalers(namespace.Name) - hpaClientV1 := client.AutoscalingV1().HorizontalPodAutoscalers(namespace.Name) - - pollInterval := time.Second - - // Search in v2 and v1 for an HPA with the given name - ctx := context.Background() - err = wait.PollUntilContextTimeout(ctx, pollInterval, timeout, false, func(c context.Context) (done bool, err error) { - hpav2, err := hpaClientV2.Get( - c, - hpaName, - metav1.GetOptions{}, - ) - - if err != nil { - hpav1, err := hpaClientV1.Get( - c, - hpaName, - metav1.GetOptions{}, - ) - if err != nil { - fmt.Printf("HPA %s not found\n", hpaName) - return false, nil - } - - if hpav1.Status.CurrentCPUUtilizationPercentage == nil { - fmt.Printf("Current metrics are not set yet for HPA %s\n", hpaName) - return false, nil - } - - if *hpav1.Spec.TargetCPUUtilizationPercentage != int32(cpuValue) { - fmt.Printf("Incorrect target CPU value found for HPA %s\n", hpaName) - return false, nil - } - return true, nil - } - - if hpav2.Status.CurrentMetrics == nil { - fmt.Printf("Current metrics are not set yet for HPA %s\n", hpaName) - return false, nil - } - - numExpectedMetrics := 0 - if cpuValue != -1 { - numExpectedMetrics += 1 - } - if memoryValue != -1 { - numExpectedMetrics += 1 - } - if len(hpav2.Spec.Metrics) != numExpectedMetrics { - fmt.Printf("Metrics has incorrect length for HPA %s\n", hpaName) - return false, nil - } - - for _, metric := range hpav2.Spec.Metrics { - if metric.Resource.Name == corev1.ResourceCPU { - if cpuValue == -1 { - fmt.Printf("Unexpected CPU metric found for HPA %s\n", hpaName) - return false, nil - } - if int32(cpuValue) != *metric.Resource.Target.AverageUtilization { - fmt.Printf("Incorrect target CPU value found for HPA %s\n", hpaName) - return false, nil - } - } else if metric.Resource.Name == corev1.ResourceMemory { - if memoryValue == -1 { - fmt.Printf("Unexpected memory metric found for HPA %s\n", hpaName) - return false, nil - } - if int32(memoryValue) != *metric.Resource.Target.AverageUtilization { - fmt.Printf("Incorrect target memory value found for HPA %s\n", hpaName) - return false, nil - } - } - } - - // validate HPA behavior - if int32(scaleDownWindow) != *hpav2.Spec.Behavior.ScaleDown.StabilizationWindowSeconds { - fmt.Printf("Incorrect scaleDown stabilization window found for HPA %s\n", hpaName) - return false, nil - } - if int32(scaleUpWindow) != *hpav2.Spec.Behavior.ScaleUp.StabilizationWindowSeconds { - fmt.Printf("Incorrect scaleUp stabilization window found for HPA %s\n", hpaName) - return false, nil - } - - return true, nil - }) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - fmt.Printf("%s is ready!\n", hpaName) -} - -func getKubeconfigPath() string { - kubeconfigEnv := os.Getenv("KUBECONFIG") - if kubeconfigEnv != "" { - if _, err := os.Stat(kubeconfigEnv); err == nil { - return kubeconfigEnv - } - } - - homeDir := homedir.HomeDir() - return filepath.Join(homeDir, ".kube", "config") -} diff --git a/tests/e2e-autoscale/autoscale/wait-until-hpa-ready.go b/tests/e2e-autoscale/autoscale/wait-until-hpa-ready.go deleted file mode 100644 index 51bc7328da..0000000000 --- a/tests/e2e-autoscale/autoscale/wait-until-hpa-ready.go +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -import ( - "context" - "fmt" - "os" - "path/filepath" - "time" - - "github.com/spf13/pflag" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/tools/clientcmd" - "k8s.io/client-go/util/homedir" -) - -func main() { - var hpaName string - var timeout time.Duration - - pflag.DurationVar(&timeout, "timeout", 5*time.Minute, "The timeout for the check.") - pflag.StringVar(&hpaName, "hpa", "", "HPA to check") - pflag.Parse() - - if len(hpaName) == 0 { - fmt.Println("hpa flag is mandatory") - os.Exit(1) - } - - kubeconfigPath := getKubeconfigPath() - - config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath) - if err != nil { - fmt.Printf("Error reading the kubeconfig: %s\n", err) - os.Exit(1) - } - - client, err := kubernetes.NewForConfig(config) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - namespace, err := client.CoreV1().Namespaces().Get(context.Background(), os.Getenv("NAMESPACE"), v1.GetOptions{}) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - hpaClientV2 := client.AutoscalingV2().HorizontalPodAutoscalers(namespace.Name) - hpaClientV1 := client.AutoscalingV1().HorizontalPodAutoscalers(namespace.Name) - - pollInterval := time.Second - - // Search in v2 and v1 for an HPA with the given name - - ctx := context.Background() - err = wait.PollUntilContextTimeout(ctx, pollInterval, timeout, false, func(c context.Context) (done bool, err error) { - hpav2, err := hpaClientV2.Get( - c, - hpaName, - v1.GetOptions{}, - ) - if err != nil { - hpav1, err := hpaClientV1.Get( - c, - hpaName, - v1.GetOptions{}, - ) - if err != nil { - fmt.Printf("HPA %s not found\n", hpaName) - return false, nil - } - - if hpav1.Status.CurrentCPUUtilizationPercentage == nil { - fmt.Printf("Current metrics are not set yet for HPA %s\n", hpaName) - return false, nil - } - return true, nil - } - - if hpav2.Status.CurrentMetrics == nil { - fmt.Printf("Current metrics are not set yet for HPA %s\n", hpaName) - return false, nil - } - return true, nil - }) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - fmt.Printf("%s is ready!\n", hpaName) -} - -func getKubeconfigPath() string { - kubeconfigEnv := os.Getenv("KUBECONFIG") - if kubeconfigEnv != "" { - if _, err := os.Stat(kubeconfigEnv); err == nil { - return kubeconfigEnv - } - } - - homeDir := homedir.HomeDir() - return filepath.Join(homeDir, ".kube", "config") -} From 77bdd5e889f05f4d3e1e9299936fa86ad8bfe64a Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Tue, 26 Sep 2023 09:26:59 +0200 Subject: [PATCH 2/9] u8ndo the format Signed-off-by: Jorge Turrado --- .github/workflows/e2e.yaml | 72 +++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index c9f87740f1..8b4bd8d5c5 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -2,9 +2,9 @@ name: "End-to-end tests" on: push: - branches: [main] + branches: [ main ] pull_request: - branches: [main] + branches: [ main ] concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -12,7 +12,7 @@ concurrency: env: CURRENT_KIND_VERSION: 0.20.0 - LEGACY_KIND_VERSION: 0.17.0 # for K8s versions latest kind doesn't support anymore + LEGACY_KIND_VERSION: 0.17.0 # for K8s versions latest kind doesn't support anymore jobs: e2e-tests: @@ -21,46 +21,46 @@ jobs: strategy: fail-fast: false matrix: - # The e2e tests are run on the lowest and highest supported k8s version. - # All Kubernetes version in between expose the same APIs, hence the operator - # should be compatible with them. - kube-version: - - "1.23" - - "1.28" - group: - - e2e - - e2e-instrumentation - - e2e-upgrade - - e2e-prometheuscr - - e2e-autoscale + # The e2e tests are run on the lowest and highest supported k8s version. + # All Kubernetes version in between expose the same APIs, hence the operator + # should be compatible with them. + kube-version: + - "1.23" + - "1.28" + group: + - e2e + - e2e-instrumentation + - e2e-upgrade + - e2e-prometheuscr + - e2e-autoscale steps: - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "~1.21.1" + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "~1.21.1" - - name: Setup kind - env: - KIND_VERSION: ${{ matrix.kube_version >= 1.21 && env.KIND_VERSION || env.LEGACY_KIND_VERSION }} - run: go install sigs.k8s.io/kind@v${KIND_VERSION} + - name: Setup kind + env: + KIND_VERSION: ${{ matrix.kube_version >= 1.21 && env.KIND_VERSION || env.LEGACY_KIND_VERSION }} + run: go install sigs.k8s.io/kind@v${KIND_VERSION} - - name: Check out code into the Go module directory - uses: actions/checkout@v4 + - name: Check out code into the Go module directory + uses: actions/checkout@v4 - - name: "install kuttl" - run: ./hack/install-kuttl.sh + - name: "install kuttl" + run: ./hack/install-kuttl.sh - - name: "run tests" - env: - KUBE_VERSION: ${{ matrix.kube-version }} - run: make prepare-e2e ${{ matrix.group }} KUBE_VERSION=$KUBE_VERSION VERSION=e2e + - name: "run tests" + env: + KUBE_VERSION: ${{ matrix.kube-version }} + run: make prepare-e2e ${{ matrix.group }} KUBE_VERSION=$KUBE_VERSION VERSION=e2e - - name: "log operator if failed" - if: ${{ failure() }} - env: - KUBE_VERSION: ${{ matrix.kube-version }} - run: make e2e-log-operator KUBE_VERSION=$KUBE_VERSION + - name: "log operator if failed" + if: ${{ failure() }} + env: + KUBE_VERSION: ${{ matrix.kube-version }} + run: make e2e-log-operator KUBE_VERSION=$KUBE_VERSION e2e-tests-check: runs-on: ubuntu-22.04 From ba8f21287e155d7b41b9aae2cfcfb129267803f0 Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Tue, 26 Sep 2023 09:27:51 +0200 Subject: [PATCH 3/9] undo wrong change Signed-off-by: Jorge Turrado --- config/manager/kustomization.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 40c0846afa..5c5f0b84cb 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,7 +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 From f77b648ea4d50dce5cde759d4678dd5aff1148f3 Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Tue, 26 Sep 2023 11:59:55 +0200 Subject: [PATCH 4/9] update kind-yaml Signed-off-by: Jorge Turrado --- kind-1.23.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kind-1.23.yaml b/kind-1.23.yaml index 9662441c62..6152755cfe 100644 --- a/kind-1.23.yaml +++ b/kind-1.23.yaml @@ -5,10 +5,10 @@ nodes: image: kindest/node:v1.23.17@sha256:59c989ff8a517a93127d4a536e7014d28e235fb3529d9fba91b3951d461edfdb kubeadmConfigPatches: - | - kind: InitConfiguration - nodeRegistration: - kubeletExtraArgs: - node-labels: "ingress-ready=true" + kind: InitConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "ingress-ready=true" extraPortMappings: - containerPort: 80 hostPort: 80 From 94fae45f3b254c192f9dd697755053b3d211576b Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Tue, 26 Sep 2023 12:01:22 +0200 Subject: [PATCH 5/9] unify stykle Signed-off-by: Jorge Turrado --- kind-1.23.yaml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/kind-1.23.yaml b/kind-1.23.yaml index 6152755cfe..09a2521d81 100644 --- a/kind-1.23.yaml +++ b/kind-1.23.yaml @@ -1,18 +1,18 @@ kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: -- role: control-plane - image: kindest/node:v1.23.17@sha256:59c989ff8a517a93127d4a536e7014d28e235fb3529d9fba91b3951d461edfdb - kubeadmConfigPatches: - - | - kind: InitConfiguration - nodeRegistration: - kubeletExtraArgs: - node-labels: "ingress-ready=true" - extraPortMappings: - - containerPort: 80 - hostPort: 80 - protocol: TCP - - containerPort: 443 - hostPort: 443 - protocol: TCP + - role: control-plane + image: kindest/node:v1.23.17@sha256:59c989ff8a517a93127d4a536e7014d28e235fb3529d9fba91b3951d461edfdb + kubeadmConfigPatches: + - | + kind: InitConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "ingress-ready=true" + extraPortMappings: + - containerPort: 80 + hostPort: 80 + protocol: TCP + - containerPort: 443 + hostPort: 443 + protocol: TCP From 56426c325b4c77585f43ff2c7058993e80dbdd9f Mon Sep 17 00:00:00 2001 From: Jorge Turrado Ferrero Date: Tue, 26 Sep 2023 20:18:00 +0200 Subject: [PATCH 6/9] revert the change --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index ee101d2c5a..13042200ad 100644 --- a/README.md +++ b/README.md @@ -594,7 +594,6 @@ The OpenTelemetry Operator *might* work on versions outside of the given range, | OpenTelemetry Operator | Kubernetes | Cert-Manager | |------------------------|----------------------|---------------------| -| v0.86.0 | v1.23 to v1.28 | v1 | | v0.85.0 | v1.19 to v1.28 | v1 | | v0.84.0 | v1.19 to v1.28 | v1 | | v0.83.0 | v1.19 to v1.27 | v1 | From ff66d75a08405271f8ab10e55d4d7d4673e76ae6 Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Thu, 28 Sep 2023 15:03:27 +0200 Subject: [PATCH 7/9] apply feedback Signed-off-by: Jorge Turrado --- .github/workflows/e2e.yaml | 3 +-- .github/workflows/scorecard.yaml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 8b4bd8d5c5..3b07a277ab 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -12,7 +12,6 @@ concurrency: env: CURRENT_KIND_VERSION: 0.20.0 - LEGACY_KIND_VERSION: 0.17.0 # for K8s versions latest kind doesn't support anymore jobs: e2e-tests: @@ -42,7 +41,7 @@ jobs: - name: Setup kind env: - KIND_VERSION: ${{ matrix.kube_version >= 1.21 && env.KIND_VERSION || env.LEGACY_KIND_VERSION }} + KIND_VERSION: ${{ env.KIND_VERSION }} run: go install sigs.k8s.io/kind@v${KIND_VERSION} - name: Check out code into the Go module directory diff --git a/.github/workflows/scorecard.yaml b/.github/workflows/scorecard.yaml index 19e2b124cf..43fd3940b6 100644 --- a/.github/workflows/scorecard.yaml +++ b/.github/workflows/scorecard.yaml @@ -12,7 +12,6 @@ concurrency: env: CURRENT_KIND_VERSION: 0.20.0 - LEGACY_KIND_VERSION: 0.17.0 # for K8s versions latest kind doesn't support anymore jobs: scorecard-tests: @@ -33,7 +32,7 @@ jobs: - name: Setup kind env: - KIND_VERSION: ${{ matrix.kube_version >= 1.21 && env.KIND_VERSION || env.LEGACY_KIND_VERSION }} + KIND_VERSION: ${{ env.KIND_VERSION }} run: go install sigs.k8s.io/kind@v${KIND_VERSION} - name: Check out code into the Go module directory From ae11f78bd6aee26539f010efe86cc2ddc036cd0b Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Thu, 28 Sep 2023 15:24:23 +0200 Subject: [PATCH 8/9] apply feedback Signed-off-by: Jorge Turrado --- internal/manifests/collector/horizontalpodautoscaler.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/manifests/collector/horizontalpodautoscaler.go b/internal/manifests/collector/horizontalpodautoscaler.go index f809434141..719e2bf9d3 100644 --- a/internal/manifests/collector/horizontalpodautoscaler.go +++ b/internal/manifests/collector/horizontalpodautoscaler.go @@ -60,7 +60,7 @@ func HorizontalPodAutoscaler(cfg config.Config, logger logr.Logger, otelcol v1al metrics := []autoscalingv2.MetricSpec{} if otelcol.Spec.Autoscaler.TargetMemoryUtilization != nil { - utilizationTarget := autoscalingv2.MetricSpec{ + memoryTarget := autoscalingv2.MetricSpec{ Type: autoscalingv2.ResourceMetricSourceType, Resource: &autoscalingv2.ResourceMetricSource{ Name: corev1.ResourceMemory, @@ -70,11 +70,11 @@ func HorizontalPodAutoscaler(cfg config.Config, logger logr.Logger, otelcol v1al }, }, } - metrics = append(metrics, utilizationTarget) + metrics = append(metrics, memoryTarget) } if otelcol.Spec.Autoscaler.TargetCPUUtilization != nil { - targetCPUUtilization := autoscalingv2.MetricSpec{ + cpuTarget := autoscalingv2.MetricSpec{ Type: autoscalingv2.ResourceMetricSourceType, Resource: &autoscalingv2.ResourceMetricSource{ Name: corev1.ResourceCPU, @@ -84,7 +84,7 @@ func HorizontalPodAutoscaler(cfg config.Config, logger logr.Logger, otelcol v1al }, }, } - metrics = append(metrics, targetCPUUtilization) + metrics = append(metrics, cpuTarget) } autoscaler := autoscalingv2.HorizontalPodAutoscaler{ From 1c7b545d32ca14df959975e406c4ec6316802660 Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Thu, 28 Sep 2023 15:25:32 +0200 Subject: [PATCH 9/9] apply feedback Signed-off-by: Jorge Turrado --- .github/workflows/e2e.yaml | 5 +---- .github/workflows/scorecard.yaml | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 3b07a277ab..fa3acafe76 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -10,9 +10,6 @@ concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true -env: - CURRENT_KIND_VERSION: 0.20.0 - jobs: e2e-tests: name: End-to-end tests @@ -41,7 +38,7 @@ jobs: - name: Setup kind env: - KIND_VERSION: ${{ env.KIND_VERSION }} + KIND_VERSION: "0.20.0" run: go install sigs.k8s.io/kind@v${KIND_VERSION} - name: Check out code into the Go module directory diff --git a/.github/workflows/scorecard.yaml b/.github/workflows/scorecard.yaml index 43fd3940b6..10e6a2d0eb 100644 --- a/.github/workflows/scorecard.yaml +++ b/.github/workflows/scorecard.yaml @@ -10,9 +10,6 @@ concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true -env: - CURRENT_KIND_VERSION: 0.20.0 - jobs: scorecard-tests: name: test on k8s @@ -32,7 +29,7 @@ jobs: - name: Setup kind env: - KIND_VERSION: ${{ env.KIND_VERSION }} + KIND_VERSION: "0.20.0" run: go install sigs.k8s.io/kind@v${KIND_VERSION} - name: Check out code into the Go module directory