@@ -18,10 +18,12 @@ package controller
18
18
19
19
import (
20
20
"context"
21
+ "fmt"
21
22
22
23
. "github.com/onsi/ginkgo/v2"
23
24
. "github.com/onsi/gomega"
24
25
26
+ v1 "k8s.io/api/core/v1"
25
27
"k8s.io/apimachinery/pkg/api/errors"
26
28
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
29
"k8s.io/apimachinery/pkg/types"
@@ -41,17 +43,51 @@ var _ = Describe("FrontProxy Controller", func() {
41
43
Namespace : "default" , // TODO(user):Modify as needed
42
44
}
43
45
frontproxy := & operatorv1alpha1.FrontProxy {}
46
+ rootShard := & operatorv1alpha1.RootShard {}
47
+ rootShardNamespacedName := types.NamespacedName {
48
+ Name : fmt .Sprintf ("rootshard-%s" , resourceName ),
49
+ Namespace : "default" ,
50
+ }
44
51
45
52
BeforeEach (func () {
46
- By ("creating the custom resource for the Kind FrontProxy" )
47
- err := k8sClient .Get (ctx , typeNamespacedName , frontproxy )
53
+ By ("creating a RootShard object" )
54
+ err := k8sClient .Get (ctx , rootShardNamespacedName , rootShard )
55
+ if err != nil && errors .IsNotFound (err ) {
56
+ rootShard = & operatorv1alpha1.RootShard {
57
+ ObjectMeta : metav1.ObjectMeta {
58
+ Name : fmt .Sprintf ("rootshard-%s" , resourceName ),
59
+ Namespace : "default" ,
60
+ },
61
+ Spec : operatorv1alpha1.RootShardSpec {
62
+ External : operatorv1alpha1.ExternalConfig {
63
+ Hostname : "example.kcp.io" ,
64
+ Port : 6443 ,
65
+ },
66
+ CommonShardSpec : operatorv1alpha1.CommonShardSpec {
67
+ Etcd : operatorv1alpha1.EtcdConfig {
68
+ Endpoints : []string {"https://localhost:2379" },
69
+ },
70
+ },
71
+ },
72
+ }
73
+ Expect (k8sClient .Create (ctx , rootShard )).To (Succeed ())
74
+ }
75
+
76
+ By ("creating a FrontProxy object" )
77
+ err = k8sClient .Get (ctx , typeNamespacedName , frontproxy )
48
78
if err != nil && errors .IsNotFound (err ) {
49
79
resource := & operatorv1alpha1.FrontProxy {
50
80
ObjectMeta : metav1.ObjectMeta {
51
81
Name : resourceName ,
52
82
Namespace : "default" ,
53
83
},
54
- // TODO(user): Specify other spec details if needed.
84
+ Spec : operatorv1alpha1.FrontProxySpec {
85
+ RootShard : operatorv1alpha1.RootShardConfig {
86
+ Reference : & v1.LocalObjectReference {
87
+ Name : rootShard .Name ,
88
+ },
89
+ },
90
+ },
55
91
}
56
92
Expect (k8sClient .Create (ctx , resource )).To (Succeed ())
57
93
}
@@ -65,6 +101,14 @@ var _ = Describe("FrontProxy Controller", func() {
65
101
66
102
By ("Cleanup the specific resource instance FrontProxy" )
67
103
Expect (k8sClient .Delete (ctx , resource )).To (Succeed ())
104
+
105
+ rootShardResource := & operatorv1alpha1.RootShard {}
106
+ err = k8sClient .Get (ctx , rootShardNamespacedName , rootShardResource )
107
+ Expect (err ).NotTo (HaveOccurred ())
108
+
109
+ By ("Cleanup the specific resource instance RootShard" )
110
+ Expect (k8sClient .Delete (ctx , rootShardResource )).To (Succeed ())
111
+
68
112
})
69
113
It ("should successfully reconcile the resource" , func () {
70
114
By ("Reconciling the created resource" )
@@ -77,8 +121,6 @@ var _ = Describe("FrontProxy Controller", func() {
77
121
NamespacedName : typeNamespacedName ,
78
122
})
79
123
Expect (err ).NotTo (HaveOccurred ())
80
- // TODO(user): Add more specific assertions depending on your controller's reconciliation logic.
81
- // Example: If you expect a certain status condition after reconciliation, verify it here.
82
124
})
83
125
})
84
126
})
0 commit comments