This issue is part of [OM-97052]: ORM v2 resize action.
All tasks in issue are completed with this PR.
Event recording needs to be done in kubeturbo outside orm, coz it must be done after Updating the owner resource.
I saw kubeturbo already initialized its own event recorder, you can pass it to kuberentes.Toolbox during initialization or use it directly (pass nil to toolbox).
Example of doing updating is in compareAndEnforce function in controllers/advicemapping_controller.go You have your own way to construct the valueFromAdvisor, ignore that part.
if m.Owner.Namespace == "" {
m.Owner.Namespace = am.Namespace
}
obj, err = kubernetes.Toolbox.GetResourceWithObjectReference(m.Owner.ObjectReference)
if err != nil {
acLog.Error(err, "finding true owner", "owner", m.Owner)
continue
}
valueInOwner, found, err := ormutils.NestedField(obj.Object, m.Owner.Path)
if err != nil {
acLog.Error(err, "finding path in owner", "path", m.Owner.Path)
continue
}
var valueFromAdvisor interface{}
vMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(m.Value)
if err != nil {
acLog.Error(err, "converting value", "value", m.Value)
continue
}
for _, v := range vMap {
valueFromAdvisor = v
break
}
if !reflect.DeepEqual(valueInOwner, valueFromAdvisor) {
ormutils.SetNestedField(obj.Object, valueFromAdvisor, m.Owner.Path)
err = kubernetes.Toolbox.UpdateResourceWithGVK(obj.GroupVersionKind(), obj)
if err != nil {
acLog.Error(err, "updating true owner", "owner", m.Owner)
continue
}
if !found {
kubernetes.Toolbox.RecordEventf(obj, "Normal", "Updated", "Updated %s as advised by %s/%s and completed omitted path", m.Owner.Path, am.GetNamespace(), am.GetName())
} else {
kubernetes.Toolbox.RecordEventf(obj, "Normal", "Updated", "Updated %s as advised by %s/%s", m.Owner.Path, am.GetNamespace(), am.GetName())
}
}
This issue is part of [OM-97052]: ORM v2 resize action.
All tasks in issue are completed with this PR.
Event recording needs to be done in kubeturbo outside orm, coz it must be done after Updating the owner resource.
I saw kubeturbo already initialized its own event recorder, you can pass it to kuberentes.Toolbox during initialization or use it directly (pass nil to toolbox).
Example of doing updating is in
compareAndEnforce
function incontrollers/advicemapping_controller.go
You have your own way to construct thevalueFromAdvisor
, ignore that part.