Skip to content

CFE-4708: Added support for a path-augment to specify files to ship beyond the extension-matching - #3204

Open
SimonThalvorsen wants to merge 2 commits into
cfengine:masterfrom
SimonThalvorsen:CFE-4708
Open

CFE-4708: Added support for a path-augment to specify files to ship beyond the extension-matching#3204
SimonThalvorsen wants to merge 2 commits into
cfengine:masterfrom
SimonThalvorsen:CFE-4708

Conversation

@SimonThalvorsen

Copy link
Copy Markdown
Contributor

Ticket: CFE-4708
Changelog: Added input_paths_extra to allow specified files to ship independent of what is specified in input_name_patterns[_extra]

@cf-bottom

Copy link
Copy Markdown

Thank you for submitting a pull request! Maybe @nickanderson can review this?

@nickanderson nickanderson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No ticket in the commit subject, that's for the PR.

I am not sure about this.

I understand that you are adding a file path to the files distributed in update.

  • This is a fully qualified file path? Can you give an example of what values a user would be expected to use here?
  • You say these files would be updated each time, regardless of validated_updates_ready, so these files could update but the rest of the policy could be skipped?

Comment thread cfe_internal/update/update_policy.cf Outdated
Comment thread cfe_internal/update/update_policy.cf Outdated
Comment thread controls/update_def.cf.in Outdated
@SimonThalvorsen

SimonThalvorsen commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

No ticket in the commit subject, that's for the PR.

I am not sure about this.

I understand that you are adding a file path to the files distributed in update.

* This is a fully qualified file path? Can you give an example of what values a user would be expected to use here?

* You say these files would be updated each time, regardless of validated_updates_ready, so these files could update but the rest of the policy could be skipped?

I am not certain that the hashing in GeneratePolicyRelease() is what messes it up, but the issue
is that originally I just added a variable input_paths_extra to contain the extra filepaths that may exists outside of what is defined in input_name_patterns (since these gets copied from before). In the first iteration i just expandend the file_select u_input_files-body to use the path_name-parameter and then use it like this:

leaf_name => {
  @(update_def.input_name_patterns), @(update_def.input_name_patterns_extra)
};
path_name => { @(update_def.input_paths_extra) };
file_result => "leaf_name|path_name";

but that only worked for the initial copy, so if the project got rebuilt with the same files(but different content) only the .sh (and assumes .txt, .cf and other accepted extensions) would get marked as changed and the client got the new content, but keeping the old, unchanged version of the other files.

The usage is intended for files added by cfbs input-type-file, where the supplied files may not match what is set inside ìnput_name_patterns and adding the extension (or no extension at all) to input_name_patterns_extra may cause more files that what one would want to get shipped.

@nickanderson

Copy link
Copy Markdown
Member

No ticket in the commit subject, that's for the PR.
I am not sure about this.
I understand that you are adding a file path to the files distributed in update.

* This is a fully qualified file path? Can you give an example of what values a user would be expected to use here?

* You say these files would be updated each time, regardless of validated_updates_ready, so these files could update but the rest of the policy could be skipped?

I am not certain that the hashing in GeneratePolicyRelease() is what messes it up, but the issue is that originally I just added a variable input_paths_extra to contain the extra filepaths that may exists outside of what is defined in input_name_patterns (since these gets copied from before). In the first iteration i just expandend the file_select u_input_files-body to use the path_name-parameter and then use it like this:

leaf_name => {
  @(update_def.input_name_patterns), @(update_def.input_name_patterns_extra)
};
path_name => { @(update_def.input_paths_extra) };
file_result => "leaf_name|path_name";

but that only worked for the initial copy, so if the project got rebuilt with the same files(but different content) only the .sh (and assumes .txt, .cf and other accepted extensions) would get marked as changed and the client got the new content, but keeping the old, unchanged version of the other files.

The usage is intended for files added by cfbs input-type-file, where the supplied files may not match what is set inside ìnput_name_patterns and adding the extension (or no extension at all) to input_name_patterns_extra may cause more files that what one would want to get shipped.

I would remove git from the equation initially. Edit files in /var/cfengine/masterfiles on a hub and understand that basic flow first.
from memory ...
validated_updates_ready is defined when the client repaires it's copy of cf_promsies_validated. cf_promises_validated on the hubs /var/cfengine/masterfiles is updated when the hub sees that it's running and validates new policy in inputs. So, you change masterfiles, update.cf runs from inputs, promises.cf runs from inputs, which causes cf_promises_validated in /var/cfengine/masterfiles to be updated, then clients see that file changed, which lifts the gate for the client to scan all the rest of the files for change.

… extension-matching

Ticket: CFE-4708
Changelog: Added `input_paths_extra` to allow specified files to ship
independent of what is specified in `input_name_patterns[_extra]`

Signed-off-by: Simon Halvorsen <simon.halvorsen@northern.tech>
Comment thread cfe_internal/update/update_policy.cf Outdated
Comment on lines +296 to +300
# reopens on new hub-side changes, so a brand-new entry
# introduced in the same run that opens the gate isn't loaded
# into memory yet (it lands in def.json partway through that
# run?) and will be stuck until a second, unrelated
# run reopens the gate again.

@SimonThalvorsen SimonThalvorsen Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So this is still a work in progress, but the current issue is mainly this

Files that get added by the def.json only gets copied over on the 2nd run of update.cf, I assume this is the staleness as described in this comment, but not certain. If the file already exists, then update/update_policy fetches and copies without problems

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it should behave this way (copying the files each time).

If you move the class guard to if => directly on the promise, the promise will only be in the context of a validated policy update which also has these extra files enabled.

There are two separate flows ... one where masterfiles is from a git repo and when thats the case cf_promises_release_id is the git commit hash. When its not git backed that id is computed from a tree hash in core. That tree hash I think only coveres specific files but I think that is probably wrong and should probably consider all files, just like git would.

@nickanderson nickanderson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I will push a change to your pr here lmk how that works for you

Comment thread cfe_internal/update/update_policy.cf Outdated
slist => filter(
"^.*\.\..*$", "update_def.input_paths_extra", "true", "true", 999
),
comment => "input_paths_extra with any entries containing a '..'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

concat() line broken comment => values.

Comment thread cfe_internal/update/update_policy.cf Outdated
Comment on lines +296 to +300
# reopens on new hub-side changes, so a brand-new entry
# introduced in the same run that opens the gate isn't loaded
# into memory yet (it lands in def.json partway through that
# run?) and will be stuck until a second, unrelated
# run reopens the gate again.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it should behave this way (copying the files each time).

If you move the class guard to if => directly on the promise, the promise will only be in the context of a validated policy update which also has these extra files enabled.

There are two separate flows ... one where masterfiles is from a git repo and when thats the case cf_promises_release_id is the git commit hash. When its not git backed that id is computed from a tree hash in core. That tree hash I think only coveres specific files but I think that is probably wrong and should probably consider all files, just like git would.

Move the input_paths_extra copy promise under the existing
am_policy_hub|validated_updates_ready class guard instead of running
unconditionally. The validated_updates_ready gate opens whenever
cf_promises_validated is updated, which happens any time the hub
detects file changes in inputs (via IsNewerFileTree), regardless of
whether those files are in the release hash. This preserves the
atomic update model without requiring the bypass.

Also use concat() for multi-line comment attributes per review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants