Skip to content

Commit

Permalink
Merge branch 'TASK-141-sources-overview' into TASK-156-match-url-to-a…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
alonkeyval committed Aug 2, 2023
2 parents c44837e + 6253cbc commit 59029f1
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
dist/
node_modules
.DS_Store
.vscode
62 changes: 62 additions & 0 deletions frontend/endpoints/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package endpoints
import (
"github.com/gin-gonic/gin"
"github.com/keyval-dev/odigos/api/odigos/v1alpha1"
"github.com/keyval-dev/odigos/common/consts"
"github.com/keyval-dev/odigos/frontend/kube"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -34,6 +35,58 @@ func GetSources(c *gin.Context) {
c.JSON(200, sources)
}

func DeleteSource(c *gin.Context) {
// to delete a source, we need to set it's instrumentation label to disable
// afterwards, odigos will detect the change and remove the instrumented application object from k8s

ns := c.Param("namespace")
kind := c.Param("kind")
name := c.Param("name")

switch kind {
case "Deployment":
deployment, err := kube.DefaultClient.AppsV1().Deployments(ns).Get(c, name, metav1.GetOptions{})
if err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
markK8sObjectInstrumentationDisabled(deployment)
_, err = kube.DefaultClient.AppsV1().Deployments(ns).Update(c, deployment, metav1.UpdateOptions{})
if err != nil {
returnError(c, err)
return
}
case "StatefulSet":
statefulSet, err := kube.DefaultClient.AppsV1().StatefulSets(ns).Get(c, name, metav1.GetOptions{})
if err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
markK8sObjectInstrumentationDisabled(statefulSet)
_, err = kube.DefaultClient.AppsV1().StatefulSets(ns).Update(c, statefulSet, metav1.UpdateOptions{})
if err != nil {
returnError(c, err)
return
}
case "DaemonSet":
daemonSet, err := kube.DefaultClient.AppsV1().DaemonSets(ns).Get(c, name, metav1.GetOptions{})
if err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
markK8sObjectInstrumentationDisabled(daemonSet)
_, err = kube.DefaultClient.AppsV1().DaemonSets(ns).Update(c, daemonSet, metav1.UpdateOptions{})
if err != nil {
returnError(c, err)
return
}
default:
c.JSON(400, gin.H{"error": "kind not supported"})
return
}
c.JSON(200, gin.H{"message": "ok"})
}

func k8sInstrumentedAppToSource(app *v1alpha1.InstrumentedApplication) Source {
var source Source
source.Name = app.OwnerReferences[0].Name
Expand All @@ -47,3 +100,12 @@ func k8sInstrumentedAppToSource(app *v1alpha1.InstrumentedApplication) Source {
}
return source
}

func markK8sObjectInstrumentationDisabled(obj metav1.Object) {
labels := obj.GetLabels()
if labels == nil {
labels = make(map[string]string)
}
labels[consts.OdigosInstrumentationLabel] = consts.InstrumentationDisabled
obj.SetLabels(labels)
}
1 change: 1 addition & 0 deletions frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func startHTTPServer(flags *Flags) (*gin.Engine, error) {
apis.GET("/namespaces", endpoints.GetNamespaces)
apis.POST("/namespaces", endpoints.PersistNamespaces)
apis.GET("/sources", endpoints.GetSources)
apis.DELETE("/sources/namespace/:namespace/kind/:kind/name/:name", endpoints.DeleteSource)
apis.GET("/applications/:namespace", endpoints.GetApplicationsInNamespace)
apis.GET("/config", endpoints.GetConfig)
apis.GET("/destination-types", endpoints.GetDestinationTypes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export function ManageDestination({
)}
<ManageDestinationHeader data={selectedDestination} />
<CreateConnectionWrapper expand={!!onDelete || false}>

<div>
<CreateConnectionForm
fields={destinationType?.fields}
Expand Down

0 comments on commit 59029f1

Please sign in to comment.