Skip to content

Commit

Permalink
update after @celene review
Browse files Browse the repository at this point in the history
  • Loading branch information
clamoriniere committed May 17, 2022
1 parent f1b216a commit 19477c1
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 43 deletions.
5 changes: 5 additions & 0 deletions controllers/datadogagent/common/const.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package common

// Resource names
Expand Down
5 changes: 5 additions & 0 deletions controllers/datadogagent/component/agent/default.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package agent

import (
Expand Down
5 changes: 5 additions & 0 deletions controllers/datadogagent/component/clusteragent/default.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package clusteragent

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package clustercheckrunner

import (
Expand Down
5 changes: 5 additions & 0 deletions controllers/datadogagent/component/const.go
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package component
5 changes: 5 additions & 0 deletions controllers/datadogagent/component/new.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package component

import (
Expand Down
5 changes: 5 additions & 0 deletions controllers/datadogagent/component/utils.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package component

import (
Expand Down
5 changes: 5 additions & 0 deletions controllers/datadogagent/controller_reconcile_agent.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package datadogagent

import (
Expand Down
5 changes: 5 additions & 0 deletions controllers/datadogagent/controller_reconcile_clc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package datadogagent

import (
Expand Down
5 changes: 5 additions & 0 deletions controllers/datadogagent/controller_reconcile_dca.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package datadogagent

import (
Expand Down
5 changes: 5 additions & 0 deletions controllers/datadogagent/controller_reconcile_v2.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package datadogagent

import (
Expand Down
5 changes: 5 additions & 0 deletions controllers/datadogagent/controller_reconcile_v2_common.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package datadogagent

import (
Expand Down
53 changes: 21 additions & 32 deletions controllers/datadogagent/feature/kubernetesstatecore/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,28 @@ type ksmFeature struct {
// Configure use to configure the feature from a v2alpha1.DatadogAgent instance.
func (f *ksmFeature) Configure(dda *v2alpha1.DatadogAgent) feature.RequiredComponents {
f.owner = dda
var output feature.RequiredComponents

if dda.Spec.Features.KubeStateMetricsCore != nil && apiutils.BoolValue(dda.Spec.Features.KubeStateMetricsCore.Enabled) {
f.enable = true
output.ClusterAgent.IsRequired = &f.enable

if dda.Spec.Features.KubeStateMetricsCore.Conf != nil {
f.customConfig = v2alpha1.ConvertCustomConfig(dda.Spec.Features.KubeStateMetricsCore.Conf)
}

f.configConfigMapName = apicommonv1.GetConfName(dda, f.customConfig, apicommon.DefaultKubeStateMetricsCoreConf)
}

if dda.Spec.Features.ClusterChecks != nil && apiutils.BoolValue(dda.Spec.Features.ClusterChecks.Enabled) {
f.clusterChecksEnabled = true
if apiutils.BoolValue(dda.Spec.Features.ClusterChecks.UseClusterChecksRunners) {
f.rbacSuffix = common.CheckRunnersSuffix
f.serviceAccountName = v2alpha1.GetClusterChecksRunnerServiceAccount(dda)
} else {
f.serviceAccountName = v2alpha1.GetClusterAgentServiceAccount(dda)
}
}
if dda.Spec.Features.ClusterChecks != nil && apiutils.BoolValue(dda.Spec.Features.ClusterChecks.Enabled) {
f.clusterChecksEnabled = true
output.ClusterCheckRunner.IsRequired = &f.clusterChecksEnabled

output := feature.RequiredComponents{}
if f.enable {
output.ClusterAgent = feature.RequiredComponent{IsRequired: &f.enable}
if f.clusterChecksEnabled {
output.ClusterCheckRunner = feature.RequiredComponent{IsRequired: &f.clusterChecksEnabled}
if apiutils.BoolValue(dda.Spec.Features.ClusterChecks.UseClusterChecksRunners) {
f.rbacSuffix = common.CheckRunnersSuffix
f.serviceAccountName = v2alpha1.GetClusterChecksRunnerServiceAccount(dda)
} else {
f.serviceAccountName = v2alpha1.GetClusterAgentServiceAccount(dda)
}
}
}

Expand All @@ -93,18 +90,18 @@ func (f *ksmFeature) Configure(dda *v2alpha1.DatadogAgent) feature.RequiredCompo
// ConfigureV1 use to configure the feature from a v1alpha1.DatadogAgent instance.
func (f *ksmFeature) ConfigureV1(dda *v1alpha1.DatadogAgent) feature.RequiredComponents {
f.owner = dda
var output feature.RequiredComponents

if dda.Spec.Features.KubeStateMetricsCore != nil {
if apiutils.BoolValue(dda.Spec.Features.KubeStateMetricsCore.Enabled) {
f.enable = true
}
if dda.Spec.Features.KubeStateMetricsCore != nil && apiutils.BoolValue(dda.Spec.Features.KubeStateMetricsCore.Enabled) {
f.enable = true
output.ClusterAgent.IsRequired = &f.enable

if dda.Spec.ClusterAgent.Config != nil && apiutils.BoolValue(dda.Spec.ClusterAgent.Config.ClusterChecksEnabled) {
if apiutils.BoolValue(dda.Spec.Features.KubeStateMetricsCore.ClusterCheck) {
f.clusterChecksEnabled = true
f.rbacSuffix = common.CheckRunnersSuffix
f.serviceAccountName = v1alpha1.GetClusterChecksRunnerServiceAccount(dda)
}
f.clusterChecksEnabled = true
f.rbacSuffix = common.CheckRunnersSuffix
f.serviceAccountName = v1alpha1.GetClusterChecksRunnerServiceAccount(dda)

output.ClusterCheckRunner.IsRequired = &f.clusterChecksEnabled
} else {
f.serviceAccountName = v1alpha1.GetClusterAgentServiceAccount(dda)
}
Expand All @@ -116,14 +113,6 @@ func (f *ksmFeature) ConfigureV1(dda *v1alpha1.DatadogAgent) feature.RequiredCom
f.configConfigMapName = apicommonv1.GetConfName(dda, f.customConfig, apicommon.DefaultKubeStateMetricsCoreConf)
}

output := feature.RequiredComponents{}
if f.enable {
output.ClusterAgent = feature.RequiredComponent{IsRequired: &f.enable}
if f.clusterChecksEnabled {
output.ClusterCheckRunner = feature.RequiredComponent{IsRequired: &f.clusterChecksEnabled}
}
}

return output
}

Expand Down
14 changes: 3 additions & 11 deletions controllers/datadogagent/feature/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
apicommonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
"github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1"
"github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1"
"github.com/DataDog/datadog-operator/apis/utils"
apiutils "github.com/DataDog/datadog-operator/apis/utils"
"github.com/DataDog/datadog-operator/controllers/datadogagent/dependencies"
"github.com/DataDog/datadog-operator/controllers/datadogagent/merger"
Expand Down Expand Up @@ -64,11 +65,6 @@ func (rc *RequiredComponent) Merge(in *RequiredComponent) *RequiredComponent {
return rc
}

const (
trueValue bool = true
falseValue bool = false
)

func merge(a, b *bool) *bool {
if a == nil && b == nil {
return nil
Expand All @@ -78,13 +74,9 @@ func merge(a, b *bool) *bool {
return a
}
if !apiutils.BoolValue(a) || !apiutils.BoolValue(b) {
return newBoolPointer(falseValue)
return utils.NewBoolPointer(false)
}
return newBoolPointer(trueValue)
}

func newBoolPointer(v bool) *bool {
return &v
return utils.NewBoolPointer(true)
}

func mergeSlices(a, b []apicommonv1.AgentContainerName) []apicommonv1.AgentContainerName {
Expand Down
5 changes: 5 additions & 0 deletions controllers/datadogagent/override/global.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package override

import (
Expand Down

0 comments on commit 19477c1

Please sign in to comment.