Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/pulumi/pulu…
Browse files Browse the repository at this point in the history
…mi-docker/sdk/v4-4.5.7
  • Loading branch information
pducolin authored Dec 12, 2024
2 parents 93e2a89 + 63fe2ae commit 810368f
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPACE }}/apps-${{ matrix.image }}

Expand Down
8 changes: 8 additions & 0 deletions common/utils/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import (
"gopkg.in/yaml.v3"
)

func YAMLMustMarshal(v any) string {
b, err := yaml.Marshal(v)
if err != nil {
panic(err)
}
return string(b)
}

func MergeYAML(oldValuesYamlContent string, newValuesYamlContent string) (string, error) {
return mergeYAML(oldValuesYamlContent, newValuesYamlContent, false)
}
Expand Down
37 changes: 37 additions & 0 deletions components/datadog/agent/kubernetes_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,43 @@ func buildLinuxHelmValues(baseName, agentImagePath, agentImageTag, clusterAgentI
"value": pulumi.String("true"),
},
},
"confd": pulumi.StringMap{
"kubernetes_state_core.yaml": pulumi.String(utils.YAMLMustMarshal(map[string]interface{}{
"init_config": nil,
"instances": []map[string]interface{}{
{
"collectors": []string{
"secrets",
"configmaps",
"nodes",
"pods",
"services",
"resourcequotas",
"replicationcontrollers",
"limitranges",
"persistentvolumeclaims",
"persistentvolumes",
"namespaces",
"endpoints",
"daemonsets",
"deployments",
"replicasets",
"statefulsets",
"cronjobs",
"jobs",
"horizontalpodautoscalers",
"poddisruptionbudgets",
"storageclasses",
"volumeattachments",
"ingresses",
"verticalpodautoscalers",
},
"labels_as_tags": map[string]interface{}{},
"annotations_as_tags": map[string]interface{}{},
},
},
})),
},
},
"clusterChecksRunner": pulumi.Map{
"enabled": pulumi.Bool(true),
Expand Down
57 changes: 39 additions & 18 deletions components/datadog/apps/nginx/k8s.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package nginx

import (
"fmt"

"github.com/DataDog/test-infra-definitions/common/config"
"github.com/DataDog/test-infra-definitions/common/utils"
componentskube "github.com/DataDog/test-infra-definitions/components/kubernetes"

"github.com/Masterminds/semver"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/apiextensions"
appsv1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/apps/v1"
autoscalingv2 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/autoscaling/v2"
autoscalingv2beta2 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/autoscaling/v2beta2"
corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1"
metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/meta/v1"
policyv1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/policy/v1"
policyv1beta1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/policy/v1beta1"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/yaml"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

Expand Down Expand Up @@ -214,21 +212,19 @@ func K8sAppDefinition(e config.Env, kubeProvider *kubernetes.Provider, namespace
}

if withDatadogAutoscaling {
ddm, err := yaml.NewConfigGroup(e.Ctx(), namespace+"/nginx", &yaml.ConfigGroupArgs{
Objs: []map[string]any{
{
"apiVersion": "datadoghq.com/v1alpha1",
"kind": "DatadogMetric",
"metadata": map[string]any{
"name": "nginx",
"namespace": namespace,
"labels": map[string]string{
"app": "nginx",
},
},
"spec": map[string]any{
"query": fmt.Sprintf("avg:nginx.net.request_per_s{kube_cluster_name:%%%%tag_kube_cluster_name%%%%,kube_namespace:%s,kube_deployment:nginx}.rollup(60)", namespace),
},
ddm, err := apiextensions.NewCustomResource(e.Ctx(), namespace+"/nginx", &apiextensions.CustomResourceArgs{
ApiVersion: pulumi.String("datadoghq.com/v1alpha1"),
Kind: pulumi.String("DatadogMetric"),
Metadata: &metav1.ObjectMetaArgs{
Name: pulumi.String("nginx"),
Namespace: pulumi.String(namespace),
Labels: pulumi.StringMap{
"app": pulumi.String("nginx"),
},
},
OtherFields: map[string]interface{}{
"spec": pulumi.Map{
"query": pulumi.Sprintf("avg:nginx.net.request_per_s{kube_cluster_name:%%%%tag_kube_cluster_name%%%%,kube_namespace:%s,kube_deployment:nginx}.rollup(60)", namespace),
},
},
}, opts...)
Expand Down Expand Up @@ -321,6 +317,31 @@ func K8sAppDefinition(e config.Env, kubeProvider *kubernetes.Provider, namespace
}
}

if _, err := apiextensions.NewCustomResource(e.Ctx(), namespace+"/nginx", &apiextensions.CustomResourceArgs{
ApiVersion: pulumi.String("autoscaling.k8s.io/v1beta2"),
Kind: pulumi.String("VerticalPodAutoscaler"),
Metadata: &metav1.ObjectMetaArgs{
Name: pulumi.String("nginx"),
Namespace: pulumi.String(namespace),
Labels: pulumi.StringMap{
"app": pulumi.String("nginx"),
},
},
OtherFields: map[string]interface{}{
"spec": pulumi.Map{
"targetRef": pulumi.Map{
"apiVersion": pulumi.String("apps/v1"),
"kind": pulumi.String("Deployment"),
"name": pulumi.String("nginx"),
},
"updatePolicy": pulumi.Map{
"updateMode": pulumi.String("Auto"),
},
},
},
}, opts...); err != nil {
return nil, err
}
}

if _, err := corev1.NewService(e.Ctx(), namespace+"/nginx", &corev1.ServiceArgs{
Expand Down
57 changes: 39 additions & 18 deletions components/datadog/apps/redis/k8s.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package redis

import (
"fmt"

"github.com/DataDog/test-infra-definitions/common/config"
"github.com/DataDog/test-infra-definitions/common/utils"
componentskube "github.com/DataDog/test-infra-definitions/components/kubernetes"
"github.com/Masterminds/semver"

"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/apiextensions"
appsv1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/apps/v1"
autoscalingv2 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/autoscaling/v2"
autoscalingv2beta2 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/autoscaling/v2beta2"
corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1"
metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/meta/v1"
policyv1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/policy/v1"
policyv1beta1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/policy/v1beta1"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/yaml"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

Expand Down Expand Up @@ -157,21 +155,19 @@ func K8sAppDefinition(e config.Env, kubeProvider *kubernetes.Provider, namespace
}

if withDatadogAutoscaling {
ddm, err := yaml.NewConfigGroup(e.Ctx(), "redis", &yaml.ConfigGroupArgs{
Objs: []map[string]any{
{
"apiVersion": "datadoghq.com/v1alpha1",
"kind": "DatadogMetric",
"metadata": map[string]any{
"name": "redis",
"namespace": namespace,
"labels": map[string]string{
"app": "redis",
},
},
"spec": map[string]any{
"query": fmt.Sprintf("avg:redis.net.instantaneous_ops_per_sec{kube_cluster_name:%%%%tag_kube_cluster_name%%%%,kube_namespace:%s,kube_deployment:redis}.rollup(60)", namespace),
},
ddm, err := apiextensions.NewCustomResource(e.Ctx(), "redis", &apiextensions.CustomResourceArgs{
ApiVersion: pulumi.String("datadoghq.com/v1alpha1"),
Kind: pulumi.String("DatadogMetric"),
Metadata: &metav1.ObjectMetaArgs{
Name: pulumi.String("redis"),
Namespace: pulumi.String(namespace),
Labels: pulumi.StringMap{
"app": pulumi.String("redis"),
},
},
OtherFields: map[string]interface{}{
"spec": pulumi.Map{
"query": pulumi.Sprintf("avg:redis.net.instantaneous_ops_per_sec{kube_cluster_name:%%%%tag_kube_cluster_name%%%%,kube_namespace:%s,kube_deployment:redis}.rollup(60)", namespace),
},
},
}, opts...)
Expand Down Expand Up @@ -254,6 +250,31 @@ func K8sAppDefinition(e config.Env, kubeProvider *kubernetes.Provider, namespace
}
}

if _, err := apiextensions.NewCustomResource(e.Ctx(), "redis", &apiextensions.CustomResourceArgs{
ApiVersion: pulumi.String("autoscaling.k8s.io/v1beta2"),
Kind: pulumi.String("VerticalPodAutoscaler"),
Metadata: &metav1.ObjectMetaArgs{
Name: pulumi.String("redis"),
Namespace: pulumi.String(namespace),
Labels: pulumi.StringMap{
"app": pulumi.String("redis"),
},
},
OtherFields: map[string]interface{}{
"spec": pulumi.Map{
"targetRef": pulumi.Map{
"apiVersion": pulumi.String("apps/v1"),
"kind": pulumi.String("Deployment"),
"name": pulumi.String("redis"),
},
"updatePolicy": pulumi.Map{
"updateMode": pulumi.String("Auto"),
},
},
},
}, opts...); err != nil {
return nil, err
}
}

if _, err := corev1.NewService(e.Ctx(), "redis", &corev1.ServiceArgs{
Expand Down
114 changes: 114 additions & 0 deletions components/kubernetes/vpa/vpa.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package vpa

import (
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
apiextensions "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/apiextensions/v1"
metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/meta/v1"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"

"github.com/DataDog/test-infra-definitions/common/config"
)

func DeployCRD(e config.Env, kubeProvider *kubernetes.Provider, opts ...pulumi.ResourceOption) (*apiextensions.CustomResourceDefinition, error) {
opts = append(opts, pulumi.Providers(kubeProvider), pulumi.DeletedWith(kubeProvider))

// This is the definition from https://github.com/kubernetes/autoscaler/blob/4d092e5f0afd519b082972c4656b3d52ae512b64/vertical-pod-autoscaler/deploy/vpa-v1-crd.yaml
return apiextensions.NewCustomResourceDefinition(e.Ctx(), "vertical-pod-autoscaler", &apiextensions.CustomResourceDefinitionArgs{
Metadata: &metav1.ObjectMetaArgs{
Name: pulumi.String("verticalpodautoscalers.autoscaling.k8s.io"),
Annotations: pulumi.StringMap{
"api-approved.kubernetes.io": pulumi.String("https://github.com/kubernetes/kubernetes/pull/63797"),
},
},
Spec: &apiextensions.CustomResourceDefinitionSpecArgs{
Group: pulumi.String("autoscaling.k8s.io"),
Scope: pulumi.String("Namespaced"),
Names: &apiextensions.CustomResourceDefinitionNamesArgs{
Kind: pulumi.String("VerticalPodAutoscaler"),
ListKind: pulumi.String("VerticalPodAutoscalerList"),
Singular: pulumi.String("verticalpodautoscaler"),
Plural: pulumi.String("verticalpodautoscalers"),
ShortNames: pulumi.StringArray{pulumi.String("vpa")},
},
Versions: &apiextensions.CustomResourceDefinitionVersionArray{
&apiextensions.CustomResourceDefinitionVersionArgs{
Name: pulumi.String("v1beta2"),
Served: pulumi.Bool(true),
Storage: pulumi.Bool(true),
Schema: &apiextensions.CustomResourceValidationArgs{
OpenAPIV3Schema: &apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("object"),
Properties: apiextensions.JSONSchemaPropsMap{
"spec": apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("object"),
Properties: apiextensions.JSONSchemaPropsMap{
"targetRef": apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("object"),
},
"updatePolicy": apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("object"),
Properties: apiextensions.JSONSchemaPropsMap{
"minReplicas": apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("integer"),
},
"updateMode": apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("string"),
},
},
},
"resourcePolicy": apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("object"),
Properties: apiextensions.JSONSchemaPropsMap{
"containerPolicies": apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("array"),
Items: &apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("object"),
Properties: apiextensions.JSONSchemaPropsMap{
"containerName": apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("string"),
},
"controlledValue": apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("string"),
Enum: pulumi.Array{
pulumi.String("RequestsAndLimits"),
pulumi.String("RequestsOnly"),
},
},
"mode": apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("string"),
Enum: pulumi.Array{
pulumi.String("Auto"),
pulumi.String("Off"),
},
},
"minAllowed": apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("object"),
},
"maxAllowed": apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("object"),
},
"controlledResources": apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("array"),
Items: &apiextensions.JSONSchemaPropsArgs{
Type: pulumi.String("string"),
Enum: pulumi.Array{
pulumi.String("cpu"),
pulumi.String("memory"),
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
}, opts...)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.5

require (
dario.cat/mergo v1.0.1
github.com/DataDog/datadog-agent/pkg/util/optional v0.59.0
github.com/DataDog/datadog-agent/pkg/util/optional v0.59.1
github.com/Masterminds/semver v1.5.0
github.com/alessio/shellescape v1.4.2
github.com/aws/aws-sdk-go-v2 v1.32.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/DataDog/datadog-agent/pkg/util/optional v0.59.0 h1:IOZeoApM4NI6dw+Sdo4PalVU1Z6uoY3vuKdl5Jm6g2M=
github.com/DataDog/datadog-agent/pkg/util/optional v0.59.0/go.mod h1:xWT/KJdJg2/0pZyAKZ6XmIiE5sM+AyUo4qvKuPHQ17U=
github.com/DataDog/datadog-agent/pkg/util/optional v0.59.1 h1:mw6zkzgGk4r83qxvEdIcwWME0P18oJlgW7QdpIKMHQI=
github.com/DataDog/datadog-agent/pkg/util/optional v0.59.1/go.mod h1:xWT/KJdJg2/0pZyAKZ6XmIiE5sM+AyUo4qvKuPHQ17U=
github.com/HdrHistogram/hdrhistogram-go v1.1.2 h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob0t8PQPMybUNFM=
github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
Expand Down
Loading

0 comments on commit 810368f

Please sign in to comment.