Skip to content

Commit

Permalink
WIP: Set Provider SynchronizationState
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgeorgousis committed Jan 13, 2025
1 parent 4fbc3d7 commit b293936
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions controllers/pipelines/provider_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"k8s.io/apimachinery/pkg/runtime"

"github.com/sky-uk/kfp-operator/apis"
config "github.com/sky-uk/kfp-operator/apis/config/v1alpha6"
"github.com/sky-uk/kfp-operator/apis/pipelines"
pipelinesv1 "github.com/sky-uk/kfp-operator/apis/pipelines/v1alpha6"
Expand Down Expand Up @@ -67,15 +68,25 @@ func (r *ProviderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
desiredDeployment, err := r.constructDeployment(provider, req.Namespace, *r.Config.DeepCopy())
if err != nil {
logger.Error(err, "unable to construct provider service deployment")
provider.Status.SynchronizationState = apis.Failed
if err = r.EC.Client.Status().Update(ctx, provider); err != nil {
logger.Error(err, "unable to update provider resource status", "provider", provider)
}
return ctrl.Result{}, err
}

existingDeployment, err := r.getDeployment(ctx, req.Namespace, provider.Name, *provider)
if err != nil && !apierrors.IsNotFound(err) {
logger.Error(err, "unable to get existing deployment")
provider.Status.SynchronizationState = apis.Failed
if err = r.EC.Client.Status().Update(ctx, provider); err != nil {
logger.Error(err, "unable to update provider resource status", "provider", provider)
}
return ctrl.Result{}, err
}

// TODO: If the Deployment is in a failed state, set the SynchronizationState on the Provider resource to Failed

logger.Info("desired provider deployment", "deployment", desiredDeployment)

if existingDeployment != nil {
Expand All @@ -87,18 +98,32 @@ func (r *ProviderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
existingDeployment.Annotations[ResourceHashAnnotation] = desiredDeployment.Annotations[ResourceHashAnnotation]
if err = r.EC.Client.Update(ctx, existingDeployment); err != nil {
logger.Error(err, "unable to update provider service deployment", "deployment", desiredDeployment)
provider.Status.SynchronizationState = apis.Failed
if err = r.EC.Client.Status().Update(ctx, provider); err != nil {
logger.Error(err, "unable to update provider resource status", "provider", provider)
}
return ctrl.Result{}, err
}
}
} else {
if err = r.EC.Client.Create(ctx, desiredDeployment); err != nil {
logger.Error(err, "unable to create provider service deployment")
provider.Status.SynchronizationState = apis.Failed
if err = r.EC.Client.Status().Update(ctx, provider); err != nil {
logger.Error(err, "unable to update provider resource status", "provider", provider)
}
return ctrl.Result{}, err
}

logger.Info("created provider deployment", "deployment", desiredDeployment)
}

// TODO: We've going to do this a lot, so probably move to helper function
provider.Status.SynchronizationState = apis.Succeeded
if err = r.EC.Client.Status().Update(ctx, provider); err != nil {
logger.Error(err, "unable to update provider resource status", "provider", provider)
}

duration := time.Since(startTime)
logger.Info("reconciliation ended", logkeys.Duration, duration)

Expand Down

0 comments on commit b293936

Please sign in to comment.