@@ -179,7 +179,7 @@ func (r *TobikoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
179179 // got claimed by another instance.
180180 lockAcquired , err := r .AcquireLock (ctx , instance , helper , instance .Spec .Parallel )
181181 if ! lockAcquired {
182- Log .Error (err , ErrConfirmLockOwnership , testOperatorLockName )
182+ Log .Error (err , fmt . Sprintf ( ErrConfirmLockOwnership , testOperatorLockName ) )
183183 return ctrl.Result {RequeueAfter : RequeueAfterValue }, err
184184 }
185185
@@ -207,39 +207,35 @@ func (r *TobikoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
207207 return ctrl.Result {RequeueAfter : RequeueAfterValue }, err
208208 }
209209
210- yamlResult , err := EnsureCloudsConfigMapExists (
211- ctx ,
212- instance ,
213- helper ,
214- serviceLabels ,
215- instance .Spec .OpenStackConfigMap ,
216- )
210+ err = r .ValidateSecretWithKeys (ctx , instance , instance .Spec .KubeconfigSecretName , []string {})
217211 if err != nil {
218212 instance .Status .Conditions .Set (condition .FalseCondition (
219213 condition .InputReadyCondition ,
220214 condition .ErrorReason ,
221215 condition .SeverityWarning ,
222216 condition .InputReadyErrorMessage ,
223217 err .Error ()))
224- return yamlResult , err
218+ return ctrl. Result {} , err
225219 }
220+ mountKubeconfig := len (instance .Spec .KubeconfigSecretName ) != 0
226221
227- err = r .ValidateSecretWithKeys (ctx , instance , instance .Spec .KubeconfigSecretName , []string {})
222+ instance .Status .Conditions .MarkTrue (condition .InputReadyCondition , condition .InputReadyMessage )
223+
224+ // Generate ConfigMaps
225+ err = r .generateServiceConfigMaps (ctx , helper , serviceLabels , instance , workflowStepIndex )
228226 if err != nil {
229227 instance .Status .Conditions .Set (condition .FalseCondition (
230- condition .InputReadyCondition ,
228+ condition .ServiceConfigReadyCondition ,
231229 condition .ErrorReason ,
232230 condition .SeverityWarning ,
233- condition .InputReadyErrorMessage ,
231+ condition .ServiceConfigReadyErrorMessage ,
234232 err .Error ()))
235233 return ctrl.Result {}, err
236234 }
237- mountKubeconfig := len (instance .Spec .KubeconfigSecretName ) != 0
238-
239- instance .Status .Conditions .MarkTrue (condition .InputReadyCondition , condition .InputReadyMessage )
235+ instance .Status .Conditions .MarkTrue (condition .ServiceConfigReadyCondition , condition .ServiceConfigReadyMessage )
236+ // Generate ConfigMaps - end
240237
241238 pvcIndex := 0
242-
243239 // Create multiple PVCs for parallel execution
244240 if instance .Spec .Parallel && workflowStepIndex < len (instance .Spec .Workflow ) {
245241 pvcIndex = workflowStepIndex
@@ -290,16 +286,13 @@ func (r *TobikoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
290286
291287 // Create Pod
292288 mountCerts := r .CheckSecretExists (ctx , instance , "combined-ca-bundle" )
293-
294- mountKeys := false
295- if (len (instance .Spec .PublicKey ) == 0 ) || (len (instance .Spec .PrivateKey ) == 0 ) {
296- Log .Info ("Both values privateKey and publicKey need to be specified. Keys not mounted." )
297- } else {
298- mountKeys = true
289+ mountKeys := len (instance .Spec .PublicKey ) > 0 && len (instance .Spec .PrivateKey ) > 0
290+ if ! mountKeys {
291+ Log .Info ("Both values 'privateKey' and 'publicKey' need to be specified. Keys not mounted." )
299292 }
300293
301294 // Prepare Tobiko env vars
302- envVars := r .PrepareTobikoEnvVars (ctx , serviceLabels , instance , helper , workflowStepIndex )
295+ envVars := r .PrepareTobikoEnvVars (instance , workflowStepIndex )
303296 podName := r .GetPodName (instance , workflowStepIndex )
304297 logsPVCName := r .GetPVCLogsName (instance , pvcIndex )
305298 containerImage , err := r .GetContainerImage (ctx , instance )
@@ -358,12 +351,51 @@ func (r *TobikoReconciler) SetupWithManager(mgr ctrl.Manager) error {
358351 Complete (r )
359352}
360353
361- // PrepareTobikoEnvVars prepares environment variables for a single workflow step
362- func (r * TobikoReconciler ) PrepareTobikoEnvVars (
354+ func (r * TobikoReconciler ) generateServiceConfigMaps (
363355 ctx context.Context ,
356+ h * helper.Helper ,
364357 labels map [string ]string ,
365358 instance * testv1beta1.Tobiko ,
366- helper * helper.Helper ,
359+ workflowStepIndex int ,
360+ ) error {
361+ err := EnsureCloudsConfigMapExists (
362+ ctx ,
363+ instance ,
364+ h ,
365+ labels ,
366+ instance .Spec .OpenStackConfigMap ,
367+ )
368+ if err != nil {
369+ return err
370+ }
371+
372+ templateSpecs := []struct {
373+ infix string
374+ key string
375+ value string
376+ }{
377+ {tobiko .ConfigMapInfixConfig , tobiko .ConfigFileName , instance .Spec .Config },
378+ {tobiko .ConfigMapInfixPrivateKey , tobiko .PrivateKeyFileName , instance .Spec .PrivateKey },
379+ {tobiko .ConfigMapInfixPublicKey , tobiko .PublicKeyFileName , instance .Spec .PublicKey },
380+ }
381+
382+ cms := make ([]util.Template , 0 , len (templateSpecs ))
383+ for _ , spec := range templateSpecs {
384+ cms = append (cms , util.Template {
385+ Name : tobiko .GetConfigMapName (instance , spec .infix , workflowStepIndex ),
386+ Namespace : instance .Namespace ,
387+ InstanceType : instance .Kind ,
388+ Labels : labels ,
389+ CustomData : map [string ]string {spec .key : spec .value },
390+ })
391+ }
392+
393+ return configmap .EnsureConfigMaps (ctx , h , instance , cms , nil )
394+ }
395+
396+ // PrepareTobikoEnvVars prepares environment variables for a single workflow step
397+ func (r * TobikoReconciler ) PrepareTobikoEnvVars (
398+ instance * testv1beta1.Tobiko ,
367399 workflowStepIndex int ,
368400) map [string ]env.Setter {
369401 // Prepare env vars
@@ -404,39 +436,5 @@ func (r *TobikoReconciler) PrepareTobikoEnvVars(
404436 })
405437 }
406438
407- // Prepare custom data
408- templateSpecs := []struct {
409- infix string
410- key string
411- value string
412- }{
413- {tobiko .ConfigMapInfixConfig , tobiko .ConfigFileName , instance .Spec .Config },
414- {tobiko .ConfigMapInfixPrivateKey , tobiko .PrivateKeyFileName , instance .Spec .PrivateKey },
415- {tobiko .ConfigMapInfixPublicKey , tobiko .PublicKeyFileName , instance .Spec .PublicKey },
416- }
417-
418- cms := make ([]util.Template , 0 , len (templateSpecs ))
419- for _ , spec := range templateSpecs {
420- cms = append (cms , util.Template {
421- Name : tobiko .GetConfigMapName (instance , spec .infix , workflowStepIndex ),
422- Namespace : instance .Namespace ,
423- InstanceType : instance .Kind ,
424- Labels : labels ,
425- CustomData : map [string ]string {spec .key : spec .value },
426- })
427- }
428-
429- err := configmap .EnsureConfigMaps (ctx , helper , instance , cms , nil )
430- if err != nil {
431- instance .Status .Conditions .Set (condition .FalseCondition (
432- condition .ServiceConfigReadyCondition ,
433- condition .ErrorReason ,
434- condition .SeverityWarning ,
435- condition .ServiceConfigReadyErrorMessage ,
436- err .Error ()))
437- return map [string ]env.Setter {}
438- }
439- instance .Status .Conditions .MarkTrue (condition .ServiceConfigReadyCondition , condition .ServiceConfigReadyMessage )
440-
441439 return envVars
442440}
0 commit comments