Skip to content

Commit da49f70

Browse files
Merge pull request #20260 from Miciah/router-add-oc-adm-router-dash-dash-syslog-dash-sidecar-flag
router: Add oc adm router --extended-logging flag
2 parents dab335c + 9d6a4c2 commit da49f70

File tree

4 files changed

+91
-3
lines changed

4 files changed

+91
-3
lines changed

contrib/completions/bash/oc

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/completions/zsh/oc

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

images/router/haproxy/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
FROM openshift/origin-cli
77

8-
RUN INSTALL_PKGS="haproxy18" && \
8+
RUN INSTALL_PKGS="haproxy18 rsyslog" && \
99
yum install -y $INSTALL_PKGS && \
1010
rpm -V $INSTALL_PKGS && \
1111
yum clean all && \

pkg/oc/admin/router/router.go

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ type RouterConfig struct {
154154
// network namespace or the container's.
155155
HostNetwork bool
156156

157+
// ExtendedLogging specifies whether to inject a sidecar container
158+
// running rsyslogd into the router pod and configure the router to send
159+
// access logs to that sidecar.
160+
ExtendedLogging bool
161+
157162
// HostPorts will expose host ports for each router port if host networking is
158163
// not set.
159164
HostPorts bool
@@ -242,6 +247,12 @@ const (
242247

243248
// Default stats port.
244249
defaultStatsPort = 1936
250+
251+
rsyslogConfigurationFile = `$ModLoad imuxsock
252+
$SystemLogSocketName /var/lib/rsyslog/rsyslog.sock
253+
$ModLoad omstdout.so
254+
*.* :omstdout:
255+
`
245256
)
246257

247258
// NewCmdRouter implements the OpenShift CLI router command.
@@ -294,6 +305,7 @@ func NewCmdRouter(f kcmdutil.Factory, parentName, name string, out, errout io.Wr
294305
cmd.Flags().IntVar(&cfg.StatsPort, "stats-port", cfg.StatsPort, "If the underlying router implementation can provide statistics this is a hint to expose it on this port. Specify 0 if you want to turn off exposing the statistics.")
295306
cmd.Flags().StringVar(&cfg.StatsPassword, "stats-password", cfg.StatsPassword, "If the underlying router implementation can provide statistics this is the requested password for auth. If not set a password will be generated. Not available for external appliance based routers (e.g. F5)")
296307
cmd.Flags().StringVar(&cfg.StatsUsername, "stats-user", cfg.StatsUsername, "If the underlying router implementation can provide statistics this is the requested username for auth. Not available for external appliance based routers (e.g. F5)")
308+
cmd.Flags().BoolVar(&cfg.ExtendedLogging, "extended-logging", cfg.ExtendedLogging, "If true, then configure the router with additional logging.")
297309
cmd.Flags().BoolVar(&cfg.HostNetwork, "host-network", cfg.HostNetwork, "If true (the default), then use host networking rather than using a separate container network stack. Not required for external appliance based routers (e.g. F5)")
298310
cmd.Flags().BoolVar(&cfg.HostPorts, "host-ports", cfg.HostPorts, "If true (the default), when not using host networking host ports will be exposed. Not required for external appliance based routers (e.g. F5)")
299311
cmd.Flags().StringVar(&cfg.ExternalHost, "external-host", cfg.ExternalHost, "If the underlying router implementation connects with an external host, this is the external host's hostname.")
@@ -717,11 +729,50 @@ func RunCmdRouter(f kcmdutil.Factory, cmd *cobra.Command, out, errout io.Writer,
717729
}
718730
env.Add(app.Environment{"DEFAULT_CERTIFICATE_DIR": defaultCertificateDir})
719731
var certName = fmt.Sprintf("%s-certs", cfg.Name)
720-
secrets, volumes, mounts, err := generateSecretsConfig(cfg, namespace, defaultCert, certName)
732+
secrets, volumes, routerMounts, err := generateSecretsConfig(cfg, namespace, defaultCert, certName)
721733
if err != nil {
722734
return fmt.Errorf("router could not be created: %v", err)
723735
}
724736

737+
var configMaps []*kapi.ConfigMap
738+
739+
if cfg.Type == "haproxy-router" && cfg.ExtendedLogging {
740+
configMaps = append(configMaps, &kapi.ConfigMap{
741+
ObjectMeta: metav1.ObjectMeta{
742+
Name: "rsyslog-config",
743+
},
744+
Data: map[string]string{
745+
"rsyslog.conf": rsyslogConfigurationFile,
746+
},
747+
})
748+
volumes = append(volumes, kapi.Volume{
749+
Name: "rsyslog-config",
750+
VolumeSource: kapi.VolumeSource{
751+
ConfigMap: &kapi.ConfigMapVolumeSource{
752+
LocalObjectReference: kapi.LocalObjectReference{
753+
Name: "rsyslog-config",
754+
},
755+
},
756+
},
757+
})
758+
// Ideally we would use a Unix domain socket in the abstract
759+
// namespace, but rsyslog does not support that, so we need a
760+
// filesystem that is common to the router and syslog
761+
// containers.
762+
volumes = append(volumes, kapi.Volume{
763+
Name: "rsyslog-socket",
764+
VolumeSource: kapi.VolumeSource{
765+
EmptyDir: &kapi.EmptyDirVolumeSource{},
766+
},
767+
})
768+
routerMounts = append(routerMounts, kapi.VolumeMount{
769+
Name: "rsyslog-socket",
770+
MountPath: "/var/lib/rsyslog",
771+
})
772+
773+
env["ROUTER_SYSLOG_ADDRESS"] = "/var/lib/rsyslog/rsyslog.sock"
774+
}
775+
725776
livenessProbe := generateLivenessProbeConfig(cfg, ports)
726777
readinessProbe := generateReadinessProbeConfig(cfg, ports)
727778

@@ -741,7 +792,7 @@ func RunCmdRouter(f kcmdutil.Factory, cmd *cobra.Command, out, errout io.Writer,
741792
LivenessProbe: livenessProbe,
742793
ReadinessProbe: readinessProbe,
743794
ImagePullPolicy: kapi.PullIfNotPresent,
744-
VolumeMounts: mounts,
795+
VolumeMounts: routerMounts,
745796
Resources: kapi.ResourceRequirements{
746797
Requests: kapi.ResourceList{
747798
kapi.ResourceCPU: resource.MustParse("100m"),
@@ -750,11 +801,44 @@ func RunCmdRouter(f kcmdutil.Factory, cmd *cobra.Command, out, errout io.Writer,
750801
},
751802
},
752803
}
804+
if cfg.Type == "haproxy-router" && cfg.ExtendedLogging {
805+
containers = append(containers, kapi.Container{
806+
Name: "syslog",
807+
Image: image,
808+
Command: []string{
809+
"/sbin/rsyslogd", "-n",
810+
// TODO: Once we have rsyslog 8.32 or later,
811+
// we can switch to -i NONE.
812+
"-i", "/tmp/rsyslog.pid",
813+
"-f", "/etc/rsyslog/rsyslog.conf",
814+
},
815+
ImagePullPolicy: kapi.PullIfNotPresent,
816+
VolumeMounts: []kapi.VolumeMount{
817+
{
818+
Name: "rsyslog-config",
819+
MountPath: "/etc/rsyslog",
820+
},
821+
{
822+
Name: "rsyslog-socket",
823+
MountPath: "/var/lib/rsyslog",
824+
},
825+
},
826+
Resources: kapi.ResourceRequirements{
827+
Requests: kapi.ResourceList{
828+
kapi.ResourceCPU: resource.MustParse("100m"),
829+
kapi.ResourceMemory: resource.MustParse("256Mi"),
830+
},
831+
},
832+
})
833+
}
753834

754835
objects := []runtime.Object{}
755836
for _, s := range secrets {
756837
objects = append(objects, s)
757838
}
839+
for _, cm := range configMaps {
840+
objects = append(objects, cm)
841+
}
758842

759843
objects = append(objects,
760844
&kapi.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: cfg.ServiceAccount}},

0 commit comments

Comments
 (0)