diff --git a/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml b/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml new file mode 100644 index 000000000000..3a3737ff36b1 --- /dev/null +++ b/.chloggen/k8sclusterreceiver-remove-deprecated-resources.yaml @@ -0,0 +1,29 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: "breaking" + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: k8sclusterreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Remove deprecated Kubernetes API resources" + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [23612,26551] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: | + Drop support of HorizontalPodAutoscaler v2beta2 version and CronJob v1beta1 version. + Note that metrics for those resources will not be emitted anymore on Kubernetes 1.22 and older. + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/receiver/k8sclusterreceiver/internal/collection/collector.go b/receiver/k8sclusterreceiver/internal/collection/collector.go index aa4685286f5f..c32a2fa57042 100644 --- a/receiver/k8sclusterreceiver/internal/collection/collector.go +++ b/receiver/k8sclusterreceiver/internal/collection/collector.go @@ -12,9 +12,7 @@ import ( "go.opentelemetry.io/collector/receiver" appsv1 "k8s.io/api/apps/v1" autoscalingv2 "k8s.io/api/autoscaling/v2" - autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2" batchv1 "k8s.io/api/batch/v1" - batchv1beta1 "k8s.io/api/batch/v1beta1" corev1 "k8s.io/api/core/v1" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/clusterresourcequota" @@ -99,15 +97,9 @@ func (dc *DataCollector) CollectMetricData(currentTime time.Time) pmetric.Metric dc.metadataStore.ForEach(gvk.CronJob, func(o any) { cronjob.RecordMetrics(dc.metricsBuilder, o.(*batchv1.CronJob), ts) }) - dc.metadataStore.ForEach(gvk.CronJobBeta, func(o any) { - cronjob.RecordMetricsBeta(dc.metricsBuilder, o.(*batchv1beta1.CronJob), ts) - }) dc.metadataStore.ForEach(gvk.HorizontalPodAutoscaler, func(o any) { hpa.RecordMetrics(dc.metricsBuilder, o.(*autoscalingv2.HorizontalPodAutoscaler), ts) }) - dc.metadataStore.ForEach(gvk.HorizontalPodAutoscalerBeta, func(o any) { - hpa.RecordMetricsBeta(dc.metricsBuilder, o.(*autoscalingv2beta2.HorizontalPodAutoscaler), ts) - }) dc.metadataStore.ForEach(gvk.ClusterResourceQuota, func(o any) { clusterresourcequota.RecordMetrics(dc.metricsBuilder, o.(*quotav1.ClusterResourceQuota), ts) }) diff --git a/receiver/k8sclusterreceiver/internal/cronjob/cronjobs.go b/receiver/k8sclusterreceiver/internal/cronjob/cronjobs.go index e7a49e6c15da..f514192d65cf 100644 --- a/receiver/k8sclusterreceiver/internal/cronjob/cronjobs.go +++ b/receiver/k8sclusterreceiver/internal/cronjob/cronjobs.go @@ -6,7 +6,6 @@ package cronjob // import "github.com/open-telemetry/opentelemetry-collector-con import ( "go.opentelemetry.io/collector/pdata/pcommon" batchv1 "k8s.io/api/batch/v1" - batchv1beta1 "k8s.io/api/batch/v1beta1" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/constants" @@ -30,26 +29,9 @@ func RecordMetrics(mb *metadata.MetricsBuilder, cj *batchv1.CronJob, ts pcommon. mb.EmitForResource(metadata.WithResource(rb.Emit())) } -func RecordMetricsBeta(mb *metadata.MetricsBuilder, cj *batchv1beta1.CronJob, ts pcommon.Timestamp) { - mb.RecordK8sCronjobActiveJobsDataPoint(ts, int64(len(cj.Status.Active))) - rb := mb.NewResourceBuilder() - rb.SetK8sNamespaceName(cj.Namespace) - rb.SetK8sCronjobUID(string(cj.UID)) - rb.SetK8sCronjobName(cj.Name) - rb.SetOpencensusResourcetype("k8s") - mb.EmitForResource(metadata.WithResource(rb.Emit())) -} - func GetMetadata(cj *batchv1.CronJob) map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata { rm := metadata.GetGenericMetadata(&cj.ObjectMeta, constants.K8sKindCronJob) rm.Metadata[cronJobKeySchedule] = cj.Spec.Schedule rm.Metadata[cronJobKeyConcurrencyPolicy] = string(cj.Spec.ConcurrencyPolicy) return map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata{experimentalmetricmetadata.ResourceID(cj.UID): rm} } - -func GetMetadataBeta(cj *batchv1beta1.CronJob) map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata { - rm := metadata.GetGenericMetadata(&cj.ObjectMeta, constants.K8sKindCronJob) - rm.Metadata[cronJobKeySchedule] = cj.Spec.Schedule - rm.Metadata[cronJobKeyConcurrencyPolicy] = string(cj.Spec.ConcurrencyPolicy) - return map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata{experimentalmetricmetadata.ResourceID(cj.UID): rm} -} diff --git a/receiver/k8sclusterreceiver/internal/gvk/gvk.go b/receiver/k8sclusterreceiver/internal/gvk/gvk.go index 2424d0c71ec6..58e540821077 100644 --- a/receiver/k8sclusterreceiver/internal/gvk/gvk.go +++ b/receiver/k8sclusterreceiver/internal/gvk/gvk.go @@ -7,20 +7,18 @@ import "k8s.io/apimachinery/pkg/runtime/schema" // Kubernetes group version kinds var ( - Pod = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"} - Node = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Node"} - Namespace = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"} - ReplicationController = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ReplicationController"} - ResourceQuota = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ResourceQuota"} - Service = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Service"} - DaemonSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "DaemonSet"} - Deployment = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"} - ReplicaSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "ReplicaSet"} - StatefulSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"} - Job = schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"} - CronJob = schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "CronJob"} - CronJobBeta = schema.GroupVersionKind{Group: "batch", Version: "v1beta1", Kind: "CronJob"} - HorizontalPodAutoscaler = schema.GroupVersionKind{Group: "autoscaling", Version: "v2", Kind: "HorizontalPodAutoscaler"} - HorizontalPodAutoscalerBeta = schema.GroupVersionKind{Group: "autoscaling", Version: "v2beta2", Kind: "HorizontalPodAutoscaler"} - ClusterResourceQuota = schema.GroupVersionKind{Group: "quota", Version: "v1", Kind: "ClusterResourceQuota"} + Pod = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"} + Node = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Node"} + Namespace = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"} + ReplicationController = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ReplicationController"} + ResourceQuota = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ResourceQuota"} + Service = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Service"} + DaemonSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "DaemonSet"} + Deployment = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"} + ReplicaSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "ReplicaSet"} + StatefulSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"} + Job = schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"} + CronJob = schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "CronJob"} + HorizontalPodAutoscaler = schema.GroupVersionKind{Group: "autoscaling", Version: "v2", Kind: "HorizontalPodAutoscaler"} + ClusterResourceQuota = schema.GroupVersionKind{Group: "quota", Version: "v1", Kind: "ClusterResourceQuota"} ) diff --git a/receiver/k8sclusterreceiver/internal/hpa/hpa.go b/receiver/k8sclusterreceiver/internal/hpa/hpa.go index 380f1fac87a7..15d437e9863e 100644 --- a/receiver/k8sclusterreceiver/internal/hpa/hpa.go +++ b/receiver/k8sclusterreceiver/internal/hpa/hpa.go @@ -6,24 +6,11 @@ package hpa // import "github.com/open-telemetry/opentelemetry-collector-contrib import ( "go.opentelemetry.io/collector/pdata/pcommon" autoscalingv2 "k8s.io/api/autoscaling/v2" - autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/metadata" ) -func RecordMetricsBeta(mb *metadata.MetricsBuilder, hpa *autoscalingv2beta2.HorizontalPodAutoscaler, ts pcommon.Timestamp) { - mb.RecordK8sHpaMaxReplicasDataPoint(ts, int64(hpa.Spec.MaxReplicas)) - mb.RecordK8sHpaMinReplicasDataPoint(ts, int64(*hpa.Spec.MinReplicas)) - mb.RecordK8sHpaCurrentReplicasDataPoint(ts, int64(hpa.Status.CurrentReplicas)) - mb.RecordK8sHpaDesiredReplicasDataPoint(ts, int64(hpa.Status.DesiredReplicas)) - rb := mb.NewResourceBuilder() - rb.SetK8sHpaUID(string(hpa.UID)) - rb.SetK8sHpaName(hpa.Name) - rb.SetK8sNamespaceName(hpa.Namespace) - mb.EmitForResource(metadata.WithResource(rb.Emit())) -} - func RecordMetrics(mb *metadata.MetricsBuilder, hpa *autoscalingv2.HorizontalPodAutoscaler, ts pcommon.Timestamp) { mb.RecordK8sHpaMaxReplicasDataPoint(ts, int64(hpa.Spec.MaxReplicas)) mb.RecordK8sHpaMinReplicasDataPoint(ts, int64(*hpa.Spec.MinReplicas)) @@ -41,9 +28,3 @@ func GetMetadata(hpa *autoscalingv2.HorizontalPodAutoscaler) map[experimentalmet experimentalmetricmetadata.ResourceID(hpa.UID): metadata.GetGenericMetadata(&hpa.ObjectMeta, "HPA"), } } - -func GetMetadataBeta(hpa *autoscalingv2beta2.HorizontalPodAutoscaler) map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata { - return map[experimentalmetricmetadata.ResourceID]*metadata.KubernetesMetadata{ - experimentalmetricmetadata.ResourceID(hpa.UID): metadata.GetGenericMetadata(&hpa.ObjectMeta, "HPA"), - } -} diff --git a/receiver/k8sclusterreceiver/internal/testutils/objects.go b/receiver/k8sclusterreceiver/internal/testutils/objects.go index b74811eff031..b4edefa5eb45 100644 --- a/receiver/k8sclusterreceiver/internal/testutils/objects.go +++ b/receiver/k8sclusterreceiver/internal/testutils/objects.go @@ -7,7 +7,6 @@ import ( quotav1 "github.com/openshift/api/quota/v1" appsv1 "k8s.io/api/apps/v1" autoscalingv2 "k8s.io/api/autoscaling/v2" - autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -34,25 +33,6 @@ func NewHPA(id string) *autoscalingv2.HorizontalPodAutoscaler { } } -func NewHPABeta(id string) *autoscalingv2beta2.HorizontalPodAutoscaler { - minReplicas := int32(2) - return &autoscalingv2beta2.HorizontalPodAutoscaler{ - ObjectMeta: v1.ObjectMeta{ - Name: "test-hpa-" + id, - Namespace: "test-namespace", - UID: types.UID("test-hpa-" + id + "-uid"), - }, - Status: autoscalingv2beta2.HorizontalPodAutoscalerStatus{ - CurrentReplicas: 5, - DesiredReplicas: 7, - }, - Spec: autoscalingv2beta2.HorizontalPodAutoscalerSpec{ - MinReplicas: &minReplicas, - MaxReplicas: 10, - }, - } -} - func NewJob(id string) *batchv1.Job { p := int32(2) c := int32(10) diff --git a/receiver/k8sclusterreceiver/receiver_test.go b/receiver/k8sclusterreceiver/receiver_test.go index 86e6f2f76cb6..6b8fba583fb7 100644 --- a/receiver/k8sclusterreceiver/receiver_test.go +++ b/receiver/k8sclusterreceiver/receiver_test.go @@ -275,12 +275,6 @@ func newFakeClientWithAllResources() *fake.Clientset { gvkToAPIResource(gvk.HorizontalPodAutoscaler), }, }, - { - GroupVersion: "autoscaling/v2beta2", - APIResources: []v1.APIResource{ - gvkToAPIResource(gvk.HorizontalPodAutoscalerBeta), - }, - }, } return client } diff --git a/receiver/k8sclusterreceiver/watcher.go b/receiver/k8sclusterreceiver/watcher.go index 3f9926738fdb..5cf39b07c584 100644 --- a/receiver/k8sclusterreceiver/watcher.go +++ b/receiver/k8sclusterreceiver/watcher.go @@ -20,9 +20,7 @@ import ( "go.uber.org/zap/zapcore" appsv1 "k8s.io/api/apps/v1" autoscalingv2 "k8s.io/api/autoscaling/v2" - autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2" batchv1 "k8s.io/api/batch/v1" - batchv1beta1 "k8s.io/api/batch/v1beta1" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" @@ -138,8 +136,8 @@ func (rw *resourceWatcher) prepareSharedInformerFactory() error { "ReplicaSet": {gvk.ReplicaSet}, "StatefulSet": {gvk.StatefulSet}, "Job": {gvk.Job}, - "CronJob": {gvk.CronJob, gvk.CronJobBeta}, - "HorizontalPodAutoscaler": {gvk.HorizontalPodAutoscaler, gvk.HorizontalPodAutoscalerBeta}, + "CronJob": {gvk.CronJob}, + "HorizontalPodAutoscaler": {gvk.HorizontalPodAutoscaler}, } for kind, gvks := range supportedKinds { @@ -214,12 +212,8 @@ func (rw *resourceWatcher) setupInformerForKind(kind schema.GroupVersionKind, fa rw.setupInformer(kind, factory.Batch().V1().Jobs().Informer()) case gvk.CronJob: rw.setupInformer(kind, factory.Batch().V1().CronJobs().Informer()) - case gvk.CronJobBeta: - rw.setupInformer(kind, factory.Batch().V1beta1().CronJobs().Informer()) case gvk.HorizontalPodAutoscaler: rw.setupInformer(kind, factory.Autoscaling().V2().HorizontalPodAutoscalers().Informer()) - case gvk.HorizontalPodAutoscalerBeta: - rw.setupInformer(kind, factory.Autoscaling().V2beta2().HorizontalPodAutoscalers().Informer()) default: rw.logger.Error("Could not setup an informer for provided group version kind", zap.String("group version kind", kind.String())) @@ -308,12 +302,8 @@ func (rw *resourceWatcher) objMetadata(obj interface{}) map[experimentalmetricme return jobs.GetMetadata(o) case *batchv1.CronJob: return cronjob.GetMetadata(o) - case *batchv1beta1.CronJob: - return cronjob.GetMetadataBeta(o) case *autoscalingv2.HorizontalPodAutoscaler: return hpa.GetMetadata(o) - case *autoscalingv2beta2.HorizontalPodAutoscaler: - return hpa.GetMetadataBeta(o) } return nil } diff --git a/receiver/k8sclusterreceiver/watcher_test.go b/receiver/k8sclusterreceiver/watcher_test.go index f4bbbb72e9dd..c6c7ee62988a 100644 --- a/receiver/k8sclusterreceiver/watcher_test.go +++ b/receiver/k8sclusterreceiver/watcher_test.go @@ -118,12 +118,6 @@ func TestIsKindSupported(t *testing.T) { gvk: gvk.Pod, expected: true, }, - { - name: "unsupported_kind", - client: fake.NewSimpleClientset(), - gvk: gvk.CronJobBeta, - expected: false, - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -178,24 +172,12 @@ func TestPrepareSharedInformerFactory(t *testing.T) { gvkToAPIResource(gvk.Job), }, }, - { - GroupVersion: "batch/v1beta1", - APIResources: []metav1.APIResource{ - gvkToAPIResource(gvk.CronJobBeta), - }, - }, { GroupVersion: "autoscaling/v2", APIResources: []metav1.APIResource{ gvkToAPIResource(gvk.HorizontalPodAutoscaler), }, }, - { - GroupVersion: "autoscaling/v2beta2", - APIResources: []metav1.APIResource{ - gvkToAPIResource(gvk.HorizontalPodAutoscalerBeta), - }, - }, } return client }(),