What changes were made to the kubectl command behavior in <REDACTED> 1.26 regarding…
- User
What changes were made to the kubectl command behavior in 1.26 regarding pruning during apply operations?
Assistant
What changes were made to the kubectl command behavior in 1.26 regarding pruning during apply operations?
I'll help you understand the changes made to the kubectl command behavior in 1.26 regarding pruning during apply operations. Let me search for the specific information about this change. K k8s_get_documentation Based on the documentation I've searched, I'll explain the changes made to kubectl command behavior in 1.26 regarding pruning during apply operations. Changes to --prune flag in kubectl apply In 1.26, an important change was made to how pruning works with the kubectl apply command. This specifically affects how objects are deleted when using the --prune flag. The kubectl apply --prune operation was marked as an alpha feature in 1.26, with a warning that "backwards incompatible changes might be introduced in subsequent releases." Background on kubectl apply --prune The kubectl apply --prune command is used as an alternative to kubectl delete to identify objects to be deleted after their configuration files have been removed from a directory. When you use apply with --prune, it queries the API server for all objects matching a set of labels, and attempts to match the returned live object configurations against the object configuration files. If an object matches the query, and it does not have a configuration file in the directory, and it has a last-applied-configuration annotation, it is deleted. Warning About Usage The documentation specifically warns users to "be careful when using this command, so that you do not delete objects unintentionally." In 1.26, there's a specific warning that "apply with prune should only be run against the root directory containing the object configuration files. Running against sub-directories can cause objects to be unintentionally deleted if they are returned by the label selector query specified with -l and do not appear in the subdirectory." New Feature: retainKeys Strategy One significant enhancement in 1.26 is the addition of the retainKeys strategy for strategic merge patches, which can be useful in scenarios where you want to control field pruning during updates. The "retainKeys" strategy was introduced to allow removing values by specifying only the keys that should be retained during a patch operation. This method uses a directive retainKeys list The fields that are present will be merged with the live object All of the missing fields will be cleared when patching All fields in the $retainKeys list must be a superset or the same as the fields present in the patch This provides a more controlled way to remove fields during updates compared to the previous approach. Example of the retainKeys Strategy A practical example was demonstrated with a Deployment using the RollingUpdate strategy. When trying to change the deployment strategy to Recreate, a regular patch would fail because the rollingUpdate field would still exist and conflict with the new strategy type. Using the retainKeys strategy allows specifying that only the type key should be retained, causing the rollingUpdate to be removed during the patch operation. Changes to Pruning Terminology The documentation also shows that the terminology was updated from "whitelist" to "allowlist" with a new --prune-allowlist flag that replaces and functions the same as the deprecated --prune-whitelist flag. Summary The key changes to kubectl's pruning behavior in 1.26 include: The kubectl apply --prune operation is explicitly marked as alpha-level functionality with warnings about potential backwards incompatible changes in future releases Introduction of the retainKeys strategy for more controlled field pruning during updates Updated terminology from "whitelist" to "allowlist" for pruning flags Strong warnings about only running pruning operations against root directories to avoid unintentional object deletion These changes provide more control over pruning operations while also making it clearer that users should be cautious when using these features to avoid data loss.
Not yet included in a published release.