feat: add restore statuses to kubernetes crd

This commit is contained in:
2024-12-08 00:47:53 +03:30
parent c5b19d3336
commit 5abc044d69
9 changed files with 101 additions and 39 deletions

View File

@@ -10,7 +10,6 @@ import (
type ManagedJob struct {
def v1alpha1.FlinkJob
client *api.Client
jarId string
crd *crd.Crd
}

View File

@@ -1,7 +1,9 @@
package managed_job
import (
"errors"
"flink-kube-operator/internal/crd/v1alpha1"
"time"
"gitea.com/logicamp/lc"
api "github.com/logi-camp/go-flink-client"
@@ -14,9 +16,14 @@ func (job *ManagedJob) restore() error {
lc.Logger.Error("[managed-job] [restore]", zap.Error(v1alpha1.ErrNoSavepointPath))
return v1alpha1.ErrNoSavepointPath
}
if job.def.Status.JarId == nil {
err := errors.New("missing jar id")
lc.Logger.Error("[managed-job] [run]", zap.Error(err))
return err
}
lc.Logger.Debug("[managed-job] [restore] restoring", zap.String("savepointPath", *job.def.Status.LastSavepointPath))
runJarResp, err := job.client.RunJar(api.RunOpts{
JarID: job.jarId,
JarID: *job.def.Status.JarId,
AllowNonRestoredState: true,
EntryClass: job.def.Spec.EntryClass,
SavepointPath: *job.def.Status.LastSavepointPath,
@@ -32,10 +39,13 @@ func (job *ManagedJob) restore() error {
// job.def.Status.Error = nil
job.crd.Patch(job.def.UID, map[string]interface{}{
"status": map[string]interface{}{
"jobId": &runJarResp.JobId,
"jobStatus": v1alpha1.JobStatusCreating,
"lifeCycleStatus": v1alpha1.LifeCycleStatusRestoring,
"error": nil,
"jobId": &runJarResp.JobId,
"jobStatus": v1alpha1.JobStatusCreating,
"lifeCycleStatus": v1alpha1.LifeCycleStatusRestoring,
"lastRestoredSavepointDate": job.def.Status.LastRestoredSavepointDate,
"restoredCount": job.def.Status.RestoredCount + 1,
"lastRestoredSavepointRestoreDate": time.Now().Format(time.RFC3339),
"error": nil,
},
})

View File

@@ -1,6 +1,7 @@
package managed_job
import (
"errors"
"flink-kube-operator/internal/crd/v1alpha1"
"flink-kube-operator/internal/jar"
@@ -24,14 +25,24 @@ func (job *ManagedJob) upload() error {
}
lc.Logger.Debug("[main] after upload jar", zap.Any("upload-jar-resp", fileName))
job.jarId = fileName
job.def.Status.JarId = &fileName
job.crd.Patch(job.def.UID, map[string]interface{}{
"status": map[string]interface{}{
"jarId": job.def.Status.JarId,
},
})
return nil
}
// run the job from saved jarId in managedJob
func (job *ManagedJob) run() error {
if job.def.Status.JarId == nil {
err := errors.New("missing jar id")
lc.Logger.Error("[managed-job] [run]", zap.Error(err))
return err
}
runJarResp, err := job.client.RunJar(api.RunOpts{
JarID: job.jarId,
JarID: *job.def.Status.JarId,
AllowNonRestoredState: true,
EntryClass: job.def.Spec.EntryClass,
})

View File

@@ -55,7 +55,7 @@ func (job ManagedJob) trackSavepoint() error {
job.crd.Patch(job.def.UID, map[string]interface{}{
"status": map[string]interface{}{
"lastSavepointPath": resp.Operation.Location,
"lastSavepointDate": time.Now(),
"lastSavepointDate": time.Now().Format(time.RFC3339),
},
})
}