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(sync): log a warning for empty pods #9599

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

idsulik
Copy link
Contributor

@idsulik idsulik commented Dec 6, 2024

Fixes: #9598

Description

  • Log a warning if no running pods are found in a namespace during the sync process.

@idsulik idsulik requested a review from a team as a code owner December 6, 2024 16:17
@idsulik idsulik requested a review from louisjimenez December 6, 2024 16:17
@@ -921,58 +921,64 @@ var pod = &v1.Pod{
}

func TestPerform(t *testing.T) {
tests := []struct {
description string
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would revert and keep description as a field instead of making this a map. It is easier to read the tests that way and is the general best practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

"pod not running": {
image: "gcr.io/k8s-skaffold:123",
files: syncMap{"test.go": {"/test.go"}},
pod: nil,
Copy link
Contributor

Choose a reason for hiding this comment

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

in the code you're only logging a warning, but here the test should fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it fails because no files were synced

@@ -328,6 +328,10 @@ func Perform(ctx context.Context, image string, files syncMap, cmdFn func(contex
return nil
}

if len(namespaces) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any way to add a test for this? not sure if that's possible with the current unit test setup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -328,6 +328,10 @@ func Perform(ctx context.Context, image string, files syncMap, cmdFn func(contex
return nil
}

if len(namespaces) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

were you able to reproduce the issue and confirm this fixes it? In the bug they filed, I didn't see anything in the logs to indicate what the issue was

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's just an assumption, because according to the log if something went wrong, it returns error, but it doesn't return any specific error if there is no namespaces OR nor running pod was found

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think these logs should be merged regardless of the issue, because in these cases(empty namespaces or no running pods) there is no way to know what went wrong

Copy link
Contributor

Choose a reason for hiding this comment

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

So I would delete this line as it'll never be hit. Specifically here: https://github.com/GoogleContainerTools/skaffold/blob/main/pkg/skaffold/deploy/util/namespaces.go#L35C4-L35C26 if the namespace is empty, it gets the kube context's namespace. If nothing was set, the default namespace is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@pull-request-size pull-request-size bot added size/M and removed size/L labels Dec 7, 2024
if test.pod == nil {
return fake.NewSimpleClientset(), nil
}

return fake.NewSimpleClientset(test.pod), test.clientErr
})

Copy link
Contributor

Choose a reason for hiding this comment

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

there are no namespaces being given below in Perform the arg is `[]string{""} - why does the first test case still work "no error"? Is there a default namespace being used?

instead of adding a new test (i.e. TestPerform_WithoutNamespaces) could you just add another test case here? First add a new value to the test struct "namespaces", add to existing tests and then pass that along when calling Perform. And in that test case you'd have an empty namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because it's []string{""} slice of 1 item and the item is an empty string, this is why the len returns a non-zero value and it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about adding one more test case to the old test, but it'll complicate the test, so decided to create a separate test

Copy link
Contributor

Choose a reason for hiding this comment

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

See above comment it turns out we don't need to check for empty namespaces and can remove the separate test. Appreciate the explanation though.

@pull-request-size pull-request-size bot added size/S and removed size/M labels Dec 11, 2024
@menahyouyeah menahyouyeah changed the title fix(sync): add validation for namespaces and handle empty pods fix(sync): log a warning for empty pods Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't sync files
2 participants