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

Clamoriniere/add skaffold kind support #33585

Draft
wants to merge 2 commits into
base: HAD-11/wassim.dhif/improve-agent-build
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
/.run @DataDog/agent-devx-loops
/.run/docker/ @DataDog/container-integrations @DataDog/container-platform

/skaffold.yaml @DataDog/agent-devx-infra @DataDog/agent-devx-loops @DataDog/container-platform
/.run/skaffold/ @DataDog/agent-devx-infra @DataDog/agent-devx-loops @DataDog/container-platform

# Gitlab files
# Files containing job contents are owned by teams in charge of the jobs + agent-devx-infra or agent-delivery
# Files that only describe structure (eg. includes, rules) are owned by agent-devx-infra
Expand Down Expand Up @@ -563,6 +566,8 @@
/tasks/update_go.py @DataDog/agent-shared-components
/tasks/unit_tests/update_go_tests.py @DataDog/agent-shared-components
/tasks/cluster_agent_cloudfoundry.py @DataDog/platform-integrations
/tasks/devcontainer.py @DataDog/agent-devx-infra @DataDog/agent-devx-loops @DataDog/container-platform
/tasks/skaffold.py @DataDog/agent-devx-infra @DataDog/agent-devx-loops @DataDog/container-platform
/tasks/new_e2e_tests.py @DataDog/agent-e2e-testing @DataDog/agent-devx-loops
/tasks/process_agent.py @DataDog/container-intake
/tasks/system_probe.py @DataDog/ebpf-platform
Expand Down
33 changes: 33 additions & 0 deletions .run/skaffold/Build and deploy using Skaffold.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Build and deploy using Skaffold" type="google-container-tools-skaffold-run-config" factoryName="google-container-tools-skaffold-run-config-dev" show_console_on_std_err="false" show_console_on_std_out="false">
<option name="allowRunningInParallel" value="false" />
<option name="buildEnvironment" value="Local" />
<option name="cleanupDeployments" value="true" />
<option name="deployToCurrentContext" value="false" />
<option name="deployToMinikube" value="true" />
<option name="envVariables" />
<option name="imageRepositoryOverride" />
<option name="kubernetesContext" />
<option name="mappings">
<list />
</option>
<option name="moduleDeploymentType" value="DEPLOY_EVERYTHING" />
<option name="projectPathOnTarget" />
<option name="resourceDeletionTimeoutMins" value="2" />
<option name="selectedOptions">
<list />
</option>
<option name="skaffoldConfigurationFilePath" value="$PROJECT_DIR$/skaffold.yaml" />
<option name="skaffoldModules">
<list>
<option value="datadog-agent" />
</list>
</option>
<option name="skaffoldNamespace" />
<option name="skaffoldProfile" />
<option name="skaffoldWatchMode" value="ON_DEMAND" />
<option name="statusCheck" value="true" />
<option name="verbosity" value="WARN" />
<method v="2" />
</configuration>
</component>
9 changes: 9 additions & 0 deletions .vscode/launch.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,14 @@
}
]
},
{
"name": "Build and deploy using Skaffold",
"type": "cloudcode.kubernetes",
"request": "launch",
"skaffoldConfig": "${workspaceFolder}/skaffold.yaml",
"watch": false,
"cleanUp": true,
"portForward": true
}
]
}
65 changes: 65 additions & 0 deletions skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apiVersion: skaffold/v4beta11
kind: Config
metadata:
name: datadog-agent
build:
platforms: [ "linux/arm64" ]
tagPolicy:
gitCommit: {
variant: "AbbrevCommitSha"
}
local:
push: false
concurrency: 0
deploy:
helm:
releases:
- name: datadog-agent
remoteChart: datadog/datadog
version: 3.88.1
setValueTemplates:
datadog:
apiKey: "{{cmd \"bash\" \"-c\" \"echo $DD_API_KEY\"}}"
appKey: "{{cmd \"bash\" \"-c\" \"echo $DD_APP_KEY\"}}"
kubelet:
tlsVerify: false
agents.image:
repository: "{{.IMAGE_REPO_agent}}"
tag: "{{.IMAGE_TAG_agent}}@{{.IMAGE_DIGEST_agent}}"
doNotCheckTag: true
clusterAgent:
image:
repository: "{{.IMAGE_REPO_clusteragent}}"
tag: "{{.IMAGE_TAG_clusteragent}}"
doNotCheckTag: true
clusterCheckRunner.image:
repository: "{{.IMAGE_REPO_agent}}"
tag: "{{.IMAGE_TAG_agent}}"
doNotCheckTag: true
profiles:
- name: kind
activation:
- kubeContext: kind
command: dev
build:
artifacts:
- image: agent
custom:
buildCommand: "inv agent.hacky-dev-image-build --target-image=$IMAGE"
- image: clusteragent
custom:
buildCommand: "inv cluster-agent.hacky-dev-image-build --target-image=$IMAGE"
- name: minikube
activation:
- kubeContext: minikube
command: dev
build:
artifacts:
- image: agent
custom:
buildCommand: "docker exec datadog_agent_devcontainer bash -c \"
inv agent.hacky-dev-image-build --target-image=$IMAGE\""
- image: clusteragent
custom:
buildCommand: "docker exec datadog_agent_devcontainer bash -c \"
inv cluster-agent.hacky-dev-image-build --target-image=$IMAGE\""
2 changes: 2 additions & 0 deletions tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
security_agent,
selinux,
setup,
skaffold,
system_probe,
systray,
testwasher,
Expand Down Expand Up @@ -210,6 +211,7 @@
ns.add_collection(modules)
ns.add_collection(pre_commit)
ns.add_collection(devcontainer)
ns.add_collection(skaffold)
ns.add_collection(omnibus)
ns.add_collection(collector)
ns.add_collection(invoke_unit_tests)
Expand Down
79 changes: 69 additions & 10 deletions tasks/devcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from collections import OrderedDict
from functools import wraps
from pathlib import Path
from enum import Enum

from invoke import task
from invoke.exceptions import Exit
Expand All @@ -17,19 +18,26 @@
from tasks.commands.docker import AGENT_REPOSITORY_PATH, DockerCLI
from tasks.flavor import AgentFlavor
from tasks.libs.common.color import Color, color_message
from tasks.libs.common.utils import is_installed

DEVCONTAINER_DIR = ".devcontainer"
DEVCONTAINER_FILE = "devcontainer.json"
DEVCONTAINER_NAME = "datadog_agent_devcontainer"
DEVCONTAINER_IMAGE = "486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/datadog-agent-devenv:1-arm64"
DEVCONTAINER_IMAGE = "registry.ddbuild.io/ci/datadog-agent-devenv:1-arm64"


class Skaffold_profile(Enum):
NONE = None
KIND = "kind"
MINIKUBE = "minikube"

@task
def setup(
_,
target="agent",
build_include=None,
build_exclude=None,
skaffold_profile=None,
flavor=AgentFlavor.base.name,
image='',
):
Expand All @@ -49,6 +57,7 @@ def setup(
)
build_exclude = [] if build_exclude is None else build_exclude.split(",")
use_tags = get_build_tags(build_include, build_exclude)
use_tags.append("test") # always include the test tag for autocompletion in vscode

if not os.path.exists(DEVCONTAINER_DIR):
os.makedirs(DEVCONTAINER_DIR)
Expand Down Expand Up @@ -82,6 +91,7 @@ def setup(
"--name",
"datadog_agent_devcontainer",
]
devcontainer["features"] = {}
devcontainer["remoteUser"] = "datadog"
devcontainer["mounts"] = ["source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind,consistency=cached"]
devcontainer["customizations"] = {
Expand All @@ -104,17 +114,71 @@ def setup(
},
"gopls": {"formatting.local": "github.com/DataDog/datadog-agent"},
},
"extensions": ["golang.Go"],
"extensions": ["golang.Go","ms-python.python","redhat.vscode-yaml"],
}
}
devcontainer["postStartCommand"] = (

# onCreateCommond runs the install-tools and deps tasks only when the devcontainer is created and not each time
# the container is started
devcontainer["onCreateCommand"] = (
f"git config --global --add safe.directory {AGENT_REPOSITORY_PATH} && invoke -e install-tools && invoke -e deps"
)

devcontainer["remoteEnv"] = {"GITLAB_TOKEN": "${localEnv:GITLAB_TOKEN}"}
devcontainer["containerEnv"] = {
"GITLAB_TOKEN": "${localEnv:GITLAB_TOKEN}",
}

configure_skaffold(devcontainer, Skaffold_profile(skaffold_profile))

with open(fullpath, "w") as sf:
json.dump(devcontainer, sf, indent=4, sort_keys=False, separators=(',', ': '))

def configure_skaffold(devcontainer: dict, profile: Skaffold_profile):
if profile == Skaffold_profile.KIND:
devcontainer["runArgs"].append("--network=host") # to connect to the kind api-server
# add requires extensions
additional_extensions = ["GoogleCloudTools.cloudcode"]
devcontainer["customizations"]["vscode"]["extensions"].extend(additional_extensions)

# Additionnal features
additional_features = {
"ghcr.io/rio/features/skaffold:2": {},
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {},
"ghcr.io/devcontainers-extra/features/kind:1": {},
"ghcr.io/dhoeric/features/google-cloud-cli:1": {},
}
devcontainer["features"].update(additional_features)

# Addionnal settings
additional_settings = {
"cloudcode.features.completion": False,
"cloudcode.ai.assistance.enabled": False,
"cloudcode.cloudsdk.checkForMissing": False,
"cloudcode.cloudsdk.autoInstall": False,
"cloudcode.autoDependencies": "off",
"cloudcode.enableGkeAutopilotSupport": False,
"cloudcode.enableMinikubeGcpAuthPlugin": False,
"cloudcode.enableTelemetry": False,
"cloudcode.updateAdcOnLogin": False,
"cloudcode.useGcloudAuthSkaffold": False,
"cloudcode.yaml.validate": False,
}
devcontainer["customizations"]["vscode"]["settings"].update(additional_settings)

# add envvars to deploy the agent
additional_envvars = {
"DD_API_KEY": "${localEnv:DD_API_KEY}",
"DD_APP_KEY": "${localEnv:DD_APP_KEY}",
}
devcontainer["containerEnv"].update(additional_envvars)

# add Datadog helm chart registry to the devcontainer
devcontainer["onCreateCommand"] += " && helm repo add datadog https://helm.datadoghq.com && helm repo update"

elif profile == Skaffold_profile.MINIKUBE:
# TODO: add minikube specific settings
pass


@task
def start(ctx, path="."):
Expand All @@ -125,7 +189,7 @@ def start(ctx, path="."):
print(color_message("No devcontainer settings found. Run `invoke devcontainer.setup` first.", Color.RED))
raise Exit(code=1)

if not is_installed(ctx):
if not is_installed(ctx, "devcontainer"):
print(
color_message("Devcontainer CLI is not installed. Run `invoke install-devcontainer-cli` first.", Color.RED)
)
Expand Down Expand Up @@ -171,11 +235,6 @@ def is_up(ctx) -> bool:
return DEVCONTAINER_NAME in res.stdout


def is_installed(ctx) -> bool:
res = ctx.run("which devcontainer", hide=True, warn=True)
return res.ok


def run_on_devcontainer(func):
"""
This decorator will run the decorated function in a devcontainer if the selected platform is linux.
Expand Down
5 changes: 5 additions & 0 deletions tasks/libs/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,8 @@ def is_linux():

def is_windows():
return sys.platform == 'win32'


def is_installed(ctx, binary) -> bool:
res = ctx.run(f"which {binary}", hide=True, warn=True)
return res.ok
Loading
Loading