This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
conformance: move kustomization logic into kustomize.go
- Loading branch information
1 parent
78a5ffe
commit 1c8acbd
Showing
2 changed files
with
70 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package conformance | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"testing" | ||
|
||
"sigs.k8s.io/kustomize/api/krusty" | ||
"sigs.k8s.io/kustomize/kyaml/filesys" | ||
) | ||
|
||
func kustomizeBaseManifests(t *testing.T, baseManifests []byte) (string, error) { | ||
// Create kyaml wrapper for local filesystem, needed for Kustomizer.Run, and tmpdir | ||
fs := filesys.MakeFsOnDisk() | ||
tmpdir := t.TempDir() | ||
|
||
// Write embedded base manifests to kyaml filesystem | ||
basedir := filepath.Join(tmpdir, "base") | ||
if err := fs.Mkdir(basedir); err != nil { | ||
return "", fmt.Errorf("Error creating base directory: %v", err) | ||
} | ||
if err := fs.WriteFile(filepath.Join(basedir, "manifests.yaml"), baseManifests); err != nil { | ||
return "", fmt.Errorf("Error writing base manifests file in base directory: %v", err) | ||
} | ||
|
||
// Copy kustomization to tmpdir | ||
b, err := fs.ReadFile("kustomization.yaml") | ||
if err != nil { | ||
return "", fmt.Errorf("Error reading kustomization: %v", err) | ||
} | ||
if err := fs.WriteFile(filepath.Join(tmpdir, "kustomization.yaml"), b); err != nil { | ||
return "", fmt.Errorf("Error writing kustomization in tmpdir: %v", err) | ||
} | ||
|
||
// Copy proxydefaults to tmpdir | ||
b, err = fs.ReadFile("proxydefaults.yaml") | ||
if err != nil { | ||
return "", fmt.Errorf("Error reading proxydefaults: %v", err) | ||
} | ||
if err := fs.WriteFile(filepath.Join(tmpdir, "proxydefaults.yaml"), b); err != nil { | ||
return "", fmt.Errorf("Error writing kustomization in tmpdir: %v", err) | ||
} | ||
|
||
// Kustomize base manifests | ||
k := krusty.MakeKustomizer( | ||
krusty.MakeDefaultOptions(), | ||
) | ||
resmap, err := k.Run(fs, tmpdir) | ||
if err != nil { | ||
return "", fmt.Errorf("Error kustomizing base manifests: %v", err) | ||
} | ||
|
||
// Parse results from kustomization run as YAML | ||
b, err = resmap.AsYaml() | ||
if err != nil { | ||
return "", fmt.Errorf("Error converting kustomized resources to YAML: %v", err) | ||
} | ||
|
||
// Write kustomized resources back to disk | ||
kustomizedPath := filepath.Join(tmpdir, "kustomized.yaml") | ||
if err := fs.WriteFile(kustomizedPath, b); err != nil { | ||
return "", fmt.Errorf("Error writing kustomized YAML to tmpdir: %v", err) | ||
} | ||
|
||
return "local://" + kustomizedPath, nil | ||
} |