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

Add a Failed condition to WebSphereLibertyDump #623

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions api/v1/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const (
OperationStatusConditionTypeEnabled OperationStatusConditionType = "Enabled"
// OperationStatusConditionTypeStarted indicates whether operation has been started
OperationStatusConditionTypeStarted OperationStatusConditionType = "Started"
// OperationStatusConditionTypeFailed indicates whether operation has failed
OperationStatusConditionTypeFailed OperationStatusConditionType = "Failed"
// OperationStatusConditionTypeCompleted indicates whether operation has been completed
OperationStatusConditionTypeCompleted OperationStatusConditionType = "Completed"
)
Expand Down
1 change: 1 addition & 0 deletions api/v1/webspherelibertydump_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
// Defines the observed state of WebSphereLibertyDump
type WebSphereLibertyDumpStatus struct {
// +listType=atomic
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Status Conditions",xDescriptors="urn:alm:descriptor:io.kubernetes.conditions"
Conditions []OperationStatusCondition `json:"conditions,omitempty"`
Versions DumpStatusVersions `json:"versions,omitempty"`
// Location of the generated dump file
Expand Down
1 change: 1 addition & 0 deletions api/v1/webspherelibertytrace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type LicenseSimple struct {
// Defines the observed state of WebSphereLibertyTrace operation
type WebSphereLibertyTraceStatus struct {
// +listType=atomic
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Status Conditions",xDescriptors="urn:alm:descriptor:io.kubernetes.conditions"
Conditions []OperationStatusCondition `json:"conditions,omitempty"`
OperatedResource OperatedResource `json:"operatedResource,omitempty"`
Versions TraceStatusVersions `json:"versions,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ metadata:
capabilities: Auto Pilot
categories: Application Runtime
containerImage: icr.io/cpopen/websphere-liberty-operator:daily
createdAt: "2024-01-30T02:09:24Z"
createdAt: "2024-03-13T13:19:52Z"
description: Deploy and manage containerized Liberty applications
olm.skipRange: '>=1.0.0 <1.3.1'
operators.openshift.io/infrastructure-features: '["disconnected"]'
Expand Down Expand Up @@ -705,6 +705,10 @@ spec:
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:checkbox
statusDescriptors:
- displayName: Status Conditions
path: conditions
x-descriptors:
- urn:alm:descriptor:io.kubernetes.conditions
- description: Location of the generated dump file
displayName: Dump File Path
path: dumpFile
Expand All @@ -729,6 +733,11 @@ spec:
path: license.accept
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:checkbox
statusDescriptors:
- displayName: Status Conditions
path: conditions
x-descriptors:
- urn:alm:descriptor:io.kubernetes.conditions
version: v1
displayName: IBM WebSphere Liberty
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ spec:
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:checkbox
statusDescriptors:
- displayName: Status Conditions
path: conditions
x-descriptors:
- urn:alm:descriptor:io.kubernetes.conditions
- description: Location of the generated dump file
displayName: Dump File Path
path: dumpFile
Expand All @@ -594,6 +598,11 @@ spec:
path: license.accept
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:checkbox
statusDescriptors:
- displayName: Status Conditions
path: conditions
x-descriptors:
- urn:alm:descriptor:io.kubernetes.conditions
version: v1
displayName: IBM WebSphere Liberty
icon:
Expand Down
38 changes: 29 additions & 9 deletions controllers/webspherelibertydump_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,18 @@ func (r *ReconcileWebSphereLibertyDump) Reconcile(ctx context.Context, request c
reqLogger.Error(err, message)
r.Recorder.Event(instance, "Warning", "ProcessingError", message)
c := webspherelibertyv1.OperationStatusCondition{
Type: webspherelibertyv1.OperationStatusConditionTypeStarted,
Status: corev1.ConditionFalse,
Type: webspherelibertyv1.OperationStatusConditionTypeStarted,
Status: corev1.ConditionFalse,
}
instance.Status.Conditions = webspherelibertyv1.SetOperationCondtion(instance.Status.Conditions, c)
// Additionally, set the condition to Failed to update the UI
f := webspherelibertyv1.OperationStatusCondition{
Type: webspherelibertyv1.OperationStatusConditionTypeFailed,
Status: corev1.ConditionTrue,
Reason: "Error",
Message: "Failed to find a pod or pod is not in running state",
}
instance.Status.Conditions = webspherelibertyv1.SetOperationCondtion(instance.Status.Conditions, c)
instance.Status.Conditions = webspherelibertyv1.SetOperationCondtion(instance.Status.Conditions, f)
instance.Status.Versions.Reconciled = utils.OperandVersion
r.Client.Status().Update(context.TODO(), instance)
return reconcile.Result{}, nil
Expand All @@ -120,22 +126,32 @@ func (r *ReconcileWebSphereLibertyDump) Reconcile(ctx context.Context, request c
Type: webspherelibertyv1.OperationStatusConditionTypeStarted,
Status: corev1.ConditionTrue,
}

instance.Status.Conditions = webspherelibertyv1.SetOperationCondtion(instance.Status.Conditions, c)
f := webspherelibertyv1.OperationStatusCondition{
Type: webspherelibertyv1.OperationStatusConditionTypeFailed,
Status: corev1.ConditionFalse,
}
instance.Status.Conditions = webspherelibertyv1.SetOperationCondtion(instance.Status.Conditions, f)
r.Client.Status().Update(context.TODO(), instance)

_, err = utils.ExecuteCommandInContainer(r.RestConfig, pod.Name, pod.Namespace, "app", []string{"/bin/sh", "-c", dumpCmd})
if err != nil {
//handle error
reqLogger.Error(err, "Execute dump cmd failed ", "cmd", dumpCmd)
reqLogger.Error(err, "Execute dump cmd failed.. ", "cmd", dumpCmd)
r.Recorder.Event(instance, "Warning", "ProcessingError", err.Error())
c = webspherelibertyv1.OperationStatusCondition{
Type: webspherelibertyv1.OperationStatusConditionTypeCompleted,
Status: corev1.ConditionFalse,
Type: webspherelibertyv1.OperationStatusConditionTypeCompleted,
Status: corev1.ConditionFalse,
}
instance.Status.Conditions = webspherelibertyv1.SetOperationCondtion(instance.Status.Conditions, c)
// Additionally, set the condition to Failed to update the UI
f = webspherelibertyv1.OperationStatusCondition{
Type: webspherelibertyv1.OperationStatusConditionTypeFailed,
Status: corev1.ConditionTrue,
Reason: "Error",
Message: err.Error(),
}
instance.Status.Conditions = webspherelibertyv1.SetOperationCondtion(instance.Status.Conditions, c)
instance.Status.Conditions = webspherelibertyv1.SetOperationCondtion(instance.Status.Conditions, f)
instance.Status.Versions.Reconciled = utils.OperandVersion
r.Client.Status().Update(context.TODO(), instance)
return reconcile.Result{}, nil
Expand All @@ -146,8 +162,12 @@ func (r *ReconcileWebSphereLibertyDump) Reconcile(ctx context.Context, request c
Type: webspherelibertyv1.OperationStatusConditionTypeCompleted,
Status: corev1.ConditionTrue,
}

instance.Status.Conditions = webspherelibertyv1.SetOperationCondtion(instance.Status.Conditions, c)
f = webspherelibertyv1.OperationStatusCondition{
Type: webspherelibertyv1.OperationStatusConditionTypeFailed,
Status: corev1.ConditionFalse,
}
instance.Status.Conditions = webspherelibertyv1.SetOperationCondtion(instance.Status.Conditions, f)
instance.Status.DumpFile = dumpFileName
instance.Status.Versions.Reconciled = utils.OperandVersion
r.Client.Status().Update(context.TODO(), instance)
Expand Down