Skip to content

Commit ed3136b

Browse files
Expose placement-api logs as the pod logs
1 parent 3f7cf6c commit ed3136b

File tree

11 files changed

+114
-56
lines changed

11 files changed

+114
-56
lines changed

api/bases/placement.openstack.org_placementapis.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ spec:
8888
additionalProperties:
8989
type: string
9090
description: 'ConfigOverwrite - interface to overwrite default config
91-
files like e.g. logging.conf or policy.json. But can also be used
92-
to add additional files. Those get added to the service config dir
93-
in /etc/<service> . TODO: -> implement'
91+
files like e.g. policy.json. But can also be used to add additional
92+
files. Those get added to the service config dir in /etc/<service>
93+
. TODO: -> implement'
9494
type: object
9595
networkAttachments:
9696
description: NetworkAttachments is a list of NetworkAttachment resource

api/v1beta1/placementapi_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ type PlacementAPISpec struct {
9898
CustomServiceConfig string `json:"customServiceConfig"`
9999

100100
// +kubebuilder:validation:Optional
101-
// ConfigOverwrite - interface to overwrite default config files like e.g. logging.conf or policy.json.
101+
// ConfigOverwrite - interface to overwrite default config files like e.g. policy.json.
102102
// But can also be used to add additional files. Those get added to the service config dir in /etc/<service> .
103103
// TODO: -> implement
104104
DefaultConfigOverwrite map[string]string `json:"defaultConfigOverwrite,omitempty"`

config/crd/bases/placement.openstack.org_placementapis.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ spec:
8888
additionalProperties:
8989
type: string
9090
description: 'ConfigOverwrite - interface to overwrite default config
91-
files like e.g. logging.conf or policy.json. But can also be used
92-
to add additional files. Those get added to the service config dir
93-
in /etc/<service> . TODO: -> implement'
91+
files like e.g. policy.json. But can also be used to add additional
92+
files. Those get added to the service config dir in /etc/<service>
93+
. TODO: -> implement'
9494
type: object
9595
networkAttachments:
9696
description: NetworkAttachments is a list of NetworkAttachment resource

controllers/placementapi_controller.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ func (r *PlacementAPIReconciler) generateServiceConfigMaps(
792792

793793
// customData hold any customization for the service.
794794
// custom.conf is going to /etc/<service>/<service>.conf.d
795-
// all other files get placed into /etc/<service> to allow overwrite of e.g. logging.conf or policy.json
795+
// all other files get placed into /etc/<service> to allow overwrite of e.g. policy.json
796796
// TODO: make sure custom.conf can not be overwritten
797797
customData := map[string]string{common.CustomServiceConfigFileName: instance.Spec.CustomServiceConfig}
798798
for key, data := range instance.Spec.DefaultConfigOverwrite {
@@ -811,10 +811,12 @@ func (r *PlacementAPIReconciler) generateServiceConfigMaps(
811811
if err != nil {
812812
return err
813813
}
814-
templateParameters := make(map[string]interface{})
815-
templateParameters["ServiceUser"] = instance.Spec.ServiceUser
816-
templateParameters["KeystoneInternalURL"] = keystoneInternalURL
817-
templateParameters["KeystonePublicURL"] = keystonePublicURL
814+
templateParameters := map[string]interface{}{
815+
"ServiceUser": instance.Spec.ServiceUser,
816+
"KeystoneInternalURL": keystoneInternalURL,
817+
"KeystonePublicURL": keystonePublicURL,
818+
"log_file": "/var/log/placement/placement-api.log",
819+
}
818820

819821
cms := []util.Template{
820822
// ScriptsConfigMap

pkg/placement/deployment.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ func Deployment(
9898
Spec: corev1.PodSpec{
9999
ServiceAccountName: instance.RbacResourceName(),
100100
Containers: []corev1.Container{
101+
{
102+
Name: ServiceName + "-log",
103+
Command: []string{
104+
"/usr/bin/dumb-init",
105+
},
106+
Args: []string{
107+
"--single-child",
108+
"--",
109+
"/usr/bin/tail",
110+
"-n+1",
111+
"-F",
112+
"/var/log/placement/placement-api.log",
113+
},
114+
Image: instance.Spec.ContainerImage,
115+
SecurityContext: &corev1.SecurityContext{
116+
RunAsUser: ptr.To(PlacementUserID),
117+
},
118+
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
119+
VolumeMounts: getVolumeMounts("api"),
120+
Resources: instance.Spec.Resources,
121+
ReadinessProbe: readinessProbe,
122+
LivenessProbe: livenessProbe,
123+
},
101124
{
102125
Name: ServiceName + "-api",
103126
Command: []string{

pkg/placement/volumes.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ func getVolumes(name string) []corev1.Volume {
5353
EmptyDir: &corev1.EmptyDirVolumeSource{Medium: ""},
5454
},
5555
},
56+
{
57+
Name: "logs",
58+
VolumeSource: corev1.VolumeSource{
59+
EmptyDir: &corev1.EmptyDirVolumeSource{Medium: ""},
60+
},
61+
},
5662
}
5763

5864
}
@@ -75,6 +81,11 @@ func getInitVolumeMounts() []corev1.VolumeMount {
7581
MountPath: "/var/lib/config-data/merged",
7682
ReadOnly: false,
7783
},
84+
{
85+
Name: "logs",
86+
MountPath: "/var/log/placement",
87+
ReadOnly: false,
88+
},
7889
}
7990
}
8091

@@ -97,5 +108,10 @@ func getVolumeMounts(serviceName string) []corev1.VolumeMount {
97108
SubPath: "placement-" + serviceName + "-config.json",
98109
ReadOnly: true,
99110
},
111+
{
112+
Name: "logs",
113+
MountPath: "/var/log/placement",
114+
ReadOnly: false,
115+
},
100116
}
101117
}

templates/placementapi/config/logging.conf

Lines changed: 0 additions & 34 deletions
This file was deleted.

templates/placementapi/config/placement-api-config.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
"dest": "/etc/httpd/conf/httpd.conf",
1919
"owner": "apache",
2020
"perm": "0644"
21-
},
22-
{
23-
"source": "/var/lib/config-data/merged/logging.conf",
24-
"dest": "/etc/placement/logging.conf",
25-
"owner": "placement",
26-
"perm": "0600"
2721
}
2822
],
2923
"permissions": [

templates/placementapi/config/placement.conf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
[DEFAULT]
2-
log_config_append = /etc/placement/logging.conf
2+
# enable log rotation in oslo config by default
3+
max_logfile_count=5
4+
max_logfile_size_mb=50
5+
log_rotation_type=size
6+
{{if (index . "log_file") }}
7+
log_file = {{ .log_file }}
8+
{{end}}
9+
debug = true
310

411
[api]
512
auth_strategy = keystone

tests/functional/placementapi_controller_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,12 @@ var _ = Describe("PlacementAPI controller", func() {
326326
)
327327

328328
job := th.GetJob(names.DBSyncJobName)
329-
Expect(job.Spec.Template.Spec.Volumes).To(HaveLen(3))
329+
Expect(job.Spec.Template.Spec.Volumes).To(HaveLen(4))
330330
Expect(job.Spec.Template.Spec.InitContainers).To(HaveLen(1))
331331
Expect(job.Spec.Template.Spec.Containers).To(HaveLen(1))
332332

333333
init := job.Spec.Template.Spec.InitContainers[0]
334-
Expect(init.VolumeMounts).To(HaveLen(3))
334+
Expect(init.VolumeMounts).To(HaveLen(4))
335335
Expect(init.Args[1]).To(ContainSubstring("init.sh"))
336336
Expect(init.Image).To(Equal("quay.io/podified-antelope-centos9/openstack-placement-api:current-podified"))
337337
env := &corev1.EnvVar{}
@@ -349,7 +349,7 @@ var _ = Describe("PlacementAPI controller", func() {
349349
Expect(env.ValueFrom.SecretKeyRef.Key).To(Equal("PlacementPassword"))
350350

351351
container := job.Spec.Template.Spec.Containers[0]
352-
Expect(container.VolumeMounts).To(HaveLen(3))
352+
Expect(container.VolumeMounts).To(HaveLen(4))
353353
Expect(container.Image).To(Equal("quay.io/podified-antelope-centos9/openstack-placement-api:current-podified"))
354354

355355
th.SimulateJobSuccess(names.DBSyncJobName)
@@ -381,6 +381,8 @@ var _ = Describe("PlacementAPI controller", func() {
381381
Expect(int(*deployment.Spec.Replicas)).To(Equal(1))
382382
Expect(deployment.Spec.Selector.MatchLabels).To(Equal(map[string]string{"service": "placement"}))
383383
Expect(deployment.Spec.Template.Spec.ServiceAccountName).To(Equal(names.ServiceAccountName.Name))
384+
Expect(len(deployment.Spec.Template.Spec.Containers)).To(Equal(2))
385+
384386
th.SimulateDeploymentReplicaReady(names.DeploymentName)
385387

386388
th.ExpectCondition(

0 commit comments

Comments
 (0)