77 "fmt"
88
99 miqv1alpha1 "github.com/ManageIQ/manageiq-pods/manageiq-operator/api/v1alpha1"
10+ miqutils "github.com/nasark/manageiq-pods/manageiq-operator/api/v1alpha1/helpers/miq-components/utils"
1011 tlstools "github.com/ManageIQ/manageiq-pods/manageiq-operator/api/v1alpha1/helpers/tlstools"
1112 routev1 "github.com/openshift/api/route/v1"
1213 appsv1 "k8s.io/api/apps/v1"
@@ -77,7 +78,7 @@ func Route(cr *miqv1alpha1.ManageIQ, scheme *runtime.Scheme, client client.Clien
7778 route .Spec .TLS .Certificate = string (public .Data ["tls.crt" ])
7879 route .Spec .TLS .Key = string (public .Data ["tls.key" ])
7980
80- internalCerts := InternalCertificatesSecret (cr , client )
81+ internalCerts := miqutils . InternalCertificatesSecret (cr , client )
8182 route .Spec .TLS .DestinationCACertificate = string (internalCerts .Data ["root_crt" ])
8283
8384 return nil
@@ -140,7 +141,7 @@ func Ingress(cr *miqv1alpha1.ManageIQ, scheme *runtime.Scheme) (*networkingv1.In
140141 },
141142 },
142143 }
143- addAppLabel (cr .Spec .AppName , & ingress .ObjectMeta )
144+ miqutils . AddAppLabel (cr .Spec .AppName , & ingress .ObjectMeta )
144145 return nil
145146 }
146147
@@ -168,26 +169,26 @@ func HttpdConfigMap(cr *miqv1alpha1.ManageIQ, scheme *runtime.Scheme, client cli
168169 if err := controllerutil .SetControllerReference (cr , configMap , scheme ); err != nil {
169170 return err
170171 }
171- addAppLabel (cr .Spec .AppName , & configMap .ObjectMeta )
172+ miqutils . AddAppLabel (cr .Spec .AppName , & configMap .ObjectMeta )
172173
173174 uiHttpProtocol , uiWebSocketProtocol := "http" , "ws"
174- if certSecret := InternalCertificatesSecret (cr , client ); certSecret .Data ["ui_crt" ] != nil && certSecret .Data ["ui_key" ] != nil {
175+ if certSecret := miqutils . InternalCertificatesSecret (cr , client ); certSecret .Data ["ui_crt" ] != nil && certSecret .Data ["ui_key" ] != nil {
175176 uiHttpProtocol , uiWebSocketProtocol = "https" , "wss"
176177 }
177178
178179 apiHttpProtocol := "http"
179- if certSecret := InternalCertificatesSecret (cr , client ); certSecret .Data ["api_crt" ] != nil && certSecret .Data ["api_key" ] != nil {
180+ if certSecret := miqutils . InternalCertificatesSecret (cr , client ); certSecret .Data ["api_crt" ] != nil && certSecret .Data ["api_key" ] != nil {
180181 apiHttpProtocol = "https"
181182 }
182183
183184 configMap .Data ["application.conf" ] = httpdApplicationConf (cr .Spec .ApplicationDomain , uiHttpProtocol , uiWebSocketProtocol , apiHttpProtocol )
184185 configMap .Data ["authentication.conf" ] = httpdAuthenticationConf (& cr .Spec )
185186
186- if certSecret := InternalCertificatesSecret (cr , client ); certSecret .Data ["httpd_crt" ] != nil && certSecret .Data ["httpd_key" ] != nil {
187+ if certSecret := miqutils . InternalCertificatesSecret (cr , client ); certSecret .Data ["httpd_crt" ] != nil && certSecret .Data ["httpd_key" ] != nil {
187188 configMap .Data ["ssl_config" ] = httpdSslConfig ()
188189 }
189190
190- if certSecret := InternalCertificatesSecret (cr , client ); certSecret .Data ["ui_crt" ] != nil && certSecret .Data ["ui_key" ] != nil {
191+ if certSecret := miqutils . InternalCertificatesSecret (cr , client ); certSecret .Data ["ui_crt" ] != nil && certSecret .Data ["ui_key" ] != nil {
191192 configMap .Data ["ssl_proxy_config" ] = httpdSslProxyConfig ()
192193 }
193194
@@ -210,8 +211,8 @@ func HttpdAuthConfigMap(cr *miqv1alpha1.ManageIQ, scheme *runtime.Scheme) (*core
210211 if err := controllerutil .SetControllerReference (cr , configMap , scheme ); err != nil {
211212 return err
212213 }
213- addAppLabel (cr .Spec .AppName , & configMap .ObjectMeta )
214- addBackupLabel (cr .Spec .BackupLabelName , & configMap .ObjectMeta )
214+ miqutils . AddAppLabel (cr .Spec .AppName , & configMap .ObjectMeta )
215+ miqutils . AddBackupLabel (cr .Spec .BackupLabelName , & configMap .ObjectMeta )
215216
216217 configMap .Data ["auth-configuration.conf" ] = httpdAuthConfigurationConf ()
217218
@@ -232,7 +233,7 @@ func HttpdAuthConfig(client client.Client, cr *miqv1alpha1.ManageIQ, scheme *run
232233 }
233234
234235 f := func () error {
235- addBackupLabel (cr .Spec .BackupLabelName , & secret .ObjectMeta )
236+ miqutils . AddBackupLabel (cr .Spec .BackupLabelName , & secret .ObjectMeta )
236237 return nil
237238 }
238239
@@ -269,8 +270,8 @@ func addOIDCEnv(secretName string, podSpec *corev1.PodSpec) {
269270 },
270271 }
271272
272- podSpec .Containers [0 ].Env = addOrUpdateEnvVar (podSpec .Containers [0 ].Env , clientId )
273- podSpec .Containers [0 ].Env = addOrUpdateEnvVar (podSpec .Containers [0 ].Env , clientSecret )
273+ podSpec .Containers [0 ].Env = miqutils . AddOrUpdateEnvVar (podSpec .Containers [0 ].Env , clientId )
274+ podSpec .Containers [0 ].Env = miqutils . AddOrUpdateEnvVar (podSpec .Containers [0 ].Env , clientSecret )
274275}
275276
276277func getHttpdAuthConfigVersion (client client.Client , namespace string , spec * miqv1alpha1.ManageIQSpec ) string {
@@ -287,26 +288,26 @@ func getHttpdAuthConfigVersion(client client.Client, namespace string, spec *miq
287288
288289func addAuthConfigVolume (podSpec * corev1.PodSpec ) {
289290 volumeMount := corev1.VolumeMount {Name : "httpd-auth-config" , MountPath : "/etc/httpd/auth-conf.d" }
290- podSpec .Containers [0 ].VolumeMounts = addOrUpdateVolumeMount (podSpec .Containers [0 ].VolumeMounts , volumeMount )
291+ podSpec .Containers [0 ].VolumeMounts = miqutils . AddOrUpdateVolumeMount (podSpec .Containers [0 ].VolumeMounts , volumeMount )
291292
292293 configMapVolumeSource := corev1.ConfigMapVolumeSource {LocalObjectReference : corev1.LocalObjectReference {Name : "httpd-auth-configs" }}
293- podSpec .Volumes = addOrUpdateVolume (podSpec .Volumes , corev1.Volume {Name : "httpd-auth-config" , VolumeSource : corev1.VolumeSource {ConfigMap : & configMapVolumeSource }})
294+ podSpec .Volumes = miqutils . AddOrUpdateVolume (podSpec .Volumes , corev1.Volume {Name : "httpd-auth-config" , VolumeSource : corev1.VolumeSource {ConfigMap : & configMapVolumeSource }})
294295}
295296
296297func addUserAuthVolume (secretName string , podSpec * corev1.PodSpec ) {
297298 volumeMount := corev1.VolumeMount {Name : "user-auth-config" , MountPath : "/etc/httpd/user-conf.d" }
298- podSpec .Containers [0 ].VolumeMounts = addOrUpdateVolumeMount (podSpec .Containers [0 ].VolumeMounts , volumeMount )
299+ podSpec .Containers [0 ].VolumeMounts = miqutils . AddOrUpdateVolumeMount (podSpec .Containers [0 ].VolumeMounts , volumeMount )
299300
300301 secretVolumeSource := corev1.SecretVolumeSource {SecretName : secretName }
301- podSpec .Volumes = addOrUpdateVolume (podSpec .Volumes , corev1.Volume {Name : "user-auth-config" , VolumeSource : corev1.VolumeSource {Secret : & secretVolumeSource }})
302+ podSpec .Volumes = miqutils . AddOrUpdateVolume (podSpec .Volumes , corev1.Volume {Name : "user-auth-config" , VolumeSource : corev1.VolumeSource {Secret : & secretVolumeSource }})
302303}
303304
304305func addOIDCCACertVolume (secretName string , podSpec * corev1.PodSpec ) {
305306 volumeMount := corev1.VolumeMount {Name : "oidc-ca-cert" , MountPath : "/etc/pki/ca-trust/source/anchors" }
306- podSpec .Containers [0 ].VolumeMounts = addOrUpdateVolumeMount (podSpec .Containers [0 ].VolumeMounts , volumeMount )
307+ podSpec .Containers [0 ].VolumeMounts = miqutils . AddOrUpdateVolumeMount (podSpec .Containers [0 ].VolumeMounts , volumeMount )
307308
308309 secretVolumeSource := corev1.SecretVolumeSource {SecretName : secretName }
309- podSpec .Volumes = addOrUpdateVolume (podSpec .Volumes , corev1.Volume {Name : "oidc-ca-cert" , VolumeSource : corev1.VolumeSource {Secret : & secretVolumeSource }})
310+ podSpec .Volumes = miqutils . AddOrUpdateVolume (podSpec .Volumes , corev1.Volume {Name : "oidc-ca-cert" , VolumeSource : corev1.VolumeSource {Secret : & secretVolumeSource }})
310311}
311312
312313func configureHttpdAuth (spec * miqv1alpha1.ManageIQSpec , podSpec * corev1.PodSpec ) {
@@ -388,7 +389,7 @@ func initializeHttpdContainer(spec *miqv1alpha1.ManageIQSpec, privileged bool, c
388389
389390 assignHttpdPorts (privileged , c )
390391
391- err := addResourceReqs (spec .HttpdMemoryLimit , spec .HttpdMemoryRequest , spec .HttpdCpuLimit , spec .HttpdCpuRequest , c )
392+ err := miqutils . AddResourceReqs (spec .HttpdMemoryLimit , spec .HttpdMemoryRequest , spec .HttpdCpuLimit , spec .HttpdCpuRequest , c )
392393 if err != nil {
393394 return err
394395 }
@@ -432,18 +433,18 @@ func HttpdDeployment(client client.Client, cr *miqv1alpha1.ManageIQ, scheme *run
432433 if err := controllerutil .SetControllerReference (cr , deployment , scheme ); err != nil {
433434 return err
434435 }
435- addAppLabel (cr .Spec .AppName , & deployment .ObjectMeta )
436+ miqutils . AddAppLabel (cr .Spec .AppName , & deployment .ObjectMeta )
436437 var repNum int32 = 1
437438 deployment .Spec .Replicas = & repNum
438439 deployment .Spec .Strategy = appsv1.DeploymentStrategy {
439440 Type : "Recreate" ,
440441 }
441- addAnnotations (cr .Spec .AppAnnotations , & deployment .Spec .Template .ObjectMeta )
442+ miqutils . AddAnnotations (cr .Spec .AppAnnotations , & deployment .Spec .Template .ObjectMeta )
442443 deployment .Spec .Template .Spec .Containers = []corev1.Container {container }
443- deployment .Spec .Template .Spec .Containers [0 ].SecurityContext = DefaultSecurityContext ()
444+ deployment .Spec .Template .Spec .Containers [0 ].SecurityContext = miqutils . DefaultSecurityContext ()
444445
445446 configMapVolumeSource := corev1.ConfigMapVolumeSource {LocalObjectReference : corev1.LocalObjectReference {Name : "httpd-configs" }}
446- deployment .Spec .Template .Spec .Volumes = addOrUpdateVolume (deployment .Spec .Template .Spec .Volumes , corev1.Volume {Name : "httpd-config" , VolumeSource : corev1.VolumeSource {ConfigMap : & configMapVolumeSource }})
447+ deployment .Spec .Template .Spec .Volumes = miqutils . AddOrUpdateVolume (deployment .Spec .Template .Spec .Volumes , corev1.Volume {Name : "httpd-config" , VolumeSource : corev1.VolumeSource {ConfigMap : & configMapVolumeSource }})
447448
448449 // Only assign the service account if we need additional privileges
449450 if privileged {
@@ -456,18 +457,18 @@ func HttpdDeployment(client client.Client, cr *miqv1alpha1.ManageIQ, scheme *run
456457
457458 // This is not used by the pod, it is defined to trigger a redeployment if the secret was updated
458459 httpdAuthConfigVersion := getHttpdAuthConfigVersion (client , cr .Namespace , & cr .Spec )
459- deployment .Spec .Template .Spec .Containers [0 ].Env = addOrUpdateEnvVar (deployment .Spec .Template .Spec .Containers [0 ].Env , corev1.EnvVar {Name : "MANAGED_HTTPD_CFG_VERSION" , Value : httpdAuthConfigVersion })
460+ deployment .Spec .Template .Spec .Containers [0 ].Env = miqutils . AddOrUpdateEnvVar (deployment .Spec .Template .Spec .Containers [0 ].Env , corev1.EnvVar {Name : "MANAGED_HTTPD_CFG_VERSION" , Value : httpdAuthConfigVersion })
460461
461- addInternalCertificate (cr , deployment , client , "httpd" , "/root" )
462+ miqutils . AddInternalCertificate (cr , deployment , client , "httpd" , "/root" )
462463
463- secret := InternalCertificatesSecret (cr , client )
464+ secret := miqutils . InternalCertificatesSecret (cr , client )
464465 if secret .Data ["root_crt" ] != nil {
465466 volumeName := "internal-root-certificate"
466467 volumeMount := corev1.VolumeMount {Name : volumeName , MountPath : "/etc/pki/ca-trust/source/anchors" , ReadOnly : true }
467- deployment .Spec .Template .Spec .Containers [0 ].VolumeMounts = addOrUpdateVolumeMount (deployment .Spec .Template .Spec .Containers [0 ].VolumeMounts , volumeMount )
468+ deployment .Spec .Template .Spec .Containers [0 ].VolumeMounts = miqutils . AddOrUpdateVolumeMount (deployment .Spec .Template .Spec .Containers [0 ].VolumeMounts , volumeMount )
468469
469470 secretVolumeSource := corev1.SecretVolumeSource {SecretName : secret .Name , Items : []corev1.KeyToPath {corev1.KeyToPath {Key : "root_crt" , Path : "root.crt" }}}
470- deployment .Spec .Template .Spec .Volumes = addOrUpdateVolume (deployment .Spec .Template .Spec .Volumes , corev1.Volume {Name : volumeName , VolumeSource : corev1.VolumeSource {Secret : & secretVolumeSource }})
471+ deployment .Spec .Template .Spec .Volumes = miqutils . AddOrUpdateVolume (deployment .Spec .Template .Spec .Volumes , corev1.Volume {Name : volumeName , VolumeSource : corev1.VolumeSource {Secret : & secretVolumeSource }})
471472 }
472473
473474 return nil
@@ -488,7 +489,7 @@ func UIService(cr *miqv1alpha1.ManageIQ, scheme *runtime.Scheme) (*corev1.Servic
488489 if err := controllerutil .SetControllerReference (cr , service , scheme ); err != nil {
489490 return err
490491 }
491- addAppLabel (cr .Spec .AppName , & service .ObjectMeta )
492+ miqutils . AddAppLabel (cr .Spec .AppName , & service .ObjectMeta )
492493 if len (service .Spec .Ports ) == 0 {
493494 service .Spec .Ports = append (service .Spec .Ports , corev1.ServicePort {})
494495 }
@@ -513,7 +514,7 @@ func WebService(cr *miqv1alpha1.ManageIQ, scheme *runtime.Scheme) (*corev1.Servi
513514 if err := controllerutil .SetControllerReference (cr , service , scheme ); err != nil {
514515 return err
515516 }
516- addAppLabel (cr .Spec .AppName , & service .ObjectMeta )
517+ miqutils . AddAppLabel (cr .Spec .AppName , & service .ObjectMeta )
517518 if len (service .Spec .Ports ) == 0 {
518519 service .Spec .Ports = append (service .Spec .Ports , corev1.ServicePort {})
519520 }
@@ -538,7 +539,7 @@ func RemoteConsoleService(cr *miqv1alpha1.ManageIQ, scheme *runtime.Scheme) (*co
538539 if err := controllerutil .SetControllerReference (cr , service , scheme ); err != nil {
539540 return err
540541 }
541- addAppLabel (cr .Spec .AppName , & service .ObjectMeta )
542+ miqutils . AddAppLabel (cr .Spec .AppName , & service .ObjectMeta )
542543 if len (service .Spec .Ports ) == 0 {
543544 service .Spec .Ports = append (service .Spec .Ports , corev1.ServicePort {})
544545 }
@@ -563,7 +564,7 @@ func HttpdService(cr *miqv1alpha1.ManageIQ, scheme *runtime.Scheme) (*corev1.Ser
563564 if err := controllerutil .SetControllerReference (cr , service , scheme ); err != nil {
564565 return err
565566 }
566- addAppLabel (cr .Spec .AppName , & service .ObjectMeta )
567+ miqutils . AddAppLabel (cr .Spec .AppName , & service .ObjectMeta )
567568 if len (service .Spec .Ports ) == 0 {
568569 service .Spec .Ports = append (service .Spec .Ports , corev1.ServicePort {})
569570 }
@@ -588,7 +589,7 @@ func HttpdDbusAPIService(cr *miqv1alpha1.ManageIQ, scheme *runtime.Scheme) (*cor
588589 if err := controllerutil .SetControllerReference (cr , service , scheme ); err != nil {
589590 return err
590591 }
591- addAppLabel (cr .Spec .AppName , & service .ObjectMeta )
592+ miqutils . AddAppLabel (cr .Spec .AppName , & service .ObjectMeta )
592593 if len (service .Spec .Ports ) == 0 {
593594 service .Spec .Ports = append (service .Spec .Ports , corev1.ServicePort {})
594595 }
@@ -615,8 +616,8 @@ func ManageTlsSecret(cr *miqv1alpha1.ManageIQ, client client.Client, scheme *run
615616 return err
616617 }
617618
618- addAppLabel (cr .Spec .AppName , & secret .ObjectMeta )
619- addBackupLabel (cr .Spec .BackupLabelName , & secret .ObjectMeta )
619+ miqutils . AddAppLabel (cr .Spec .AppName , & secret .ObjectMeta )
620+ miqutils . AddBackupLabel (cr .Spec .BackupLabelName , & secret .ObjectMeta )
620621
621622 return nil
622623 }
0 commit comments