This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmd): add command to check the configuration
imported from https://github.com/codeready-toolchain/argocd-checker Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
- Loading branch information
Showing
14 changed files
with
1,599 additions
and
319 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
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,61 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/codeready-toolchain/sandbox-argocd/pkg/validation" | ||
|
||
charmlog "github.com/charmbracelet/log" | ||
"github.com/spf13/afero" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewValidateConfigCmd() *cobra.Command { | ||
|
||
var apps, components []string | ||
var baseDir string | ||
var verbose bool | ||
|
||
checkCmd := &cobra.Command{ | ||
Use: "check-config --base-dir=$(pwd) --apps apps-of-apps,apps --components components --verbose=false", | ||
Short: "Checks the Argo CD configuration", | ||
Args: cobra.ExactArgs(0), | ||
|
||
Run: func(cmd *cobra.Command, _ []string) { | ||
logger := charmlog.New(cmd.OutOrStderr()) | ||
logger.SetLevel(charmlog.InfoLevel) | ||
if verbose { | ||
logger.SetLevel(charmlog.DebugLevel) | ||
} | ||
logger.Info("🏁 Checking Argo CD configuration", "base-dir", baseDir) | ||
afs := afero.Afero{ | ||
Fs: afero.NewOsFs(), | ||
} | ||
// verifies that the source path of the Applications and ApplicationSets exists | ||
if err := validation.CheckApplications(logger, afs, baseDir, apps...); err != nil { | ||
logger.Error(strings.ReplaceAll(err.Error(), ": ", ":\n")) | ||
os.Exit(1) | ||
} | ||
// verifies that `kustomize build` on each component completes successfully | ||
if err := validation.CheckComponents(logger, afs, baseDir, components...); err != nil { | ||
logger.Error(strings.ReplaceAll(err.Error(), ": ", ":\n")) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
checkCmd.Flags().StringSliceVar(&apps, "apps", []string{}, "path(s) to the applications (comma-separated, relative to '--baseDir')") | ||
if err := checkCmd.MarkFlagRequired("apps"); err != nil { | ||
panic(fmt.Sprintf("failed to mark flag as required: %s", err)) | ||
} | ||
checkCmd.Flags().StringVar(&baseDir, "base-dir", ".", "base directory of the repository") | ||
checkCmd.Flags().StringSliceVar(&components, "components", []string{}, "path(s) to the components (comma-separated, relative to '--baseDir')") | ||
if err := checkCmd.MarkFlagRequired("components"); err != nil { | ||
panic(fmt.Sprintf("failed to mark flag as required: %s", err)) | ||
} | ||
checkCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "verbose output") | ||
return checkCmd | ||
|
||
} |
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
Oops, something went wrong.