mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 02:20:53 +00:00
Defer openAPI cleanup
This commit is contained in:
@@ -342,7 +342,7 @@ openAPI:
|
||||
func TestAddUpdateSubstitution(t *testing.T) {
|
||||
path := filepath.Join(os.TempDir(), "resourcefile")
|
||||
|
||||
//write initial resourcefile to temp path
|
||||
// write initial resourcefile to temp path
|
||||
err := ioutil.WriteFile(path, []byte(resourcefile), 0666)
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
@@ -360,7 +360,7 @@ func TestAddUpdateSubstitution(t *testing.T) {
|
||||
|
||||
values := []Value{value1, value2}
|
||||
|
||||
//add a setter definition
|
||||
// add a setter definition
|
||||
subd := SubstitutionDefinition{
|
||||
Name: "image",
|
||||
Pattern: "IMAGE_NAME:IMAGE_TAG",
|
||||
|
||||
@@ -42,13 +42,13 @@ openAPI:
|
||||
func TestDelete_Filter2(t *testing.T) {
|
||||
path := filepath.Join(os.TempDir(), "resourcefile2")
|
||||
|
||||
//write initial resourcefile to temp path
|
||||
// write initial resourcefile to temp path
|
||||
err := ioutil.WriteFile(path, []byte(resourcefile2), 0666)
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
//add a deleter definition
|
||||
// add a deleter definition
|
||||
dd := DeleterDefinition{
|
||||
Name: "image",
|
||||
DefinitionPrefix: fieldmeta.SetterDefinitionPrefix,
|
||||
|
||||
@@ -29,9 +29,11 @@ type List struct {
|
||||
|
||||
// ListSetters initializes l.Setters with the setters from the OpenAPI definitions in the file
|
||||
func (l *List) ListSetters(openAPIPath, resourcePath string) error {
|
||||
if err := openapi.AddSchemaFromFile(openAPIPath); err != nil {
|
||||
clean, err := openapi.AddSchemaFromFile(openAPIPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer clean()
|
||||
y, err := yaml.ReadFile(openAPIPath)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -41,9 +43,11 @@ func (l *List) ListSetters(openAPIPath, resourcePath string) error {
|
||||
|
||||
// ListSubst initializes l.Substitutions with the substitutions from the OpenAPI definitions in the file
|
||||
func (l *List) ListSubst(openAPIPath string) error {
|
||||
if err := openapi.AddSchemaFromFile(openAPIPath); err != nil {
|
||||
clean, err := openapi.AddSchemaFromFile(openAPIPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer clean()
|
||||
y, err := yaml.ReadFile(openAPIPath)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -71,10 +71,11 @@ func TestDeleterCreator_Delete(t *testing.T) {
|
||||
DefinitionPrefix: fieldmeta.SetterDefinitionPrefix,
|
||||
}
|
||||
|
||||
err = openapi.AddSchemaFromFile(openAPI.Name())
|
||||
clean, err := openapi.AddSchemaFromFile(openAPI.Name())
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
defer clean()
|
||||
dc.OpenAPIPath = openAPI.Name()
|
||||
dc.ResourcesPath = resource.Name()
|
||||
|
||||
|
||||
@@ -39,9 +39,11 @@ func (d DeleterCreator) Delete() error {
|
||||
}
|
||||
|
||||
// Load the updated definitions
|
||||
if err := openapi.AddSchemaFromFile(d.OpenAPIPath); err != nil {
|
||||
clean, err := openapi.AddSchemaFromFile(d.OpenAPIPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer clean()
|
||||
|
||||
// Update the resources with the deleter reference
|
||||
inout := &kio.LocalPackageReadWriter{PackagePath: d.ResourcesPath, PackageFileName: d.OpenAPIFileName}
|
||||
|
||||
@@ -79,9 +79,11 @@ func (fs FieldSetter) Set() (int, error) {
|
||||
}
|
||||
|
||||
// Load the updated definitions
|
||||
if err := openapi.AddSchemaFromFile(fs.OpenAPIPath); err != nil {
|
||||
clean, err := openapi.AddSchemaFromFile(fs.OpenAPIPath)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer clean()
|
||||
|
||||
// Update the resources with the new value
|
||||
// Set NoDeleteFiles to true as SetAll will return only the nodes of files which should be updated and
|
||||
@@ -108,9 +110,11 @@ func (fs FieldSetter) Set() (int, error) {
|
||||
// If syncOpenAPI is true, the openAPI files in destination directories are also
|
||||
// updated with the setter values in the input openAPI file
|
||||
func SetAllSetterDefinitions(syncOpenAPI bool, openAPIPath string, dirs ...string) error {
|
||||
if err := openapi.AddSchemaFromFile(openAPIPath); err != nil {
|
||||
clean, err := openapi.AddSchemaFromFile(openAPIPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer clean()
|
||||
for _, destDir := range dirs {
|
||||
if syncOpenAPI {
|
||||
openAPIFileName := filepath.Base(openAPIPath)
|
||||
@@ -122,7 +126,7 @@ func SetAllSetterDefinitions(syncOpenAPI bool, openAPIPath string, dirs ...strin
|
||||
rw := &kio.LocalPackageReadWriter{
|
||||
PackagePath: destDir,
|
||||
// set output won't include resources from files which
|
||||
//weren't modified. make sure we don't delete them.
|
||||
// weren't modified. make sure we don't delete them.
|
||||
NoDeleteFiles: true,
|
||||
}
|
||||
|
||||
|
||||
@@ -103,9 +103,11 @@ func (c SetterCreator) Create() error {
|
||||
}
|
||||
|
||||
// Load the updated definitions
|
||||
if err := openapi.AddSchemaFromFile(c.OpenAPIPath); err != nil {
|
||||
clean, err := openapi.AddSchemaFromFile(c.OpenAPIPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer clean()
|
||||
// if the setter is of array type write the derived list values back to
|
||||
// openAPI definitions
|
||||
if len(a.ListValues) > 0 {
|
||||
|
||||
@@ -93,9 +93,11 @@ func (c SubstitutionCreator) Create() error {
|
||||
}
|
||||
|
||||
// Load the updated definitions
|
||||
if err := openapi.AddSchemaFromFile(c.OpenAPIPath); err != nil {
|
||||
clean, err := openapi.AddSchemaFromFile(c.OpenAPIPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer clean()
|
||||
|
||||
visited := sets.String{}
|
||||
ref, err := spec.NewRef(fieldmeta.DefinitionsPrefix + fieldmeta.SubstitutionDefinitionPrefix + c.Name)
|
||||
@@ -119,9 +121,11 @@ func (c SubstitutionCreator) Create() error {
|
||||
}
|
||||
|
||||
// Load the updated definitions after setters are created
|
||||
if err := openapi.AddSchemaFromFile(c.OpenAPIPath); err != nil {
|
||||
clean, err = openapi.AddSchemaFromFile(c.OpenAPIPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer clean()
|
||||
|
||||
// revert openAPI file if there are cycles detected in created input substitution
|
||||
if err := checkForCycles(ext, visited); err != nil {
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestGetValuesForMarkers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//if expectedError is not nil, check for correctness of error message
|
||||
// if expectedError is not nil, check for correctness of error message
|
||||
assert.Contains(t, err.Error(), test.expectedError.Error())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -154,7 +154,8 @@ openAPI:
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
err = openapi.AddSchemaFromFile(filepath.Join(dir, "Krmfile"))
|
||||
clean, err := openapi.AddSchemaFromFile(filepath.Join(dir, "Krmfile"))
|
||||
defer clean()
|
||||
if err != nil {
|
||||
// do nothing if openAPI file or schema doesn't exist, CheckRequiredSettersSet()
|
||||
// should not throw any error
|
||||
|
||||
Reference in New Issue
Block a user