Skip to content

Commit

Permalink
Add a conductor ramdisk-logs sidecar
Browse files Browse the repository at this point in the history
This implements the runlogwatch.sh approach of metal3[1] to write any
deployment logs to the console, making them accessable to the end user
via the same mechanism as other openstack service logs.

As part of this change the deploy logs directory needs to be moved to a
directory on a volume shared by the pod. This is now
/var/lib/ironic/ramdisk-logs

Jira: OSPRH-1947

[1] https://github.com/metal3-io/ironic-image/blob/main/scripts/runlogwatch.sh
  • Loading branch information
steveb committed Sep 16, 2024
1 parent 93e827d commit 52d00a2
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 4 deletions.
5 changes: 3 additions & 2 deletions controllers/ironicconductor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,9 @@ func (r *IronicConductorReconciler) generateServiceConfigMaps(
Type: util.TemplateTypeScripts,
InstanceType: instance.Kind,
AdditionalTemplate: map[string]string{
"common.sh": "/common/bin/common.sh",
"get_net_ip": "/common/bin/get_net_ip",
"common.sh": "/common/bin/common.sh",
"get_net_ip": "/common/bin/get_net_ip",
"runlogwatch.sh": "/common/bin/runlogwatch.sh",
},
Labels: cmLabels,
},
Expand Down
20 changes: 20 additions & 0 deletions pkg/ironicconductor/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,15 @@ func StatefulSet(
httpbootEnvVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS")
httpbootEnvVars["CONFIG_HASH"] = env.SetValue(configHash)

ramdiskLogsEnvVars := map[string]env.Setter{}
ramdiskLogsEnvVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS")
ramdiskLogsEnvVars["CONFIG_HASH"] = env.SetValue(configHash)

volumes := GetVolumes(instance)
conductorVolumeMounts := GetVolumeMounts("ironic-conductor")
httpbootVolumeMounts := GetVolumeMounts("httpboot")
dnsmasqVolumeMounts := GetVolumeMounts("dnsmasq")
ramdiskLogsVolumeMounts := GetVolumeMounts("ramdisk-logs")
initVolumeMounts := GetInitVolumeMounts()

// Add the CA bundle
Expand All @@ -163,6 +168,7 @@ func StatefulSet(
conductorVolumeMounts = append(conductorVolumeMounts, instance.Spec.TLS.CreateVolumeMounts(nil)...)
httpbootVolumeMounts = append(httpbootVolumeMounts, instance.Spec.TLS.CreateVolumeMounts(nil)...)
dnsmasqVolumeMounts = append(dnsmasqVolumeMounts, instance.Spec.TLS.CreateVolumeMounts(nil)...)
ramdiskLogsVolumeMounts = append(ramdiskLogsVolumeMounts, instance.Spec.TLS.CreateVolumeMounts(nil)...)
initVolumeMounts = append(initVolumeMounts, instance.Spec.TLS.CreateVolumeMounts(nil)...)
}

Expand Down Expand Up @@ -201,10 +207,24 @@ func StatefulSet(
LivenessProbe: httpbootLivenessProbe,
// StartupProbe: startupProbe,
}
ramdiskLogsContainer := corev1.Container{
Name: "ramdisk-logs",
Command: []string{
"/bin/bash",
},
Args: args,
Image: instance.Spec.ContainerImage,
Env: env.MergeEnvs([]corev1.EnvVar{}, ramdiskLogsEnvVars),
VolumeMounts: ramdiskLogsVolumeMounts,
SecurityContext: &corev1.SecurityContext{
RunAsUser: &runAsUser,
},
}

containers := []corev1.Container{
conductorContainer,
httpbootContainer,
ramdiskLogsContainer,
}

if instance.Spec.ProvisionNetwork != "" {
Expand Down
17 changes: 17 additions & 0 deletions templates/common/bin/runlogwatch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/bash

# Ramdisk logs path
LOG_DIR=${LOG_DIR:-/var/lib/ironic/ramdisk-logs}

while :; do
sleep 5

while read -r fn; do
echo
echo "************ Contents of $fn ramdisk log file bundle **************"
tar -xOzvvf "$fn" | sed -e "s/^/$(basename "$fn"): /"
rm -f "$fn"
# find all *.tar.gz files which are older than six seconds
done < <(find "${LOG_DIR}" -mmin +0.1 -type f -name "*.tar.gz")

done
4 changes: 4 additions & 0 deletions templates/common/config/ironic.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ auth_strategy={{if .Standalone}}noauth{{else}}keystone{{end}}
grub_config_path=EFI/BOOT/grub.cfg
isolinux_bin=/usr/share/syslinux/isolinux.bin


[agent]
deploy_logs_local_path=/var/lib/ironic/ramdisk-logs

{{if .Standalone}}
[service_catalog]
auth_type=none
Expand Down
3 changes: 3 additions & 0 deletions templates/ironicconductor/bin/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ fi
if [ ! -d "/var/lib/ironic/httpboot" ]; then
mkdir /var/lib/ironic/httpboot
fi
if [ ! -d "/var/lib/ironic/ramdisk-logs" ]; then
mkdir /var/lib/ironic/ramdisk-logs
fi
# Build an ESP image
pushd /var/lib/ironic/httpboot
if [ ! -a "esp.img" ]; then
Expand Down
3 changes: 3 additions & 0 deletions templates/ironicconductor/config/ramdisk-logs-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"command": "/usr/local/bin/container-scripts/runlogwatch.sh"
}
4 changes: 2 additions & 2 deletions tests/functional/ironicconductor_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ var _ = Describe("IronicConductor controller", func() {
// Check the resulting deployment fields
Expect(int(*depl.Spec.Replicas)).To(Equal(1))
Expect(depl.Spec.Template.Spec.Volumes).To(HaveLen(6))
Expect(depl.Spec.Template.Spec.Containers).To(HaveLen(2))
Expect(depl.Spec.Template.Spec.Containers).To(HaveLen(3))

// cert deployment volumes
th.AssertVolumeExists(ironicNames.CaBundleSecretName.Name, depl.Spec.Template.Spec.Volumes)
Expand Down Expand Up @@ -309,7 +309,7 @@ var _ = Describe("IronicConductor controller", func() {
// Check the resulting deployment fields
Expect(int(*depl.Spec.Replicas)).To(Equal(1))
Expect(depl.Spec.Template.Spec.Volumes).To(HaveLen(6))
Expect(depl.Spec.Template.Spec.Containers).To(HaveLen(2))
Expect(depl.Spec.Template.Spec.Containers).To(HaveLen(3))

// Grab the current config hash
originalHash := GetEnvVarValue(
Expand Down

0 comments on commit 52d00a2

Please sign in to comment.