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

Checkout whether serviceability has been set for dump and trace #579

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/webspherelibertydump_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (r *ReconcileWebSphereLibertyDump) Reconcile(ctx context.Context, request c
time := time.Now()
dumpFolder := "/serviceability/" + pod.Namespace + "/" + pod.Name
dumpFileName := dumpFolder + "/" + time.Format("2006-01-02_15:04:05") + ".zip"
dumpCmd := "mkdir -p " + dumpFolder + " && server dump --archive=" + dumpFileName
dumpCmd := "if [ ! -d \"serviceability\" ]; then exit 1; fi && " + "mkdir -p " + dumpFolder + " && server dump --archive=" + dumpFileName
if len(instance.Spec.Include) > 0 {
dumpCmd += " --include="
for i := range instance.Spec.Include {
Expand Down
2 changes: 1 addition & 1 deletion controllers/webspherelibertytrace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (r *ReconcileWebSphereLibertyTrace) Reconcile(ctx context.Context, request
}
traceConfig += "/></server>"

_, err = lutils.ExecuteCommandInContainer(r.RestConfig, podName, podNamespace, "app", []string{"/bin/sh", "-c", "mkdir -p " + traceOutputDir + " && echo '" + traceConfig + "' > " + traceConfigFile})
_, err = lutils.ExecuteCommandInContainer(r.RestConfig, podName, podNamespace, "app", []string{"/bin/sh", "-c", "if [ ! -d \"serviceability\" ]; then exit 1; fi && " + "mkdir -p " + traceOutputDir + " && echo '" + traceConfig + "' > " + traceConfigFile})
if err != nil {
reqLogger.Error(err, "Encountered error while setting up trace for pod "+podName+" in namespace "+podNamespace)
return r.UpdateStatus(err, webspherelibertyv1.OperationStatusConditionTypeEnabled, *instance, corev1.ConditionFalse, podName, podChanged)
Expand Down
6 changes: 5 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ func ExecuteCommandInContainer(config *rest.Config, podName, podNamespace, conta
})

if err != nil {
return stderr.String(), fmt.Errorf("Encountered error while running command: %v ; Stderr: %v ; Error: %v", command, stderr.String(), err.Error())
if strings.Contains(err.Error(), "command terminated with exit code 1") {
return stderr.String(), fmt.Errorf("Unable to find serviceability directory. Please check that serviceability has been configured correctly in the relevant WebsphereLibertyApplication custom resource for pod: %v in namespace: %v.", podName, podNamespace)
} else {
return stderr.String(), fmt.Errorf("Encountered error while running command: %v ; Stderr: %v ; Error: %v", command, stderr.String(), err.Error())
}
}

return stderr.String(), nil
Expand Down