Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

deletes pipelines on space removal #2352

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hrishin
Copy link
Member

@hrishin hrishin commented Nov 21, 2018

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

  • REST API to delete pipeline by space label
  • Test cases for delete pipeline(buildconfig) method
  • 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

@hrishin
Copy link
Member Author

hrishin commented Nov 21, 2018

force pushed by mistake :/


//delete pipelines from the space
spaceLabel := space.Data.Attributes.Name
log.Debug(ctx, map[string]interface{}{"label": spaceLabel}, "deleting pipelines in")
Copy link
Contributor

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))
}
Copy link
Contributor

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 ??

Copy link
Member Author

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.

design/pipelines.go Outdated Show resolved Hide resolved
controller/pipelines.go Outdated Show resolved Hide resolved

// 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")
Copy link
Member

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)
Copy link
Member

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 :)

Copy link
Member Author

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Could you use a more meaningful name please?
  2. 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?

Copy link
Member Author

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.

Copy link
Member Author

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)
Copy link
Member

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.

@sbose78
Copy link
Member

sbose78 commented Nov 21, 2018

Btw, in follow-up PRs, do you plan to remove 'apps' from -stage and -run as well while deleting a space :) ?

@hrishin
Copy link
Member Author

hrishin commented Nov 21, 2018

Thank you 👍 @nurali-techie @sbose78 for initial review.

Btw, in follow-up PRs, do you plan to remove 'apps' from -stage and -run as well while deleting a space

Its already taken care by existing code https://github.com/fabric8-services/fabric8-wit/blob/master/controller/space.go#L359
Is that what you mean @sbose78 ?

controller/space.go Outdated Show resolved Hide resolved
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
@codecov
Copy link

codecov bot commented Nov 29, 2018

Codecov Report

Merging #2352 into master will decrease coverage by 0.31%.
The diff coverage is 20%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
controller/deployments.go 70.2% <ø> (+14.35%) ⬆️
controller/platform_clients.go 0% <0%> (ø)
controller/pipelines.go 0% <0%> (ø)
controller/space.go 69.88% <100%> (+0.23%) ⬆️
kubernetes/deployments_kubeclient.go 71.81% <66.66%> (-0.2%) ⬇️
workitem/workitem_repository.go 68.02% <0%> (+0.22%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d7fb836...0b1e507. Read the comment docs.

}
if k8sSpace == nil {
return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("namespace", "user"))
}
Copy link
Contributor

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 ??

Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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 {
Copy link
Contributor

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
Copy link
Contributor

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")
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor

@nurali-techie nurali-techie left a 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.

@ppitonak
Copy link
Contributor

ppitonak commented Jan 4, 2019

@hrishin @michaelkleinhenz what is the next step with this PR?

@michaelkleinhenz
Copy link
Collaborator

@ppitonak let's coordinate with @kwk on Monday. He was also working on delete spaces.

@hrishin
Copy link
Member Author

hrishin commented Jan 4, 2019

@ppitonak will update this PR soon, got sidetrack from this work.

Thanks, @michaelkleinhenz for heads up, will sync with @kwk.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants