Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kompose will keep trying its job #477

Merged
merged 1 commit into from
Apr 3, 2017

Conversation

surajnarwade
Copy link
Contributor

fixes #270

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 8, 2017
@surajnarwade
Copy link
Contributor Author

cc @surajssd @containscafeine @kadel

@@ -640,9 +640,10 @@ func (k *Kubernetes) Undeploy(komposeObject kobject.KomposeObject, opt kobject.C
//FIXME: gracePeriod is nil
err = rpDeployment.Stop(namespace, t.Name, TIMEOUT*time.Second, nil)
if err != nil {
return err
Copy link
Member

@cdrage cdrage Mar 9, 2017

Choose a reason for hiding this comment

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

These REALLY shouldn't be removed... If it errors out during deployment Kompose should return an err. It's not good Go practice to simply log.Error(err).

If we're retrying for a job.... this should be more complicated and use a Go channel (maybe) + retry maybe 3 times + timeout then return err.

Thoughts @kadel ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cdrage , if we returned the error, kompose will not be able to keep doing its job (as discussed in issue, its there only in the case of kompose down)

Copy link
Member

Choose a reason for hiding this comment

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

Whole point of the issue is that we error out (return error) and that is not good. We need at least try delete the rest of the objects. Error in deleting one of the objects shouldn't be show stopper for deleting the rest.

On the other hand, Undeploy function should probably return error if we can't be sure that all the objects were deleted. Maybe those error should be aggregated so it can be returned at the end.

@containscafeine was looking into error handling lately. He might know what would be best here.

Copy link
Contributor

@concaf concaf Mar 13, 2017

Choose a reason for hiding this comment

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

How about we defer the return err statements? This way, the errors will get returned at the end of Undeploy() and by that time the other resources would also have been deleted?

Copy link
Member

Choose a reason for hiding this comment

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

I don't know if defer is going to help here.
Maybe just collecting all the errors to array and then returning it should be enough.

Copy link
Member

Choose a reason for hiding this comment

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

Just create a list of errors and then return that maybe and the caller of undeploy should print it in right way or whatever!

@cdrage
Copy link
Member

cdrage commented Mar 10, 2017

Please use git commit --amend as well to update your git message so it's more descriptive!

@surajssd
Copy link
Member

Anyway the code this PR is editing is gonna go away because @procrypt is working on new approach of deleting things! #483

@kadel
Copy link
Member

kadel commented Mar 16, 2017

It is not going to go away. This logic will be still needed, #483 is not solving this problem.
But it will create lot of annoying conflicts :-(

@surajnarwade
Copy link
Contributor Author

cc @kadel @surajssd @cdrage

}
}
}
}
return nil
return ErrorList
Copy link
Member

Choose a reason for hiding this comment

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

This seems a bit unconventional for Go, why an ErrorList? We should be returning an error when it actually happens and not continue throughout the code, should this be nil? @kadel

Honestly, it seems awkward that in order to "keep trying" for Kompose, it means going against Go conventions and continuing through the code brute-force. Having logic throughout the code would be more viable instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cdrage , as @kadel said, create list of errors and return it after deleting all components.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, shouldn't we use https://golang.org/pkg/go/scanner/#ErrorList instead? @kadel

Copy link
Member

Choose a reason for hiding this comment

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

This seems a bit unconventional for Go, why an ErrorList? We should be returning an error when it actually happens and not continue throughout the code, should this be nil? @kadel

I don't think that this is against Go conventions. It quite common to aggregate errors into slice. If you look at Kubernetes code base you can see it there. Only difference is that they are doing it little bit smarter. They don't return slice of errors, but Aggregate. Aggregate is special type that implements error interface and can contain multiple errors. (see https://github.com/kubernetes/kubernetes/blob/55bee3ad21f025b1416a4e1f10de753f484b66d3/staging/src/k8s.io/apimachinery/pkg/util/errors/errors.go#L36).
I don't think we need to do that like that right now, just returning []error should be enough.

Something went wrong, even if we tried to continue but we need to inform user that something wasn't deleted.

This is simplification, because ideally deletion should happen in parallel. Every delete should have run its own goroutine. But I don't think we should worry about that right now. Doing it serially on-by-one is ok for now.

Copy link
Member

Choose a reason for hiding this comment

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

This makes sense. Instead of Go routines (maybe implement them later if API calls start becoming lengthy), just iterating through each-step would be the best-case-scenario. I totally agree!

@kadel
Copy link
Member

kadel commented Mar 28, 2017

Okay, shouldn't we use https://golang.org/pkg/go/scanner/#ErrorList instead? @kadel

It looks like that ErrorList is specially made for scanner package.

@@ -691,17 +691,19 @@ func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.Con
}

// Undeploy deletes deployed objects from Kubernetes cluster
func (k *Kubernetes) Undeploy(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) error {
func (k *Kubernetes) Undeploy(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) []error {
var ErrorList []error
Copy link
Member

Choose a reason for hiding this comment

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

There shouldn't be capital 'E'. it should be lower-case.
Uppercase in go means public variable, we don't want that here.

@@ -495,20 +495,22 @@ func (o *OpenShift) Deploy(komposeObject kobject.KomposeObject, opt kobject.Conv
}

//Undeploy removes deployed artifacts from OpenShift cluster
func (o *OpenShift) Undeploy(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) error {
func (o *OpenShift) Undeploy(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) []error {
var ErrorList []error
Copy link
Member

Choose a reason for hiding this comment

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

same here. this should be errorList

Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

Other than the changes requests (removing comments), LGTM.

//Convert komposeObject
objects, err := k.Transform(komposeObject, opt)

if err != nil {
return errors.Wrap(err, "k.Transform failed")
errorList = append(errorList, err)
//return errors.Wrap(err, "k.Transform failed")
Copy link
Member

Choose a reason for hiding this comment

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

need to remove this comment

//Convert komposeObject
objects, err := o.Transform(komposeObject, opt)

if err != nil {
return errors.Wrap(err, "o.Transform failed")
errorList = append(errorList, err)
//return errors.Wrap(err, "o.Transform failed")
Copy link
Member

Choose a reason for hiding this comment

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

this needs to be removed

fixes kubernetes#270

all errors in undeploy method(both kubernetes and openshift) are appended in a slice of errors,
and then it will be returned after successful deletion of all components.
@surajnarwade
Copy link
Contributor Author

@cdrage done with changes

@cdrage
Copy link
Member

cdrage commented Apr 3, 2017

LGTM

@cdrage cdrage merged commit 14a5ed3 into kubernetes:master Apr 3, 2017
@kadel
Copy link
Member

kadel commented Apr 3, 2017

I just found that there is a BIG mistake in there.

If it can't connect to cluster it panics.

Problem is that we continue after every error.
There should be return after some errors, and after every error in switch should be break

@cdrage
Copy link
Member

cdrage commented Apr 3, 2017

@kadel Yeah. I thought we were brute-forcing the force down since we're iterating right through each-one of them.

I've opened up a PR to revert this so we can at least push a release today.

@kadel
Copy link
Member

kadel commented Apr 3, 2017

yeh, that was a bit too much brute-forcing :-)
For example we can't continue and call Stop if client creation failed. In that case it should continue and try to create client again for next object.

cdrage added a commit that referenced this pull request Apr 10, 2017
new take on "Kompose will keep trying its job #477"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. rebase needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make kompose keep trying its job
6 participants