From 7326cf6f0f4f8b2fd4a71fd42fa20a28605b0afe Mon Sep 17 00:00:00 2001 From: nocturnalastro Date: Thu, 19 Sep 2024 13:52:50 +0100 Subject: [PATCH] Count leaves of the patch to find smallest diff In the case where a patch can not be made for one of the templates it will fallback to the old method of counting the number of lines --- pkg/compare/compare.go | 127 +++++++++++++----- .../localout.golden | 2 +- ...apps.v1.DaemonSet.kube-system.kindnet.yaml | 1 + 3 files changed, 95 insertions(+), 35 deletions(-) diff --git a/pkg/compare/compare.go b/pkg/compare/compare.go index 55e8a0cf..dbe71d7e 100644 --- a/pkg/compare/compare.go +++ b/pkg/compare/compare.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io/fs" - "math" "os" "path/filepath" "slices" @@ -34,21 +33,21 @@ import ( var ( compareLong = templates.LongDesc(` Compare a known valid reference configuration and a set of specific cluster configuration CRs. - - The reference configuration consists of Resource templates. + + The reference configuration consists of Resource templates. Resource Templates are files that contain Resource definitions and with fixed and optional content. Optional content is represented as Go templates. - The compare command will match each Resource in the cluster configuration to a Resource Template in the reference - configuration. Then, the templated Resource will be injected with the cluster Resource parameters. + The compare command will match each Resource in the cluster configuration to a Resource Template in the reference + configuration. Then, the templated Resource will be injected with the cluster Resource parameters. For each cluster Resource, a diff between the Resource and its matching injected template will be presented to the user. - + The input cluster configuration may be provided as an "offline" set of CRs or can be pulled from a live cluster. - + The Reference also includes a mandatory metadata.yaml file where all the Resource templates should be specified. The Resource templates can be divided into components. Each component and Resource template can be set as required, resulting in a report to the user in case one of them is missing. - - Each Resource definition should be in its own template file. + + Each Resource definition should be in its own template file. The input to the Go template is the "input cluster configuration" in order to allow expected user variable content to be synchronized between cluster CR and reference CR prior to the diff. The usage of all Go built-in functions is supported along with the functions in the Sprig library. @@ -56,20 +55,20 @@ var ( Before using functions that can fail for nil values, always check that the value exists. It's possible to pass a user config that contains an option to specify manual matches between cluster resources - and Resource templates. The matches can be added to the config as pairs of - apiVersion_kind_namespace_name: