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

add flag to allow overwriting of probes #74

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions probe_builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,16 @@ def cli(debug):
@click.option('-j', '--jobs', type=click.INT, default=len(os.sched_getaffinity(0)))
@click.option('-k', '--kernel-type', type=click.Choice(sorted(CLI_DISTROS.keys())))
@click.option('-f', '--filter', default='')
@click.option('-o', '--overwrite', is_flag=True)
@click.option('-p', '--probe-name')
@click.option('-r', '--retries', type=click.INT, default=1)
@click.option('-s', '--source-dir')
@click.option('-t', '--download-timeout', type=click.FLOAT)
@click.option('-v', '--probe-version')
@click.argument('package', nargs=-1)
def build(builder_image_prefix,
download_concurrency, jobs, kernel_type, filter, probe_name, retries,
download_concurrency, jobs, kernel_type, filter, overwrite,
probe_name, retries,
source_dir, download_timeout, probe_version, package):
workspace_dir = os.getcwd()
builder_source = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand All @@ -135,7 +137,7 @@ def build(builder_image_prefix,
with ThreadPoolExecutor(max_workers=jobs) as executor:
kernels_futures = []
for release, target in kernel_dirs:
future = executor.submit(distro_builder.build_kernel, workspace, probe, distro.builder_distro, release, target)
future = executor.submit(distro_builder.build_kernel, workspace, probe, distro.builder_distro, release, target, overwrite)
kernels_futures.append((release, future))


Expand Down
4 changes: 2 additions & 2 deletions probe_builder/builder/builder_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def probe_built(probe, output_dir, kernel_release, config_hash, bpf):
probe_file_name = probe_output_file(probe, kernel_release, config_hash, bpf)
return os.path.exists(os.path.join(output_dir, probe_file_name))

def skip_build(probe, output_dir, kernel_release, config_hash, bpf):
if probe_built(probe, output_dir, kernel_release, config_hash, bpf):
def skip_build(probe, output_dir, kernel_release, config_hash, bpf, overwrite=False):
if not overwrite and probe_built(probe, output_dir, kernel_release, config_hash, bpf):
return "Already built"

if (kernel_release, config_hash) in SKIPPED_KERNELS:
Expand Down
14 changes: 7 additions & 7 deletions probe_builder/builder/distro/base_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_kernel_dir(self, workspace, release, target):

@classmethod
def build_kernel_impl(cls, config_hash, container_name, image_name, kernel_dir, probe, release, workspace, bpf,
skip_reason):
skip_reason, overwrite=False):
if bpf:
label = 'eBPF'
args = ['bpf']
Expand All @@ -81,7 +81,7 @@ def build_kernel_impl(cls, config_hash, container_name, image_name, kernel_dir,
args = []

output_dir = workspace.subdir('output')
if builder_image.probe_built(probe, output_dir, release, config_hash, bpf):
if not overwrite and builder_image.probe_built(probe, output_dir, release, config_hash, bpf):
return cls.ProbeBuildResult(cls.ProbeBuildResult.BUILD_EXISTING, 0)

if skip_reason:
Expand All @@ -107,12 +107,12 @@ def build_kernel_impl(cls, config_hash, container_name, image_name, kernel_dir,
logger.warn(make_string(line))
return cls.ProbeBuildResult(cls.ProbeBuildResult.BUILD_FAILED, took, stdout)

def build_kernel(self, workspace, probe, builder_distro, release, target):
def build_kernel(self, workspace, probe, builder_distro, release, target, overwrite=False):
config_hash = self.hash_config(release, target)
output_dir = workspace.subdir('output')

kmod_skip_reason = builder_image.skip_build(probe, output_dir, release, config_hash, False)
ebpf_skip_reason = builder_image.skip_build(probe, output_dir, release, config_hash, True)
kmod_skip_reason = builder_image.skip_build(probe, output_dir, release, config_hash, False, overwrite)
ebpf_skip_reason = builder_image.skip_build(probe, output_dir, release, config_hash, True, overwrite)
try:
os.makedirs(output_dir, 0o755)
except OSError as exc:
Expand All @@ -139,9 +139,9 @@ def build_kernel(self, workspace, probe, builder_distro, release, target):

return self.KernelBuildResult(
self.build_kernel_impl(config_hash, container_name, image_name, kernel_dir, probe, release, workspace, False,
kmod_skip_reason),
kmod_skip_reason, overwrite),
self.build_kernel_impl(config_hash, container_name, image_name, kernel_dir, probe, release, workspace, True,
ebpf_skip_reason),
ebpf_skip_reason, overwrite),
)

def batch_packages(self, kernel_files):
Expand Down
2 changes: 1 addition & 1 deletion probe_builder/builder/distro/flatcar.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def batch_packages(self, kernel_files):

@classmethod
def build_kernel_impl(cls, config_hash, container_name, image_name, kernel_dir, probe, release, workspace, bpf,
skip_reason):
skip_reason, overwrite=False):
if bpf:
label = 'eBPF'
args = ['bpf']
Expand Down