-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new kind provisioners (aws and local) and update generic k8s e2e …
…tests
- Loading branch information
1 parent
45bff5e
commit 0c3c3a0
Showing
15 changed files
with
1,194 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
namePrefix: datadog-operator-e2e- | ||
namespace: e2e-operator | ||
resources: | ||
- ../crd | ||
- ../rbac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: e2elocal | ||
runtime: go | ||
description: Generic scenario (check scenario variable) | ||
config: | ||
pulumi:disable-default-providers: ["*"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// 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 common | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"runtime" | ||
) | ||
|
||
var ( | ||
NamespaceName = "e2e-operator" | ||
K8sVersion = GetEnv("K8S_VERSION", "1.26") | ||
ImgPullPassword = GetEnv("IMAGE_PULL_PASSWORD", "") | ||
OperatorImageName = GetEnv("IMG", "") | ||
|
||
DdaMinimalPath = filepath.Join(ManifestsPath, "datadog-agent-minimum.yaml") | ||
ManifestsPath = filepath.Join(ProjectRootPath, "test/e2e/manifests/new_manifests") | ||
|
||
timeout int64 = 60 | ||
ProjectRootPath = projectRoot() | ||
) | ||
|
||
const ( | ||
NodeAgentSelector = "agent.datadoghq.com/component=agent" | ||
ClusterAgentSelector = "agent.datadoghq.com/component=cluster-agent" | ||
ClusterCheckRunnerSelector = "agent.datadoghq.com/component=cluster-checks-runner" | ||
) | ||
|
||
// 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 GetEnv(key, fallback string) string { | ||
if value, ok := os.LookupEnv(key); ok { | ||
return value | ||
} | ||
return fallback | ||
} | ||
|
||
func ParseCollectorJson(collectorOutput string) map[string]interface{} { | ||
var jsonString string | ||
var jsonObject map[string]interface{} | ||
|
||
re := regexp.MustCompile(`(\{.*\})`) | ||
match := re.FindStringSubmatch(collectorOutput) | ||
if len(match) > 0 { | ||
jsonString = match[0] | ||
} else { | ||
return map[string]interface{}{} | ||
} | ||
|
||
// Parse collector JSON | ||
err := json.Unmarshal([]byte(jsonString), &jsonObject) | ||
if err != nil { | ||
return map[string]interface{}{} | ||
} | ||
return jsonObject | ||
} | ||
|
||
func projectRoot() string { | ||
_, b, _, ok := runtime.Caller(0) | ||
if ok { | ||
return filepath.Join(filepath.Dir(b), "../../..") | ||
} | ||
return "" | ||
} |
35 changes: 35 additions & 0 deletions
35
test/e2e/manifests/new_manifests/autodiscovery-annotation.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx-deployment | ||
labels: | ||
app: nginx | ||
namespace: e2e-operator | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: nginx | ||
e2e: autodiscovery | ||
template: | ||
metadata: | ||
annotations: | ||
ad.datadoghq.com/nginx.check_names: '["http_check"]' | ||
ad.datadoghq.com/nginx.init_configs: '[{}]' | ||
ad.datadoghq.com/nginx.instances: | | ||
[ | ||
{ | ||
"name": "http_custom_identifier", | ||
"url": "http://www.google.com" | ||
} | ||
] | ||
ad.datadoghq.com/tolerate-unready: "true" | ||
labels: | ||
app: nginx | ||
e2e: autodiscovery | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx:1.14.2 | ||
ports: | ||
- containerPort: 80 |
19 changes: 19 additions & 0 deletions
19
test/e2e/manifests/new_manifests/datadog-agent-ccr-enabled.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: datadoghq.com/v2alpha1 | ||
kind: DatadogAgent | ||
metadata: | ||
name: datadog-ccr-enabled | ||
namespace: e2e-operator | ||
labels: | ||
agent.datadoghq.com/e2e-test: datadog-agent-ccr-enabled | ||
spec: | ||
global: | ||
kubelet: | ||
tlsVerify: false | ||
features: | ||
clusterChecks: | ||
enabled: true | ||
useClusterChecksRunners: true | ||
liveContainerCollection: | ||
enabled: true | ||
logCollection: | ||
enabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apiVersion: datadoghq.com/v2alpha1 | ||
kind: DatadogAgent | ||
metadata: | ||
name: datadog-agent-logs | ||
namespace: e2e-operator | ||
labels: | ||
agent.datadoghq.com/e2e-test: datadog-agent-logs | ||
spec: | ||
global: | ||
kubelet: | ||
tlsVerify: false | ||
features: | ||
clusterChecks: | ||
enabled: true | ||
useClusterChecksRunners: false | ||
logCollection: | ||
enabled: true | ||
containerCollectAll: true | ||
liveContainerCollection: | ||
enabled: true |
10 changes: 10 additions & 0 deletions
10
test/e2e/manifests/new_manifests/datadog-agent-minimum.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: datadoghq.com/v2alpha1 | ||
kind: DatadogAgent | ||
metadata: | ||
namespace: e2e-operator | ||
labels: | ||
agent.datadoghq.com/e2e-test: datadog-agent-minimum | ||
spec: | ||
global: | ||
kubelet: | ||
tlsVerify: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// 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 provisioners | ||
|
||
import ( | ||
"fmt" | ||
"github.com/DataDog/datadog-operator/pkg/plugin/common" | ||
e2ecommon "github.com/DataDog/datadog-operator/test/e2e/common" | ||
"os" | ||
"path/filepath" | ||
"sigs.k8s.io/kustomize/api/types" | ||
"sigs.k8s.io/kustomize/kyaml/resid" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
var ( | ||
NewMgrKustomizeDirPath = filepath.Join(e2ecommon.ProjectRootPath, "config", "new-e2e") | ||
) | ||
|
||
const ( | ||
DefaultMgrImageName = "gcr.io/datadoghq/operator" | ||
DefaultMgrImgTag = "latest" | ||
DefaultMgrFileName = "e2e-manager.yaml" | ||
UserData = `#!/bin/bash | ||
echo "User Data" | ||
echo "Installing kubectl" | ||
snap install kubectl --classic | ||
echo "Verifying kubectl" | ||
kubectl version --client | ||
echo "Installing kubens" | ||
curl -sLo kubens https://github.com/ahmetb/kubectx/releases/download/v0.9.5/kubens | ||
chmod +x kubens | ||
mv kubens /usr/local/bin/ | ||
echo ' | ||
alias k="kubectl" | ||
alias kg="kubectl get" | ||
alias kgp="kubectl get pod" | ||
alias krm="kubectl delete" | ||
alias krmp="kubectl delete pod" | ||
alias kd="kubectl describe" | ||
alias kdp="kubectl describe pod" | ||
alias ke="kubectl edit" | ||
alias kl="kubectl logs" | ||
alias kx="kubectl exec" | ||
' >> /home/ubuntu/.bashrc | ||
` | ||
) | ||
|
||
func loadKustomization(path string) (*types.Kustomization, error) { | ||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var kustomization types.Kustomization | ||
if err := yaml.Unmarshal(data, &kustomization); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &kustomization, nil | ||
} | ||
|
||
func saveKustomization(path string, kustomization *types.Kustomization) error { | ||
data, err := yaml.Marshal(kustomization) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := os.WriteFile(path, data, 0644); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// updateKustomization Updates kustomization.yaml file in given kustomize directory with extra resources and image name and tag if `IMG` environment variable is set. | ||
func UpdateKustomization(kustomizeDirPath string, kustomizeResourcePaths []string) error { | ||
var imgName, imgTag string | ||
|
||
kustomizationFilePath := fmt.Sprintf("%s/kustomization.yaml", kustomizeDirPath) | ||
k, err := loadKustomization(kustomizationFilePath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Update resources with target e2e-manager resource yaml | ||
if kustomizeResourcePaths != nil { | ||
// We empty slice to avoid accumulating patches from previous tests | ||
k.Patches = k.Patches[:0] | ||
for _, res := range kustomizeResourcePaths { | ||
k.Patches = append(k.Patches, types.Patch{ | ||
Path: res, | ||
Target: &types.Selector{ | ||
ResId: resid.NewResIdKindOnly("Deployment", "manager"), | ||
}, | ||
}) | ||
} | ||
} | ||
|
||
// Update image | ||
if os.Getenv("IMG") != "" { | ||
imgName, imgTag = common.SplitImageString(os.Getenv("IMG")) | ||
} else { | ||
imgName = DefaultMgrImageName | ||
imgTag = DefaultMgrImgTag | ||
} | ||
for i, img := range k.Images { | ||
if img.Name == "controller" { | ||
k.Images[i].NewName = imgName | ||
k.Images[i].NewTag = imgTag | ||
} | ||
} | ||
|
||
if err := saveKustomization(kustomizationFilePath, k); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.