-
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?
Conversation
97c79c9
to
165ab7a
Compare
force pushed by mistake :/ |
controller/space.go
Outdated
|
||
//delete pipelines from the space | ||
spaceLabel := space.Data.Attributes.Name | ||
log.Debug(ctx, map[string]interface{}{"label": spaceLabel}, "deleting pipelines in") |
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.
seems error msg is not complete ??
|
||
if err != nil { | ||
log.Error(ctx, nil, fmt.Sprintf("error occurred while deleting pipelines from space : %s", spaceLabel)) | ||
} |
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.
we need to return error here .. right ??
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.
Initially, I assumed it a failure of this call should not fail delete space considering .
I will fix this.
|
||
// The deployments API communicates with the rest of WIT via the stnadard WIT API. | ||
// This environment variable is used for local development of the deployments API, to point ot a remote WIT. | ||
witURLStr := os.Getenv("FABRIC8_WIT_API_URL") |
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.
Shouldn't read directly from env, should come from the viper config object ( configuration/configuration.go )
// ClientGetter creates an instances of clients used by this controller | ||
type ClientGetter interface { | ||
GetKubeClient(ctx context.Context) (kubernetes.KubeClientInterface, error) | ||
GetAndCheckOSIOClient(ctx context.Context) (OpenshiftIOClient, error) |
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.
Should we really be using osio
further in our identifiers given that there's gonna be changes :)
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.
:)
) | ||
|
||
// ClientGetter creates an instances of clients used by this controller | ||
type ClientGetter interface { |
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.
- Could you use a more meaningful name please?
- This is not something that should be part of the controller layer. This should be a part of the service layer. Could you maybe put in a different new/existing package?
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.
Yes, we tried to decouple it from the controller layer but stumbled into the extensive refactoring. Though it's better to do progressive refactoring.
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.
GetAndCheckOSIOClient
is tightly coupled to the controller layer.
"FABRIC8_WIT_API_URL": witURLStr, | ||
"err": err, | ||
}, "cannot parse FABRIC8_WIT_API_URL: %s", witURLStr) | ||
return nil, errs.Wrapf(err, "cannot parse FABRIC8_WIT_API_URL: %s", witURLStr) |
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.
Could you please use a more specific error from the errors
package. That way, jsonapi.JSONErrorResponse(ctx, err)
will convert it into the right status code.
Btw, in follow-up PRs, do you plan to remove 'apps' from -stage and -run as well while deleting a space :) ? |
Thank you 👍 @nurali-techie @sbose78 for initial review.
Its already taken care by existing code https://github.com/fabric8-services/fabric8-wit/blob/master/controller/space.go#L359 |
pipelines doesnt get deleted while removing a space which leaves dangling pipelines in OpenShift. This patch deletes the pipelines while removing a space Patch adds - REST API to delete pipeline by space label - Test cases for delete pipeline(buildconfig) function - Delete BuildConfig API in OpenShift client - Test cases for delete BuildConfig API - Refactors kubernetes_client to get client objects - Fixes delete OpenShift resources tests Fixes -openshiftio/openshift.io#3802
- updates an API to delete by space id - updates an API URL - fixes test cases
3e1585a
to
0b1e507
Compare
Codecov Report
@@ Coverage Diff @@
## master #2352 +/- ##
==========================================
- Coverage 70.18% 69.86% -0.32%
==========================================
Files 171 173 +2
Lines 16919 17056 +137
==========================================
+ Hits 11874 11916 +42
- Misses 3893 3980 +87
- Partials 1152 1160 +8
Continue to review full report at Codecov.
|
} | ||
if k8sSpace == nil { | ||
return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("namespace", "user")) | ||
} |
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.
should be 500 rather 404 ??
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.
if resource not found then it should be 404 right?
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.
My thinking is like .. user ask to delete_space .. if space not found then 404
is fine but here it's namespace
and if that not found then returning 404
gives the impression that space_not_found. so to me namesapce_not_found it's internal_error when one is trying to deleting_space. This is feedback comment.
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.
@hrishin I am fine with either 404
or 500
.
return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("namespace", "user")) | ||
} | ||
|
||
osc, err := c.GetOSClient(ctx) |
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.
For OSIO client, it's osioClient.. While for OS client, it's osc.. we can have consistency between these names here :-)
} | ||
|
||
userNS := *k8sSpace.Name | ||
spacename, err := c.getSpaceNameFromSpaceID(ctx.SpaceID) |
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.
we can reuse osioClient
by passing it to getSpaceNameFromSpaceID()
.
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
not sure c.Context
will do, but it's always better to use request context (here it's DeletePipelinesContext
)
} | ||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
plz remove/replace fmt
; check space
text.
} | ||
|
||
// Delete a pipelines from given space | ||
func (c *PipelinesController) Delete(ctx *app.DeletePipelinesContext) error { |
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()
.
if len(errorsList) != 0 { | ||
var errString string | ||
for _, err = range errorsList { | ||
errString += fmt.Sprintf("%s\n", err) | ||
} | ||
return errors.NewInternalErrorFromString(errString) | ||
} | ||
|
||
//delete pipelines from the space |
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.
I guess it's better to extract delete_pipleline logic out from deleteOpenShiftResource()
..
.. because it will make delete_pipeline test clean test_link. These tests has nothing to do with deployment.
It can be refactor like:
deleteOpenShiftResource() {
deleteDeployments()
deletePipelines()
}
deleteDeployments() {
}
deletePipelines() {
}
require.NoError(t, err) | ||
t.Run("with delete pipeline success", func(t *testing.T) { | ||
// given | ||
r, err := recorder.New("../test/data/deployments/deployments_delete_space.ok") |
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.
it's better to have separate dir for pipeline rather using deployments
dir to keep test files.
} | ||
|
||
// GetOSClient creates a OpenShift client for the appropriate cluster assigned to the current user | ||
func (g *defaultClientGetter) GetOSClient(ctx context.Context) (kubernetes.OpenShiftRESTAPI, error) { |
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.
impl of GetOSClient()
share lot of common impl from GetKubeClient()
above. Can we refactor and have one common method to do common stuff.
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.
@hrishin it would be good if you can do some refactoring and add tests.
@hrishin @michaelkleinhenz what is the next step with this PR? |
@ppitonak will update this PR soon, got sidetrack from this work. Thanks, @michaelkleinhenz for heads up, will sync with @kwk. |
Pipelines don't get deleted while removing a space
which leaves dangling pipelines in OpenShift.
This patch deletes the pipelines while removing a
space
Patch adds
Fixes
-openshiftio/openshift.io#3802