Skip to content

Commit

Permalink
Miscellaneous fixes (#107)
Browse files Browse the repository at this point in the history
* Fixes #97,  Fixes #95, Fixes #101, Fixes #102
* Make the definition of `DD_CRI_SOCKET_PATH` and `DOCKER_HOST` for all containers.
* Fix DatadogMetric generation with operator-sdk 0.17
* Add a way to specify environment variables for all containers
* Allow to use a custom secret key name when providing API or APP key via an existing secret
* This patch adds `$.spec.agent.env` for environment variables that must
defined for all the agents and not only the core one.


Co-authored-by: Cedric Lamoriniere <cedric.lamoriniere@datadoghq.com>
  • Loading branch information
L3n41c and clamoriniere committed Jun 3, 2020
1 parent f53066b commit cb2eac8
Show file tree
Hide file tree
Showing 12 changed files with 469 additions and 48 deletions.
150 changes: 144 additions & 6 deletions deploy/crds/datadoghq.com_datadogagents_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,116 @@ spec:
with hostNetwork, you have to specify DNS policy explicitly to
'ClusterFirstWithHostNet'.
type: string
env:
description: 'Environment variables for all Datadog Agents Ref:
https://docs.datadoghq.com/agent/docker/?tab=standard#environment-variables'
items:
description: EnvVar represents an environment variable present
in a Container.
properties:
name:
description: Name of the environment variable. Must be a C_IDENTIFIER.
type: string
value:
description: 'Variable references $(VAR_NAME) are expanded
using the previous defined environment variables in the
container and any service environment variables. If a variable
cannot be resolved, the reference in the input string will
be unchanged. The $(VAR_NAME) syntax can be escaped with
a double $$, ie: $$(VAR_NAME). Escaped references will never
be expanded, regardless of whether the variable exists or
not. Defaults to "".'
type: string
valueFrom:
description: Source for the environment variable's value.
Cannot be used if value is not empty.
properties:
configMapKeyRef:
description: Selects a key of a ConfigMap.
properties:
key:
description: The key to select.
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind,
uid?'
type: string
optional:
description: Specify whether the ConfigMap or its
key must be defined
type: boolean
required:
- key
type: object
fieldRef:
description: 'Selects a field of the pod: supports metadata.name,
metadata.namespace, metadata.labels, metadata.annotations,
spec.nodeName, spec.serviceAccountName, status.hostIP,
status.podIP, status.podIPs.'
properties:
apiVersion:
description: Version of the schema the FieldPath is
written in terms of, defaults to "v1".
type: string
fieldPath:
description: Path of the field to select in the specified
API version.
type: string
required:
- fieldPath
type: object
resourceFieldRef:
description: 'Selects a resource of the container: only
resources limits and requests (limits.cpu, limits.memory,
limits.ephemeral-storage, requests.cpu, requests.memory
and requests.ephemeral-storage) are currently supported.'
properties:
containerName:
description: 'Container name: required for volumes,
optional for env vars'
type: string
divisor:
anyOf:
- type: integer
- type: string
description: Specifies the output format of the exposed
resources, defaults to "1"
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
resource:
description: 'Required: resource to select'
type: string
required:
- resource
type: object
secretKeyRef:
description: Selects a key of a secret in the pod's namespace
properties:
key:
description: The key of the secret to select from. Must
be a valid secret key.
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind,
uid?'
type: string
optional:
description: Specify whether the Secret or its key
must be defined
type: boolean
required:
- key
type: object
type: object
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
hostNetwork:
description: Host networking requested for this pod. Use the host's
network namespace. If this option is set, the ports that will
Expand Down Expand Up @@ -7124,20 +7234,48 @@ spec:
Agent runs. ref: https://app.datadoghq.com/account/settings#agent/kubernetes'
type: string
apiKeyExistingSecret:
description: APIKeyExistingSecret Use existing Secret which stores
API key instead of creating a new one. If set, this parameter
takes precedence over "apiKey".
description: APIKeyExistingSecret is DEPRECATED. In order to pass
the API key through an existing secret, please consider "apiSecret"
instead. If set, this parameter takes precedence over "apiKey".
type: string
apiSecret:
description: APISecret Use existing Secret which stores API key
instead of creating a new one. If set, this parameter takes precedence
over "apiKey" and "apiKeyExistingSecret".
properties:
keyName:
description: KeyName is the key of the secret to use
type: string
secretName:
description: SecretName is the name of the secret
type: string
required:
- secretName
type: object
appKey:
description: If you are using clusterAgent.metricsProvider.enabled
= true, you must set a Datadog application key for read access
to your metrics.
type: string
appKeyExistingSecret:
description: Use existing Secret which stores APP key instead of
creating a new one If set, this parameter takes precedence over
"appKey".
description: AppKeyExistingSecret is DEPRECATED. In order to pass
the APP key through an existing secret, please consider "appSecret"
instead. If set, this parameter takes precedence over "appKey".
type: string
appSecret:
description: APPSecret Use existing Secret which stores API key
instead of creating a new one. If set, this parameter takes precedence
over "apiKey" and "appKeyExistingSecret".
properties:
keyName:
description: KeyName is the key of the secret to use
type: string
secretName:
description: SecretName is the name of the secret
type: string
required:
- secretName
type: object
token:
description: This needs to be at least 32 characters a-zA-z It is
a preshared key between the node agents and the cluster agent
Expand Down
37 changes: 35 additions & 2 deletions pkg/apis/datadoghq/v1alpha1/datadogagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,35 @@ type AgentCredentials struct {
// ref: https://app.datadoghq.com/account/settings#agent/kubernetes
APIKey string `json:"apiKey,omitempty"`

// APIKeyExistingSecret Use existing Secret which stores API key instead of creating a new one.
// APIKeyExistingSecret is DEPRECATED.
// In order to pass the API key through an existing secret, please consider "apiSecret" instead.
// If set, this parameter takes precedence over "apiKey".
// +optional
// +deprecated
APIKeyExistingSecret string `json:"apiKeyExistingSecret,omitempty"`

// APISecret Use existing Secret which stores API key instead of creating a new one.
// If set, this parameter takes precedence over "apiKey" and "apiKeyExistingSecret".
// +optional
APISecret *Secret `json:"apiSecret,omitempty"`

// If you are using clusterAgent.metricsProvider.enabled = true, you must set
// a Datadog application key for read access to your metrics.
// +optional
AppKey string `json:"appKey,omitempty"`

// Use existing Secret which stores APP key instead of creating a new one
// AppKeyExistingSecret is DEPRECATED.
// In order to pass the APP key through an existing secret, please consider "appSecret" instead.
// If set, this parameter takes precedence over "appKey".
// +optional
// +deprecated
AppKeyExistingSecret string `json:"appKeyExistingSecret,omitempty"`

// APPSecret Use existing Secret which stores API key instead of creating a new one.
// If set, this parameter takes precedence over "apiKey" and "appKeyExistingSecret".
// +optional
APPSecret *Secret `json:"appSecret,omitempty"`

// This needs to be at least 32 characters a-zA-z
// It is a preshared key between the node agents and the cluster agent
// +optional
Expand All @@ -77,6 +91,17 @@ type AgentCredentials struct {
UseSecretBackend *bool `json:"useSecretBackend,omitempty"`
}

// Secret contains a secret name and an included key
// +k8s:openapi-gen=true
type Secret struct {
// SecretName is the name of the secret
SecretName string `json:"secretName"`

// KeyName is the key of the secret to use
// +optional
KeyName string `json:"keyName,omitempty"`
}

// DatadogAgentSpecAgentSpec defines the desired state of the node Agent
// +k8s:openapi-gen=true
type DatadogAgentSpecAgentSpec struct {
Expand Down Expand Up @@ -138,6 +163,14 @@ type DatadogAgentSpecAgentSpec struct {
// +optional
HostPID bool `json:"hostPID,omitempty"`

// Environment variables for all Datadog Agents
// Ref: https://docs.datadoghq.com/agent/docker/?tab=standard#environment-variables
//
// +optional
// +listType=map
// +listMapKey=name
Env []corev1.EnvVar `json:"env,omitempty"`

// Trace Agent configuration
// +optional
Apm APMSpec `json:"apm,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/datadoghq/v1alpha1/test/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type NewDatadogAgentOptions struct {
ClusterChecksRunnerVolumeMounts []corev1.VolumeMount
ClusterChecksRunnerEnvVars []corev1.EnvVar
APIKeyExistingSecret string
APISecret *datadoghqv1alpha1.Secret
Site string
HostPort int32
HostNetwork bool
Expand Down Expand Up @@ -223,6 +224,10 @@ func NewDefaultedDatadogAgent(ns, name string, options *NewDatadogAgentOptions)
if options.APIKeyExistingSecret != "" {
ad.Spec.Credentials.APIKeyExistingSecret = options.APIKeyExistingSecret
}

if options.APISecret != nil {
ad.Spec.Credentials.APISecret = options.APISecret
}
}
return datadoghqv1alpha1.DefaultDatadogAgent(ad)
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/apis/datadoghq/v1alpha1/zz_generated.deepcopy.go

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

0 comments on commit cb2eac8

Please sign in to comment.