Skip to content

Commit

Permalink
Use PatchInstance from lib-common
Browse files Browse the repository at this point in the history
  • Loading branch information
gibizer committed Jan 6, 2023
1 parent 762f273 commit fc2eb54
Show file tree
Hide file tree
Showing 8 changed files with 740 additions and 346 deletions.
36 changes: 0 additions & 36 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,39 +274,3 @@ func (r *ReconcilerBase) GenerateConfigs(
// to enable unit testing at some point.
return configmap.EnsureConfigMaps(ctx, h, instance, cms, envVars)
}

func (r *ReconcilerBase) patchInstance(ctx context.Context, h *helper.Helper, instance client.Object) error {
var err error

if err = h.SetAfter(instance); err != nil {
util.LogErrorForObject(h, err, "Set after and calc patch/diff", instance)
return err
}

changes := h.GetChanges()
patch := client.MergeFrom(h.GetBeforeObject())

if changes["metadata"] {
err = r.Client.Patch(ctx, instance, patch)
if k8s_errors.IsConflict(err) {
util.LogForObject(h, "Metadata update conflict", instance)
return err
} else if err != nil && !k8s_errors.IsNotFound(err) {
util.LogErrorForObject(h, err, "Metadate update failed", instance)
return err
}
}

if changes["status"] {
err = r.Client.Status().Patch(ctx, instance, patch)
if k8s_errors.IsConflict(err) {
util.LogForObject(h, "Status update conflict", instance)
return err

} else if err != nil && !k8s_errors.IsNotFound(err) {
util.LogErrorForObject(h, err, "Status update failed", instance)
return err
}
}
return nil
}
2 changes: 1 addition & 1 deletion controllers/nova_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul
instance.Status.Conditions.MarkTrue(
condition.ReadyCondition, condition.ReadyMessage)
}
err := r.patchInstance(ctx, h, instance)
err := h.PatchInstance(ctx, instance)
if err != nil {
_err = err
return
Expand Down
2 changes: 1 addition & 1 deletion controllers/novaapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (r *NovaAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
instance.Status.Conditions.MarkTrue(
condition.ReadyCondition, condition.ReadyMessage)
}
err := r.patchInstance(ctx, h, instance)
err := h.PatchInstance(ctx, instance)
if err != nil {
_err = err
return
Expand Down
2 changes: 1 addition & 1 deletion controllers/novacell_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (r *NovaCellReconciler) Reconcile(ctx context.Context, req ctrl.Request) (r
instance.Status.Conditions.MarkTrue(
condition.ReadyCondition, condition.ReadyMessage)
}
err := r.patchInstance(ctx, h, instance)
err := h.PatchInstance(ctx, instance)
if err != nil {
_err = err
return
Expand Down
2 changes: 1 addition & 1 deletion controllers/novaconductor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (r *NovaConductorReconciler) Reconcile(ctx context.Context, req ctrl.Reques
instance.Status.Conditions.MarkTrue(
condition.ReadyCondition, condition.ReadyMessage)
}
err := r.patchInstance(ctx, h, instance)
err := h.PatchInstance(ctx, instance)
if err != nil {
_err = err
return
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ require (
)

replace github.com/openstack-k8s-operators/nova-operator/api => ./api

replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/abays/lib-common/modules/common v0.0.0-20230106150407-26befd79f212
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBp
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/abays/lib-common/modules/common v0.0.0-20230106150407-26befd79f212 h1:lhBhT1FVdNmgCgJ8o5axKThz1R4QroLtONt13mPEOL4=
github.com/abays/lib-common/modules/common v0.0.0-20230106150407-26befd79f212/go.mod h1:qV9OlokZRpqbHI3lmeN5EOmIKynWphw6GPl3zP9KOGM=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down Expand Up @@ -284,8 +286,6 @@ github.com/openshift/api v3.9.0+incompatible h1:fJ/KsefYuZAjmrr3+5U9yZIZbTOpVkDD
github.com/openshift/api v3.9.0+incompatible/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY=
github.com/openstack-k8s-operators/keystone-operator/api v0.0.0-20221215165910-80274d6445b1 h1:rzLz7ooPDuhhkMtpG8iPsTmtyWO28IKDVnQbYUOywV4=
github.com/openstack-k8s-operators/keystone-operator/api v0.0.0-20221215165910-80274d6445b1/go.mod h1:HfMoeyB6kEPfH6Q5YlLyUwmY5ZIgEsDoIBvArE01Oto=
github.com/openstack-k8s-operators/lib-common/modules/common v0.0.0-20221212162305-ec57ccd85ad5 h1:gp/aw5rthQSztEpaQqp8fopYtq2dhkU0YkKobwlKriU=
github.com/openstack-k8s-operators/lib-common/modules/common v0.0.0-20221212162305-ec57ccd85ad5/go.mod h1:qV9OlokZRpqbHI3lmeN5EOmIKynWphw6GPl3zP9KOGM=
github.com/openstack-k8s-operators/lib-common/modules/database v0.0.0-20221212162305-ec57ccd85ad5 h1:ldWyhD/8exhrf2QzDvLlEG/HRZ6sG/HX7NvNfTdr44M=
github.com/openstack-k8s-operators/lib-common/modules/database v0.0.0-20221212162305-ec57ccd85ad5/go.mod h1:rONM/XgvFs6putDIxRHNv9/CTGh2afAvJM5wRP2OywY=
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.0.0-20220915080953-f73a201a1da6 h1:MVNEHyqD0ZdO9jiyUSKw5M2T9Lc4l4Wx1pdC2/BSJ5Y=
Expand Down
Loading

0 comments on commit fc2eb54

Please sign in to comment.