Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rename action endpoints #1125

Merged
merged 14 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

.PHONY: all
all: build
all: generate manifests

##@ General

Expand Down
100 changes: 100 additions & 0 deletions frontend/endpoints/actions/renameattribute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package actions

import (
"github.com/gin-gonic/gin"
"github.com/keyval-dev/odigos/api/odigos/actions/v1alpha1"
"github.com/keyval-dev/odigos/frontend/kube"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func GetRenameAttribute(c *gin.Context, odigosns string, id string) {
action, err := kube.DefaultClient.ActionsClient.RenameAttributes(odigosns).Get(c, id, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
c.JSON(404, gin.H{
"error": "not found",
})
return
} else {
c.JSON(500, gin.H{
"error": err.Error(),
})
return
}
}
c.JSON(200, action.Spec)
}

func CreateRenameAttribute(c *gin.Context, odigosns string) {
var action v1alpha1.RenameAttribute
if err := c.ShouldBindJSON(&action.Spec); err != nil {
c.JSON(400, gin.H{
"error": err.Error(),
})
return
}
action.GenerateName = "ra-"
generatedAction, err := kube.DefaultClient.ActionsClient.RenameAttributes(odigosns).Create(c, &action, metav1.CreateOptions{})
if err != nil {
c.JSON(500, gin.H{
"error": err.Error(),
})
return
}
c.JSON(201, gin.H{
"id": generatedAction.Name,
})
}

func UpdateRenameAttribute(c *gin.Context, odigosns string, id string) {
action, err := kube.DefaultClient.ActionsClient.RenameAttributes(odigosns).Get(c, id, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
c.JSON(404, gin.H{
"error": "not found",
})
return
} else {
c.JSON(500, gin.H{
"error": err.Error(),
})
}
return
}
action.Spec = v1alpha1.RenameAttributeSpec{}
if err := c.ShouldBindJSON(&action.Spec); err != nil {
c.JSON(400, gin.H{
"error": err.Error(),
})
return
}
action.Name = id

_, err = kube.DefaultClient.ActionsClient.RenameAttributes(odigosns).Update(c, action, metav1.UpdateOptions{})
if err != nil {
c.JSON(500, gin.H{
"error": err.Error(),
})
return
}
c.JSON(204, nil)
}

func DeleteRenameAttribute(c *gin.Context, odigosns string, id string) {
err := kube.DefaultClient.ActionsClient.RenameAttributes(odigosns).Delete(c, id, metav1.DeleteOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
c.JSON(404, gin.H{
"error": "not found",
})
return
} else {
c.JSON(500, gin.H{
"error": err.Error(),
})
return
}
}
c.JSON(204, nil)
}
16 changes: 16 additions & 0 deletions frontend/endpoints/actions/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,21 @@ func GetActions(c *gin.Context, odigosns string) {
})
}

raActions, err := kube.DefaultClient.ActionsClient.RenameAttributes(odigosns).List(c, metav1.ListOptions{})
if err != nil {
c.JSON(500, gin.H{
"error": err.Error(),
})
return
}

for _, action := range raActions.Items {
response = append(response, IcaInstanceResponse{
Id: action.Name,
Type: action.Kind,
Spec: action.Spec,
})
}

c.JSON(200, response)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading