From 639e53f9a0c1cbcbe3fcea42734e9e921de6ee2f Mon Sep 17 00:00:00 2001 From: Vladimir Kozhukalov Date: Thu, 17 Dec 2020 18:33:34 +0300 Subject: [PATCH] Change default manifest target path Now the target path for the default manifest is $HOME/.airship/default. This is reasonable default location. The target path is a mandatory field in the definition of a manifest. If a user wants to use her current working directory as a location the manifests, then it must be properly configured in the $HOME/.airship/config. Relates-To: #416 Relates-To: #417 Change-Id: I96601803939df5c7369d1580842dfabeb19aa017 --- cmd/document/pull.go | 16 ++++++++++ .../document-pull-cmd-with-help.golden | 7 +++- docs/source/cli/airshipctl_document_pull.md | 7 +++- pkg/cluster/status.go | 2 +- pkg/config/config.go | 4 +-- pkg/config/constants.go | 2 -- pkg/config/manifest.go | 9 +++++- pkg/config/manifest_test.go | 32 +++++++++++++++++++ pkg/config/utils.go | 6 ++-- pkg/document/pull/pull.go | 4 +-- 10 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 pkg/config/manifest_test.go diff --git a/cmd/document/pull.go b/cmd/document/pull.go index 38d392035..a1fb7168f 100644 --- a/cmd/document/pull.go +++ b/cmd/document/pull.go @@ -15,18 +15,34 @@ package document import ( + "fmt" + "path/filepath" + "github.com/spf13/cobra" "opendev.org/airship/airshipctl/pkg/config" "opendev.org/airship/airshipctl/pkg/document/pull" ) +const ( + long = ` +The remote manifests repositories as well as the target path where +the repositories will be cloned are defined in the airship config file. + +By default the airship config file is initialized with the +repository "https://opendev.org/airship/treasuremap" as a source of +manifests and with the manifests target path "%s". +` +) + // NewPullCommand creates a new command for pulling airship document repositories func NewPullCommand(cfgFactory config.Factory) *cobra.Command { var noCheckout bool documentPullCmd := &cobra.Command{ Use: "pull", Short: "Pulls documents from remote git repository", + Long: fmt.Sprintf(long[1:], filepath.Join( + config.HomeEnvVar, config.AirshipConfigDir, config.AirshipDefaultManifest)), RunE: func(cmd *cobra.Command, args []string) error { return pull.Pull(cfgFactory, noCheckout) }, diff --git a/cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-help.golden b/cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-help.golden index d2e2c889c..a38ae7402 100644 --- a/cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-help.golden +++ b/cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-help.golden @@ -1,4 +1,9 @@ -Pulls documents from remote git repository +The remote manifests repositories as well as the target path where +the repositories will be cloned are defined in the airship config file. + +By default the airship config file is initialized with the +repository "https://opendev.org/airship/treasuremap" as a source of +manifests and with the manifests target path "$HOME/.airship/default". Usage: pull [flags] diff --git a/docs/source/cli/airshipctl_document_pull.md b/docs/source/cli/airshipctl_document_pull.md index e2397be01..576708e5c 100644 --- a/docs/source/cli/airshipctl_document_pull.md +++ b/docs/source/cli/airshipctl_document_pull.md @@ -4,7 +4,12 @@ Pulls documents from remote git repository ### Synopsis -Pulls documents from remote git repository +The remote manifests repositories as well as the target path where +the repositories will be cloned are defined in the airship config file. + +By default the airship config file is initialized with the +repository "https://opendev.org/airship/treasuremap" as a source of +manifests and with the manifests target path "$HOME/.airship/default". ``` airshipctl document pull [flags] diff --git a/pkg/cluster/status.go b/pkg/cluster/status.go index c05442135..0e69581db 100644 --- a/pkg/cluster/status.go +++ b/pkg/cluster/status.go @@ -65,7 +65,7 @@ func (o *statusOptions) GetStatusMapDocs() (*StatusMap, []document.Document, err return nil, nil, err } - docBundle, err := document.NewBundleByPath(manifest.TargetPath) + docBundle, err := document.NewBundleByPath(manifest.GetTargetPath()) if err != nil { return nil, nil, err } diff --git a/pkg/config/config.go b/pkg/config/config.go index bd72958df..b06157e55 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -333,7 +333,7 @@ func (c *Config) CurrentContextTargetPath() (string, error) { if err != nil { return "", err } - return ccm.TargetPath, nil + return ccm.GetTargetPath(), nil } // CurrentContextPhaseRepositoryDir returns phase repository directory from current context's manifest @@ -516,7 +516,7 @@ func (c *Config) CurrentContextManifestMetadata() (*Metadata, error) { PhaseMeta: &PhaseMeta{}, } - data, err := c.fileSystem.ReadFile(filepath.Join(manifest.TargetPath, phaseRepoDir, manifest.MetadataPath)) + data, err := c.fileSystem.ReadFile(filepath.Join(manifest.GetTargetPath(), phaseRepoDir, manifest.MetadataPath)) if err != nil { return nil, err } diff --git a/pkg/config/constants.go b/pkg/config/constants.go index 1d62caeb8..72aea2290 100644 --- a/pkg/config/constants.go +++ b/pkg/config/constants.go @@ -50,8 +50,6 @@ const ( const ( // DefaultTestPhaseRepo holds default repo name DefaultTestPhaseRepo = "primary" - // DefaultTargetPath holds default target path - DefaultTargetPath = "/tmp/default" // DefaultManifestMetadataFile default path to manifest metadata file DefaultManifestMetadataFile = "manifests/site/test-site/metadata.yaml" ) diff --git a/pkg/config/manifest.go b/pkg/config/manifest.go index 20978d452..48d572657 100644 --- a/pkg/config/manifest.go +++ b/pkg/config/manifest.go @@ -14,7 +14,9 @@ limitations under the License. package config -import "sigs.k8s.io/yaml" +import ( + "sigs.k8s.io/yaml" +) // Manifest is a tuple of references to a Manifest (how do Identify, collect , // find the yaml manifests that airship uses to perform its operations) @@ -74,3 +76,8 @@ func (m *Manifest) String() string { } return string(yamlData) } + +// GetTargetPath returns TargetPath field +func (m *Manifest) GetTargetPath() string { + return m.TargetPath +} diff --git a/pkg/config/manifest_test.go b/pkg/config/manifest_test.go new file mode 100644 index 000000000..e45a53087 --- /dev/null +++ b/pkg/config/manifest_test.go @@ -0,0 +1,32 @@ +/* + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package config_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "opendev.org/airship/airshipctl/pkg/config" +) + +func TestGetTargetPath(t *testing.T) { + expected := "test" + m := &config.Manifest{ + TargetPath: expected, + } + p := m.GetTargetPath() + assert.Equal(t, expected, p) +} diff --git a/pkg/config/utils.go b/pkg/config/utils.go index 9bde58142..7088ee6d1 100644 --- a/pkg/config/utils.go +++ b/pkg/config/utils.go @@ -16,8 +16,10 @@ package config import ( "encoding/base64" + "path/filepath" "opendev.org/airship/airshipctl/pkg/fs" + "opendev.org/airship/airshipctl/pkg/util" ) // NewConfig returns a newly initialized Config object @@ -49,7 +51,7 @@ func NewConfig() *Config { }, }, }, - TargetPath: "/tmp/" + AirshipDefaultManifest, + TargetPath: filepath.Join(util.UserHomeDir(), AirshipConfigDir, AirshipDefaultManifest), PhaseRepositoryName: DefaultTestPhaseRepo, InventoryRepositoryName: DefaultTestPhaseRepo, MetadataPath: DefaultManifestMetadataFile, @@ -84,7 +86,7 @@ func NewManifest() *Manifest { return &Manifest{ InventoryRepositoryName: DefaultTestPhaseRepo, PhaseRepositoryName: DefaultTestPhaseRepo, - TargetPath: DefaultTargetPath, + TargetPath: filepath.Join(util.UserHomeDir(), AirshipConfigDir, AirshipDefaultManifest), Repositories: map[string]*Repository{DefaultTestPhaseRepo: NewRepository()}, MetadataPath: DefaultManifestMetadataFile, } diff --git a/pkg/document/pull/pull.go b/pkg/document/pull/pull.go index 72b9482f3..284aeba7c 100644 --- a/pkg/document/pull/pull.go +++ b/pkg/document/pull/pull.go @@ -44,12 +44,12 @@ func cloneRepositories(cfg *config.Config, noCheckout bool) error { if err != nil { return err } - repository, err := repo.NewRepository(currentManifest.TargetPath, extraRepoConfig) + repository, err := repo.NewRepository(currentManifest.GetTargetPath(), extraRepoConfig) if err != nil { return err } log.Printf("Downloading %s repository %s from %s into %s", - repoName, repository.Name, extraRepoConfig.URL(), currentManifest.TargetPath) + repoName, repository.Name, extraRepoConfig.URL(), currentManifest.GetTargetPath()) err = repository.Download(noCheckout) if err != nil { return err