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

Fix error handling when trying to delete remote resources not present in Devfile #6659

Conversation

rm3l
Copy link
Member

@rm3l rm3l commented Mar 14, 2023

What type of PR is this:

/kind bug

What does this PR do / why we need it:
Stumbled upon this issue recently, and found a mistake in the if condition used to skip non-deletable resources (like PodMetrics).

We had this previously, which would actually never match:

if !kerrors.IsNotFound(err) || !kerrors.IsMethodNotSupported(err) {

After adding some unit tests, I also noticed that the way any error is detected might lead to a race condition: multiple Goroutines are trying to assign a shared error variable, and we are using that to determine the return value.
This is solved by using errgroup instead, which looks more appropriate to simplify goroutine error handling.

Which issue(s) this PR fixes:
Fixes #6475

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:

rm3l added 4 commits March 14, 2023 10:35
… not present in Devfile

Several Goroutines could potentially modify the same shared error variable,
leading to weird behaviour, caught by the unit tests.
Using errgroup allows simplifying goroutine error handling.
…s not present in Devfile

Replace with a klog message, as the spinner does not add much value to the end user.

Plus, it keeps displaying because we are regenerating the adapter which calls this function indefinitely.
@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label Mar 14, 2023
@netlify
Copy link

netlify bot commented Mar 14, 2023

Deploy Preview for odo-docusaurus-preview canceled.

Name Link
🔨 Latest commit afbd4d6
🔍 Latest deploy log https://app.netlify.com/sites/odo-docusaurus-preview/deploys/641055d64efc7000088264bd

@openshift-ci openshift-ci bot requested review from feloy and kadel March 14, 2023 11:09
@rm3l rm3l requested review from valaparthvi and removed request for kadel March 14, 2023 11:09
@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 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

OpenShift Unauthenticated Tests on commit finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

NoCluster Tests on commit finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

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

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

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

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

Windows Tests (OCP) on commit finished with errors.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

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

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

OpenShift Tests on commit finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Mar 14, 2023

Kubernetes Docs Tests on commit 8a002e1 finished with errors.
View logs: TXT HTML

@@ -693,40 +692,36 @@ func (a Adapter) deleteRemoteResources(objectsToRemove []unstructured.Unstructur
resources = append(resources, fmt.Sprintf("%s/%s", u.GetKind(), u.GetName()))
}

var err error
spinner := log.Spinnerf("Deleting resources not present in the Devfile: %s", strings.Join(resources, ", "))
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume we're sacrificing the spinner message to be able to use errgroup and make sure we don't run into race conditions, yes?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could have used errgroup with the spinner, as the spinner is started outside of the group and its status is updated after all goroutines have exited.
The problem is that odo will continuously try to delete such resources that it couldn't delete (and display the spinner over and over again), which adds too much clutter to the terminal, IMO.
Also, I found the final status of the spinner to be a bit misleading by displaying , because it ignored PodMetrics resources (in the example below), but it didn't delete them actually as it will try again to delete them :-).

Sample output with the spinner
$ odo dev                                                                                                                                                                                                           
  __                                                                                                                                                                                                                
 /  \__     Developing using the "my-node-app" Devfile                                                                                                                                                              
 \__/  \    Namespace: default                                                                                                                                                                                      
 /  \__/    odo version: v3.8.0                                                                                                                                                                                     
 \__/                                                                                                                                                                                                               
                                                                                                                                                                                                                    
↪ Running on the cluster in Dev mode                                                                                                                                                                                
 •  Waiting for Kubernetes resources  ...                                                                                                                                                                           
 ✓  Creating resource Pod/k8s-deploybydefault-true-and-not-referenced                                                                                                                                               
 ✓  Creating resource Pod/k8s-deploybydefault-false-and-not-referenced                                                                                                                                              
 ✓  Creating resource Pod/ocp-deploybydefault-true-and-not-referenced                                                                                                                                               
 ✓  Creating resource Pod/k8s-deploybydefault-not-set-and-not-referenced                                                                                                                                            
 ✓  Creating resource Pod/ocp-deploybydefault-false-and-not-referenced                                                                                                                                              
 ✓  Creating resource Pod/ocp-deploybydefault-not-set-and-not-referenced                                                                                                                                            
 ⚠  Pod is Pending                                                                                                                                                                                                  
 ✓  Pod is Running                                                                                                                                                                                                  
 ✓  Deleting resources not present in the Devfile: PodMetrics/k8s-deploybydefault-false-and-not-referenced, PodMetrics/k8s-deploybydefault-not-set-and-not-referenced, PodMetrics/k8s-deploybydefault-true-and-not-referenced, PodMetrics/ocp-deploybydefault-false-and-not-referenced, PodMetrics/ocp-deploybydefault-not-set-and-not-referenced, PodMetrics/ocp-deploybydefault-true-and-not-referenced [186ms]
 ✓  Syncing files into the container [101ms]
 ✓  Building your application in container (command: build) [3s]
 •  Executing the application (command: start-app)  ...
 -  Forwarding from 127.0.0.1:20001 -> 3000


↪ Dev mode
 Status:
 Watching for changes in the current directory /home/asoro/work/tmp/5694-implement-autobuild-and-deploybydefault

 Keyboard Commands:
[Ctrl+c] - Exit and delete resources from the cluster 
     [p] - Manually apply local changes to the application on the cluster
 ✓  Deleting resources not present in the Devfile: PodMetrics/k8s-deploybydefault-false-and-not-referenced, PodMetrics/k8s-deploybydefault-not-set-and-not-referenced, PodMetrics/k8s-deploybydefault-true-and-not-referenced, PodMetrics/ocp-deploybydefault-false-and-not-referenced, PodMetrics/ocp-deploybydefault-not-set-and-not-referenced, PodMetrics/ocp-deploybydefault-true-and-not-referenced [215ms]
 ✓  Deleting resources not present in the Devfile: PodMetrics/k8s-deploybydefault-false-and-not-referenced, PodMetrics/k8s-deploybydefault-not-set-and-not-referenced, PodMetrics/k8s-deploybydefault-true-and-not-referenced, PodMetrics/ocp-deploybydefault-false-and-not-referenced, PodMetrics/ocp-deploybydefault-not-set-and-not-referenced, PodMetrics/ocp-deploybydefault-true-and-not-referenced [839ms]
 ✓  Deleting resources not present in the Devfile: PodMetrics/k8s-deploybydefault-false-and-not-referenced, PodMetrics/k8s-deploybydefault-not-set-and-not-referenced, PodMetrics/k8s-deploybydefault-true-and-not-referenced, PodMetrics/ocp-deploybydefault-false-and-not-referenced, PodMetrics/ocp-deploybydefault-not-set-and-not-referenced, PodMetrics/ocp-deploybydefault-true-and-not-referenced [860ms]
 ✓  Deleting resources not present in the Devfile: PodMetrics/k8s-deploybydefault-false-and-not-referenced, PodMetrics/k8s-deploybydefault-not-set-and-not-referenced, PodMetrics/k8s-deploybydefault-true-and-not-r
eferenced, PodMetrics/ocp-deploybydefault-false-and-not-referenced, PodMetrics/ocp-deploybydefault-not-set-and-not-referenced, PodMetrics/ocp-deploybydefault-true-and-not-referenced [853ms]
 ✓  Deleting resources not present in the Devfile: PodMetrics/k8s-deploybydefault-false-and-not-referenced, PodMetrics/k8s-deploybydefault-not-set-and-not-referenced, PodMetrics/k8s-deploybydefault-true-and-not-r
eferenced, PodMetrics/ocp-deploybydefault-false-and-not-referenced, PodMetrics/ocp-deploybydefault-not-set-and-not-referenced, PodMetrics/ocp-deploybydefault-true-and-not-referenced [849ms]
 ✓  Deleting resources not present in the Devfile: PodMetrics/k8s-deploybydefault-false-and-not-referenced, PodMetrics/k8s-deploybydefault-not-set-and-not-referenced, PodMetrics/k8s-deploybydefault-true-and-not-r
eferenced, PodMetrics/ocp-deploybydefault-false-and-not-referenced, PodMetrics/ocp-deploybydefault-not-set-and-not-referenced, PodMetrics/ocp-deploybydefault-true-and-not-referenced [855ms]

...

This is why I thought it would make sense to klog this instead.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Mar 15, 2023
@rm3l
Copy link
Member Author

rm3l commented Mar 15, 2023

  user-guides/quickstart/docs-mdx/java/java_odo_dev_output.mdx
  Expected
      <string>:   (
        	"""
        	... // 10 identical lines
        	✓  Added storage m2 to component
        	âš   Pod is Pending
      - 	✓  Pod is Running
        	✓  Syncing files into the container [1s]
        	✓  Building your application in container (command: build) [1s]
        	... // 9 identical lines
        	[Ctrl+c] - Exit and delete resources from the cluster
        	[p] - Manually apply local changes to the application on the cluster
      + 	✓  Pod is Running
        	```
        	"""
        )
      
  to be empty
  In [It] at: /go/odo_1/tests/documentation/user-guides/doc_user_guides_quickstart_test.go:256

To be addressed by #6545

/override Kubernetes-Integration-Tests/Kubernetes-Docs-Integration-Tests

@openshift-ci
Copy link

openshift-ci bot commented Mar 15, 2023

@rm3l: Overrode contexts on behalf of rm3l: Kubernetes-Integration-Tests/Kubernetes-Docs-Integration-Tests

In response to this:

 user-guides/quickstart/docs-mdx/java/java_odo_dev_output.mdx
 Expected
     <string>:   (
       	"""
       	... // 10 identical lines
       	✓  Added storage m2 to component
       	âš   Pod is Pending
     - 	✓  Pod is Running
       	✓  Syncing files into the container [1s]
       	✓  Building your application in container (command: build) [1s]
       	... // 9 identical lines
       	[Ctrl+c] - Exit and delete resources from the cluster
       	[p] - Manually apply local changes to the application on the cluster
     + 	✓  Pod is Running
       	```
       	"""
       )
     
 to be empty
 In [It] at: /go/odo_1/tests/documentation/user-guides/doc_user_guides_quickstart_test.go:256

To be addressed by #6545

/override Kubernetes-Integration-Tests/Kubernetes-Docs-Integration-Tests

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@rm3l
Copy link
Member Author

rm3l commented Mar 16, 2023

Flaky tests.

/override windows-integration-test/Windows-test

@openshift-ci
Copy link

openshift-ci bot commented Mar 16, 2023

@rm3l: Overrode contexts on behalf of rm3l: windows-integration-test/Windows-test

In response to this:

Flaky tests.

/override windows-integration-test/Windows-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-merge-robot openshift-merge-robot merged commit bffb9b0 into redhat-developer:main Mar 16, 2023
@rm3l rm3l deleted the 6475-podmetrics-is-not-a-deletable-resource-and-needs-to-handled-properly-by-odo-dev branch March 16, 2023 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. 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.

PodMetrics is not a deletable resource and needs to handled properly by odo dev
3 participants