Skip to content

Commit

Permalink
feat: add more logs to object change
Browse files Browse the repository at this point in the history
  • Loading branch information
TrayserCassa committed Dec 16, 2024
1 parent c7dc075 commit d28acdd
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions internal/k8s/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"
)

func GetWatchNamespace() (string, error) {
Expand Down Expand Up @@ -354,8 +355,21 @@ func EnsureObjectWithHash(
obj.SetAnnotations(annotations)
}

if oldObject.GetAnnotations()["shopware.com/last-config-hash"] != hash ||
!objectMetaEqual(obj, oldObject) {
hashChanged := oldObject.GetAnnotations()["shopware.com/last-config-hash"] != hash
objectMetaChanged := !objectMetaEqual(obj, oldObject)

if hashChanged || objectMetaChanged {
if hashChanged {
log.FromContext(ctx).Info("Object last-config-hash has changed", "old", oldObject.GetAnnotations()["shopware.com/last-config-hash"], "new", hash)
} else {
log.FromContext(ctx).Info(
"Object meta has changed",
"oldAnnotations", oldObject.GetAnnotations(),
"newAnnotations", obj.GetAnnotations(),
"oldLabels", oldObject.GetLabels(),
"newLabels", obj.GetLabels(),
)
}

obj.SetResourceVersion(oldObject.GetResourceVersion())
switch object := obj.(type) {
Expand Down

0 comments on commit d28acdd

Please sign in to comment.