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

[CECO-1106] DDA config for Admission Controller sidecar injection using selector and profile #1209

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 54 additions & 23 deletions apis/datadoghq/v2alpha1/datadogagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,60 @@ type AdmissionControllerFeatureConfig struct {
CWSInstrumentation *CWSInstrumentationConfig `json:"cwsInstrumentation,omitempty"`
}

type AgentSidecarInjectionConfig struct {
// Enabled enables Sidecar injections.
// Default: false
// +optional
Enabled *bool `json:"enabled"`
// ClusterAgentCommunicationEnabled enables communication between Agent sidecars and the Cluster Agent.
// Default : true
// +optional
ClusterAgentCommunicationEnabled *bool `json:"clusterAgentCommunicationEnabled,omitempty"`
// Provider is used to add infrastructure provider-specific configurations to the Agent sidecar.
// Currently only "fargate" is supported.
// To use the feature in other environments (including local testing) omit the config.
// See also: https://docs.datadoghq.com/integrations/eks_fargate
// +optional
Provider *string `json:"provider,omitempty"`
// Registry overrides the default registry for the sidecar Agent.
// +optional
Registry *string `json:"registry,omitempty"`
// Image overrides the default Agent image name and tag for the Agent sidecar.
// +optional
Image *commonv1.AgentImageConfig `json:"image,omitempty"`
// Selectors define the pod selector for sidecar injection. Only one rule is supported.
// +optional
// +listType=atomic
Selectors []*Selector `json:"selectors,omitempty"`
// Profiles define the sidecar configuration override. Only one profile is supported.
// +optional
// +listType=atomic
Profiles []*Profile `json:"profiles,omitempty"`
}

// Selectors define a pod selector for sidecar injection.
type Selector struct {
// NamespaceSelector specifies the label selector for namespaces.
// +optional
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
// ObjectSelector specifies the label selector for objects.
// +optional
ObjectSelector *metav1.LabelSelector `json:"objectSelector,omitempty"`
}

// Profile defines a sidecar configuration override.
type Profile struct {
// EnvVars specifies the environment variables for the profile.
// +optional
// +listType=map
// +listMapKey=name
EnvVars []corev1.EnvVar `json:"env,omitempty"`

// ResourceRequirements specifies the resource requirements for the profile.
// +optional
ResourceRequirements *corev1.ResourceRequirements `json:"resources,omitempty"`
}

// CWSInstrumentationConfig contains the configuration of the CWS Instrumentation admission controller endpoint.
type CWSInstrumentationConfig struct {
// Enable the CWS Instrumentation admission controller endpoint.
Expand Down Expand Up @@ -1275,29 +1329,6 @@ type FIPSConfig struct {
CustomFIPSConfig *CustomConfig `json:"customFIPSConfig,omitempty"`
}

type AgentSidecarInjectionConfig struct {
// Enabled enables Sidecar injections.
// Default: false
// +optional
Enabled *bool `json:"enabled"`
// ClusterAgentCommunicationEnabled enables communication between Agent sidecars and the Cluster Agent.
// Default : true
// +optional
ClusterAgentCommunicationEnabled *bool `json:"clusterAgentCommunicationEnabled,omitempty"`
// Provider is used to add infrastructure provider-specific configurations to the Agent sidecar.
// Currently only "fargate" is supported.
// To use the feature in other environments (including local testing) omit the config.
// See also: https://docs.datadoghq.com/integrations/eks_fargate
// +optional
Provider *string `json:"provider,omitempty"`
// Registry overrides the default registry for the sidecar Agent.
// +optional
Registry *string `json:"registry,omitempty"`
// Image overrides the default Agent image name and tag for the Agent sidecar.
// +optional
Image *commonv1.AgentImageConfig `json:"image,omitempty"`
}

// DatadogAgent Deployment with the Datadog Operator.
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
Expand Down
51 changes: 51 additions & 0 deletions apis/datadoghq/v2alpha1/test/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
"github.com/DataDog/datadog-operator/apis/utils"
apiutils "github.com/DataDog/datadog-operator/apis/utils"
defaulting "github.com/DataDog/datadog-operator/pkg/defaulting"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type DatadogAgentBuilder struct {
Expand Down Expand Up @@ -273,6 +276,54 @@ func (builder *DatadogAgentBuilder) WithSidecarInjectionImageTag(tag string) *Da
return builder
}

func (builder *DatadogAgentBuilder) WithSidecarInjectionSelectors(selectorKey, selectorValue string) *DatadogAgentBuilder {
builder.initAdmissionController()
builder.initSidecarInjection()

selectors := []*v2alpha1.Selector{
{
NamespaceSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
selectorKey: selectorValue,
},
},
ObjectSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
selectorKey: selectorValue,
},
},
},
}

builder.datadogAgent.Spec.Features.AdmissionController.AgentSidecarInjection.Selectors = selectors
return builder
}

func (builder *DatadogAgentBuilder) WithSidecarInjectionProfiles(envKey, envValue, resourceCPU, resourceMem string) *DatadogAgentBuilder {
builder.initAdmissionController()
builder.initSidecarInjection()

profiles := []*v2alpha1.Profile{
{
EnvVars: []corev1.EnvVar{
{
Name: envKey,
Value: envValue,
},
},
ResourceRequirements: &corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(resourceCPU),
corev1.ResourceMemory: resource.MustParse(resourceMem),
},
},
},
}

builder.datadogAgent.Spec.Features.AdmissionController.AgentSidecarInjection.Profiles = profiles
return builder
}

// Process Discovery
func (builder *DatadogAgentBuilder) initProcessDiscovery() {
if builder.datadogAgent.Spec.Features.ProcessDiscovery == nil {
Expand Down
74 changes: 74 additions & 0 deletions apis/datadoghq/v2alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading