Skip to content

Commit d947b2c

Browse files
seans3k8s-publishing-bot
authored andcommittedOct 11, 2024
LeaderMigrationConfig now uses strict validation
Kubernetes-commit: 553b2041e1e4ab31bf2180b36e38a9d0c42ebcfb
1 parent 5f8a4c1 commit d947b2c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
 

‎pkg/leadermigration/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
util "k8s.io/apimachinery/pkg/util/runtime"
2626
"k8s.io/apimachinery/pkg/util/validation/field"
2727
internal "k8s.io/controller-manager/config"
28-
"k8s.io/controller-manager/config/v1"
28+
v1 "k8s.io/controller-manager/config/v1"
2929
"k8s.io/controller-manager/config/v1alpha1"
3030
"k8s.io/controller-manager/config/v1beta1"
3131
)
@@ -63,7 +63,7 @@ func ReadLeaderMigrationConfiguration(configFilePath string) (*internal.LeaderMi
6363
if err != nil {
6464
return nil, fmt.Errorf("unable to read leader migration configuration from %q: %w", configFilePath, err)
6565
}
66-
config, gvk, err := serializer.NewCodecFactory(cfgScheme).UniversalDecoder().Decode(data, nil, nil)
66+
config, gvk, err := serializer.NewCodecFactory(cfgScheme, serializer.EnableStrict).UniversalDecoder().Decode(data, nil, nil)
6767
if err != nil {
6868
return nil, err
6969
}

‎pkg/leadermigration/config/config_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,30 @@ controllerLeaders: []
8282
ControllerLeaders: []internal.ControllerLeaderConfiguration{},
8383
},
8484
},
85+
{
86+
name: "unknown field causes error with strict validation",
87+
content: `
88+
apiVersion: controllermanager.config.k8s.io/v1alpha1
89+
kind: LeaderMigrationConfiguration
90+
leaderName: migration-120-to-121
91+
resourceLock: endpoints
92+
foo: bar
93+
controllerLeaders: []
94+
`,
95+
expectErr: true,
96+
},
97+
{
98+
name: "duplicate field causes error with strict validation",
99+
content: `
100+
apiVersion: controllermanager.config.k8s.io/v1alpha1
101+
kind: LeaderMigrationConfiguration
102+
leaderName: migration-120-to-121
103+
resourceLock: endpoints
104+
resourceLock: endpoints1
105+
controllerLeaders: []
106+
`,
107+
expectErr: true,
108+
},
85109
{
86110
name: "withLeaders",
87111
content: `

0 commit comments

Comments
 (0)
Please sign in to comment.