@@ -26,7 +26,7 @@ import (
2626 appsv1 "k8s.io/api/apps/v1"
2727 corev1 "k8s.io/api/core/v1"
2828 "k8s.io/apimachinery/pkg/api/resource"
29- v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030 "k8s.io/apimachinery/pkg/types"
3131 "k8s.io/apimachinery/pkg/util/intstr"
3232)
@@ -39,19 +39,24 @@ const (
3939 timeout = time .Second * 60
4040 duration = time .Second * 30
4141 interval = time .Millisecond * 250
42+
43+ imageName = "progressofficial/marklogic-db:11.3.0-ubi-rootless"
4244)
4345
4446var replicas = int32 (2 )
47+ var fsGroup = int64 (2 )
48+ var fsGroupChangePolicy = corev1 .FSGroupChangeOnRootMismatch
49+ var runAsUser = int64 (1000 )
50+ var runAsNonRoot bool = true
51+ var allowPrivilegeEscalation bool = false
52+ var typeNamespaceName = types.NamespacedName {Name : Name , Namespace : Namespace }
4553
4654const resourceCpuValue = int64 (1 )
4755const resourceMemoryValue = int64 (268435456 )
4856
4957// 100Mi
5058const resourceHugepageValue = int64 (104857600 )
5159
52- var typeNamespaceName = types.NamespacedName {Name : Name , Namespace : Namespace }
53-
54- const imageName = "progressofficial/marklogic-db:11.3.0-ubi-rootless"
5560const fluentBitImage = "fluent/fluent-bit:3.1.1"
5661
5762var groupConfig = databasev1alpha1.GroupConfig {
@@ -70,17 +75,17 @@ var _ = Describe("MarkLogicGroup controller", func() {
7075 It ("Should create a MarklogicGroup CR, StatefulSet and Service" , func () {
7176 // Create the namespace
7277 ns := corev1.Namespace {
73- ObjectMeta : v1 .ObjectMeta {Name : Namespace },
78+ ObjectMeta : metav1 .ObjectMeta {Name : Namespace },
7479 }
7580 Expect (k8sClient .Create (ctx , & ns )).Should (Succeed ())
7681
7782 // Declaring the Marklogic Group object and create CR
7883 mlGroup := & databasev1alpha1.MarklogicGroup {
79- TypeMeta : v1 .TypeMeta {
84+ TypeMeta : metav1 .TypeMeta {
8085 Kind : "MarklogicGroup" ,
8186 APIVersion : "database.marklogic.com/v1alpha1" ,
8287 },
83- ObjectMeta : v1 .ObjectMeta {
88+ ObjectMeta : metav1 .ObjectMeta {
8489 Name : Name ,
8590 Namespace : Namespace ,
8691 },
@@ -97,7 +102,16 @@ var _ = Describe("MarkLogicGroup controller", func() {
97102 ClusterDomain : "cluster.local" ,
98103 TopologySpreadConstraints : []corev1.TopologySpreadConstraint {{MaxSkew : 2 , TopologyKey : "kubernetes.io/hostname" , WhenUnsatisfiable : corev1 .ScheduleAnyway }},
99104 Affinity : & corev1.Affinity {PodAffinity : & corev1.PodAffinity {PreferredDuringSchedulingIgnoredDuringExecution : []corev1.WeightedPodAffinityTerm {{PodAffinityTerm : corev1.PodAffinityTerm {TopologyKey : "kubernetes.io/hostname" }, Weight : 100 }}}},
100- LogCollection : & databasev1alpha1.LogCollection {Enabled : true , Image : "fluent/fluent-bit:3.1.1" , Files : databasev1alpha1.LogFilesConfig {ErrorLogs : true , AccessLogs : true , RequestLogs : true , CrashLogs : true , AuditLogs : true }, Outputs : "stdout" },
105+ PodSecurityContext : & corev1.PodSecurityContext {
106+ FSGroup : & fsGroup ,
107+ FSGroupChangePolicy : & fsGroupChangePolicy ,
108+ },
109+ ContainerSecurityContext : & corev1.SecurityContext {
110+ RunAsUser : & runAsUser ,
111+ RunAsNonRoot : & runAsNonRoot ,
112+ AllowPrivilegeEscalation : & allowPrivilegeEscalation ,
113+ },
114+ LogCollection : & databasev1alpha1.LogCollection {Enabled : true , Image : "fluent/fluent-bit:3.1.1" , Files : databasev1alpha1.LogFilesConfig {ErrorLogs : true , AccessLogs : true , RequestLogs : true , CrashLogs : true , AuditLogs : true }, Outputs : "stdout" },
101115 },
102116 }
103117 Expect (k8sClient .Create (ctx , mlGroup )).Should (Succeed ())
@@ -130,6 +144,11 @@ var _ = Describe("MarkLogicGroup controller", func() {
130144 Expect (createdCR .Spec .TopologySpreadConstraints [0 ].TopologyKey ).Should (Equal ("kubernetes.io/hostname" ))
131145 Expect (createdCR .Spec .TopologySpreadConstraints [0 ].WhenUnsatisfiable ).Should (Equal (corev1 .ScheduleAnyway ))
132146 Expect (createdCR .Spec .Affinity .PodAffinity .PreferredDuringSchedulingIgnoredDuringExecution [0 ].Weight ).Should (Equal (int32 (100 )))
147+ Expect (createdCR .Spec .PodSecurityContext .FSGroup ).Should (Equal (& fsGroup ))
148+ Expect (* createdCR .Spec .PodSecurityContext .FSGroupChangePolicy ).Should (Equal (corev1 .FSGroupChangeOnRootMismatch ))
149+ Expect (* createdCR .Spec .ContainerSecurityContext .RunAsUser ).Should (Equal (int64 (1000 )))
150+ Expect (createdCR .Spec .ContainerSecurityContext .RunAsNonRoot ).Should (Equal (& runAsNonRoot ))
151+ Expect (createdCR .Spec .ContainerSecurityContext .AllowPrivilegeEscalation ).Should (Equal (& allowPrivilegeEscalation ))
133152 Expect (createdCR .Spec .LogCollection .Enabled ).Should (Equal (true ))
134153 Expect (createdCR .Spec .LogCollection .Image ).Should (Equal (fluentBitImage ))
135154
0 commit comments