Skip to content

Commit

Permalink
require host and member kubeconfigs (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrancisc authored Aug 5, 2024
1 parent f1ff8ef commit 456bd90
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions pkg/cmd/adm/register_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,25 @@ import (
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"
"time"

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/toolchain-common/pkg/cluster"
"github.com/codeready-toolchain/toolchain-common/pkg/condition"
"github.com/kubesaw/ksctl/pkg/client"
"github.com/kubesaw/ksctl/pkg/cmd/flags"
"github.com/kubesaw/ksctl/pkg/configuration"
clicontext "github.com/kubesaw/ksctl/pkg/context"
"github.com/kubesaw/ksctl/pkg/ioutils"
"github.com/kubesaw/ksctl/pkg/utils"
errs "github.com/pkg/errors"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/client-go/util/homedir"

errs "github.com/pkg/errors"
"github.com/spf13/cobra"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -80,26 +78,16 @@ func NewRegisterMemberCmd() *cobra.Command {
},
}

defaultKubeConfigPath := ""

// first check if KUBECONFIG env variable is set
if kubeconfigPath := os.Getenv("KUBECONFIG"); kubeconfigPath != "" {
defaultKubeConfigPath = kubeconfigPath
} else if home := homedir.HomeDir(); home != "" {
// use home kubeconfig if no KUBECONFIG env var was set
defaultKubeConfigPath = filepath.Join(home, ".kube", "config")
}

// keep these values in sync with the values in defaultRegisterMemberArgs() function in the tests.
defaultHostKubeConfig := defaultKubeConfigPath
defaultMemberKubeConfig := defaultKubeConfigPath
defaultLetsEncrypt := true
defaultNameSuffix := ""
defaultHostNs := "toolchain-host-operator"
defaultMemberNs := "toolchain-member-operator"

cmd.Flags().StringVar(&commandArgs.hostKubeConfig, "host-kubeconfig", defaultKubeConfigPath, fmt.Sprintf("Path to the kubeconfig file of the host cluster (default: '%s')", defaultHostKubeConfig))
cmd.Flags().StringVar(&commandArgs.memberKubeConfig, "member-kubeconfig", defaultMemberKubeConfig, fmt.Sprintf("Path to the kubeconfig file of the member cluster (default: '%s')", defaultMemberKubeConfig))
cmd.Flags().StringVar(&commandArgs.hostKubeConfig, "host-kubeconfig", "", "Path to the kubeconfig file of the host cluster")
flags.MustMarkRequired(cmd, "host-kubeconfig")
cmd.Flags().StringVar(&commandArgs.memberKubeConfig, "member-kubeconfig", "", "Path to the kubeconfig file of the member cluster")
flags.MustMarkRequired(cmd, "member-kubeconfig")
cmd.Flags().BoolVar(&commandArgs.useLetsEncrypt, "lets-encrypt", defaultLetsEncrypt, fmt.Sprintf("Whether to use Let's Encrypt certificates or rely on the cluster certs (default: %t)", defaultLetsEncrypt))
cmd.Flags().StringVar(&commandArgs.nameSuffix, "name-suffix", defaultNameSuffix, fmt.Sprintf("The suffix to append to the member name used when there are multiple members in a single cluster (default: '%s')", defaultNameSuffix))
cmd.Flags().StringVar(&commandArgs.hostNamespace, "host-ns", defaultHostNs, fmt.Sprintf("The namespace of the host operator in the host cluster (default: '%s')", defaultHostNs))
Expand Down

0 comments on commit 456bd90

Please sign in to comment.