feat: add delete functionality for namespace resources
This commit is contained in:
@@ -927,3 +927,33 @@ func K8sConfigMapDelete(ctx context.Context, db *gorm.DB, store store.Store) fib
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func K8sNamespaceDelete(ctx context.Context, db *gorm.DB, store store.Store) fiber.Handler {
|
||||
return func(c fiber.Ctx) error {
|
||||
var req struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(c.Body(), &req); err != nil {
|
||||
return resp.R400(c, "", nil, err)
|
||||
}
|
||||
|
||||
if req.Name == "" {
|
||||
return resp.R400(c, "", nil, fmt.Errorf("name is required"))
|
||||
}
|
||||
|
||||
clientset, err := getK8sClient(db)
|
||||
if err != nil {
|
||||
return resp.R500(c, "", nil, err)
|
||||
}
|
||||
|
||||
err = clientset.CoreV1().Namespaces().Delete(c.Context(), req.Name, metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
return resp.R500(c, "", nil, fmt.Errorf("failed to delete namespace: %w", err))
|
||||
}
|
||||
|
||||
return resp.R200(c, map[string]any{
|
||||
"name": req.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user