@@ -36,8 +36,21 @@ const (
3636 DefaultStorageClass = "local-storage"
3737 DefaultComputeSSHKeySecret = "dataplane-ansible-ssh-private-key-secret" // #nosec G101
3838 DefaultWorkloadSSHKeySecret = "dataplane-ansible-ssh-private-key-secret" // #nosec G101
39+ ExtraConfigMapName = "extra-config"
40+ ExtraConfigVolName = "extra-config-vol"
41+ ExtraConfigMountPath = "/etc/extra-config"
42+ ExtraSecretName = "extra-secret" // #nosec G101
43+ ExtraSecretVolName = "extra-secret-vol" // #nosec G101
44+ ExtraSecretMountPath = "/etc/extra-secret" // #nosec G101
3945)
4046
47+ type ExtraMount struct {
48+ VolName string
49+ SourceName string // ConfigMap or Secret name
50+ MountPath string
51+ IsSecret bool
52+ }
53+
4154func CreateUnstructured (rawObj map [string ]any ) * unstructured.Unstructured {
4255 logger .Info ("Creating" , "raw" , rawObj )
4356 unstructuredObj := & unstructured.Unstructured {Object : rawObj }
@@ -87,6 +100,136 @@ func CreateTestOperatorConfigMap(namespace string) *corev1.ConfigMap {
87100 }
88101}
89102
103+ func CreateExtraConfigMap (namespace string , name string ) {
104+ cm := & corev1.ConfigMap {
105+ ObjectMeta : metav1.ObjectMeta {
106+ Name : name ,
107+ Namespace : namespace ,
108+ },
109+ Data : map [string ]string {
110+ "config.conf" : "key=value" ,
111+ },
112+ }
113+ Expect (k8sClient .Create (ctx , cm )).Should (Succeed ())
114+ }
115+
116+ func CreateExtraSecret (namespace string , name string ) {
117+ secret := & corev1.Secret {
118+ ObjectMeta : metav1.ObjectMeta {
119+ Name : name ,
120+ Namespace : namespace ,
121+ },
122+ StringData : map [string ]string {
123+ "secret.conf" : "key=value" ,
124+ },
125+ }
126+ Expect (k8sClient .Create (ctx , secret )).Should (Succeed ())
127+ }
128+
129+ func BuildExtraMountsSpec (propagation string , mounts ... ExtraMount ) []map [string ]any {
130+ volumes := []map [string ]any {}
131+ volumeMounts := []map [string ]any {}
132+
133+ for _ , m := range mounts {
134+ vol := map [string ]any {"name" : m .VolName }
135+ if m .IsSecret {
136+ vol ["secret" ] = map [string ]any {"secretName" : m .SourceName }
137+ } else {
138+ vol ["configMap" ] = map [string ]any {"name" : m .SourceName }
139+ }
140+ volumes = append (volumes , vol )
141+
142+ volumeMounts = append (volumeMounts , map [string ]any {
143+ "name" : m .VolName ,
144+ "mountPath" : m .MountPath ,
145+ "readOnly" : true ,
146+ })
147+ }
148+
149+ extraVol := map [string ]any {
150+ "volumes" : volumes ,
151+ "mounts" : volumeMounts ,
152+ }
153+ if propagation != "" {
154+ extraVol ["propagation" ] = []string {propagation }
155+ }
156+ return []map [string ]any {
157+ {"extraVol" : []map [string ]any {extraVol }},
158+ }
159+ }
160+
161+ func ExpectPodHasConfigMapVolume (pod * corev1.Pod , volName string , cmName string ) {
162+ foundVolume := false
163+ for _ , vol := range pod .Spec .Volumes {
164+ if vol .Name == volName {
165+ foundVolume = true
166+ Expect (vol .VolumeSource .ConfigMap ).NotTo (BeNil ())
167+ Expect (vol .VolumeSource .ConfigMap .Name ).To (Equal (cmName ))
168+ break
169+ }
170+ }
171+ Expect (foundVolume ).To (BeTrue (), "expected pod to have volume '%s'" , volName )
172+ }
173+
174+ func ExpectPodHasSecretVolume (pod * corev1.Pod , volName string , secretName string ) {
175+ foundVolume := false
176+ for _ , vol := range pod .Spec .Volumes {
177+ if vol .Name == volName {
178+ foundVolume = true
179+ Expect (vol .VolumeSource .Secret ).NotTo (BeNil ())
180+ Expect (vol .VolumeSource .Secret .SecretName ).To (Equal (secretName ))
181+ break
182+ }
183+ }
184+ Expect (foundVolume ).To (BeTrue (), "expected pod to have volume '%s'" , volName )
185+ }
186+
187+ func ExpectPodHasVolumeMount (pod * corev1.Pod , volName string , mountPath string ) {
188+ container := pod .Spec .Containers [0 ]
189+ foundMount := false
190+ for _ , mount := range container .VolumeMounts {
191+ if mount .Name == volName {
192+ foundMount = true
193+ Expect (mount .MountPath ).To (Equal (mountPath ))
194+ Expect (mount .ReadOnly ).To (BeTrue ())
195+ break
196+ }
197+ }
198+ Expect (foundMount ).To (BeTrue (), "expected container to have volumeMount '%s'" , volName )
199+ }
200+
201+ func ExpectPodNotHasVolume (pod * corev1.Pod , volName string ) {
202+ for _ , vol := range pod .Spec .Volumes {
203+ Expect (vol .Name ).NotTo (Equal (volName ),
204+ "volume should not be propagated with wrong propagation type" )
205+ }
206+ }
207+
208+ func ExpectPodNotHasVolumeMount (pod * corev1.Pod , volName string ) {
209+ container := pod .Spec .Containers [0 ]
210+ for _ , mount := range container .VolumeMounts {
211+ Expect (mount .Name ).NotTo (Equal (volName ),
212+ "volumeMount should not be propagated with wrong propagation type" )
213+ }
214+ }
215+
216+ func GetDefaultConfigMapExtraMount () ExtraMount {
217+ return ExtraMount {
218+ VolName : ExtraConfigVolName ,
219+ SourceName : ExtraConfigMapName ,
220+ MountPath : ExtraConfigMountPath ,
221+ }
222+ }
223+
224+ func GetDefaultSecretExtraMount () ExtraMount {
225+ return ExtraMount {
226+ VolName : ExtraSecretVolName ,
227+ SourceName : ExtraSecretName ,
228+ MountPath : ExtraSecretMountPath ,
229+ IsSecret : true ,
230+ }
231+ }
232+
90233func GetTestOperatorPVC (namespace string , instanceName string ) * corev1.PersistentVolumeClaim {
91234 var pvc corev1.PersistentVolumeClaim
92235 Eventually (func (g Gomega ) {
0 commit comments