scheduler_perf: fail when input YAML is invalid
The YAML files get decoded into an unstructured object, without validation, and then sent to the apiserver with a generic client. The default behavior is to issue a warning to the client, which gets logged by client-go. What we want instead is an error that causes the test to fail in a clean way right at the beginning.
This commit is contained in:
		@@ -95,17 +95,23 @@ func (c *createAny) run(tCtx ktesting.TContext) {
 | 
				
			|||||||
			return fmt.Errorf("map %q to resource: %v", gk, err)
 | 
								return fmt.Errorf("map %q to resource: %v", gk, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		resourceClient := tCtx.Dynamic().Resource(mapping.Resource)
 | 
							resourceClient := tCtx.Dynamic().Resource(mapping.Resource)
 | 
				
			||||||
 | 
							options := metav1.CreateOptions{
 | 
				
			||||||
 | 
								// If the YAML input is invalid, then we want the
 | 
				
			||||||
 | 
								// apiserver to tell us via an error. This can
 | 
				
			||||||
 | 
								// happen because decoding into an unstructured object
 | 
				
			||||||
 | 
								// doesn't validate.
 | 
				
			||||||
 | 
								FieldValidation: "Strict",
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		if c.Namespace != "" {
 | 
							if c.Namespace != "" {
 | 
				
			||||||
			if mapping.Scope.Name() != meta.RESTScopeNameNamespace {
 | 
								if mapping.Scope.Name() != meta.RESTScopeNameNamespace {
 | 
				
			||||||
				return fmt.Errorf("namespace %q set for %q, but %q has scope %q", c.Namespace, c.TemplatePath, gk, mapping.Scope.Name())
 | 
									return fmt.Errorf("namespace %q set for %q, but %q has scope %q", c.Namespace, c.TemplatePath, gk, mapping.Scope.Name())
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			_, err = resourceClient.Namespace(c.Namespace).Create(tCtx, obj, metav1.CreateOptions{})
 | 
								_, err = resourceClient.Namespace(c.Namespace).Create(tCtx, obj, options)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			if mapping.Scope.Name() != meta.RESTScopeNameRoot {
 | 
								if mapping.Scope.Name() != meta.RESTScopeNameRoot {
 | 
				
			||||||
				return fmt.Errorf("namespace not set for %q, but %q has scope %q", c.TemplatePath, gk, mapping.Scope.Name())
 | 
									return fmt.Errorf("namespace not set for %q, but %q has scope %q", c.TemplatePath, gk, mapping.Scope.Name())
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			_, err = resourceClient.Create(tCtx, obj, metav1.CreateOptions{})
 | 
								_, err = resourceClient.Create(tCtx, obj, options)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user