Skip to content

Commit

Permalink
feat: odigos describe remote flag to run the cluster (#1541)
Browse files Browse the repository at this point in the history
This can be used to run `odigos describe` in machines where `kubectl`
may lacks permissions for some of the resources.

It runs the describe in the ui deployment which can access the relevant
resources, and return it with http to the cli
  • Loading branch information
blumamir authored Sep 25, 2024
1 parent 12171a0 commit 33d30af
Show file tree
Hide file tree
Showing 10 changed files with 587 additions and 432 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ui/node_modules
frontend/node_modules
.git/
Dockerfile
odiglet/Dockerfile
Expand Down
483 changes: 53 additions & 430 deletions cli/cmd/describe.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions cli/cmd/resources/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ func NewUIClusterRole() *rbacv1.ClusterRole {
Resources: []string{"configmaps"},
Verbs: []string{"get", "list", "watch", "patch", "create", "delete", "update"},
},
{
APIGroups: []string{""},
Resources: []string{"pods"},
Verbs: []string{"get", "list"},
},
{
APIGroups: []string{"apps"},
Resources: []string{"deployments", "statefulsets", "daemonsets"},
Expand Down
2 changes: 2 additions & 0 deletions cli/pkg/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

type Client struct {
kubernetes.Interface
Clientset *kubernetes.Clientset
Dynamic *dynamic.DynamicClient
ApiExtensions apiextensionsclient.Interface
OdigosClient v1alpha1.OdigosV1alpha1Interface
Expand Down Expand Up @@ -65,6 +66,7 @@ func CreateClient(cmd *cobra.Command) (*Client, error) {

return &Client{
Interface: clientset,
Clientset: clientset,
Dynamic: dynamicClient,
ApiExtensions: extendClientset,
OdigosClient: odigosClient,
Expand Down
1 change: 1 addition & 0 deletions docs/cli/odigos_describe.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Pods (Total 1, Running 1):

```
-n, --namespace namespace of the source being described (default "default")
-r, --remote use odigos ui service in the cluster to describe the entity
```


Expand Down
2 changes: 1 addition & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ FROM gcr.io/distroless/static:nonroot
WORKDIR /app
COPY --from=backend /app/frontend/odigos-ui .
USER 65532:65532
ENTRYPOINT ["/app/odigos-ui"]
ENTRYPOINT ["/app/odigos-ui", "--address", "0.0.0.0"]
26 changes: 26 additions & 0 deletions frontend/endpoints/describe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package endpoints

import (
"github.com/gin-gonic/gin"
"github.com/odigos-io/odigos/frontend/kube"
"github.com/odigos-io/odigos/k8sutils/pkg/describe"
)

func DescribeSource(c *gin.Context, ns string, kind string, name string) {
ctx := c.Request.Context()
switch kind {
case "deployment":
describeText := describe.DescribeDeployment(ctx, kube.DefaultClient.Interface, kube.DefaultClient.OdigosClient, ns, name)
c.Writer.WriteString(describeText)
case "daemonset":
describeText := describe.DescribeDaemonSet(ctx, kube.DefaultClient.Interface, kube.DefaultClient.OdigosClient, ns, name)
c.Writer.WriteString(describeText)
case "statefulset":
describeText := describe.DescribeStatefulSet(ctx, kube.DefaultClient.Interface, kube.DefaultClient.OdigosClient, ns, name)
c.Writer.WriteString(describeText)
default:
c.JSON(404, gin.H{
"message": "kind not supported",
})
}
}
5 changes: 5 additions & 0 deletions frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ func startHTTPServer(flags *Flags, odigosMetrics *collectormetrics.OdigosMetrics
apis.DELETE("/instrumentation-rules/:id", func(c *gin.Context) { endpoints.DeleteInstrumentationRule(c, flags.Namespace, c.Param("id")) })
apis.PUT("/instrumentation-rules/:id", func(c *gin.Context) { endpoints.UpdateInstrumentationRule(c, flags.Namespace, c.Param("id")) })

// Describe
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"))
})

apis.GET("/actions", func(c *gin.Context) { actions.GetActions(c, flags.Namespace) })

// AddClusterInfo
Expand Down
7 changes: 7 additions & 0 deletions helm/odigos/templates/ui/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ rules:
- create
- delete
- update
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- apiGroups:
- apps
resources:
Expand Down
Loading

0 comments on commit 33d30af

Please sign in to comment.