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

Create local kind cluster install #647

Merged
merged 22 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7bfe97f
Create local kind cluster install
KevinFairise2 Feb 26, 2024
33a1630
Merge branch 'main' into kfairise/local-kind
KevinFairise2 Feb 28, 2024
8e47989
Add API on Kubernetes Agent to be able to set environment variables
KevinFairise2 Apr 4, 2024
b952dac
Update fakeintake env vars to be able to not use ssl
KevinFairise2 Apr 4, 2024
0fa8d53
Local Fakeintake in Kubernetes
KevinFairise2 Apr 4, 2024
5df1e3c
Use const for localPort
KevinFairise2 Apr 4, 2024
2d12c95
Merge branch 'main' of github.com:DataDog/test-infra-definitions into…
KevinFairise2 Apr 4, 2024
02f7fb0
Fix lint
KevinFairise2 Apr 4, 2024
fde677b
Do not install the fakeintake in Kubernetes, rather use a docker vers…
KevinFairise2 Apr 10, 2024
29982fd
Remove runner interface try
KevinFairise2 Apr 10, 2024
7804b1e
Remove not needed env var configuration
KevinFairise2 Apr 10, 2024
2e39a1d
Remove unneeded kubeconfig modif
KevinFairise2 Apr 10, 2024
a12d6bf
Remove configureEnvVars
KevinFairise2 Apr 10, 2024
acafc92
Make linter happy
KevinFairise2 Apr 12, 2024
f77c11b
Remove AMI
KevinFairise2 Apr 22, 2024
5542a3f
Update components/datadog/fakeintake/docker.go
KevinFairise2 Apr 22, 2024
050bab2
Update components/datadog/fakeintake/docker.go
KevinFairise2 Apr 22, 2024
9f6baba
gofmt
KevinFairise2 Apr 23, 2024
8d100bc
gomodtidy
KevinFairise2 Apr 23, 2024
9f6a94e
Handle error
KevinFairise2 May 13, 2024
bfc0096
Merge branch 'main' of github.com:DataDog/test-infra-definitions into…
KevinFairise2 May 13, 2024
df37cf1
Use new Env interface
KevinFairise2 May 13, 2024
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
6 changes: 6 additions & 0 deletions common/config/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/pulumi/pulumi-awsx/sdk/v2/go/awsx"
"github.com/pulumi/pulumi-command/sdk/go/command"
"github.com/pulumi/pulumi-docker/sdk/v4/go/docker"
"github.com/pulumi/pulumi-eks/sdk/v2/go/eks"
"github.com/pulumi/pulumi-random/sdk/v4/go/random"
"github.com/pulumi/pulumi-tls/sdk/v4/go/tls"
Expand All @@ -22,6 +23,7 @@ const (
ProviderAWSX ProviderID = "awsx"
ProviderEKS ProviderID = "eks"
ProviderAzure ProviderID = "azure"
ProviderDocker ProviderID = "docker"
)

func dummyProvidersFactory() map[ProviderID]func(ctx *pulumi.Context, name string) (pulumi.ProviderResource, error) {
Expand All @@ -46,6 +48,10 @@ func dummyProvidersFactory() map[ProviderID]func(ctx *pulumi.Context, name strin
provider, err := eks.NewProvider(ctx, name, nil)
return provider, err
},
ProviderDocker: func(ctx *pulumi.Context, name string) (pulumi.ProviderResource, error) {
provider, err := docker.NewProvider(ctx, name, nil)
return provider, err
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/datadog/agent/kubernetes_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func (values HelmValues) configureFakeintake(e config.Env, fakeintake *fakeintak
},
pulumi.StringMap{
"name": pulumi.String("DD_LOGS_CONFIG_ADDITIONAL_ENDPOINTS"),
"value": pulumi.Sprintf(`[{"host": "%s"}]`, fakeintake.Host),
"value": pulumi.Sprintf(`[{"host": "%s", "port": %v, "use_ssl": "%t"}]`, fakeintake.Host, fakeintake.Port, fakeintake.Scheme == "https"),
KevinFairise2 marked this conversation as resolved.
Show resolved Hide resolved
},
pulumi.StringMap{
"name": pulumi.String("DD_LOGS_CONFIG_USE_HTTP"),
Expand Down
57 changes: 57 additions & 0 deletions components/datadog/fakeintake/docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package fakeintake

import (
"net"

"github.com/DataDog/test-infra-definitions/common/config"
"github.com/DataDog/test-infra-definitions/components"
"github.com/pulumi/pulumi-docker/sdk/v4/go/docker"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

const hostPort = 30080

func NewLocalDockerFakeintake(e config.Env, resourceName string) (*Fakeintake, error) {
return components.NewComponent(e, resourceName, func(comp *Fakeintake) error {

_, err := docker.NewContainer(e.Ctx(), e.CommonNamer().ResourceName("local-docker-container"), &docker.ContainerArgs{
Image: pulumi.String("public.ecr.aws/datadog/fakeintake:latest"),
Ports: docker.ContainerPortArray{
&docker.ContainerPortArgs{
Internal: pulumi.Int(80),
External: pulumi.Int(hostPort),
},
},
}, e.WithProviders(config.ProviderDocker))
if err != nil {
return err
}

localIP, err := getLocalIP()
if err != nil {
return err
}

comp.Host = pulumi.Sprintf(localIP.String())
comp.Port = hostPort
comp.Scheme = "http"
comp.URL = pulumi.Sprintf("%s://%s:%d", comp.Scheme, comp.Host, comp.Port)

return nil
})
}

func getLocalIP() (net.IP, error) {
// Open a connection to an external valid URL to
// get the local address from the connection instance
// The URL does not need to exist
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
return nil, err
}
defer conn.Close()

localAddr := conn.LocalAddr().(*net.UDPAddr)

return localAddr.IP, nil
}
1 change: 1 addition & 0 deletions components/kubernetes/kind-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ containerdConfigPatches:
networking:
apiServerAddress: "0.0.0.0"
apiServerPort: 8443

58 changes: 58 additions & 0 deletions components/kubernetes/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kubernetes
import (
_ "embed"
"fmt"

"regexp"
"strings"

Expand Down Expand Up @@ -108,3 +109,60 @@ func NewKindCluster(env config.Env, vm *remote.Host, resourceName, kindClusterNa
return nil
}, opts...)
}

func NewLocalKindCluster(env config.Env, resourceName, kindClusterName string, kubeVersion string, opts ...pulumi.ResourceOption) (*Cluster, error) {
return components.NewComponent(env, resourceName, func(clusterComp *Cluster) error {
opts = utils.MergeOptions[pulumi.ResourceOption](opts, pulumi.Parent(clusterComp))
commonEnvironment := env

kindVersionConfig, err := getKindVersionConfig(kubeVersion)
if err != nil {
return err
}

runner := command.NewLocalRunner(env, command.LocalRunnerArgs{
// User: user.Username,
OSCommand: command.NewUnixOSCommand(),
})

clusterConfigFilePath := fmt.Sprintf("/tmp/kind-cluster-%s.yaml", kindClusterName)
clusterConfig, err := runner.Command("kind-config", &command.Args{
Create: pulumi.Sprintf("cat - | tee %s > /dev/null", clusterConfigFilePath),
Delete: pulumi.Sprintf("rm -f %s", clusterConfigFilePath),
Stdin: pulumi.String(kindClusterConfig),
}, opts...)
if err != nil {
return err
}

nodeImage := fmt.Sprintf("%s/%s:%s", env.InfraOSDescriptor(), kindNodeImageName, kindVersionConfig.nodeImageVersion)
createCluster, err := runner.Command(
commonEnvironment.CommonNamer().ResourceName("kind-create-cluster", resourceName),
&command.Args{
Create: pulumi.Sprintf("kind create cluster --name %s --config %s --image %s --wait %s", kindClusterName, clusterConfigFilePath, nodeImage, kindReadinessWait),
Delete: pulumi.Sprintf("kind delete cluster --name %s", kindClusterName),
Triggers: pulumi.Array{pulumi.String(kindClusterConfig)},
},
utils.MergeOptions(opts, utils.PulumiDependsOn(clusterConfig), pulumi.DeleteBeforeReplace(true))...,
)
if err != nil {
return err
}

kubeConfigCmd, err := runner.Command(
commonEnvironment.CommonNamer().ResourceName("kind-kubeconfig", resourceName),
&command.Args{
Create: pulumi.Sprintf("kind get kubeconfig --name %s", kindClusterName),
},
utils.MergeOptions(opts, utils.PulumiDependsOn(createCluster))...,
)
if err != nil {
return err
}

clusterComp.KubeConfig = kubeConfigCmd.Stdout
clusterComp.ClusterName = pulumi.String(kindClusterName).ToStringOutput()

return nil
}, opts...)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/pulumi/pulumi-azure-native-sdk/network/v2 v2.30.0
github.com/pulumi/pulumi-azure-native-sdk/v2 v2.30.0
github.com/pulumi/pulumi-command/sdk v0.9.2
github.com/pulumi/pulumi-docker/sdk/v4 v4.5.1
github.com/pulumi/pulumi-eks/sdk/v2 v2.2.1
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.9.0
github.com/pulumi/pulumi-libvirt/sdk v0.4.5
Expand Down Expand Up @@ -103,7 +104,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect
github.com/pulumi/esc v0.8.2 // indirect
github.com/pulumi/pulumi-docker/sdk/v4 v4.5.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
Expand Down