Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into issue-123
Browse files Browse the repository at this point in the history
  • Loading branch information
ruivieira committed Oct 17, 2023
2 parents b887847 + 964c1c5 commit a60bfe1
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 150 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,31 @@ If these parameters are unspecified, the [default image and tag](config/base/par
If you'd like to change the service image/tag after deploying the operator, simply change the parameters in the KFDef. Any
TrustyAI service deployed subsequently will use the new image and tag.

### `TrustyAIService` Status Updates

The `TrustyAIService` custom resource tracks the availability of `InferenceServices` and `PersistentVolumeClaims (PVCs)`
through its `status` field. Below are the status types and reasons that are available:

#### `InferenceService` Status

| Status Type | Status Reason | Description |
|-------------------------------|-----------------------------------|-----------------------------------|
| `InferenceServicesPresent` | `InferenceServicesNotFound` | InferenceServices were not found. |
| `InferenceServicesPresent` | `InferenceServicesFound` | InferenceServices were found. |

#### `PersistentVolumeClaim` (PVCs) Status

| Status Type | Status Reason | Description |
|------------------|-----------------|------------------------------------|
| `PVCAvailable` | `PVCNotFound` | `PersistentVolumeClaim` not found. |
| `PVCAvailable` | `PVCFound` | `PersistentVolumeClaim` found. |


#### Status Behavior

- If a PVC is not available, the `Ready` status of `TrustyAIService` will be set to `False`.
- However, if `InferenceServices` are not found, the `Ready` status of `TrustyAIService` will not be affected, _i.e._, it is `Ready` by all other conditions, it will remain so.

## Contributing

Please see the [CONTRIBUTING.md](./CONTRIBUTING.md) file for more details on how to contribute to this project.
Expand Down
24 changes: 24 additions & 0 deletions api/v1alpha1/trustyaiservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,27 @@ type TrustyAIServiceList struct {
func init() {
SchemeBuilder.Register(&TrustyAIService{}, &TrustyAIServiceList{})
}

// SetStatus sets the status of the TrustyAIService
func (t *TrustyAIService) SetStatus(condType, reason, message string, status corev1.ConditionStatus) {
now := metav1.Now()
condition := Condition{
Type: condType,
Status: status,
Reason: reason,
Message: message,
LastTransitionTime: now,
}
// Replace or append condition
found := false
for i, cond := range t.Status.Conditions {
if cond.Type == condType {
t.Status.Conditions[i] = condition
found = true
break
}
}
if !found {
t.Status.Conditions = append(t.Status.Conditions, condition)
}
}
22 changes: 0 additions & 22 deletions controllers/conditions.go

This file was deleted.

17 changes: 17 additions & 0 deletions controllers/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,20 @@ const (
volumeMountName = "volume"
defaultRequeueDelay = time.Minute
)

// Status types
const (
StatusTypeInferenceServicesPresent = "InferenceServicesPresent"
StatusTypePVCAvailable = "PVCAvailable"
StatusTypeRouteAvailable = "RouteAvailable"
)

// Status reasons
const (
StatusReasonInferenceServicesNotFound = "InferenceServicesNotFound"
StatusReasonInferenceServicesFound = "InferenceServicesFound"
StatusReasonPVCNotFound = "PVCNotFound"
StatusReasonPVCFound = "PVCFound"
StatusReasonRouteNotFound = "RouteNotFound"
StatusReasonRouteFound = "RouteFound"
)
19 changes: 18 additions & 1 deletion controllers/inference_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
kservev1beta1 "github.com/kserve/kserve/pkg/apis/serving/v1beta1"
trustyaiopendatahubiov1alpha1 "github.com/trustyai-explainability/trustyai-service-operator/api/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -127,14 +128,23 @@ func generateEnvVarValue(currentValue, newValue string, remove bool) string {
return currentValue
}

func (r *TrustyAIServiceReconciler) handleInferenceServices(ctx context.Context, namespace string, labelKey string, labelValue string, envVarName string, crName string, remove bool) (bool, error) {
func (r *TrustyAIServiceReconciler) handleInferenceServices(ctx context.Context, instance *trustyaiopendatahubiov1alpha1.TrustyAIService, namespace string, labelKey string, labelValue string, envVarName string, crName string, remove bool) (bool, error) {
var inferenceServices kservev1beta1.InferenceServiceList

if err := r.List(ctx, &inferenceServices, client.InNamespace(namespace)); err != nil {
log.FromContext(ctx).Error(err, "Could not list InferenceService objects.")
return false, err
}

if len(inferenceServices.Items) == 0 {
_, updateErr := r.updateStatus(ctx, instance, UpdateInferenceServiceNotPresent)
if updateErr != nil {
log.FromContext(ctx).Error(updateErr, "Could not update status for InferenceService not present")
return false, updateErr
}
return true, nil
}

for _, infService := range inferenceServices.Items {
annotations := infService.GetAnnotations()
// Check the annotation "serving.kserve.io/deploymentMode: ModelMesh"
Expand All @@ -152,6 +162,13 @@ func (r *TrustyAIServiceReconciler) handleInferenceServices(ctx context.Context,
}
}
}

instance.SetStatus("InferenceServicesPresent", "InferenceServicesFound", "InferenceServices found", corev1.ConditionTrue)
_, updateErr := r.updateStatus(ctx, instance, UpdateInferenceServicePresent)
if updateErr != nil {
log.FromContext(ctx).Error(updateErr, "Could not update status for InferenceService present")
return false, updateErr
}
return true, nil
}

Expand Down
60 changes: 60 additions & 0 deletions controllers/statuses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package controllers

import (
"context"
trustyaiopendatahubiov1alpha1 "github.com/trustyai-explainability/trustyai-service-operator/api/v1alpha1"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)

func (r *TrustyAIServiceReconciler) updateStatus(ctx context.Context, original *trustyaiopendatahubiov1alpha1.TrustyAIService, update func(saved *trustyaiopendatahubiov1alpha1.TrustyAIService),
) (*trustyaiopendatahubiov1alpha1.TrustyAIService, error) {
saved := &trustyaiopendatahubiov1alpha1.TrustyAIService{}
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
err := r.Client.Get(ctx, client.ObjectKeyFromObject(original), saved)
if err != nil {
return err
}
// update status here
update(saved)

// Try to update
err = r.Client.Status().Update(ctx, saved)
return err
})
if err != nil {
log.FromContext(ctx).Error(err, "Failed to update TrustyAIService status")
}
return saved, err
}

func UpdateInferenceServiceNotPresent(saved *trustyaiopendatahubiov1alpha1.TrustyAIService) {
saved.SetStatus(StatusTypeInferenceServicesPresent, StatusReasonInferenceServicesNotFound, "InferenceServices not found", v1.ConditionFalse)
saved.Status.Phase = "Not Ready"
saved.Status.Ready = v1.ConditionFalse

}

func UpdateInferenceServicePresent(saved *trustyaiopendatahubiov1alpha1.TrustyAIService) {
saved.SetStatus(StatusTypeInferenceServicesPresent, StatusReasonInferenceServicesFound, "InferenceServices found", v1.ConditionTrue)
}

func UpdatePVCNotAvailable(saved *trustyaiopendatahubiov1alpha1.TrustyAIService) {
saved.SetStatus(StatusTypePVCAvailable, StatusReasonPVCNotFound, "PersistentVolumeClaim not found", v1.ConditionFalse)
saved.Status.Phase = "Not Ready"
saved.Status.Ready = v1.ConditionFalse
}

func UpdatePVCAvailable(saved *trustyaiopendatahubiov1alpha1.TrustyAIService) {
saved.SetStatus(StatusTypePVCAvailable, StatusReasonPVCFound, "PersistentVolumeClaim found", v1.ConditionTrue)
}

func UpdateRouteAvailable(saved *trustyaiopendatahubiov1alpha1.TrustyAIService) {
saved.SetStatus(StatusTypeRouteAvailable, StatusReasonRouteFound, "Route found", v1.ConditionTrue)
}

func UpdateRouteNotAvailable(saved *trustyaiopendatahubiov1alpha1.TrustyAIService) {
saved.SetStatus(StatusTypeRouteAvailable, StatusReasonRouteNotFound, "Route not found", v1.ConditionFalse)
}
Loading

0 comments on commit a60bfe1

Please sign in to comment.