Skip to content
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
4 changes: 2 additions & 2 deletions cmd/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,8 +996,8 @@ func TestGetRestConfig(t *testing.T) {
}{
"EmptyKubeconfigEnvVar": {
kubeconfigPath: "",
expectError: true, // Will error when no in-cluster config is available
errorContains: "no configuration has been provided",
expectError: true,
errorContains: "KUBECONFIG environment variable is not set",
},
"ValidKubeconfigPath": {
setupFile: func() string {
Expand Down
7 changes: 6 additions & 1 deletion cmd/diff/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/crossplane/crossplane-runtime/v2/pkg/errors"
"github.com/crossplane/crossplane-runtime/v2/pkg/logging"

"github.com/crossplane/crossplane/v2/cmd/crank/version"
Expand Down Expand Up @@ -79,5 +80,9 @@ func main() {
}

func getRestConfig() (*rest.Config, error) {
return clientcmd.BuildConfigFromFlags("", os.Getenv("KUBECONFIG"))
kubeconfig := os.Getenv("KUBECONFIG")
if kubeconfig == "" {
return nil, errors.New("KUBECONFIG environment variable is not set. Please set KUBECONFIG to point to your kubeconfig file")
}
return clientcmd.BuildConfigFromFlags("", kubeconfig)
}
Loading