-
Notifications
You must be signed in to change notification settings - Fork 2
/
controllers.go
54 lines (48 loc) · 1.57 KB
/
controllers.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
package common
import (
"context"
"time"
heistv1alpha1 "github.com/youniqx/heist/pkg/apis/heist.youniqx.com/v1alpha1"
"github.com/youniqx/heist/pkg/testhelper"
"github.com/youniqx/heist/pkg/vault"
"github.com/youniqx/heist/pkg/vault/testenv"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
)
type TestDataWrapper struct {
K8sClient client.Client
TestEnv *envtest.Environment
VaultEnv testenv.TestEnv
RootAPI vault.API
K8sEnv testhelper.KubernetesTestHelper
DefaultCipherText string
}
const (
requeueAfter = 60 * time.Second
// YouniqxFinalizer defines the finalizer value used by all CRDs.
YouniqxFinalizer = "youniqx.com/finalizer"
)
// Requeue unifies the returned controller result when an error occurs.
// By default it the handling of the CRD is queued to run in 5 seconds.
var Requeue = ctrl.Result{
Requeue: true,
RequeueAfter: requeueAfter,
}
func FindRootCA(ctx context.Context, k8s client.Client, ca *heistv1alpha1.VaultCertificateAuthority) (*heistv1alpha1.VaultCertificateAuthority, error) {
potentialRoot := ca
for potentialRoot.Spec.Issuer != "" {
nextCA := &heistv1alpha1.VaultCertificateAuthority{
ObjectMeta: metav1.ObjectMeta{
Name: potentialRoot.Spec.Issuer,
Namespace: potentialRoot.Namespace,
},
}
if err := k8s.Get(ctx, client.ObjectKeyFromObject(nextCA), nextCA); err != nil {
return nil, err
}
potentialRoot = nextCA
}
return potentialRoot, nil
}