mirror of
https://github.com/kubernetes/client-go.git
synced 2025-08-08 18:57:24 +00:00
Merge pull request #110436 from nicks/nicks/issue-1108
client-go: fix panic in ConfirmUsable validation Kubernetes-commit: 349efaabf89cf894d3f7ef16f3936318ae96728e
This commit is contained in:
commit
acab036eff
4
go.mod
4
go.mod
@ -24,7 +24,7 @@ require (
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
|
||||
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8
|
||||
google.golang.org/protobuf v1.27.1
|
||||
k8s.io/api v0.0.0-20220614194928-60387f6ceb7c
|
||||
k8s.io/api v0.0.0-20220614194929-edebc6706dde
|
||||
k8s.io/apimachinery v0.0.0-20220614194717-c5be38573c73
|
||||
k8s.io/klog/v2 v2.60.1
|
||||
k8s.io/kube-openapi v0.0.0-20220603121420-31174f50af60
|
||||
@ -63,6 +63,6 @@ require (
|
||||
)
|
||||
|
||||
replace (
|
||||
k8s.io/api => k8s.io/api v0.0.0-20220614194928-60387f6ceb7c
|
||||
k8s.io/api => k8s.io/api v0.0.0-20220614194929-edebc6706dde
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20220614194717-c5be38573c73
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -513,8 +513,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
k8s.io/api v0.0.0-20220614194928-60387f6ceb7c h1:DC+Zvr6/68fhuaIy5pTL0W4bAhbrnZi4jxozgPQ6vp0=
|
||||
k8s.io/api v0.0.0-20220614194928-60387f6ceb7c/go.mod h1:GLhFhgtyTRwgH456jroUFHnl0QFlRJ7RFJ41U7TgOZc=
|
||||
k8s.io/api v0.0.0-20220614194929-edebc6706dde h1:uI3Bauw5zHxpzCFMum9XlALU5iK37yEiAZgKdVUQHGA=
|
||||
k8s.io/api v0.0.0-20220614194929-edebc6706dde/go.mod h1:GLhFhgtyTRwgH456jroUFHnl0QFlRJ7RFJ41U7TgOZc=
|
||||
k8s.io/apimachinery v0.0.0-20220614194717-c5be38573c73 h1:EBei3PXKAoJZbqTqFYcQVh/wJcgXA/X1w7m8tBDyi3s=
|
||||
k8s.io/apimachinery v0.0.0-20220614194717-c5be38573c73/go.mod h1:iknpugsBdD8jeaGNZyi85Q334Mj3GFqi1SEHEEB/KQM=
|
||||
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
|
||||
|
@ -204,8 +204,19 @@ func ConfirmUsable(config clientcmdapi.Config, passedContextName string) error {
|
||||
|
||||
if exists {
|
||||
validationErrors = append(validationErrors, validateContext(contextName, *context, config)...)
|
||||
validationErrors = append(validationErrors, validateAuthInfo(context.AuthInfo, *config.AuthInfos[context.AuthInfo])...)
|
||||
validationErrors = append(validationErrors, validateClusterInfo(context.Cluster, *config.Clusters[context.Cluster])...)
|
||||
|
||||
// Default to empty users and clusters and let the validation function report an error.
|
||||
authInfo := config.AuthInfos[context.AuthInfo]
|
||||
if authInfo == nil {
|
||||
authInfo = &clientcmdapi.AuthInfo{}
|
||||
}
|
||||
validationErrors = append(validationErrors, validateAuthInfo(context.AuthInfo, *authInfo)...)
|
||||
|
||||
cluster := config.Clusters[context.Cluster]
|
||||
if cluster == nil {
|
||||
cluster = &clientcmdapi.Cluster{}
|
||||
}
|
||||
validationErrors = append(validationErrors, validateClusterInfo(context.Cluster, *cluster)...)
|
||||
}
|
||||
|
||||
return newErrConfigurationInvalid(validationErrors)
|
||||
|
@ -65,6 +65,42 @@ func TestConfirmUsableBadInfoButOkConfig(t *testing.T) {
|
||||
badValidation.testConfig(t)
|
||||
}
|
||||
|
||||
func TestConfirmUsableMissingObjects(t *testing.T) {
|
||||
config := clientcmdapi.NewConfig()
|
||||
config.Clusters["kind-cluster"] = &clientcmdapi.Cluster{
|
||||
Server: "anything",
|
||||
}
|
||||
config.AuthInfos["kind-user"] = &clientcmdapi.AuthInfo{
|
||||
Token: "any-value",
|
||||
}
|
||||
config.Contexts["missing-user"] = &clientcmdapi.Context{
|
||||
Cluster: "kind-cluster",
|
||||
AuthInfo: "garbage",
|
||||
}
|
||||
config.Contexts["missing-cluster"] = &clientcmdapi.Context{
|
||||
Cluster: "garbage",
|
||||
AuthInfo: "kind-user",
|
||||
}
|
||||
|
||||
missingUser := configValidationTest{
|
||||
config: config,
|
||||
expectedErrorSubstring: []string{
|
||||
`user "garbage" was not found for context "missing-user"`,
|
||||
},
|
||||
}
|
||||
missingUser.testConfirmUsable("missing-user", t)
|
||||
missingUser.testConfig(t)
|
||||
|
||||
missingCluster := configValidationTest{
|
||||
config: config,
|
||||
expectedErrorSubstring: []string{
|
||||
`cluster "garbage" was not found for context "missing-cluster"`,
|
||||
},
|
||||
}
|
||||
missingCluster.testConfirmUsable("missing-cluster", t)
|
||||
missingCluster.testConfig(t)
|
||||
}
|
||||
|
||||
func TestConfirmUsableBadInfoConfig(t *testing.T) {
|
||||
config := clientcmdapi.NewConfig()
|
||||
config.Clusters["missing ca"] = &clientcmdapi.Cluster{
|
||||
|
Loading…
Reference in New Issue
Block a user