-
Notifications
You must be signed in to change notification settings - Fork 22
/
oathkeeper.go
67 lines (57 loc) · 2.27 KB
/
oathkeeper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package oathkeeper
import (
"context"
"errors"
"github.com/kyma-project/api-gateway/internal/conditions"
"time"
"github.com/kyma-project/api-gateway/apis/operator/v1alpha1"
"github.com/kyma-project/api-gateway/controllers"
"github.com/kyma-project/api-gateway/internal/reconciliations/oathkeeper/maester"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)
func NewReconciler() Reconciler {
return Reconciler{
ReadinessRetryConfig: RetryConfig{
Attempts: 60,
Delay: 2 * time.Second,
},
}
}
type Reconciler struct {
ReadinessRetryConfig RetryConfig
}
type RetryConfig struct {
Attempts uint
Delay time.Duration
}
func (r Reconciler) ReconcileAndVerifyReadiness(ctx context.Context, k8sClient client.Client, apiGatewayCR *v1alpha1.APIGateway) controllers.Status {
status := Reconcile(ctx, k8sClient, apiGatewayCR)
ctrl.Log.Info("Reconciled Oathkeeper", "status", status)
if !status.IsReady() {
return status
}
ctrl.Log.Info("Waiting for Oathkeeper Deployment to become ready")
err := waitForOathkeeperDeploymentToBeReady(ctx, k8sClient, r.ReadinessRetryConfig)
if err != nil {
return controllers.ErrorStatus(err, "Oathkeeper did not start successfully", conditions.OathkeeperReconcileFailed.Condition())
}
return controllers.ReadyStatus(conditions.OathkeeperReconcileSucceeded.Condition())
}
func Reconcile(ctx context.Context, k8sClient client.Client, apiGatewayCR *v1alpha1.APIGateway) controllers.Status {
err := errors.Join(
reconcileOryOathkeeperRuleCRD(ctx, k8sClient, *apiGatewayCR),
maester.ReconcileMaester(ctx, k8sClient, *apiGatewayCR),
reconcileOryJWKSSecret(ctx, k8sClient, *apiGatewayCR),
reconcileOryOathkeeperConfigConfigMap(ctx, k8sClient, *apiGatewayCR),
reconcileOathkeeperHPA(ctx, k8sClient, *apiGatewayCR),
reconcileOryOathkeeperServiceAccount(ctx, k8sClient, *apiGatewayCR),
reconcileOryOathkeeperServices(ctx, k8sClient, *apiGatewayCR),
reconcileOathkeeperDeployment(ctx, k8sClient, *apiGatewayCR),
reconcileOathkeeperPdb(ctx, k8sClient, *apiGatewayCR),
)
if err != nil {
return controllers.ErrorStatus(err, "Oathkeeper did not reconcile successfully", conditions.OathkeeperReconcileFailed.Condition())
}
return controllers.ReadyStatus(conditions.OathkeeperReconcileSucceeded.Condition())
}