From 82d095a7890d9e5ab2cddd01f6b312e87908ed34 Mon Sep 17 00:00:00 2001 From: dee0sap <82829708+dee0sap@users.noreply.github.com> Date: Wed, 15 May 2024 02:57:17 -0700 Subject: [PATCH] Fix issue 186 - default is ignored (#420) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change. ## What type of PR is this? (check all applicable) - [ ] 🍕 Feature - [x] 🐛 Bug Fix - [ ] 📝 Documentation Update - [ ] 🎨 Style - [ ] 🧑‍💻 Code Refactor - [ ] 🔥 Performance Improvements - [x] ✅ Test - [ ] 🤖 Build - [ ] 🔁 CI - [ ] 📦 Chore (Release) - [ ] ⏩ Revert ## Related Tickets & Documents - Related Issue # (issue) - Closes # 186 - Fixes # 186 > Remove if not applicable ## Screenshots ## Added tests? - [x ] 👍 yes - [ ] 🙅 no, because they aren't needed - [ ] 🙋 no, because I need help - [ ] Separate ticket for tests # (issue/pr) Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration ## Added to documentation? - [ ] 📜 README.md - [x ] 🙅 no documentation needed ## Checklist: - [x ] My code follows the style guidelines of this project - [ x] I have performed a self-review of my code - [ x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x ] My changes generate no new warnings - [ x] I have added tests that prove my fix is effective or that my feature works - [ x] New and existing unit tests pass locally with my changes ** - [ ] Any dependent changes have been merged and published in downstream modules ** NOTE: Tests in screenshot below are failing on the main branch as well. So while not all tests are passing with my change it is not the case that I added any new failures. ![image](https://github.com/open-component-model/ocm-controller/assets/82829708/0d33bf10-a889-44ee-b7ce-4f784e1126be) --------- Co-authored-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> --- controllers/mutation_reconcile_looper.go | 40 ++--- controllers/mutation_reconcile_looper_test.go | 32 ++++ controllers/spifftemplatedoc.go | 139 ++++++++++++++++++ controllers/yqlib_log_init.go | 20 +++ go.mod | 18 ++- go.sum | 41 +++++- main.go | 7 + 7 files changed, 257 insertions(+), 40 deletions(-) create mode 100644 controllers/spifftemplatedoc.go create mode 100644 controllers/yqlib_log_init.go diff --git a/controllers/mutation_reconcile_looper.go b/controllers/mutation_reconcile_looper.go index 40fb319c..5b107a55 100644 --- a/controllers/mutation_reconcile_looper.go +++ b/controllers/mutation_reconcile_looper.go @@ -507,47 +507,31 @@ func (m *MutationReconcileLooper) createSubstitutionRulesForConfigurationValues( func (m *MutationReconcileLooper) generateSubstitutions( subst []localize.Substitution, - defaults, values, schema []byte, + defaults, configValues, schema []byte, ) (localize.Substitutions, error) { - // configure defaults - templ := make(map[string]any) - if err := ocmruntime.DefaultYAMLEncoding.Unmarshal(defaults, &templ); err != nil { - return nil, fmt.Errorf("cannot unmarshal template: %w", err) - } - - // configure values overrides... must be a better way - var valuesMap map[string]any - if err := ocmruntime.DefaultYAMLEncoding.Unmarshal(values, &valuesMap); err != nil { - return nil, fmt.Errorf("cannot unmarshal values: %w", err) - } + var err error + var spiffTemplateDoc *spiffTemplateDoc - for k, v := range valuesMap { - if _, ok := templ[k]; ok { - templ[k] = v - } + if spiffTemplateDoc, err = mergeDefaultsAndConfigValues(defaults, configValues); err != nil { + return nil, err } - // configure adjustments - list := []any{} - for _, e := range subst { - list = append(list, e) + if err = spiffTemplateDoc.addSpiffRules(subst); err != nil { + return nil, err } - templateKey := "ocmAdjustmentsTemplateKey" - templ[templateKey] = list - - templateBytes, err := ocmruntime.DefaultJSONEncoding.Marshal(templ) - if err != nil { - return nil, fmt.Errorf("cannot marshal template: %w", err) + var spiffTemplateBytes []byte + if spiffTemplateBytes, err = spiffTemplateDoc.marshal(); err != nil { + return nil, err } if len(schema) > 0 { - if err := spiff.ValidateByScheme(values, schema); err != nil { + if err := spiff.ValidateByScheme(configValues, schema); err != nil { return nil, fmt.Errorf("validation failed: %w", err) } } - config, err := spiff.CascadeWith(spiff.TemplateData(templateKey, templateBytes), spiff.Mode(spiffing.MODE_PRIVATE)) + config, err := spiff.CascadeWith(spiff.TemplateData(ocmAdjustmentsTemplateKey, spiffTemplateBytes), spiff.Mode(spiffing.MODE_PRIVATE)) if err != nil { return nil, fmt.Errorf("error while doing cascade with: %w", err) } diff --git a/controllers/mutation_reconcile_looper_test.go b/controllers/mutation_reconcile_looper_test.go index 715c6837..611ae033 100644 --- a/controllers/mutation_reconcile_looper_test.go +++ b/controllers/mutation_reconcile_looper_test.go @@ -6,6 +6,7 @@ package controllers import ( "context" + "encoding/json" "testing" "cuelang.org/go/cue" @@ -17,6 +18,7 @@ import ( v1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1" "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1" + "github.com/open-component-model/ocm/pkg/contexts/ocm/utils/localize" ocmruntime "github.com/open-component-model/ocm/pkg/runtime" "github.com/open-component-model/ocm-controller/api/v1alpha1" @@ -43,6 +45,36 @@ type reference struct { component string } +func TestGenerateSubstitutionsUseDefaults(t *testing.T) { + m := &MutationReconcileLooper{} + iSbs := localize.Substitutions{ + localize.Substitution{ + FilePath: "values.yaml", + ValueMapping: localize.ValueMapping{ + Name: "1", + ValuePath: "dmi.gcp_project_id", + Value: []byte("\"(( dmi.gcp_project_id ))\""), + }, + }, + } + + dflts := `dmi: + some_aws_val: foo + gcp_project_id: ~` + + vls := `dmi: + some_aws_val: blah` + + schm := "" + + oSbs, err := m.generateSubstitutions(iSbs, []byte(dflts), []byte(vls), []byte(schm)) + assert.NoError(t, err) + assert.Equal(t, len(iSbs), len(oSbs)) + var expected json.RawMessage + expected.UnmarshalJSON([]byte("null")) + assert.Equal(t, oSbs[0].ValueMapping.Value, expected) +} + func TestPopulateReferences(t *testing.T) { ctx := context.Background() cueCtx := cuecontext.New() diff --git a/controllers/spifftemplatedoc.go b/controllers/spifftemplatedoc.go new file mode 100644 index 00000000..3ca7f97d --- /dev/null +++ b/controllers/spifftemplatedoc.go @@ -0,0 +1,139 @@ +// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package controllers + +import ( + "bytes" + "container/list" + "fmt" + + "github.com/mikefarah/yq/v4/pkg/yqlib" + "github.com/open-component-model/ocm/pkg/contexts/ocm/utils/localize" + ocmruntime "github.com/open-component-model/ocm/pkg/runtime" +) + +// Key we store spiff rules under within spiff template doc. +const ocmAdjustmentsTemplateKey = "ocmAdjustmentsTemplateKey" + +// makeYqNode unmarshalls bytes into a CandidateNode +// In order to make debugging easier later during yaml processing we take in +// file name, document index and file index values which are then set on +// the CandidateNode. +func makeYqNode(docBytes []byte, fileName string, docIndex, fileIndex uint) (*yqlib.CandidateNode, error) { + yamlPreferences := yqlib.NewDefaultYamlPreferences() + yamlDecoder := yqlib.NewYamlDecoder(yamlPreferences) + rdr := bytes.NewBuffer(docBytes) + + if err := yamlDecoder.Init(rdr); err != nil { + return nil, err + } + + ret, err := yamlDecoder.Decode() + if err != nil { + return nil, err + } + + ret.SetDocument(docIndex) + ret.SetFilename(fileName) + ret.SetFileIndex(int(fileIndex)) + + return ret, nil +} + +// spiffTemplateDoc is a wrapper around CandidateNode. Its purpose is to make the code in +// MutationReconcileLooper::generateSubstitutions easier to read. +// +// spiffTemplateDoc also represents a spiff++ template with a particular structure : +// ( defaults yaml merged with config values yaml ) +// + sequence of ocm controller conifg rules stored under the key 'ocmAdjustmentsTemplateKey'. +type spiffTemplateDoc yqlib.CandidateNode + +// Store subst, in json form, under key ocmAdjustmentsTemplateKey. +func (s *spiffTemplateDoc) addSpiffRules(subst []localize.Substitution) error { + var err error + + var adjustmentBytes []byte + if adjustmentBytes, err = ocmruntime.DefaultJSONEncoding.Marshal(subst); err != nil { + return fmt.Errorf("failed to marshal substitutions: %w", err) + } + + var adjustmentsDoc *yqlib.CandidateNode + + const fileIndex = 2 + if adjustmentsDoc, err = makeYqNode(adjustmentBytes, "adjustments", 0, fileIndex); err != nil { + return fmt.Errorf("failed to marshal adjustments: %w", err) + } + + ((*yqlib.CandidateNode)(s)).AddKeyValueChild( + &yqlib.CandidateNode{ + Kind: yqlib.ScalarNode, + Value: ocmAdjustmentsTemplateKey, + }, + adjustmentsDoc) + + return nil +} + +func (s *spiffTemplateDoc) marshal() ([]byte, error) { + encoder := yqlib.NewYamlEncoder(yqlib.NewDefaultYamlPreferences()) + buf := bytes.NewBuffer([]byte{}) + pw := yqlib.NewSinglePrinterWriter(buf) + p := yqlib.NewPrinter(encoder, pw) + + // Often yq is working with list of nodes because matches what + // yaml files are. Yaml files are sequences of yaml documents. + // This is one of those case. + nodes := list.New() + nodes.PushBack(((*yqlib.CandidateNode)(s))) + + if err := p.PrintResults(nodes); err != nil { + return nil, fmt.Errorf("failed to print results: %w", err) + } + + return buf.Bytes(), nil +} + +// mergeDefaultsAndConfigValues unmarshals defaults and configValues to yaml +// and then returns the deep merge result produced by yqlib. +func mergeDefaultsAndConfigValues(defaults, configValues []byte) (*spiffTemplateDoc, error) { + var err error + var defaultsDoc, configValuesDoc *yqlib.CandidateNode + + if defaultsDoc, err = makeYqNode(defaults, "defaults", 0, 0); err != nil { + return nil, fmt.Errorf("failed to make default document: %w", err) + } + + if configValuesDoc, err = makeYqNode(configValues, "values", 0, 1); err != nil { + return nil, fmt.Errorf("failed to parse values values: %w", err) + } + + evaluator := yqlib.NewAllAtOnceEvaluator() + var mergeResult *list.List + const mergeExpression = ". as $item ireduce({}; . * $item )" + + // We get back a list because yq supports expressions that produce + // multiple yaml documents. + // And unfortunately golang lists aren't type safe. + // So now we have all these assertions to make sure we got back a single + // yaml document like we expect. + if mergeResult, err = evaluator.EvaluateNodes(mergeExpression, defaultsDoc, configValuesDoc); err != nil { + return nil, fmt.Errorf("failed to evaluate nodes: %w", err) + } + + if docCount := mergeResult.Len(); docCount != 1 { + return nil, fmt.Errorf("merge of defaults and config has incorrect doc count. docCount: %v expression: '%v' defaults: '%v' config values '%v", + docCount, mergeExpression, defaultsDoc, configValuesDoc) + } + + if value := mergeResult.Front().Value; value == nil { + return nil, fmt.Errorf("merge of defaults and config values produced nil result. expression: '%v' defaults: '%v' config values '%v", + mergeExpression, defaultsDoc, configValuesDoc) + } else if node, ok := value.(*yqlib.CandidateNode); ok { + return ((*spiffTemplateDoc)(node)), nil + } + + return nil, fmt.Errorf("merge of defaults and config values did not produce *CandidateNode. expression: '%v' defaults: '%v' config values '%v", + mergeExpression, defaultsDoc, configValuesDoc) +} diff --git a/controllers/yqlib_log_init.go b/controllers/yqlib_log_init.go new file mode 100644 index 00000000..d5352684 --- /dev/null +++ b/controllers/yqlib_log_init.go @@ -0,0 +1,20 @@ +//go:build test + +// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package controllers + +import ( + glog "gopkg.in/op/go-logging.v1" +) + +// In production main func will take care of setting the log yq-lib log level. +// In test we count on this to set the default log level for all tests. +// We do this because yqlib log is very chatty even if it is sometimes very useful. +// Of course in an individual test one could change the level and reset to the default +// via a defer call. +func init() { + glog.SetLevel(glog.WARNING, "yq-lib") +} diff --git a/go.mod b/go.mod index d00fbb73..478bdcd2 100644 --- a/go.mod +++ b/go.mod @@ -61,6 +61,7 @@ require ( github.com/vmware-labs/yaml-jsonpath v0.3.2 github.com/xeipuuv/gojsonschema v1.2.0 golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc + gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 helm.sh/helm/v3 v3.14.2 k8s.io/apimachinery v0.29.0 k8s.io/client-go v0.29.0 @@ -92,7 +93,9 @@ require ( github.com/Microsoft/hcsshim v0.12.0-rc.1 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c // indirect github.com/ThalesIgnite/crypto11 v1.2.5 // indirect + github.com/a8m/envsubst v1.4.2 // indirect github.com/acomagu/bufpipe v1.0.3 // indirect + github.com/alecthomas/participle/v2 v2.1.1 // indirect github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 // indirect github.com/alibabacloud-go/cr-20160607 v1.0.1 // indirect github.com/alibabacloud-go/cr-20181201 v1.0.10 // indirect @@ -161,6 +164,7 @@ require ( github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960 // indirect github.com/drone/envsubst v1.0.3 // indirect + github.com/elliotchance/orderedmap v1.5.1 // indirect github.com/emicklei/go-restful/v3 v3.11.1 // indirect github.com/evanphx/json-patch v5.7.0+incompatible // indirect github.com/evanphx/json-patch/v5 v5.7.0 // indirect @@ -194,6 +198,7 @@ require ( github.com/go-openapi/strfmt v0.22.1 // indirect github.com/go-openapi/validate v0.22.4 // indirect github.com/go-test/deep v1.1.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect github.com/goccy/go-yaml v1.11.3 // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang/snappy v0.0.4 // indirect @@ -224,6 +229,7 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267 // indirect + github.com/jinzhu/copier v0.4.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/klauspost/compress v1.17.4 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect @@ -256,7 +262,7 @@ require ( github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pborman/uuid v1.2.1 // indirect github.com/pelletier/go-toml v1.9.5 // indirect - github.com/pelletier/go-toml/v2 v2.1.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.0 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect @@ -299,6 +305,7 @@ require ( github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xlab/treeprint v1.2.0 // indirect + github.com/yuin/gopher-lua v1.1.1 // indirect github.com/zeebo/blake3 v0.2.3 // indirect github.com/zeebo/errs v1.3.0 // indirect go.mongodb.org/mongo-driver v1.14.0 // indirect @@ -347,6 +354,7 @@ require ( github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/mailru/easyjson v0.7.7 // indirect + github.com/mikefarah/yq/v4 v4.43.1 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect @@ -358,11 +366,11 @@ require ( github.com/spf13/pflag v1.0.5 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.26.0 // indirect - golang.org/x/crypto v0.19.0 // indirect - golang.org/x/net v0.20.0 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/net v0.22.0 // indirect golang.org/x/oauth2 v0.16.0 // indirect - golang.org/x/sys v0.17.0 // indirect - golang.org/x/term v0.17.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/term v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 1cbbd314..2c7b36a7 100644 --- a/go.sum +++ b/go.sum @@ -86,8 +86,16 @@ github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d h1:UrqY+r/O github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ= github.com/ThalesIgnite/crypto11 v1.2.5 h1:1IiIIEqYmBvUYFeMnHqRft4bwf/O36jryEUpY+9ef8E= github.com/ThalesIgnite/crypto11 v1.2.5/go.mod h1:ILDKtnCKiQ7zRoNxcp36Y1ZR8LBPmR2E23+wTQe/MlE= +github.com/a8m/envsubst v1.4.2 h1:4yWIHXOLEJHQEFd4UjrWDrYeYlV7ncFWJOCBRLOZHQg= +github.com/a8m/envsubst v1.4.2/go.mod h1:MVUTQNGQ3tsjOOtKCNd+fl8RzhsXcDvvAEzkhGtlsbY= github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk= github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= +github.com/alecthomas/assert/v2 v2.3.0 h1:mAsH2wmvjsuvyBvAmCtm7zFsBlb8mIHx5ySLVdDZXL0= +github.com/alecthomas/assert/v2 v2.3.0/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= +github.com/alecthomas/participle/v2 v2.1.1 h1:hrjKESvSqGHzRb4yW1ciisFJ4p3MGYih6icjJvbsmV8= +github.com/alecthomas/participle/v2 v2.1.1/go.mod h1:Y1+hAs8DHPmc3YUFzqllV+eSQ9ljPTk0ZkPMtEdAx2c= +github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= +github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= @@ -334,6 +342,8 @@ github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9 github.com/dvsekhvalnov/jose2go v0.0.0-20170216131308-f21a8cedbbae/go.mod h1:7BvyPhdbLxMXIYTFPLsyJRFMsKmOZnQmzh6Gb+uquuM= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153 h1:yUdfgN0XgIJw7foRItutHYUIhlcKzcSf5vDpdhQAKTc= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= +github.com/elliotchance/orderedmap v1.5.1 h1:G1X4PYlljzimbdQ3RXmtIZiQ9d6aRQ3sH1nzjq5mECE= +github.com/elliotchance/orderedmap v1.5.1/go.mod h1:wsDwEaX5jEoyhbs7x93zk2H/qv0zwuhg4inXhDkYqys= github.com/emicklei/go-restful/v3 v3.11.1 h1:S+9bSbua1z3FgCnV0KKOSSZ3mDthb5NyEPL5gEpCvyk= github.com/emicklei/go-restful/v3 v3.11.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/emicklei/proto v1.10.0 h1:pDGyFRVV5RvV+nkBK9iy3q67FBy9Xa7vwrOTE+g5aGw= @@ -477,6 +487,8 @@ github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEe github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-yaml v1.11.3 h1:B3W9IdWbvrUu2OYQGwvU1nZtvMQJPBKgBUuweJjLj6I= github.com/goccy/go-yaml v1.11.3/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= @@ -613,6 +625,8 @@ github.com/hashicorp/vault-client-go v0.4.3 h1:zG7STGVgn/VK6rnZc0k8PGbfv2x/sJExR github.com/hashicorp/vault-client-go v0.4.3/go.mod h1:4tDw7Uhq5XOxS1fO+oMtotHL7j4sB9cp0T7U6m4FzDY= github.com/hashicorp/vault/api v1.10.0 h1:/US7sIjWN6Imp4o/Rj1Ce2Nr5bki/AXi9vAW3p2tOJQ= github.com/hashicorp/vault/api v1.10.0/go.mod h1:jo5Y/ET+hNyz+JnKDt8XLAdKs+AM0G5W0Vp1IrFI8N8= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef h1:A9HsByNhogrvm9cWb28sjiS3i7tcKCkflWFEkHfuAgM= github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -632,6 +646,8 @@ github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267/go.mod h1:h1n github.com/jellydator/ttlcache/v3 v3.1.1 h1:RCgYJqo3jgvhl+fEWvjNW8thxGWsgxi+TPhRir1Y9y8= github.com/jellydator/ttlcache/v3 v3.1.1/go.mod h1:hi7MGFdMAwZna5n2tuvh63DvFLzVKySzCVW6+0gA2n4= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= +github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8= +github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= github.com/jinzhu/gorm v0.0.0-20170222002820-5409931a1bb8/go.mod h1:Vla75njaFJ8clLU1W44h34PjIkijhjHIYnZxMqCdxqo= github.com/jinzhu/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o= github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs= @@ -719,6 +735,8 @@ github.com/miekg/pkcs11 v1.0.2/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WT github.com/miekg/pkcs11 v1.0.3-0.20190429190417-a667d056470f/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= github.com/miekg/pkcs11 v1.1.1 h1:Ugu9pdy6vAYku5DEpVWVFPYnzV+bxB+iRdbuFSu7TvU= github.com/miekg/pkcs11 v1.1.1/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= +github.com/mikefarah/yq/v4 v4.43.1 h1:1bCrQwVDhjGnPboQidy30hu6U2TCd8sUQTy1hKCHOGI= +github.com/mikefarah/yq/v4 v4.43.1/go.mod h1:jcSqtyUKbPWvwaa8cNw8Ej4rmPb3iWE8zYvpkTvM7oc= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -810,8 +828,8 @@ github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw= github.com/pborman/uuid v1.2.1/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= -github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= -github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pelletier/go-toml/v2 v2.2.0 h1:QLgLl2yMN7N+ruc31VynXs1vhMZa7CeHHejIeBAsoHo= +github.com/pelletier/go-toml/v2 v2.2.0/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 h1:Ii+DKncOVM8Cu1Hc+ETb5K+23HdAMvESYE3ZJ5b5cMI= @@ -819,6 +837,8 @@ github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rK github.com/pjbgf/sha1cd v0.2.3/go.mod h1:HOK9QrgzdHpbc2Kzip0Q1yi3M2MFGPADtR6HjG65m5M= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -1012,6 +1032,8 @@ github.com/yuin/goldmark v1.1.30/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M= +github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43 h1:+lm10QQTNSBd8DVTNGHx7o/IKu9HYDvLMffDhbyLccI= github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs= github.com/yvasiyarov/gorelic v0.0.0-20141212073537-a9bba5b9ab50 h1:hlE8//ciYMztlGpl/VA+Zm1AcTPHYkHJPbHqE6WJUXE= @@ -1080,8 +1102,9 @@ golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2Uz golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= -golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM= golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= @@ -1129,8 +1152,8 @@ golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ= @@ -1189,8 +1212,9 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -1201,8 +1225,9 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo= -golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= +golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -1307,6 +1332,8 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 h1:6D+BvnJ/j6e222UW8s2qTSe3wGBtvo0MbVQG/c5k8RE= +gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473/go.mod h1:N1eN2tsCx0Ydtgjl4cqmbRCsY4/+z4cYDeqwZTk6zog= gopkg.in/rethinkdb/rethinkdb-go.v6 v6.2.1 h1:d4KQkxAaAiRY2h5Zqis161Pv91A37uZyJOx73duwUwM= gopkg.in/rethinkdb/rethinkdb-go.v6 v6.2.1/go.mod h1:WbjuEoo1oadwzQ4apSDU+JTvmllEHtsNHS6y7vFc7iw= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= diff --git a/main.go b/main.go index bda1d685..868cdda5 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( "github.com/fluxcd/pkg/runtime/events" sourcev1 "github.com/fluxcd/source-controller/api/v1" sourcev1beta2 "github.com/fluxcd/source-controller/api/v1beta2" + glog "gopkg.in/op/go-logging.v1" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/dynamic" @@ -111,6 +112,12 @@ func main() { flag.Parse() ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) + // 2024-05-11 : + // We're setting the go-log leve because it is used by yqlib + // If we ever make it possible to set the log level for the service + // , I mean stop hard coding the log level, then we will need to remember + // to set it both for controller-runtime ( i.e. zap ) and yqlib ( i.e. go-log ) + glog.SetLevel(glog.WARNING, "yq-lib") restConfig := ctrl.GetConfigOrDie()