@@ -16,15 +16,10 @@ import (
1616 "open-cluster-management.io/policy-generator-plugin/internal/types"
1717)
1818
19- const (
20- localSchemaFileName = "schema.json"
21- kustomizeDir = "kustomize"
22- )
23-
24- type KustomizeJSON struct {
25- types.Filepath `json:"openapi,omitempty" yaml:"openapi,omitempty"`
26- Patches []Patch `json:"patches" yaml:"patches"`
27- Resources []string `json:"resources" yaml:"resources"`
19+ type kustomizeFile struct {
20+ OpenAPI types.Filepath `json:"openapi,omitempty" yaml:"openapi,omitempty"`
21+ Patches []Patch `json:"patches" yaml:"patches"`
22+ Resources []string `json:"resources" yaml:"resources"`
2823}
2924
3025type Patch struct {
@@ -183,19 +178,22 @@ func setPatchDefaults(
183178// the patched manifests. An error is returned if the patches can't be applied. This should be
184179// run after the Validate method.
185180func (m * manifestPatcher ) ApplyPatches () ([]map [string ]interface {}, error ) {
186- kustomizeDir := "kustomize"
181+ const (
182+ localSchemaFileName = "schema.json"
183+ kustomizeDir = "kustomize"
184+ )
187185
188186 // Create the file system in memory with the Kustomize YAML files
189187 fSys := filesys .MakeFsInMemory ()
190188
191- err := InitializeInMemoryKustomizeDir (fSys , m .openAPI .Path )
189+ err := initializeInMemoryKustomizeDir (fSys , m .openAPI .Path , kustomizeDir , localSchemaFileName )
192190 if err != nil {
193191 return nil , fmt .Errorf ("failed to initialize Kustomize dir: %w" , err )
194192 }
195193
196- kustomizationYAMLFile := KustomizeJSON {}
194+ kustomizationYAMLFile := kustomizeFile {}
197195 if m .openAPI .Path != "" {
198- kustomizationYAMLFile .Filepath .Path = localSchemaFileName
196+ kustomizationYAMLFile .OpenAPI .Path = localSchemaFileName
199197 }
200198
201199 options := []struct {
@@ -271,7 +269,9 @@ func (m *manifestPatcher) ApplyPatches() ([]map[string]interface{}, error) {
271269}
272270
273271// Initializes the in-memory file system with base directory and open API schema
274- func InitializeInMemoryKustomizeDir (fSys filesys.FileSystem , schema string ) (err error ) {
272+ func initializeInMemoryKustomizeDir (fSys filesys.FileSystem , schema ,
273+ kustomizeDir , localSchemaFileName string ,
274+ ) (err error ) {
275275 err = fSys .Mkdir (kustomizeDir )
276276 if err != nil {
277277 return fmt .Errorf ("an unexpected error occurred when configuring Kustomize: %w" , err )
@@ -282,12 +282,12 @@ func InitializeInMemoryKustomizeDir(fSys filesys.FileSystem, schema string) (err
282282
283283 schemaJSON , err := os .ReadFile (schema )
284284 if err != nil {
285- return fmt .Errorf ("unable to open file: %s, err : %w " , schema , err )
285+ return fmt .Errorf ("error reading file %s: %w " , schema , err )
286286 }
287287
288288 err = fSys .WriteFile (path .Join (kustomizeDir , localSchemaFileName ), schemaJSON )
289289 if err != nil {
290- return fmt .Errorf ("error writing schema, err : %w" , err )
290+ return fmt .Errorf ("error writing schema: %w" , err )
291291 }
292292 }
293293
0 commit comments