diff --git a/cmd/argocd/commands/cluster.go b/cmd/argocd/commands/cluster.go index 3cda1b37d39fa..c5778ed95aef0 100644 --- a/cmd/argocd/commands/cluster.go +++ b/cmd/argocd/commands/cluster.go @@ -42,6 +42,9 @@ func NewClusterCommand(clientOpts *argocdclient.ClientOptions, pathOpts *clientc // NewClusterAddCommand returns a new instance of an `argocd cluster add` command func NewClusterAddCommand(clientOpts *argocdclient.ClientOptions, pathOpts *clientcmd.PathOptions) *cobra.Command { + var ( + inCluster bool + ) var command = &cobra.Command{ Use: "add", Short: fmt.Sprintf("%s cluster add CONTEXT", cliName), @@ -71,6 +74,9 @@ func NewClusterAddCommand(clientOpts *argocdclient.ClientOptions, pathOpts *clie conn, clusterIf := argocdclient.NewClientOrDie(clientOpts).NewClusterClientOrDie() defer util.Close(conn) clst := NewCluster(args[0], conf, managerBearerToken) + if inCluster { + clst.Server = common.KubernetesInternalAPIServerAddr + } clstCreateReq := cluster.ClusterCreateRequest{Cluster: clst} clst, err = clusterIf.Create(context.Background(), &clstCreateReq) errors.CheckError(err) @@ -78,6 +84,7 @@ func NewClusterAddCommand(clientOpts *argocdclient.ClientOptions, pathOpts *clie }, } command.PersistentFlags().StringVar(&pathOpts.LoadingRules.ExplicitPath, pathOpts.ExplicitFileFlag, pathOpts.LoadingRules.ExplicitPath, "use a particular kubeconfig file") + command.Flags().BoolVar(&inCluster, "in-cluster", false, "Indicates ArgoCD resides inside this cluster and should connect using the internal k8s hostname (kubernetes.default.svc)") return command } diff --git a/common/common.go b/common/common.go index 3f8f217d2e8a0..2066ece7aa1c2 100644 --- a/common/common.go +++ b/common/common.go @@ -20,6 +20,9 @@ const ( AuthCookieName = "argocd.token" // ResourcesFinalizerName is a number of application CRD finalizer ResourcesFinalizerName = "resources-finalizer." + MetadataPrefix + + // KubernetesInternalAPIServerAddr is address of the k8s API server when accessing internal to the cluster + KubernetesInternalAPIServerAddr = "https://kubernetes.default.svc" ) const (