Skip to content

Commit 0f87033

Browse files
[mq] working branch - merge eff6243 on top of main at e6dc4b0
{"baseBranch":"main","baseCommit":"e6dc4b092edd02292850439bf60f69f8e2b2a8df","createdAt":"2025-03-10T22:52:21.607384Z","headSha":"eff624343612589612306631420d008430f423c9","id":"7aa38d0c-b93a-4408-8bdc-aad5667dce31","priority":"200","pullRequestNumber":"1444","queuedAt":"2025-03-10T22:52:21.606565Z","status":"STATUS_QUEUED"}
2 parents ff46aa2 + eff6243 commit 0f87033

File tree

10 files changed

+250
-13
lines changed

10 files changed

+250
-13
lines changed

components/datadog/apps/npm-tools/k8s.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package npmtools
33
import (
44
"fmt"
55

6-
"github.com/DataDog/test-infra-definitions/common/config"
7-
"github.com/DataDog/test-infra-definitions/common/utils"
8-
componentskube "github.com/DataDog/test-infra-definitions/components/kubernetes"
9-
106
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
117
appsv1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/apps/v1"
128
corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1"
139
metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/meta/v1"
1410
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
11+
12+
"github.com/DataDog/test-infra-definitions/common/config"
13+
"github.com/DataDog/test-infra-definitions/common/utils"
14+
componentskube "github.com/DataDog/test-infra-definitions/components/kubernetes"
1515
)
1616

1717
func K8sAppDefinition(e config.Env, kubeProvider *kubernetes.Provider, namespace string, testURL string, opts ...pulumi.ResourceOption) (*componentskube.Workload, error) {
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package cilium
2+
3+
import (
4+
"reflect"
5+
6+
kubeHelm "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/helm/v3"
7+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
8+
9+
"github.com/DataDog/test-infra-definitions/common"
10+
)
11+
12+
type Params struct {
13+
HelmValues HelmValues
14+
Version string
15+
}
16+
17+
type Option = func(*Params) error
18+
19+
func NewParams(options ...Option) (*Params, error) {
20+
return common.ApplyOption(&Params{}, options)
21+
}
22+
23+
func WithHelmValues(values HelmValues) Option {
24+
return func(p *Params) error {
25+
p.HelmValues = values
26+
return nil
27+
}
28+
}
29+
30+
func WithVersion(version string) Option {
31+
return func(p *Params) error {
32+
p.Version = version
33+
return nil
34+
}
35+
}
36+
37+
type HelmComponent struct {
38+
pulumi.ResourceState
39+
40+
CiliumHelmReleaseStatus kubeHelm.ReleaseStatusOutput
41+
}
42+
43+
func boolValue(i pulumi.Input) bool {
44+
pv := reflect.ValueOf(i)
45+
if pv.Kind() == reflect.Ptr {
46+
if pv.IsNil() {
47+
return false
48+
}
49+
50+
pv = pv.Elem()
51+
}
52+
53+
return pv.Bool()
54+
}
55+
56+
func (p *Params) hasKubeProxyReplacement() bool {
57+
if v, ok := p.HelmValues["kubeProxyReplacement"]; ok {
58+
return boolValue(v)
59+
}
60+
61+
return false
62+
}

components/kubernetes/cilium/helm.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package cilium
2+
3+
import (
4+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
5+
6+
"github.com/DataDog/test-infra-definitions/common/config"
7+
"github.com/DataDog/test-infra-definitions/components/kubernetes"
8+
"github.com/DataDog/test-infra-definitions/resources/helm"
9+
)
10+
11+
type HelmValues pulumi.Map
12+
13+
func NewHelmInstallation(e config.Env, cluster *kubernetes.Cluster, params *Params, opts ...pulumi.ResourceOption) (*HelmComponent, error) {
14+
helmComponent := &HelmComponent{}
15+
if err := e.Ctx().RegisterComponentResource("dd:cilium", "cilium", helmComponent, opts...); err != nil {
16+
return nil, err
17+
}
18+
19+
if params.hasKubeProxyReplacement() {
20+
params.HelmValues["k8sServiceHost"] = cluster.KubeInternalServerAddress
21+
params.HelmValues["k8sServicePort"] = cluster.KubeInternalServerPort
22+
}
23+
24+
opts = append(opts, pulumi.Parent(helmComponent))
25+
ciliumBase, err := helm.NewInstallation(e, helm.InstallArgs{
26+
RepoURL: "https://helm.cilium.io",
27+
ChartName: "cilium",
28+
InstallName: "cilium",
29+
Namespace: "kube-system",
30+
Values: pulumi.Map(params.HelmValues),
31+
Version: pulumi.StringPtr(params.Version),
32+
}, opts...)
33+
if err != nil {
34+
return nil, err
35+
}
36+
37+
helmComponent.CiliumHelmReleaseStatus = ciliumBase.Status
38+
resourceOutputs := pulumi.Map{
39+
"CiliumBaseHelmReleaseStatus": ciliumBase.Status,
40+
}
41+
42+
if err := e.Ctx().RegisterResourceOutputs(helmComponent, resourceOutputs); err != nil {
43+
return nil, err
44+
}
45+
46+
return helmComponent, nil
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
nodes:
4+
- role: control-plane
5+
extraMounts:
6+
- hostPath: /proc
7+
containerPath: /host/proc
8+
- role: worker
9+
extraMounts:
10+
- hostPath: /proc
11+
containerPath: /host/proc
12+
containerdConfigPatches:
13+
- |-
14+
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
15+
endpoint = ["https://mirror.gcr.io", "https://registry-1.docker.io"]
16+
networking:
17+
apiServerAddress: "0.0.0.0"
18+
apiServerPort: 8443
19+
disableDefaultCNI: true
20+
{{if .KubeProxyReplacement}}
21+
kubeProxyMode: "none"
22+
{{end}}

components/kubernetes/cilium/kind.go

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package cilium
2+
3+
import (
4+
"embed"
5+
"fmt"
6+
"net/url"
7+
"strings"
8+
"text/template"
9+
10+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
11+
"gopkg.in/yaml.v3"
12+
13+
"github.com/DataDog/test-infra-definitions/common/config"
14+
"github.com/DataDog/test-infra-definitions/common/utils"
15+
"github.com/DataDog/test-infra-definitions/components/command"
16+
"github.com/DataDog/test-infra-definitions/components/kubernetes"
17+
"github.com/DataDog/test-infra-definitions/components/remote"
18+
)
19+
20+
//go:embed kind-cilium-cluster.yaml
21+
var kindCilumClusterFS embed.FS
22+
23+
func kindKubeClusterConfigFromCiliumParams(params *Params) (string, error) {
24+
o := struct {
25+
KubeProxyReplacement bool
26+
}{
27+
KubeProxyReplacement: params.hasKubeProxyReplacement(),
28+
}
29+
30+
kindCiliumClusterTemplate, err := template.ParseFS(kindCilumClusterFS, "kind-cilium-cluster.yaml")
31+
if err != nil {
32+
return "", err
33+
}
34+
35+
var kindCilumClusterConfig strings.Builder
36+
if err = kindCiliumClusterTemplate.Execute(&kindCilumClusterConfig, o); err != nil {
37+
return "", err
38+
}
39+
40+
return kindCilumClusterConfig.String(), nil
41+
}
42+
43+
func NewKindCluster(env config.Env, vm *remote.Host, name string, kubeVersion string, ciliumOpts []Option, opts ...pulumi.ResourceOption) (*kubernetes.Cluster, error) {
44+
params, err := NewParams(ciliumOpts...)
45+
if err != nil {
46+
return nil, fmt.Errorf("could not create cilium params from opts: %w", err)
47+
}
48+
49+
clusterConfig, err := kindKubeClusterConfigFromCiliumParams(params)
50+
if err != nil {
51+
return nil, err
52+
}
53+
54+
cluster, err := kubernetes.NewKindClusterWithConfig(env, vm, name, kubeVersion, clusterConfig, opts...)
55+
if err != nil {
56+
return nil, err
57+
}
58+
59+
if params.hasKubeProxyReplacement() {
60+
runner := vm.OS.Runner()
61+
kindClusterName := env.CommonNamer().DisplayName(49) // We can have some issues if the name is longer than 50 characters
62+
kubeConfigInternalCmd, err := runner.Command(
63+
env.CommonNamer().ResourceName("kube-kubeconfig-internal"),
64+
&command.Args{
65+
Create: pulumi.Sprintf("kind get kubeconfig --name %s --internal", kindClusterName),
66+
},
67+
utils.MergeOptions(opts, utils.PulumiDependsOn(cluster))...,
68+
)
69+
if err != nil {
70+
return nil, err
71+
}
72+
73+
hostPort := kubeConfigInternalCmd.StdoutOutput().ApplyT(
74+
func(v string) ([]string, error) {
75+
out := map[string]interface{}{}
76+
if err := yaml.Unmarshal([]byte(v), out); err != nil {
77+
return nil, fmt.Errorf("error unmarshaling output of kubeconfig: %w", err)
78+
}
79+
80+
clusters := out["clusters"].([]interface{})
81+
cluster := clusters[0].(map[string]interface{})["cluster"]
82+
server := cluster.(map[string]interface{})["server"].(string)
83+
u, err := url.Parse(server)
84+
if err != nil {
85+
return nil, fmt.Errorf("could not parse server address %s: %w", server, err)
86+
}
87+
88+
return []string{u.Hostname(), u.Port()}, nil
89+
},
90+
).(pulumi.StringArrayOutput)
91+
92+
cluster.KubeInternalServerAddress = hostPort.Index(pulumi.Int(0))
93+
cluster.KubeInternalServerPort = hostPort.Index(pulumi.Int(1))
94+
}
95+
96+
return cluster, nil
97+
}

components/kubernetes/component.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package kubernetes
22

33
import (
4-
"github.com/DataDog/test-infra-definitions/components"
54
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
65
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
6+
7+
"github.com/DataDog/test-infra-definitions/components"
78
)
89

910
// The type that is used to import the KubernetesCluster component
@@ -21,8 +22,10 @@ type Cluster struct {
2122

2223
KubeProvider *kubernetes.Provider
2324

24-
ClusterName pulumi.StringOutput `pulumi:"clusterName"`
25-
KubeConfig pulumi.StringOutput `pulumi:"kubeConfig"`
25+
ClusterName pulumi.StringOutput `pulumi:"clusterName"`
26+
KubeConfig pulumi.StringOutput `pulumi:"kubeConfig"`
27+
KubeInternalServerAddress pulumi.StringOutput `pulumi:"kubeInternalServerAddress"`
28+
KubeInternalServerPort pulumi.StringOutput `pulumi:"kubeInternalServerPort"`
2629
}
2730

2831
func (c *Cluster) Export(ctx *pulumi.Context, out *ClusterOutput) error {

components/kubernetes/istio/istio.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func NewHelmInstallation(e config.Env, opts ...pulumi.ResourceOption) (*HelmComp
119119
return helmComponent, nil
120120
}
121121

122-
func NewHttpbinServiceInstallation(e config.CommonEnvironment, opts ...pulumi.ResourceOption) (*corev1.Service, error) {
122+
func NewHttpbinServiceInstallation(e config.Env, opts ...pulumi.ResourceOption) (*corev1.Service, error) {
123123
// deploy httpbin on default namespace
124124
httpbinServiceAccount, err := corev1.NewServiceAccount(e.Ctx(), "httpbin", &corev1.ServiceAccountArgs{
125125
Metadata: metav1.ObjectMetaArgs{Name: pulumi.String("httpbin")},

components/kubernetes/k8sapply/component.go

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package k8sapply
22

33
import (
44
"fmt"
5+
56
"github.com/DataDog/test-infra-definitions/common/config"
67
kubeComp "github.com/DataDog/test-infra-definitions/components/kubernetes"
78
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"

components/kubernetes/kind.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ package kubernetes
33
import (
44
_ "embed"
55
"fmt"
6-
76
"regexp"
87
"strings"
98

9+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
10+
1011
"github.com/DataDog/test-infra-definitions/common/config"
1112
"github.com/DataDog/test-infra-definitions/common/utils"
1213
"github.com/DataDog/test-infra-definitions/components"
1314
"github.com/DataDog/test-infra-definitions/components/command"
1415
"github.com/DataDog/test-infra-definitions/components/docker"
1516
"github.com/DataDog/test-infra-definitions/components/os"
1617
"github.com/DataDog/test-infra-definitions/components/remote"
17-
18-
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
1918
)
2019

2120
const (
@@ -28,6 +27,10 @@ var kindClusterConfig string
2827

2928
// Install Kind on a Linux virtual machine.
3029
func NewKindCluster(env config.Env, vm *remote.Host, name string, kubeVersion string, opts ...pulumi.ResourceOption) (*Cluster, error) {
30+
return NewKindClusterWithConfig(env, vm, name, kubeVersion, kindClusterConfig, opts...)
31+
}
32+
33+
func NewKindClusterWithConfig(env config.Env, vm *remote.Host, name string, kubeVersion, kindConfig string, opts ...pulumi.ResourceOption) (*Cluster, error) {
3134
return components.NewComponent(env, name, func(clusterComp *Cluster) error {
3235
kindClusterName := env.CommonNamer().DisplayName(49) // We can have some issues if the name is longer than 50 characters
3336
opts = utils.MergeOptions[pulumi.ResourceOption](opts, pulumi.Parent(clusterComp))
@@ -57,7 +60,7 @@ func NewKindCluster(env config.Env, vm *remote.Host, name string, kubeVersion st
5760

5861
clusterConfigFilePath := fmt.Sprintf("/tmp/kind-cluster-%s.yaml", name)
5962
clusterConfig, err := vm.OS.FileManager().CopyInlineFile(
60-
pulumi.String(kindClusterConfig),
63+
pulumi.String(kindConfig),
6164
clusterConfigFilePath, opts...)
6265
if err != nil {
6366
return err
@@ -69,7 +72,7 @@ func NewKindCluster(env config.Env, vm *remote.Host, name string, kubeVersion st
6972
&command.Args{
7073
Create: pulumi.Sprintf("kind create cluster --name %s --config %s --image %s --wait %s", kindClusterName, clusterConfigFilePath, nodeImage, kindReadinessWait),
7174
Delete: pulumi.Sprintf("kind delete cluster --name %s", kindClusterName),
72-
Triggers: pulumi.Array{pulumi.String(kindClusterConfig)},
75+
Triggers: pulumi.Array{pulumi.String(kindConfig)},
7376
},
7477
utils.MergeOptions(opts, utils.PulumiDependsOn(clusterConfig, kindInstall), pulumi.DeleteBeforeReplace(true))...,
7578
)

resources/helm/helm.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type InstallArgs struct {
1414
Namespace string
1515
ValuesYAML pulumi.AssetOrArchiveArrayInput
1616
Values pulumi.MapInput
17+
Version pulumi.StringPtrInput
1718
}
1819

1920
// Important: set relevant Kubernetes provider in `opts`
@@ -29,5 +30,6 @@ func NewInstallation(e config.Env, args InstallArgs, opts ...pulumi.ResourceOpti
2930
DependencyUpdate: pulumi.BoolPtr(true),
3031
ValueYamlFiles: args.ValuesYAML,
3132
Values: args.Values,
33+
Version: args.Version,
3234
}, opts...)
3335
}

0 commit comments

Comments
 (0)