@@ -68,6 +68,42 @@ func (c *Cluster) listResources() error {
6868 return nil
6969}
7070
71+ func hasSidecar (sidecars []cpov1.Sidecar , name string ) bool {
72+ for _ , s := range sidecars {
73+ if s .Name == name {
74+ return true
75+ }
76+ }
77+ return false
78+ }
79+
80+ func (c * Cluster ) generateExporterSidecar () * cpov1.Sidecar {
81+ monitor := c .Spec .Monitoring
82+ sidecar := & cpov1.Sidecar {
83+ Name : "postgres-exporter" ,
84+ DockerImage : monitor .Image ,
85+ Ports : []v1.ContainerPort {
86+ {
87+ ContainerPort : monitorPort ,
88+ Protocol : v1 .ProtocolTCP ,
89+ },
90+ },
91+ Env : c .generateMonitoringEnvVars (),
92+ SecurityContext : & v1.SecurityContext {
93+ AllowPrivilegeEscalation : c .OpConfig .Resources .SpiloAllowPrivilegeEscalation ,
94+ Privileged : & c .OpConfig .Resources .SpiloPrivileged ,
95+ ReadOnlyRootFilesystem : util .True (),
96+ Capabilities : generateCapabilities (c .OpConfig .AdditionalPodCapabilities ),
97+ },
98+ }
99+
100+ if c .OpConfig .EnableReadinessProbe {
101+ sidecar .ReadinessProbe = generateExporterReadinessProbe ()
102+ }
103+
104+ return sidecar
105+ }
106+
71107func (c * Cluster ) createStatefulSet () (* appsv1.StatefulSet , error ) {
72108 c .setProcessName ("creating statefulset" )
73109 // check if it's allowed that spec contains initContainers
@@ -82,25 +118,11 @@ func (c *Cluster) createStatefulSet() (*appsv1.StatefulSet, error) {
82118 }
83119
84120 if c .Spec .Monitoring != nil {
85- monitor := c .Spec .Monitoring
86- sidecar := & cpov1.Sidecar {
87- Name : "postgres-exporter" ,
88- DockerImage : monitor .Image ,
89- Ports : []v1.ContainerPort {
90- {
91- ContainerPort : monitorPort ,
92- Protocol : v1 .ProtocolTCP ,
93- },
94- },
95- Env : c .generateMonitoringEnvVars (),
96- SecurityContext : & v1.SecurityContext {
97- AllowPrivilegeEscalation : c .OpConfig .Resources .SpiloAllowPrivilegeEscalation ,
98- Privileged : & c .OpConfig .Resources .SpiloPrivileged ,
99- ReadOnlyRootFilesystem : util .True (),
100- Capabilities : generateCapabilities (c .OpConfig .AdditionalPodCapabilities ),
101- },
121+ if exporterSidecar := c .generateExporterSidecar (); exporterSidecar != nil {
122+ if ! hasSidecar (c .Spec .Sidecars , "postgres-exporter" ) {
123+ c .Spec .Sidecars = append (c .Spec .Sidecars , * exporterSidecar )
124+ }
102125 }
103- c .Spec .Sidecars = append (c .Spec .Sidecars , * sidecar ) //populate the sidecar spec so that the sidecar is automatically created
104126 }
105127
106128 statefulSetSpec , err := c .generateStatefulSet (& c .Spec )
0 commit comments