mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Merge pull request #48963 from Raffo/master
Automatic merge from submit-queue (batch tested with PRs 52792, 48963). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix range for min value in imagepolicy admission **What this PR does / why we need it**: This makes the range for imagepolicy admission work properly. Currently if we specify `1s` for the value of `AllowTTL` or `DenyTTL` in the configuration yaml, we get a message like the following: ``` Error: failed to initialize plugins: Couldn't init admission plugin "ImagePolicyWebhook": valid value is between 1s and 30m0s, got 1s ``` This is due to a wrong comparison which is fixed in this PR. The rest of the PR just adds tests for this behaviour.
This commit is contained in:
commit
3812230f4d
@ -86,7 +86,7 @@ func normalizeConfigDuration(name string, scale, value, min, max, defaultValue t
|
||||
value *= scale
|
||||
|
||||
// check value is within range
|
||||
if value <= min || value > max {
|
||||
if value < min || value > max {
|
||||
return value, fmt.Errorf("valid value is between %v and %v, got %v", min, max, value)
|
||||
}
|
||||
return value, nil
|
||||
|
@ -89,6 +89,34 @@ func TestConfigNormalization(t *testing.T) {
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
test: "config within normal ranges for min values",
|
||||
config: imagePolicyWebhookConfig{
|
||||
AllowTTL: minAllowTTL / time.Second,
|
||||
DenyTTL: minDenyTTL / time.Second,
|
||||
RetryBackoff: minRetryBackoff,
|
||||
},
|
||||
normalizedConfig: imagePolicyWebhookConfig{
|
||||
AllowTTL: minAllowTTL,
|
||||
DenyTTL: minDenyTTL,
|
||||
RetryBackoff: minRetryBackoff * time.Millisecond,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
test: "config within normal ranges for max values",
|
||||
config: imagePolicyWebhookConfig{
|
||||
AllowTTL: maxAllowTTL / time.Second,
|
||||
DenyTTL: maxDenyTTL / time.Second,
|
||||
RetryBackoff: maxRetryBackoff / time.Millisecond,
|
||||
},
|
||||
normalizedConfig: imagePolicyWebhookConfig{
|
||||
AllowTTL: maxAllowTTL,
|
||||
DenyTTL: maxDenyTTL,
|
||||
RetryBackoff: maxRetryBackoff,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
err := normalizeWebhookConfig(&tt.config)
|
||||
|
Loading…
Reference in New Issue
Block a user