diff --git a/controllers/horizon_controller.go b/controllers/horizon_controller.go index 4a7db03..ee31dc8 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 010f680..df813b6 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 cec0da8..92e0e7f 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 38dc2f5..b41bf9b 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/horizon", + 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 0000000..e67156c --- /dev/null +++ b/templates/horizon/config/01-config.conf @@ -0,0 +1,2 @@ +[DEFAULT] +log_file = {{ .LogFile }}