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 15 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.
Jump to
Jump to file
Failed to load files.
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 @@ -393,7 +393,7 @@ func (values HelmValues) configureFakeintake(e config.CommonEnvironment, fakeint
},
pulumi.Map{
"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.Map{
"name": pulumi.String("DD_LOGS_CONFIG_USE_HTTP"),
Expand Down
52 changes: 52 additions & 0 deletions components/datadog/fakeintake/docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package fakeintake

import (
"log"
"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.CommonEnvironment, 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 := getLocalIP()
KevinFairise2 marked this conversation as resolved.
Show resolved Hide resolved

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 {
conn, err := net.Dial("udp", "255.255.255.255:80") // initiate a connection to get the local address, the url does not need to exist
KevinFairise2 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Fatal(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ question
Should you rather return the error, instead of panicking?

}
defer conn.Close()

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

return localAddr.IP
}
1 change: 1 addition & 0 deletions components/kubernetes/kind-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,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.CommonEnvironment, vm *remote.Host, resourceName,
return nil
}, opts...)
}

func NewLocalKindCluster(env config.CommonEnvironment, 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", kindNodeImageRegistry, kindVersionConfig.nodeImageVersion)
KevinFairise2 marked this conversation as resolved.
Show resolved Hide resolved
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...)
}