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

odo delete component - show warning that something was not deleted #5598

Merged

Conversation

valaparthvi
Copy link
Contributor

@valaparthvi valaparthvi commented Mar 29, 2022

Signed-off-by: Parthvi Vala pvala@redhat.com

What type of PR is this:
/kind feature

What does this PR do / why we need it:
This PR adds information about not deleted component resources because devfile.yaml was changed.

Which issue(s) this PR fixes:

Fixes #5555

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:

  1. mkdir /tmp/101; cd /tmp/101
  2. cp $ODOPATH/tests/examples/source/devfiles/nodejs/devfile-deploy-with-multiple-resources.yaml devfile.yaml
  3. cp -r $ODOPATH/tests/examples/source/nodejs/* .
  4. export PODMAN_CMD=echo
  5. odo deploy
  6. odo dev
  7. Replace my-cs service name to my-changed-cs in devfile.yaml
  8. odo delete component

Output will be similar to:

➜  odo delete component                                                                                                                                                  
Searching resources to delete, please wait...                                                                                                                                
This will delete "mynodejs" from the namespace "default".                                                                                                                    
 •  The component contains the following resources that will get deleted:                                                                                                    
        - Deployment: mynodejs-app                                                                                                                                           
? Are you sure you want to delete "mynodejs" and all its resources? Yes                                                                                                      
The component "mynodejs" is successfully deleted from namespace "default"                                                                                                    
 •  There are still resources left in the cluster that might be belonging to the deleted component.
        - Service: my-cs
        - Deployment: my-component
        - Endpoints: my-cs
If you want to delete those, execute `odo delete component --name mynodejs --namespace default`

@netlify
Copy link

netlify bot commented Mar 29, 2022

Deploy Preview for odo-docusaurus-preview canceled.

Name Link
🔨 Latest commit d414924
🔍 Latest deploy log https://app.netlify.com/sites/odo-docusaurus-preview/deploys/624421279904a4000813f7f2

@openshift-ci openshift-ci bot added the kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation label Mar 29, 2022
@valaparthvi valaparthvi requested a review from kadel March 29, 2022 05:38
@openshift-ci openshift-ci bot requested review from dharmit and rnapoles-rh March 29, 2022 05:38
@odo-robot
Copy link

odo-robot bot commented Mar 29, 2022

Unit Tests on commit dd04882 finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Mar 29, 2022

Kubernetes Tests on commit dd04882 finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Mar 29, 2022

OpenShift Tests on commit dd04882 finished with errors.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Mar 29, 2022

Validate Tests on commit dd04882 finished successfully.
View logs: TXT HTML

@valaparthvi valaparthvi requested review from feloy and removed request for rnapoles-rh March 29, 2022 06:28
var remainingResources []unstructured.Unstructured
k8sResources, _ := o.clientset.DeleteClient.ListResourcesToDelete(componentName, namespace)
// get resources present in k8sResources(present on the cluster) but not in devfileResources(not present in the devfile)
if len(k8sResources) != 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Is this check redundant? I wonder so because we are already returning when if len(devfileResources) == 0, and I think it's safe to assume that if that condition is not satisfied, this condition will never be satisfied. WDYT?

for _, k8sresource := range k8sResources {
var present bool
for _, dresource := range devfileResources {
// skip the component's endpoints resource
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// skip the component's endpoints resource
// skip the component's endpoints resource

Copy link
Member

Choose a reason for hiding this comment

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

Also, there's more happening below than just skipping an endpoint resource. Can you summarize that briefly in the code comment?

for _, dresource := range devfileResources {
// skip the component's endpoints resource
if reflect.DeepEqual(dresource, k8sresource) || (k8sresource.GetKind() == "Endpoints" && strings.Contains(k8sresource.GetName(), componentName)) {
present = true
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 add a break statement here so that it doesn't check for the remaining resources in the slice?

log.Infof("No resource found for component %q in namespace %q\n", componentName, namespace)
return nil
}

var remainingResources []unstructured.Unstructured
k8sResources, _ := o.clientset.DeleteClient.ListResourcesToDelete(componentName, namespace)
Copy link
Member

@dharmit dharmit Mar 29, 2022

Choose a reason for hiding this comment

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

This is not a part of this PR, but, IMO, this method should have been named ListKubernetesResourceToDelete ListClusterResourceToDelete instead. The other method in this interface, ListResourcesToDeleteFromDevfile, is clear from its name itself as to which resources it will delete.

Comment on lines +170 to +160
for _, resource := range remainingResources {
fmt.Printf("\t- %s: %s\n", resource.GetKind(), resource.GetName())
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the tabwriter here instead? It takes care of formatting. We have used it in the odo code in the past.

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 mentioned that he will be modifying the UX for odo. I'd rather leave this and the delete UX in general, in his good hands.

@dharmit dharmit mentioned this pull request Mar 29, 2022
3 tasks
@valaparthvi valaparthvi requested a review from dharmit March 29, 2022 14:49
@valaparthvi valaparthvi changed the title odo delete component - show warning that something was not deleted [WIP] odo delete component - show warning that something was not deleted Mar 29, 2022
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. label Mar 29, 2022
@feloy
Copy link
Contributor

feloy commented Mar 29, 2022

Please update the mock so the unit tests and validation pass
/approve

@openshift-ci
Copy link

openshift-ci bot commented Mar 29, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: feloy

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. label Mar 29, 2022
Signed-off-by: Parthvi Vala <pvala@redhat.com>
Signed-off-by: Parthvi Vala <pvala@redhat.com>
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.5% 0.5% Duplication

@valaparthvi valaparthvi changed the title [WIP] odo delete component - show warning that something was not deleted odo delete component - show warning that something was not deleted Mar 30, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. label Mar 30, 2022
@feloy
Copy link
Contributor

feloy commented Mar 30, 2022

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Mar 30, 2022
@openshift-merge-robot openshift-merge-robot merged commit 2e95384 into redhat-developer:main Mar 30, 2022
cdrage pushed a commit to cdrage/odo that referenced this pull request Aug 31, 2022
…edhat-developer#5598)

* Warn about missing resources

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Dharmit's review

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Add unit tests and some other changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation lgtm Indicates that a PR is ready to be merged. Required by Prow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

odo delete component - show warning that something was not deleted
4 participants