Skip to content

Commit

Permalink
Code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
KnVerey committed Jul 14, 2022
1 parent 16f83e1 commit e9ea157
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
3 changes: 1 addition & 2 deletions api/filters/filtersutil/setters.go
Expand Up @@ -94,8 +94,7 @@ func hasExistingValue(node *yaml.RNode, key string) bool {
if node.IsNilOrEmpty() {
return false
}
if key == "" {
// scalar node
if err := yaml.ErrorIfInvalid(node, yaml.ScalarNode); err == nil {
return yaml.GetValue(node) != ""
}
entry := node.Field(key)
Expand Down
2 changes: 1 addition & 1 deletion api/filters/nameref/nameref.go
Expand Up @@ -337,7 +337,7 @@ func (f Filter) selectReferral(
return candidates[0], nil
}
ids := getIds(candidates)
return nil, fmt.Errorf(" found multiple possible referrals: %s\n%s", ids, f.failureDetails(candidates))
return nil, fmt.Errorf("found multiple possible referrals: %s\n%s", ids, f.failureDetails(candidates))
}

func (f Filter) failureDetails(resources []*resource.Resource) string {
Expand Down
13 changes: 4 additions & 9 deletions api/filters/namespace/namespace.go
Expand Up @@ -20,8 +20,8 @@ type Filter struct {
// FsSlice contains the FieldSpecs to locate the namespace field
FsSlice types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`

// SkipExisting means only blank namespace fields will be set
SkipExisting bool `json:"skipExisting" yaml:"skipExisting"`
// UnsetOnly means only blank namespace fields will be set
UnsetOnly bool `json:"UnsetOnly" yaml:"UnsetOnly"`

// SetRoleBindingSubjects determines which subject fields in RoleBinding and ClusterRoleBinding
// objects will have their namespace fields set. Overrides field specs provided for these types, if any.
Expand Down Expand Up @@ -160,12 +160,7 @@ func (ns Filter) roleBindingHack(obj *yaml.RNode, gvk resid.Gvk) error {
}

func isRoleBinding(kind string) bool {
switch kind {
case roleBindingKind, clusterRoleBindingKind:
return true
default:
return false
}
return kind == roleBindingKind || kind == clusterRoleBindingKind
}

// removeRoleBindingFieldSpecs removes from the list fieldspecs that
Expand Down Expand Up @@ -193,7 +188,7 @@ func (ns Filter) removeMetaNamespaceFieldSpecs(fs types.FsSlice) types.FsSlice {
}

func (ns *Filter) fieldSetter() filtersutil.SetFn {
if ns.SkipExisting {
if ns.UnsetOnly {
return ns.trackableSetter.SetEntryIfEmpty("", ns.Namespace, yaml.NodeTagString)
}
return ns.trackableSetter.SetEntry("", ns.Namespace, yaml.NodeTagString)
Expand Down
4 changes: 2 additions & 2 deletions api/internal/builtins/NamespaceTransformer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions plugin/builtin/namespacetransformer/NamespaceTransformer.go
Expand Up @@ -18,7 +18,7 @@ import (
type plugin struct {
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
SkipExisting bool `json:"skipExisting" yaml:"skipExisting"`
UnsetOnly bool `json:"unsetOnly" yaml:"unsetOnly"`
SetRoleBindingSubjects namespace.RoleBindingSubjectMode `json:"setRoleBindingSubjects" yaml:"setRoleBindingSubjects"`
}

Expand Down Expand Up @@ -58,7 +58,7 @@ func (p *plugin) Transform(m resmap.ResMap) error {
Namespace: p.Namespace,
FsSlice: p.FieldSpecs,
SetRoleBindingSubjects: p.SetRoleBindingSubjects,
SkipExisting: p.SkipExisting,
UnsetOnly: p.UnsetOnly,
}); err != nil {
return err
}
Expand Down
Expand Up @@ -272,7 +272,7 @@ metadata:
})
}

func TestNamespaceTransformer_SkipExistingTrue(t *testing.T) {
func TestNamespaceTransformer_UnsetOnlyTrue(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
PrepBuiltin("NamespaceTransformer")
defer th.Reset()
Expand All @@ -282,7 +282,7 @@ kind: NamespaceTransformer
metadata:
name: notImportantHere
namespace: test
skipExisting: true
unsetOnly: true
fieldSpecs:
- path: metadata/namespace
create: true
Expand Down

0 comments on commit e9ea157

Please sign in to comment.