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 16, 2025
1 parent 4fbc3d7 commit 6d1002c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 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,30 @@ 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
}

if deploymentFailed(existingDeployment) {
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)
}
}

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

if existingDeployment != nil {
Expand All @@ -87,18 +103,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 Expand Up @@ -203,3 +233,14 @@ func setResourceHashAnnotation(deployment *appsv1.Deployment) error {

return nil
}

func deploymentFailed(deployment *appsv1.Deployment) bool {
for _, condition := range deployment.Status.Conditions {
if (condition.Type == appsv1.DeploymentProgressing && condition.Status == v1.ConditionFalse) ||
(condition.Type == appsv1.DeploymentAvailable && condition.Status == v1.ConditionFalse) ||
(condition.Type == appsv1.DeploymentReplicaFailure && condition.Status == v1.ConditionTrue) {
return true
}
}
return false
}

0 comments on commit 6d1002c

Please sign in to comment.