Fix kubectl explain bug when additionalProperties in schema defines as boolean. (#124506)
* Fix kubectl explain bug when additionalProperties in schema defines as: `additionalProperties: true` to ignore iterating. * trigger error on kubectl explain with integration test on crd with non bool additionalfields * add changes to fix the problem * replace sleep with loop and retry for kubectl explain integration test * replaced testdata file with inline create Kubernetes-commit: 834658cb26c1cfbb2b41ac2f04711563ee534682
This commit is contained in:
parent
b31dce3246
commit
55821cad07
2
go.mod
2
go.mod
|
|
@ -32,7 +32,7 @@ require (
|
||||||
k8s.io/api v0.0.0-20240516203440-664bdd58a30d
|
k8s.io/api v0.0.0-20240516203440-664bdd58a30d
|
||||||
k8s.io/apimachinery v0.0.0-20240510224318-1da46c3f5a5b
|
k8s.io/apimachinery v0.0.0-20240510224318-1da46c3f5a5b
|
||||||
k8s.io/cli-runtime v0.0.0-20240509010650-cee732fd4ad8
|
k8s.io/cli-runtime v0.0.0-20240509010650-cee732fd4ad8
|
||||||
k8s.io/client-go v0.0.0-20240520163845-86f83bc81899
|
k8s.io/client-go v0.0.0-20240521090535-c7396197f39e
|
||||||
k8s.io/component-base v0.0.0-20240509004100-482591e4108c
|
k8s.io/component-base v0.0.0-20240509004100-482591e4108c
|
||||||
k8s.io/component-helpers v0.0.0-20240511203730-30c6ab0cd73e
|
k8s.io/component-helpers v0.0.0-20240511203730-30c6ab0cd73e
|
||||||
k8s.io/klog/v2 v2.120.1
|
k8s.io/klog/v2 v2.120.1
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -275,8 +275,8 @@ k8s.io/apimachinery v0.0.0-20240510224318-1da46c3f5a5b h1:UTQPecSyfYRHmREs/0iVer
|
||||||
k8s.io/apimachinery v0.0.0-20240510224318-1da46c3f5a5b/go.mod h1:+hpAhBheGa7Ub4X6JfKqjEeACgGYZqZv+ILGzigzVGU=
|
k8s.io/apimachinery v0.0.0-20240510224318-1da46c3f5a5b/go.mod h1:+hpAhBheGa7Ub4X6JfKqjEeACgGYZqZv+ILGzigzVGU=
|
||||||
k8s.io/cli-runtime v0.0.0-20240509010650-cee732fd4ad8 h1:2CkqqqVdTCyNf/z2DF5qKs42HHsIU0bkkWb7nNgw0LE=
|
k8s.io/cli-runtime v0.0.0-20240509010650-cee732fd4ad8 h1:2CkqqqVdTCyNf/z2DF5qKs42HHsIU0bkkWb7nNgw0LE=
|
||||||
k8s.io/cli-runtime v0.0.0-20240509010650-cee732fd4ad8/go.mod h1:fM1OoEh4Wil6xcm53hPjs5c2Bu37hxWoaEOmXui1Fh4=
|
k8s.io/cli-runtime v0.0.0-20240509010650-cee732fd4ad8/go.mod h1:fM1OoEh4Wil6xcm53hPjs5c2Bu37hxWoaEOmXui1Fh4=
|
||||||
k8s.io/client-go v0.0.0-20240520163845-86f83bc81899 h1:oalNG1NReIkNNMCPVq5rzOLYH3mWP2n3MqnI3fBerPk=
|
k8s.io/client-go v0.0.0-20240521090535-c7396197f39e h1:ELb5A6Mh1VC9KKJYaFUf/6m16G5HEO7q6wRnDSsWNS4=
|
||||||
k8s.io/client-go v0.0.0-20240520163845-86f83bc81899/go.mod h1:mF3HjWextzMO13L26Q3GHi+ttX57kjYOBB0XT26k9/o=
|
k8s.io/client-go v0.0.0-20240521090535-c7396197f39e/go.mod h1:mF3HjWextzMO13L26Q3GHi+ttX57kjYOBB0XT26k9/o=
|
||||||
k8s.io/component-base v0.0.0-20240509004100-482591e4108c h1:dsvBpyLyEc10p5ARPS+9ZZgYIu8W89k2T9oNWvgxEmQ=
|
k8s.io/component-base v0.0.0-20240509004100-482591e4108c h1:dsvBpyLyEc10p5ARPS+9ZZgYIu8W89k2T9oNWvgxEmQ=
|
||||||
k8s.io/component-base v0.0.0-20240509004100-482591e4108c/go.mod h1:iQnJj8brojGA7iHRX01Yx9zVMeAuOGBVhQ0UpOm7vTw=
|
k8s.io/component-base v0.0.0-20240509004100-482591e4108c/go.mod h1:iQnJj8brojGA7iHRX01Yx9zVMeAuOGBVhQ0UpOm7vTw=
|
||||||
k8s.io/component-helpers v0.0.0-20240511203730-30c6ab0cd73e h1:bUUq3s9IvslnDKC6FN8MlNzYWPIM0hMc0CCITY/mZFw=
|
k8s.io/component-helpers v0.0.0-20240511203730-30c6ab0cd73e h1:bUUq3s9IvslnDKC6FN8MlNzYWPIM0hMc0CCITY/mZFw=
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ Takes dictionary as argument with keys:
|
||||||
{{- else if $resolved.items -}}
|
{{- else if $resolved.items -}}
|
||||||
{{- /* If the schema is an array then traverse the array item fields */ -}}
|
{{- /* If the schema is an array then traverse the array item fields */ -}}
|
||||||
{{- template "output" (set $nextContext "schema" $resolved.items) -}}
|
{{- template "output" (set $nextContext "schema" $resolved.items) -}}
|
||||||
{{- else if $resolved.additionalProperties -}}
|
{{- else if and $resolved.additionalProperties (not (eq "bool" (printf "%T" $resolved.additionalProperties))) -}}
|
||||||
{{- /* If the schema is a map then traverse the map item fields */ -}}
|
{{- /* If the schema is a map then traverse the map item fields */ -}}
|
||||||
{{- template "output" (set $nextContext "schema" $resolved.additionalProperties) -}}
|
{{- template "output" (set $nextContext "schema" $resolved.additionalProperties) -}}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
|
|
@ -182,7 +182,9 @@ Takes dictionary as argument with keys:
|
||||||
{{- template "fieldList" (set $nextContext "schema" .)}}
|
{{- template "fieldList" (set $nextContext "schema" .)}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- if $resolved.items}}{{- template "fieldList" (set $nextContext "schema" $resolved.items)}}{{end}}
|
{{- if $resolved.items}}{{- template "fieldList" (set $nextContext "schema" $resolved.items)}}{{end}}
|
||||||
{{- if $resolved.additionalProperties}}{{- template "fieldList" (set $nextContext "schema" $resolved.additionalProperties)}}{{end}}
|
{{- if and $resolved.additionalProperties (not (eq "bool" (printf "%T" $resolved.additionalProperties))) -}}
|
||||||
|
{{- template "fieldList" (set $nextContext "schema" $resolved.additionalProperties)}}
|
||||||
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
|
|
@ -235,7 +237,7 @@ Takes dictionary as argument with keys:
|
||||||
{{- if .items -}}
|
{{- if .items -}}
|
||||||
{{- template "description" (set $ "schema" .items) -}}
|
{{- template "description" (set $ "schema" .items) -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- if .additionalProperties -}}
|
{{- if and .additionalProperties (not (eq "bool" (printf "%T" .additionalProperties))) -}}
|
||||||
{{- template "description" (set $ "schema" .additionalProperties) -}}
|
{{- template "description" (set $ "schema" .additionalProperties) -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
@ -256,7 +258,7 @@ Takes dictionary as argument with keys:
|
||||||
{{- with $.schema -}}
|
{{- with $.schema -}}
|
||||||
{{- if .items -}}
|
{{- if .items -}}
|
||||||
[]{{template "typeGuess" (set $ "schema" .items)}}
|
[]{{template "typeGuess" (set $ "schema" .items)}}
|
||||||
{{- else if .additionalProperties -}}
|
{{- else if and .additionalProperties (not (eq "bool" (printf "%T" .additionalProperties))) -}}
|
||||||
map[string]{{template "typeGuess" (set $ "schema" .additionalProperties)}}
|
map[string]{{template "typeGuess" (set $ "schema" .additionalProperties)}}
|
||||||
{{- else if and .allOf (not .properties) (eq (len .allOf) 1) -}}
|
{{- else if and .allOf (not .properties) (eq (len .allOf) 1) -}}
|
||||||
{{- /* If allOf has a single element and there are no direct
|
{{- /* If allOf has a single element and there are no direct
|
||||||
|
|
|
||||||
|
|
@ -392,6 +392,20 @@ func TestPlaintext(t *testing.T) {
|
||||||
checkEquals("string"),
|
checkEquals("string"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// Shows that the typeguess template works with boolean additionalProperties
|
||||||
|
Name: "True additionalProperties",
|
||||||
|
Subtemplate: "typeGuess",
|
||||||
|
Context: map[string]any{
|
||||||
|
"schema": map[string]any{
|
||||||
|
"type": "string",
|
||||||
|
"additionalProperties": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Checks: []check{
|
||||||
|
checkEquals("string"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
// Show that a ref to a primitive type uses the referred type's type
|
// Show that a ref to a primitive type uses the referred type's type
|
||||||
Name: "PrimitiveRef",
|
Name: "PrimitiveRef",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue