Skip to content
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

🌱 ClusterClass: improve logging #5751

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions controllers/topology/desired_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ func (r *ClusterReconciler) computeDesiredState(ctx context.Context, s *scope.Sc
// corresponding template defined in the blueprint.
func computeInfrastructureCluster(_ context.Context, s *scope.Scope) (*unstructured.Unstructured, error) {
template := s.Blueprint.InfrastructureClusterTemplate
templateClonedFromref := s.Blueprint.ClusterClass.Spec.Infrastructure.Ref
templateClonedFromRef := s.Blueprint.ClusterClass.Spec.Infrastructure.Ref
cluster := s.Current.Cluster
currentRef := cluster.Spec.InfrastructureRef

infrastructureCluster, err := templateToObject(templateToInput{
template: template,
templateClonedFromRef: templateClonedFromref,
templateClonedFromRef: templateClonedFromRef,
cluster: cluster,
namePrefix: fmt.Sprintf("%s-", cluster.Name),
currentObjectRef: currentRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type TemplateRef struct {
MachineDeploymentRef MachineDeploymentRef
}

func (t *TemplateRef) String() string {
func (t TemplateRef) String() string {
Copy link
Member Author

@sbueringer sbueringer Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the String func should always be implemented with a value receiver. That way it works independent of if the TemplateRef is a pointer or not (I tested it with ~ fmt.Sprintf("%s %s", &api.TemplateRef{..}, api.TemplateRef{..})

This leads to the question if we should fix it in other cases too:

  • func (n *Node) String() string {

    • exported type in test/infrastructure/docker/docker/types
  • func (p *ProviderID) String() string {

    • exported type in controllers/noderefutil
  • func (n *NetworkRanges) String() string {

    • exported type in api/v1beta1
  • func (t *healthCheckTarget) string() string {

    • Just saw that one is lower case so it doesn't implement the interface anyway

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's open an issue for this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: #5755

ret := fmt.Sprintf("%s %s/%s", t.TemplateType, t.APIVersion, t.Kind)
if t.MachineDeploymentRef.TopologyName != "" {
ret = fmt.Sprintf("%s, MachineDeployment topology %s", ret, t.MachineDeploymentRef.TopologyName)
Expand Down
6 changes: 3 additions & 3 deletions controllers/topology/internal/extensions/patches/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func applyPatchesToRequest(ctx context.Context, req *api.GenerateRequest, resp *
log := tlog.LoggerFrom(ctx)

for _, patch := range resp.Items {
log = log.WithValues("templateRef", patch.TemplateRef)
log = log.WithValues("templateRef", patch.TemplateRef.String())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to call the .String() func here explicitly because WithValues (and its underlying funcs) does not automatically use String() if the type implements the Stringer interface like fmt.Sprintf does


// Get the template the patch should be applied to.
template := getTemplate(req, patch.TemplateRef)
Expand All @@ -264,7 +264,7 @@ func applyPatchesToRequest(ctx context.Context, req *api.GenerateRequest, resp *

switch patch.PatchType {
case api.JSONPatchType:
log.V(5).Infof("Accumulating JSON patch", "patch", string(patch.Patch.Raw))
log.V(5).Infof("Accumulating JSON patch: %s", string(patch.Patch.Raw))
jsonPatch, err := jsonpatch.DecodePatch(patch.Patch.Raw)
if err != nil {
return errors.Wrapf(err, "failed to apply patch to template %s: error decoding json patch (RFC6902): %s",
Expand All @@ -277,7 +277,7 @@ func applyPatchesToRequest(ctx context.Context, req *api.GenerateRequest, resp *
template.TemplateRef, string(patch.Patch.Raw))
}
case api.JSONMergePatchType:
log.V(5).Infof("Accumulating JSON merge patch", "patch", string(patch.Patch.Raw))
log.V(5).Infof("Accumulating JSON merge patch: %s", string(patch.Patch.Raw))
patchedTemplate, err = jsonpatch.MergePatch(template.Template.Raw, patch.Patch.Raw)
if err != nil {
return errors.Wrapf(err, "failed to apply patch to template %s: error applying json merge patch (RFC7386): %s",
Expand Down
2 changes: 1 addition & 1 deletion controllers/topology/internal/extensions/patches/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func patchUnstructured(ctx context.Context, original, modified *unstructured.Uns
}

// Log the delta between the object before and after applying the accumulated patches.
log.V(4).WithObject(original).Infof("Applying accumulated patches", "diff", string(diff))
log.V(4).WithObject(original).Infof("Applying accumulated patches to desired state: %s", string(diff))

// Overwrite original.
*original = *patched
Expand Down