diff --git a/.golangci-kustomize.yml b/.golangci-kustomize.yml index c82a87361..e2fadf5ba 100644 --- a/.golangci-kustomize.yml +++ b/.golangci-kustomize.yml @@ -23,10 +23,12 @@ linters: - nakedret - staticcheck - structcheck - # - stylecheck (panics) + # stylecheck demands that acronyms not be treated as words + # in camelCase, so JsonOp become JSONOp, etc. Yuck. + # - stylecheck # - typecheck (fails in lots of places) - unconvert - # - unused (panics) + - unused - unparam - varcheck diff --git a/api/builtins/hashtransformer.go b/api/builtins/hashtransformer.go index 8de0d94bd..b96d90c24 100644 --- a/api/builtins/hashtransformer.go +++ b/api/builtins/hashtransformer.go @@ -23,7 +23,7 @@ func (p *HashTransformerPlugin) Config( // Transform appends hash to generated resources. func (p *HashTransformerPlugin) Transform(m resmap.ResMap) error { for _, res := range m.Resources() { - if res.NeedHashSuffix() { + if res.ShouldAddHashSuffixToName() { h, err := p.hasher.Hash(res) if err != nil { return err diff --git a/api/go.sum b/api/go.sum index 95908b3b9..9dfdab7f4 100644 --- a/api/go.sum +++ b/api/go.sum @@ -389,6 +389,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190909003024-a7b16738d86b h1:XfVGCX+0T4WOStkaOsJRllbsiImhB2jgVBGc9L0lPGc= golang.org/x/net v0.0.0-20190909003024-a7b16738d86b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= diff --git a/api/internal/accumulator/refvartransformer.go b/api/internal/accumulator/refvartransformer.go index 48f2b7396..1900cdc4b 100644 --- a/api/internal/accumulator/refvartransformer.go +++ b/api/internal/accumulator/refvartransformer.go @@ -70,7 +70,9 @@ func (rv *refVarTransformer) replaceVars(in interface{}) (interface{}, error) { // This field can potentially contain a $(VAR) since it is // of string type. return expansion2.Expand(s, rv.mappingFunc), nil - //nolint:staticcheck (erroneously claims that `case nil` is unreachable) + // staticcheck erroneously claims that `case nil` + // is unreachable here, so suppressing it. + //nolint:staticcheck case nil: return nil, nil default: diff --git a/api/internal/plugins/execplugin/execplugin_test.go b/api/internal/plugins/execplugin/execplugin_test.go index 9974ff96a..aa002868c 100644 --- a/api/internal/plugins/execplugin/execplugin_test.go +++ b/api/internal/plugins/execplugin/execplugin_test.go @@ -157,7 +157,7 @@ func TestUpdateResourceOptions(t *testing.T) { if !a.Equals(b) { t.Errorf("expected %v got %v", a, b) } - if a.NeedHashSuffix() != b.NeedHashSuffix() { + if a.ShouldAddHashSuffixToName() != b.ShouldAddHashSuffixToName() { t.Errorf("") } if a.Behavior() != b.Behavior() { diff --git a/api/internal/target/kusttarget.go b/api/internal/target/kusttarget.go index 093fe57d4..2ee0d03cf 100644 --- a/api/internal/target/kusttarget.go +++ b/api/internal/target/kusttarget.go @@ -222,11 +222,6 @@ func (kt *KustTarget) computeInventory( return ra.Transform(p) } -func (kt *KustTarget) shouldAddHashSuffixesToGeneratedResources() bool { - return kt.kustomization.GeneratorOptions == nil || - !kt.kustomization.GeneratorOptions.DisableNameSuffixHash -} - // AccumulateTarget returns a new ResAccumulator, // holding customized resources and the data/rules used // to do so. The name back references and vars are diff --git a/api/resource/resource.go b/api/resource/resource.go index 99939806a..7c44f9fcc 100644 --- a/api/resource/resource.go +++ b/api/resource/resource.go @@ -252,9 +252,10 @@ func (r *Resource) Behavior() types.GenerationBehavior { return r.options.Behavior() } -// NeedHashSuffix checks if the resource need a hash suffix -func (r *Resource) NeedHashSuffix() bool { - return r.options != nil && r.options.NeedsHashSuffix() +// ShouldAddHashSuffixToName returns true if a resource +// content hash should be appended to the name of the resource. +func (r *Resource) ShouldAddHashSuffixToName() bool { + return r.options != nil && r.options.ShouldAddHashSuffixToName() } // GetNamespace returns the namespace the resource thinks it's in. diff --git a/api/types/genargs.go b/api/types/genargs.go index 93acbad84..a80955b36 100644 --- a/api/types/genargs.go +++ b/api/types/genargs.go @@ -28,18 +28,17 @@ func (g *GenArgs) String() string { } return "{" + strings.Join([]string{ - "nsfx:" + strconv.FormatBool(g.NeedsHashSuffix()), + "nsfx:" + strconv.FormatBool(g.ShouldAddHashSuffixToName()), "beh:" + g.Behavior().String()}, ",") + "}" } -// NeedsHashSuffix returns true if the hash suffix is needed. -// It is needed when the two conditions are both met -// 1) GenArgs is not nil -// 2) DisableNameSuffixHash in GeneratorOptions is not set to true -func (g *GenArgs) NeedsHashSuffix() bool { - return g.args != nil && (g.opts == nil || !g.opts.DisableNameSuffixHash) +// ShouldAddHashSuffixToName returns true if a resource +// content hash should be appended to the name of the resource. +func (g *GenArgs) ShouldAddHashSuffixToName() bool { + return g.args != nil && + (g.opts == nil || !g.opts.DisableNameSuffixHash) } // Behavior returns Behavior field of GeneratorArgs