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 2, 2024
1 parent 18fc0ca commit bb6f196
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 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
6 changes: 2 additions & 4 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
4 changes: 2 additions & 2 deletions tests/kuttl/common/assert_sample_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ spec:
- mountPath: /usr/local/bin/container-scripts
name: scripts
readOnly: true
- mountPath: /var/log/placement
name: logs
- mountPath: /var/lib/config-data/
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

0 comments on commit bb6f196

Please sign in to comment.