Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Commit

Permalink
Implements using ~/.config/tanzu/tkg/local as the config dir (#2305)
Browse files Browse the repository at this point in the history
- Adds `getLocalBomPath()` function
- Renames `bundle` to `bomImage` in `getTkrBom` function

Signed-off-by: John McBride <[email protected]>
  • Loading branch information
jpmcb authored and joshrosso committed Jan 18, 2022
1 parent be19512 commit 2e725b7
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions cli/cmd/plugin/standalone-cluster/tanzu/tanzu.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const (
configDir = ".config"
tanzuConfigDir = "tanzu"
tkgConfigDir = "tkg"
localConfigDir = "local"
bomDir = "bom"
tkgSysNamespace = "tkg-system"
tkgSvcAcctName = "core-pkgs"
tkgCoreRepoName = "tkg-core-repository"
Expand Down Expand Up @@ -180,17 +182,26 @@ func getTkgConfigDir() (path string, err error) {
return path, nil
}

func getTkgBomPath() (path string, err error) {
func getTkgLocalConfigDir() (path string, err error) {
tkgConfigDir, err := getTkgConfigDir()
if err != nil {
return "", err
}

return filepath.Join(tkgConfigDir, "bom"), nil
return filepath.Join(tkgConfigDir, localConfigDir), nil
}

func getLocalBomPath() (path string, err error) {
tkgLocalConfigDir, err := getTkgLocalConfigDir()
if err != nil {
return "", err
}

return filepath.Join(tkgLocalConfigDir, bomDir), nil
}

func getTkrBom(registry string) error {
bomPath, err := getTkgBomPath()
bomPath, err := getLocalBomPath()
if err != nil {
return err
}
Expand All @@ -213,20 +224,20 @@ func getTkrBom(registry string) error {
return nil
}

bundle, err := tkr.NewTkrImageReader(registry)
bomImage, err := tkr.NewTkrImageReader(registry)
if err != nil {
return err
}

err = bundle.DownloadImage()
err = bomImage.DownloadImage()
if err != nil {
return err
}

// Move the file from the temporary directory into the tanzu config dir
// TODO: these files names should be made configurable (from the LocalConfig ..?)
err = os.Rename(
filepath.Join(bundle.GetDownloadPath(), "tkr-bom-v1.21.2+vmware.1-tkg.1.yaml"),
filepath.Join(bomImage.GetDownloadPath(), "tkr-bom-v1.21.2+vmware.1-tkg.1.yaml"),
filepath.Join(bomPath, "tkr-bom-v1.21.2+vmware.1-tkg.1.yaml"),
)

Expand All @@ -238,7 +249,7 @@ func getTkrBom(registry string) error {
}

func parseTKRBom(fileName string) (*tkr.TKRBom, error) {
tkgBomPath, err := getTkgBomPath()
tkgBomPath, err := getLocalBomPath()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 2e725b7

Please sign in to comment.