-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56dea3d
commit f67ed5e
Showing
6 changed files
with
229 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package nova | ||
|
||
import ( | ||
batchv1 "k8s.io/api/batch/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/utils/ptr" | ||
|
||
"github.com/openstack-k8s-operators/lib-common/modules/common/env" | ||
novav1 "github.com/openstack-k8s-operators/nova-operator/api/v1beta1" | ||
) | ||
|
||
func CellDeleteJob( | ||
instance *novav1.Nova, | ||
cell *novav1.NovaCell, | ||
configName string, | ||
scriptName string, | ||
inputHash string, | ||
labels map[string]string, | ||
) *batchv1.Job { | ||
args := []string{"-c", KollaServiceCommand} | ||
|
||
envVars := map[string]env.Setter{} | ||
envVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS") | ||
envVars["KOLLA_BOOTSTRAP"] = env.SetValue("true") | ||
envVars["CELL_NAME"] = env.SetValue(cell.Spec.CellName) | ||
|
||
// This is stored in the Job so that if the input of the job changes | ||
// then it results in a new job hash and therefore lib-common will re-run | ||
// the job | ||
envVars["INPUT_HASH"] = env.SetValue(inputHash) | ||
|
||
env := env.MergeEnvs([]corev1.EnvVar{}, envVars) | ||
|
||
jobName := instance.Name + "-" + cell.Spec.CellName + "-cell-delete" | ||
|
||
volumes := []corev1.Volume{ | ||
GetConfigVolume(configName), | ||
GetScriptVolume(scriptName), | ||
} | ||
volumeMounts := []corev1.VolumeMount{ | ||
GetConfigVolumeMount(), | ||
GetScriptVolumeMount(), | ||
GetKollaConfigVolumeMount("cell-delete"), | ||
} | ||
|
||
// add CA cert if defined | ||
if instance.Spec.APIServiceTemplate.TLS.CaBundleSecretName != "" { | ||
volumes = append(volumes, instance.Spec.APIServiceTemplate.TLS.CreateVolume()) | ||
volumeMounts = append(volumeMounts, instance.Spec.APIServiceTemplate.TLS.CreateVolumeMounts(nil)...) | ||
} | ||
|
||
job := &batchv1.Job{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: jobName, | ||
Namespace: instance.Namespace, | ||
Labels: labels, | ||
}, | ||
Spec: batchv1.JobSpec{ | ||
Template: corev1.PodTemplateSpec{ | ||
Spec: corev1.PodSpec{ | ||
RestartPolicy: corev1.RestartPolicyOnFailure, | ||
ServiceAccountName: instance.RbacResourceName(), | ||
Volumes: volumes, | ||
Containers: []corev1.Container{ | ||
{ | ||
Name: "nova-manage", | ||
Command: []string{ | ||
"/bin/bash", | ||
}, | ||
Args: args, | ||
Image: cell.Spec.ConductorContainerImageURL, | ||
SecurityContext: &corev1.SecurityContext{ | ||
RunAsUser: ptr.To(NovaUserID), | ||
}, | ||
Env: env, | ||
VolumeMounts: volumeMounts, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
return job | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
# Copyright 2023. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -xe | ||
|
||
export CELL_NAME=${CELL_NAME:?"Please specify a CELL_NAME variable."} | ||
|
||
# NOTE(gibi): nova-manage should be enhanced upstream to get rid of this | ||
# uglyness | ||
# Note the "|" around the CELL_NAME, that is needed as a single line from | ||
# nova-manage cell_v2 cell_list can match to multiple cells if the cell name | ||
# is part of the line, e.g. as the user name of the DB URL | ||
cell_uuid=$(nova-manage cell_v2 list_cells | tr ' ' '|' | tr --squeeze-repeats '|' | grep -e "^|$CELL_NAME|" | cut -d '|' -f 3) | ||
|
||
if [ -z "${cell_uuid}" ]; then | ||
nova-manage cell_v2 delete_cell --cell_uuid "${cell_uuid}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"command": "/bin/ensure_cell_mapping.sh", | ||
"config_files": [ | ||
{ | ||
"source": "/var/lib/openstack/config/nova-blank.conf", | ||
"dest": "/etc/nova/nova.conf", | ||
"owner": "nova", | ||
"perm": "0600" | ||
}, | ||
{ | ||
"source": "/var/lib/openstack/config/01-nova.conf", | ||
"dest": "/etc/nova/nova.conf.d/01-nova.conf", | ||
"owner": "nova", | ||
"perm": "0600" | ||
}, | ||
{ | ||
"source": "/var/lib/openstack/config/02-nova-override.conf", | ||
"dest": "/etc/nova/nova.conf.d/02-nova-override.conf", | ||
"owner": "nova", | ||
"perm": "0600", | ||
"optional": true | ||
}, | ||
{ | ||
"source": "/var/lib/openstack/bin/delete_cell.sh", | ||
"dest": "/bin/", | ||
"owner": "nova", | ||
"perm": "0700" | ||
}, | ||
{ | ||
"source": "/var/lib/openstack/config/my.cnf", | ||
"dest": "/etc/my.cnf", | ||
"owner": "nova", | ||
"perm": "0644" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters