-
Notifications
You must be signed in to change notification settings - Fork 377
frontend: Add delete cluster button for non dynamic clusters #3423
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
frontend: Add delete cluster button for non dynamic clusters #3423
Conversation
42e0eb8
to
3b173f4
Compare
reviewed deleting non dynamic clusters from different config locations with @skoeva works as intended 💯 |
3b173f4
to
c6f403b
Compare
was asked to keep this in one PR and not split it by backend/frontend, mind running through the tests one more time like we did before? |
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.
Works for me, LGTM
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 know I asked questions or gave suggestions about previously existing code, but they are good to think about in the context of this PR. Please check them out.
About the i18n, please do not translate new strings unless you know the language (because it'll be difficult to spot by speakers later).
backend/cmd/headlamp.go
Outdated
if source == kubeConfigSource { | ||
err = kubeconfig.RemoveContextFromFile(originalName, configPath) | ||
} else { | ||
err = kubeconfig.RemoveContextFromFile(name, configPath) | ||
} |
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 could instead assign a variable with the actual name we are using for deleting and then have only one function call with it (more readable).
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!
c6f403b
to
fe14134
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.
Much better now but still room to improve.
if (source === 'kubeconfig' && originalName && removeKubeConfig) { | ||
// for non dynamic clusters, we need to use the original name as a query parameter to find the actual context in the kubeconfig | ||
// and remove it from the kubeconfig file. | ||
deleteURL = `/cluster/${cluster}?removeKubeConfig=${removeFromKubeConfig}&source=${source}&configPath=${kubeconfigOrigin}&originalName=${originalName}`; |
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 we are sending the configPath, doesn't the source="kubeconfig" get redundant?
i.e. can we decide in the backend if we should do the same logic by just checking if configPath is sent in the request?
(honest question)
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 see what you're saying here, but having something as destructive as this delete function I went for a more double requirement approach.
I have been experimenting with this logic and finding ways to extend the functionality for permanent deleting clusters for plugins also (I will open a PR for this later after this one is merged, if you think its a worth while feature to have. I have the implementation ready, I just want to land it for non dynamic first)
We are technically getting the config path (under kubeconfigOrigin
) for every delete request when setting the check box to true, so having just a check for a location to delete from I feel isn't narrow enough.
On the other hand, this does open up possibilities of deleting beyond the non dynamic range here (as I mentioned for removing clusters from default headlamp dir) so I think having another check to make sure the kubeconfig source is nondynamic would be needed for this scope, as it is easily turned to delete in other places.
057042e
to
c00dd32
Compare
added a disable option for the confirm dialog to work with checkboxes also added confirm step to deleting clusters |
backend/cmd/headlamp.go
Outdated
originalName := r.URL.Query().Get("originalName") | ||
source := r.URL.Query().Get("source") | ||
|
||
const kubeConfigSource = "kubeconfig" |
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 this is the commit introducing the lint issue, you should add the fix into this one and not on a different commit.
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.
fixed!
const description = | ||
cluster.meta_data?.source === 'kubeconfig' | ||
? t( | ||
'translation|This action will delete cluster {{ clusterName }} from source {{ source }}', |
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 there's still some confusion in what this message is about:
If users can only either delete or not delete the cluster (including removing it from the kubeconfig), then we don't need a check box to confirm they want to remove the cluster from the kubeconfig.
Adding the checkbox would be only useful in a scenario where we can give the option for the cluster to be removed from Headlamp's listing but not from the kubeconfig. Since this is not possible as the clusters are read from the kubeconfig, we can just tell the user that the action will remove the cluster/context from the kubeconfig file (no need for a checkbox).
And the user choices/buttons should be "Cancel" "Delete".
Hope this makes sense.
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.
removed the checkbox logic
c00dd32
to
2bd066c
Compare
1fe018f
to
55df4aa
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.
Thanks for the update. I think now it's very close.
deleteCluster(cluster.name || '') | ||
const clusterID = cluster.meta_data?.clusterID; | ||
const clusterSource = cluster.meta_data?.source; | ||
const originalName = clusterSource === 'kubeconfig' ? cluster.meta_data?.originalName : ''; |
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 it be?
const originalName = cluster.meta_data?.originalName ?? '';
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.
added this, works the same
useEffect(() => { | ||
// If the cluster is from kubeconfig, we want to set the delete to kubeconfig. | ||
if (cluster?.meta_data?.source === 'kubeconfig') { | ||
setDeleteFromKubeconfig(true); | ||
} else { | ||
setDeleteFromKubeconfig(false); | ||
} | ||
}, [deleteFromKubeconfig]); |
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 you need this state?
You could just have const deleteFromKubeconfig = cluster?.meta_data?.source === 'kubeconfig'
.
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.
Had react render issues when trying to use something close to this but inside removeClusterDescription
Moved it under kubeconfigOrigin and seems to work the same now
…beConfigPersistenceFile into MakeHeadlampKubeConfigsDir and DefaultHeadlampKubeConfigFile
…rom local kubeconfig
…terID for nondynamic clusters
55df4aa
to
16b7e4b
Compare
… dynamic clusters
16b7e4b
to
7e33c41
Compare
…g non-dynamic clusters
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: joaquimrocha, skoeva, vyncent-t The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Desciption
This PR introduces changes to enable deleting non dynamic clusters while at the Headlamp home view. Users now have the option to either remove the cluster from their default kubeconfig (similar to how it is now for other clusters), or to remove the cluster from the actual source kubeconfig file on their machine.
How to test non default kubeconfig delete
Start headlamp in app mode
Create a non dynamic cluster
Click the menu options for said dynamic cluster

Notice the
Delete
button is now available for dynamic clustersLocate your kubeconfig for your nondynamic clusters on your machine
Click delete and view pop up dialog for the delete cluster button
Click yes and notice the cluster being removed from the kubeconfig file
How to test default kubeconfig delete
Start headlamp in app mode
Create a non dynamic cluster
Click the menu options for said dynamic cluster

Notice the
Delete
button is now available for dynamic clustersLocate your kubeconfig for your nondynamic clusters on your machine
Click delete and view pop up dialog for the delete cluster button
Click yes and notice the cluster being removed from the the home view and not the kubeconfig file
Reworked from - #2567