This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print pod logs for failed scenarios.
- Loading branch information
Showing
7 changed files
with
149 additions
and
18 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
42 changes: 42 additions & 0 deletions
42
...ain/java/io/quarkus/ts/openshift/common/actions/CopyLogsOnOpenShiftFailureActionImpl.java
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,42 @@ | ||
package io.quarkus.ts.openshift.common.actions; | ||
|
||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.quarkus.ts.openshift.common.Command; | ||
import io.quarkus.ts.openshift.common.config.Config; | ||
import io.quarkus.ts.openshift.common.injection.TestResource; | ||
import io.quarkus.ts.openshift.common.util.OpenShiftUtil; | ||
|
||
import java.io.File; | ||
|
||
public class CopyLogsOnOpenShiftFailureActionImpl implements OnOpenShiftFailureAction { | ||
|
||
private static final String INSTANCES_LOGS_OUTPUT_DIRECTORY = "instance-logs"; | ||
private static final String DEFAULT_LOG_OUTPUT_DIRECTORY = "target/logs"; | ||
private static final String LOG_SUFFIX = ".log"; | ||
|
||
@TestResource | ||
private OpenShiftUtil openShiftUtil; | ||
|
||
@TestResource | ||
private Config config; | ||
|
||
@Override | ||
public void execute() throws Exception { | ||
String namespace = openShiftUtil.getNamespace(); | ||
for (Pod pod : openShiftUtil.getPods()) { | ||
String podName = pod.getMetadata().getName(); | ||
new Command("oc", "logs", podName).outputToFile(getOutputFile(podName, namespace)).runAndWait(); | ||
} | ||
} | ||
|
||
private String getOutputFolder() { | ||
return config.getAsString(INSTANCES_LOGS_OUTPUT_DIRECTORY, DEFAULT_LOG_OUTPUT_DIRECTORY); | ||
} | ||
|
||
private File getOutputFile(String name, String customLogFolderName) { | ||
File outputDirectory = new File(getOutputFolder(), customLogFolderName); | ||
outputDirectory.mkdirs(); | ||
return new File(outputDirectory, name + LOG_SUFFIX); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
common/src/main/java/io/quarkus/ts/openshift/common/actions/OnOpenShiftFailureAction.java
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,14 @@ | ||
package io.quarkus.ts.openshift.common.actions; | ||
|
||
/** | ||
* Interface to perform an action after an OpenShift failure. | ||
*/ | ||
public interface OnOpenShiftFailureAction { | ||
|
||
/** | ||
* Action to perform | ||
* | ||
* @throws Exception to be logged | ||
*/ | ||
void execute() throws Exception; | ||
} |
12 changes: 12 additions & 0 deletions
12
.../java/io/quarkus/ts/openshift/common/actions/PrintStatusOnOpenShiftFailureActionImpl.java
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,12 @@ | ||
package io.quarkus.ts.openshift.common.actions; | ||
|
||
import io.quarkus.ts.openshift.common.Command; | ||
|
||
public class PrintStatusOnOpenShiftFailureActionImpl implements OnOpenShiftFailureAction { | ||
|
||
@Override | ||
public void execute() throws Exception { | ||
new Command("oc", "status", "--suggest").runAndWait(); | ||
} | ||
|
||
} |
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
2 changes: 2 additions & 0 deletions
2
...sources/META-INF/services/io.quarkus.ts.openshift.common.actions.OnOpenShiftFailureAction
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,2 @@ | ||
io.quarkus.ts.openshift.common.actions.PrintStatusOnOpenShiftFailureActionImpl | ||
io.quarkus.ts.openshift.common.actions.CopyLogsOnOpenShiftFailureActionImpl |