Skip to content

Commit 0d6bfa8

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

File tree

7 files changed

+87
-8
lines changed

7 files changed

+87
-8
lines changed

controllers/ironic_controller.go

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import (
4949
"sigs.k8s.io/controller-runtime/pkg/builder"
5050
"sigs.k8s.io/controller-runtime/pkg/client"
5151
"sigs.k8s.io/controller-runtime/pkg/handler"
52+
"sigs.k8s.io/controller-runtime/pkg/predicate"
5253
"sigs.k8s.io/controller-runtime/pkg/reconcile"
5354

5455
batchv1 "k8s.io/api/batch/v1"
@@ -218,6 +219,52 @@ func (r *IronicReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
218219

219220
// SetupWithManager sets up the controller with the Manager.
220221
func (r *IronicReconciler) SetupWithManager(mgr ctrl.Manager) error {
222+
// watch for configmap where the CM owner label AND the CR.Spec.ManagingCrName label matches
223+
configMapFn := func(ctx context.Context, o client.Object) []reconcile.Request {
224+
Log := r.GetLogger(ctx)
225+
226+
result := []reconcile.Request{}
227+
228+
// get all API CRs
229+
apis := &ironicv1.IronicInspectorList{}
230+
listOpts := []client.ListOption{
231+
client.InNamespace(o.GetNamespace()),
232+
}
233+
if err := r.Client.List(
234+
ctx,
235+
apis,
236+
listOpts...); err != nil {
237+
238+
Log.Error(err, "Unable to retrieve API CRs %v")
239+
return nil
240+
}
241+
242+
label := o.GetLabels()
243+
// TODO: Just trying to verify that the CM is owned by this CR's managing CR
244+
if l, ok := label[labels.GetOwnerNameLabelSelector(
245+
labels.GetGroupLabel(ironic.ServiceName))]; ok {
246+
for _, cr := range apis.Items {
247+
// return reconcil event for the CR where the CM owner label
248+
// AND the parentIronicName matches
249+
if l == ironicv1.GetOwningIronicName(&cr) {
250+
// return namespace and Name of CR
251+
name := client.ObjectKey{
252+
Namespace: o.GetNamespace(),
253+
Name: cr.Name,
254+
}
255+
Log.Info(fmt.Sprintf(
256+
"ConfigMap object %s and CR %s marked with label: %s",
257+
o.GetName(), cr.Name, l))
258+
result = append(
259+
result, reconcile.Request{NamespacedName: name})
260+
}
261+
}
262+
}
263+
if len(result) > 0 {
264+
return result
265+
}
266+
return nil
267+
}
221268
return ctrl.NewControllerManagedBy(mgr).
222269
For(&ironicv1.Ironic{}).
223270
Owns(&ironicv1.IronicConductor{}).
@@ -228,10 +275,13 @@ func (r *IronicReconciler) SetupWithManager(mgr ctrl.Manager) error {
228275
Owns(&mariadbv1.MariaDBAccount{}).
229276
Owns(&batchv1.Job{}).
230277
Owns(&corev1.Secret{}).
231-
Owns(&corev1.ConfigMap{}).
232278
Owns(&corev1.ServiceAccount{}).
233279
Owns(&rbacv1.Role{}).
234280
Owns(&rbacv1.RoleBinding{}).
281+
Watches(
282+
&corev1.ConfigMap{},
283+
handler.EnqueueRequestsFromMapFunc(configMapFn),
284+
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{})).
235285
Watches(&keystonev1.KeystoneAPI{},
236286
handler.EnqueueRequestsFromMapFunc(r.findObjectForSrc),
237287
builder.WithPredicates(keystonev1.KeystoneAPIStatusChangedPredicate)).
@@ -539,6 +589,10 @@ func (r *IronicReconciler) reconcileNormal(ctx context.Context, instance *ironic
539589
}
540590
}
541591

592+
if instance.Spec.IronicAPI.CustomServiceConfig == "" {
593+
instance.Spec.IronicAPI.CustomServiceConfig = instance.Spec.IronicSpecCore.CustomServiceConfig
594+
}
595+
542596
// deploy ironic-api
543597
ironicAPI, op, err := r.apiDeploymentCreateOrUpdate(instance, &keystoneEndpoints)
544598
if err != nil {
@@ -935,8 +989,8 @@ func (r *IronicReconciler) generateServiceConfigMaps(
935989
// all other files get placed into /etc/ironic to allow overwrite of e.g. policy.json
936990
// TODO: make sure custom.conf can not be overwritten
937991
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
992+
"01-ironic-custom.conf": instance.Spec.CustomServiceConfig,
993+
"my.cnf": db.GetDatabaseClientConfig(tlsCfg), //(mschuppert) for now just get the default my.cnf
940994

941995
}
942996
for key, data := range instance.Spec.DefaultConfigOverwrite {

controllers/ironicapi_controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (r *IronicAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Man
227227
// watch for configmap where the CM owner label AND the CR.Spec.ManagingCrName label matches
228228
configMapFn := func(ctx context.Context, o client.Object) []reconcile.Request {
229229
Log := r.GetLogger(ctx)
230-
230+
Log.Info("In the configMapFn and watching for it")
231231
result := []reconcile.Request{}
232232

233233
// get all API CRs
@@ -241,10 +241,15 @@ func (r *IronicAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Man
241241
}
242242

243243
label := o.GetLabels()
244+
245+
Log.Info(fmt.Sprintf("GetLabels: %s and GroupLbel %s", label, labels.GetGroupLabel(ironic.ServiceName)))
246+
244247
// TODO: Just trying to verify that the CM is owned by this CR's managing CR
245248
if l, ok := label[labels.GetOwnerNameLabelSelector(labels.GetGroupLabel(ironic.ServiceName))]; ok {
249+
Log.Info("For loop for l and ok")
246250
for _, cr := range apis.Items {
247251
// return reconcil event for the CR where the CM owner label AND the parentIronicName matches
252+
Log.Info("Return reconcile event log")
248253
if l == ironicv1.GetOwningIronicName(&cr) {
249254
// return namespace and Name of CR
250255
name := client.ObjectKey{
@@ -253,6 +258,8 @@ func (r *IronicAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Man
253258
}
254259
Log.Info(fmt.Sprintf("ConfigMap object %s and CR %s marked with label: %s", o.GetName(), cr.Name, l))
255260
result = append(result, reconcile.Request{NamespacedName: name})
261+
} else {
262+
Log.Info("GetOwningIronicName returns nothing")
256263
}
257264
}
258265
}

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)