-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UX changes: - Only print an error when a pod doesn't have a matching container instead of exiting early. - Return a non-zero status code when no pod is found at all. Details: In certain situations there might be 3rd-party pods running in the Flux namespace that cause the command to fail streaming logs, e.g. when they have multiple containers but none of them is called `manager` (which all Flux-maintained pods do). An example of such a situation is when Flux is installed with the 3rd-party Flux extension on AKS. The `logs` command is now more forgiving and merely logs an error in these situations instead of completely bailing out. It still returns a non-zero exit code. For the parallel log streaming with `-f` the code is now a little more complex so that errors are now written to stderr in parallel with all other logs written to stdout. That's what `asyncCopy` is for. refs #3944 Signed-off-by: Max Jonas Werner <mail@makk.es>
- Loading branch information
Max Jonas Werner
committed
Jun 5, 2023
1 parent
c0fa6e6
commit 6b8afc9
Showing
4 changed files
with
138 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
/* | ||
Copyright 2021 The Flux authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestLogsNoArgs(t *testing.T) { | ||
cmd := cmdTestCase{ | ||
args: "logs", | ||
assert: assertSuccess(), | ||
} | ||
cmd.runTestCmd(t) | ||
} | ||
|
||
func TestLogsWrongNamespace(t *testing.T) { | ||
cmd := cmdTestCase{ | ||
args: "logs --flux-namespace=default", | ||
assert: assertError(`no Flux pods found in namespace "default"`), | ||
} | ||
cmd.runTestCmd(t) | ||
} | ||
|
||
func TestLogsAllNamespaces(t *testing.T) { | ||
cmd := cmdTestCase{ | ||
args: "logs --all-namespaces", | ||
assert: assertSuccess(), | ||
} | ||
cmd.runTestCmd(t) | ||
} | ||
|
||
func TestLogsSince(t *testing.T) { | ||
cmd := cmdTestCase{ | ||
args: "logs --since=2m", | ||
assert: assertSuccess(), | ||
} | ||
cmd.runTestCmd(t) | ||
} | ||
|
||
func TestLogsSinceInvalid(t *testing.T) { | ||
cmd := cmdTestCase{ | ||
args: "logs --since=XXX", | ||
assert: assertError(`invalid argument "XXX" for "--since" flag: time: invalid duration "XXX"`), | ||
} | ||
cmd.runTestCmd(t) | ||
} | ||
|
||
func TestLogsSinceTime(t *testing.T) { | ||
cmd := cmdTestCase{ | ||
args: "logs --since-time=2021-08-06T14:26:25.546Z", | ||
assert: assertSuccess(), | ||
} | ||
cmd.runTestCmd(t) | ||
} | ||
|
||
func TestLogsSinceTimeInvalid(t *testing.T) { | ||
cmd := cmdTestCase{ | ||
args: "logs --since-time=XXX", | ||
assert: assertError("XXX is not a valid (RFC3339) time"), | ||
} | ||
cmd.runTestCmd(t) | ||
} | ||
|
||
func TestLogsSinceOnlyOneAllowed(t *testing.T) { | ||
cmd := cmdTestCase{ | ||
args: "logs --since=2m --since-time=2021-08-06T14:26:25.546Z", | ||
assert: assertError("at most one of `sinceTime` or `sinceSeconds` may be specified"), | ||
} | ||
cmd.runTestCmd(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters