feat(crd): add update custom resource status
This commit is contained in:
@@ -2,11 +2,53 @@ package crd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flink-kube-operator/internal/crd/v1alpha1"
|
||||
"fmt"
|
||||
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"gitea.com/logicamp/lc"
|
||||
"go.uber.org/zap"
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
|
||||
func (crd Crd) AddEvent(jobUid types.UID, event string) {
|
||||
crd.client.UpdateStatus(context.Background(), nil, v1.UpdateOptions{})
|
||||
func (crd Crd) SetJobStatus(jobUid types.UID, status string) error {
|
||||
job := GetJob(jobUid)
|
||||
// Define the patch data (JSON Merge Patch format)
|
||||
patchData := map[string]interface{}{
|
||||
"status": v1alpha1.FlinkJobStatus{},
|
||||
}
|
||||
patchBytes, err := json.Marshal(patchData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error marshaling patch data: %w", err)
|
||||
}
|
||||
|
||||
// Patch the status subresource
|
||||
unstructuredJob, err := crd.client.
|
||||
Namespace(job.GetNamespace()).
|
||||
Patch(
|
||||
context.Background(),
|
||||
job.GetName(),
|
||||
types.MergePatchType, // Use MergePatchType for JSON Merge Patch
|
||||
patchBytes,
|
||||
metaV1.PatchOptions{},
|
||||
)
|
||||
if err != nil {
|
||||
lc.Logger.Error(
|
||||
"[crd] [status] error patching custom resource status",
|
||||
zap.String("namespace", job.GetNamespace()),
|
||||
zap.Error(err),
|
||||
)
|
||||
return err
|
||||
}
|
||||
patched, err := convertFromUnstructured(unstructuredJob)
|
||||
if err != nil {
|
||||
lc.Logger.Error("[crd] [status] error in structure unstructured patched", zap.Error(err))
|
||||
}
|
||||
lc.Logger.Debug("[crd] [status] set status", zap.Any("statusUpdateObj", patched))
|
||||
if err != nil {
|
||||
lc.Logger.Error("[crd] [status] ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user