Skip to content

Commit 54c255e

Browse files
authored
Merge pull request kubernetes#86294 from enj/enj/i/negative_disable_kms_cache
kms: use negative cachesize value to disable caching
2 parents 4ff6928 + a16808f commit 54c255e

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

staging/src/k8s.io/apiserver/pkg/apis/config/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ type IdentityConfiguration struct{}
8888
type KMSConfiguration struct {
8989
// name is the name of the KMS plugin to be used.
9090
Name string
91-
// cacheSize is the maximum number of secrets which are cached in memory. The default value is 1000.
91+
// cachesize is the maximum number of secrets which are cached in memory. The default value is 1000.
92+
// Set to a negative value to disable caching.
9293
// +optional
9394
CacheSize *int32
9495
// endpoint is the gRPC server listening address, for example "unix:///var/run/kms-provider.sock".
9596
Endpoint string
96-
// Timeout for gRPC calls to kms-plugin (ex. 5s). The default is 3 seconds.
97+
// timeout for gRPC calls to kms-plugin (ex. 5s). The default is 3 seconds.
9798
// +optional
9899
Timeout *metav1.Duration
99100
}

staging/src/k8s.io/apiserver/pkg/apis/config/v1/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ type IdentityConfiguration struct{}
8888
type KMSConfiguration struct {
8989
// name is the name of the KMS plugin to be used.
9090
Name string `json:"name"`
91-
// cacheSize is the maximum number of secrets which are cached in memory. The default value is 1000.
91+
// cachesize is the maximum number of secrets which are cached in memory. The default value is 1000.
92+
// Set to a negative value to disable caching.
9293
// +optional
9394
CacheSize *int32 `json:"cachesize,omitempty"`
9495
// endpoint is the gRPC server listening address, for example "unix:///var/run/kms-provider.sock".
9596
Endpoint string `json:"endpoint"`
96-
// Timeout for gRPC calls to kms-plugin (ex. 5s). The default is 3 seconds.
97+
// timeout for gRPC calls to kms-plugin (ex. 5s). The default is 3 seconds.
9798
// +optional
9899
Timeout *metav1.Duration `json:"timeout,omitempty"`
99100
}

staging/src/k8s.io/apiserver/pkg/apis/config/validation/validation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const (
3434
mandatoryFieldErrFmt = "%s is a mandatory field for a %s"
3535
base64EncodingErr = "secrets must be base64 encoded"
3636
zeroOrNegativeErrFmt = "%s should be a positive value"
37-
negativeValueErrFmt = "%s can't be negative"
37+
nonZeroErrFmt = "%s should be a positive value, or negative to disable"
3838
encryptionConfigNilErr = "EncryptionConfiguration can't be nil"
3939
)
4040

@@ -184,8 +184,8 @@ func validateKMSConfiguration(c *config.KMSConfiguration, fieldPath *field.Path)
184184

185185
func validateKMSCacheSize(c *config.KMSConfiguration, fieldPath *field.Path) field.ErrorList {
186186
allErrs := field.ErrorList{}
187-
if *c.CacheSize <= 0 {
188-
allErrs = append(allErrs, field.Invalid(fieldPath, *c.CacheSize, fmt.Sprintf(zeroOrNegativeErrFmt, "cachesize")))
187+
if *c.CacheSize == 0 {
188+
allErrs = append(allErrs, field.Invalid(fieldPath, *c.CacheSize, fmt.Sprintf(nonZeroErrFmt, "cachesize")))
189189
}
190190

191191
return allErrs

staging/src/k8s.io/apiserver/pkg/apis/config/validation/validation_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,13 @@ func TestKMSProviderCacheSize(t *testing.T) {
331331
desc: "invalid zero cache size",
332332
in: &config.KMSConfiguration{CacheSize: &zeroCacheSize},
333333
want: field.ErrorList{
334-
field.Invalid(cacheField, int32(0), fmt.Sprintf(zeroOrNegativeErrFmt, "cachesize")),
334+
field.Invalid(cacheField, int32(0), fmt.Sprintf(nonZeroErrFmt, "cachesize")),
335335
},
336336
},
337337
{
338-
desc: "negative caches size",
338+
desc: "valid negative caches size",
339339
in: &config.KMSConfiguration{CacheSize: &negativeCacheSize},
340-
want: field.ErrorList{
341-
field.Invalid(cacheField, negativeCacheSize, fmt.Sprintf(zeroOrNegativeErrFmt, "cachesize")),
342-
},
340+
want: field.ErrorList{},
343341
},
344342
}
345343

0 commit comments

Comments
 (0)