From 01acc3e7e3dd50878a1af2c3fc4f73064e9add3e Mon Sep 17 00:00:00 2001 From: Joao Marcal Date: Fri, 31 May 2024 17:22:39 +0100 Subject: [PATCH] addon: removes metrics for dev-preview --- deploy/resources/cluster_role.yaml | 6 +- go.mod | 2 +- internal/addon/helm/values.go | 25 +---- internal/addon/helm/values_test.go | 8 -- .../addon/manifests/charts/mcoa/Chart.yaml | 3 - .../charts/mcoa/charts/metrics/Chart.yaml | 5 - .../charts/metrics/templates/_helpers.tpl | 17 --- .../metrics/templates/clusterrolebinding.yaml | 16 --- .../charts/metrics/templates/configmap.yaml | 103 ------------------ .../charts/metrics/templates/deployment.yaml | 82 -------------- .../mcoa/charts/metrics/templates/role.yaml | 24 ---- .../metrics/templates/serviceaccount.yaml | 9 -- .../charts/mcoa/charts/metrics/values.yaml | 3 - .../addon/manifests/charts/mcoa/values.yaml | 3 - internal/addon/var.go | 3 - internal/metrics/metrics.go | 58 ---------- internal/metrics/metrics_test.go | 103 ------------------ main.go | 5 - 18 files changed, 5 insertions(+), 470 deletions(-) delete mode 100644 internal/addon/manifests/charts/mcoa/charts/metrics/Chart.yaml delete mode 100644 internal/addon/manifests/charts/mcoa/charts/metrics/templates/_helpers.tpl delete mode 100644 internal/addon/manifests/charts/mcoa/charts/metrics/templates/clusterrolebinding.yaml delete mode 100644 internal/addon/manifests/charts/mcoa/charts/metrics/templates/configmap.yaml delete mode 100644 internal/addon/manifests/charts/mcoa/charts/metrics/templates/deployment.yaml delete mode 100644 internal/addon/manifests/charts/mcoa/charts/metrics/templates/role.yaml delete mode 100644 internal/addon/manifests/charts/mcoa/charts/metrics/templates/serviceaccount.yaml delete mode 100644 internal/addon/manifests/charts/mcoa/charts/metrics/values.yaml delete mode 100644 internal/metrics/metrics.go delete mode 100644 internal/metrics/metrics_test.go diff --git a/deploy/resources/cluster_role.yaml b/deploy/resources/cluster_role.yaml index a28e398..fe28293 100644 --- a/deploy/resources/cluster_role.yaml +++ b/deploy/resources/cluster_role.yaml @@ -75,8 +75,4 @@ # Role for addon to perform tracing specific actions - apiGroups: ["opentelemetry.io"] resources: ["opentelemetrycollectors"] - verbs: ["get", "list", "watch"] - # Roles for addon to perform metrics specific actions - - apiGroups: ["route.openshift.io"] - resources: ["routes"] - verbs: ["get"] + verbs: ["get", "list", "watch"] \ No newline at end of file diff --git a/go.mod b/go.mod index 453c089..54c30a2 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/ViaQ/logerr/v2 v2.1.0 github.com/imdario/mergo v0.3.16 github.com/open-telemetry/opentelemetry-operator v0.93.0 - github.com/openshift/api v0.0.0-20240124164020-e2ce40831f2e // release-4.15 + github.com/openshift/api v0.0.0-20240124164020-e2ce40831f2e // indirect; release-4.15 github.com/openshift/cluster-logging-operator v0.0.0-20231130135759-9270994dc4bc github.com/operator-framework/api v0.17.7 github.com/spf13/cobra v1.8.0 diff --git a/internal/addon/helm/values.go b/internal/addon/helm/values.go index fe74e17..c01dafa 100644 --- a/internal/addon/helm/values.go +++ b/internal/addon/helm/values.go @@ -7,7 +7,6 @@ import ( "github.com/rhobs/multicluster-observability-addon/internal/addon" lhandlers "github.com/rhobs/multicluster-observability-addon/internal/logging/handlers" lmanifests "github.com/rhobs/multicluster-observability-addon/internal/logging/manifests" - "github.com/rhobs/multicluster-observability-addon/internal/metrics" thandlers "github.com/rhobs/multicluster-observability-addon/internal/tracing/handlers" tmanifests "github.com/rhobs/multicluster-observability-addon/internal/tracing/manifests" "k8s.io/klog/v2" @@ -22,13 +21,11 @@ const annotationLocalCluster = "local-cluster" type HelmChartValues struct { Enabled bool `json:"enabled"` - Metrics metrics.MetricsValues `json:"metrics"` Logging lmanifests.LoggingValues `json:"logging"` Tracing tmanifests.TracingValues `json:"tracing"` } type Options struct { - MetricsDisabled bool LoggingDisabled bool TracingDisabled bool } @@ -56,14 +53,6 @@ func GetValuesFunc(k8s client.Client) addonfactory.GetValuesFunc { Enabled: true, } - if !opts.MetricsDisabled { - metrics, err := metrics.GetValuesFunc(k8s, cluster, addon, aodc) - if err != nil { - return nil, err - } - userValues.Metrics = metrics - } - if !opts.LoggingDisabled { loggingOpts, err := lhandlers.BuildOptions(k8s, addon, aodc) if err != nil { @@ -116,28 +105,20 @@ func buildOptions(addOnDeployment *addonapiv1alpha1.AddOnDeploymentConfig) (Opti } for _, keyvalue := range addOnDeployment.Spec.CustomizedVariables { - if keyvalue.Name == addon.AdcMetricsDisabledKey { - value, err := strconv.ParseBool(keyvalue.Value) - if err != nil { - return opts, err - } - opts.MetricsDisabled = value - } - if keyvalue.Name == addon.AdcLoggingDisabledKey { + switch keyvalue.Name { + case addon.AdcLoggingDisabledKey: value, err := strconv.ParseBool(keyvalue.Value) if err != nil { return opts, err } opts.LoggingDisabled = value - } - if keyvalue.Name == addon.AdcTracingisabledKey { + case addon.AdcTracingisabledKey: value, err := strconv.ParseBool(keyvalue.Value) if err != nil { return opts, err } opts.TracingDisabled = value } - } return opts, nil } diff --git a/internal/addon/helm/values_test.go b/internal/addon/helm/values_test.go index bc4f724..3636676 100644 --- a/internal/addon/helm/values_test.go +++ b/internal/addon/helm/values_test.go @@ -59,10 +59,6 @@ func Test_Mcoa_Disable_Charts(t *testing.T) { }, Spec: addonapiv1alpha1.AddOnDeploymentConfigSpec{ CustomizedVariables: []addonapiv1alpha1.CustomizedVariable{ - { - Name: "metricsDisabled", - Value: "true", - }, { Name: "loggingDisabled", Value: "true", @@ -127,10 +123,6 @@ func Test_Mcoa_Disable_Chart_Hub(t *testing.T) { }, Spec: addonapiv1alpha1.AddOnDeploymentConfigSpec{ CustomizedVariables: []addonapiv1alpha1.CustomizedVariable{ - { - Name: "metricsDisabled", - Value: "true", - }, { Name: "loggingDisabled", Value: "true", diff --git a/internal/addon/manifests/charts/mcoa/Chart.yaml b/internal/addon/manifests/charts/mcoa/Chart.yaml index 0842491..638e6e8 100644 --- a/internal/addon/manifests/charts/mcoa/Chart.yaml +++ b/internal/addon/manifests/charts/mcoa/Chart.yaml @@ -5,9 +5,6 @@ version: 1.0.0 appVersion: "1.0.0" dependencies: -- name: metrics - repository: 'file://./charts/metrics' - condition: metrics.enabled - name: logging repository: 'file://./charts/logging' condition: logging.enabled diff --git a/internal/addon/manifests/charts/mcoa/charts/metrics/Chart.yaml b/internal/addon/manifests/charts/mcoa/charts/metrics/Chart.yaml deleted file mode 100644 index 31ab298..0000000 --- a/internal/addon/manifests/charts/mcoa/charts/metrics/Chart.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: v2 -description: A Helm chart for installing metrics collection and forwarding -name: metrics -version: 1.0.0 -appVersion: "1.0.0" diff --git a/internal/addon/manifests/charts/mcoa/charts/metrics/templates/_helpers.tpl b/internal/addon/manifests/charts/mcoa/charts/metrics/templates/_helpers.tpl deleted file mode 100644 index 0dc0412..0000000 --- a/internal/addon/manifests/charts/mcoa/charts/metrics/templates/_helpers.tpl +++ /dev/null @@ -1,17 +0,0 @@ - -{{- define "metricshelm.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - - -{{- define "metricshelm.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* Generate basic labels */}} -{{- define "metricshelm.labels" }} -app: {{ template "metricshelm.name" . }} -chart: {{ template "metricshelm.chart" . }} -release: {{ .Release.Name }} -app.kubernetes.io/part-of: multicluster-observability-addon -{{- end }} diff --git a/internal/addon/manifests/charts/mcoa/charts/metrics/templates/clusterrolebinding.yaml b/internal/addon/manifests/charts/mcoa/charts/metrics/templates/clusterrolebinding.yaml deleted file mode 100644 index e6e8c10..0000000 --- a/internal/addon/manifests/charts/mcoa/charts/metrics/templates/clusterrolebinding.yaml +++ /dev/null @@ -1,16 +0,0 @@ -{{- if .Values.enabled }} -kind: ClusterRoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: multicluster-observability-addon:metrics:agent - labels: - {{- include "metricshelm.labels" . | indent 4 }} -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: multicluster-observability-addon:metrics:agent -subjects: - - kind: ServiceAccount - name: multicluster-observability-metrics - namespace: open-cluster-management-addon-observability -{{- end }} diff --git a/internal/addon/manifests/charts/mcoa/charts/metrics/templates/configmap.yaml b/internal/addon/manifests/charts/mcoa/charts/metrics/templates/configmap.yaml deleted file mode 100644 index 4a4e25d..0000000 --- a/internal/addon/manifests/charts/mcoa/charts/metrics/templates/configmap.yaml +++ /dev/null @@ -1,103 +0,0 @@ -{{- if .Values.enabled }} -kind: ConfigMap -apiVersion: v1 -metadata: - name: prometheus-agent-conf - namespace: open-cluster-management-addon-observability - labels: - {{- include "metricshelm.labels" . | indent 4 }} -data: - prometheus.yml: |- - global: - scrape_interval: 5s - evaluation_interval: 5s - - scrape_configs: - - job_name: 'federate' - scrape_interval: 4m - - honor_labels: true - metrics_path: '/federate' - - scheme: https - tls_config: - ca_file: /etc/serving-certs-ca-bundle/service-ca.crt - bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token - - params: - 'match[]': - - '{__name__="up"}' - - '{__name__=":node_memory_MemAvailable_bytes:sum"}' - - '{__name__="cluster:capacity_cpu_cores:sum"}' - - '{__name__="cluster:capacity_memory_bytes:sum"}' - - '{__name__="cluster:container_cpu_usage:ratio"}' - - '{__name__="cluster:container_spec_cpu_shares:ratio"}' - - '{__name__="cluster:cpu_usage_cores:sum"}' - - '{__name__="cluster:memory_usage:ratio"}' - - '{__name__="cluster:memory_usage_bytes:sum"}' - - '{__name__="cluster:usage:resources:sum"}' - - '{__name__="cluster_infrastructure_provider"}' - - '{__name__="cluster_version"}' - - '{__name__="cluster_version_payload"}' - - '{__name__="container_cpu_cfs_throttled_periods_total"}' - - '{__name__="container_memory_cache"}' - - '{__name__="container_memory_rss"}' - - '{__name__="container_memory_swap"}' - - '{__name__="container_memory_working_set_bytes"}' - - '{__name__="container_network_receive_bytes_total"}' - - '{__name__="container_network_receive_packets_dropped_total"}' - - '{__name__="container_network_receive_packets_total"}' - - '{__name__="container_network_transmit_bytes_total"}' - - '{__name__="container_network_transmit_packets_dropped_total"}' - - '{__name__="container_network_transmit_packets_total"}' - - '{__name__="haproxy_backend_connections_total"}' - - '{__name__="instance:node_cpu_utilisation:rate1m"}' - - '{__name__="instance:node_load1_per_cpu:ratio"}' - - '{__name__="instance:node_memory_utilisation:ratio"}' - - '{__name__="instance:node_network_receive_bytes_excluding_lo:rate1m"}' - - '{__name__="instance:node_network_receive_drop_excluding_lo:rate1m",}' - - '{__name__="instance:node_network_transmit_bytes_excluding_lo:rate1m"}' - - '{__name__="instance:node_network_transmit_drop_excluding_lo:rate1m"}' - - '{__name__="instance:node_num_cpu:sum"}' - - '{__name__="instance:node_vmstat_pgmajfault:rate1m"}' - - '{__name__="instance_device:node_disk_io_time_seconds:rate1m"}' - - '{__name__="instance_device:node_disk_io_time_weighted_seconds:rate1m"}' - - '{__name__="kube_node_status_allocatable_cpu_cores"}' - - '{__name__="kube_node_status_allocatable_memory_bytes"}' - - '{__name__="kube_pod_container_resource_limits_cpu_cores"}' - - '{__name__="kube_pod_container_resource_limits_memory_bytes"}' - - '{__name__="kube_pod_container_resource_requests_cpu_cores"}' - - '{__name__="kube_pod_container_resource_requests_memory_bytes"}' - - '{__name__="kube_pod_info"}' - - '{__name__="kube_resourcequota"}' - - '{__name__="machine_cpu_cores"}' - - '{__name__="machine_memory_bytes"}' - - '{__name__="mixin_pod_workload"}' - - '{__name__="node_cpu_seconds_total"}' - - '{__name__="node_filesystem_avail_bytes"}' - - '{__name__="node_filesystem_size_bytes"}' - - '{__name__="node.oc_memory_MemAvailable_bytes"}' - - '{__name__="node_namespace_pod_container:container_cpu_usage_seconds_total:sum_rate"}' - - '{__name__="node_namespace_pod_container:container_memory_cache"}' - - '{__name__="node_namespace_pod_container:container_memory_rss"}' - - '{__name__="node_namespace_pod_container:container_memory_swap"}' - - '{__name__="node_namespace_pod_container:container_memory_working_set_bytes"}' - - '{__name__="node_netstat_Tcp_OutSegs"}' - - '{__name__="node_netstat_Tcp_RetransSegs"}' - - '{__name__="node_netstat_TcpExt_TCPSynRetrans"}' - - static_configs: - - targets: - - 'prometheus-k8s.openshift-monitoring.svc:9092' - labels: - prometheus_agent: "true" - - remote_write: - - url: {{ .Values.destinationEndpoint }} - metadata_config: - send: false - tls_config: - ca_file: /tlscerts/ca/ca.crt - cert_file: /tlscerts/certs/tls.crt - key_file: /tlscerts/certs/tls.key -{{- end }} diff --git a/internal/addon/manifests/charts/mcoa/charts/metrics/templates/deployment.yaml b/internal/addon/manifests/charts/mcoa/charts/metrics/templates/deployment.yaml deleted file mode 100644 index a06ace7..0000000 --- a/internal/addon/manifests/charts/mcoa/charts/metrics/templates/deployment.yaml +++ /dev/null @@ -1,82 +0,0 @@ -{{- if .Values.enabled }} -kind: Deployment -apiVersion: apps/v1 -metadata: - name: metrics-addon-agent - namespace: open-cluster-management-addon-observability - labels: - {{- include "metricshelm.labels" . | indent 4 }} - app.kubernetes.io/component: metrics-agent -spec: - replicas: 1 - selector: - matchLabels: - {{- include "metricshelm.labels" . | indent 6 }} - app.kubernetes.io/component: metrics-agent - template: - metadata: - labels: - {{- include "metricshelm.labels" . | indent 8 }} - app.kubernetes.io/component: metrics-agent - spec: - serviceAccountName: multicluster-observability-metrics - volumes: - - name: prometheus-config-volume - configMap: - name: prometheus-agent-conf - defaultMode: 420 - - name: prometheus-storage-volume - emptyDir: {} - - name: serving-certs-ca-bundle - configMap: - name: metrics-collector-serving-certs-ca-bundle - - name: mtlsca - secret: - secretName: observability-managed-cluster-certs - - name: mtlscerts - secret: - secretName: observability-controller-open-cluster-management.io-observability-signer-client-cert - dnsPolicy: ClusterFirst - terminationGracePeriodSeconds: 30 - containers: - - name: prometheus-agent - ports: - - containerPort: 9090 - protocol: TCP - resources: - requests: - cpu: 500m - memory: 500M - limits: - cpu: 1 - memory: 1Gi - imagePullPolicy: IfNotPresent - securityContext: {} - terminationMessagePath: /dev/termination-log - terminationMessagePolicy: File - volumeMounts: - - name: prometheus-config-volume - mountPath: /etc/prometheus/ - - name: prometheus-storage-volume - mountPath: /prometheus/ - - name: mtlscerts - readOnly: true - mountPath: /tlscerts/certs - - name: mtlsca - readOnly: true - mountPath: /tlscerts/ca - - name: serving-certs-ca-bundle - mountPath: /etc/serving-certs-ca-bundle - readOnly: true - image: "quay.io/prometheus/prometheus:v2.48.1" - args: - - "--log.level=debug" - - "--config.file=/etc/prometheus/prometheus.yml" - - "--web.enable-lifecycle" - - "--enable-feature=agent" - strategy: - type: RollingUpdate - rollingUpdate: - maxUnavailable: 25% - maxSurge: 25% -{{- end }} diff --git a/internal/addon/manifests/charts/mcoa/charts/metrics/templates/role.yaml b/internal/addon/manifests/charts/mcoa/charts/metrics/templates/role.yaml deleted file mode 100644 index f53835c..0000000 --- a/internal/addon/manifests/charts/mcoa/charts/metrics/templates/role.yaml +++ /dev/null @@ -1,24 +0,0 @@ -{{- if .Values.enabled }} -kind: ClusterRole -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: multicluster-observability-addon:metrics:agent - labels: - {{- include "metricshelm.labels" . | indent 4 }} -rules: - - apiGroups: [""] - resources: - - nodes - - nodes/proxy - - services - - endpoints - - pods - verbs: ["get", "list", "watch"] - - apiGroups: - - extensions - resources: - - ingresses - verbs: ["get", "list", "watch"] - - nonResourceURLs: ["/federate"] - verbs: ["get"] -{{- end }} diff --git a/internal/addon/manifests/charts/mcoa/charts/metrics/templates/serviceaccount.yaml b/internal/addon/manifests/charts/mcoa/charts/metrics/templates/serviceaccount.yaml deleted file mode 100644 index ca6bd55..0000000 --- a/internal/addon/manifests/charts/mcoa/charts/metrics/templates/serviceaccount.yaml +++ /dev/null @@ -1,9 +0,0 @@ -{{- if .Values.enabled }} -kind: ServiceAccount -apiVersion: v1 -metadata: - name: multicluster-observability-metrics - namespace: open-cluster-management-addon-observability - labels: - {{- include "metricshelm.labels" . | indent 4 }} -{{- end }} diff --git a/internal/addon/manifests/charts/mcoa/charts/metrics/values.yaml b/internal/addon/manifests/charts/mcoa/charts/metrics/values.yaml deleted file mode 100644 index a0d94fa..0000000 --- a/internal/addon/manifests/charts/mcoa/charts/metrics/values.yaml +++ /dev/null @@ -1,3 +0,0 @@ -nameOverride: null -enabled: true -destinationEndpoint: "" diff --git a/internal/addon/manifests/charts/mcoa/values.yaml b/internal/addon/manifests/charts/mcoa/values.yaml index abb967e..d6fd194 100644 --- a/internal/addon/manifests/charts/mcoa/values.yaml +++ b/internal/addon/manifests/charts/mcoa/values.yaml @@ -2,9 +2,6 @@ nameOverride: null enabled: true -metrics: - enabled: true - logging: enabled: true diff --git a/internal/addon/var.go b/internal/addon/var.go index 8291147..79be9db 100644 --- a/internal/addon/var.go +++ b/internal/addon/var.go @@ -9,13 +9,11 @@ const ( InstallNamespace = "open-cluster-management" McoaChartDir = "manifests/charts/mcoa" - MetricsChartDir = "manifests/charts/mcoa/charts/metrics" LoggingChartDir = "manifests/charts/mcoa/charts/logging" TracingChartDir = "manifests/charts/mcoa/charts/tracing" AddonDeploymentConfigResource = "addondeploymentconfigs" - AdcMetricsDisabledKey = "metricsDisabled" AdcLoggingDisabledKey = "loggingDisabled" AdcTracingisabledKey = "tracingDisabled" ) @@ -24,6 +22,5 @@ const ( //go:embed manifests/charts/mcoa //go:embed manifests/charts/mcoa/templates/_helpers.tpl //go:embed manifests/charts/mcoa/charts/logging/templates/_helpers.tpl -//go:embed manifests/charts/mcoa/charts/metrics/templates/_helpers.tpl //go:embed manifests/charts/mcoa/charts/tracing/templates/_helpers.tpl var FS embed.FS diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go deleted file mode 100644 index 72e49fc..0000000 --- a/internal/metrics/metrics.go +++ /dev/null @@ -1,58 +0,0 @@ -package metrics - -import ( - "context" - "fmt" - - routev1 "github.com/openshift/api/route/v1" - "k8s.io/apimachinery/pkg/types" - addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1" - clusterv1 "open-cluster-management.io/api/cluster/v1" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -type MetricsValues struct { - Enabled bool `json:"enabled"` - // TODO: revert this hack to the official way as recommended by the docs. - // See https://open-cluster-management.io/developer-guides/addon/#values-definition. - AddonInstallNamespace string `json:"addonInstallNamespace"` - DestinationEndpoint string `json:"destinationEndpoint"` -} - -func GetValuesFunc( - k8sClient client.Client, - _ *clusterv1.ManagedCluster, - mca *addonapiv1alpha1.ManagedClusterAddOn, - adoc *addonapiv1alpha1.AddOnDeploymentConfig, -) (MetricsValues, error) { - endpoint, err := getDestinationEndpoint(k8sClient, adoc) - if err != nil { - return MetricsValues{}, fmt.Errorf("failed to get metrics destination endpoint: %w", err) - } - values := MetricsValues{ - Enabled: true, - AddonInstallNamespace: mca.Spec.InstallNamespace, - DestinationEndpoint: endpoint, - } - return values, nil -} - -func getDestinationEndpoint(k8sClient client.Client, adoc *addonapiv1alpha1.AddOnDeploymentConfig) (string, error) { - if adoc != nil { - for _, customVar := range adoc.Spec.CustomizedVariables { - if customVar.Name == "metricsDestinationEndpoint" { - return customVar.Value, nil - } - } - } - - route := &routev1.Route{} - err := k8sClient.Get(context.TODO(), types.NamespacedName{ - Namespace: "open-cluster-management-observability", - Name: "observatorium-api", - }, route) - if err != nil { - return "", err - } - return fmt.Sprintf("https://%s/api/metrics/v1/default/api/v1/receive", route.Spec.Host), nil -} diff --git a/internal/metrics/metrics_test.go b/internal/metrics/metrics_test.go deleted file mode 100644 index 891d17a..0000000 --- a/internal/metrics/metrics_test.go +++ /dev/null @@ -1,103 +0,0 @@ -package metrics - -import ( - "testing" - - v1 "k8s.io/api/apps/v1" - - "github.com/rhobs/multicluster-observability-addon/internal/addon" - - operatorsv1 "github.com/operator-framework/api/pkg/operators/v1" - operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" - "github.com/stretchr/testify/require" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/klog/v2" - "open-cluster-management.io/addon-framework/pkg/addonfactory" - "open-cluster-management.io/addon-framework/pkg/addonmanager/addontesting" - "open-cluster-management.io/addon-framework/pkg/agent" - addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1" - fakeaddon "open-cluster-management.io/api/client/addon/clientset/versioned/fake" - clusterv1 "open-cluster-management.io/api/cluster/v1" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -var ( - _ = operatorsv1.AddToScheme(scheme.Scheme) - _ = operatorsv1alpha1.AddToScheme(scheme.Scheme) -) - -func testingGetValues(k8s client.Client) addonfactory.GetValuesFunc { - return func( - cluster *clusterv1.ManagedCluster, - addon *addonapiv1alpha1.ManagedClusterAddOn, - ) (addonfactory.Values, error) { - logging, err := GetValuesFunc(k8s, cluster, addon, nil) - if err != nil { - return nil, err - } - - return addonfactory.JsonStructToValues(logging) - } -} - -func Test_GenerateManagedClusterResources(t *testing.T) { - var ( - managedCluster *clusterv1.ManagedCluster - managedClusterAddOn *addonapiv1alpha1.ManagedClusterAddOn - addOnDeploymentConfig *addonapiv1alpha1.AddOnDeploymentConfig - ) - - managedCluster = addontesting.NewManagedCluster("cluster1") - managedClusterAddOn = addontesting.NewAddon("test", "cluster1") - - managedClusterAddOn.Status.ConfigReferences = []addonapiv1alpha1.ConfigReference{ - { - ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{ - Group: "addon.open-cluster-management.io", - Resource: "addondeploymentconfigs", - }, - ConfigReferent: addonapiv1alpha1.ConfigReferent{ - Namespace: "open-cluster-management", - Name: "multicluster-observability-addon", - }, - }, - } - - addOnDeploymentConfig = &addonapiv1alpha1.AddOnDeploymentConfig{ - ObjectMeta: metav1.ObjectMeta{ - Name: "multicluster-observability-addon", - Namespace: "open-cluster-management", - }, - Spec: addonapiv1alpha1.AddOnDeploymentConfigSpec{ - CustomizedVariables: []addonapiv1alpha1.CustomizedVariable{}, - }, - } - - fakeAddonClient := fakeaddon.NewSimpleClientset(addOnDeploymentConfig) - addonConfigValuesFn := addonfactory.GetAddOnDeploymentConfigValues( - addonfactory.NewAddOnDeploymentConfigGetter(fakeAddonClient), - addonfactory.ToAddOnCustomizedVariableValues, - ) - - metricsAgentAddon, err := addonfactory.NewAgentAddonFactory(addon.Name, addon.FS, "manifests/charts/mcoa/charts/metrics"). - WithGetValuesFuncs(addonConfigValuesFn). - WithAgentRegistrationOption(&agent.RegistrationOption{}). - WithScheme(scheme.Scheme). - BuildHelmAgentAddon() - if err != nil { - klog.Fatalf("failed to build agent %v", err) - } - - objects, err := metricsAgentAddon.Manifests(managedCluster, managedClusterAddOn) - require.NoError(t, err) - require.Equal(t, 5, len(objects)) - - for _, obj := range objects { - switch obj := obj.(type) { - // TODO: check the generated objects - case *v1.Deployment: - require.Equal(t, obj.Name, "metrics-addon-agent") - } - } -} diff --git a/main.go b/main.go index 5b84734..f96e87a 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,6 @@ import ( "time" otelv1alpha1 "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - routev1 "github.com/openshift/api/route/v1" loggingapis "github.com/openshift/cluster-logging-operator/apis" operatorsv1 "github.com/operator-framework/api/pkg/operators/v1" operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" @@ -117,10 +116,6 @@ func runController(ctx context.Context, kubeConfig *rest.Config) error { if err != nil { return err } - // Necessary for metrics to get Routes hosts - if err = routev1.Install(scheme.Scheme); err != nil { - return err - } // Reconcile AddOnDeploymentConfig err = addonapiv1alpha1.AddToScheme(scheme.Scheme)