Skip to content

Commit

Permalink
status
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkab committed Sep 5, 2019
1 parent 302db0f commit f23d332
Show file tree
Hide file tree
Showing 6 changed files with 304 additions and 71 deletions.
18 changes: 17 additions & 1 deletion api/v1alpha1/oauth2client_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type StatusCode string

const (
StatusRegistrationFailed StatusCode = "CLIENT_REGISTRATION_FAILED"
StatusCreateSecretFailed StatusCode = "SECRET_CREATION_FAILED"
)

// OAuth2ClientSpec defines the desired state of OAuth2Client
type OAuth2ClientSpec struct {
// +kubebuilder:validation:MaxItems=4
Expand Down Expand Up @@ -58,7 +65,16 @@ type OAuth2ClientStatus struct {
// ClientID is the id for this client.
ClientID *string `json:"clientID,omitempty"`
// ObservedGeneration represents the most recent generation observed by the daemon set controller.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
ReconciliationError ReconciliationError
}

// ReconciliationError represents an error that occurred during the reconciliation process
type ReconciliationError struct {
// Code is the status code of the reconciliation error
Code StatusCode
// Description is the description of the reconciliation error
Description string
}

// +kubebuilder:object:root=true
Expand Down
101 changes: 101 additions & 0 deletions controllers/mocks/HydraClientInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions controllers/oauth2client_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ func (r *OAuth2ClientReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *OAuth2ClientReconciler) registerOAuth2Client(ctx context.Context, client *hydrav1alpha1.OAuth2Client) error {
created, err := r.HydraClient.PostOAuth2Client(client.ToOAuth2ClientJSON())
if err != nil {
client.Status.ObservedGeneration = client.Generation
client.Status.ReconciliationError = hydrav1alpha1.ReconciliationError{
Code: hydrav1alpha1.StatusRegistrationFailed,
Description: err.Error(),
}
if updateErr := r.Status().Update(ctx, client); updateErr != nil {
return err
}

return err
}

Expand All @@ -121,6 +130,10 @@ func (r *OAuth2ClientReconciler) registerOAuth2Client(ctx context.Context, clien
err = r.Create(ctx, &clientSecret)
if err != nil {
r.Log.Error(err, fmt.Sprintf("error creating secret for client %s/%s ", client.Name, client.Namespace), "oauth2client", "register")
client.Status.ReconciliationError = hydrav1alpha1.ReconciliationError{
Code: hydrav1alpha1.StatusCreateSecretFailed,
Description: err.Error(),
}
} else {
client.Status.Secret = &clientSecret.Name
}
Expand Down
Loading

0 comments on commit f23d332

Please sign in to comment.