Skip to content

Commit

Permalink
kustomize edit add replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-chenzz committed Nov 16, 2023
1 parent 5308f95 commit c242a1e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions kustomize/commands/edit/add/addreplacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type addReplacementOptions struct {

func newCmdAddReplacement(fSys filesys.FileSystem) *cobra.Command {
var o addReplacementOptions
o.Replacement.Source = &types.SourceSelector{}
o.Replacement.Targets = append(o.Replacement.Targets, &types.TargetSelector{})
cmd := &cobra.Command{
Use: "replacement",
Short: "add an item to replacement field",
Expand Down Expand Up @@ -59,14 +61,19 @@ func (o *addReplacementOptions) RunAddReplacement(fSys filesys.FileSystem) error
return err

Check failure on line 61 in kustomize/commands/edit/add/addreplacement.go

View workflow job for this annotation

GitHub Actions / Lint

error returned from external package is unwrapped: sig: func (*sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile.kustomizationFile).Read() (*sigs.k8s.io/kustomize/api/types.Kustomization, error) (wrapcheck)
}

if o.Replacement.Targets != nil {
o.Replacement.Targets = nil
}
if o.Replacement.Source != nil {
o.Replacement.Source = nil
}

for _, r := range m.Replacements {
if r.Replacement.Source != nil || r.Replacement.Targets != nil {
if r.Path == o.Replacement.Path {
log.Printf("replacement %#v already in kustomization file", r)
return errors.New("already in kust")
}
if len(r.Path) > 0 && r.Path == o.Replacement.Path {
log.Printf("replacement %#v already in kustomization file", r)
return errors.New("already in kust")
}
m.Replacements = append(m.Replacements, r)
}
m.Replacements = append(m.Replacements, o.Replacement)
return mf.Write(m)

Check failure on line 78 in kustomize/commands/edit/add/addreplacement.go

View workflow job for this annotation

GitHub Actions / Lint

error returned from external package is unwrapped: sig: func (*sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile.kustomizationFile).Write(kustomization *sigs.k8s.io/kustomize/api/types.Kustomization) error (wrapcheck)
}

0 comments on commit c242a1e

Please sign in to comment.