Skip to content

Commit 0c25f80

Browse files
committed
Make unit test for FrontProxy pass
On-behalf-of: SAP <[email protected]> Signed-off-by: Marvin Beckers <[email protected]>
1 parent 5bfb272 commit 0c25f80

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

internal/controller/frontproxy_controller_test.go

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ package controller
1818

1919
import (
2020
"context"
21+
"fmt"
2122

2223
. "github.com/onsi/ginkgo/v2"
2324
. "github.com/onsi/gomega"
2425

26+
v1 "k8s.io/api/core/v1"
2527
"k8s.io/apimachinery/pkg/api/errors"
2628
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2729
"k8s.io/apimachinery/pkg/types"
@@ -41,17 +43,51 @@ var _ = Describe("FrontProxy Controller", func() {
4143
Namespace: "default", // TODO(user):Modify as needed
4244
}
4345
frontproxy := &operatorv1alpha1.FrontProxy{}
46+
rootShard := &operatorv1alpha1.RootShard{}
47+
rootShardNamespacedName := types.NamespacedName{
48+
Name: fmt.Sprintf("rootshard-%s", resourceName),
49+
Namespace: "default",
50+
}
4451

4552
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)
4878
if err != nil && errors.IsNotFound(err) {
4979
resource := &operatorv1alpha1.FrontProxy{
5080
ObjectMeta: metav1.ObjectMeta{
5181
Name: resourceName,
5282
Namespace: "default",
5383
},
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+
},
5591
}
5692
Expect(k8sClient.Create(ctx, resource)).To(Succeed())
5793
}
@@ -65,6 +101,14 @@ var _ = Describe("FrontProxy Controller", func() {
65101

66102
By("Cleanup the specific resource instance FrontProxy")
67103
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+
68112
})
69113
It("should successfully reconcile the resource", func() {
70114
By("Reconciling the created resource")
@@ -77,8 +121,6 @@ var _ = Describe("FrontProxy Controller", func() {
77121
NamespacedName: typeNamespacedName,
78122
})
79123
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.
82124
})
83125
})
84126
})

internal/resources/frontproxy/deployment.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ func DeploymentReconciler(frontproxy *operatorv1alpha1.FrontProxy, rootshard *op
242242
}
243243

244244
func getArgs(frontproxy *operatorv1alpha1.FrontProxy) []string {
245-
246245
args := []string{
247246
"--secure-port=6443",
248247
"--root-kubeconfig=/etc/kcp-front-proxy/kubeconfig/kubeconfig",
@@ -252,7 +251,6 @@ func getArgs(frontproxy *operatorv1alpha1.FrontProxy) []string {
252251
"--client-ca-file=/etc/kcp-front-proxy/client-ca/tls.crt",
253252
"--mapping-file=/etc/kcp-front-proxy/config/path-mapping.yaml",
254253
"--service-account-key-file=/etc/kcp/tls/service-account/tls.key",
255-
//"--authentication-drop-groups=system:kcp:logical-cluster-admin",
256254
}
257255

258256
return args

0 commit comments

Comments
 (0)