Skip to content

Commit

Permalink
Share common structs in common/v1 and adds missing fields to v2alpha1 (
Browse files Browse the repository at this point in the history
  • Loading branch information
vboulineau committed Apr 26, 2022
1 parent b9ad1fc commit 1bca592
Show file tree
Hide file tree
Showing 37 changed files with 38,596 additions and 15,125 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: registry.ddbuild.io/images/mirror/golang:1.17
image: registry.ddbuild.io/images/mirror/golang:1.17.6-bullseye
variables:
GO111MODULE: "on"
PROJECTNAME: "datadog-operator"
Expand Down
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# Image URL to use all building/pushing image targets
IMG ?= gcr.io/datadoghq/operator:$(IMG_VERSION)

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
CRD_OPTIONS ?= "crd:preserveUnknownFields=false"
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.20

Expand Down Expand Up @@ -134,8 +133,8 @@ manifests: generate-manifests patch-crds ## Generate manifestcd s e.g. CRD, RBAC

.PHONY: generate-manifests
generate-manifests: $(CONTROLLER_GEN)
$(CONTROLLER_GEN) $(CRD_OPTIONS),crdVersions=v1 rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases/v1
$(CONTROLLER_GEN) $(CRD_OPTIONS),crdVersions=v1beta1 rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases/v1beta1
$(CONTROLLER_GEN) $(CRD_OPTIONS),crdVersions=v1 rbac:roleName=manager-role webhook paths="./apis/..." output:crd:artifacts:config=config/crd/bases/v1
$(CONTROLLER_GEN) $(CRD_OPTIONS),crdVersions=v1beta1 rbac:roleName=manager-role webhook paths="./apis/..." output:crd:artifacts:config=config/crd/bases/v1beta1

.PHONY: generate
generate: $(CONTROLLER_GEN) generate-openapi generate-docs ## Generate code
Expand Down
38 changes: 38 additions & 0 deletions apis/datadoghq/common/v1/agent_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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

import corev1 "k8s.io/api/core/v1"

// AgentImageConfig defines the agent container image config.
// +kubebuilder:object:generate=true
type AgentImageConfig struct {
// Define the image to use:
// Use "gcr.io/datadoghq/agent:latest" for Datadog Agent 7.
// Use "datadog/dogstatsd:latest" for standalone Datadog Agent DogStatsD 7.
// Use "gcr.io/datadoghq/cluster-agent:latest" for Datadog Cluster Agent.
// Use "agent" with the registry and tag configurations for <registry>/agent:<tag>.
// Use "cluster-agent" with the registry and tag configurations for <registry>/cluster-agent:<tag>.
Name string `json:"name,omitempty"`

// Define the image tag to use.
// To be used if the Name field does not correspond to a full image string.
// +optional
Tag string `json:"tag,omitempty"`

// Define whether the Agent image should support JMX.
// +optional
JMXEnabled bool `json:"jmxEnabled,omitempty"`

// The Kubernetes pull policy:
// Use Always, Never or IfNotPresent.
PullPolicy *corev1.PullPolicy `json:"pullPolicy,omitempty"`

// It is possible to specify Docker registry credentials.
// See https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod
// +optional
PullSecrets *[]corev1.LocalObjectReference `json:"pullSecrets,omitempty"`
}
54 changes: 54 additions & 0 deletions apis/datadoghq/common/v1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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

import corev1 "k8s.io/api/core/v1"

// SecretConfig contains a secret name and an included key.
// +kubebuilder:object:generate=true
type SecretConfig 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"`
}

// ConfigMapConfig contains ConfigMap information used to store a configuration file.
// +kubebuilder:object:generate=true
type ConfigMapConfig struct {
// Name is the name of the ConfigMap.
Name string `json:"name,omitempty"`

// Items maps a ConfigMap data key to a file path mount.
// +listType=map
// +listMapKey=key
// +optional
Items []corev1.KeyToPath `json:"items,omitempty"`
}

// KubeletConfig contains the kubelet configuration parameters.
// +kubebuilder:object:generate=true
type KubeletConfig struct {
// Host overrides the host used to contact kubelet API (default to status.hostIP).
// +optional
Host *corev1.EnvVarSource `json:"host,omitempty"`

// TLSVerify toggles kubelet TLS verification.
// Default: true
// +optional
TLSVerify *bool `json:"tlsVerify,omitempty"`

// HostCAPath is the host path where the kubelet CA certificate is stored.
// +optional
HostCAPath string `json:"hostCAPath,omitempty"`

// AgentCAPath is the container path where the kubelet CA certificate is stored.
// Default: '/var/run/host-kubelet-ca.crt' if hostCAPath is set, else '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt'
// +optional
AgentCAPath string `json:"agentCAPath,omitempty"`
}
106 changes: 106 additions & 0 deletions apis/datadoghq/common/v1/zz_generated.deepcopy.go

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

27 changes: 14 additions & 13 deletions apis/datadoghq/v1alpha1/datadogagent_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

commonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
apiutils "github.com/DataDog/datadog-operator/apis/utils"
"github.com/DataDog/datadog-operator/pkg/defaulting"
"github.com/DataDog/datadog-operator/pkg/utils"
Expand Down Expand Up @@ -250,7 +251,7 @@ func DefaultDatadogAgentSpecAgent(agent *DatadogAgentSpecAgentSpec) *DatadogAgen
agentOverride.UseExtendedDaemonset = agent.UseExtendedDaemonset
}

if img := DefaultDatadogAgentSpecAgentImage(agent, defaultAgentImageName, defaulting.AgentLatestVersion); !apiutils.IsEqualStruct(*img, ImageConfig{}) {
if img := DefaultDatadogAgentSpecAgentImage(agent, defaultAgentImageName, defaulting.AgentLatestVersion); !apiutils.IsEqualStruct(*img, commonv1.AgentImageConfig{}) {
agentOverride.Image = img
}

Expand Down Expand Up @@ -292,10 +293,10 @@ func DefaultDatadogAgentSpecAgent(agent *DatadogAgentSpecAgentSpec) *DatadogAgen

// DefaultDatadogAgentSpecAgentImage used to default a ImageConfig for the Agent, Cluster Agent and the Cluster Check Runner.
// Returns the defaulted ImageConfig.
func DefaultDatadogAgentSpecAgentImage(agent *DatadogAgentSpecAgentSpec, name, tag string) *ImageConfig {
imgOverride := &ImageConfig{}
func DefaultDatadogAgentSpecAgentImage(agent *DatadogAgentSpecAgentSpec, name, tag string) *commonv1.AgentImageConfig {
imgOverride := &commonv1.AgentImageConfig{}
if agent.Image == nil {
agent.Image = &ImageConfig{}
agent.Image = &commonv1.AgentImageConfig{}
}

if agent.Image.Name == "" {
Expand Down Expand Up @@ -1019,9 +1020,9 @@ func DefaultDatadogAgentSpecClusterAgent(clusterAgent *DatadogAgentSpecClusterAg
}

if clusterAgent.Image == nil {
clusterAgent.Image = &ImageConfig{}
clusterAgent.Image = &commonv1.AgentImageConfig{}
}
if img := DefaultDatadogClusterAgentImage(clusterAgent, defaultClusterAgentImageName, defaulting.ClusterAgentLatestVersion); !apiutils.IsEqualStruct(*img, ImageConfig{}) {
if img := DefaultDatadogClusterAgentImage(clusterAgent, defaultClusterAgentImageName, defaulting.ClusterAgentLatestVersion); !apiutils.IsEqualStruct(*img, commonv1.AgentImageConfig{}) {
clusterAgentOverride.Image = img
}

Expand Down Expand Up @@ -1138,10 +1139,10 @@ func DefaultAdmissionController(conf *ClusterAgentConfig) *AdmissionControllerCo

// DefaultDatadogClusterAgentImage used to default a ImageConfig for the Agent, Cluster Agent and the Cluster Check Runner.
// Returns the defaulted ImageConfig.
func DefaultDatadogClusterAgentImage(dca *DatadogAgentSpecClusterAgentSpec, name, tag string) *ImageConfig {
imgOverride := &ImageConfig{}
func DefaultDatadogClusterAgentImage(dca *DatadogAgentSpecClusterAgentSpec, name, tag string) *commonv1.AgentImageConfig {
imgOverride := &commonv1.AgentImageConfig{}
if dca.Image == nil {
dca.Image = &ImageConfig{}
dca.Image = &commonv1.AgentImageConfig{}
}

if dca.Image.Name == "" {
Expand Down Expand Up @@ -1186,7 +1187,7 @@ func DefaultDatadogAgentSpecClusterChecksRunner(clusterChecksRunner *DatadogAgen
clcOverride.Enabled = clusterChecksRunner.Enabled
}

if img := DefaultDatadogAgentSpecClusterChecksRunnerImage(clusterChecksRunner, defaultAgentImageName, defaulting.AgentLatestVersion); !apiutils.IsEqualStruct(img, ImageConfig{}) {
if img := DefaultDatadogAgentSpecClusterChecksRunnerImage(clusterChecksRunner, defaultAgentImageName, defaulting.AgentLatestVersion); !apiutils.IsEqualStruct(img, commonv1.AgentImageConfig{}) {
clcOverride.Image = img
}

Expand All @@ -1207,10 +1208,10 @@ func DefaultDatadogAgentSpecClusterChecksRunner(clusterChecksRunner *DatadogAgen

// DefaultDatadogAgentSpecClusterChecksRunnerImage used to default a ImageConfig for the Agent, Cluster Agent and the Cluster Check Runner.
// Returns the defaulted ImageConfig.
func DefaultDatadogAgentSpecClusterChecksRunnerImage(clc *DatadogAgentSpecClusterChecksRunnerSpec, name, tag string) *ImageConfig {
imgOverride := &ImageConfig{}
func DefaultDatadogAgentSpecClusterChecksRunnerImage(clc *DatadogAgentSpecClusterChecksRunnerSpec, name, tag string) *commonv1.AgentImageConfig {
imgOverride := &commonv1.AgentImageConfig{}
if clc.Image == nil {
clc.Image = &ImageConfig{}
clc.Image = &commonv1.AgentImageConfig{}
}

if clc.Image.Name == "" {
Expand Down

0 comments on commit 1bca592

Please sign in to comment.