diff --git a/frontend/graph/generated.go b/frontend/graph/generated.go index 47916d30c..42dd0c20e 100644 --- a/frontend/graph/generated.go +++ b/frontend/graph/generated.go @@ -197,7 +197,7 @@ type ComplexityRoot struct { Mutation struct { CreateAction func(childComplexity int, action model.ActionInput) int CreateNewDestination func(childComplexity int, destination model.DestinationInput) int - DeleteAction func(childComplexity int, id string) int + DeleteAction func(childComplexity int, id string, actionType string) int PersistK8sNamespace func(childComplexity int, namespace model.PersistNamespaceItemInput) int PersistK8sSources func(childComplexity int, namespace string, sources []*model.PersistNamespaceSourceInput) int TestConnectionForDestination func(childComplexity int, destination model.DestinationInput) int @@ -263,7 +263,7 @@ type MutationResolver interface { UpdateDestination(ctx context.Context, id string, destination model.DestinationInput) (*model.Destination, error) CreateAction(ctx context.Context, action model.ActionInput) (model.Action, error) UpdateAction(ctx context.Context, id string, action model.ActionInput) (model.Action, error) - DeleteAction(ctx context.Context, id string) (bool, error) + DeleteAction(ctx context.Context, id string, actionType string) (bool, error) } type QueryResolver interface { ComputePlatform(ctx context.Context) (*model.ComputePlatform, error) @@ -908,7 +908,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Mutation.DeleteAction(childComplexity, args["id"].(string)), true + return e.complexity.Mutation.DeleteAction(childComplexity, args["id"].(string), args["actionType"].(string)), true case "Mutation.persistK8sNamespace": if e.complexity.Mutation.PersistK8sNamespace == nil { @@ -1339,6 +1339,15 @@ func (ec *executionContext) field_Mutation_deleteAction_args(ctx context.Context } } args["id"] = arg0 + var arg1 string + if tmp, ok := rawArgs["actionType"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("actionType")) + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["actionType"] = arg1 return args, nil } @@ -5790,7 +5799,7 @@ func (ec *executionContext) _Mutation_deleteAction(ctx context.Context, field gr }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Mutation().DeleteAction(rctx, fc.Args["id"].(string)) + return ec.resolvers.Mutation().DeleteAction(rctx, fc.Args["id"].(string), fc.Args["actionType"].(string)) }) if err != nil { ec.Error(ctx, err) diff --git a/frontend/graph/schema.graphqls b/frontend/graph/schema.graphqls index 591a40011..83a1d71be 100644 --- a/frontend/graph/schema.graphqls +++ b/frontend/graph/schema.graphqls @@ -311,5 +311,5 @@ type Mutation { createAction(action: ActionInput!): Action! updateAction(id: ID!, action: ActionInput!): Action! - deleteAction(id: ID!): Boolean! + deleteAction(id: ID!, actionType: String!): Boolean! } diff --git a/frontend/graph/schema.resolvers.go b/frontend/graph/schema.resolvers.go index 553cbbf33..aa8415bea 100644 --- a/frontend/graph/schema.resolvers.go +++ b/frontend/graph/schema.resolvers.go @@ -600,8 +600,24 @@ func (r *mutationResolver) UpdateAction(ctx context.Context, id string, action m } // DeleteAction is the resolver for the deleteAction field. -func (r *mutationResolver) DeleteAction(ctx context.Context, id string) (bool, error) { - panic(fmt.Errorf("not implemented: DeleteAction - deleteAction")) +func (r *mutationResolver) DeleteAction(ctx context.Context, id string, actionType string) (bool, error) { + + switch actionType { + case actionservices.ActionTypeAddClusterInfo: + err := actionservices.DeleteAddClusterInfo(ctx, id) + if err != nil { + return false, fmt.Errorf("failed to delete AddClusterInfo: %v", err) + } + + case actionservices.ActionTypeDeleteAttribute: + // Handle other action types... + + default: + return false, fmt.Errorf("unsupported action type: %s", actionType) + } + + // Return true if the deletion was successful + return true, nil } // ComputePlatform is the resolver for the computePlatform field. diff --git a/frontend/services/actions/addclusterinfo.go b/frontend/services/actions/addclusterinfo.go index aefc359ef..57f324883 100644 --- a/frontend/services/actions/addclusterinfo.go +++ b/frontend/services/actions/addclusterinfo.go @@ -10,6 +10,7 @@ import ( "github.com/odigos-io/odigos/frontend/graph/model" "github.com/odigos-io/odigos/frontend/kube" "github.com/odigos-io/odigos/frontend/services" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -144,3 +145,18 @@ func UpdateAddClusterInfo(ctx context.Context, id string, action model.ActionInp return response, nil } + +func DeleteAddClusterInfo(ctx context.Context, id string) error { + odigosns := consts.DefaultOdigosNamespace + + // Delete the action by its ID from Kubernetes + err := kube.DefaultClient.ActionsClient.AddClusterInfos(odigosns).Delete(ctx, id, metav1.DeleteOptions{}) + if err != nil { + if apierrors.IsNotFound(err) { + return fmt.Errorf("AddClusterInfo action with ID %s not found", id) + } + return fmt.Errorf("failed to delete AddClusterInfo action: %v", err) + } + + return nil +}