Skip to content

Commit

Permalink
Fix scripts volum issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkisaolamb committed Feb 5, 2024
1 parent 04516ed commit fa32909
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 26 deletions.
21 changes: 12 additions & 9 deletions controllers/placementapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ func (r *PlacementAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request

apiEndpoints, result, err := r.ensureServiceExposed(ctx, h, instance)

if err != nil {
if (err != nil || result != ctrl.Result{}) {
// We can ignore RequeueAfter as we are watching the Service resource
// but we have to return while waiting for the service to be exposed
return ctrl.Result{}, err
}

Expand All @@ -441,10 +443,10 @@ func (r *PlacementAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request
}

result, err = r.ensureKeystoneEndpoint(ctx, h, instance, apiEndpoints)
if err != nil {
if (err != nil || result != ctrl.Result{}) {
// We can ignore RequeueAfter as we are watching the KeystoneEndpoint resource
return ctrl.Result{}, err
}

result, err = r.ensureDbSync(ctx, instance, h, serviceAnnotations)
if (err != nil || result != ctrl.Result{}) {
return result, err
Expand Down Expand Up @@ -482,6 +484,7 @@ func (r *PlacementAPIReconciler) ensureServiceExposed(
}
apiEndpoints := make(map[string]string)

serviceLabels := getServiceLabels(instance)
for endpointType, data := range placementEndpoints {
endpointTypeStr := string(endpointType)
endpointName := placement.ServiceName + "-" + endpointTypeStr
Expand All @@ -492,7 +495,7 @@ func (r *PlacementAPIReconciler) ensureServiceExposed(
}

exportLabels := util.MergeStringMaps(
getServiceLabels(instance),
serviceLabels,
map[string]string{
service.AnnotationEndpointKey: endpointTypeStr,
},
Expand All @@ -504,7 +507,7 @@ func (r *PlacementAPIReconciler) ensureServiceExposed(
Name: endpointName,
Namespace: instance.Namespace,
Labels: exportLabels,
Selector: getServiceLabels(instance),
Selector: serviceLabels,
Port: service.GenericServicePort{
Name: endpointName,
Port: data.Port,
Expand All @@ -522,7 +525,7 @@ func (r *PlacementAPIReconciler) ensureServiceExposed(
condition.ExposeServiceReadyErrorMessage,
err.Error()))

return nil, ctrl.Result{}, err
return apiEndpoints, ctrl.Result{}, err
}

svc.AddAnnotation(map[string]string{
Expand Down Expand Up @@ -554,14 +557,14 @@ func (r *PlacementAPIReconciler) ensureServiceExposed(
condition.ExposeServiceReadyErrorMessage,
err.Error()))

return nil, ctrlResult, err
return apiEndpoints, ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.ExposeServiceReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.ExposeServiceReadyRunningMessage))
return nil, ctrlResult, nil
return apiEndpoints, ctrlResult, nil
}
// create service - end

Expand All @@ -574,7 +577,7 @@ func (r *PlacementAPIReconciler) ensureServiceExposed(
apiEndpoints[string(endpointType)], err = svc.GetAPIEndpoint(
svcOverride.EndpointURL, data.Protocol, data.Path)
if err != nil {
return nil, ctrl.Result{}, err
return apiEndpoints, ctrl.Result{}, err
}
}

Expand Down
8 changes: 3 additions & 5 deletions pkg/placement/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ func getVolumes(name string) []corev1.Volume {
{
Name: "scripts",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
Secret: &corev1.SecretVolumeSource{
DefaultMode: &scriptsVolumeDefaultMode,
LocalObjectReference: corev1.LocalObjectReference{
Name: name + "-scripts",
},
SecretName: name + "-scripts",
},
},
},
Expand Down Expand Up @@ -70,7 +68,7 @@ func getVolumeMounts(serviceName string) []corev1.VolumeMount {
},
{
Name: "config-data",
MountPath: "/var/lib/config-data/",
MountPath: "/var/lib/config-data/merged",
ReadOnly: false,
},
{
Expand Down
8 changes: 4 additions & 4 deletions templates/placementapi/config/placement-api-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
"command": "/usr/sbin/httpd -DFOREGROUND",
"config_files": [
{
"source": "/var/lib/config-data/placement.conf",
"source": "/var/lib/config-data/merged/placement.conf",
"dest": "/etc/placement/placement.conf",
"owner": "placement",
"perm": "0600"
},
{
"source": "/var/lib/config-data/httpd.conf",
"source": "/var/lib/config-data/merged/httpd.conf",
"dest": "/etc/httpd/conf/httpd.conf",
"owner": "apache",
"perm": "0644"
},
{
"source": "/var/lib/config-data/custom.conf",
"source": "/var/lib/config-data/merged/custom.conf",
"dest": "/etc/placement/placement.conf.d/custom.conf",
"owner": "placement",
"perm": "0600"
},
{
"source": "/var/lib/config-data/ssl.conf",
"source": "/var/lib/config-data/merged/ssl.conf",
"dest": "/etc/httpd/conf.d/ssl.conf",
"owner": "apache",
"perm": "0644"
Expand Down
4 changes: 2 additions & 2 deletions templates/placementapi/config/placement-dbsync-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"command": "placement-manage db sync",
"config_files": [
{
"source": "/var/lib/config-data/placement.conf",
"source": "/var/lib/config-data/merged/placement.conf",
"dest": "/etc/placement/placement.conf",
"owner": "placement",
"perm": "0600"
},
{
"source": "/var/lib/config-data/custom.conf",
"source": "/var/lib/config-data/merged/custom.conf",
"dest": "/etc/placement/placement.conf.d/custom.conf",
"owner": "placement",
"perm": "0600"
Expand Down
6 changes: 3 additions & 3 deletions tests/kuttl/common/assert_sample_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ spec:
- mountPath: /usr/local/bin/container-scripts
name: scripts
readOnly: true
- mountPath: /var/lib/config-data/
- mountPath: /var/log/placement
name: logs
- mountPath: /var/lib/config-data/merged
name: config-data
- mountPath: /var/lib/kolla/config_files/config.json
name: config-data
readOnly: true
subPath: placement-api-config.json
- mountPath: /var/log/placement
name: logs
- args:
- -c
- /usr/local/bin/kolla_start
Expand Down
21 changes: 21 additions & 0 deletions tests/kuttl/common/errors_cleanup_placement.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ kind: Deployment
metadata:
name: placement
---
# the openshift annotations can't be checked through the deployment above
apiVersion: v1
kind: Pod
metadata:
annotations:
openshift.io/scc: anyuid
labels:
service: placement
---
apiVersion: v1
kind: Service
metadata:
Expand Down Expand Up @@ -62,6 +71,18 @@ spec:
---
apiVersion: v1
kind: Secret
metadata:
labels:
placement.openstack.org/name: placement
name: placement-scripts
ownerReferences:
- blockOwnerDeletion: true
controller: true
kind: PlacementAPI
name: placement
---
apiVersion: v1
kind: Secret
metadata:
labels:
placement.openstack.org/name: placement
Expand Down
6 changes: 3 additions & 3 deletions tests/kuttl/tests/placement_deploy_tls/03-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ spec:
- mountPath: /usr/local/bin/container-scripts
name: scripts
readOnly: true
- mountPath: /var/lib/config-data
- mountPath: /var/log/placement
name: logs
- mountPath: /var/lib/config-data/merged
name: config-data
- mountPath: /var/lib/kolla/config_files/config.json
name: config-data
readOnly: true
subPath: placement-api-config.json
- mountPath: /var/log/placement
name: logs
- mountPath: /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
name: combined-ca-bundle
readOnly: true
Expand Down

0 comments on commit fa32909

Please sign in to comment.