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

dev: add Tiltfile for local development #382

Merged
merged 1 commit into from
Oct 17, 2024
Merged
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
63 changes: 63 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- mode: Python -*-

# Extensions
load('ext://helm_resource', 'helm_resource', 'helm_repo')

# Specifies that Tilt is allowed to run against the specified k8s context name.
allow_k8s_contexts('kubernetes-admin@kubernetes')
# Anonymous, ephemeral image registry.
default_registry('ttl.sh')

# Run a defined set of services via config.set_enabled_resources.
config.define_string_list("to-run", args=True)
cfg = config.parse()
groups = {
'balloons': ['binary-build-logs', 'controller-logs'],
'topology-aware': ['binary-build-logs', 'controller-logs'],
}

resources = []
for resource_name in cfg.get('to-run', []):
if resource_name in groups:
resources += groups[resource_name]
config.set_enabled_resources(resources)

# Fail if the policy name is not provided.
if len(resources) == 0:
fail("🚨 ERROR: No policy passed! Please run: tilt up <POLICY_NAME>")

POLICY = resource_name
IMAGE_BASE = "ttl.sh/ghcr.io/containers/nri-plugins/nri-resource-policy-"
IMAGE = IMAGE_BASE + POLICY
COMPILE_CMD = ('make BINARIES= OTHER_IMAGE_TARGETS= PLUGINS=nri-resource-policy-' + POLICY + ' build-plugins')
DEPS = ['./pkg', './cmd', './deployment']

###################################
# The main tasks are executed here.
###################################

# Builds a binary.
local_resource(
'binary-build-logs',
COMPILE_CMD,
deps=DEPS
)

# Builds a container image.
docker_build(
IMAGE,
'.',
dockerfile='./cmd/plugins/' + POLICY + '/Dockerfile'
fmuyassarov marked this conversation as resolved.
Show resolved Hide resolved
)

# Deploy the policy Helm chart.
helm_resource(
'controller-logs',
'./deployment/helm/' + POLICY,
namespace='kube-system',
deps=DEPS,
image_deps=[IMAGE],
image_keys=[('image.registry', 'image.repository', 'image.tag')],
flags=['--set=image.name=' + IMAGE],
resource_deps=['binary-build-logs']
)