Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CONTINT-4506] add resource labels and annotations as tags to orchestrator #32877

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type CollectorMetadata struct {
Version string
IsSkipped bool
SkippedReason string
LabelsAsTags map[string]string
AnnotationsAsTags map[string]string
}

// FullName returns a string that contains the collector name and version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/collectors"
k8sCollectors "github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/collectors/k8s"
"github.com/DataDog/datadog-agent/pkg/config/utils"
)

// CollectorInventory is used to store and retrieve available collectors.
Expand All @@ -26,34 +27,35 @@ type CollectorInventory struct {
// NewCollectorInventory returns a new inventory containing all known
// collectors.
func NewCollectorInventory(cfg config.Component, store workloadmeta.Component, tagger tagger.Component) *CollectorInventory {
metadataAsTags := utils.GetMetadataAsTags(cfg)
return &CollectorInventory{
collectors: []collectors.CollectorVersions{
k8sCollectors.NewCRDCollectorVersions(),
k8sCollectors.NewClusterCollectorVersions(),
k8sCollectors.NewClusterRoleBindingCollectorVersions(),
k8sCollectors.NewClusterRoleCollectorVersions(),
k8sCollectors.NewCronJobCollectorVersions(),
k8sCollectors.NewDaemonSetCollectorVersions(),
k8sCollectors.NewDeploymentCollectorVersions(),
k8sCollectors.NewHorizontalPodAutoscalerCollectorVersions(),
k8sCollectors.NewIngressCollectorVersions(),
k8sCollectors.NewJobCollectorVersions(),
k8sCollectors.NewLimitRangeCollectorVersions(),
k8sCollectors.NewNamespaceCollectorVersions(),
k8sCollectors.NewNetworkPolicyCollectorVersions(),
k8sCollectors.NewNodeCollectorVersions(),
k8sCollectors.NewPersistentVolumeClaimCollectorVersions(),
k8sCollectors.NewPersistentVolumeCollectorVersions(),
k8sCollectors.NewPodDisruptionBudgetCollectorVersions(),
k8sCollectors.NewReplicaSetCollectorVersions(),
k8sCollectors.NewRoleBindingCollectorVersions(),
k8sCollectors.NewRoleCollectorVersions(),
k8sCollectors.NewServiceAccountCollectorVersions(),
k8sCollectors.NewServiceCollectorVersions(),
k8sCollectors.NewStatefulSetCollectorVersions(),
k8sCollectors.NewStorageClassCollectorVersions(),
k8sCollectors.NewUnassignedPodCollectorVersions(cfg, store, tagger),
k8sCollectors.NewVerticalPodAutoscalerCollectorVersions(),
k8sCollectors.NewClusterRoleBindingCollectorVersions(metadataAsTags),
k8sCollectors.NewClusterRoleCollectorVersions(metadataAsTags),
k8sCollectors.NewCronJobCollectorVersions(metadataAsTags),
k8sCollectors.NewDaemonSetCollectorVersions(metadataAsTags),
k8sCollectors.NewDeploymentCollectorVersions(metadataAsTags),
k8sCollectors.NewHorizontalPodAutoscalerCollectorVersions(metadataAsTags),
k8sCollectors.NewIngressCollectorVersions(metadataAsTags),
k8sCollectors.NewJobCollectorVersions(metadataAsTags),
k8sCollectors.NewLimitRangeCollectorVersions(metadataAsTags),
k8sCollectors.NewNamespaceCollectorVersions(metadataAsTags),
k8sCollectors.NewNetworkPolicyCollectorVersions(metadataAsTags),
k8sCollectors.NewNodeCollectorVersions(metadataAsTags),
k8sCollectors.NewPersistentVolumeClaimCollectorVersions(metadataAsTags),
k8sCollectors.NewPersistentVolumeCollectorVersions(metadataAsTags),
k8sCollectors.NewPodDisruptionBudgetCollectorVersions(metadataAsTags),
k8sCollectors.NewReplicaSetCollectorVersions(metadataAsTags),
k8sCollectors.NewRoleBindingCollectorVersions(metadataAsTags),
k8sCollectors.NewRoleCollectorVersions(metadataAsTags),
k8sCollectors.NewServiceAccountCollectorVersions(metadataAsTags),
k8sCollectors.NewServiceCollectorVersions(metadataAsTags),
k8sCollectors.NewStatefulSetCollectorVersions(metadataAsTags),
k8sCollectors.NewStorageClassCollectorVersions(metadataAsTags),
k8sCollectors.NewUnassignedPodCollectorVersions(cfg, store, tagger, metadataAsTags),
k8sCollectors.NewVerticalPodAutoscalerCollectorVersions(metadataAsTags),
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewClusterCollector() *ClusterCollector {
IsMetadataProducer: true,
IsManifestProducer: true,
SupportsManifestBuffering: true,
Name: "clusters",
Name: clusterName,
NodeType: orchestrator.K8sCluster,
},
processor: k8sProcessors.NewClusterProcessor(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import (
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/collectors"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/processors"
k8sProcessors "github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/processors/k8s"
"github.com/DataDog/datadog-agent/pkg/config/utils"
"github.com/DataDog/datadog-agent/pkg/orchestrator"

"k8s.io/apimachinery/pkg/labels"
rbacv1Informers "k8s.io/client-go/informers/rbac/v1"
rbacv1Listers "k8s.io/client-go/listers/rbac/v1"
"k8s.io/client-go/tools/cache"
)

// NewClusterRoleCollectorVersions builds the group of collector versions.
func NewClusterRoleCollectorVersions() collectors.CollectorVersions {
func NewClusterRoleCollectorVersions(metadataAsTags utils.MetadataAsTags) collectors.CollectorVersions {
return collectors.NewCollectorVersions(
NewClusterRoleCollector(),
NewClusterRoleCollector(metadataAsTags),
)
}

Expand All @@ -36,17 +36,23 @@ type ClusterRoleCollector struct {

// NewClusterRoleCollector creates a new collector for the Kubernetes
// ClusterRole resource.
func NewClusterRoleCollector() *ClusterRoleCollector {
func NewClusterRoleCollector(metadataAsTags utils.MetadataAsTags) *ClusterRoleCollector {
resourceType := getResourceType(clusterRoleName, clusterRoleVersion)
labelsAsTags := metadataAsTags.GetResourcesLabelsAsTags()[resourceType]
annotationsAsTags := metadataAsTags.GetResourcesAnnotationsAsTags()[resourceType]

return &ClusterRoleCollector{
metadata: &collectors.CollectorMetadata{
IsDefaultVersion: true,
IsStable: true,
IsMetadataProducer: true,
IsManifestProducer: true,
SupportsManifestBuffering: true,
Name: "clusterroles",
Name: clusterRoleName,
NodeType: orchestrator.K8sClusterRole,
Version: "rbac.authorization.k8s.io/v1",
Version: clusterRoleVersion,
LabelsAsTags: labelsAsTags,
AnnotationsAsTags: annotationsAsTags,
},
processor: processors.NewProcessor(new(k8sProcessors.ClusterRoleHandlers)),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/collectors"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/processors"
k8sProcessors "github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/processors/k8s"
"github.com/DataDog/datadog-agent/pkg/config/utils"
"github.com/DataDog/datadog-agent/pkg/orchestrator"

"k8s.io/apimachinery/pkg/labels"
Expand All @@ -20,9 +21,9 @@ import (
)

// NewClusterRoleBindingCollectorVersions builds the group of collector versions.
func NewClusterRoleBindingCollectorVersions() collectors.CollectorVersions {
func NewClusterRoleBindingCollectorVersions(metadataAsTags utils.MetadataAsTags) collectors.CollectorVersions {
return collectors.NewCollectorVersions(
NewClusterRoleBindingCollector(),
NewClusterRoleBindingCollector(metadataAsTags),
)
}

Expand All @@ -36,17 +37,23 @@ type ClusterRoleBindingCollector struct {

// NewClusterRoleBindingCollector creates a new collector for the Kubernetes
// ClusterRoleBinding resource.
func NewClusterRoleBindingCollector() *ClusterRoleBindingCollector {
func NewClusterRoleBindingCollector(metadataAsTags utils.MetadataAsTags) *ClusterRoleBindingCollector {
resourceType := getResourceType(clusterRoleBindingName, clusterRoleBindingVersion)
labelsAsTags := metadataAsTags.GetResourcesLabelsAsTags()[resourceType]
annotationsAsTags := metadataAsTags.GetResourcesAnnotationsAsTags()[resourceType]

return &ClusterRoleBindingCollector{
metadata: &collectors.CollectorMetadata{
IsDefaultVersion: true,
IsStable: true,
IsMetadataProducer: true,
IsManifestProducer: true,
SupportsManifestBuffering: true,
Name: "clusterrolebindings",
Name: clusterRoleBindingName,
NodeType: orchestrator.K8sClusterRoleBinding,
Version: "rbac.authorization.k8s.io/v1",
Version: clusterRoleBindingVersion,
LabelsAsTags: labelsAsTags,
AnnotationsAsTags: annotationsAsTags,
},
processor: processors.NewProcessor(new(k8sProcessors.ClusterRoleBindingHandlers)),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func NewCRDCollector() *CRDCollector {
IsManifestProducer: true,
IsMetadataProducer: false,
SupportsManifestBuffering: false,
Name: "customresourcedefinitions",
Name: crdName,
NodeType: orchestrator.K8sCRD,
Version: "apiextensions.k8s.io/v1",
Version: crdVersion,
},
processor: processors.NewProcessor(new(k8sProcessors.CRDHandlers)),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ package k8s

import (
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/collectors"
"github.com/DataDog/datadog-agent/pkg/config/utils"
)

// NewCronJobCollectorVersions builds the group of collector versions for
func NewCronJobCollectorVersions() collectors.CollectorVersions {
func NewCronJobCollectorVersions(metadataAsTags utils.MetadataAsTags) collectors.CollectorVersions {
return collectors.NewCollectorVersions(
NewCronJobV1Collector(),
NewCronJobV1Beta1Collector(),
NewCronJobV1Collector(metadataAsTags),
NewCronJobV1Beta1Collector(metadataAsTags),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/collectors"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/processors"
k8sProcessors "github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/processors/k8s"
"github.com/DataDog/datadog-agent/pkg/config/utils"
"github.com/DataDog/datadog-agent/pkg/orchestrator"

"k8s.io/apimachinery/pkg/labels"
Expand All @@ -28,17 +29,23 @@ type CronJobV1Collector struct {
}

// NewCronJobV1Collector creates a new collector for the Kubernetes Job resource.
func NewCronJobV1Collector() *CronJobV1Collector {
func NewCronJobV1Collector(metadataAsTags utils.MetadataAsTags) *CronJobV1Collector {
resourceType := getResourceType(cronJobName, cronJobVersionV1)
labelsAsTags := metadataAsTags.GetResourcesLabelsAsTags()[resourceType]
annotationsAsTags := metadataAsTags.GetResourcesAnnotationsAsTags()[resourceType]

return &CronJobV1Collector{
metadata: &collectors.CollectorMetadata{
IsDefaultVersion: true,
IsStable: true,
IsMetadataProducer: true,
IsManifestProducer: true,
SupportsManifestBuffering: true,
Name: "cronjobs",
Name: cronJobName,
NodeType: orchestrator.K8sCronJob,
Version: "batch/v1",
Version: cronJobVersionV1,
LabelsAsTags: labelsAsTags,
AnnotationsAsTags: annotationsAsTags,
},
processor: processors.NewProcessor(new(k8sProcessors.CronJobV1Handlers)),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/collectors"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/processors"
k8sProcessors "github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/processors/k8s"
"github.com/DataDog/datadog-agent/pkg/config/utils"
"github.com/DataDog/datadog-agent/pkg/orchestrator"

"k8s.io/apimachinery/pkg/labels"
Expand All @@ -28,17 +29,23 @@ type CronJobV1Beta1Collector struct {
}

// NewCronJobV1Beta1Collector creates a new collector for the Kubernetes Job resource.
func NewCronJobV1Beta1Collector() *CronJobV1Beta1Collector {
func NewCronJobV1Beta1Collector(metadataAsTags utils.MetadataAsTags) *CronJobV1Beta1Collector {
resourceType := getResourceType(cronJobName, cronJobVersionV1Beta1)
labelsAsTags := metadataAsTags.GetResourcesLabelsAsTags()[resourceType]
annotationsAsTags := metadataAsTags.GetResourcesAnnotationsAsTags()[resourceType]

return &CronJobV1Beta1Collector{
metadata: &collectors.CollectorMetadata{
IsDefaultVersion: false,
IsStable: true,
IsMetadataProducer: true,
IsManifestProducer: true,
SupportsManifestBuffering: true,
Name: "cronjobs",
Name: cronJobName,
NodeType: orchestrator.K8sCronJob,
Version: "batch/v1beta1",
Version: cronJobVersionV1Beta1,
LabelsAsTags: labelsAsTags,
AnnotationsAsTags: annotationsAsTags,
},
processor: processors.NewProcessor(new(k8sProcessors.CronJobV1Beta1Handlers)),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/collectors"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/processors"
k8sProcessors "github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/processors/k8s"
"github.com/DataDog/datadog-agent/pkg/config/utils"
"github.com/DataDog/datadog-agent/pkg/orchestrator"

"k8s.io/apimachinery/pkg/labels"
Expand All @@ -20,9 +21,9 @@ import (
)

// NewDaemonSetCollectorVersions builds the group of collector versions.
func NewDaemonSetCollectorVersions() collectors.CollectorVersions {
func NewDaemonSetCollectorVersions(metadataAsTags utils.MetadataAsTags) collectors.CollectorVersions {
return collectors.NewCollectorVersions(
NewDaemonSetCollector(),
NewDaemonSetCollector(metadataAsTags),
)
}

Expand All @@ -36,17 +37,23 @@ type DaemonSetCollector struct {

// NewDaemonSetCollector creates a new collector for the Kubernetes DaemonSet
// resource.
func NewDaemonSetCollector() *DaemonSetCollector {
func NewDaemonSetCollector(metadataAsTags utils.MetadataAsTags) *DaemonSetCollector {
resourceType := getResourceType(daemonSetName, daemonSetVersion)
labelsAsTags := metadataAsTags.GetResourcesLabelsAsTags()[resourceType]
annotationsAsTags := metadataAsTags.GetResourcesAnnotationsAsTags()[resourceType]

return &DaemonSetCollector{
metadata: &collectors.CollectorMetadata{
IsDefaultVersion: true,
IsStable: true,
IsMetadataProducer: true,
IsManifestProducer: true,
SupportsManifestBuffering: true,
Name: "daemonsets",
Name: daemonSetName,
NodeType: orchestrator.K8sDaemonSet,
Version: "apps/v1",
Version: daemonSetVersion,
LabelsAsTags: labelsAsTags,
AnnotationsAsTags: annotationsAsTags,
},
processor: processors.NewProcessor(new(k8sProcessors.DaemonSetHandlers)),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/collectors"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/processors"
k8sProcessors "github.com/DataDog/datadog-agent/pkg/collector/corechecks/cluster/orchestrator/processors/k8s"
"github.com/DataDog/datadog-agent/pkg/config/utils"
"github.com/DataDog/datadog-agent/pkg/orchestrator"

"k8s.io/apimachinery/pkg/labels"
Expand All @@ -20,9 +21,9 @@ import (
)

// NewDeploymentCollectorVersions builds the group of collector versions.
func NewDeploymentCollectorVersions() collectors.CollectorVersions {
func NewDeploymentCollectorVersions(metadataAsTags utils.MetadataAsTags) collectors.CollectorVersions {
return collectors.NewCollectorVersions(
NewDeploymentCollector(),
NewDeploymentCollector(metadataAsTags),
)
}

Expand All @@ -36,17 +37,23 @@ type DeploymentCollector struct {

// NewDeploymentCollector creates a new collector for the Kubernetes Deployment
// resource.
func NewDeploymentCollector() *DeploymentCollector {
func NewDeploymentCollector(metadataAsTags utils.MetadataAsTags) *DeploymentCollector {
resourceType := getResourceType(deploymentName, deploymentVersion)
labelsAsTags := metadataAsTags.GetResourcesLabelsAsTags()[resourceType]
annotationsAsTags := metadataAsTags.GetResourcesAnnotationsAsTags()[resourceType]

return &DeploymentCollector{
metadata: &collectors.CollectorMetadata{
IsDefaultVersion: true,
IsStable: true,
IsMetadataProducer: true,
IsManifestProducer: true,
SupportsManifestBuffering: true,
Name: "deployments",
Name: deploymentName,
NodeType: orchestrator.K8sDeployment,
Version: "apps/v1",
Version: deploymentVersion,
LabelsAsTags: labelsAsTags,
AnnotationsAsTags: annotationsAsTags,
},
processor: processors.NewProcessor(new(k8sProcessors.DeploymentHandlers)),
}
Expand Down
Loading
Loading