Skip to content

Commit

Permalink
Add UT
Browse files Browse the repository at this point in the history
  • Loading branch information
caseydavenport committed Dec 7, 2023
1 parent 0d66042 commit 73e6973
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
19 changes: 19 additions & 0 deletions pkg/render/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,7 @@ var _ = Describe("API server rendering tests (Calico)", func() {
Expect(d.Spec.Template.Spec.Tolerations).To(HaveLen(1))
Expect(d.Spec.Template.Spec.Tolerations).To(ConsistOf(tol))
})

It("should render the correct env and/or images when FIPS mode is enabled (OSS)", func() {
fipsEnabled := operatorv1.FIPSModeEnabled
cfg.Installation.FIPSMode = &fipsEnabled
Expand All @@ -2048,4 +2049,22 @@ var _ = Describe("API server rendering tests (Calico)", func() {
Expect(d.Spec.Template.Spec.Containers[0].Image).To(ContainSubstring("-fips"))
})
})

Context("multi-tenant", func() {
BeforeEach(func() {
cfg.MultiTenant = true
})

It("should not install tigera-network-admin and tigera-ui-user", func() {
component, err := render.APIServer(cfg)
Expect(err).NotTo(HaveOccurred())

// Expect no UISettings / UISettingsGroups to be installed.
resources, _ := component.Objects()
obj := rtest.GetResource(resources, "tigera-network-admin", "", "rbac.authorization.k8s.io", "v1", "ClusterRole")
Expect(obj).To(BeNil())
obj = rtest.GetResource(resources, "tigera-ui-user", "", "rbac.authorization.k8s.io", "v1", "ClusterRole")
Expect(obj).To(BeNil())
})
})
})
32 changes: 30 additions & 2 deletions pkg/render/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package render_test

import (
"fmt"
"reflect"
"strconv"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -968,7 +969,7 @@ var _ = Describe("Tigera Secure Manager rendering tests", func() {
})

It("should render multi-tenant environment variables", func() {
tenantAResources := renderObjects(renderConfig{
resources := renderObjects(renderConfig{
oidc: false,
managementCluster: nil,
installation: installation,
Expand All @@ -985,7 +986,7 @@ var _ = Describe("Tigera Secure Manager rendering tests", func() {
},
},
})
d := rtest.GetResource(tenantAResources, "tigera-manager", tenantANamespace, appsv1.GroupName, "v1", "Deployment").(*appsv1.Deployment)
d := rtest.GetResource(resources, "tigera-manager", tenantANamespace, appsv1.GroupName, "v1", "Deployment").(*appsv1.Deployment)
envs := d.Spec.Template.Spec.Containers[2].Env
esProxyEnv := d.Spec.Template.Spec.Containers[1].Env
Expect(envs).To(ContainElement(corev1.EnvVar{Name: "VOLTRON_TENANT_NAMESPACE", Value: tenantANamespace}))
Expand All @@ -994,6 +995,33 @@ var _ = Describe("Tigera Secure Manager rendering tests", func() {
Expect(envs).To(ContainElement(corev1.EnvVar{Name: "VOLTRON_LINSEED_ENDPOINT", Value: fmt.Sprintf("https://tigera-linseed.%s.svc", tenantANamespace)}))
Expect(esProxyEnv).To(ContainElement(corev1.EnvVar{Name: "VOLTRON_URL", Value: fmt.Sprintf("https://tigera-manager.%s.svc:9443", tenantANamespace)}))
})

It("should not install UISettings / UISettingsGroups", func() {
resources := renderObjects(renderConfig{
oidc: false,
managementCluster: nil,
installation: installation,
compliance: compliance,
complianceFeatureActive: true,
ns: tenantBNamespace,
bindingNamespaces: []string{tenantANamespace, tenantBNamespace},
tenant: &operatorv1.Tenant{
ObjectMeta: metav1.ObjectMeta{
Name: "tenant",
Namespace: tenantANamespace,
},
Spec: operatorv1.TenantSpec{
ID: "tenant-a",
},
},
})

// Expect no UISettings / UISettingsGroups to be installed.
for _, res := range resources {
Expect(reflect.TypeOf(res)).NotTo(Equal(reflect.TypeOf(&v3.UISettings{})), "Unexpected UISettings in multi-tenant mode")
Expect(reflect.TypeOf(res)).NotTo(Equal(reflect.TypeOf(&v3.UISettingsGroup{})), "Unexpected UISettingsGroup in multi-tenant mode")
}
})
})

Context("single-tenant rendering", func() {
Expand Down

0 comments on commit 73e6973

Please sign in to comment.