Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/akamai/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func Create() *cobra.Command {
return wrerr
}

isValid, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if !isValid {
catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if err != nil {
wrerr := fmt.Errorf("catalog validation failed: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
Expand Down
4 changes: 2 additions & 2 deletions cmd/aws/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func Create() *cobra.Command {
return wrerr
}

isValid, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if !isValid {
catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if err != nil {
wrerr := fmt.Errorf("invalid catalog apps: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
Expand Down
4 changes: 2 additions & 2 deletions cmd/azure/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func Create() *cobra.Command {
return wrerr
}

isValid, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if !isValid {
catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if err != nil {
wrerr := fmt.Errorf("invalid catalog apps: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
Expand Down
4 changes: 2 additions & 2 deletions cmd/civo/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func Create() *cobra.Command {

stepper.NewProgressStep("Validate Configuration")

isValid, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if !isValid {
catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if err != nil {
wrerr := fmt.Errorf("catalog validation failed: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
Expand Down
2 changes: 1 addition & 1 deletion cmd/digitalocean/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Create() *cobra.Command {
return wrerr
}

_, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if err != nil {
wrerr := fmt.Errorf("failed to validate catalog apps: %w", err)
stepper.FailCurrentStep(wrerr)
Expand Down
2 changes: 1 addition & 1 deletion cmd/google/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Create() *cobra.Command {
return wrerr
}

_, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if err != nil {
wrerr := fmt.Errorf("failed to validate catalog apps: %w", err)
stepper.FailCurrentStep(wrerr)
Expand Down
6 changes: 1 addition & 5 deletions cmd/k3d/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,11 @@ func runK3d(cmd *cobra.Command, _ []string) error {
utilities.CreateK1ClusterDirectory(cliFlags.ClusterName)
utils.DisplayLogHints()

isValid, catalogApps, err := catalog.ValidateCatalogApps(cmd.Context(), cliFlags.InstallCatalogApps)
catalogApps, err := catalog.ValidateCatalogApps(cmd.Context(), cliFlags.InstallCatalogApps)
if err != nil {
return fmt.Errorf("failed to validate catalog apps: %w", err)
}

if !isValid {
return errors.New("catalog apps validation failed")
}

switch cliFlags.GitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
Expand Down
2 changes: 1 addition & 1 deletion cmd/k3s/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func Create() *cobra.Command {
return wrerr
}

_, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if err != nil {
wrerr := fmt.Errorf("validation of catalog apps failed: %w", err)
stepper.FailCurrentStep(wrerr)
Expand Down
2 changes: 1 addition & 1 deletion cmd/vultr/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Create() *cobra.Command {
return wrerr
}

_, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if err != nil {
wrerr := fmt.Errorf("catalog validation failed: %w", err)
stepper.FailCurrentStep(wrerr)
Expand Down
60 changes: 29 additions & 31 deletions internal/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

apiTypes "github.com/konstructio/kubefirst-api/pkg/types"

"github.com/rs/zerolog/log"
"gopkg.in/yaml.v3"
)

Expand All @@ -36,84 +35,83 @@ func NewGitHub() *git.Client {
return git.NewClient(nil)
}

func ReadActiveApplications(ctx context.Context) (apiTypes.GitopsCatalogApps, error) {
func ReadActiveApplications(ctx context.Context) (*apiTypes.GitopsCatalogApps, error) {
gh := GitHubClient{
Client: NewGitHub(),
}

activeContent, err := gh.ReadGitopsCatalogRepoContents(ctx)
if err != nil {
return apiTypes.GitopsCatalogApps{}, fmt.Errorf("error retrieving gitops catalog repository content: %w", err)
return nil, fmt.Errorf("error retrieving gitops catalog repository content: %w", err)
}

index, err := gh.ReadGitopsCatalogIndex(ctx, activeContent)
if err != nil {
return apiTypes.GitopsCatalogApps{}, fmt.Errorf("error retrieving gitops catalog index content: %w", err)
return nil, fmt.Errorf("error retrieving gitops catalog index content: %w", err)
}

var out apiTypes.GitopsCatalogApps

err = yaml.Unmarshal(index, &out)
if err != nil {
return apiTypes.GitopsCatalogApps{}, fmt.Errorf("error retrieving gitops catalog applications: %w", err)
return nil, fmt.Errorf("error retrieving gitops catalog applications: %w", err)
}

return out, nil
return &out, nil
}

func ValidateCatalogApps(ctx context.Context, catalogApps string) (bool, []apiTypes.GitopsCatalogApp, error) {
items := strings.Split(catalogApps, ",")

gitopsCatalogapps := []apiTypes.GitopsCatalogApp{}
func ValidateCatalogApps(ctx context.Context, catalogApps string) ([]apiTypes.GitopsCatalogApp, error) {
if catalogApps == "" {
return true, gitopsCatalogapps, nil
// No catalog apps to install
return nil, nil
Comment thread
nathan-nicholson marked this conversation as resolved.
}

apps, err := ReadActiveApplications(ctx)
if err != nil {
log.Error().Msgf("error getting gitops catalog applications: %s", err)
return false, gitopsCatalogapps, err
return nil, err
}

items := strings.Split(catalogApps, ",")
gitopsCatalogapps := make([]apiTypes.GitopsCatalogApp, 0, len(items))
for _, app := range items {
found := false

for _, catalogApp := range apps.Apps {
if app == catalogApp.Name {
found = true

if catalogApp.SecretKeys != nil {
for _, secret := range catalogApp.SecretKeys {
secretValue := os.Getenv(secret.Env)

if secretValue == "" {
return false, gitopsCatalogapps, fmt.Errorf("your %q environment variable is not set for %q catalog application. Please set and try again", secret.Env, app)
}

secret.Value = secretValue
for pos, secret := range catalogApp.SecretKeys {
secretValue := os.Getenv(secret.Env)
if secretValue == "" {
return nil, fmt.Errorf("your %q environment variable is not set for %q catalog application. Please set and try again", secret.Env, app)
}

secret.Value = secretValue
catalogApp.SecretKeys[pos] = secret
}

if catalogApp.ConfigKeys != nil {
for _, config := range catalogApp.ConfigKeys {
configValue := os.Getenv(config.Env)
if configValue == "" {
return false, gitopsCatalogapps, fmt.Errorf("your %q environment variable is not set for %q catalog application. Please set and try again", config.Env, app)
}
config.Value = configValue
for pos, config := range catalogApp.ConfigKeys {
configValue := os.Getenv(config.Env)
if configValue == "" {
return nil, fmt.Errorf("your %q environment variable is not set for %q catalog application. Please set and try again", config.Env, app)
}

config.Value = configValue
catalogApp.ConfigKeys[pos] = config
}

gitopsCatalogapps = append(gitopsCatalogapps, catalogApp)

break
}
}

if !found {
return false, gitopsCatalogapps, fmt.Errorf("catalog app is not supported: %q", app)
return nil, fmt.Errorf("catalog app is not supported: %q", app)
}
}

return true, gitopsCatalogapps, nil
return gitopsCatalogapps, nil
}

func (gh *GitHubClient) ReadGitopsCatalogRepoContents(ctx context.Context) ([]*git.RepositoryContent, error) {
Expand Down