diff --git a/cmd/admin/v1/cluster.go b/cmd/admin/v1/cluster.go index e145b37..6167504 100644 --- a/cmd/admin/v1/cluster.go +++ b/cmd/admin/v1/cluster.go @@ -118,9 +118,29 @@ func newClusterCmd(c *config.Config) *cobra.Command { Short: "commands for cluster machines", } + // metal admin cluster monitoring + monitoringCmd := &cobra.Command{ + Use: "monitoring", + Short: "fetch endpoint and access credentials for cluster monitoring", + RunE: func(cmd *cobra.Command, args []string) error { + id, err := genericcli.GetExactlyOneArg(args) + if err != nil { + return err + } + + clusterMonitoring, err := w.getMonitoringCredentials(id) + if err != nil { + return err + } + + return c.DescribePrinter.Print(clusterMonitoring) + }, + ValidArgsFunction: c.Completion.AdminClusterListCompletion, + } + machineCmd.AddCommand(machineListCmd, machineSSHCmd) - return genericcli.NewCmds(cmdsConfig, kubeconfigCmd, machineCmd) + return genericcli.NewCmds(cmdsConfig, kubeconfigCmd, machineCmd, monitoringCmd) } func (c *cluster) Create(rq any) (*apiv1.Cluster, error) { @@ -242,6 +262,22 @@ func (c *cluster) kubeconfig(args []string) error { return nil } +func (c *cluster) getMonitoringCredentials(id string) (*apiv1.ClusterMonitoring, error) { + ctx, cancel := c.c.NewRequestContext() + defer cancel() + + req := &adminv1.ClusterServiceGetMonitoringCredentialsRequest{ + Uuid: id, + } + + resp, err := c.c.Client.Adminv1().Cluster().GetMonitoringCredentials(ctx, connect.NewRequest(req)) + if err != nil { + return nil, fmt.Errorf("failed to get cluster credentials: %w", err) + } + + return resp.Msg.Monitoring, nil +} + func (c *cluster) machineList(args []string) error { ctx, cancel := c.c.NewRequestContext() defer cancel() diff --git a/cmd/api/v1/cluster.go b/cmd/api/v1/cluster.go index f3129fe..7afcce5 100644 --- a/cmd/api/v1/cluster.go +++ b/cmd/api/v1/cluster.go @@ -147,19 +147,19 @@ func newClusterCmd(c *config.Config) *cobra.Command { monitoringCmd := &cobra.Command{ Use: "monitoring", - Short: "fetch endpoints and access credentials to cluster monitoring", + Short: "fetch endpoint and access credentials for cluster monitoring", RunE: func(cmd *cobra.Command, args []string) error { id, err := genericcli.GetExactlyOneArg(args) if err != nil { return err } - cluster, err := w.Get(id) + clusterMonitoring, err := w.getMonitoringCredentials(id) if err != nil { return err } - return c.DescribePrinter.Print(cluster.Monitoring) + return c.DescribePrinter.Print(clusterMonitoring) }, ValidArgsFunction: c.Completion.ClusterListCompletion, } @@ -322,6 +322,23 @@ func (c *cluster) Get(id string) (*apiv1.Cluster, error) { return resp.Msg.Cluster, nil } +func (c *cluster) getMonitoringCredentials(id string) (*apiv1.ClusterMonitoring, error) { + ctx, cancel := c.c.NewRequestContext() + defer cancel() + + req := &apiv1.ClusterServiceGetMonitoringCredentialsRequest{ + Uuid: id, + Project: c.c.GetProject(), + } + + resp, err := c.c.Client.Apiv1().Cluster().GetMonitoringCredentials(ctx, connect.NewRequest(req)) + if err != nil { + return nil, fmt.Errorf("failed to get cluster credentials: %w", err) + } + + return resp.Msg.Monitoring, nil +} + func (c *cluster) List() ([]*apiv1.Cluster, error) { ctx, cancel := c.c.NewRequestContext() defer cancel() diff --git a/docs/metal_cluster.md b/docs/metal_cluster.md index b0ce8fb..f8c09f9 100644 --- a/docs/metal_cluster.md +++ b/docs/metal_cluster.md @@ -36,7 +36,7 @@ manage kubernetes clusters * [metal cluster exec-config](metal_cluster_exec-config.md) - fetch exec-config of a cluster * [metal cluster kubeconfig](metal_cluster_kubeconfig.md) - fetch kubeconfig of a cluster * [metal cluster list](metal_cluster_list.md) - list all clusters -* [metal cluster monitoring](metal_cluster_monitoring.md) - fetch endpoints and access credentials to cluster monitoring +* [metal cluster monitoring](metal_cluster_monitoring.md) - fetch endpoint and access credentials for cluster monitoring * [metal cluster reconcile](metal_cluster_reconcile.md) - reconcile a cluster * [metal cluster status](metal_cluster_status.md) - fetch status of a cluster * [metal cluster update](metal_cluster_update.md) - updates the cluster diff --git a/docs/metal_cluster_monitoring.md b/docs/metal_cluster_monitoring.md index 39b5401..f88ea6b 100644 --- a/docs/metal_cluster_monitoring.md +++ b/docs/metal_cluster_monitoring.md @@ -1,6 +1,6 @@ ## metal cluster monitoring -fetch endpoints and access credentials to cluster monitoring +fetch endpoint and access credentials for cluster monitoring ``` metal cluster monitoring [flags] diff --git a/go.mod b/go.mod index ac4d8ee..2c841c4 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/fatih/color v1.19.0 github.com/golang-jwt/jwt/v5 v5.3.1 github.com/google/go-cmp v0.7.0 - github.com/metal-stack-cloud/api v0.16.9 + github.com/metal-stack-cloud/api v0.16.11-0.20260826143907-4dfc96d1bd98 github.com/metal-stack/metal-lib v0.26.3 github.com/metal-stack/v v1.0.3 github.com/spf13/afero v1.15.0 diff --git a/go.sum b/go.sum index db3cd73..0a40d09 100644 --- a/go.sum +++ b/go.sum @@ -256,8 +256,8 @@ github.com/mdlayher/sdnotify v1.0.0 h1:Ma9XeLVN/l0qpyx1tNeMSeTjCPH6NtuD6/N9XdTlQ github.com/mdlayher/sdnotify v1.0.0/go.mod h1:HQUmpM4XgYkhDLtd+Uad8ZFK1T9D5+pNxnXQjCeJlGE= github.com/mdlayher/socket v0.6.1 h1:M7uj2NtuujUY4mYr1C57NmfNiRHbkKpnBxO856lsc3A= github.com/mdlayher/socket v0.6.1/go.mod h1:+/SGtqc9V+5dAuRgQsU0fGBI+oRDiW7O2Obx10OIWfg= -github.com/metal-stack-cloud/api v0.16.9 h1:biSqJ1BI3ExRbZD4Oz5z0SoO9b8T9uvrRSZrYtZDfco= -github.com/metal-stack-cloud/api v0.16.9/go.mod h1:fct2KsojPKyGgB7bZun42Teb80Pb4LvnMmAOfcco0N0= +github.com/metal-stack-cloud/api v0.16.11-0.20260826143907-4dfc96d1bd98 h1:PiM5slGnSAXNUtUML01kRLtN9t/GAxor9qbKKWQt71s= +github.com/metal-stack-cloud/api v0.16.11-0.20260826143907-4dfc96d1bd98/go.mod h1:qVXtruhliCBHisv1u6YXPAFtQrGURel60aVakLQyT4g= github.com/metal-stack/metal-lib v0.26.3 h1:K5gLoD65m6p3l6qCPrfavIdvNdWfmF2QdXrvU2URaZs= github.com/metal-stack/metal-lib v0.26.3/go.mod h1:cNXjPBs8SFnjqfBobuSbm5mDk6E/jS8PVeIOrV/7POE= github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs=