-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NETOBSERV-1076 Fix CR stuck in Updating state #374
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,12 @@ func (m *NamespacedObjectManager) FetchAll(ctx context.Context) error { | |
// On success, placeholder is filled with resource. Caller should keep a pointer to it. | ||
} | ||
} | ||
log.Info("Fetched: " + strings.Join(fetched, ",") + ". Not found: " + strings.Join(notFound, ",")) | ||
if len(fetched) > 0 { | ||
log.Info("FETCHED: " + strings.Join(fetched, ",")) | ||
} | ||
if len(notFound) > 0 { | ||
log.Info("(Items not deployed: " + strings.Join(notFound, ",") + ")") | ||
} | ||
return nil | ||
} | ||
|
||
|
@@ -83,7 +88,7 @@ func (m *NamespacedObjectManager) cleanup(ctx context.Context, namespace string) | |
ref := obj.placeholder.DeepCopyObject().(client.Object) | ||
ref.SetName(obj.name) | ||
ref.SetNamespace(namespace) | ||
log.Info("Deleting old "+obj.kind, "Namespace", namespace, "Name", obj.name) | ||
log.Info("DELETING "+obj.kind, "Namespace", namespace, "Name", obj.name) | ||
err := m.client.Delete(ctx, ref) | ||
if client.IgnoreNotFound(err) != nil { | ||
log.Error(err, "Failed to delete old "+obj.kind, "Namespace", namespace, "Name", obj.name) | ||
|
@@ -103,7 +108,7 @@ func (m *NamespacedObjectManager) TryDelete(ctx context.Context, obj client.Obje | |
if m.Exists(obj) { | ||
log := log.FromContext(ctx) | ||
kind := reflect.TypeOf(obj).String() | ||
log.Info("Deleting old "+kind, "Namespace", obj.GetNamespace(), "Name", obj.GetName()) | ||
log.Info("DELETING "+kind, "Namespace", obj.GetNamespace(), "Name", obj.GetName()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I don't know if there is a need to have all caps here I don't think this align with go coding style ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The intent is to make some important information more visible - I found it very useful when debugging, whereas with the normal sentence case it's sometimes hard to find relevant logs at a glance. That's really for pragmatism. |
||
err := m.client.Delete(ctx, obj) | ||
if err != nil { | ||
log.Error(err, "Failed to delete old "+kind, "Namespace", obj.GetNamespace(), "Name", obj.GetName()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ func (c *Client) CreateOwned(ctx context.Context, obj client.Object) error { | |
return err | ||
} | ||
kind := reflect.TypeOf(obj).String() | ||
log.Info("Creating a new "+kind, "Namespace", obj.GetNamespace(), "Name", obj.GetName()) | ||
log.Info("CREATING a new "+kind, "Namespace", obj.GetNamespace(), "Name", obj.GetName()) | ||
err = c.Create(ctx, obj) | ||
if err != nil { | ||
log.Error(err, "Failed to create new "+kind, "Namespace", obj.GetNamespace(), "Name", obj.GetName()) | ||
|
@@ -48,7 +48,6 @@ func (c *Client) CreateOwned(ctx context.Context, obj client.Object) error { | |
// UpdateOwned is an helper function that updates an object, sets owner reference and writes info & errors logs | ||
func (c *Client) UpdateOwned(ctx context.Context, old, obj client.Object) error { | ||
log := log.FromContext(ctx) | ||
c.SetChanged(true) | ||
if old != nil { | ||
obj.SetResourceVersion(old.GetResourceVersion()) | ||
} | ||
|
@@ -58,12 +57,22 @@ func (c *Client) UpdateOwned(ctx context.Context, old, obj client.Object) error | |
return err | ||
} | ||
kind := reflect.TypeOf(obj).String() | ||
log.Info("Updating "+kind, "Namespace", obj.GetNamespace(), "Name", obj.GetName()) | ||
log.Info("UPDATING "+kind, "Namespace", obj.GetNamespace(), "Name", obj.GetName()) | ||
err = c.Update(ctx, obj) | ||
if err != nil { | ||
log.Error(err, "Failed to update "+kind, "Namespace", obj.GetNamespace(), "Name", obj.GetName()) | ||
return err | ||
} | ||
err = c.Get(ctx, client.ObjectKeyFromObject(obj), obj) | ||
if err != nil { | ||
log.Error(err, "Failed to get updated resource "+kind, "Namespace", obj.GetNamespace(), "Name", obj.GetName()) | ||
return err | ||
} | ||
if obj.GetResourceVersion() != old.GetResourceVersion() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about using deep.Equal(old, obj) to know if it was updated or not ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess that would work also, but is there a benefit? A simple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. u never know what k8s do that is why I suggested to deepEqual to be 100% certain There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think given the official definition of resource version, we should be fine: https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions
That's exactly what's done here |
||
c.SetChanged(true) | ||
} else { | ||
log.Info(kind+" not updated", "Namespace", obj.GetNamespace(), "Name", obj.GetName()) | ||
} | ||
return nil | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,8 @@ func (w *Watcher) ProcessCACert(ctx context.Context, cl helper.Client, tls *flow | |
|
||
func (w *Watcher) reconcile(ctx context.Context, cl helper.Client, ref objectRef, destNamespace string) (string, error) { | ||
rlog := log.FromContext(ctx, "Name", ref.name, "Source namespace", ref.namespace, "Target namespace", destNamespace) | ||
report := helper.NewChangeReport("Watcher for " + string(ref.kind) + " " + ref.name) | ||
defer report.LogIfNeeded(ctx) | ||
|
||
w.watch(ref.kind, ref.name, ref.namespace) | ||
var watchable Watchable | ||
|
@@ -141,12 +143,19 @@ func (w *Watcher) reconcile(ctx context.Context, cl helper.Client, ref objectRef | |
return "", err | ||
} | ||
} else { | ||
// Update existing | ||
rlog.Info(fmt.Sprintf("updating %s %s in namespace %s", ref.kind, ref.name, destNamespace)) | ||
watchable.PrepareForUpdate(obj, target) | ||
if err := cl.UpdateOwned(ctx, target, target); err != nil { | ||
// Check for update | ||
targetDigest, err := watchable.GetDigest(target, ref.keys) | ||
if err != nil { | ||
return "", err | ||
} | ||
if report.Check("Digest changed", targetDigest != digest) { | ||
// Update existing | ||
rlog.Info(fmt.Sprintf("updating %s %s in namespace %s", ref.kind, ref.name, destNamespace)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this log spam the log file or its not expected to change too often ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no it's not expected to change often, hardly never, in fact: only during certificate rotations or if the certificate owner (kafka/loki/...) is reinstalled |
||
watchable.PrepareForUpdate(obj, target) | ||
if err := cl.UpdateOwned(ctx, target, target); err != nil { | ||
return "", err | ||
} | ||
} | ||
} | ||
} | ||
return digest, nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will break with older versions podman since it doesn't have
--amend
but since we default to docker at least out CI should be fineThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since recent podman does have
--amend
: https://docs.podman.io/en/latest/markdown/podman-manifest-create.1.html#options I think that's ok.idk in which version it was introduced, but the outdated version shipped with the github CI image that used once was really out of date in my understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/containers/podman/releases/tag/v4.3.0 or later