Skip to content

Commit 594b6c2

Browse files
committed
fix: hook-pod-logs waits for pod restart count > 0 before checking -p logs
1 parent 9dd3578 commit 594b6c2

4 files changed

Lines changed: 30 additions & 24 deletions

File tree

website/docs/fastpaths/developer/amazon-eks-pod-identity/tests/hook-pod-logs.sh

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@ before() {
55
}
66

77
after() {
8-
# The pod may need extra time to crash and have previous logs available
9-
# Retry up to 240s re-fetching logs until we find the expected error
10-
LATEST_POD=$(kubectl get pods -n carts -l app.kubernetes.io/component=service --sort-by=.metadata.creationTimestamp -o jsonpath='{.items[-1:].metadata.name}')
8+
# Wait for the carts pod to crash and restart at least once
9+
# then check previous container logs for the expected credential error
10+
echo "Waiting for carts pod to crash and restart..."
1111

12-
for i in $(seq 1 24); do
13-
LOG_OUTPUT=$(kubectl logs -n carts -p "$LATEST_POD" 2>/dev/null || true)
14-
if [[ "$LOG_OUTPUT" == *"Unable to load credentials"* ]]; then
15-
echo "Found expected credential error in logs"
16-
return 0
12+
for i in $(seq 1 36); do
13+
RESTARTS=$(kubectl get pods -n carts -l app.kubernetes.io/component=service --sort-by=.metadata.creationTimestamp -o jsonpath='{.items[-1:].status.containerStatuses[0].restartCount}' 2>/dev/null || echo "0")
14+
if [ "$RESTARTS" -gt 0 ] 2>/dev/null; then
15+
LATEST_POD=$(kubectl get pods -n carts -l app.kubernetes.io/component=service --sort-by=.metadata.creationTimestamp -o jsonpath='{.items[-1:].metadata.name}')
16+
LOG_OUTPUT=$(kubectl logs -n carts -p "$LATEST_POD" 2>/dev/null || true)
17+
if [[ "$LOG_OUTPUT" == *"Unable to load credentials"* ]]; then
18+
echo "Found expected credential error after $i attempts (restarts=$RESTARTS)"
19+
return 0
20+
fi
1721
fi
18-
echo "Attempt $i: credential error not found yet, waiting..."
22+
echo "Attempt $i: restarts=$RESTARTS, waiting..."
1923
sleep 10
2024
done
2125

22-
echo "Failed to find expected credential error after retries"
23-
echo "Last log output: ${LOG_OUTPUT:-empty}"
26+
echo "Failed to find expected credential error after 360s"
2427
exit 1
2528
}
2629

website/docs/fastpaths/developer/amazon-eks-pod-identity/understanding.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The first place to look for the issue is the logs of the `carts` service:
77

88
```bash hook=pod-logs timeout=480
99
$ LATEST_POD=$(kubectl get pods -n carts -l app.kubernetes.io/component=service --sort-by=.metadata.creationTimestamp -o jsonpath='{.items[-1:].metadata.name}')
10-
sleep 180
10+
sleep 60
1111
kubectl logs -n carts -p $LATEST_POD
1212
[...]
1313
software.amazon.awssdk.core.exception.SdkClientException: Unable to load credentials from any of the providers in the chain AwsCredentialsProviderChain(credentialsProviders=[SystemPropertyCredentialsProvider(), EnvironmentVariableCredentialsProvider(), WebIdentityTokenCredentialsProvider(), ProfileCredentialsProvider(profileName=default, profileFile=ProfileFile(sections=[])), ContainerCredentialsProvider(), InstanceProfileCredentialsProvider()]) : [SystemPropertyCredentialsProvider(): Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId)., EnvironmentVariableCredentialsProvider(): Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId)., WebIdentityTokenCredentialsProvider(): Either the environment variable AWS_WEB_IDENTITY_TOKEN_FILE or the javaproperty aws.webIdentityTokenFile must be set., ProfileCredentialsProvider(profileName=default, profileFile=ProfileFile(sections=[])): Profile file contained no credentials for profile 'default': ProfileFile(sections=[]), ContainerCredentialsProvider(): Cannot fetch credentials from container - neither AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variables are set., InstanceProfileCredentialsProvider(): Failed to load credentials from IMDS.]

website/docs/fastpaths/operator/amazon-eks-pod-identity/tests/hook-pod-logs.sh

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@ before() {
55
}
66

77
after() {
8-
# The pod may need extra time to crash and have previous logs available
9-
# Retry up to 240s re-fetching logs until we find the expected error
10-
LATEST_POD=$(kubectl get pods -n carts -l app.kubernetes.io/component=service --sort-by=.metadata.creationTimestamp -o jsonpath='{.items[-1:].metadata.name}')
8+
# Wait for the carts pod to crash and restart at least once
9+
# then check previous container logs for the expected credential error
10+
echo "Waiting for carts pod to crash and restart..."
1111

12-
for i in $(seq 1 24); do
13-
LOG_OUTPUT=$(kubectl logs -n carts -p "$LATEST_POD" 2>/dev/null || true)
14-
if [[ "$LOG_OUTPUT" == *"Unable to load credentials"* ]]; then
15-
echo "Found expected credential error in logs"
16-
return 0
12+
for i in $(seq 1 36); do
13+
RESTARTS=$(kubectl get pods -n carts -l app.kubernetes.io/component=service --sort-by=.metadata.creationTimestamp -o jsonpath='{.items[-1:].status.containerStatuses[0].restartCount}' 2>/dev/null || echo "0")
14+
if [ "$RESTARTS" -gt 0 ] 2>/dev/null; then
15+
LATEST_POD=$(kubectl get pods -n carts -l app.kubernetes.io/component=service --sort-by=.metadata.creationTimestamp -o jsonpath='{.items[-1:].metadata.name}')
16+
LOG_OUTPUT=$(kubectl logs -n carts -p "$LATEST_POD" 2>/dev/null || true)
17+
if [[ "$LOG_OUTPUT" == *"Unable to load credentials"* ]]; then
18+
echo "Found expected credential error after $i attempts (restarts=$RESTARTS)"
19+
return 0
20+
fi
1721
fi
18-
echo "Attempt $i: credential error not found yet, waiting..."
22+
echo "Attempt $i: restarts=$RESTARTS, waiting..."
1923
sleep 10
2024
done
2125

22-
echo "Failed to find expected credential error after retries"
23-
echo "Last log output: ${LOG_OUTPUT:-empty}"
26+
echo "Failed to find expected credential error after 360s"
2427
exit 1
2528
}
2629

website/docs/fastpaths/operator/amazon-eks-pod-identity/understanding.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The first place to look for the issue is the logs of the `carts` service:
77

88
```bash hook=pod-logs timeout=480
99
$ LATEST_POD=$(kubectl get pods -n carts -l app.kubernetes.io/component=service --sort-by=.metadata.creationTimestamp -o jsonpath='{.items[-1:].metadata.name}')
10-
sleep 180
10+
sleep 60
1111
kubectl logs -n carts -p $LATEST_POD
1212
[...]
1313
software.amazon.awssdk.core.exception.SdkClientException: Unable to load credentials from any of the providers in the chain AwsCredentialsProviderChain(credentialsProviders=[SystemPropertyCredentialsProvider(), EnvironmentVariableCredentialsProvider(), WebIdentityTokenCredentialsProvider(), ProfileCredentialsProvider(profileName=default, profileFile=ProfileFile(sections=[])), ContainerCredentialsProvider(), InstanceProfileCredentialsProvider()]) : [SystemPropertyCredentialsProvider(): Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId)., EnvironmentVariableCredentialsProvider(): Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId)., WebIdentityTokenCredentialsProvider(): Either the environment variable AWS_WEB_IDENTITY_TOKEN_FILE or the javaproperty aws.webIdentityTokenFile must be set., ProfileCredentialsProvider(profileName=default, profileFile=ProfileFile(sections=[])): Profile file contained no credentials for profile 'default': ProfileFile(sections=[]), ContainerCredentialsProvider(): Cannot fetch credentials from container - neither AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variables are set., InstanceProfileCredentialsProvider(): Failed to load credentials from IMDS.]

0 commit comments

Comments
 (0)