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

fix: failure when helmrepository and the helmrelease are in different namespaces #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion cmd/helmrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd

import (
"context"
"fmt"
"os"
"strconv"

Expand Down Expand Up @@ -64,6 +65,10 @@ with kubectl.`,
helmReleaseNamespace, _ := cmd.Flags().GetString("namespace")
confirmMigrate, _ := cmd.Flags().GetBool("confirm-migrate")

if helmReleaseName == "" || helmReleaseNamespace == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed. You can do this with cobra using MarkFlagsRequiredTogether.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use the MarkFlagsRequiredTogether, we'll get an error for command that doesn't require either of those flags such as mta scan.

log.Fatal("Both --name and --namespace flags must be provided")
}

// Set up the default context
ctx := context.TODO()

Expand Down Expand Up @@ -103,8 +108,10 @@ with kubectl.`,
}

// Get the helmchart based on type, report if error
helmChartName := fmt.Sprintf("%s-%s", helmReleaseNamespace, helmReleaseName)

helmChart := &sourcev1.HelmChart{}
err = k.Get(ctx, types.NamespacedName{Namespace: helmRepoNamespace, Name: helmRepoNamespace + "-" + helmRelease.Name}, helmChart)
err = k.Get(ctx, types.NamespacedName{Namespace: helmRepoNamespace, Name: helmChartName}, helmChart)
if err != nil {
log.Fatal(err)
}
Expand Down