From 8adb32bd7461ccd2b3b699b7ebad08ef3bbc37b1 Mon Sep 17 00:00:00 2001 From: Owen McGonagle Date: Tue, 17 Dec 2024 17:18:48 -0500 Subject: [PATCH 1/2] Initial changes --- controllers/horizon_controller.go | 4 ++++ pkg/horizon/const.go | 18 ++++++++++++++++++ pkg/horizon/deployment.go | 20 ++++++++++++++++++++ pkg/horizon/volumes.go | 19 +++++++++++++++++++ templates/horizon/config/01-config.conf | 2 ++ 5 files changed, 63 insertions(+) create mode 100644 templates/horizon/config/01-config.conf diff --git a/controllers/horizon_controller.go b/controllers/horizon_controller.go index 4a7db03a..ee31dc85 100644 --- a/controllers/horizon_controller.go +++ b/controllers/horizon_controller.go @@ -907,6 +907,10 @@ func (r *HorizonReconciler) generateServiceConfigMaps( templateParameters["SSLCertificateKeyFile"] = fmt.Sprintf("/etc/pki/tls/private/%s.key", horizon.ServiceName) } + templateParameters := map[string]interface{}{ + "LogFile": horizon.LogFile, + } + cms := []util.Template{ // ConfigMap { diff --git a/pkg/horizon/const.go b/pkg/horizon/const.go index 010f6806..df813b6e 100644 --- a/pkg/horizon/const.go +++ b/pkg/horizon/const.go @@ -38,9 +38,27 @@ const ( // HorizonExtraVolTypeUndefined can be used to label an extraMount which is // not associated to anything in particular HorizonExtraVolTypeUndefined storage.ExtraVolType = "Undefined" + // Horizon is the global ServiceType that refers to all the components deployed // by the horizon-operator Horizon storage.PropagationType = "Horizon" + + //LogFile - + LogFile = "/var/log/horizon/horizon.log" + + // logVolume - + logVolume = "logs" + + DefaultsConfigFileName = "00-config.conf" + // ServiceConfigFileName - Represents service config generated in the operator + ServiceConfigFileName = "01-config.conf" + // CustomConfigFileName - Config snippets inherited by the top-level CR + CustomConfigFileName = "02-config.conf" + // CustomServiceConfigFileName - Config snippets defined for the sub CR + CustomServiceConfigFileName = "03-config.conf" + // CustomServiceConfigSecretsFileName - Snippet generated by Secrets passed + // to the sub CR + CustomServiceConfigSecretsFileName = "04-config.conf" ) // HorizonPropagation is the definition of the Horizon propagation service diff --git a/pkg/horizon/deployment.go b/pkg/horizon/deployment.go index cec0da84..92e0e7f2 100644 --- a/pkg/horizon/deployment.go +++ b/pkg/horizon/deployment.go @@ -135,6 +135,22 @@ func Deployment( Spec: corev1.PodSpec{ ServiceAccountName: instance.RbacResourceName(), Containers: []corev1.Container{ + // the first container in a pod is the default selected + // by oc log so define the log stream container first. + { + Name: instance.Name + "-log", + Command: []string{ + "/bin/bash", + }, + Args: []string{"-c", "tail -n+1 -F " + LogFile}, + Image: instance.Spec.ContainerImage, + SecurityContext: &corev1.SecurityContext{ + RunAsUser: &runAsUser, + }, + Env: env.MergeEnvs([]corev1.EnvVar{}, envVars), + VolumeMounts: []corev1.VolumeMount{GetLogVolumeMount()}, + Resources: instance.Spec.Resources, + }, { Name: ServiceName, Command: []string{ @@ -146,6 +162,7 @@ func Deployment( }, Env: env.MergeEnvs([]corev1.EnvVar{}, envVars), VolumeMounts: volumeMounts, + []corev1.VolumeMount{GetLogVolumeMount()}...), Resources: instance.Spec.Resources, ReadinessProbe: readinessProbe, LivenessProbe: livenessProbe, @@ -158,6 +175,9 @@ func Deployment( }, }, } + deployment.Spec.Template.Spec.Volumes = append(GetVolumes( + instance.Name, + instance.Spec.ExtraMounts), GetLogVolume()) deployment.Spec.Template.Spec.Affinity = affinity.DistributePods( common.AppSelector, []string{ diff --git a/pkg/horizon/volumes.go b/pkg/horizon/volumes.go index 38dc2f57..8e486a83 100644 --- a/pkg/horizon/volumes.go +++ b/pkg/horizon/volumes.go @@ -96,3 +96,22 @@ func getVolumeMounts( } return vm } + +// GetLogVolumeMount - Horizon API LogVolumeMount +func GetLogVolumeMount() corev1.VolumeMount { + return corev1.VolumeMount{ + Name: logVolume, + MountPath: "/var/log/manila", + ReadOnly: false, + } +} + +// GetLogVolume - Horizon API LogVolume +func GetLogVolume() corev1.Volume { + return corev1.Volume{ + Name: logVolume, + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{Medium: ""}, + }, + } +} diff --git a/templates/horizon/config/01-config.conf b/templates/horizon/config/01-config.conf new file mode 100644 index 00000000..e67156c5 --- /dev/null +++ b/templates/horizon/config/01-config.conf @@ -0,0 +1,2 @@ +[DEFAULT] +log_file = {{ .LogFile }} From e636fedc86b95506aaaaedbca5289bf0dc472f57 Mon Sep 17 00:00:00 2001 From: Owen McGonagle Date: Wed, 18 Dec 2024 08:11:04 -0500 Subject: [PATCH 2/2] Fixed typo --- pkg/horizon/volumes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/horizon/volumes.go b/pkg/horizon/volumes.go index 8e486a83..b41bf9be 100644 --- a/pkg/horizon/volumes.go +++ b/pkg/horizon/volumes.go @@ -101,7 +101,7 @@ func getVolumeMounts( func GetLogVolumeMount() corev1.VolumeMount { return corev1.VolumeMount{ Name: logVolume, - MountPath: "/var/log/manila", + MountPath: "/var/log/horizon", ReadOnly: false, } }