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 Dec 18, 2022
1 parent b9bd4c1 commit f8960ed
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 42 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
}
3 changes: 2 additions & 1 deletion controllers/nova_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
common_instance "github.com/openstack-k8s-operators/lib-common/modules/common/instance"
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"
database "github.com/openstack-k8s-operators/lib-common/modules/database"

Expand Down Expand Up @@ -111,7 +112,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 := common_instance.PatchInstance(ctx, h, instance)
if err != nil {
_err = err
return
Expand Down
3 changes: 2 additions & 1 deletion controllers/novaapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
common_instance "github.com/openstack-k8s-operators/lib-common/modules/common/instance"
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
"github.com/openstack-k8s-operators/lib-common/modules/common/statefulset"
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"
Expand Down Expand Up @@ -115,7 +116,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 := common_instance.PatchInstance(ctx, h, instance)
if err != nil {
_err = err
return
Expand Down
3 changes: 2 additions & 1 deletion controllers/novacell_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
common_instance "github.com/openstack-k8s-operators/lib-common/modules/common/instance"
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"

novav1 "github.com/openstack-k8s-operators/nova-operator/api/v1beta1"
Expand Down Expand Up @@ -96,7 +97,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 := common_instance.PatchInstance(ctx, h, instance)
if err != nil {
_err = err
return
Expand Down
3 changes: 2 additions & 1 deletion controllers/novaconductor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/configmap"
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
common_instance "github.com/openstack-k8s-operators/lib-common/modules/common/instance"
job "github.com/openstack-k8s-operators/lib-common/modules/common/job"
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
"github.com/openstack-k8s-operators/lib-common/modules/common/statefulset"
Expand Down Expand Up @@ -106,7 +107,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 := common_instance.PatchInstance(ctx, h, 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-20221215201557-feb92dd06374
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-20221215201557-feb92dd06374 h1:5/ZA3UQouRnQNocxrMcGnNJBSb0HENs6O3x9jB1FtKs=
github.com/abays/lib-common/modules/common v0.0.0-20221215201557-feb92dd06374/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-20221123090515-e2561e258f0a h1:x1MGRitaQNIKdcyJUtcXRvKFhN3l5hcYlc7lD5N0APg=
github.com/openstack-k8s-operators/keystone-operator/api v0.0.0-20221123090515-e2561e258f0a/go.mod h1:SwhyYcQUbpT4QLuqdsLjAlM0oPouHIJy1gVOkM4O5xQ=
github.com/openstack-k8s-operators/lib-common/modules/common v0.0.0-20221124114404-c42a739be111 h1:X5Y2zXwOiPPFoQN0Ox8C2jL1tZo3+S9BjcOf9h/EYbU=
github.com/openstack-k8s-operators/lib-common/modules/common v0.0.0-20221124114404-c42a739be111/go.mod h1:qV9OlokZRpqbHI3lmeN5EOmIKynWphw6GPl3zP9KOGM=
github.com/openstack-k8s-operators/lib-common/modules/database v0.0.0-20221115095652-2c390a9d20b4 h1:RSIOKTJoJivtHJPhXXU6raTApSXsHK/CJS10iFqeI8s=
github.com/openstack-k8s-operators/lib-common/modules/database v0.0.0-20221115095652-2c390a9d20b4/go.mod h1:umGUqQO4JtgefAaIwZjP+TxfxsLMEEeK/6VNzk8ooaI=
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.0.0-20220915080953-f73a201a1da6 h1:MVNEHyqD0ZdO9jiyUSKw5M2T9Lc4l4Wx1pdC2/BSJ5Y=
Expand Down
4 changes: 4 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/abays/lib-common v0.0.1-0.20221215201557-feb92dd06374 h1:+4HkOhkCzT+DWKNJatjEvjtwuuGRZ9Tn+wXZb8lg2jc=
github.com/abays/lib-common v0.0.1-0.20221215201557-feb92dd06374/go.mod h1:B+aMnILkpz6LbQ6yeq9+dXN8Spexsfoisr5+7aIyLyg=
github.com/abays/lib-common/modules/common v0.0.0-20221215201557-feb92dd06374 h1:5/ZA3UQouRnQNocxrMcGnNJBSb0HENs6O3x9jB1FtKs=
github.com/abays/lib-common/modules/common v0.0.0-20221215201557-feb92dd06374/go.mod h1:qV9OlokZRpqbHI3lmeN5EOmIKynWphw6GPl3zP9KOGM=
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210826220005-b48c857c3a0e/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
Expand Down

0 comments on commit f8960ed

Please sign in to comment.