Skip to content

Commit

Permalink
feat: odigos describe remote
Browse files Browse the repository at this point in the history
  • Loading branch information
blumamir committed Oct 17, 2024
1 parent dd51f6e commit 5532631
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 11 deletions.
35 changes: 26 additions & 9 deletions cli/cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ var describeCmd = &cobra.Command{

var describeText string
if describeRemoteFlag {
// TODO: remote flag support
// describeText = executeRemoteDescribe(ctx, client, "odigos", "", "")
describeText = executeRemoteOdigosDescribe(ctx, client, odigosNs)
} else {
describeText = describe.DescribeOdigos(ctx, client.Clientset, client.OdigosClient, odigosNs)
describeText = describe.DescribeOdigos(ctx, client, client.OdigosClient, odigosNs)
}
fmt.Println(describeText)
},
Expand Down Expand Up @@ -72,7 +71,7 @@ var describeSourceDeploymentCmd = &cobra.Command{

var describeText string
if describeRemoteFlag {
describeText = executeRemoteDescribe(ctx, client, "deployment", ns, name)
describeText = executeRemoteSourceDescribe(ctx, client, "deployment", ns, name)
} else {
describeText = describe.DescribeDeployment(ctx, client.Interface, client.OdigosClient, ns, name)
}
Expand All @@ -98,7 +97,7 @@ var describeSourceDaemonSetCmd = &cobra.Command{

var describeText string
if describeRemoteFlag {
describeText = executeRemoteDescribe(ctx, client, "daemonset", ns, name)
describeText = executeRemoteSourceDescribe(ctx, client, "daemonset", ns, name)
} else {
describeText = describe.DescribeDaemonSet(ctx, client.Interface, client.OdigosClient, ns, name)
}
Expand All @@ -124,16 +123,16 @@ var describeSourceStatefulSetCmd = &cobra.Command{

var describeText string
if describeRemoteFlag {
describeText = executeRemoteDescribe(ctx, client, "statefulset", ns, name)
describeText = executeRemoteSourceDescribe(ctx, client, "statefulset", ns, name)
} else {
describeText = describe.DescribeStatefulSet(ctx, client.Interface, client.OdigosClient, ns, name)
}
fmt.Println(describeText)
},
}

func executeRemoteDescribe(ctx context.Context, client *kube.Client, workloadKind string, workloadNs string, workloadName string) string {
uiSvcProxyEndpoint := getUiServiceEndpoint(ctx, client, workloadKind, workloadNs, workloadName)
func executeRemoteOdigosDescribe(ctx context.Context, client *kube.Client, odigosNs string) string {
uiSvcProxyEndpoint := getUiServiceOdigosEndpoint(ctx, client, odigosNs)
request := client.Clientset.RESTClient().Get().AbsPath(uiSvcProxyEndpoint).Do(ctx)
response, err := request.Raw()
if err != nil {
Expand All @@ -143,7 +142,25 @@ func executeRemoteDescribe(ctx context.Context, client *kube.Client, workloadKin
}
}

func getUiServiceEndpoint(ctx context.Context, client *kube.Client, workloadKind string, workloadNs string, workloadName string) string {
func executeRemoteSourceDescribe(ctx context.Context, client *kube.Client, workloadKind string, workloadNs string, workloadName string) string {
uiSvcProxyEndpoint := getUiServiceSourceEndpoint(ctx, client, workloadKind, workloadNs, workloadName)
request := client.Clientset.RESTClient().Get().AbsPath(uiSvcProxyEndpoint).Do(ctx)
response, err := request.Raw()
if err != nil {
return "Remote describe failed: " + err.Error()
} else {
return string(response)
}
}

func getUiServiceOdigosEndpoint(ctx context.Context, client *kube.Client, odigosNs string) string {
uiServiceName := "ui"
uiServicePort := 3000

return fmt.Sprintf("/api/v1/namespaces/%s/services/%s:%d/proxy/api/describe/odigos", odigosNs, uiServiceName, uiServicePort)
}

func getUiServiceSourceEndpoint(ctx context.Context, client *kube.Client, workloadKind string, workloadNs string, workloadName string) string {
ns, err := resources.GetOdigosNamespace(client, ctx)
if resources.IsErrNoOdigosNamespaceFound(err) {
fmt.Println("\033[31mERROR\033[0m no odigos installation found in the current cluster. use \"odigos install\" to install odigos in the cluster or check that kubeconfig is pointing to the correct cluster.")
Expand Down
10 changes: 10 additions & 0 deletions cli/cmd/resources/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ func NewUIRole(ns string) *rbacv1.Role {
"pods",
},
},
{
Verbs: []string{
"get",
"list",
},
APIGroups: []string{"apps"},
Resources: []string{
"replicasets",
},
},
{
Verbs: []string{
"get",
Expand Down
8 changes: 8 additions & 0 deletions frontend/endpoints/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ import (
"github.com/gin-gonic/gin"
"github.com/odigos-io/odigos/frontend/kube"
"github.com/odigos-io/odigos/k8sutils/pkg/describe"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
)

func DescribeOdigos(c *gin.Context) {
ctx := c.Request.Context()
odiogosNs := env.GetCurrentNamespace()
describeText := describe.DescribeOdigos(ctx, kube.DefaultClient, kube.DefaultClient.OdigosClient, odiogosNs)
c.Writer.WriteString(describeText)
}

func DescribeSource(c *gin.Context, ns string, kind string, name string) {
ctx := c.Request.Context()
switch kind {
Expand Down
3 changes: 3 additions & 0 deletions frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ func startHTTPServer(flags *Flags, odigosMetrics *collectormetrics.OdigosMetrics
apis.PUT("/instrumentation-rules/:id", func(c *gin.Context) { endpoints.UpdateInstrumentationRule(c, flags.Namespace, c.Param("id")) })

// Describe
apis.GET("/describe/odigos", func(c *gin.Context) {
endpoints.DescribeOdigos(c)
})
apis.GET("/describe/source/namespace/:namespace/kind/:kind/name/:name", func(c *gin.Context) {
endpoints.DescribeSource(c, c.Param("namespace"), c.Param("kind"), c.Param("name"))
})
Expand Down
7 changes: 7 additions & 0 deletions helm/odigos/templates/ui/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ rules:
- get
- list
- watch
- apiGroups:
- "apps"
resources:
- replicasets
verbs:
- get
- list
- apiGroups:
- "odigos.io"
resources:
Expand Down
2 changes: 1 addition & 1 deletion k8sutils/pkg/describe/odigos.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func printDescribeOdigos(odigosVersion string, clusterCollector clusterCollector
return sb.String()
}

func DescribeOdigos(ctx context.Context, kubeClient *kubernetes.Clientset, odigosClient odigosclientset.OdigosV1alpha1Interface, odigosNs string) string {
func DescribeOdigos(ctx context.Context, kubeClient kubernetes.Interface, odigosClient odigosclientset.OdigosV1alpha1Interface, odigosNs string) string {

odigosVersion, err := getters.GetOdigosVersionInClusterFromConfigMap(ctx, kubeClient, odigosNs)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion k8sutils/pkg/getters/odigosversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (

// Return the Odigos version installed in the cluster.
// The function assumes odigos is installed, and will return an error if it is not or if the version cannot be detected (not expected in normal operation).
func GetOdigosVersionInClusterFromConfigMap(ctx context.Context, client *kubernetes.Clientset, ns string) (string, error) {
func GetOdigosVersionInClusterFromConfigMap(ctx context.Context, client kubernetes.Interface, ns string) (string, error) {
cm, err := client.CoreV1().ConfigMaps(ns).Get(ctx, consts.OdigosDeploymentConfigMapName, metav1.GetOptions{})
if err != nil {
return "", ErrNoOdigosDeploymentConfigMap
Expand Down

0 comments on commit 5532631

Please sign in to comment.