Skip to content

add PodProtections for DefaultEvictorArgs #1665

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

googs1025
Copy link
Member

fix: #1664

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign a7i for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 12, 2025
@googs1025 googs1025 marked this pull request as draft April 13, 2025 02:20
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 13, 2025
@@ -49,6 +49,9 @@ func SetDefaults_DefaultEvictorArgs(obj runtime.Object) {
if args.PriorityThreshold == nil {
args.PriorityThreshold = nil
}
if args.EvictionProtection == nil {
args.EvictionProtection = nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this function ?

Copy link
Member Author

Choose a reason for hiding this comment

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

oh... This is also where I am confused. I just added it in the same way as before...

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunate product of duplicating the no-op constructs.

@googs1025 googs1025 force-pushed the refator/evict_arg branch 3 times, most recently from fa6f9f0 to 93b0f88 Compare April 23, 2025 02:00
README.md Outdated
nodeFit: true
minReplicas: 2
# List of disabled default pod protections. This allows users to selectively disable certain protection rules.
Copy link
Member Author

Choose a reason for hiding this comment

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

We will recommend users to use the new config here

}

if args.MinReplicas == 1 {
klog.V(4).Info("DefaultEvictor minReplicas must be greater than 1 to check for min pods during eviction. This check will be ignored during eviction.")
}

// check if any deprecated fields are set to true
Copy link
Member Author

Choose a reason for hiding this comment

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

validate check here: We do not want users to mix old and new config. If any of the old config is true and there is a value in the new config list (including: DisabledDefaultPodProtections and ExtraPodProtections), it means that they are mixed and the validation fails.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 23, 2025
@googs1025 googs1025 marked this pull request as ready for review April 23, 2025 12:05
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 23, 2025
@googs1025 googs1025 marked this pull request as draft April 23, 2025 12:41
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 23, 2025
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 23, 2025
frameworktypes "sigs.k8s.io/descheduler/pkg/framework/types"
"sigs.k8s.io/descheduler/pkg/utils"
)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think add new file constraints.go to be more clear

@googs1025
Copy link
Member Author

I hope we can reach an agreement and merge it into the master before the next release. 😄
@ingvagabund @a7i @ricardomaraschini Can you help with this PR? I know this may take some time....


// DisabledDefaultPodProtections is a list that specifies which default Pod protection mechanisms are disabled.
// Users can selectively disable certain default protection rules via this field.
DisabledDefaultPodProtections []DisabledDefaultPodProtection `json:"disabledDefaultPodProtections,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

What about to put the list of disabled and extra enabled policies under a single field? E.g.

# Pod anti-eviction/protection policies.
# The list of policies enabled by default:
# - protect pods with local storage, extend disabled with 'podsWithLocalStorage' to disable the protection
# - protect daemon set pods, extend disabled with `daemonSetPods` to disable the protection
# - ...
protectionPolicies:
  # list of extra enabled policies
  extraEnabled:
  # list of disabled pod policies
  disabled:

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Here is a good suggestion
we can config like this:

- name: "DefaultEvictor"
  args:
    # Deprecated: Use `disabledDefaultPodProtections` with "systemCriticalPods" instead.
    # evictSystemCriticalPods: true
    # Deprecated: Use `disabledDefaultPodProtections` with "failedBarePods" instead.
    # evictFailedBarePods: true
    # Deprecated: Use `disabledDefaultPodProtections` with "withLocalStorage" instead.
    # evictLocalStoragePods: true
    nodeFit: true
    minReplicas: 2
    protectionPolicies:
      extraEnabled:
         - withPVC
         - withoutPDB
      # list of disabled pod policies
      disabled:
         - withLocalStorage
         - systemCriticalPods
         - failedBarePods
         - daemonSetPods


// DisabledDefaultPodProtection defines the type for default Pod protection mechanisms.
// Each value represents a specific protection rule that can be disabled.
type DisabledDefaultPodProtection string
Copy link
Contributor

Choose a reason for hiding this comment

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

Both DisabledDefaultPodProtection and ExtraPodProtection can be consolidated into a single type. E.g.

type PodProtectionPolicy string

const (
	PodsWithLocalStorage PodProtectionPolicy = "podsWithLocalStorage"
	DaemonSetPods PodProtectionPolicy = "daemonSetPods"
	SystemCriticalPods PodProtectionPolicy = "systemCriticalPods"
	FailedBarePods PodProtectionPolicy = "failedBarePods"
	PodsWithPVC PodProtectionPolicy = "podsWithPVC"
	PodsWithoutPDB PodProtectionPolicy = "podsWithoutPDB"
)

With some of the policies enabled by default. Other used for extra enabling or disabling. Also, would you please have defaults.go set the default list of enabled policies too? E.g.

args.defaultPodProtectionPolicies = [PodsWithLocalStorage, DaemonSetPods, ...]

while extending the new private defaultPodProtectionPolicies field with a comment saying the list of default policies is a subject to change?

Copy link
Member Author

Choose a reason for hiding this comment

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

#1664 (comment)
@ingvagabund
We have discussed why not to use the default value here

Copy link
Member Author

Choose a reason for hiding this comment

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

I thinks this(set default value) will make the behavior incompatible with previous. I think using two types will not have any impact for user. It will also avoid coding errors of different strategies in the delegate (because we distinguish enable and disable as different types).

Copy link
Contributor

Choose a reason for hiding this comment

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

defaultPodProtectionPolicies is going to be a private variable only, not exposed to customers. Only for internal use.

Copy link
Member Author

Choose a reason for hiding this comment

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

got this

@googs1025 googs1025 force-pushed the refator/evict_arg branch 6 times, most recently from e4d12bc to d3ce730 Compare May 17, 2025 03:44
}

// PodProtectionPolicy defines the protection policy for a pod.
type PodProtectionPolicy string
Copy link
Member Author

Choose a reason for hiding this comment

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

Change to one type and use ExtraEnabled Disabled to decide

if uint(len(objs)) < defaultEvictorArgs.MinReplicas {
return fmt.Errorf("owner has %d replicas which is less than minReplicas of %d", len(objs), defaultEvictorArgs.MinReplicas)
}
if !useNewConfig {
Copy link
Member Author

Choose a reason for hiding this comment

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

We are here to maintain compatibility with the old config logic.

@googs1025 googs1025 force-pushed the refator/evict_arg branch from d3ce730 to 478a67e Compare May 17, 2025 03:47
Copy link
Contributor

@ingvagabund ingvagabund left a comment

Choose a reason for hiding this comment

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

To make the review and refactoring easier to follow would you please move the changes in constaints.go into a separate PR? Without introducing the pod protection policy. Just to refactor the code is it's easier to introduce the pod protection policies later.

// It supports both new-style (PodProtectionPolicies) and legacy-style flags.
func getEffectiveProtectedPolicies(args *DefaultEvictorArgs) []PodProtectionPolicy {
if args.defaultPodProtectionPolicies == nil {
args.defaultPodProtectionPolicies = BuiltInPodProtectionPolicies
Copy link
Contributor

Choose a reason for hiding this comment

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

defaultPodProtectionPolicies is used only for internal purposes so the same list of default policies does not have to be duplicated. If you plan to define BuiltInPodProtectionPolicies as well the new variable can be used instead of the internal defaultPodProtectionPolicies field.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed BuiltInPodProtectionPolicies
I think we just use defaultPodProtectionPolicies is enough 🤔

@googs1025 googs1025 force-pushed the refator/evict_arg branch from 478a67e to 0b33128 Compare May 19, 2025 00:44
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 19, 2025
@googs1025 googs1025 force-pushed the refator/evict_arg branch from 0b33128 to cfd5c26 Compare May 19, 2025 12:48
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 19, 2025
@googs1025 googs1025 force-pushed the refator/evict_arg branch 4 times, most recently from 12f11a2 to bd0d074 Compare May 19, 2025 15:02
| `ignorePodsWithoutPDB` |`bool`|`false`| set whether pods without PodDisruptionBudget should be evicted or ignored |

### Example policy
| Name | Type | Default Value | Description |
Copy link
Member Author

Choose a reason for hiding this comment

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

@googs1025 googs1025 requested a review from ingvagabund May 19, 2025 15:10
@ingvagabund
Copy link
Contributor

Apologies for the delays. I will not be able to finish the review. I am leaving for a vacation until June 8. I will resume once I am back.

@googs1025 googs1025 force-pushed the refator/evict_arg branch from bd0d074 to 09c9970 Compare May 27, 2025 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

follow-up feature: refactor DefaultEvictorArgs for more clear config
4 participants