Fix: Cannot update application status ComponentsReady to "true" (#6524)
Fix: Cannot update application status ComponentsReady to "true" (#2444) * Fix: Cannot update application status ComponentsReady to "true" * update --------- Signed-off-by: wenhaozhou <wenhaozhou@yunify.com>
This commit is contained in:
@@ -89,8 +89,7 @@ func (r *Reconciler) SetupWithManager(mgr *kscontroller.Manager) error {
|
|||||||
Name: GetApplictionName(obj.GetLabels()),
|
Name: GetApplictionName(obj.GetLabels()),
|
||||||
Namespace: obj.GetNamespace()}}}
|
Namespace: obj.GetNamespace()}}}
|
||||||
})
|
})
|
||||||
p := predicate.GenerationChangedPredicate{
|
p := predicate.Funcs{
|
||||||
TypedFuncs: predicate.Funcs{
|
|
||||||
UpdateFunc: func(e event.UpdateEvent) bool {
|
UpdateFunc: func(e event.UpdateEvent) bool {
|
||||||
return isApp(e.ObjectOld, e.ObjectOld)
|
return isApp(e.ObjectOld, e.ObjectOld)
|
||||||
},
|
},
|
||||||
@@ -100,7 +99,6 @@ func (r *Reconciler) SetupWithManager(mgr *kscontroller.Manager) error {
|
|||||||
DeleteFunc: func(e event.DeleteEvent) bool {
|
DeleteFunc: func(e event.DeleteEvent) bool {
|
||||||
return isApp(e.Object)
|
return isApp(e.Object)
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
// Watch for changes to Application
|
// Watch for changes to Application
|
||||||
err = c.Watch(source.Kind(mgr.GetCache(), s, h, p))
|
err = c.Watch(source.Kind(mgr.GetCache(), s, h, p))
|
||||||
@@ -139,12 +137,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
|
|||||||
newApplicationStatus := r.getNewApplicationStatus(ctx, &app, resources, &errs)
|
newApplicationStatus := r.getNewApplicationStatus(ctx, &app, resources, &errs)
|
||||||
|
|
||||||
newApplicationStatus.ObservedGeneration = app.Generation
|
newApplicationStatus.ObservedGeneration = app.Generation
|
||||||
if equality.Semantic.DeepEqual(newApplicationStatus, &app.Status) {
|
if !equality.Semantic.DeepEqual(newApplicationStatus, &app.Status) {
|
||||||
return ctrl.Result{}, nil
|
err = r.updateApplicationStatus(ctx, req.NamespacedName, newApplicationStatus)
|
||||||
|
if err != nil {
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = r.updateApplicationStatus(ctx, req.NamespacedName, newApplicationStatus)
|
return ctrl.Result{}, nil
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reconciler) updateComponents(ctx context.Context, app *appv1beta1.Application) ([]*unstructured.Unstructured, []error) {
|
func (r *Reconciler) updateComponents(ctx context.Context, app *appv1beta1.Application) ([]*unstructured.Unstructured, []error) {
|
||||||
@@ -240,15 +240,15 @@ func (r *Reconciler) setOwnerRefForResources(ctx context.Context, ownerRef metav
|
|||||||
|
|
||||||
if !ownerRefFound {
|
if !ownerRefFound {
|
||||||
ownerRefs = append(ownerRefs, ownerRef)
|
ownerRefs = append(ownerRefs, ownerRef)
|
||||||
}
|
|
||||||
resource.SetOwnerReferences(ownerRefs)
|
resource.SetOwnerReferences(ownerRefs)
|
||||||
err := r.Client.Update(ctx, resource)
|
err := r.Update(ctx, resource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// We log this error, but we continue and try to set the ownerRefs on the other resources.
|
// We log this error, but we continue and try to set the ownerRefs on the other resources.
|
||||||
klog.Error(err, "ErrorSettingOwnerRef", "gvk", resource.GroupVersionKind().String(),
|
klog.Error(err, "ErrorSettingOwnerRef", "gvk", resource.GroupVersionKind().String(),
|
||||||
"namespace", resource.GetNamespace(), "name", resource.GetName())
|
"namespace", resource.GetNamespace(), "name", resource.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user