-
Notifications
You must be signed in to change notification settings - Fork 86
deletes pipelines on space removal #2352
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package controller | ||
|
||
import ( | ||
"fmt" | ||
"github.com/fabric8-services/fabric8-wit/app" | ||
"github.com/fabric8-services/fabric8-wit/configuration" | ||
"github.com/fabric8-services/fabric8-wit/errors" | ||
"github.com/fabric8-services/fabric8-wit/jsonapi" | ||
"github.com/fabric8-services/fabric8-wit/log" | ||
"github.com/goadesign/goa" | ||
errs "github.com/pkg/errors" | ||
"github.com/satori/go.uuid" | ||
) | ||
|
||
// pipeline implements the pipeline resource. | ||
type PipelinesController struct { | ||
*goa.Controller | ||
Config *configuration.Registry | ||
ClientGetter | ||
} | ||
|
||
func NewPipelineController(service *goa.Service, config *configuration.Registry) *PipelinesController { | ||
return &PipelinesController{ | ||
Controller: service.NewController("PipelinesController"), | ||
Config: config, | ||
ClientGetter: &defaultClientGetter{ | ||
config: config, | ||
}, | ||
} | ||
} | ||
|
||
// Delete a pipelines from given space | ||
func (c *PipelinesController) Delete(ctx *app.DeletePipelinesContext) error { | ||
|
||
osioClient, err := c.GetAndCheckOSIOClient(ctx) | ||
if err != nil { | ||
return jsonapi.JSONErrorResponse(ctx, err) | ||
} | ||
|
||
k8sSpace, err := osioClient.GetNamespaceByType(ctx, nil, "user") | ||
if err != nil { | ||
return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "unable to retrieve 'user' namespace")) | ||
} | ||
if k8sSpace == nil { | ||
return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("namespace", "user")) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be 500 rather 404 ?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if resource not found then it should be 404 right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My thinking is like .. user ask to delete_space .. if space not found then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hrishin I am fine with either |
||
|
||
osc, err := c.GetOSClient(ctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For OSIO client, it's osioClient.. While for OS client, it's osc.. we can have consistency between these names here :-) |
||
if err != nil { | ||
return jsonapi.JSONErrorResponse(ctx, err) | ||
} | ||
|
||
userNS := *k8sSpace.Name | ||
spacename, err := c.getSpaceNameFromSpaceID(ctx.SpaceID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can reuse |
||
if err != nil { | ||
return jsonapi.JSONErrorResponse(ctx, err) | ||
} | ||
|
||
resp, err := osc.DeleteBuildConfig(userNS, map[string]string{"space": *spacename}) | ||
if err != nil { | ||
log.Error(ctx, map[string]interface{}{ | ||
"err": err, | ||
"space_name": *spacename, | ||
}, "error occurred while deleting pipeline") | ||
return jsonapi.JSONErrorResponse(ctx, err) | ||
} | ||
|
||
log.Info(ctx, map[string]interface{}{"response": resp}, "deleted pipelines :") | ||
|
||
return ctx.OK([]byte{}) | ||
} | ||
|
||
func (c *PipelinesController) getSpaceNameFromSpaceID(spaceID uuid.UUID) (*string, error) { | ||
// use WIT API to convert Space UUID to Space name | ||
osioclient, err := c.GetAndCheckOSIOClient(c.Context) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
osioSpace, err := osioclient.GetSpaceByID(c.Context, spaceID) | ||
fmt.Printf("spcae %#v", osioSpace) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plz remove/replace |
||
|
||
if err != nil { | ||
return nil, errs.Wrapf(err, "unable to convert space UUID %s to space name", spaceID) | ||
} | ||
|
||
if osioSpace == nil || osioSpace.Attributes == nil || osioSpace.Attributes.Name == nil { | ||
return nil, errs.Errorf("space UUID %s is not valid a space", spaceID) | ||
} | ||
|
||
return osioSpace.Attributes.Name, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz add tests for
Delete()
.