Skip to content

Commit

Permalink
dynamic supported configs
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Mange <[email protected]>
  • Loading branch information
thibaultmg committed Nov 25, 2024
1 parent 413717f commit c1e846f
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,6 @@ spec:
defaultConfig:
name: multicluster-observability-addon
namespace: open-cluster-management-observability
# Describes the default log forwarding outputs for each log type applied to all managed clusters.
- group: observability.openshift.io
resource: clusterlogforwarders
# Describes the default OpenTelemetryCollector type applied to all managed clusters.
- group: opentelemetry.io
resource: opentelemetrycollectors
# Describes the default Instrumentation type applied to all managed clusters.
- group: opentelemetry.io
resource: instrumentations
# Metrics forwarding configuration types.
- group: monitoring.coreos.com
resource: prometheusagents
- group: monitoring.coreos.com
resource: scrapeconfigs
- group: monitoring.coreos.com
resource: prometheusrules
- group: ""
resource: configmaps # For the proxy sidecar configuration of the prometheus agent
installStrategy:
type: Placements
placements:
Expand Down
115 changes: 115 additions & 0 deletions operators/multiclusterobservability/pkg/rendering/renderer_mcoa.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"context"
"fmt"

prometheusv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
prometheusalpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -168,6 +170,119 @@ func (r *MCORenderer) renderClusterManagementAddOn(
}
u.SetLabels(cLabels)

cma := &addonapiv1alpha1.ClusterManagementAddOn{}
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, cma); err != nil {
return nil, err
}

// Add default platform configs
if r.cr.Spec.Capabilities.Platform != nil {
if r.cr.Spec.Capabilities.Platform.Logs.Collection.Enabled {
cma.Spec.SupportedConfigs = append(cma.Spec.SupportedConfigs, addonapiv1alpha1.ConfigMeta{
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{
Group: "observability.openshift.io",
Resource: "clusterlogforwarders",
},
DefaultConfig: &addonapiv1alpha1.ConfigReferent{
Name: "instance",
Namespace: mcoconfig.GetDefaultNamespace(),
},
})
}

if r.cr.Spec.Capabilities.Platform.Metrics.Collection.Enabled {
cma.Spec.SupportedConfigs = append(cma.Spec.SupportedConfigs, addonapiv1alpha1.ConfigMeta{
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{
Group: prometheusalpha1.SchemeGroupVersion.Group,
Resource: prometheusalpha1.PrometheusAgentName,
},
DefaultConfig: &addonapiv1alpha1.ConfigReferent{
Name: "acm-platform-metrics-collector-default",
Namespace: mcoconfig.GetDefaultNamespace(),
},
})
cma.Spec.SupportedConfigs = append(cma.Spec.SupportedConfigs, addonapiv1alpha1.ConfigMeta{
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{
Resource: "configmaps",
},
DefaultConfig: &addonapiv1alpha1.ConfigReferent{
Name: "acm-platform-metrics-collector-default-envoy-config",
Namespace: mcoconfig.GetDefaultNamespace(),
},
})
cma.Spec.SupportedConfigs = append(cma.Spec.SupportedConfigs, addonapiv1alpha1.ConfigMeta{
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{
Group: prometheusalpha1.SchemeGroupVersion.Group,
Resource: prometheusalpha1.ScrapeConfigName,
},
DefaultConfig: &addonapiv1alpha1.ConfigReferent{
Name: "platform-metrics-default",
Namespace: mcoconfig.GetDefaultNamespace(),
},
})
cma.Spec.SupportedConfigs = append(cma.Spec.SupportedConfigs, addonapiv1alpha1.ConfigMeta{
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{
Group: prometheusv1.SchemeGroupVersion.Group,
Resource: prometheusv1.PrometheusRuleName,
},
DefaultConfig: &addonapiv1alpha1.ConfigReferent{
Name: "platform-rules-default",
Namespace: mcoconfig.GetDefaultNamespace(),
},
})
}

}

if r.cr.Spec.Capabilities.UserWorkloads != nil {
if r.cr.Spec.Capabilities.UserWorkloads.Metrics.Collection.Enabled {
cma.Spec.SupportedConfigs = append(cma.Spec.SupportedConfigs, addonapiv1alpha1.ConfigMeta{
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{
Group: prometheusalpha1.SchemeGroupVersion.Group,
Resource: prometheusalpha1.PrometheusAgentName,
},
DefaultConfig: &addonapiv1alpha1.ConfigReferent{
Name: "acm-user-workload-metrics-collector-default",
Namespace: mcoconfig.GetDefaultNamespace(),
},
})
cma.Spec.SupportedConfigs = append(cma.Spec.SupportedConfigs, addonapiv1alpha1.ConfigMeta{
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{
Resource: "configmaps",
},
DefaultConfig: &addonapiv1alpha1.ConfigReferent{
Name: "acm-user-workload-metrics-collector-default-envoy-config",
Namespace: mcoconfig.GetDefaultNamespace(),
},
})
}

if r.cr.Spec.Capabilities.UserWorkloads.Traces.Collection.Collector.Enabled {
cma.Spec.SupportedConfigs = append(cma.Spec.SupportedConfigs, addonapiv1alpha1.ConfigMeta{
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{
Group: "opentelemetry.io",
Resource: "opentelemetrycollectors",
},
DefaultConfig: &addonapiv1alpha1.ConfigReferent{
Name: "instance",
Namespace: mcoconfig.GetDefaultNamespace(),
},
})
}

if r.cr.Spec.Capabilities.UserWorkloads.Traces.Collection.Instrumentation.Enabled {
cma.Spec.SupportedConfigs = append(cma.Spec.SupportedConfigs, addonapiv1alpha1.ConfigMeta{
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{
Group: "opentelemetry.io",
Resource: "instrumentations",
},
DefaultConfig: &addonapiv1alpha1.ConfigReferent{
Name: "instance",
Namespace: mcoconfig.GetDefaultNamespace(),
},
})
}
}
return u, nil
}

Expand Down

0 comments on commit c1e846f

Please sign in to comment.