Skip to content

Commit

Permalink
feat: tracking rating status
Browse files Browse the repository at this point in the history
Signed-off-by: zqq454224016 <[email protected]>
  • Loading branch information
zqq454224016 committed Sep 22, 2023
1 parent 70b25bc commit 37e1844
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion config/samples/rating_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function waitRatingDone() {
namespace=$1
ratingName=$2
START_TIME=$(date +%s)
sleep 2 # wait for operator patch status. avoid 0=0 situationss
sleep 2 # wait for operator patch status. avoid 0=0 situations
while true; do
complete=$(kubectl -n${namespace} get rating ${ratingName} -ojson --ignore-not-found=true | jq '.status.pipelineRuns' | jq '{l:length,o:map(select(.conditions[0].type=="Succeeded" and .conditions[0].status=="True"))|length}' | jq '.l == .o')
if [[ $complete == "true" ]]; then
Expand Down
43 changes: 26 additions & 17 deletions controllers/rating_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,23 @@ func (r *RatingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
}
return reconcile.Result{}, err
}

instanceDeepCopy := instance.DeepCopy()
done, err := r.ratingChecker(ctx, &instance)
if !done {
return reconcile.Result{Requeue: true}, err
cond := corev1alpha1.Condition{
Status: v1.ConditionFalse,
LastTransitionTime: metav1.Now(),
Reason: corev1alpha1.ReasonReconcileError,
Message: "Rating disabled in component's repository",
Type: corev1alpha1.TypeReady,
}
instanceDeepCopy.Status.ConditionedStatus = corev1alpha1.ConditionedStatus{
Conditions: []corev1alpha1.Condition{cond},
}
if err := r.Client.Status().Patch(ctx, instanceDeepCopy, client.MergeFrom(&instance)); err != nil {
return reconcile.Result{}, err
}
return reconcile.Result{}, err
}

if err := r.CreatePipelineRun(logger, ctx, &instance); err != nil {
Expand Down Expand Up @@ -117,21 +130,6 @@ func (r RatingReconciler) ratingChecker(ctx context.Context, instance *corev1alp
return false, err
}
if !repository.Spec.EnableRating {
instanceDeepCopy := instance.DeepCopy()
cond := corev1alpha1.Condition{
Status: v1.ConditionFalse,
LastTransitionTime: metav1.Now(),
Reason: corev1alpha1.ReasonReconcileError,
Message: "Rating disabled in component's repository",
Type: corev1alpha1.TypeReady,
}
instanceDeepCopy.Status.ConditionedStatus = corev1alpha1.ConditionedStatus{
Conditions: []corev1alpha1.Condition{cond},
}
if err := r.Client.Status().Patch(ctx, instanceDeepCopy, client.MergeFrom(instance)); err != nil {
return false, err
}

return false, errors.NewResourceExpired("Rating disabled in component's repository")
}

Expand Down Expand Up @@ -216,6 +214,17 @@ func (r *RatingReconciler) CreatePipelineRun(logger logr.Logger, ctx context.Con

instanceDeepCopy := instance.DeepCopy()
instanceDeepCopy.Status.PipelineRuns = pipelineRunStatus
instanceDeepCopy.Status.ConditionedStatus = corev1alpha1.ConditionedStatus{
Conditions: []corev1alpha1.Condition{
{
Status: v1.ConditionFalse,
LastTransitionTime: metav1.Now(),
Reason: corev1alpha1.RatingRunning,
Message: "Rating enabled in component's repository",
Type: corev1alpha1.TypeReady,
},
},
}
if err := r.Client.Status().Patch(ctx, instanceDeepCopy, client.MergeFrom(instance)); err != nil {
return err
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
arcadiav1 "github.com/kubeagi/arcadia/api/v1alpha1"
"github.com/kubeagi/arcadia/pkg/llms"
"github.com/kubeagi/arcadia/pkg/llms/zhipuai"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -242,6 +243,17 @@ func OnPromptUpdate(logger logr.Logger, c client.Client) func(event.UpdateEvent,
// }
// }

deepCopyRating.Status.ConditionedStatus = corev1alpha1.ConditionedStatus{
Conditions: []corev1alpha1.Condition{
{
Status: v1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: corev1alpha1.RatingSucceeded,
Message: "Rating enabled in component's repository",
Type: corev1alpha1.TypeReady,
},
},
}
deepCopyRating.Status.Evaluations[dimension] = evaluationStatus
err = c.Status().Patch(context.TODO(), deepCopyRating, client.MergeFrom(rating))
if err != nil {
Expand Down

0 comments on commit 37e1844

Please sign in to comment.