Skip to content

pkg_rpm: add rpm_own_tree_dirs attribute to own directories in TreeArtifacts - #1089

Open
chouquette wants to merge 1 commit into
bazelbuild:mainfrom
chouquette:chouquette/pkg-rpm-tree-dirs
Open

chouquette wants to merge 1 commit into
bazelbuild:mainfrom
chouquette:chouquette/pkg-rpm-tree-dirs

Conversation

@chouquette

Copy link
Copy Markdown
Contributor

When a TreeArtifact is packaged with pkg_rpm, its files are added to the %files list but its directories are not. The package doesn't own them, so they are left behind on uninstall.

Owning those directories unconditionally isn't safe, since a TreeArtifact may be installed into a directory shared with other packages (e.g. /usr/lib). Owning such a directory would let the package override its mode and ownership.

This PR adds an opt-in rpm_own_tree_dirs attribute, set through pkg_attributes on the mapping rule. When it's set, pkg_rpm also adds a %dir entry for the TreeArtifact destination and every directory below it. The default behavior is unchanged.

@cgrindel cgrindel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I will leave open so that @aiuto can review as well.

gh-worker-dd-mergequeue-cf854d Bot pushed a commit to DataDog/datadog-agent that referenced this pull request Oct 22, 2026
…8466)

<!--Please give us some feedback on your experience writing this PR ! https://app.datadoghq.com/forms/43db4c02-6837-400c-8083-692e141b1b88 !-->

### What does this PR do?

Fix a gap in the RPM packages that was leaving some directories as not owned by our bazel generated packages.
There are 2 paths that we need to cover.
* All directories that are automatically collected through `dd_cc_packaged` and installed in `//:install_dir` should be owned by our RPM package.
This is implemented by a new rule, `dd_pkg_owned_dirs`, which is called from a new wrapper around `pkg_rpm`: `dd_pkg_rpm`.
* Tree artifacts collected by `package_license` are marked as owned. This is done by:
    * A patch to rules_pkg (sent upstream as bazelbuild/rules_pkg#1089, which we use directly from this PR for now)
    * A small modification to the rule invocation on our side so that the attribute is passed for anything related to the collected licenses.

Debian doesn't have the same concept of directory ownership, so debian packages aren't touched by this PR.

### Motivation

Since these folders are not owned, they aren't removed on uninstall, which causes some E2E tests to fail:
```
Messages:   	should not find anything in install folder, found 14 dir entries.
        	            	Content: /opt/datadog-agent/, /opt/datadog-agent/LICENSES, /opt/datadog-agent/bin, /opt/datadog-agent/bin/agent, /opt/datadog-agent/bin/agent/dist, /opt/datadog-agent/bin/agent/dist/views, /opt/datadog-agent/bin/agent/dist/views/css, /opt/datadog-agent/bin/agent/dist/views/fonts, /opt/datadog-agent/bin/agent/dist/views/images, /opt/datadog-agent/bin/agent/dist/views/js, /opt/datadog-agent/embedded, /opt/datadog-agent/sources, /opt/datadog-agent/sources/systemd
```

With these changes, the directories are correctly owned and therefore removed upon uninstall.

### Describe how you validated your changes

Tested in the WIP PR to create the iot-agent packages with bazel, the E2E install tests now pass: https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/2155467243

### Additional Notes


Co-authored-by: hugo.beauzee <hugo.beauzee@datadoghq.com>
@aiuto

aiuto commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

The rpm_own_tree_dirs=True behavior is obviously the correct behavior. But it would have consequences for people
depending on the old behavior, so it should be a breaking change.

Since the next release has to be version 2.x anyway, why don't we make the default behavior the True case.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants