Skip to content

Commit 838cb17

Browse files
committed
Fix customServiceConfig bug <Jira: OSPRH-10696>
1 parent e634c08 commit 838cb17

File tree

6 files changed

+73
-7
lines changed

6 files changed

+73
-7
lines changed

controllers/ironic_controller.go

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,52 @@ func (r *IronicReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
218218

219219
// SetupWithManager sets up the controller with the Manager.
220220
func (r *IronicReconciler) SetupWithManager(mgr ctrl.Manager) error {
221+
// watch for configmap where the CM owner label AND the CR.Spec.ManagingCrName label matches
222+
configMapFn := func(ctx context.Context, o client.Object) []reconcile.Request {
223+
Log := r.GetLogger(ctx)
224+
225+
result := []reconcile.Request{}
226+
227+
// get all API CRs
228+
apis := &ironicv1.IronicInspectorList{}
229+
listOpts := []client.ListOption{
230+
client.InNamespace(o.GetNamespace()),
231+
}
232+
if err := r.Client.List(
233+
ctx,
234+
apis,
235+
listOpts...); err != nil {
236+
237+
Log.Error(err, "Unable to retrieve API CRs %v")
238+
return nil
239+
}
240+
241+
label := o.GetLabels()
242+
// TODO: Just trying to verify that the CM is owned by this CR's managing CR
243+
if l, ok := label[labels.GetOwnerNameLabelSelector(
244+
labels.GetGroupLabel(ironic.ServiceName))]; ok {
245+
for _, cr := range apis.Items {
246+
// return reconcil event for the CR where the CM owner label
247+
// AND the parentIronicName matches
248+
if l == ironicv1.GetOwningIronicName(&cr) {
249+
// return namespace and Name of CR
250+
name := client.ObjectKey{
251+
Namespace: o.GetNamespace(),
252+
Name: cr.Name,
253+
}
254+
Log.Info(fmt.Sprintf(
255+
"ConfigMap object %s and CR %s marked with label: %s",
256+
o.GetName(), cr.Name, l))
257+
result = append(
258+
result, reconcile.Request{NamespacedName: name})
259+
}
260+
}
261+
}
262+
if len(result) > 0 {
263+
return result
264+
}
265+
return nil
266+
}
221267
return ctrl.NewControllerManagedBy(mgr).
222268
For(&ironicv1.Ironic{}).
223269
Owns(&ironicv1.IronicConductor{}).
@@ -228,10 +274,12 @@ func (r *IronicReconciler) SetupWithManager(mgr ctrl.Manager) error {
228274
Owns(&mariadbv1.MariaDBAccount{}).
229275
Owns(&batchv1.Job{}).
230276
Owns(&corev1.Secret{}).
231-
Owns(&corev1.ConfigMap{}).
232277
Owns(&corev1.ServiceAccount{}).
233278
Owns(&rbacv1.Role{}).
234279
Owns(&rbacv1.RoleBinding{}).
280+
Watches(
281+
&corev1.ConfigMap{},
282+
handler.EnqueueRequestsFromMapFunc(configMapFn)).
235283
Watches(&keystonev1.KeystoneAPI{},
236284
handler.EnqueueRequestsFromMapFunc(r.findObjectForSrc),
237285
builder.WithPredicates(keystonev1.KeystoneAPIStatusChangedPredicate)).
@@ -935,8 +983,8 @@ func (r *IronicReconciler) generateServiceConfigMaps(
935983
// all other files get placed into /etc/ironic to allow overwrite of e.g. policy.json
936984
// TODO: make sure custom.conf can not be overwritten
937985
customData := map[string]string{
938-
common.CustomServiceConfigFileName: instance.Spec.CustomServiceConfig,
939-
"my.cnf": db.GetDatabaseClientConfig(tlsCfg), //(mschuppert) for now just get the default my.cnf
986+
"01-ironic-custom.conf": instance.Spec.CustomServiceConfig,
987+
"my.cnf": db.GetDatabaseClientConfig(tlsCfg), //(mschuppert) for now just get the default my.cnf
940988

941989
}
942990
for key, data := range instance.Spec.DefaultConfigOverwrite {

pkg/ironicapi/volumes.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
package ironicapi
22

33
import (
4+
"fmt"
5+
"strings"
6+
47
"github.com/openstack-k8s-operators/ironic-operator/pkg/ironic"
58
corev1 "k8s.io/api/core/v1"
69
)
710

811
// GetVolumes -
912
func GetVolumes(name string) []corev1.Volume {
1013
var config0640AccessMode int32 = 0640
11-
14+
parentName := strings.Replace(name, "-api", "", 1)
1215
apiVolumes := []corev1.Volume{
1316
{
1417
Name: "config-data-custom",
1518
VolumeSource: corev1.VolumeSource{
1619
Secret: &corev1.SecretVolumeSource{
1720
DefaultMode: &config0640AccessMode,
18-
SecretName: name + "-config-data",
21+
SecretName: fmt.Sprintf("%s-config-data", parentName),
1922
},
2023
},
2124
},

pkg/ironicconductor/volumes.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ironicconductor
22

33
import (
44
"fmt"
5+
"strings"
56

67
ironicv1 "github.com/openstack-k8s-operators/ironic-operator/api/v1beta1"
78
"github.com/openstack-k8s-operators/ironic-operator/pkg/ironic"
@@ -11,13 +12,15 @@ import (
1112
// GetVolumes -
1213
func GetVolumes(instance *ironicv1.IronicConductor) []corev1.Volume {
1314
var config0640AccessMode int32 = 0640
15+
parentName := strings.Replace(instance.Name, "-conductor", "", 1)
16+
1417
conductorVolumes := []corev1.Volume{
1518
{
1619
Name: "config-data-custom",
1720
VolumeSource: corev1.VolumeSource{
1821
Secret: &corev1.SecretVolumeSource{
1922
DefaultMode: &config0640AccessMode,
20-
SecretName: fmt.Sprintf("%s-config-data", instance.Name),
23+
SecretName: fmt.Sprintf("%s-config-data", parentName),
2124
},
2225
},
2326
},

templates/common/bin/common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function common_ironic_config {
4444
export CUSTOMCONF=${CustomConf:-""}
4545

4646
SVC_CFG=/etc/ironic/ironic.conf
47-
SVC_CFG_MERGED=/var/lib/config-data/merged/ironic.conf
47+
SVC_CFG_MERGED=/var/lib/config-data/merged/01-ironic-custom.conf
4848

4949
# Copy default service config from container image as base
5050
cp -a ${SVC_CFG} ${SVC_CFG_MERGED}

templates/ironicapi/config/ironic-api-config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
"owner": "ironic",
1414
"perm": "0600"
1515
},
16+
{
17+
"source": "/var/lib/config-data/merged/01-ironic-custom.conf",
18+
"dest": "/etc/ironic/ironic.conf.d/01-ironic-custom.conf",
19+
"owner": "ironic",
20+
"perm": "0600"
21+
},
1622
{
1723
"source": "/var/lib/config-data/merged/ironic-api-httpd.conf",
1824
"dest": "/etc/httpd/conf/httpd.conf",

templates/ironicconductor/config/ironic-conductor-config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
"owner": "ironic",
1414
"perm": "0600"
1515
},
16+
{
17+
"source": "/var/lib/config-data/merged/01-ironic-custom.conf",
18+
"dest": "/etc/ironic/ironic.conf.d/01-ironic-custom.conf",
19+
"owner": "ironic",
20+
"perm": "0600"
21+
},
1622
{
1723
"source": "/var/lib/config-data/merged/my.cnf",
1824
"dest": "/etc/my.cnf",

0 commit comments

Comments
 (0)