diff --git a/cmd/argocd/commands/cluster.go b/cmd/argocd/commands/cluster.go index 172c2d27e6..c95a65f8ee 100644 --- a/cmd/argocd/commands/cluster.go +++ b/cmd/argocd/commands/cluster.go @@ -54,7 +54,7 @@ func NewClusterAddCommand(clientOpts *argocdclient.ClientOptions, pathOpts *clie systemNamespace string ) var command = &cobra.Command{ - Use: "add", + Use: "add CONTEXT", Short: fmt.Sprintf("%s cluster add CONTEXT", cliName), Run: func(c *cobra.Command, args []string) { var configAccess clientcmd.ConfigAccess = pathOpts @@ -65,9 +65,10 @@ func NewClusterAddCommand(clientOpts *argocdclient.ClientOptions, pathOpts *clie } config, err := configAccess.GetStartingConfig() errors.CheckError(err) - clstContext := config.Contexts[args[0]] + contextName := args[0] + clstContext := config.Contexts[contextName] if clstContext == nil { - log.Fatalf("Context %s does not exist in kubeconfig", args[0]) + log.Fatalf("Context %s does not exist in kubeconfig", contextName) } overrides := clientcmd.ConfigOverrides{ @@ -93,7 +94,7 @@ func NewClusterAddCommand(clientOpts *argocdclient.ClientOptions, pathOpts *clie } conn, clusterIf := argocdclient.NewClientOrDie(clientOpts).NewClusterClientOrDie() defer util.Close(conn) - clst := NewCluster(args[0], conf, managerBearerToken, awsAuthConf) + clst := NewCluster(contextName, conf, managerBearerToken, awsAuthConf) if inCluster { clst.Server = common.KubernetesInternalAPIServerAddr } @@ -101,9 +102,9 @@ func NewClusterAddCommand(clientOpts *argocdclient.ClientOptions, pathOpts *clie Cluster: clst, Upsert: upsert, } - clst, err = clusterIf.Create(context.Background(), &clstCreateReq) + _, err = clusterIf.Create(context.Background(), &clstCreateReq) errors.CheckError(err) - fmt.Printf("Cluster '%s' added\n", clst.Name) + fmt.Printf("Cluster '%s' added\n", clst.Server) }, } command.PersistentFlags().StringVar(&pathOpts.LoadingRules.ExplicitPath, pathOpts.ExplicitFileFlag, pathOpts.LoadingRules.ExplicitPath, "use a particular kubeconfig file") diff --git a/ui/src/app/applications/components/application-summary/application-summary.tsx b/ui/src/app/applications/components/application-summary/application-summary.tsx index 30d2c2ac9f..d460c897d3 100644 --- a/ui/src/app/applications/components/application-summary/application-summary.tsx +++ b/ui/src/app/applications/components/application-summary/application-summary.tsx @@ -49,7 +49,7 @@ export const ApplicationSummary = (props: { }, { title: 'CLUSTER', - view: , + view: , edit: (formApi: FormApi) => ( services.clusters.list().then((clusters) => clusters.map((cluster) => ({ title: clusterTitle(cluster), diff --git a/ui/src/app/applications/components/applications-list/applications-table.tsx b/ui/src/app/applications/components/applications-list/applications-table.tsx index ac773a214a..6341792d74 100644 --- a/ui/src/app/applications/components/applications-list/applications-table.tsx +++ b/ui/src/app/applications/components/applications-list/applications-table.tsx @@ -53,7 +53,7 @@ export const ApplicationsTable = (props: {
Destination:
-
/{app.spec.destination.namespace}
+
/{app.spec.destination.namespace}
diff --git a/ui/src/app/shared/components/cluster.tsx b/ui/src/app/shared/components/cluster.tsx index 20b9ea675d..5adc93b395 100644 --- a/ui/src/app/shared/components/cluster.tsx +++ b/ui/src/app/shared/components/cluster.tsx @@ -17,13 +17,13 @@ const clusterHTML = (cluster: models.Cluster, showUrl: boolean) => { return {text}; }; -async function getCluster(clusters: Promise, url: string): Promise { +async function getCluster(clusters: Promise, server: string): Promise { let cluster: models.Cluster; if (clusters) { - cluster = await clusters.then((items) => items.find((item) => item.server === url)); + cluster = await clusters.then((items) => items.find((item) => item.server === server)); } else { try { - cluster = await services.clusters.get(url); + cluster = await services.clusters.get(server); } catch { cluster = null; } @@ -31,8 +31,8 @@ async function getCluster(clusters: Promise, url: string): Pro if (!cluster) { cluster = { connectionState: null, - name: url, - server: url, + name: server, + server, serverVersion: null, }; } @@ -41,11 +41,11 @@ async function getCluster(clusters: Promise, url: string): Pro export const ClusterCtx = React.createContext>>(null); -export const Cluster = (props: {url: string; showUrl?: boolean; }) => ( +export const Cluster = (props: {server: string; showUrl?: boolean; }) => ( {(clusters) => ( - {props.url}} - load={(url) => getCluster(clusters, url)}>{(cluster: models.Cluster) => clusterHTML(cluster, props.showUrl)} + {props.server}} + load={(server) => getCluster(clusters, server)}>{(cluster: models.Cluster) => clusterHTML(cluster, props.showUrl)} )} ); diff --git a/util/db/cluster.go b/util/db/cluster.go index ab8d52e6f9..937a73a754 100644 --- a/util/db/cluster.go +++ b/util/db/cluster.go @@ -210,8 +210,8 @@ func (db *db) UpdateCluster(ctx context.Context, c *appv1.Cluster) (*appv1.Clust } // Delete deletes a cluster by name -func (db *db) DeleteCluster(ctx context.Context, name string) error { - secret, err := db.getClusterSecret(name) +func (db *db) DeleteCluster(ctx context.Context, server string) error { + secret, err := db.getClusterSecret(server) if err != nil { if errorStatus, ok := status.FromError(err); ok && errorStatus.Code() == codes.NotFound { return nil diff --git a/util/db/cluster_test.go b/util/db/cluster_test.go new file mode 100644 index 0000000000..a95c8035ce --- /dev/null +++ b/util/db/cluster_test.go @@ -0,0 +1,13 @@ +package db + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_serverToSecretName(t *testing.T) { + name, err := serverToSecretName("http://foo") + assert.NoError(t, err) + assert.Equal(t, "cluster-foo-752281925", name) +} diff --git a/util/db/db.go b/util/db/db.go index 867fd6cbea..52e1b4f025 100644 --- a/util/db/db.go +++ b/util/db/db.go @@ -18,11 +18,11 @@ type ArgoDB interface { // WatchClusters allow watching for cluster events WatchClusters(ctx context.Context, callback func(*ClusterEvent)) error // Get returns a cluster from a query - GetCluster(ctx context.Context, name string) (*appv1.Cluster, error) + GetCluster(ctx context.Context, server string) (*appv1.Cluster, error) // UpdateCluster updates a cluster UpdateCluster(ctx context.Context, c *appv1.Cluster) (*appv1.Cluster, error) // DeleteCluster deletes a cluster by name - DeleteCluster(ctx context.Context, name string) error + DeleteCluster(ctx context.Context, server string) error // ListRepositories lists repositories ListRepositories(ctx context.Context) ([]*appv1.Repository, error) diff --git a/util/db/db_test.go b/util/db/db_test.go index 5248ae6fc9..7ef37d82b2 100644 --- a/util/db/db_test.go +++ b/util/db/db_test.go @@ -296,33 +296,35 @@ func TestUpdateRepositoryWithManagedSecrets(t *testing.T) { } func TestGetClusterSuccessful(t *testing.T) { - clusterURL := "https://mycluster" + server := "my-cluster" + name := "my-name" clientset := getClientset(nil, &v1.Secret{ ObjectMeta: metav1.ObjectMeta{ - Name: "mycluster-443", Namespace: testNamespace, Labels: map[string]string{ common.LabelKeySecretType: common.LabelValueSecretTypeCluster, }, }, Data: map[string][]byte{ - "server": []byte(clusterURL), + "server": []byte(server), + "name": []byte(name), "config": []byte("{}"), }, }) db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset) - cluster, err := db.GetCluster(context.Background(), clusterURL) - assert.Nil(t, err) - assert.Equal(t, clusterURL, cluster.Server) + cluster, err := db.GetCluster(context.Background(), server) + assert.NoError(t, err) + assert.Equal(t, server, cluster.Server) + assert.Equal(t, name, cluster.Name) } func TestGetNonExistingCluster(t *testing.T) { - clusterURL := "https://mycluster" + server := "https://mycluster" clientset := getClientset(nil) db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset) - _, err := db.GetCluster(context.Background(), clusterURL) + _, err := db.GetCluster(context.Background(), server) assert.NotNil(t, err) status, ok := status.FromError(err) assert.True(t, ok) @@ -330,19 +332,19 @@ func TestGetNonExistingCluster(t *testing.T) { } func TestCreateClusterSuccessful(t *testing.T) { - clusterURL := "https://mycluster" + server := "https://mycluster" clientset := getClientset(nil) db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset) _, err := db.CreateCluster(context.Background(), &v1alpha1.Cluster{ - Server: clusterURL, + Server: server, }) assert.Nil(t, err) secret, err := clientset.CoreV1().Secrets(testNamespace).Get("cluster-mycluster-3274446258", metav1.GetOptions{}) assert.Nil(t, err) - assert.Equal(t, clusterURL, string(secret.Data["server"])) + assert.Equal(t, server, string(secret.Data["server"])) assert.Equal(t, common.AnnotationValueManagedByArgoCD, secret.Annotations[common.AnnotationKeyManagedBy]) }