Merge pull request #83787 from sttts/sttts-crd-int-or-string-panic-fix
apiextensions: fix panic with x-kuberentes-int-or-string in CRDs
This commit is contained in:
		@@ -48,6 +48,7 @@ go_test(
 | 
				
			|||||||
    srcs = [
 | 
					    srcs = [
 | 
				
			||||||
        "convert_test.go",
 | 
					        "convert_test.go",
 | 
				
			||||||
        "goopenapi_test.go",
 | 
					        "goopenapi_test.go",
 | 
				
			||||||
 | 
					        "unfold_test.go",
 | 
				
			||||||
        "validation_test.go",
 | 
					        "validation_test.go",
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    embed = [":go_default_library"],
 | 
					    embed = [":go_default_library"],
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,7 @@ type Structural struct {
 | 
				
			|||||||
	Generic
 | 
						Generic
 | 
				
			||||||
	Extensions
 | 
						Extensions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	*ValueValidation
 | 
						ValueValidation *ValueValidation
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// +k8s:deepcopy-gen=true
 | 
					// +k8s:deepcopy-gen=true
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,13 +35,16 @@ func (s *Structural) Unfold() *Structural {
 | 
				
			|||||||
				return false
 | 
									return false
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if s.AnyOf == nil {
 | 
								if s.ValueValidation == nil {
 | 
				
			||||||
				s.AnyOf = []NestedValueValidation{
 | 
									s.ValueValidation = &ValueValidation{}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if s.ValueValidation.AnyOf == nil {
 | 
				
			||||||
 | 
									s.ValueValidation.AnyOf = []NestedValueValidation{
 | 
				
			||||||
					{ForbiddenGenerics: Generic{Type: "integer"}},
 | 
										{ForbiddenGenerics: Generic{Type: "integer"}},
 | 
				
			||||||
					{ForbiddenGenerics: Generic{Type: "string"}},
 | 
										{ForbiddenGenerics: Generic{Type: "string"}},
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				s.AllOf = append([]NestedValueValidation{
 | 
									s.ValueValidation.AllOf = append([]NestedValueValidation{
 | 
				
			||||||
					{
 | 
										{
 | 
				
			||||||
						ValueValidation: ValueValidation{
 | 
											ValueValidation: ValueValidation{
 | 
				
			||||||
							AnyOf: []NestedValueValidation{
 | 
												AnyOf: []NestedValueValidation{
 | 
				
			||||||
@@ -50,7 +53,7 @@ func (s *Structural) Unfold() *Structural {
 | 
				
			|||||||
							},
 | 
												},
 | 
				
			||||||
						},
 | 
											},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
				}, s.AllOf...)
 | 
									}, s.ValueValidation.AllOf...)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return true
 | 
								return true
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,32 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					Copyright 2019 The Kubernetes Authors.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Licensed under the Apache License, Version 2.0 (the "License");
 | 
				
			||||||
 | 
					you may not use this file except in compliance with the License.
 | 
				
			||||||
 | 
					You may obtain a copy of the License at
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    http://www.apache.org/licenses/LICENSE-2.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Unless required by applicable law or agreed to in writing, software
 | 
				
			||||||
 | 
					distributed under the License is distributed on an "AS IS" BASIS,
 | 
				
			||||||
 | 
					WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
				
			||||||
 | 
					See the License for the specific language governing permissions and
 | 
				
			||||||
 | 
					limitations under the License.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package schema
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TestStructuralUnfoldNilValueValidation tests that Unfold() does not crash
 | 
				
			||||||
 | 
					// on a IntOrString pattern with nil ValueValidation.
 | 
				
			||||||
 | 
					func TestStructuralUnfoldIntOrString(t *testing.T) {
 | 
				
			||||||
 | 
						schema := Structural{
 | 
				
			||||||
 | 
							Extensions: Extensions{
 | 
				
			||||||
 | 
								XIntOrString: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						schema.Unfold()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user