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

ADX-252 Local kubernetes provider #23153

Merged
merged 48 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
b1433fe
Create kindvm provider and kindvm host
KevinFairise2 Feb 8, 2024
144baff
Merge branch 'main' into kfairise/kindvm-provisioner
KevinFairise2 Feb 12, 2024
e513cf5
Create kindvm scenario test
KevinFairise2 Feb 13, 2024
7e41abe
Use test-infra commit
KevinFairise2 Feb 13, 2024
8101da1
Update test/new-e2e/examples/kindvm_test.go
KevinFairise2 Feb 14, 2024
5a0c67e
Address suggestions
KevinFairise2 Feb 14, 2024
9390033
Merge branch 'kfairise/kindvm-provisioner' of github.com:DataDog/data…
KevinFairise2 Feb 14, 2024
dfc3036
Merge branch 'main' into kfairise/kindvm-provisioner
KevinFairise2 Feb 15, 2024
d5366fe
WIP
KevinFairise2 Feb 16, 2024
f482714
Address suggestions
KevinFairise2 Feb 19, 2024
2fa0ecb
Rename KubernetesHost to Kubernetes
KevinFairise2 Feb 19, 2024
4cbb71d
Tidy
KevinFairise2 Feb 19, 2024
7b58c56
Merge branch 'main' into kfairise/kindvm-provisioner
KevinFairise2 Feb 20, 2024
1025db0
Update test
KevinFairise2 Feb 20, 2024
285a533
Rename kind test
KevinFairise2 Feb 20, 2024
ba19615
Fix linter
KevinFairise2 Feb 20, 2024
c19c0a8
Merge branch 'main' into kfairise/kindvm-provisioner
KevinFairise2 Feb 22, 2024
30f919c
Update go + runner image
KevinFairise2 Feb 22, 2024
3c98ec3
Tidy
KevinFairise2 Feb 22, 2024
189e9d1
Create local kind provisioner
KevinFairise2 Feb 26, 2024
8d71c97
Merge branch 'main' into kfairise/local-kind
KevinFairise2 Feb 28, 2024
dc4c692
Bump deps
KevinFairise2 Feb 28, 2024
feb0633
Update init of fakeintake to use clientURL if provided
KevinFairise2 Apr 4, 2024
3f2d686
Update local kind provider to deploy a local fakeintake
KevinFairise2 Apr 4, 2024
1d9ecfd
Merge branch 'main' of github.com:DataDog/datadog-agent into kfairise…
KevinFairise2 Apr 4, 2024
ee90b6b
Exclude fakeintake container from log collection
KevinFairise2 Apr 4, 2024
72930fe
Remove useless commented code
KevinFairise2 Apr 4, 2024
a2a4c6e
Remove newline
KevinFairise2 Apr 4, 2024
2fd3660
Remove useless options
KevinFairise2 Apr 4, 2024
768d1e4
Update test-infra
KevinFairise2 Apr 4, 2024
0831734
Tidy
KevinFairise2 Apr 4, 2024
baac558
Remove deleted field
KevinFairise2 Apr 4, 2024
0f898dc
WIP
KevinFairise2 Apr 11, 2024
5e5ddf9
Merge branch 'main' of github.com:DataDog/datadog-agent into kfairise…
KevinFairise2 May 16, 2024
aad9aa5
Create example and last fixes
KevinFairise2 May 16, 2024
37284b6
Fix K8SApp signature change
KevinFairise2 May 24, 2024
68463c3
Fix release name change
KevinFairise2 May 24, 2024
295c7d3
Fix release name change
KevinFairise2 May 24, 2024
1b166f7
Merge branch 'main' into kfairise/local-kind
KevinFairise2 May 24, 2024
fff6654
Update test-infra version
KevinFairise2 May 24, 2024
d3f47fb
Fix test-infra bump issues
KevinFairise2 May 24, 2024
c72d8b1
Tidy
KevinFairise2 May 24, 2024
05b433c
Pass provider in eks provider
KevinFairise2 May 24, 2024
b316884
Enable autoscaling
KevinFairise2 May 27, 2024
4f8f534
Bump test-infra to fix quote
KevinFairise2 May 27, 2024
176882d
Fix orchestrator test
KevinFairise2 May 27, 2024
1eb060d
Fix orchestrator test
KevinFairise2 May 28, 2024
dacbe46
Final bump of test-infra
KevinFairise2 May 28, 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
39 changes: 39 additions & 0 deletions test/new-e2e/examples/kind_local_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 examples

import (
"context"
"strings"
"testing"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
localkubernetes "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments/local/kubernetes"
"github.com/stretchr/testify/assert"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type myLocalKindSuite struct {
e2e.BaseSuite[environments.Kubernetes]
}

func TestMyLocalKindSuite(t *testing.T) {
e2e.Run(t, &myLocalKindSuite{}, e2e.WithProvisioner(localkubernetes.Provisioner()))
}

func (v *myLocalKindSuite) TestClusterAgentInstalled() {
res, _ := v.Env().KubernetesCluster.Client().CoreV1().Pods("datadog").List(context.TODO(), v1.ListOptions{})
containsClusterAgent := false
for _, pod := range res.Items {
if strings.Contains(pod.Name, "cluster-agent") {
containsClusterAgent = true
break
}
}
assert.True(v.T(), containsClusterAgent, "Cluster Agent not found")
assert.Equal(v.T(), v.Env().Agent.InstallNameLinux, "dda")
}
2 changes: 1 addition & 1 deletion test/new-e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
// `TEST_INFRA_DEFINITIONS_BUILDIMAGES` matches the commit sha in the module version
// Example: github.com/DataDog/test-infra-definitions v0.0.0-YYYYMMDDHHmmSS-0123456789AB
// => TEST_INFRA_DEFINITIONS_BUILDIMAGES: 0123456789AB
github.com/DataDog/test-infra-definitions v0.0.0-20240507122412-65fbab1e1eaf
github.com/DataDog/test-infra-definitions v0.0.0-20240516134444-36386457bf95
github.com/aws/aws-sdk-go-v2 v1.26.1
github.com/aws/aws-sdk-go-v2/config v1.27.11
github.com/aws/aws-sdk-go-v2/service/ec2 v1.138.1
Expand Down
4 changes: 2 additions & 2 deletions test/new-e2e/go.sum

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

185 changes: 185 additions & 0 deletions test/new-e2e/pkg/environments/local/kubernetes/kind.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
// 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 localkubernetes contains the provisioner for the local Kubernetes based environments
package localkubernetes

import (
"fmt"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/optional"

"github.com/DataDog/test-infra-definitions/components/datadog/agent"
"github.com/DataDog/test-infra-definitions/resources/local"

fakeintakeComp "github.com/DataDog/test-infra-definitions/components/datadog/fakeintake"
"github.com/DataDog/test-infra-definitions/components/datadog/kubernetesagentparams"
kubeComp "github.com/DataDog/test-infra-definitions/components/kubernetes"
"github.com/DataDog/test-infra-definitions/scenarios/aws/fakeintake"

"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

const (
provisionerBaseID = "aws-kind-"
defaultVMName = "kind"
)

// ProvisionerParams contains all the parameters needed to create the environment
type ProvisionerParams struct {
name string
agentOptions []kubernetesagentparams.Option
fakeintakeOptions []fakeintake.Option
extraConfigParams runner.ConfigMap
}

func newProvisionerParams() *ProvisionerParams {
return &ProvisionerParams{
name: defaultVMName,
agentOptions: []kubernetesagentparams.Option{},
fakeintakeOptions: []fakeintake.Option{},
extraConfigParams: runner.ConfigMap{},
}
}

// ProvisionerOption is a function that modifies the ProvisionerParams
type ProvisionerOption func(*ProvisionerParams) error

// WithName sets the name of the provisioner
func WithName(name string) ProvisionerOption {
return func(params *ProvisionerParams) error {
params.name = name
return nil
}
}

// WithAgentOptions adds options to the agent
func WithAgentOptions(opts ...kubernetesagentparams.Option) ProvisionerOption {
return func(params *ProvisionerParams) error {
params.agentOptions = opts
return nil
}
}

// WithoutFakeIntake removes the fake intake
func WithoutFakeIntake() ProvisionerOption {
return func(params *ProvisionerParams) error {
params.fakeintakeOptions = nil
return nil
}
}

// WithoutAgent removes the agent
func WithoutAgent() ProvisionerOption {
return func(params *ProvisionerParams) error {
params.agentOptions = nil
return nil
}
}

// WithExtraConfigParams adds extra config parameters to the environment
func WithExtraConfigParams(configMap runner.ConfigMap) ProvisionerOption {
return func(params *ProvisionerParams) error {
params.extraConfigParams = configMap
return nil
}
}

// Provisioner creates a new provisioner
func Provisioner(opts ...ProvisionerOption) e2e.TypedProvisioner[environments.Kubernetes] {
// We ALWAYS need to make a deep copy of `params`, as the provisioner can be called multiple times.
// and it's easy to forget about it, leading to hard to debug issues.
params := newProvisionerParams()
_ = optional.ApplyOptions(params, opts)

provisioner := e2e.NewTypedPulumiProvisioner(provisionerBaseID+params.name, func(ctx *pulumi.Context, env *environments.Kubernetes) error {
// We ALWAYS need to make a deep copy of `params`, as the provisioner can be called multiple times.
// and it's easy to forget about it, leading to hard to debug issues.
params := newProvisionerParams()
_ = optional.ApplyOptions(params, opts)

return KindRunFunc(ctx, env, params)
}, params.extraConfigParams)

return provisioner
}

// KindRunFunc is the Pulumi run function that runs the provisioner
func KindRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *ProvisionerParams) error {

localEnv, err := local.NewEnvironment(ctx)
if err != nil {
return err
}

kindCluster, err := kubeComp.NewLocalKindCluster(&localEnv, localEnv.CommonNamer().ResourceName("kind"), params.name, localEnv.KubernetesVersion())
if err != nil {
return err
}

err = kindCluster.Export(ctx, &env.KubernetesCluster.ClusterOutput)
if err != nil {
return err
}

kubeProvider, err := kubernetes.NewProvider(ctx, localEnv.CommonNamer().ResourceName("k8s-provider"), &kubernetes.ProviderArgs{
EnableServerSideApply: pulumi.Bool(true),
Kubeconfig: kindCluster.KubeConfig,
})
if err != nil {
return err
}

if params.fakeintakeOptions != nil {
fakeintakeOpts := []fakeintake.Option{fakeintake.WithLoadBalancer()}
params.fakeintakeOptions = append(fakeintakeOpts, params.fakeintakeOptions...)
fakeIntake, err := fakeintakeComp.NewLocalDockerFakeintake(&localEnv, "fakeintake")
if err != nil {
return err
}
err = fakeIntake.Export(ctx, &env.FakeIntake.FakeintakeOutput)
if err != nil {
return err
}

if params.agentOptions != nil {
newOpts := []kubernetesagentparams.Option{kubernetesagentparams.WithFakeintake(fakeIntake)}
params.agentOptions = append(newOpts, params.agentOptions...)
}
} else {
env.FakeIntake = nil
}

if params.agentOptions != nil {
kindClusterName := ctx.Stack()
helmValues := fmt.Sprintf(`
datadog:
kubelet:
tlsVerify: false
clusterName: "%s"
agents:
useHostNetwork: true
`, kindClusterName)

newOpts := []kubernetesagentparams.Option{kubernetesagentparams.WithHelmValues(helmValues)}
params.agentOptions = append(newOpts, params.agentOptions...)
agent, err := agent.NewKubernetesAgent(&localEnv, kindClusterName, kubeProvider, params.agentOptions...)
if err != nil {
return err
}
err = agent.Export(ctx, &env.Agent.KubernetesAgentOutput)
if err != nil {
return err
}
} else {
env.Agent = nil
}

return nil
}
Loading