Skip to content

chore: fix "make build" #976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contrib/functions/ts/sops/package-lock.json

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

2 changes: 1 addition & 1 deletion examples/apply-replacements-simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $ kpt fn render apply-replacements-simple

### Expected result

`job.yaml` should now have the following conents:
`job.yaml` should now have the following contents:

```yaml
apiVersion: batch/v1
Expand Down
2 changes: 0 additions & 2 deletions functions/go/apply-replacements/generated/docs.go

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

6 changes: 3 additions & 3 deletions functions/go/apply-setters/applysetters/apply_setters.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ For input ApplySetters [name: env, value: "[stage, prod]"], qthe yaml node is tr
environments: # kpt-set: ${env}
- stage
- prod

*/
func (as *ApplySetters) visitMapping(object *yaml.RNode, path string) error {
return object.VisitFields(func(node *yaml.MapNode) error {
Expand Down Expand Up @@ -180,15 +179,16 @@ e.g.for input of scalar node 'nginx:1.7.1 # kpt-set: ${image}:${tag}' in the yam

apiVersion: v1
...
image: nginx:1.7.1 # kpt-set: ${image}:${tag}

image: nginx:1.7.1 # kpt-set: ${image}:${tag}

and for input ApplySetters [[name: image, value: ubuntu], [name: tag, value: 1.8.0]]
The yaml node is transformed to

apiVersion: v1
...
image: ubuntu:1.8.0 # kpt-set: ${image}:${tag}

image: ubuntu:1.8.0 # kpt-set: ${image}:${tag}
*/
func (as *ApplySetters) visitScalar(object *yaml.RNode, path string) error {
if object.IsNil() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package applysetters

import (
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -438,18 +437,18 @@ roles: # kpt-set: ${roles}
for i := range tests {
test := tests[i]
t.Run(test.name, func(t *testing.T) {
baseDir, err := ioutil.TempDir("", "")
baseDir, err := os.MkdirTemp("", "")
if !assert.NoError(t, err) {
t.FailNow()
}
defer os.RemoveAll(baseDir)

r, err := ioutil.TempFile(baseDir, "k8s-cli-*.yaml")
r, err := os.CreateTemp(baseDir, "k8s-cli-*.yaml")
if !assert.NoError(t, err) {
t.FailNow()
}
defer os.Remove(r.Name())
err = ioutil.WriteFile(r.Name(), []byte(test.input), 0600)
err = os.WriteFile(r.Name(), []byte(test.input), 0600)
if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down Expand Up @@ -486,7 +485,7 @@ roles: # kpt-set: ${roles}
t.FailNow()
}

actualResources, err := ioutil.ReadFile(r.Name())
actualResources, err := os.ReadFile(r.Name())
if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down
4 changes: 1 addition & 3 deletions functions/go/apply-setters/generated/docs.go

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

2 changes: 1 addition & 1 deletion functions/go/apply-setters/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
)

//nolint
// nolint
func main() {
asp := ApplySettersProcessor{}
cmd := command.Build(&asp, command.StandaloneEnabled, false)
Expand Down
37 changes: 24 additions & 13 deletions functions/go/create-setters/createsetters/create_setters.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ func (cs *CreateSetters) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
return nodes, nil
}

/**
/*
*
preProcessScalarSetters simplifies the process of setting comments for
scalar values by creating a *strings.Replacer
e.g., For Scalar Setters [[name: image, value: nginx], [name: env, value: dev]].,
Expand All @@ -116,7 +117,8 @@ func (cs *CreateSetters) preProcessScalarSetters() {
cs.replacer = strings.NewReplacer(replacerArgs...)
}

/**
/*
*
visitMapping takes the mapping node and performs following steps,
checks if it is a sequence node
checks if all the values in the node match any of the ArraySetters
Expand Down Expand Up @@ -217,7 +219,8 @@ func (cs *CreateSetters) visitMapping(object *yaml.RNode, path string) error {
})
}

/**
/*
*
visitScalar accepts the input scalar node and performs following steps,
checks if it is a scalar node
adds the linecomment if it's value matches with any of the setter
Expand All @@ -226,16 +229,18 @@ e.g.for input of scalar node 'nginx:1.7.1' in the yaml node

apiVersion: v1
...
env: dev
image: nginx:1.7.1

env: dev
image: nginx:1.7.1

and for input CreateSetters [[name: image, value: nginx], [name: env, value: dev], [name: tag, value: 1.7.1]]
The yaml node is transformed to

apiVersion: v1
...
env: dev # kpt-set: ${env}
image: nginx:1.7.1 # kpt-set: ${image}:${tag}

env: dev # kpt-set: ${env}
image: nginx:1.7.1 # kpt-set: ${image}:${tag}
*/
func (cs *CreateSetters) visitScalar(object *yaml.RNode, path string) error {
if object.YNode().Kind != yaml.ScalarNode {
Expand Down Expand Up @@ -312,7 +317,8 @@ func hasMatchValue(nodeValues []string, setters []ScalarSetter) bool {
return false
}

/**
/*
*
getLineComment checks if any of the setters value matches with the node value
replaces that part of the node value with the ${setterName}
e.g.for input of scalar node 'nginx:1.7.1' in the yaml node
Expand All @@ -339,22 +345,27 @@ func getLineComment(nodeValue string, replacer *strings.Replacer) (string, bool)
return output, valueMatch
}

/**
/*
*
Decode decodes the input yaml node into CreatSetters struct
places the setter either in ScalarSetters or ArraySetters
sorts the ScalarSetters using CompareSetters

e.g.for input ScalarSetters
[[name: image, value: nginx], [name: ubuntu, value: nginx-abc]]

[[name: image, value: nginx], [name: ubuntu, value: nginx-abc]]

for scalar node:
spec: nginx-development

spec: nginx-development

Sorts the ScalarSetters to avoid following case of substrings
spec: nginx-abc-development # kpt-set: ${image}-abc-development

spec: nginx-abc-development # kpt-set: ${image}-abc-development

ScalarSetters array is transformed to
[[name: ubuntu, value: nginx-abc], [name: image, value: nginx]]

[[name: ubuntu, value: nginx-abc], [name: image, value: nginx]]
*/
func Decode(rn *yaml.RNode, fcd *CreateSetters) error {
if len(rn.GetDataMap()) == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package createsetters

import (
"fmt"
"io/ioutil"
"os"
"sort"
"strings"
Expand Down Expand Up @@ -525,18 +524,18 @@ spec:
for i := range tests {
test := tests[i]
t.Run(test.name, func(t *testing.T) {
baseDir, err := ioutil.TempDir("", "")
baseDir, err := os.MkdirTemp("", "")
if !assert.NoError(t, err) {
t.FailNow()
}
defer os.RemoveAll(baseDir)

r, err := ioutil.TempFile(baseDir, "k8s-cli-*.yaml")
r, err := os.CreateTemp(baseDir, "k8s-cli-*.yaml")
if !assert.NoError(t, err) {
t.FailNow()
}
defer os.Remove(r.Name())
err = ioutil.WriteFile(r.Name(), []byte(test.input), 0600)
err = os.WriteFile(r.Name(), []byte(test.input), 0600)
if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down Expand Up @@ -584,7 +583,7 @@ spec:
t.FailNow()
}

actualResources, err := ioutil.ReadFile(r.Name())
actualResources, err := os.ReadFile(r.Name())
if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down
2 changes: 0 additions & 2 deletions functions/go/create-setters/generated/docs.go

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

2 changes: 1 addition & 1 deletion functions/go/create-setters/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
)

//nolint
// nolint
func main() {
csp := CreateSettersProcessor{}
cmd := command.Build(&csp, command.StandaloneEnabled, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gcpservices

import (
"bytes"
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -709,14 +708,14 @@ metadata:
func setupInputs(t *testing.T, resourceMap map[string]string) string {
t.Helper()
require := require.New(t)
baseDir, err := ioutil.TempDir("", "")
baseDir, err := os.MkdirTemp("", "")
require.NoError(err)

for rpath, data := range resourceMap {
filePath := path.Join(baseDir, rpath)
err = os.MkdirAll(path.Dir(filePath), os.ModePerm)
require.NoError(err)
err = ioutil.WriteFile(path.Join(baseDir, rpath), []byte(data), 0644)
err = os.WriteFile(path.Join(baseDir, rpath), []byte(data), 0644)
require.NoError(err)
}
return baseDir
Expand Down
2 changes: 0 additions & 2 deletions functions/go/enable-gcp-services/generated/docs.go

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

2 changes: 1 addition & 1 deletion functions/go/enable-gcp-services/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"sigs.k8s.io/kustomize/kyaml/fn/framework/command"
)

//nolint
// nolint
func main() {
psf := ProjectServiceSetFunction{}
cmd := command.Build(&psf, command.StandaloneEnabled, false)
Expand Down
2 changes: 0 additions & 2 deletions functions/go/ensure-name-substring/generated/docs.go

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

1 change: 0 additions & 1 deletion functions/go/ensure-name-substring/nameref/nameref.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type nameReferenceConfig struct {
//
// If the Deployment's name changes, e.g. a prefix is added,
// then the HPA's reference to the Deployment must be fixed.
//
func FixNameBackReference(m resmap.ResMap) error {
c, err := getDefaultConfig()
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions functions/go/export-terraform/generated/docs.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package terraformgenerator

import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -95,7 +94,7 @@ func TestTerraformGeneration(t *testing.T) {
require.NoError(err)

// round-trip to disk to make sure all annotations are consistent
tmpDir, err := ioutil.TempDir("", "export-terraform-test-*")
tmpDir, err := os.MkdirTemp("", "export-terraform-test-*")
defer os.RemoveAll(tmpDir)
require.NoError(err)
err = testutil.ResourceListToDirectory(tempRL, tmpDir)
Expand Down Expand Up @@ -142,7 +141,7 @@ func TestTerraformGeneration(t *testing.T) {
// diff command) to do it. This will be addressed in the next iteration.
// The workaround is that we read the resource files as a ResourceList and
// then compare this ResourceList with the expected ResourceList.
tmpDir, err := ioutil.TempDir("", "export-terraform-test-*")
tmpDir, err := os.MkdirTemp("", "export-terraform-test-*")
defer os.RemoveAll(tmpDir)
require.NoError(err)
err = testutil.ResourceListToDirectory(actualRL, tmpDir)
Expand Down
5 changes: 2 additions & 3 deletions functions/go/fix/fixpkg/fix_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fixpkg

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -12,7 +11,7 @@ import (
)

func TestFixV1alpha1ToV1(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
assert.NoError(t, err)
defer os.RemoveAll(dir)
err = copyutil.CopyDir("../../../../testdata/fix/nginx-v1alpha1", dir)
Expand Down Expand Up @@ -57,7 +56,7 @@ func TestFixV1alpha1ToV1(t *testing.T) {
}

func TestFixV1alpha2ToV1(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
assert.NoError(t, err)
defer os.RemoveAll(dir)
err = copyutil.CopyDir("../../../../testdata/fix/nginx-v1alpha2", dir)
Expand Down
2 changes: 0 additions & 2 deletions functions/go/fix/generated/docs.go

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

2 changes: 1 addition & 1 deletion functions/go/fix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sigs.k8s.io/kustomize/kyaml/fn/framework/command"
)

//nolint
// nolint
func main() {
fp := FixProcessor{}
cmd := command.Build(&fp, command.StandaloneEnabled, false)
Expand Down
Loading