Skip to content

Commit

Permalink
follow-up after a2ff4b1
Browse files Browse the repository at this point in the history
Adds `status` field to the `VMUserStatus` subresource.

It allows to track VMUser state and simplifies debugging.

Signed-off-by: f41gh7 <[email protected]>
  • Loading branch information
f41gh7 committed Aug 14, 2024
1 parent 3bc9696 commit a283f1e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions api/operator/v1beta1/vmuser_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions config/crd/overlay/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/operator/factory/vmauth/vmusers_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit a283f1e

Please sign in to comment.