|
| 1 | +// Copyright The OpenTelemetry Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package collector |
| 16 | + |
| 17 | +import ( |
| 18 | + "github.com/go-logr/logr" |
| 19 | + autoscalingv1 "k8s.io/api/autoscaling/v1" |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | + |
| 22 | + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" |
| 23 | + "github.com/open-telemetry/opentelemetry-operator/internal/config" |
| 24 | + "github.com/open-telemetry/opentelemetry-operator/pkg/naming" |
| 25 | +) |
| 26 | + |
| 27 | +const defaultCPUTarget int32 = 90 |
| 28 | + |
| 29 | +func HorizontalPodAutoscaler(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemetryCollector) autoscalingv1.HorizontalPodAutoscaler { |
| 30 | + labels := Labels(otelcol) |
| 31 | + labels["app.kubernetes.io/name"] = naming.Collector(otelcol) |
| 32 | + |
| 33 | + annotations := Annotations(otelcol) |
| 34 | + cpuTarget := defaultCPUTarget |
| 35 | + |
| 36 | + return autoscalingv1.HorizontalPodAutoscaler{ |
| 37 | + ObjectMeta: metav1.ObjectMeta{ |
| 38 | + Name: naming.Collector(otelcol), |
| 39 | + Namespace: otelcol.Namespace, |
| 40 | + Labels: labels, |
| 41 | + Annotations: annotations, |
| 42 | + }, |
| 43 | + Spec: autoscalingv1.HorizontalPodAutoscalerSpec{ |
| 44 | + ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{ |
| 45 | + APIVersion: "apps/v1", |
| 46 | + Kind: "Deployment", |
| 47 | + Name: naming.Collector(otelcol), |
| 48 | + }, |
| 49 | + MinReplicas: otelcol.Spec.Replicas, |
| 50 | + MaxReplicas: *otelcol.Spec.MaxReplicas, |
| 51 | + TargetCPUUtilizationPercentage: &cpuTarget, |
| 52 | + }, |
| 53 | + } |
| 54 | +} |
0 commit comments