add delete namespace with route deleteAdmiraltySession
This commit is contained in:
parent
c0b8ac1eee
commit
cb23289097
@ -106,6 +106,12 @@ func (c *AdmiraltyController) GetOneTarget() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res, err := serv.GetTargets(c.Ctx.Request.Context())
|
res, err := serv.GetTargets(c.Ctx.Request.Context())
|
||||||
|
if err != nil {
|
||||||
|
c.Ctx.Output.SetStatus(500)
|
||||||
|
c.ServeJSON()
|
||||||
|
c.Data["json"] = map[string]string{"error": err.Error()}
|
||||||
|
return
|
||||||
|
}
|
||||||
id = "target-" + id
|
id = "target-" + id
|
||||||
found := slices.Contains(res, id)
|
found := slices.Contains(res, id)
|
||||||
if !found {
|
if !found {
|
||||||
@ -117,6 +123,34 @@ func (c *AdmiraltyController) GetOneTarget() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title DeleteAdmiraltySession
|
||||||
|
// @Description find one Admiralty Target
|
||||||
|
// @Param execution path string true "the name of the target to get"
|
||||||
|
// @Success 200
|
||||||
|
// @router /targets/:execution [delete]
|
||||||
|
func (c *AdmiraltyController) DeleteAdmiraltySession() {
|
||||||
|
id := c.Ctx.Input.Param(":execution")
|
||||||
|
serv, err := infrastructure.NewService()
|
||||||
|
if err != nil {
|
||||||
|
// change code to 500
|
||||||
|
c.Ctx.Output.SetStatus(500)
|
||||||
|
c.ServeJSON()
|
||||||
|
c.Data["json"] = map[string]string{"error": err.Error()}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = serv.DeleteNamespace(c.Ctx.Request.Context(), id)
|
||||||
|
if err != nil {
|
||||||
|
c.Ctx.Output.SetStatus(500)
|
||||||
|
c.ServeJSON()
|
||||||
|
c.Data["json"] = map[string]string{"error": err.Error()}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Data["json"] = id
|
||||||
|
c.ServeJSON()
|
||||||
|
}
|
||||||
|
|
||||||
// @Title CreateAdmiraltySource
|
// @Title CreateAdmiraltySource
|
||||||
// @Description Create an Admiralty Source on remote cluster
|
// @Description Create an Admiralty Source on remote cluster
|
||||||
// @Param execution path string true "execution id of the workflow"
|
// @Param execution path string true "execution id of the workflow"
|
||||||
@ -155,7 +189,12 @@ func (c *AdmiraltyController) CreateAdmiraltySource() {
|
|||||||
// TODO : Return a description of the created resource
|
// TODO : Return a description of the created resource
|
||||||
var respData map[string]interface{}
|
var respData map[string]interface{}
|
||||||
err = json.Unmarshal(res, &respData)
|
err = json.Unmarshal(res, &respData)
|
||||||
|
if err != nil {
|
||||||
|
c.Ctx.Output.SetStatus(500)
|
||||||
|
c.ServeJSON()
|
||||||
|
c.Data["json"] = map[string]string{"error": err.Error()}
|
||||||
|
return
|
||||||
|
}
|
||||||
c.Ctx.Output.SetStatus(201)
|
c.Ctx.Output.SetStatus(201)
|
||||||
c.Data["json"] = respData
|
c.Data["json"] = respData
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
|
@ -335,6 +335,5 @@ func (o *BookingController) createNamespace(ns string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("ROLLLLLE BIND")
|
|
||||||
return serv.CreateRoleBinding(o.Ctx.Request.Context(), ns, "argo-role-binding", role)
|
return serv.CreateRoleBinding(o.Ctx.Request.Context(), ns, "argo-role-binding", role)
|
||||||
}
|
}
|
||||||
|
@ -197,10 +197,33 @@ func (k *KubernetesService) CreateRoleBinding(ctx context.Context, ns string, ro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (k *KubernetesService) DeleteNamespace(ctx context.Context, ns string) error {
|
func (k *KubernetesService) DeleteNamespace(ctx context.Context, ns string) error {
|
||||||
|
targetGVR := schema.GroupVersionResource{
|
||||||
|
Group: "multicluster.admiralty.io",
|
||||||
|
Version: "v1alpha1",
|
||||||
|
Resource: "targets",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the Target
|
||||||
|
dyn, err := NewDynamicClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = dyn.Resource(targetGVR).Namespace(ns).Delete(context.TODO(), "target-"+ns, metav1.DeleteOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = k.Set.CoreV1().ServiceAccounts(ns).Delete(context.TODO(), "sa-"+ns, metav1.DeleteOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
// Delete the namespace
|
// Delete the namespace
|
||||||
if err := k.Set.CoreV1().Namespaces().Delete(ctx, ns, metav1.DeleteOptions{}); err != nil {
|
if err := k.Set.CoreV1().Namespaces().Delete(ctx, ns, metav1.DeleteOptions{}); err != nil {
|
||||||
return errors.New("Error deleting namespace: " + err.Error())
|
return errors.New("Error deleting namespace: " + err.Error())
|
||||||
}
|
}
|
||||||
|
LockKill.Lock()
|
||||||
|
Kill = append(Kill, ns)
|
||||||
|
LockKill.Unlock()
|
||||||
fmt.Println("Namespace deleted successfully!")
|
fmt.Println("Namespace deleted successfully!")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -80,24 +81,19 @@ func (p *PrometheusService) queryPrometheus(promURL string, expr string, namespa
|
|||||||
return metric
|
return metric
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PrometheusService) Call(bookingID string) (*booking.Booking, map[string]models.MetricsSnapshot) {
|
func (p *PrometheusService) Call(book *booking.Booking) (*booking.Booking, map[string]models.MetricsSnapshot) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
metrics := map[string]models.MetricsSnapshot{}
|
metrics := map[string]models.MetricsSnapshot{}
|
||||||
// get all booking... from executions_id == namespace typed datacenter.
|
// get all booking... from executions_id == namespace typed datacenter.
|
||||||
bAccess := oclib.NewRequest(oclib.LibDataEnum(oclib.BOOKING), "", "", []string{}, nil)
|
|
||||||
book := bAccess.LoadOne(bookingID)
|
|
||||||
if book.Err != "" {
|
|
||||||
fmt.Errorf("stop because of empty : %s", book.Err)
|
|
||||||
return nil, metrics
|
|
||||||
}
|
|
||||||
cUAccess := oclib.NewRequest(oclib.LibDataEnum(oclib.COMPUTE_UNITS), "", "", []string{}, nil)
|
cUAccess := oclib.NewRequest(oclib.LibDataEnum(oclib.COMPUTE_UNITS), "", "", []string{}, nil)
|
||||||
cRAccess := oclib.NewRequest(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE), "", "", []string{}, nil)
|
cRAccess := oclib.NewRequest(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE), "", "", []string{}, nil)
|
||||||
|
|
||||||
rr := cRAccess.LoadOne(book.Data.(*booking.Booking).ResourceID)
|
rr := cRAccess.LoadOne(book.ResourceID)
|
||||||
if rr.Err != "" {
|
if rr.Err != "" {
|
||||||
fmt.Errorf("can't proceed because of unfound resource %s : %s", book.Data.(*booking.Booking).ResourceID, rr.Err)
|
fmt.Errorf("can't proceed because of unfound resource %s : %s", book.ResourceID, rr.Err)
|
||||||
return book.Data.(*booking.Booking), metrics
|
return book, metrics
|
||||||
}
|
}
|
||||||
computeRes := rr.ToComputeResource()
|
computeRes := rr.ToComputeResource()
|
||||||
for _, instance := range computeRes.Instances {
|
for _, instance := range computeRes.Instances {
|
||||||
@ -120,7 +116,7 @@ func (p *PrometheusService) Call(bookingID string) (*booking.Booking, map[string
|
|||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for _, expr := range queriesMetrics {
|
for _, expr := range queriesMetrics {
|
||||||
snapshot.Metrics = append(snapshot.Metrics,
|
snapshot.Metrics = append(snapshot.Metrics,
|
||||||
p.queryPrometheus(r.(*compute_units.ComputeUnits).MonitorPath, expr, book.Data.(*booking.Booking).ExecutionsID))
|
p.queryPrometheus(r.(*compute_units.ComputeUnits).MonitorPath, expr, book.ExecutionsID))
|
||||||
}
|
}
|
||||||
metrics[instance.Name] = snapshot
|
metrics[instance.Name] = snapshot
|
||||||
}()
|
}()
|
||||||
@ -128,9 +124,11 @@ func (p *PrometheusService) Call(bookingID string) (*booking.Booking, map[string
|
|||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
return book.Data.(*booking.Booking), metrics
|
return book, metrics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var LockKill = &sync.Mutex{}
|
||||||
|
|
||||||
func (p *PrometheusService) Stream(bookingID string, end *time.Time, interval time.Duration, flusher *http.Flusher, encoder *json.Encoder) {
|
func (p *PrometheusService) Stream(bookingID string, end *time.Time, interval time.Duration, flusher *http.Flusher, encoder *json.Encoder) {
|
||||||
e := time.Now().UTC().Add(time.Hour * 1)
|
e := time.Now().UTC().Add(time.Hour * 1)
|
||||||
if end != nil {
|
if end != nil {
|
||||||
@ -139,9 +137,27 @@ func (p *PrometheusService) Stream(bookingID string, end *time.Time, interval ti
|
|||||||
max := 100
|
max := 100
|
||||||
bookIDS := []string{}
|
bookIDS := []string{}
|
||||||
mets := map[string][]models.MetricsSnapshot{}
|
mets := map[string][]models.MetricsSnapshot{}
|
||||||
|
bAccess := oclib.NewRequest(oclib.LibDataEnum(oclib.BOOKING), "", "", []string{}, nil)
|
||||||
|
book := bAccess.LoadOne(bookingID)
|
||||||
|
if book.Err != "" {
|
||||||
|
fmt.Errorf("stop because of empty : %s", book.Err)
|
||||||
|
}
|
||||||
for time.Now().Before(e) {
|
for time.Now().Before(e) {
|
||||||
|
if slices.Contains(Kill, book.Data.(*booking.Booking).ExecutionsID) {
|
||||||
|
newKill := []string{}
|
||||||
|
for _, k := range Kill {
|
||||||
|
if k != book.Data.(*booking.Booking).ExecutionsID {
|
||||||
|
newKill = append(newKill, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LockKill.Lock()
|
||||||
|
Kill = newKill
|
||||||
|
LockKill.Unlock()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
book, metrics := p.Call(bookingID)
|
book, metrics := p.Call(book.Data.(*booking.Booking))
|
||||||
for k, v := range metrics {
|
for k, v := range metrics {
|
||||||
if me, ok := mets[k]; !ok {
|
if me, ok := mets[k]; !ok {
|
||||||
mets[k] = []models.MetricsSnapshot{v}
|
mets[k] = []models.MetricsSnapshot{v}
|
||||||
@ -178,4 +194,6 @@ func (p *PrometheusService) Stream(bookingID string, end *time.Time, interval ti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Kill = []string{}
|
||||||
|
|
||||||
// should add a datacenter... under juridiction... of opencloud...
|
// should add a datacenter... under juridiction... of opencloud...
|
||||||
|
Loading…
Reference in New Issue
Block a user