Skip to content

Commit 116e4af

Browse files
committed
Fix configuration of ironic neutron agent Jira: <OSPRH-10696>
1 parent 11c9133 commit 116e4af

File tree

9 files changed

+120
-274
lines changed

9 files changed

+120
-274
lines changed

controllers/ironicneutronagent_controller.go

Lines changed: 66 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,22 @@ func (r *IronicNeutronAgentReconciler) findObjectsForSrc(ctx context.Context, sr
312312
return requests
313313
}
314314

315+
func (r *IronicNeutronAgentReconciler) getTransportURL(
316+
ctx context.Context,
317+
h *helper.Helper,
318+
instance *ironicv1.IronicNeutronAgent,
319+
) (string, error) {
320+
transportURLSecret, _, err := secret.GetSecret(ctx, h, instance.Status.TransportURLSecret, instance.Namespace)
321+
if err != nil {
322+
return "", err
323+
}
324+
transportURL, ok := transportURLSecret.Data["transport_url"]
325+
if !ok {
326+
return "", fmt.Errorf("transport_url %w Transport Secret", util.ErrNotFound)
327+
}
328+
return string(transportURL), nil
329+
}
330+
315331
func (r *IronicNeutronAgentReconciler) reconcileTransportURL(
316332
ctx context.Context,
317333
instance *ironicv1.IronicNeutronAgent,
@@ -435,28 +451,6 @@ func (r *IronicNeutronAgentReconciler) reconcileConfigMapsAndSecrets(
435451
// all cert input checks out so report InputReady
436452
instance.Status.Conditions.MarkTrue(condition.TLSInputReadyCondition, condition.InputReadyMessage)
437453

438-
//
439-
// Create ConfigMaps required as input for the Service and calculate an overall hash of hashes
440-
//
441-
442-
// create custom Configmap for IronicNeutronAgent input
443-
// - %-scripts configmap holding scripts to e.g. bootstrap the service
444-
// - %-config configmap holding minimal neutron config required to get the
445-
// service up, user can add additional files to be added to the service
446-
// - parameters which has passwords gets added from the OpenStack secret via the init container
447-
//
448-
err = r.generateServiceConfigMaps(ctx, helper, instance, &configMapVars)
449-
if err != nil {
450-
instance.Status.Conditions.Set(condition.FalseCondition(
451-
condition.ServiceConfigReadyCondition,
452-
condition.ErrorReason,
453-
condition.SeverityWarning,
454-
condition.ServiceConfigReadyErrorMessage,
455-
err.Error()))
456-
return ctrl.Result{}, "", err
457-
}
458-
// Create ConfigMaps - end
459-
460454
// create hash over all the different input resources to identify if any those changed
461455
// and a restart/recreate is required.
462456
inputHash, hashChanged, err := r.createHashOfInputHashes(ctx, instance, configMapVars)
@@ -476,6 +470,24 @@ func (r *IronicNeutronAgentReconciler) reconcileConfigMapsAndSecrets(
476470
instance.Status.Conditions.MarkTrue(
477471
condition.ServiceConfigReadyCondition,
478472
condition.ServiceConfigReadyMessage)
473+
474+
// Create Secrets required as input for the Service and calculate an overall hash of hashes
475+
//
476+
477+
//
478+
// create Secret required for ironicneutronagent input. It contains minimal ironicneutronagent config required
479+
// to get the service up, user can add additional files to be added to the service.
480+
err = r.generateServiceSecrets(ctx, helper, instance, &configMapVars)
481+
if err != nil {
482+
instance.Status.Conditions.Set(condition.FalseCondition(
483+
condition.ServiceConfigReadyCondition,
484+
condition.ErrorReason,
485+
condition.SeverityWarning,
486+
condition.ServiceConfigReadyErrorMessage,
487+
err.Error()))
488+
return ctrl.Result{}, "", err
489+
}
490+
479491
// Create ConfigMaps and Secrets - end
480492

481493
return ctrl.Result{}, inputHash, nil
@@ -712,24 +724,25 @@ func (r *IronicNeutronAgentReconciler) reconcileUpgrade(
712724
return ctrl.Result{}, nil
713725
}
714726

715-
// generateServiceConfigMaps - create custom configmap to hold service-specific config
716-
func (r *IronicNeutronAgentReconciler) generateServiceConfigMaps(
727+
// generateServiceSecrets - create secrets which service configuration
728+
func (r *IronicNeutronAgentReconciler) generateServiceSecrets(
717729
ctx context.Context,
718730
h *helper.Helper,
719731
instance *ironicv1.IronicNeutronAgent,
720732
envVars *map[string]env.Setter,
721733
) error {
722-
//
723-
// create custom Configmap for ironic-neutron-agnet-specific config input
724-
// - %-config-data configmap holding custom config for the service config
725-
//
726-
727-
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(ironic.ServiceName), map[string]string{})
734+
// Create/update secrets from templates
735+
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(ironicneutronagent.ServiceName), map[string]string{})
728736

729737
// customData hold any customization for the service.
730-
// custom.conf is going to be merged into /etc/ironic/ironic.conf
731-
// TODO: make sure custom.conf can not be overwritten
732-
customData := map[string]string{common.CustomServiceConfigFileName: instance.Spec.CustomServiceConfig}
738+
// 02-ironic_neutron_agent-custom.conf is going to /etc/neutron/plugins/ml2
739+
// 01-ironic_neutron_agent.conf is going to /etc/neutron/plugins/ml2 such that it gets loaded before custom one
740+
customData := map[string]string{
741+
"02-ironic_neutron_agent-custom.conf": instance.Spec.CustomServiceConfig,
742+
}
743+
for key, data := range instance.Spec.DefaultConfigOverwrite {
744+
customData[key] = data
745+
}
733746

734747
keystoneAPI, err := keystonev1.GetKeystoneAPI(ctx, h, instance.Namespace, map[string]string{})
735748
if err != nil {
@@ -744,35 +757,40 @@ func (r *IronicNeutronAgentReconciler) generateServiceConfigMaps(
744757
return err
745758
}
746759

760+
transportURL, err := r.getTransportURL(ctx, h, instance)
761+
if err != nil {
762+
return err
763+
}
764+
765+
ospSecret, _, err := secret.GetSecret(ctx, h, instance.Spec.Secret, instance.Namespace)
766+
if err != nil {
767+
return err
768+
}
769+
747770
templateParameters := make(map[string]interface{})
748771
templateParameters["ServiceUser"] = instance.Spec.ServiceUser
749772
templateParameters["KeystoneInternalURL"] = keystoneInternalURL
750773
templateParameters["KeystonePublicURL"] = keystonePublicURL
774+
templateParameters["TransportURL"] = transportURL
775+
776+
// Other OpenStack services
777+
servicePassword := string(ospSecret.Data[instance.Spec.PasswordSelectors.Service])
778+
templateParameters["ServicePassword"] = servicePassword
779+
templateParameters["keystone_authtoken"] = servicePassword
780+
templateParameters["service_catalog"] = servicePassword
781+
templateParameters["ironic"] = servicePassword
751782

752783
cms := []util.Template{
753-
// Scripts ConfigMap
754-
{
755-
Name: fmt.Sprintf("%s-scripts", instance.Name),
756-
Namespace: instance.Namespace,
757-
Type: util.TemplateTypeScripts,
758-
InstanceType: instance.Kind,
759-
AdditionalTemplate: map[string]string{
760-
"common.sh": "/common/bin/common.sh",
761-
},
762-
Labels: cmLabels,
763-
},
764-
// Custom ConfigMap
765784
{
766-
Name: fmt.Sprintf("%s-config-data", instance.Name),
785+
Name: fmt.Sprintf("%s-config", instance.Name),
767786
Namespace: instance.Namespace,
768787
Type: util.TemplateTypeConfig,
769788
InstanceType: instance.Kind,
770789
CustomData: customData,
771-
ConfigOptions: templateParameters,
772790
Labels: cmLabels,
791+
ConfigOptions: templateParameters,
773792
},
774793
}
775-
776794
return secret.EnsureSecrets(ctx, h, instance, cms, envVars)
777795
}
778796

pkg/ironicneutronagent/deployment.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ func Deployment(
6767

6868
volumes := GetVolumes(instance.Name)
6969
volumeMounts := GetVolumeMounts()
70-
initVolumeMounts := GetInitVolumeMounts()
7170

7271
// Add the CA bundle
7372
if instance.Spec.TLS.CaBundleSecretName != "" {
7473
volumes = append(volumes, instance.Spec.TLS.CreateVolume())
7574
volumeMounts = append(volumeMounts, instance.Spec.TLS.CreateVolumeMounts(nil)...)
76-
initVolumeMounts = append(initVolumeMounts, instance.Spec.TLS.CreateVolumeMounts(nil)...)
7775
}
7876

7977
// Default oslo.service graceful_shutdown_timeout is 60, so align with that
@@ -137,14 +135,5 @@ func Deployment(
137135
)
138136
}
139137

140-
initContainerDetails := APIDetails{
141-
ContainerImage: instance.Spec.ContainerImage,
142-
OSPSecret: instance.Spec.Secret,
143-
TransportURLSecret: instance.Status.TransportURLSecret,
144-
UserPasswordSelector: instance.Spec.PasswordSelectors.Service,
145-
VolumeMounts: initVolumeMounts,
146-
}
147-
deployment.Spec.Template.Spec.InitContainers = InitContainer(initContainerDetails)
148-
149138
return deployment
150139
}

pkg/ironicneutronagent/initcontainer.go

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

pkg/ironicneutronagent/volumes.go

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,56 +22,18 @@ import (
2222

2323
// GetVolumes -
2424
func GetVolumes(name string) []corev1.Volume {
25-
var scriptsVolumeDefaultMode int32 = 0755
2625
var config0640AccessMode int32 = 0640
2726

2827
return []corev1.Volume{
2928
{
30-
Name: "scripts",
31-
VolumeSource: corev1.VolumeSource{
32-
Secret: &corev1.SecretVolumeSource{
33-
DefaultMode: &scriptsVolumeDefaultMode,
34-
SecretName: name + "-scripts",
35-
},
36-
},
37-
},
38-
{
39-
Name: "config-data",
29+
Name: "config",
4030
VolumeSource: corev1.VolumeSource{
4131
Secret: &corev1.SecretVolumeSource{
4232
DefaultMode: &config0640AccessMode,
43-
SecretName: name + "-config-data",
33+
SecretName: name + "-config",
4434
},
4535
},
4636
},
47-
{
48-
Name: "config-data-merged",
49-
VolumeSource: corev1.VolumeSource{
50-
EmptyDir: &corev1.EmptyDirVolumeSource{Medium: ""},
51-
},
52-
},
53-
}
54-
55-
}
56-
57-
// GetInitVolumeMounts - IronicNeutronAgent init task VolumeMounts
58-
func GetInitVolumeMounts() []corev1.VolumeMount {
59-
return []corev1.VolumeMount{
60-
{
61-
Name: "scripts",
62-
MountPath: "/usr/local/bin/container-scripts",
63-
ReadOnly: true,
64-
},
65-
{
66-
Name: "config-data",
67-
MountPath: "/var/lib/config-data/default",
68-
ReadOnly: true,
69-
},
70-
{
71-
Name: "config-data-merged",
72-
MountPath: "/var/lib/config-data/merged",
73-
ReadOnly: false,
74-
},
7537
}
7638

7739
}
@@ -80,21 +42,15 @@ func GetInitVolumeMounts() []corev1.VolumeMount {
8042
func GetVolumeMounts() []corev1.VolumeMount {
8143
return []corev1.VolumeMount{
8244
{
83-
Name: "scripts",
84-
MountPath: "/usr/local/bin/container-scripts",
45+
Name: "config",
46+
MountPath: "/var/lib/config-data/default",
8547
ReadOnly: true,
8648
},
8749
{
88-
Name: "config-data-merged",
89-
MountPath: "/var/lib/config-data/merged",
90-
ReadOnly: false,
91-
},
92-
{
93-
Name: "config-data",
50+
Name: "config",
9451
MountPath: "/var/lib/kolla/config_files/config.json",
9552
SubPath: "ironic-neutron-agent-config.json",
9653
ReadOnly: true,
9754
},
9855
}
99-
10056
}

0 commit comments

Comments
 (0)