Skip to content

Commit

Permalink
Adds status updates to authorino CRD
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaferson committed Nov 1, 2021
1 parent a46d247 commit c409b92
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
3 changes: 0 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
<<<<<<< HEAD
# Ignore all files which are not go type
!**/*.go
!**/*.mod
!**/*.sum
=======
# Ignore build and test binaries.
bin/
testbin/
>>>>>>> 2620723 (Adds reconcilation of Authorino instances)
5 changes: 4 additions & 1 deletion api/v1beta1/authorino_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ type AuthorinoStatus struct {
// Important: Run "make" to regenerate code after modifying this file

// Number of authorino instances in the cluster
AuthorinoInstances int32 `json:"authorinoInstances"`
AuthorinoInstances int `json:"authorinoInstances"`

// Number of authorino instances in the cluster
Ready bool `json:"ready"`

// Conditions is an array of the current Authorino's CR conditions
// Supported condition types: ConditionReady
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ spec:
properties:
authorinoInstances:
description: Number of authorino instances in the cluster
format: int32
type: integer
conditions:
description: 'Conditions is an array of the current Authorino''s CR
Expand Down Expand Up @@ -114,8 +113,12 @@ spec:
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
ready:
description: Number of authorino instances in the cluster
type: boolean
required:
- authorinoInstances
- ready
type: object
type: object
served: true
Expand Down
28 changes: 26 additions & 2 deletions controllers/authorino_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,18 @@ func (r *AuthorinoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}

log.Info("Found an instance of authorino", "authorinoInstanceName", authorinoInstance.Name)
authorinoInstance.Status.Ready = false

err = r.authorinoServices(authorinoInstance)
if err != nil {
authorinoInstance.Status.Ready = false
log.Error(err, "Failed to create authorino services")
return ctrl.Result{}, err
}

err = r.authorinoPermission(authorinoInstance, req.NamespacedName.Namespace)
if err != nil {
authorinoInstance.Status.Ready = false
log.Error(err, "Failed to create authorino permission")
return ctrl.Result{}, err
}
Expand All @@ -106,12 +109,14 @@ func (r *AuthorinoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
newDeployment := r.authorinoDeployment(authorinoInstance)
err = r.Create(ctx, newDeployment)
if err != nil {
authorinoInstance.Status.Ready = false
log.Error(err, "Failed to create Authorino deployment resource", newDeployment.Name, newDeployment.Namespace)
return ctrl.Result{}, err
}
// Deployment created successfully - return and requeue
return ctrl.Result{Requeue: true}, nil
} else if err != nil {
authorinoInstance.Status.Ready = false
log.Error(err, "Failed to get Deployment for Authorino")
return ctrl.Result{}, err
}
Expand All @@ -127,9 +132,17 @@ func (r *AuthorinoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
return ctrl.Result{RequeueAfter: time.Minute}, nil
}

//TODO: handle deletiton

//TODO: update status
err = r.handleStatusUpdate(authorinoInstance)
if err != nil {
return ctrl.Result{}, err
}

if err == nil {
authorinoInstance.Status.Ready = true
}

r.Status().Update(context.TODO(), authorinoInstance)

return ctrl.Result{RequeueAfter: time.Minute}, nil
}
Expand Down Expand Up @@ -566,6 +579,17 @@ func (r *AuthorinoReconciler) authorinoServices(authorino *authorinooperatorv1be
return nil
}

func (r *AuthorinoReconciler) handleStatusUpdate(authorino *authorinooperatorv1beta1.Authorino) error {
authorinoInstances := authorinooperatorv1beta1.AuthorinoList{}
err := r.List(context.TODO(), &authorinoInstances)
if err != nil {
return fmt.Errorf("Failed getting authorino instances, err: %w", err)
}

authorino.Status.AuthorinoInstances = len(authorinoInstances.Items)
return nil
}

func labelsForAuthorino(name string) map[string]string {
return map[string]string{
"control-plane": "controller-manager",
Expand Down

0 comments on commit c409b92

Please sign in to comment.