-
Notifications
You must be signed in to change notification settings - Fork 48
Add support for lokoctl component delete
#268
Conversation
pkg/components/util/delete.go
Outdated
} | ||
|
||
// AggregateErrors conflates multiple errors stored in a string form and returns a single error. | ||
func AggregateErrors(errs []string) 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.
Why not use hcl.Diagnostics
instead?
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 think hcl.Diagnostics is not very helpful to the end user because it does not list all the errors and oly gives output as follows:
FATA[0016] <nil>: uninstall: Release not loaded: openebs-operator: release: not found; , and 4 other diagnostic(s) args="[]" command="lokoctl component delete"
This is not very helpful. As a user I want to know all the errors that have occurred.
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.
@surajssd you need to iterate over it and print each one in desired format to make it usable for the 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.
Then the API is not very user friendly. Because this function AggregateErrors
clubs all the errors one on each line and the output looks like following:
$ lokoctl component delete --delete-namespace
Do you want to delete components: "openebs-operator,openebs-storage-class,prometheus-operator,contour,metallb,cert-manager,httpbin"? [type "yes" to continue]:
yes
Deleting component 'openebs-operator'...
Deleting component 'openebs-storage-class'...
Deleting component 'prometheus-operator'...
Deleting component 'contour'...
Deleting component 'metallb'...
Deleting component 'cert-manager'...
Deleting component 'httpbin'...
FATA[0008] uninstall: Release not loaded: openebs-operator: release: not found
uninstall: Release not loaded: openebs-storage-class: release: not found
uninstall: Release not loaded: prometheus-operator: release: not found
namespaces "monitoring" not found
uninstall: Release not loaded: contour: release: not found
namespaces "projectcontour" not found
uninstall: Release not loaded: metallb: release: not found
namespaces "metallb-system" not found
uninstall: Release not loaded: cert-manager: release: not found
namespaces "cert-manager" not found
uninstall: Release not loaded: httpbin: release: not found
namespaces "httpbin" not found args="[]" command="lokoctl component delete"
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.
¯\(ツ)/¯
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 think we don't need this function - see #268 (comment).
6395159
to
ae85bf0
Compare
@surajssd we will need to update the cli documentation. |
Another instance of
But does not fail locally. My version of the tool is |
2bc4e8b
to
f2db453
Compare
On CI we use 1.13.8, as 1.14.0 has issues with memory usage.
I was hitting the same, but I'm running 1.14.0 locally too. @surajssd what about running |
@surajssd I pulled some extra reviewers, as I'm not convinced with |
f2db453
to
4658ccc
Compare
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 2 cent.
7932019
to
67e6cf7
Compare
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.
Some comments.
67e6cf7
to
5aa9a9d
Compare
5aa9a9d
to
e7842e2
Compare
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 would also be good to add some tests for uninstalling the components, as we have no unit tests for this either.
contextLogger.Fatal(diags) | ||
} | ||
|
||
componentsToDelete := make([]string, len(args)) |
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.
Why do we need to use make
and copy
here? Why can't we just do:
d := args
if len(d) == 0 {
for _, c := range lokoCfg.RootConfig.Components {
d = append(d, c.Name)
}
}
I think this code is much simpler and less confusing for people starting with Go.
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.
IMO it idiomatic to make
and copy
. Current code is just 2 lines.
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.
And for someone starting with golang they will learn new things, won't they?
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 just think my approach is simpler and is something you usually see in Go code, so I'm asking, if there is some specific reason you wrote it this way?
cli/cmd/component-delete.go
Outdated
|
||
resp, err := uninstall.Run(name) | ||
// ignore the err when we have deleted the release already or it does not exist for some reason | ||
if err != nil && !strings.Contains(err.Error(), "uninstall: Release not loaded") { |
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.
Maybe we could check if the release exists before trying to uninstall it to avoid doing string comparison on errors. This seems rather fragile.
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.
done, but even when we check if the installation/release exists. It all boils down on what assumptions we are willing to trust more?
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.
IMO it's better to check if the release exists, as this is the same what helm
is doing and it's a GET operation, which is OK if it fails, where DELETE is something which should not fail normally. Also with GET there is specific error type as far as I remember.
e7842e2
to
d03568a
Compare
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.
Sorry @surajssd, that I didn't look thoroughly enough before, I put few more comments on things I'd like to clarify.
f780b7c
to
749154a
Compare
958cb7b
to
a764fbb
Compare
Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
This commit adds `Name` field in the struct `Metadata`. This helps identify what that component is. Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
This commit adds support of deleting the installed the component. Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
77962b4
to
bf16a66
Compare
Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
bf16a66
to
7b2f936
Compare
All the changes were incorporated :-)
NOTE: For detailed information, see changes per commit.
Fixes #67