From a283f1e67d6f226a63e2595434ba9f8ade67076e Mon Sep 17 00:00:00 2001 From: f41gh7 Date: Wed, 14 Aug 2024 16:09:52 +0200 Subject: [PATCH] follow-up after a2ff4b16f52f3acd92784d67c4f0846bd0bb9298 Adds `status` field to the `VMUserStatus` subresource. It allows to track VMUser state and simplifies debugging. Signed-off-by: f41gh7 --- api/operator/v1beta1/vmuser_types.go | 4 ++++ config/crd/overlay/crd.yaml | 9 +++++++++ .../controller/operator/factory/vmauth/vmusers_config.go | 6 +++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/api/operator/v1beta1/vmuser_types.go b/api/operator/v1beta1/vmuser_types.go index ec453bad..ea66a262 100644 --- a/api/operator/v1beta1/vmuser_types.go +++ b/api/operator/v1beta1/vmuser_types.go @@ -131,6 +131,8 @@ type TargetRefBasicAuth struct { // VMUserStatus defines the observed state of VMUser type VMUserStatus struct { + // Status defines update status of resource + Status UpdateStatus `json:"status,omitempty"` // LastSyncError contains error message for unsuccessful config generation // for given user LastSyncError string `json:"lastSyncError,omitempty"` @@ -141,6 +143,8 @@ type VMUserStatus struct { // VMUser is the Schema for the vmusers API // +kubebuilder:object:root=true // +kubebuilder:subresource:status +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" +// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.status" // +kubebuilder:printcolumn:name="Sync Error",type="string",JSONPath=".status.lastSyncError" // +genclient type VMUser struct { diff --git a/config/crd/overlay/crd.yaml b/config/crd/overlay/crd.yaml index 841fd44b..52b17e82 100644 --- a/config/crd/overlay/crd.yaml +++ b/config/crd/overlay/crd.yaml @@ -30195,6 +30195,12 @@ spec: scope: Namespaced versions: - additionalPrinterColumns: + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + - jsonPath: .status.status + name: Status + type: string - jsonPath: .status.lastSyncError name: Sync Error type: string @@ -30740,6 +30746,9 @@ spec: LastSyncError contains error message for unsuccessful config generation for given user type: string + status: + description: Status defines update status of resource + type: string type: object type: object served: true diff --git a/internal/controller/operator/factory/vmauth/vmusers_config.go b/internal/controller/operator/factory/vmauth/vmusers_config.go index 061375df..674341e6 100644 --- a/internal/controller/operator/factory/vmauth/vmusers_config.go +++ b/internal/controller/operator/factory/vmauth/vmusers_config.go @@ -127,9 +127,9 @@ func buildVMAuthConfig(ctx context.Context, rclient client.Client, vmauth *vmv1b } for _, user := range sus.users { // restore status back to normal - if user.Status.LastSyncError != "" { + if user.Status.Status != vmv1beta1.UpdateStatusOperational { pt := client.RawPatch(types.MergePatchType, - []byte(`{"status": {"lastSyncError": "" } }`)) + []byte(fmt.Sprintf(`{"status": {"lastSyncError": "" ,"status": %q } }`, vmv1beta1.UpdateStatusOperational))) if err := rclient.Status().Patch(ctx, user, pt); err != nil { return nil, fmt.Errorf("failed to patch status of vmuser=%q: %w", user.Name, err) } @@ -144,7 +144,7 @@ func buildVMAuthConfig(ctx context.Context, rclient client.Client, vmauth *vmv1b // patch update status pt := client.RawPatch(types.MergePatchType, - []byte(fmt.Sprintf(`{"status": {"lastSyncError": %q } }`, brokenUser.Status.CurrentSyncError))) + []byte(fmt.Sprintf(`{"status": {"lastSyncError": %q , "status": %q} }`, brokenUser.Status.CurrentSyncError, vmv1beta1.UpdateStatusFailed))) if err := rclient.Status().Patch(ctx, brokenUser, pt); err != nil { return nil, fmt.Errorf("failed to patch status of broken vmuser=%q: %w", brokenUser.Name, err) }