Skip to content

Commit

Permalink
Remove initcontainer and add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkisaolamb committed Jan 23, 2024
1 parent aa65e13 commit ddbdc9c
Show file tree
Hide file tree
Showing 10 changed files with 539 additions and 718 deletions.
953 changes: 490 additions & 463 deletions controllers/placementapi_controller.go

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions pkg/placement/dbsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,5 @@ func DbSyncJob(

job.Spec.Template.Spec.Volumes = getVolumes(ServiceName)

initContainerDetails := APIDetails{
ContainerImage: instance.Spec.ContainerImage,
DatabaseHost: instance.Status.DatabaseHostname,
DatabaseUser: instance.Spec.DatabaseUser,
DatabaseName: DatabaseName,
OSPSecret: instance.Spec.Secret,
DBPasswordSelector: instance.Spec.PasswordSelectors.Database,
UserPasswordSelector: instance.Spec.PasswordSelectors.Service,
VolumeMounts: getInitVolumeMounts(),
}
job.Spec.Template.Spec.InitContainers = initContainer(initContainerDetails)

return job
}
12 changes: 0 additions & 12 deletions pkg/placement/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,5 @@ func Deployment(
deployment.Spec.Template.Spec.NodeSelector = instance.Spec.NodeSelector
}

initContainerDetails := APIDetails{
ContainerImage: instance.Spec.ContainerImage,
DatabaseHost: instance.Status.DatabaseHostname,
DatabaseUser: instance.Spec.DatabaseUser,
DatabaseName: DatabaseName,
OSPSecret: instance.Spec.Secret,
DBPasswordSelector: instance.Spec.PasswordSelectors.Database,
UserPasswordSelector: instance.Spec.PasswordSelectors.Service,
VolumeMounts: getInitVolumeMounts(),
}
deployment.Spec.Template.Spec.InitContainers = initContainer(initContainerDetails)

return deployment
}
96 changes: 0 additions & 96 deletions pkg/placement/initcontainer.go

This file was deleted.

36 changes: 0 additions & 36 deletions templates/common/common.sh

This file was deleted.

46 changes: 0 additions & 46 deletions templates/placementapi/bin/init.sh

This file was deleted.

7 changes: 4 additions & 3 deletions templates/placementapi/config/placement.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ log_file = {{ .log_file }}
{{end}}
debug = true

[placement_database]
connection = mysql+pymysql://{{ .DBUser }}:{{ .DBPassword}}@{{ .DBAddress }}/{{ .DBName }}

[api]
auth_strategy = keystone

Expand All @@ -19,6 +22,4 @@ username = {{ .ServiceUser }}
www_authenticate_uri = {{ .KeystonePublicURL }}
auth_url = {{ .KeystoneInternalURL }}
auth_type = password
interface = internal

[placement_database]
interface = internal
23 changes: 23 additions & 0 deletions test/kuttl/test-suites/default/output/kuttl-test-placement.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "",
"tests": 1,
"failures": 0,
"time": "163.223",
"testsuite": [
{
"tests": 1,
"failures": 0,
"timestamp": "2024-01-03T14:17:48.154181969+01:00",
"time": "0.000",
"name": "tests/kuttl/test-suites/default/",
"testcase": [
{
"classname": "default",
"name": "deps",
"timestamp": "2024-01-03T14:17:48.154297214+01:00",
"time": "0.000"
}
]
}
]
}
46 changes: 22 additions & 24 deletions tests/functional/placementapi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ var _ = Describe("PlacementAPI controller", func() {
condition.InputReadyCondition,
corev1.ConditionFalse,
)
th.ExpectCondition(
names.PlacementAPIName,
ConditionGetterFunc(PlacementConditionGetter),
condition.RoleBindingReadyCondition,
corev1.ConditionTrue,
)
th.ExpectCondition(
names.PlacementAPIName,
ConditionGetterFunc(PlacementConditionGetter),
condition.RoleReadyCondition,
corev1.ConditionTrue,
)
th.ExpectCondition(
names.PlacementAPIName,
ConditionGetterFunc(PlacementConditionGetter),
condition.ServiceAccountReadyCondition,
corev1.ConditionTrue,
)
unknownConditions := []condition.Type{
condition.DBReadyCondition,
condition.DBSyncReadyCondition,
Expand All @@ -96,14 +114,11 @@ var _ = Describe("PlacementAPI controller", func() {
condition.KeystoneServiceReadyCondition,
condition.KeystoneEndpointReadyCondition,
condition.NetworkAttachmentsReadyCondition,
condition.ServiceAccountReadyCondition,
condition.RoleReadyCondition,
condition.RoleBindingReadyCondition,
}

placement := GetPlacementAPI(names.PlacementAPIName)
// +2 as InputReady and Ready is False asserted above
Expect(placement.Status.Conditions).To(HaveLen(len(unknownConditions) + 2))
// +5 as InputReady, Ready, Service and Role are ready is False asserted above
Expect(placement.Status.Conditions).To(HaveLen(len(unknownConditions) + 5))

for _, cond := range unknownConditions {
th.ExpectCondition(
Expand Down Expand Up @@ -234,6 +249,8 @@ var _ = Describe("PlacementAPI controller", func() {
ContainSubstring("www_authenticate_uri = %s", keystoneAPI.Status.APIEndpoints["public"]))
Expect(cm.Data["placement.conf"]).Should(
ContainSubstring("username = placement"))
Expect(cm.Data["placement.conf"]).Should(
ContainSubstring("connection = mysql+pymysql://placement:PlacementDatabasePassword@/placement"))
})

It("creates service account, role and rolebindig", func() {
Expand Down Expand Up @@ -361,27 +378,8 @@ var _ = Describe("PlacementAPI controller", func() {

job := th.GetJob(names.DBSyncJobName)
Expect(job.Spec.Template.Spec.Volumes).To(HaveLen(4))
Expect(job.Spec.Template.Spec.InitContainers).To(HaveLen(1))
Expect(job.Spec.Template.Spec.Containers).To(HaveLen(1))

init := job.Spec.Template.Spec.InitContainers[0]
Expect(init.VolumeMounts).To(HaveLen(4))
Expect(init.Args[1]).To(ContainSubstring("init.sh"))
Expect(init.Image).To(Equal("quay.io/podified-antelope-centos9/openstack-placement-api:current-podified"))
env := &corev1.EnvVar{}
Expect(init.Env).To(ContainElement(HaveField("Name", "DatabaseHost"), env))
Expect(env.Value).To(Equal("hostname-for-openstack"))
Expect(init.Env).To(ContainElement(HaveField("Name", "DatabaseUser"), env))
Expect(env.Value).To(Equal("placement"))
Expect(init.Env).To(ContainElement(HaveField("Name", "DatabaseName"), env))
Expect(env.Value).To(Equal("placement"))
Expect(init.Env).To(ContainElement(HaveField("Name", "DatabasePassword"), env))
Expect(env.ValueFrom.SecretKeyRef.LocalObjectReference.Name).To(Equal(SecretName))
Expect(env.ValueFrom.SecretKeyRef.Key).To(Equal("PlacementDatabasePassword"))
Expect(init.Env).To(ContainElement(HaveField("Name", "PlacementPassword"), env))
Expect(env.ValueFrom.SecretKeyRef.LocalObjectReference.Name).To(Equal(SecretName))
Expect(env.ValueFrom.SecretKeyRef.Key).To(Equal("PlacementPassword"))

container := job.Spec.Template.Spec.Containers[0]
Expect(container.VolumeMounts).To(HaveLen(4))
Expect(container.Image).To(Equal("quay.io/podified-antelope-centos9/openstack-placement-api:current-podified"))
Expand Down
26 changes: 0 additions & 26 deletions tests/kuttl/common/assert_sample_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,32 +177,6 @@ spec:
successThreshold: 1
timeoutSeconds: 5
resources: {}
initContainers:
- args:
- -c
- /usr/local/bin/container-scripts/init.sh
command:
- /bin/bash
env:
- name: DatabasePassword
valueFrom:
secretKeyRef:
key: PlacementDatabasePassword
name: osp-secret
- name: PlacementPassword
valueFrom:
secretKeyRef:
key: PlacementPassword
name: osp-secret
- name: DatabaseHost
value: openstack
- name: DatabaseName
value: placement
- name: DatabaseUser
value: placement
imagePullPolicy: IfNotPresent
name: init
resources: {}
restartPolicy: Always
securityContext: {}
serviceAccount: placement-placement
Expand Down

0 comments on commit ddbdc9c

Please sign in to comment.