Skip to content

Commit e45b675

Browse files
authored
[autoscaling] Move to v1alpha2 as only supported version for Cluster Agent 7.64+ (#1845)
1 parent 4e83d29 commit e45b675

File tree

6 files changed

+78
-5
lines changed

6 files changed

+78
-5
lines changed

api/datadoghq/v1alpha1/datadogpodautoscaler_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ type DatadogPodAutoscalerPolicy struct {
142142
// +kubebuilder:printcolumn:name="Generated",type="date",JSONPath=".status.vertical.target.generatedAt"
143143
// +kubebuilder:printcolumn:name="Able to Apply",type="string",JSONPath=".status.conditions[?(@.type=='VerticalAbleToApply')].status"
144144
// +kubebuilder:printcolumn:name="Last Trigger",type="date",JSONPath=".status.vertical.lastAction.time"
145-
// +kubebuilder:storageversion
146145
// DatadogPodAutoscaler is the Schema for the datadogpodautoscalers API
147146
type DatadogPodAutoscaler struct {
148147
metav1.TypeMeta `json:",inline"`

api/datadoghq/v1alpha2/datadogpodautoscaler_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ type DatadogPodAutoscalerApplyPolicy struct {
134134
// +kubebuilder:printcolumn:name="Generated",type="date",JSONPath=".status.vertical.target.generatedAt"
135135
// +kubebuilder:printcolumn:name="Able to Apply",type="string",JSONPath=".status.conditions[?(@.type=='VerticalAbleToApply')].status"
136136
// +kubebuilder:printcolumn:name="Last Trigger",type="date",JSONPath=".status.vertical.lastAction.time"
137+
// +kubebuilder:storageversion
137138
// DatadogPodAutoscaler is the Schema for the datadogpodautoscalers API
138139
type DatadogPodAutoscaler struct {
139140
metav1.TypeMeta `json:",inline"`

config/crd/bases/v1/datadoghq.com_datadogpodautoscalers.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ spec:
562562
type: object
563563
type: object
564564
served: true
565-
storage: true
565+
storage: false
566566
subresources:
567567
status: {}
568568
- additionalPrinterColumns:
@@ -1110,6 +1110,6 @@ spec:
11101110
type: object
11111111
type: object
11121112
served: true
1113-
storage: false
1113+
storage: true
11141114
subresources:
11151115
status: {}

internal/controller/datadogagent/feature/orchestratorexplorer/feature.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package orchestratorexplorer
77

88
import (
99
"fmt"
10+
"slices"
1011

1112
"github.com/go-logr/logr"
1213
corev1 "k8s.io/api/core/v1"
@@ -25,6 +26,11 @@ import (
2526
"github.com/DataDog/datadog-operator/pkg/utils"
2627
)
2728

29+
const (
30+
currentDatadogPodAutoscalerResource = "datadoghq.com/v1alpha2/datadogpodautoscalers"
31+
oldDatadogPodAutoscalerResource = "datadoghq.com/v1alpha1/datadogpodautoscalers"
32+
)
33+
2834
func init() {
2935
err := feature.Register(feature.OrchestratorExplorerIDType, buildOrchestratorExplorerFeature)
3036
if err != nil {
@@ -120,6 +126,26 @@ func (f *orchestratorExplorerFeature) Configure(dda *v2alpha1.DatadogAgent) (req
120126
}
121127
f.serviceAccountName = constants.GetClusterAgentServiceAccount(dda)
122128

129+
// Handle automatic addition of OOTB resources
130+
// Autoscaling: Add DPA resource if enabled and replace older versions if present
131+
autoscaling := dda.Spec.Features.Autoscaling
132+
if autoscaling != nil && autoscaling.Workload != nil && apiutils.BoolValue(autoscaling.Workload.Enabled) {
133+
addRequired := true
134+
for i := range f.customResources {
135+
if f.customResources[i] == oldDatadogPodAutoscalerResource {
136+
f.customResources[i] = currentDatadogPodAutoscalerResource
137+
addRequired = false
138+
}
139+
}
140+
if addRequired {
141+
f.customResources = append(f.customResources, currentDatadogPodAutoscalerResource)
142+
}
143+
}
144+
145+
// Unique the custom resources as the check will output a warning if there are duplicates
146+
slices.Sort(f.customResources)
147+
f.customResources = slices.Compact(f.customResources)
148+
123149
if constants.IsClusterChecksEnabled(dda) {
124150
if constants.IsCCREnabled(dda) {
125151
f.runInClusterChecksRunner = true

internal/controller/datadogagent/feature/orchestratorexplorer/feature_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import (
1616
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake"
1717
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test"
1818
mergerfake "github.com/DataDog/datadog-operator/internal/controller/datadogagent/merger/fake"
19+
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/store"
1920
"github.com/DataDog/datadog-operator/pkg/constants"
2021
"github.com/DataDog/datadog-operator/pkg/controller/utils/comparison"
22+
"github.com/DataDog/datadog-operator/pkg/kubernetes"
2123
"github.com/DataDog/datadog-operator/pkg/testutils"
2224

2325
"github.com/google/go-cmp/cmp"
@@ -74,6 +76,36 @@ func Test_orchestratorExplorerFeature_Configure(t *testing.T) {
7476
ClusterAgent: orchestratorExplorerClusterAgentWantFuncV2(),
7577
Agent: test.NewDefaultComponentTest().WithWantFunc(orchestratorExplorerNodeAgentNoProcessAgentWantFunc),
7678
},
79+
{
80+
Name: "orchestrator explorer enabled with autoscaling and custom CRs",
81+
DDA: testutils.NewDatadogAgentBuilder().
82+
WithOrchestratorExplorerEnabled(true).
83+
WithWorkloadAutoscalerEnabled(true).
84+
WithOrchestratorExplorerCustomResources([]string{"datadoghq.com/v1alpha1/datadogpodautoscalers", "datadoghq.com/v1alpha1/watermarkpodautoscalers"}).
85+
Build(),
86+
WantConfigure: true,
87+
WantDependenciesFunc: func(t testing.TB, sc store.StoreClient) {
88+
cm, found := sc.Get(kubernetes.ConfigMapKind, "", "-orchestrator-explorer-config")
89+
assert.True(t, found)
90+
assert.NotNil(t, cm)
91+
92+
cmData := cm.(*corev1.ConfigMap).Data["orchestrator.yaml"]
93+
want := `---
94+
cluster_check: false
95+
ad_identifiers:
96+
- _kube_orchestrator
97+
init_config:
98+
99+
instances:
100+
- skip_leader_election: false
101+
crd_collectors:
102+
- datadoghq.com/v1alpha1/watermarkpodautoscalers
103+
- datadoghq.com/v1alpha2/datadogpodautoscalers
104+
`
105+
106+
assert.Equal(t, want, cmData)
107+
},
108+
},
77109
{
78110
Name: "orchestrator explorer enabled and runs on cluster checks runner",
79111
DDA: testutils.NewDatadogAgentBuilder().

pkg/testutils/builder.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@ func (builder *DatadogAgentBuilder) WithProcessChecksInCoreAgent(enabled bool) *
179179
return builder
180180
}
181181

182+
func (builder *DatadogAgentBuilder) WithWorkloadAutoscalerEnabled(enabled bool) *DatadogAgentBuilder {
183+
builder.datadogAgent.Spec.Features.Autoscaling = &v2alpha1.AutoscalingFeatureConfig{
184+
Workload: &v2alpha1.WorkloadAutoscalingFeatureConfig{
185+
Enabled: apiutils.NewBoolPointer(enabled),
186+
},
187+
}
188+
189+
return builder
190+
}
191+
182192
// Admission Controller
183193
func (builder *DatadogAgentBuilder) initAdmissionController() {
184194
if builder.datadogAgent.Spec.Features.AdmissionController == nil {
@@ -392,8 +402,7 @@ func (builder *DatadogAgentBuilder) WithOTelCollectorEnabled(enabled bool) *Data
392402

393403
func (builder *DatadogAgentBuilder) WithOTelCollectorConfig() *DatadogAgentBuilder {
394404
builder.datadogAgent.Spec.Features.OtelCollector.Conf = &v2alpha1.CustomConfig{}
395-
builder.datadogAgent.Spec.Features.OtelCollector.Conf.ConfigData =
396-
apiutils.NewStringPointer(defaultconfig.DefaultOtelCollectorConfig)
405+
builder.datadogAgent.Spec.Features.OtelCollector.Conf.ConfigData = apiutils.NewStringPointer(defaultconfig.DefaultOtelCollectorConfig)
397406
return builder
398407
}
399408

@@ -582,6 +591,12 @@ func (builder *DatadogAgentBuilder) WithOrchestratorExplorerCustomConfigData(cus
582591
return builder
583592
}
584593

594+
func (builder *DatadogAgentBuilder) WithOrchestratorExplorerCustomResources(customResources []string) *DatadogAgentBuilder {
595+
builder.initOE()
596+
builder.datadogAgent.Spec.Features.OrchestratorExplorer.CustomResources = customResources
597+
return builder
598+
}
599+
585600
// Cluster Checks
586601

587602
func (builder *DatadogAgentBuilder) initCC() {

0 commit comments

Comments
 (0)