Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gen from all namespaces in config repo if none specified #445

Merged
merged 1 commit into from
Jul 10, 2024
Merged
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
1 change: 0 additions & 1 deletion cmd/lekko/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ func initCmd() *cobra.Command {
// Codegen
spin.Suffix = " Running codegen..."
spin.Start()
// TODO: make sure that `default` namespace exists
repoPath := try.To1(repo.PrepareGithubRepo())
if err := gen.GenNative(cmd.Context(), nlProject, lekkoPath, repoPath, gen.GenOptions{}); err != nil {
return errors.Wrap(err, "codegen for default namespace")
Expand Down
16 changes: 16 additions & 0 deletions pkg/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/lekkodev/cli/pkg/dotlekko"
"github.com/lekkodev/cli/pkg/native"
"github.com/lekkodev/cli/pkg/repo"
)

type GenOptions struct {
Expand All @@ -50,9 +51,24 @@ func GenNative(ctx context.Context, project *native.Project, lekkoPath, repoPath
if err != nil {
return errors.Wrap(err, "create output dir")
}
r, err := repo.NewLocal(repoPath, nil)
if err != nil {
return errors.Wrap(err, "read local repository")
}

if len(opts.Namespaces) == 0 {
// Try to generate from only existing namespaces in code
opts.Namespaces = try.To1(native.ListNamespaces(absLekkoPath, project.Language))
// If no existing namespaces in code, generate from all namespaces in config repo
if len(opts.Namespaces) == 0 {
nsMDs, err := r.ListNamespaces(ctx)
if err != nil {
return errors.Wrap(err, "list namespaces")
}
for _, nsMD := range nsMDs {
opts.Namespaces = append(opts.Namespaces, nsMD.Name)
}
}
}

switch project.Language {
Expand Down