From f520d66018bf51da185f8a45855733bddf9d2ea4 Mon Sep 17 00:00:00 2001 From: Andreas Thaler Date: Tue, 4 Feb 2025 18:17:30 +0100 Subject: [PATCH] renamed constants --- internal/resources/common/annotations.go | 24 +++---- internal/resources/common/labels.go | 64 +++++++++---------- internal/resources/fluentbit/resources.go | 32 +++++----- internal/resources/otelcollector/agent.go | 22 +++---- internal/resources/otelcollector/core.go | 8 +-- internal/resources/otelcollector/gateway.go | 40 ++++++------ internal/resources/otelcollector/rbac.go | 8 +-- .../otelcollector/testdata/metric-agent.yaml | 2 + internal/resources/selfmonitor/resources.go | 4 +- internal/utils/k8s/utils.go | 2 +- internal/utils/k8s/utils_test.go | 19 +++--- main.go | 2 +- 12 files changed, 113 insertions(+), 114 deletions(-) diff --git a/internal/resources/common/annotations.go b/internal/resources/common/annotations.go index b5f8edff8..05391e3c7 100644 --- a/internal/resources/common/annotations.go +++ b/internal/resources/common/annotations.go @@ -1,18 +1,18 @@ package common const ( - ChecksumConfigAnnotationKey = "checksum/config" + AnnotationKeyChecksumConfig = "checksum/config" - IstioExcludeInboundPortsAnnotationKey = "traffic.sidecar.istio.io/excludeInboundPorts" - IstioIncludeOutboundPortsAnnotationKey = "traffic.sidecar.istio.io/includeOutboundPorts" - IstioIncludeOutboundIPRangesAnnotationKey = "traffic.sidecar.istio.io/includeOutboundIPRanges" - IstioUserVolumeMountAnnotationKey = "sidecar.istio.io/userVolumeMount" - IstioInterceptionModeAnnotationKey = "sidecar.istio.io/interceptionMode" - IstioInterceptionModeAnnotationValue = "TPROXY" - IstioProxyConfigAnnotationKey = "proxy.istio.io/config" + AnnotationKeyIstioExcludeInboundPorts = "traffic.sidecar.istio.io/excludeInboundPorts" + AnnotationKeyIstioIncludeOutboundPorts = "traffic.sidecar.istio.io/includeOutboundPorts" + AnnotationKeyIstioIncludeOutboundIPRanges = "traffic.sidecar.istio.io/includeOutboundIPRanges" + AnnotationKeyIstioUserVolumeMount = "sidecar.istio.io/userVolumeMount" + AnnotationKeyIstioInterceptionMode = "sidecar.istio.io/interceptionMode" + AnnotationValueIstioInterceptionModeTProxy = "TPROXY" + AnnotationKeyIstioProxyConfig = "proxy.istio.io/config" - PrometheusScrapeAnnotationKey = "prometheus.io/scrape" - PrometheusPortAnnotationKey = "prometheus.io/port" - PrometheusSchemeAnnotationKey = "prometheus.io/scheme" - PrometheusPathAnnotationKey = "prometheus.io/path" + AnnotationKeyPrometheusScrape = "prometheus.io/scrape" + AnnotationKeyPrometheusPort = "prometheus.io/port" + AnnotationKeyPrometheusScheme = "prometheus.io/scheme" + AnnotationKeyPrometheusPath = "prometheus.io/path" ) diff --git a/internal/resources/common/labels.go b/internal/resources/common/labels.go index f964d2623..42adc9d24 100644 --- a/internal/resources/common/labels.go +++ b/internal/resources/common/labels.go @@ -1,49 +1,49 @@ package common const ( - KymaModuleLabelKey = "kyma-project.io/module" - KymaModuleLabelValue = "telemetry" + LabelKeyKymaModule = "kyma-project.io/module" + LabelValueKymaModule = "telemetry" - K8sNameLabelKey = "app.kubernetes.io/name" - K8sPartOfLabelKey = "app.kubernetes.io/part-of" - K8sPartOfLabelValue = "telemetry" - K8sManagedByLabelKey = "app.kubernetes.io/managed-by" - K8sManagedByLabelValue = "telemetry-manager" - K8sComponentLabelKey = "app.kubernetes.io/component" - K8sComponentLabelValueController = "controller" - K8sComponentLabelValueAgent = "agent" - K8sComponentLabelValueGateway = "gateway" - K8sComponentLabelValueMonitor = "monitor" - K8sInstanceLabelKey = "app.kubernetes.io/instance" - K8sInstanceLabelValue = "telemetry" - K8sHostnameLabelKey = "kubernetes.io/hostname" - K8sZoneLabelKey = "topology.kubernetes.io/zone" + LabelKeyK8sName = "app.kubernetes.io/name" + LabelKeyK8sPartOf = "app.kubernetes.io/part-of" + LabelValueK8sPartOf = "telemetry" + LabelKeyK8sManagedBy = "app.kubernetes.io/managed-by" + LabelValueK8sManagedBy = "telemetry-manager" + LabelKeyK8sComponent = "app.kubernetes.io/component" + LabelValueK8sComponentController = "controller" + LabelValueK8sComponentAgent = "agent" + LabelValueK8sComponentGateway = "gateway" + LabelValueK8sComponentMonitor = "monitor" + LabelKeyK8sInstance = "app.kubernetes.io/instance" + LabelValueK8sInstance = "telemetry" + LabelKeyK8sHostname = "kubernetes.io/hostname" + LabelKeyK8sZone = "topology.kubernetes.io/zone" - IstioInjectLabelKey = "sidecar.istio.io/inject" + LabelKeyIstioInject = "sidecar.istio.io/inject" - TelemetryLogIngestLabelKey = "telemetry.kyma-project.io/log-ingest" - TelemetryLogExportLabelKey = "telemetry.kyma-project.io/log-export" - TelemetryTraceIngestLabelKey = "telemetry.kyma-project.io/trace-ingest" - TelemetryTraceExportLabelKey = "telemetry.kyma-project.io/trace-export" - TelemetryMetricIngestLabelKey = "telemetry.kyma-project.io/metric-ingest" - TelemetryMetricExportLabelKey = "telemetry.kyma-project.io/metric-export" - TelemetryMetricScrapeLabelKey = "telemetry.kyma-project.io/metric-scrape" - TelemetrySelfMonitorLabelKey = "telemetry.kyma-project.io/self-monitor" - TelemetrySelfMonitorLabelValue = "enabled" + LabelKeyTelemetryLogIngest = "telemetry.kyma-project.io/log-ingest" + LabelKeyTelemetryLogExport = "telemetry.kyma-project.io/log-export" + LabelKeyTelemetryTraceIngest = "telemetry.kyma-project.io/trace-ingest" + LabelKeyTelemetryTraceExport = "telemetry.kyma-project.io/trace-export" + LabelKeyTelemetryMetricIngest = "telemetry.kyma-project.io/metric-ingest" + LabelKeyTelemetryMetricExport = "telemetry.kyma-project.io/metric-export" + LabelKeyTelemetryMetricScrape = "telemetry.kyma-project.io/metric-scrape" + LabelKeyTelemetrySelfMonitor = "telemetry.kyma-project.io/self-monitor" + LabelValueTelemetrySelfMonitor = "enabled" ) func MakeDefaultLabels(baseName string, componentLabelValue string) map[string]string { return map[string]string{ - K8sNameLabelKey: baseName, - KymaModuleLabelKey: KymaModuleLabelValue, - K8sPartOfLabelKey: K8sPartOfLabelValue, - K8sManagedByLabelKey: K8sManagedByLabelValue, - K8sComponentLabelKey: componentLabelValue, + LabelKeyK8sName: baseName, + LabelKeyKymaModule: LabelValueKymaModule, + LabelKeyK8sPartOf: LabelValueK8sPartOf, + LabelKeyK8sManagedBy: LabelValueK8sManagedBy, + LabelKeyK8sComponent: componentLabelValue, } } func MakeDefaultSelectorLabels(baseName string) map[string]string { return map[string]string{ - K8sNameLabelKey: baseName, + LabelKeyK8sName: baseName, } } diff --git a/internal/resources/fluentbit/resources.go b/internal/resources/fluentbit/resources.go index fa1346708..a48dca391 100644 --- a/internal/resources/fluentbit/resources.go +++ b/internal/resources/fluentbit/resources.go @@ -51,12 +51,12 @@ func MakeDaemonSet(name types.NamespacedName, checksum string, dsConfig DaemonSe } annotations := make(map[string]string) - annotations[commonresources.ChecksumConfigAnnotationKey] = checksum - annotations[commonresources.IstioExcludeInboundPortsAnnotationKey] = fmt.Sprintf("%v,%v", ports.HTTP, ports.ExporterMetrics) + annotations[commonresources.AnnotationKeyChecksumConfig] = checksum + annotations[commonresources.AnnotationKeyIstioExcludeInboundPorts] = fmt.Sprintf("%v,%v", ports.HTTP, ports.ExporterMetrics) podLabels := Labels() - podLabels[commonresources.IstioInjectLabelKey] = "true" - podLabels[commonresources.TelemetryLogExportLabelKey] = "true" + podLabels[commonresources.LabelKeyIstioInject] = "true" + podLabels[commonresources.LabelKeyTelemetryLogExport] = "true" return &appsv1.DaemonSet{ TypeMeta: metav1.TypeMeta{}, @@ -267,7 +267,7 @@ func MakeClusterRole(name types.NamespacedName) *rbacv1.ClusterRole { func MakeMetricsService(name types.NamespacedName) *corev1.Service { serviceLabels := Labels() - serviceLabels[commonresources.TelemetrySelfMonitorLabelKey] = commonresources.TelemetrySelfMonitorLabelValue + serviceLabels[commonresources.LabelKeyTelemetrySelfMonitor] = commonresources.LabelValueTelemetrySelfMonitor return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -275,10 +275,10 @@ func MakeMetricsService(name types.NamespacedName) *corev1.Service { Namespace: name.Namespace, Labels: serviceLabels, Annotations: map[string]string{ - commonresources.PrometheusScrapeAnnotationKey: "true", - commonresources.PrometheusPortAnnotationKey: strconv.Itoa(ports.HTTP), - commonresources.PrometheusSchemeAnnotationKey: "http", - commonresources.PrometheusPathAnnotationKey: "/api/v2/metrics/prometheus", + commonresources.AnnotationKeyPrometheusScrape: "true", + commonresources.AnnotationKeyPrometheusPort: strconv.Itoa(ports.HTTP), + commonresources.AnnotationKeyPrometheusScheme: "http", + commonresources.AnnotationKeyPrometheusPath: "/api/v2/metrics/prometheus", }, }, Spec: corev1.ServiceSpec{ @@ -298,7 +298,7 @@ func MakeMetricsService(name types.NamespacedName) *corev1.Service { func MakeExporterMetricsService(name types.NamespacedName) *corev1.Service { serviceLabels := Labels() - serviceLabels[commonresources.TelemetrySelfMonitorLabelKey] = commonresources.TelemetrySelfMonitorLabelValue + serviceLabels[commonresources.LabelKeyTelemetrySelfMonitor] = commonresources.LabelValueTelemetrySelfMonitor return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -306,9 +306,9 @@ func MakeExporterMetricsService(name types.NamespacedName) *corev1.Service { Namespace: name.Namespace, Labels: serviceLabels, Annotations: map[string]string{ - commonresources.PrometheusScrapeAnnotationKey: "true", - commonresources.PrometheusPortAnnotationKey: strconv.Itoa(ports.ExporterMetrics), - commonresources.PrometheusSchemeAnnotationKey: "http", + commonresources.AnnotationKeyPrometheusScrape: "true", + commonresources.AnnotationKeyPrometheusPort: strconv.Itoa(ports.ExporterMetrics), + commonresources.AnnotationKeyPrometheusScheme: "http", }, }, Spec: corev1.ServiceSpec{ @@ -421,15 +421,15 @@ end } func Labels() map[string]string { - result := commonresources.MakeDefaultLabels("fluent-bit", commonresources.K8sComponentLabelValueAgent) - result[commonresources.K8sInstanceLabelKey] = commonresources.K8sInstanceLabelValue + result := commonresources.MakeDefaultLabels("fluent-bit", commonresources.LabelValueK8sComponentAgent) + result[commonresources.LabelKeyK8sInstance] = commonresources.LabelValueK8sInstance return result } func SelectorLabels() map[string]string { result := commonresources.MakeDefaultSelectorLabels("fluent-bit") - result[commonresources.K8sInstanceLabelKey] = commonresources.K8sInstanceLabelValue + result[commonresources.LabelKeyK8sInstance] = commonresources.LabelValueK8sInstance return result } diff --git a/internal/resources/otelcollector/agent.go b/internal/resources/otelcollector/agent.go index ade6d0a52..a08f9aad1 100644 --- a/internal/resources/otelcollector/agent.go +++ b/internal/resources/otelcollector/agent.go @@ -37,8 +37,8 @@ var ( func NewMetricAgentApplierDeleter(image, namespace, priorityClassName string) *AgentApplierDeleter { extraLabels := map[string]string{ - commonresources.TelemetryMetricScrapeLabelKey: "true", - commonresources.IstioInjectLabelKey: "true", // inject Istio sidecar for SDS certificates and agent-to-gateway communication + commonresources.LabelKeyTelemetryMetricScrape: "true", + commonresources.LabelKeyIstioInject: "true", // inject Istio sidecar for SDS certificates and agent-to-gateway communication } return &AgentApplierDeleter{ @@ -75,11 +75,11 @@ type AgentApplyOptions struct { func (aad *AgentApplierDeleter) ApplyResources(ctx context.Context, c client.Client, opts AgentApplyOptions) error { name := types.NamespacedName{Namespace: aad.namespace, Name: aad.baseName} - if err := applyCommonResources(ctx, c, name, commonresources.K8sComponentLabelValueAgent, aad.rbac, opts.AllowedPorts); err != nil { + if err := applyCommonResources(ctx, c, name, commonresources.LabelValueK8sComponentAgent, aad.rbac, opts.AllowedPorts); err != nil { return fmt.Errorf("failed to create common resource: %w", err) } - configMap := makeConfigMap(name, commonresources.K8sComponentLabelValueAgent, opts.CollectorConfigYAML) + configMap := makeConfigMap(name, commonresources.LabelValueK8sComponentAgent, opts.CollectorConfigYAML) if err := k8sutils.CreateOrUpdateConfigMap(ctx, c, configMap); err != nil { return fmt.Errorf("failed to create configmap: %w", err) } @@ -120,7 +120,7 @@ func (aad *AgentApplierDeleter) DeleteResources(ctx context.Context, c client.Cl } func (aad *AgentApplierDeleter) makeAgentDaemonSet(configChecksum string) *appsv1.DaemonSet { - annotations := map[string]string{commonresources.ChecksumConfigAnnotationKey: configChecksum} + annotations := map[string]string{commonresources.AnnotationKeyChecksumConfig: configChecksum} maps.Copy(annotations, makeIstioAnnotations(IstioCertPath)) resources := aad.makeAgentResourceRequirements() @@ -149,7 +149,7 @@ func (aad *AgentApplierDeleter) makeAgentDaemonSet(configChecksum string) *appsv podSpec := makePodSpec(aad.baseName, aad.image, opts...) selectorLabels := commonresources.MakeDefaultSelectorLabels(aad.baseName) - labels := commonresources.MakeDefaultLabels(aad.baseName, common.K8sComponentLabelValueAgent) + labels := commonresources.MakeDefaultLabels(aad.baseName, common.LabelValueK8sComponentAgent) podLabels := make(map[string]string) maps.Copy(podLabels, labels) maps.Copy(podLabels, aad.extraPodLabel) @@ -190,13 +190,13 @@ func (aad *AgentApplierDeleter) makeAgentResourceRequirements() corev1.ResourceR func makeIstioAnnotations(istioCertPath string) map[string]string { // Provision Istio certificates for Prometheus Receiver running as a part of MetricAgent by injecting a sidecar which will rotate SDS certificates and output them to a volume. However, the sidecar should not intercept scraping requests because Prometheus’s model of direct endpoint access is incompatible with Istio’s sidecar proxy model. return map[string]string{ - common.IstioProxyConfigAnnotationKey: fmt.Sprintf(`# configure an env variable OUTPUT_CERTS to write certificates to the given folder + common.AnnotationKeyIstioProxyConfig: fmt.Sprintf(`# configure an env variable OUTPUT_CERTS to write certificates to the given folder proxyMetadata: OUTPUT_CERTS: %s `, istioCertPath), - common.IstioUserVolumeMountAnnotationKey: fmt.Sprintf(`[{"name": "%s", "mountPath": "%s"}]`, istioCertVolumeName, istioCertPath), - common.IstioIncludeOutboundPortsAnnotationKey: strconv.Itoa(int(ports.OTLPGRPC)), - common.IstioExcludeInboundPortsAnnotationKey: strconv.Itoa(int(ports.Metrics)), - common.IstioIncludeOutboundIPRangesAnnotationKey: "", + common.AnnotationKeyIstioUserVolumeMount: fmt.Sprintf(`[{"name": "%s", "mountPath": "%s"}]`, istioCertVolumeName, istioCertPath), + common.AnnotationKeyIstioIncludeOutboundPorts: strconv.Itoa(int(ports.OTLPGRPC)), + common.AnnotationKeyIstioExcludeInboundPorts: strconv.Itoa(int(ports.Metrics)), + common.AnnotationKeyIstioIncludeOutboundIPRanges: "", } } diff --git a/internal/resources/otelcollector/core.go b/internal/resources/otelcollector/core.go index 0d3c0e7b3..9767594f2 100644 --- a/internal/resources/otelcollector/core.go +++ b/internal/resources/otelcollector/core.go @@ -155,7 +155,7 @@ func makeSecret(name types.NamespacedName, component string, secretData map[stri func makeMetricsService(name types.NamespacedName, component string) *corev1.Service { labels := commonresources.MakeDefaultLabels(name.Name, component) - labels[commonresources.TelemetrySelfMonitorLabelKey] = commonresources.TelemetrySelfMonitorLabelValue + labels[commonresources.LabelKeyTelemetrySelfMonitor] = commonresources.LabelValueTelemetrySelfMonitor selectorLabels := commonresources.MakeDefaultSelectorLabels(name.Name) @@ -165,9 +165,9 @@ func makeMetricsService(name types.NamespacedName, component string) *corev1.Ser Namespace: name.Namespace, Labels: labels, Annotations: map[string]string{ - commonresources.PrometheusScrapeAnnotationKey: "true", - commonresources.PrometheusPortAnnotationKey: strconv.Itoa(int(ports.Metrics)), - commonresources.PrometheusSchemeAnnotationKey: "http", + commonresources.AnnotationKeyPrometheusScrape: "true", + commonresources.AnnotationKeyPrometheusPort: strconv.Itoa(int(ports.Metrics)), + commonresources.AnnotationKeyPrometheusScheme: "http", }, }, Spec: corev1.ServiceSpec{ diff --git a/internal/resources/otelcollector/gateway.go b/internal/resources/otelcollector/gateway.go index eb42f5eb7..86c6d4809 100644 --- a/internal/resources/otelcollector/gateway.go +++ b/internal/resources/otelcollector/gateway.go @@ -62,9 +62,9 @@ var ( func NewLogGatewayApplierDeleter(image, namespace, priorityClassName string) *GatewayApplierDeleter { extraLabels := map[string]string{ - commonresources.TelemetryLogIngestLabelKey: "true", - commonresources.TelemetryLogExportLabelKey: "true", - commonresources.IstioInjectLabelKey: "true", // inject istio sidecar + commonresources.LabelKeyTelemetryLogIngest: "true", + commonresources.LabelKeyTelemetryLogExport: "true", + commonresources.LabelKeyIstioInject: "true", // inject istio sidecar } return &GatewayApplierDeleter{ @@ -86,9 +86,9 @@ func NewLogGatewayApplierDeleter(image, namespace, priorityClassName string) *Ga func NewMetricGatewayApplierDeleter(image, namespace, priorityClassName string) *GatewayApplierDeleter { extraLabels := map[string]string{ - commonresources.TelemetryMetricIngestLabelKey: "true", - commonresources.TelemetryMetricExportLabelKey: "true", - commonresources.IstioInjectLabelKey: "true", // inject istio sidecar + commonresources.LabelKeyTelemetryMetricIngest: "true", + commonresources.LabelKeyTelemetryMetricExport: "true", + commonresources.LabelKeyIstioInject: "true", // inject istio sidecar } return &GatewayApplierDeleter{ @@ -110,9 +110,9 @@ func NewMetricGatewayApplierDeleter(image, namespace, priorityClassName string) func NewTraceGatewayApplierDeleter(image, namespace, priorityClassName string) *GatewayApplierDeleter { extraLabels := map[string]string{ - commonresources.TelemetryTraceIngestLabelKey: "true", - commonresources.TelemetryTraceExportLabelKey: "true", - commonresources.IstioInjectLabelKey: "true", // inject istio sidecar + commonresources.LabelKeyTelemetryTraceIngest: "true", + commonresources.LabelKeyTelemetryTraceExport: "true", + commonresources.LabelKeyIstioInject: "true", // inject istio sidecar } return &GatewayApplierDeleter{ @@ -166,16 +166,16 @@ type GatewayApplyOptions struct { func (gad *GatewayApplierDeleter) ApplyResources(ctx context.Context, c client.Client, opts GatewayApplyOptions) error { name := types.NamespacedName{Namespace: gad.namespace, Name: gad.baseName} - if err := applyCommonResources(ctx, c, name, commonresources.K8sComponentLabelValueGateway, gad.rbac, opts.AllowedPorts); err != nil { + if err := applyCommonResources(ctx, c, name, commonresources.LabelValueK8sComponentGateway, gad.rbac, opts.AllowedPorts); err != nil { return fmt.Errorf("failed to create common resource: %w", err) } - secret := makeSecret(name, commonresources.K8sComponentLabelValueGateway, opts.CollectorEnvVars) + secret := makeSecret(name, commonresources.LabelValueK8sComponentGateway, opts.CollectorEnvVars) if err := k8sutils.CreateOrUpdateSecret(ctx, c, secret); err != nil { return fmt.Errorf("failed to create env secret: %w", err) } - configMap := makeConfigMap(name, commonresources.K8sComponentLabelValueGateway, opts.CollectorConfigYAML) + configMap := makeConfigMap(name, commonresources.LabelValueK8sComponentGateway, opts.CollectorConfigYAML) if err := k8sutils.CreateOrUpdateConfigMap(ctx, c, configMap); err != nil { return fmt.Errorf("failed to create configmap: %w", err) } @@ -243,7 +243,7 @@ func (gad *GatewayApplierDeleter) DeleteResources(ctx context.Context, c client. } func (gad *GatewayApplierDeleter) makeGatewayDeployment(configChecksum string, opts GatewayApplyOptions) *appsv1.Deployment { - labels := commonresources.MakeDefaultLabels(gad.baseName, commonresources.K8sComponentLabelValueGateway) + labels := commonresources.MakeDefaultLabels(gad.baseName, commonresources.LabelValueK8sComponentGateway) selectorLabels := commonresources.MakeDefaultSelectorLabels(gad.baseName) podLabels := make(map[string]string) maps.Copy(podLabels, labels) @@ -318,7 +318,7 @@ func makePodAffinity(labels map[string]string) corev1.Affinity { { Weight: 100, //nolint:mnd // 100% weight PodAffinityTerm: corev1.PodAffinityTerm{ - TopologyKey: commonresources.K8sHostnameLabelKey, + TopologyKey: commonresources.LabelKeyK8sHostname, LabelSelector: &metav1.LabelSelector{ MatchLabels: labels, }, @@ -327,7 +327,7 @@ func makePodAffinity(labels map[string]string) corev1.Affinity { { Weight: 100, //nolint:mnd // 100% weight PodAffinityTerm: corev1.PodAffinityTerm{ - TopologyKey: commonresources.K8sZoneLabelKey, + TopologyKey: commonresources.LabelKeyK8sZone, LabelSelector: &metav1.LabelSelector{ MatchLabels: labels, }, @@ -339,7 +339,7 @@ func makePodAffinity(labels map[string]string) corev1.Affinity { } func (gad *GatewayApplierDeleter) makeOTLPService() *corev1.Service { - commonLabels := commonresources.MakeDefaultLabels(gad.baseName, commonresources.K8sComponentLabelValueGateway) + commonLabels := commonresources.MakeDefaultLabels(gad.baseName, commonresources.LabelValueK8sComponentGateway) selectorLabels := commonresources.MakeDefaultSelectorLabels(gad.baseName) return &corev1.Service{ @@ -370,7 +370,7 @@ func (gad *GatewayApplierDeleter) makeOTLPService() *corev1.Service { } func (gad *GatewayApplierDeleter) makePeerAuthentication() *istiosecurityclientv1.PeerAuthentication { - commonLabels := commonresources.MakeDefaultLabels(gad.baseName, commonresources.K8sComponentLabelValueGateway) + commonLabels := commonresources.MakeDefaultLabels(gad.baseName, commonresources.LabelValueK8sComponentGateway) selectorLabels := commonresources.MakeDefaultSelectorLabels(gad.baseName) return &istiosecurityclientv1.PeerAuthentication{ @@ -387,7 +387,7 @@ func (gad *GatewayApplierDeleter) makePeerAuthentication() *istiosecurityclientv } func (gad *GatewayApplierDeleter) makeAnnotations(configChecksum string, opts GatewayApplyOptions) map[string]string { - annotations := map[string]string{commonresources.ChecksumConfigAnnotationKey: configChecksum} + annotations := map[string]string{commonresources.AnnotationKeyChecksumConfig: configChecksum} if opts.IstioEnabled { var excludeInboundPorts []string @@ -395,11 +395,11 @@ func (gad *GatewayApplierDeleter) makeAnnotations(configChecksum string, opts Ga excludeInboundPorts = append(excludeInboundPorts, fmt.Sprintf("%d", p)) } - annotations[commonresources.IstioExcludeInboundPortsAnnotationKey] = strings.Join(excludeInboundPorts, ", ") + annotations[commonresources.AnnotationKeyIstioExcludeInboundPorts] = strings.Join(excludeInboundPorts, ", ") // When a workload is outside the istio mesh and communicates with pod in service mesh, the envoy proxy does not // preserve the source IP and destination IP. To preserve source/destination IP we need TPROXY interception mode. // More info: https://istio.io/latest/docs/reference/config/istio.mesh.v1alpha1/#ProxyConfig-InboundInterceptionMode - annotations[commonresources.IstioInterceptionModeAnnotationKey] = commonresources.IstioInterceptionModeAnnotationValue + annotations[commonresources.AnnotationKeyIstioInterceptionMode] = commonresources.AnnotationValueIstioInterceptionModeTProxy } return annotations diff --git a/internal/resources/otelcollector/rbac.go b/internal/resources/otelcollector/rbac.go index e361ee6ec..148183b8a 100644 --- a/internal/resources/otelcollector/rbac.go +++ b/internal/resources/otelcollector/rbac.go @@ -110,7 +110,7 @@ func withRoleBinding() RBACOption { func makeTraceGatewayRBAC(namespace string) rbac { return *newRBAC( types.NamespacedName{Name: TraceGatewayName, Namespace: namespace}, - commonresources.K8sComponentLabelValueGateway, + commonresources.LabelValueK8sComponentGateway, withClusterRole(withK8sAttributeRules()), withClusterRoleBinding(), ) @@ -119,7 +119,7 @@ func makeTraceGatewayRBAC(namespace string) rbac { func makeMetricAgentRBAC(namespace string) rbac { return *newRBAC( types.NamespacedName{Name: MetricAgentName, Namespace: namespace}, - commonresources.K8sComponentLabelValueAgent, + commonresources.LabelValueK8sComponentAgent, withClusterRole(withKubeletStatsRules(), withPrometheusRules(), withK8sClusterRules()), withClusterRoleBinding(), withRole(withSingletonCreatorRules()), @@ -130,7 +130,7 @@ func makeMetricAgentRBAC(namespace string) rbac { func makeMetricGatewayRBAC(namespace string) rbac { return *newRBAC( types.NamespacedName{Name: MetricGatewayName, Namespace: namespace}, - commonresources.K8sComponentLabelValueGateway, + commonresources.LabelValueK8sComponentGateway, withClusterRole(withK8sAttributeRules(), withKymaStatsRules()), withClusterRoleBinding(), withRole(withSingletonCreatorRules()), @@ -141,7 +141,7 @@ func makeMetricGatewayRBAC(namespace string) rbac { func makeLogGatewayRBAC(namespace string) rbac { return *newRBAC( types.NamespacedName{Name: LogGatewayName, Namespace: namespace}, - commonresources.K8sComponentLabelValueGateway, + commonresources.LabelValueK8sComponentGateway, withClusterRole(withK8sAttributeRules()), withClusterRoleBinding(), ) diff --git a/internal/resources/otelcollector/testdata/metric-agent.yaml b/internal/resources/otelcollector/testdata/metric-agent.yaml index 40d58438c..fe11f1f9d 100644 --- a/internal/resources/otelcollector/testdata/metric-agent.yaml +++ b/internal/resources/otelcollector/testdata/metric-agent.yaml @@ -47,6 +47,8 @@ kind: ServiceAccount metadata: creationTimestamp: null labels: + app.kubernetes.io/component: agent + app.kubernetes.io/managed-by: telemetry-manager app.kubernetes.io/name: telemetry-metric-agent app.kubernetes.io/part-of: telemetry kyma-project.io/module: telemetry diff --git a/internal/resources/selfmonitor/resources.go b/internal/resources/selfmonitor/resources.go index 0394a2353..7103d7489 100644 --- a/internal/resources/selfmonitor/resources.go +++ b/internal/resources/selfmonitor/resources.go @@ -253,9 +253,9 @@ func (ad *ApplierDeleter) makeDeployment(configChecksum, configPath, configFile selectorLabels := commonresources.MakeDefaultSelectorLabels(ad.Config.BaseName) podLabels := make(map[string]string) maps.Copy(podLabels, labels) - podLabels[commonresources.IstioInjectLabelKey] = "false" + podLabels[commonresources.LabelKeyIstioInject] = "false" - annotations := map[string]string{commonresources.ChecksumConfigAnnotationKey: configChecksum} + annotations := map[string]string{commonresources.AnnotationKeyChecksumConfig: configChecksum} resources := makeResourceRequirements() podSpec := makePodSpec(ad.Config.BaseName, ad.Config.Deployment.Image, configPath, configFile, commonresources.WithPriorityClass(ad.Config.Deployment.PriorityClassName), diff --git a/internal/utils/k8s/utils.go b/internal/utils/k8s/utils.go index 4f82d6b4d..48c4c6241 100644 --- a/internal/utils/k8s/utils.go +++ b/internal/utils/k8s/utils.go @@ -339,7 +339,7 @@ func mergeMaps(newMap map[string]string, oldMap map[string]string) map[string]st func mergePodAnnotations(newMeta *metav1.ObjectMeta, oldMeta metav1.ObjectMeta) { newMeta.SetAnnotations(mergeMapsByPrefix(newMeta.Annotations, oldMeta.Annotations, "kubectl.kubernetes.io/")) - newMeta.SetAnnotations(mergeMapsByPrefix(newMeta.Annotations, oldMeta.Annotations, commonresources.ChecksumConfigAnnotationKey)) + newMeta.SetAnnotations(mergeMapsByPrefix(newMeta.Annotations, oldMeta.Annotations, commonresources.AnnotationKeyChecksumConfig)) newMeta.SetAnnotations(mergeMapsByPrefix(newMeta.Annotations, oldMeta.Annotations, "istio-operator.kyma-project.io/restartedAt")) } diff --git a/internal/utils/k8s/utils_test.go b/internal/utils/k8s/utils_test.go index 7cf83d7df..dd0b9dd52 100644 --- a/internal/utils/k8s/utils_test.go +++ b/internal/utils/k8s/utils_test.go @@ -113,21 +113,18 @@ func TestMergePodAnnotations(t *testing.T) { { name: "should preserve existing checksum annotations", existing: map[string]string{ - "checksum/1": "1", - "checksum/2": "2", - "checksum/3": "3", - "unrelated": "foo", + "checksum/config": "1", + "checksum/config-a": "2", + "checksum/Config": "3", + "unrelated": "foo", }, desired: map[string]string{ - "checksum/2": "b", - "checksum/3": "3", - "checksum/4": "4", + "checksum/cOnfig": "6", }, expectedMerged: map[string]string{ - "checksum/1": "1", - "checksum/2": "b", - "checksum/3": "3", - "checksum/4": "4", + "checksum/config": "1", + "checksum/config-a": "2", + "checksum/cOnfig": "6", }, }, { diff --git a/main.go b/main.go index ab5cb8fe4..af3e952bc 100644 --- a/main.go +++ b/main.go @@ -471,7 +471,7 @@ func createSelfMonitoringConfig() telemetry.SelfMonitorConfig { Config: selfmonitor.Config{ BaseName: selfMonitorName, Namespace: telemetryNamespace, - ComponentType: commonresources.K8sComponentLabelValueMonitor, + ComponentType: commonresources.LabelValueK8sComponentMonitor, Deployment: selfmonitor.DeploymentConfig{ Image: selfMonitorImage, PriorityClassName: normalPriorityClassName,