Skip to content

Commit

Permalink
use terratest
Browse files Browse the repository at this point in the history
  • Loading branch information
fanny-jiang committed Mar 28, 2024
1 parent 2e3bc32 commit 1a6018a
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 1,038 deletions.
3 changes: 0 additions & 3 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ spec:
args:
- --enable-leader-election
- --pprof
- --webhookEnabled
image: controller:latest
imagePullPolicy: IfNotPresent
name: manager
Expand Down Expand Up @@ -58,7 +57,5 @@ spec:
path: /healthz/
port: 8081
periodSeconds: 10
imagePullSecrets:
- name: registry-credentials
terminationGracePeriodSeconds: 10
serviceAccountName: controller-manager
99 changes: 99 additions & 0 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// 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 e2e

import (
"os"
"path/filepath"
"testing"
"time"

"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
manifestsPath = "./manifests"
mgrKustomizeDirPath = "../../config/default"
imagePullSecretName = "registry-credentials"
)

var (
k8sVersion = getEnv("K8S_VERSION", "1.26")
imageTag = getEnv("TARGET_IMAGE", "gcr.io/datadoghq/operator:latest")
imgPullPassword = getEnv("IMAGE_PULL_PASSWORD", "")
tmpDir string
kubeConfigPath string
kubectlOptions *k8s.KubectlOptions

ddaMinimalPath = filepath.Join(manifestsPath, "datadog-agent-minimum.yaml")

namespaceName = "system"
)

// getAbsPath Return absolute path for given path
func getAbsPath(path string) (string, error) {
absPath, err := filepath.Abs(path)
if err != nil {
return "", err
}
_, err = os.Stat(absPath)
if err != nil {
return "", err
}
if os.IsNotExist(err) {
return "", err
}

return absPath, nil
}

func operatorTransformationFunc() func(state map[string]interface{}, opts ...pulumi.ResourceOption) {
return func(state map[string]interface{}, opts ...pulumi.ResourceOption) {
name := state["metadata"].(map[string]interface{})["name"]

if imageTag != "" && state["kind"] == "Deployment" && name == "datadog-operator-manager" {
template := state["spec"].(map[string]interface{})["template"]
templateSpec := template.(map[string]interface{})["spec"]
templateSpec.(map[string]interface{})["imagePullSecrets"] = []map[string]interface{}{{"name": imagePullSecretName}}
containers := templateSpec.(map[string]interface{})["containers"]
container := containers.([]interface{})[0]
container.(map[string]interface{})["image"] = imageTag

}
}
}

func contextConfig(kubeConfig string) (cleanupFunc func(), err error) {
tmpDir = "/tmp"
kubeConfigPath = filepath.Join(tmpDir, ".kubeconfig")

kcFile, err := os.Create(kubeConfigPath)
if err != nil {
return nil, err
}
defer kcFile.Close()

_, err = kcFile.WriteString(kubeConfig)
return func() {
_ = os.Remove(kubeConfigPath)
}, nil
}

func verifyNumPodsForSelector(t *testing.T, kubectlOptions *k8s.KubectlOptions, numPods int, selector string) {
t.Log("Waiting for number of pods created", "number", numPods, "selector", selector)
k8s.WaitUntilNumPodsCreated(t, kubectlOptions, v1.ListOptions{
LabelSelector: selector,
}, numPods, 9, 15*time.Second)
}

func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}
104 changes: 0 additions & 104 deletions test/e2e/const.go

This file was deleted.

47 changes: 24 additions & 23 deletions test/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ module github.com/DataDog/datadog-operator/e2e
go 1.21.6

require (
github.com/DataDog/datadog-agent/test/new-e2e v0.51.1
github.com/DataDog/datadog-operator v1.4.0
github.com/DataDog/test-infra-definitions v0.0.0-20240306160032-a1d921006e35
github.com/DataDog/datadog-agent/test/new-e2e v0.52.0
github.com/DataDog/test-infra-definitions v0.0.0-20240322160927-3eac4b5bb0c4
github.com/google/go-cmp v0.6.0
github.com/gruntwork-io/terratest v0.46.13
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.9.0
github.com/pulumi/pulumi/sdk/v3 v3.108.1
k8s.io/api v0.28.3
k8s.io/apimachinery v0.28.3
k8s.io/api v0.28.4
k8s.io/apimachinery v0.28.4
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/DataDog/agent-payload/v5 v5.0.100 // indirect
github.com/DataDog/datadog-agent/test/fakeintake v0.51.1 // indirect
github.com/DataDog/agent-payload/v5 v5.0.103-0.20240118142331-3069f58aa284 // indirect
github.com/DataDog/datadog-agent/pkg/proto v0.52.0 // indirect
github.com/DataDog/datadog-agent/test/fakeintake v0.52.0 // indirect
github.com/DataDog/datadog-api-client-go/v2 v2.19.0 // indirect
github.com/DataDog/extendeddaemonset v0.9.0-rc.2 // indirect
github.com/DataDog/mmh3 v0.0.0-20200805151601-30884ca2197a // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/DataDog/zstd_0 v0.0.0-20210310093942-586c1286621f // indirect
Expand All @@ -29,6 +30,7 @@ require (
github.com/alessio/shellescape v1.4.2 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aws/aws-sdk-go v1.44.298 // indirect
github.com/aws/aws-sdk-go-v2 v1.25.2 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.6 // indirect
Expand All @@ -50,41 +52,42 @@ require (
github.com/aws/aws-sdk-go-v2/service/sts v1.28.3 // indirect
github.com/aws/smithy-go v1.20.1 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/charmbracelet/bubbles v0.18.0 // indirect
github.com/charmbracelet/bubbletea v0.25.0 // indirect
github.com/charmbracelet/lipgloss v0.10.0 // indirect
github.com/cheggaaa/pb v1.0.29 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/containerd/console v1.0.4 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/djherbis/times v1.6.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.11.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-sql-driver/mysql v1.4.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
github.com/gruntwork-io/go-commons v0.8.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl/v2 v2.20.0 // indirect
Expand All @@ -101,9 +104,11 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
Expand All @@ -115,15 +120,13 @@ require (
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pgavlin/fx v0.1.6 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/sftp v1.13.6 // indirect
github.com/pkg/term v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/pquerna/otp v1.2.0 // indirect
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect
github.com/pulumi/esc v0.8.2 // indirect
github.com/pulumi/pulumi-aws/sdk/v6 v6.25.0 // indirect
Expand All @@ -135,6 +138,7 @@ require (
github.com/pulumi/pulumi-tls/sdk/v4 v4.11.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
github.com/samber/lo v1.39.0 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
Expand All @@ -145,9 +149,11 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.5-0.20231013065317-89920137cdfa // indirect
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
github.com/tinylib/msgp v1.1.8 // indirect
github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/urfave/cli v1.22.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/zclconf/go-cty v1.14.3 // indirect
go.uber.org/atomic v1.11.0 // indirect
Expand All @@ -162,7 +168,6 @@ require (
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.19.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240304212257-790db918fca8 // indirect
google.golang.org/grpc v1.62.1 // indirect
Expand All @@ -172,15 +177,11 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.23.5 // indirect
k8s.io/client-go v0.28.3 // indirect
k8s.io/component-base v0.28.3 // indirect
k8s.io/client-go v0.28.4 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-aggregator v0.23.5 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
lukechampine.com/frand v1.4.2 // indirect
sigs.k8s.io/controller-runtime v0.11.2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
Loading

0 comments on commit 1a6018a

Please sign in to comment.