forked from tigera/operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
guardian_test.go
89 lines (80 loc) · 3.3 KB
/
guardian_test.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) 2020 Tigera, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package render_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
operator "github.com/tigera/operator/pkg/apis/operator/v1"
"github.com/tigera/operator/pkg/components"
"github.com/tigera/operator/pkg/render"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
)
var _ = Describe("Rendering tests", func() {
var g render.Component
var resources []runtime.Object
BeforeEach(func() {
addr := "127.0.0.1:1234"
secret := &corev1.Secret{
TypeMeta: metav1.TypeMeta{Kind: "Secret", APIVersion: "v1"},
ObjectMeta: metav1.ObjectMeta{
Name: render.GuardianSecretName,
Namespace: render.OperatorNamespace(),
},
Data: map[string][]byte{
"cert": []byte("foo"),
"key": []byte("bar"),
},
}
g = render.Guardian(
addr,
[]*corev1.Secret{{
TypeMeta: metav1.TypeMeta{Kind: "Secret", APIVersion: "v1"},
ObjectMeta: metav1.ObjectMeta{
Name: "pull-secret",
Namespace: render.OperatorNamespace(),
},
}},
false,
&operator.Installation{Spec: operator.InstallationSpec{Registry: "my-reg/"}},
secret,
)
resources, _ = g.Objects()
})
It("should render all resources for a managed cluster", func() {
expectedResources := []struct {
name string
ns string
group string
version string
kind string
}{
{name: render.GuardianNamespace, ns: "", group: "", version: "v1", kind: "Namespace"},
{name: "pull-secret", ns: render.GuardianNamespace, group: "", version: "v1", kind: "Secret"},
{name: render.GuardianServiceAccountName, ns: render.GuardianNamespace, group: "", version: "v1", kind: "ServiceAccount"},
{name: render.GuardianClusterRoleName, ns: "", group: "rbac.authorization.k8s.io", version: "v1", kind: "ClusterRole"},
{name: render.GuardianClusterRoleBindingName, ns: "", group: "rbac.authorization.k8s.io", version: "v1", kind: "ClusterRoleBinding"},
{name: render.GuardianDeploymentName, ns: render.GuardianNamespace, group: "apps", version: "v1", kind: "Deployment"},
{name: render.GuardianServiceName, ns: render.GuardianNamespace, group: "", version: "", kind: ""},
{name: render.GuardianSecretName, ns: render.GuardianNamespace, group: "", version: "v1", kind: "Secret"},
}
Expect(len(resources)).To(Equal(len(expectedResources)))
for i, expectedRes := range expectedResources {
ExpectResource(resources[i], expectedRes.name, expectedRes.ns, expectedRes.group, expectedRes.version, expectedRes.kind)
}
deployment := resources[5].(*appsv1.Deployment)
Expect(deployment.Spec.Template.Spec.Containers[0].Image).Should(Equal("my-reg/tigera/guardian:" + components.ComponentGuardian.Version))
})
})