Skip to content

Commit

Permalink
Localize fields: openapi, configurations, crds (kubernetes-sigs#4907)
Browse files Browse the repository at this point in the history
* Localize openapi, configurations, crds

* Add integration test

* Move krusty test

* Address code review feedback
  • Loading branch information
annasong20 authored and kishorerj committed Jan 8, 2023
1 parent 8a4efa2 commit a0bd001
Show file tree
Hide file tree
Showing 5 changed files with 406 additions and 165 deletions.
37 changes: 31 additions & 6 deletions api/internal/localizer/localizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,38 @@ func (lc *localizer) load() (*types.Kustomization, string, error) {
// localizeNativeFields localizes paths on kustomize-native fields, like configMapGenerator, that kustomize has a
// built-in understanding of. This excludes helm-related fields, such as `helmGlobals` and `helmCharts`.
func (lc *localizer) localizeNativeFields(kust *types.Kustomization) error {
for i, path := range kust.Components {
newPath, err := lc.localizeDir(path)
if path, exists := kust.OpenAPI["path"]; exists {
newPath, err := lc.localizeFile(path)
if err != nil {
return errors.WrapPrefixf(err, "unable to localize components field")
return errors.WrapPrefixf(err, "unable to localize openapi path")
}
kust.OpenAPI["path"] = newPath
}

for fieldName, field := range map[string]struct {
paths []string
locFn func(string) (string, error)
}{
"components": {
kust.Components,
lc.localizeDir,
},
"configurations": {
kust.Configurations,
lc.localizeFile,
},
"crds": {
kust.Crds,
lc.localizeFile,
},
} {
for i, path := range field.paths {
newPath, err := field.locFn(path)
if err != nil {
return errors.WrapPrefixf(err, "unable to localize %s path", fieldName)
}
field.paths[i] = newPath
}
kust.Components[i] = newPath
}

for i := range kust.ConfigMapGenerator {
Expand Down Expand Up @@ -168,8 +194,7 @@ func (lc *localizer) localizeNativeFields(kust *types.Kustomization) error {
}
}

// TODO(annasong): localize all other kustomization fields: resources, bases, crds, configurations,
// openapi, configMapGenerator.env, secretGenerator.env
// TODO(annasong): localize all other kustomization fields: resources, bases, configMapGenerator.env, secretGenerator.env
return nil
}

Expand Down
Loading

0 comments on commit a0bd001

Please sign in to comment.