Skip to content

Commit cf1a15c

Browse files
authored
Merge pull request #6444 from XiShanYongYe-Chang/remove-toleration-flags-karmada-webhook
Remove default-not-ready-toleration-seconds and default-unreachable-toleration-seconds flags
2 parents 23848b3 + cd1ae69 commit cf1a15c

File tree

12 files changed

+25
-128
lines changed

12 files changed

+25
-128
lines changed

artifacts/deploy/karmada-webhook.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ spec:
3737
- --bind-address=$(POD_IP)
3838
- --metrics-bind-address=$(POD_IP):8080
3939
- --health-probe-bind-address=$(POD_IP):8000
40-
- --default-not-ready-toleration-seconds=30
41-
- --default-unreachable-toleration-seconds=30
4240
- --secure-port=8443
4341
- --cert-dir=/etc/karmada/pki/server
4442
- --feature-gates=AllAlpha=true,AllBeta=true

cmd/webhook/app/options/options.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ type Options struct {
6868
// that do not explicitly tolerate it, potentially causing unexpected service disruptions.
6969
AllowNoExecuteTaintPolicy bool
7070

71-
DefaultNotReadyTolerationSeconds int64
72-
DefaultUnreachableTolerationSeconds int64
73-
7471
ProfileOpts profileflag.Options
7572
}
7673

@@ -98,12 +95,6 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
9895
flags.StringVar(&o.HealthProbeBindAddress, "health-probe-bind-address", ":8000", "The TCP address that the controller should bind to for serving health probes(e.g. 127.0.0.1:8000, :8000)")
9996
flags.BoolVar(&o.AllowNoExecuteTaintPolicy, "allow-no-execute-taint-policy", false, "Allows configuring taints with NoExecute effect in ClusterTaintPolicy. Given the impact of NoExecute, applying such a taint to a cluster may trigger the eviction of workloads that do not explicitly tolerate it, potentially causing unexpected service disruptions. \nThis parameter is designed to remain disabled by default and requires careful evaluation by administrators before being enabled.")
10097

101-
// webhook flags
102-
flags.Int64Var(&o.DefaultNotReadyTolerationSeconds, "default-not-ready-toleration-seconds", 300, "Indicates the tolerationSeconds of the propagation policy toleration for notReady:NoExecute that is added by default to every propagation policy that does not already have such a toleration.")
103-
_ = flags.MarkDeprecated("default-not-ready-toleration-seconds", "Karmada will no longer automatically add cluster.karmada.io/not-ready:NoExecute taint to cluster objects, so there is no need to add default tolerations in propagation policy, default-not-ready-toleration-seconds is deprecated and will be removed in v1.15.")
104-
flags.Int64Var(&o.DefaultUnreachableTolerationSeconds, "default-unreachable-toleration-seconds", 300, "Indicates the tolerationSeconds of the propagation policy toleration for unreachable:NoExecute that is added by default to every propagation policy that does not already have such a toleration.")
105-
_ = flags.MarkDeprecated("default-unreachable-toleration-seconds", "Karmada will no longer automatically add cluster.karmada.io/unreachable:NoExecute taint to cluster objects, so there is no need to add default tolerations in propagation policy, default-unreachable-toleration-seconds is deprecated and will be removed in v1.15.")
106-
10798
features.FeatureGate.AddFlag(flags)
10899
o.ProfileOpts.AddFlags(flags)
109100
}

cmd/webhook/app/webhook.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ func Run(ctx context.Context, opts *options.Options) error {
187187
// ClusterOverridePolicy
188188
hookServer.Register("/validate-clusteroverridepolicy", &webhook.Admission{Handler: &clusteroverridepolicy.ValidatingAdmission{Decoder: decoder}})
189189
// ClusterPropagationPolicy
190-
hookServer.Register("/mutate-clusterpropagationpolicy", &webhook.Admission{Handler: clusterpropagationpolicy.NewMutatingHandler(
191-
opts.DefaultNotReadyTolerationSeconds, opts.DefaultUnreachableTolerationSeconds, decoder)})
190+
hookServer.Register("/mutate-clusterpropagationpolicy", &webhook.Admission{Handler: clusterpropagationpolicy.NewMutatingHandler(decoder)})
192191
hookServer.Register("/validate-clusterpropagationpolicy", &webhook.Admission{Handler: &clusterpropagationpolicy.ValidatingAdmission{Decoder: decoder}})
193192
// ClusterTaintPolicy
194193
hookServer.Register("/validate-clustertaintpolicy", &webhook.Admission{Handler: &clustertaintpolicy.ValidatingAdmission{Decoder: decoder, AllowNoExecuteTaintPolicy: opts.AllowNoExecuteTaintPolicy}})
@@ -198,8 +197,7 @@ func Run(ctx context.Context, opts *options.Options) error {
198197
hookServer.Register("/mutate-overridepolicy", &webhook.Admission{Handler: &overridepolicy.MutatingAdmission{Decoder: decoder}})
199198
hookServer.Register("/validate-overridepolicy", &webhook.Admission{Handler: &overridepolicy.ValidatingAdmission{Decoder: decoder}})
200199
// PropagationPolicy
201-
hookServer.Register("/mutate-propagationpolicy", &webhook.Admission{Handler: propagationpolicy.NewMutatingHandler(
202-
opts.DefaultNotReadyTolerationSeconds, opts.DefaultUnreachableTolerationSeconds, decoder)})
200+
hookServer.Register("/mutate-propagationpolicy", &webhook.Admission{Handler: propagationpolicy.NewMutatingHandler(decoder)})
203201
hookServer.Register("/validate-propagationpolicy", &webhook.Admission{Handler: &propagationpolicy.ValidatingAdmission{Decoder: decoder}})
204202

205203
// work group

operator/pkg/controlplane/webhook/manifests.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ spec:
5959
- --bind-address=$(POD_IP)
6060
- --metrics-bind-address=$(POD_IP):8080
6161
- --health-probe-bind-address=$(POD_IP):8000
62-
- --default-not-ready-toleration-seconds=30
63-
- --default-unreachable-toleration-seconds=30
6462
- --secure-port=8443
6563
- --cert-dir=/var/serving-cert
6664
- --v=4

pkg/util/helper/taint.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -192,26 +192,6 @@ func GetMatchingTolerations(taints []corev1.Taint, tolerations []corev1.Tolerati
192192
return true, result
193193
}
194194

195-
// NewNotReadyToleration returns a default not ready toleration.
196-
func NewNotReadyToleration(tolerationSeconds int64) *corev1.Toleration {
197-
return &corev1.Toleration{
198-
Key: clusterv1alpha1.TaintClusterNotReady,
199-
Operator: corev1.TolerationOpExists,
200-
Effect: corev1.TaintEffectNoExecute,
201-
TolerationSeconds: &tolerationSeconds,
202-
}
203-
}
204-
205-
// NewUnreachableToleration returns a default unreachable toleration.
206-
func NewUnreachableToleration(tolerationSeconds int64) *corev1.Toleration {
207-
return &corev1.Toleration{
208-
Key: clusterv1alpha1.TaintClusterUnreachable,
209-
Operator: corev1.TolerationOpExists,
210-
Effect: corev1.TaintEffectNoExecute,
211-
TolerationSeconds: &tolerationSeconds,
212-
}
213-
}
214-
215195
// GenerateTaintsMessage returns a string that describes the taints of a cluster.
216196
func GenerateTaintsMessage(taints []corev1.Taint) string {
217197
if len(taints) == 0 {

pkg/util/helper/taint_test.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -666,44 +666,6 @@ func TestGetMatchingTolerations(t *testing.T) {
666666
}
667667
}
668668

669-
func TestNewNotReadyToleration(t *testing.T) {
670-
expectedKey := clusterv1alpha1.TaintClusterNotReady
671-
expectedOperator := corev1.TolerationOpExists
672-
expectedEffect := corev1.TaintEffectNoExecute
673-
expectedSeconds := int64(123)
674-
675-
toleration := NewNotReadyToleration(expectedSeconds)
676-
677-
if toleration.Key != expectedKey {
678-
t.Errorf("Expected key %q but got %q", expectedKey, toleration.Key)
679-
}
680-
if toleration.Operator != expectedOperator {
681-
t.Errorf("Expected operator %q but got %q", expectedOperator, toleration.Operator)
682-
}
683-
if toleration.Effect != expectedEffect {
684-
t.Errorf("Expected effect %q but got %q", expectedEffect, toleration.Effect)
685-
}
686-
if *toleration.TolerationSeconds != expectedSeconds {
687-
t.Errorf("Expected seconds %d but got %d", expectedSeconds, *toleration.TolerationSeconds)
688-
}
689-
}
690-
691-
func TestNewUnreachableToleration(t *testing.T) {
692-
tolerationSeconds := int64(300)
693-
expectedToleration := &corev1.Toleration{
694-
Key: clusterv1alpha1.TaintClusterUnreachable,
695-
Operator: corev1.TolerationOpExists,
696-
Effect: corev1.TaintEffectNoExecute,
697-
TolerationSeconds: &tolerationSeconds,
698-
}
699-
700-
actualToleration := NewUnreachableToleration(tolerationSeconds)
701-
702-
if !reflect.DeepEqual(actualToleration, expectedToleration) {
703-
t.Errorf("NewUnreachableToleration() = %v, want %v", actualToleration, expectedToleration)
704-
}
705-
}
706-
707669
func TestGenerateTaintsMessage(t *testing.T) {
708670
tests := []struct {
709671
name string

pkg/webhook/clusterpropagationpolicy/mutating.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,15 @@ import (
3535
// MutatingAdmission mutates API request if necessary.
3636
type MutatingAdmission struct {
3737
Decoder admission.Decoder
38-
39-
DefaultNotReadyTolerationSeconds int64
40-
DefaultUnreachableTolerationSeconds int64
4138
}
4239

4340
// Check if our MutatingAdmission implements necessary interface
4441
var _ admission.Handler = &MutatingAdmission{}
4542

4643
// NewMutatingHandler builds a new admission.Handler.
47-
func NewMutatingHandler(notReadyTolerationSeconds, unreachableTolerationSeconds int64, decoder admission.Decoder) admission.Handler {
44+
func NewMutatingHandler(decoder admission.Decoder) admission.Handler {
4845
return &MutatingAdmission{
49-
DefaultNotReadyTolerationSeconds: notReadyTolerationSeconds,
50-
DefaultUnreachableTolerationSeconds: unreachableTolerationSeconds,
51-
Decoder: decoder,
46+
Decoder: decoder,
5247
}
5348
}
5449

@@ -64,8 +59,6 @@ func (a *MutatingAdmission) Handle(_ context.Context, req admission.Request) adm
6459

6560
// Set default spread constraints if both 'SpreadByField' and 'SpreadByLabel' not set.
6661
helper.SetDefaultSpreadConstraints(policy.Spec.Placement.SpreadConstraints)
67-
helper.AddTolerations(&policy.Spec.Placement, helper.NewNotReadyToleration(a.DefaultNotReadyTolerationSeconds),
68-
helper.NewUnreachableToleration(a.DefaultUnreachableTolerationSeconds))
6962

7063
if helper.ContainsServiceImport(policy.Spec.ResourceSelectors) {
7164
policy.Spec.PropagateDeps = true

pkg/webhook/clusterpropagationpolicy/mutating_test.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"testing"
2626

2727
admissionv1 "k8s.io/api/admission/v1"
28-
corev1 "k8s.io/api/core/v1"
2928
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3029
"k8s.io/apimachinery/pkg/runtime"
3130
"k8s.io/utils/ptr"
@@ -34,13 +33,10 @@ import (
3433

3534
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
3635
"github.com/karmada-io/karmada/pkg/util"
37-
"github.com/karmada-io/karmada/pkg/util/helper"
3836
)
3937

4038
var (
41-
notReadyTolerationSeconds int64 = 300
42-
unreachableTolerationSeconds int64 = 300
43-
failOverGracePeriodSeconds int32 = 600
39+
failOverGracePeriodSeconds int32 = 600
4440
)
4541

4642
type fakeMutationDecoder struct {
@@ -89,9 +85,7 @@ func TestMutatingAdmission_Handle(t *testing.T) {
8985

9086
for _, tt := range tests {
9187
t.Run(tt.name, func(t *testing.T) {
92-
v := NewMutatingHandler(
93-
notReadyTolerationSeconds, unreachableTolerationSeconds, tt.decoder,
94-
)
88+
v := NewMutatingHandler(tt.decoder)
9589
got := v.Handle(context.Background(), tt.req)
9690
if !reflect.DeepEqual(got, tt.want) {
9791
t.Errorf("Handle() = %v, want %v", got, tt.want)
@@ -162,10 +156,6 @@ func TestMutatingAdmission_Handle_FullCoverage(t *testing.T) {
162156
ReplicaSchedulingType: policyv1alpha1.ReplicaSchedulingTypeDivided,
163157
ReplicaDivisionPreference: policyv1alpha1.ReplicaDivisionPreferenceWeighted,
164158
},
165-
ClusterTolerations: []corev1.Toleration{
166-
*helper.NewNotReadyToleration(notReadyTolerationSeconds),
167-
*helper.NewUnreachableToleration(unreachableTolerationSeconds),
168-
},
169159
},
170160
PropagateDeps: true,
171161
ResourceSelectors: []policyv1alpha1.ResourceSelector{
@@ -196,9 +186,7 @@ func TestMutatingAdmission_Handle_FullCoverage(t *testing.T) {
196186
req.Object.Raw = wantBytes
197187

198188
// Instantiate the mutating handler.
199-
mutatingHandler := NewMutatingHandler(
200-
notReadyTolerationSeconds, unreachableTolerationSeconds, decoder,
201-
)
189+
mutatingHandler := NewMutatingHandler(decoder)
202190

203191
// Call the Handle function.
204192
got := mutatingHandler.Handle(context.Background(), req)

pkg/webhook/propagationpolicy/mutating.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,15 @@ import (
3535
// MutatingAdmission mutates API request if necessary.
3636
type MutatingAdmission struct {
3737
Decoder admission.Decoder
38-
39-
DefaultNotReadyTolerationSeconds int64
40-
DefaultUnreachableTolerationSeconds int64
4138
}
4239

4340
// Check if our MutatingAdmission implements necessary interface
4441
var _ admission.Handler = &MutatingAdmission{}
4542

4643
// NewMutatingHandler builds a new admission.Handler.
47-
func NewMutatingHandler(notReadyTolerationSeconds, unreachableTolerationSeconds int64, decoder admission.Decoder) admission.Handler {
44+
func NewMutatingHandler(decoder admission.Decoder) admission.Handler {
4845
return &MutatingAdmission{
49-
DefaultNotReadyTolerationSeconds: notReadyTolerationSeconds,
50-
DefaultUnreachableTolerationSeconds: unreachableTolerationSeconds,
51-
Decoder: decoder,
46+
Decoder: decoder,
5247
}
5348
}
5449

@@ -75,8 +70,6 @@ func (a *MutatingAdmission) Handle(_ context.Context, req admission.Request) adm
7570

7671
// Set default spread constraints if both 'SpreadByField' and 'SpreadByLabel' not set.
7772
helper.SetDefaultSpreadConstraints(policy.Spec.Placement.SpreadConstraints)
78-
helper.AddTolerations(&policy.Spec.Placement, helper.NewNotReadyToleration(a.DefaultNotReadyTolerationSeconds),
79-
helper.NewUnreachableToleration(a.DefaultUnreachableTolerationSeconds))
8073

8174
if helper.ContainsServiceImport(policy.Spec.ResourceSelectors) {
8275
policy.Spec.PropagateDeps = true

pkg/webhook/propagationpolicy/mutating_test.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"testing"
2626

2727
admissionv1 "k8s.io/api/admission/v1"
28-
corev1 "k8s.io/api/core/v1"
2928
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3029
"k8s.io/apimachinery/pkg/runtime"
3130
"k8s.io/utils/ptr"
@@ -34,13 +33,10 @@ import (
3433

3534
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
3635
"github.com/karmada-io/karmada/pkg/util"
37-
"github.com/karmada-io/karmada/pkg/util/helper"
3836
)
3937

4038
var (
41-
notReadyTolerationSeconds int64 = 300
42-
unreachableTolerationSeconds int64 = 300
43-
failOverGracePeriodSeconds int32 = 600
39+
failOverGracePeriodSeconds int32 = 600
4440
)
4541

4642
type fakeMutationDecoder struct {
@@ -89,9 +85,7 @@ func TestMutatingAdmission_Handle(t *testing.T) {
8985

9086
for _, tt := range tests {
9187
t.Run(tt.name, func(t *testing.T) {
92-
m := NewMutatingHandler(
93-
notReadyTolerationSeconds, unreachableTolerationSeconds, tt.decoder,
94-
)
88+
m := NewMutatingHandler(tt.decoder)
9589
got := m.Handle(context.Background(), tt.req)
9690
if !reflect.DeepEqual(got, tt.want) {
9791
t.Errorf("Handle() = %v, want %v", got, tt.want)
@@ -166,10 +160,6 @@ func TestMutatingAdmission_Handle_FullCoverage(t *testing.T) {
166160
ReplicaSchedulingType: policyv1alpha1.ReplicaSchedulingTypeDivided,
167161
ReplicaDivisionPreference: policyv1alpha1.ReplicaDivisionPreferenceWeighted,
168162
},
169-
ClusterTolerations: []corev1.Toleration{
170-
*helper.NewNotReadyToleration(notReadyTolerationSeconds),
171-
*helper.NewUnreachableToleration(unreachableTolerationSeconds),
172-
},
173163
},
174164
PropagateDeps: true,
175165
ResourceSelectors: []policyv1alpha1.ResourceSelector{
@@ -202,9 +192,7 @@ func TestMutatingAdmission_Handle_FullCoverage(t *testing.T) {
202192
req.Object.Raw = wantBytes
203193

204194
// Instantiate the mutating handler.
205-
mutatingHandler := NewMutatingHandler(
206-
notReadyTolerationSeconds, unreachableTolerationSeconds, decoder,
207-
)
195+
mutatingHandler := NewMutatingHandler(decoder)
208196

209197
// Call the Handle function.
210198
got := mutatingHandler.Handle(context.Background(), req)

0 commit comments

Comments
 (0)