Skip to content

Commit

Permalink
renamed constants
Browse files Browse the repository at this point in the history
  • Loading branch information
a-thaler committed Feb 4, 2025
1 parent 5931f83 commit f520d66
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 114 deletions.
24 changes: 12 additions & 12 deletions internal/resources/common/annotations.go
Original file line number Diff line number Diff line change
@@ -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"
)
64 changes: 32 additions & 32 deletions internal/resources/common/labels.go
Original file line number Diff line number Diff line change
@@ -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,
}
}
32 changes: 16 additions & 16 deletions internal/resources/fluentbit/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -267,18 +267,18 @@ 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{
Name: fmt.Sprintf("%s-metrics", name.Name),
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{
Expand All @@ -298,17 +298,17 @@ 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{
Name: fmt.Sprintf("%s-exporter-metrics", name.Name),
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{
Expand Down Expand Up @@ -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
}
22 changes: 11 additions & 11 deletions internal/resources/otelcollector/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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: "",
}
}
8 changes: 4 additions & 4 deletions internal/resources/otelcollector/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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{
Expand Down
Loading

0 comments on commit f520d66

Please sign in to comment.