diff --git a/bin/pre-commit.sh b/bin/pre-commit.sh index 11b0cf91f..27caee5c0 100755 --- a/bin/pre-commit.sh +++ b/bin/pre-commit.sh @@ -35,6 +35,10 @@ function testGoImports { diff -u <(echo -n) <(go_dirs | xargs -0 goimports -l) } +function testGoLint { + diff -u <(echo -n) <(go_dirs | xargs -0 golint --min_confidence 0.85 ) +} + function testGoVet { go vet -all ./... } @@ -49,6 +53,7 @@ function testExamples { runTest testGoFmt runTest testGoImports +runTest testGoLint runTest testGoVet runTest testGoTest runTest testExamples diff --git a/pkg/app/application.go b/pkg/app/application.go index 09f55a152..552d75808 100644 --- a/pkg/app/application.go +++ b/pkg/app/application.go @@ -35,6 +35,7 @@ import ( "github.com/kubernetes-sigs/kustomize/pkg/types" ) +// Application interface exposes methods to get resources of the application. type Application interface { // Resources computes and returns the resources for the app. Resources() (resmap.ResMap, error) @@ -57,7 +58,7 @@ type applicationImpl struct { loader loader.Loader } -// NewApp parses the kustomization file at the path using the loader. +// New parses the kustomization file at the path using the loader and returns application. func New(loader loader.Loader) (Application, error) { content, err := loader.Load(constants.KustomizationFileName) if err != nil { diff --git a/pkg/configmapandsecret/util/configmap.go b/pkg/configmapandsecret/util/configmap.go index a8dc2ebdd..bf3c2d0f0 100644 --- a/pkg/configmapandsecret/util/configmap.go +++ b/pkg/configmapandsecret/util/configmap.go @@ -27,7 +27,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation" ) -// handleConfigMapFromLiteralSources adds the specified literal source +// HandleConfigMapFromLiteralSources adds the specified literal source // information into the provided configMap. func HandleConfigMapFromLiteralSources(configMap *v1.ConfigMap, literalSources []string) error { for _, literalSource := range literalSources { @@ -43,7 +43,7 @@ func HandleConfigMapFromLiteralSources(configMap *v1.ConfigMap, literalSources [ return nil } -// handleConfigMapFromFileSources adds the specified file source information +// HandleConfigMapFromFileSources adds the specified file source information // into the provided configMap func HandleConfigMapFromFileSources(configMap *v1.ConfigMap, fileSources []string) error { for _, fileSource := range fileSources { @@ -88,7 +88,7 @@ func HandleConfigMapFromFileSources(configMap *v1.ConfigMap, fileSources []strin return nil } -// handleConfigMapFromEnvFileSource adds the specified env file source information +// HandleConfigMapFromEnvFileSource adds the specified env file source information // into the provided configMap func HandleConfigMapFromEnvFileSource(configMap *v1.ConfigMap, envFileSource string) error { info, err := os.Stat(envFileSource) diff --git a/pkg/configmapandsecret/util/util.go b/pkg/configmapandsecret/util/util.go index dbff43c49..4970bd508 100644 --- a/pkg/configmapandsecret/util/util.go +++ b/pkg/configmapandsecret/util/util.go @@ -41,6 +41,7 @@ func ParseRFC3339(s string, nowFn func() metav1.Time) (metav1.Time, error) { return metav1.Time{Time: t}, nil } +// HashObject encodes object using given codec and returns MD5 sum of the result. func HashObject(obj runtime.Object, codec runtime.Codec) (string, error) { data, err := runtime.Encode(codec, obj) if err != nil { diff --git a/pkg/internal/error/configmaperror.go b/pkg/internal/error/configmaperror.go index 8d0ac7f6e..1d60d78a2 100644 --- a/pkg/internal/error/configmaperror.go +++ b/pkg/internal/error/configmaperror.go @@ -19,6 +19,7 @@ package error import "fmt" +// ConfigmapError represents error with a configmap. type ConfigmapError struct { Path string ErrorMsg string diff --git a/pkg/internal/error/kustomizationerror.go b/pkg/internal/error/kustomizationerror.go index d5726538a..0d53ca9b8 100644 --- a/pkg/internal/error/kustomizationerror.go +++ b/pkg/internal/error/kustomizationerror.go @@ -20,7 +20,7 @@ import ( "fmt" ) -// First pass to encapsulate fields for more informative error messages. +// KustomizationError represents an error with a kustomization. type KustomizationError struct { KustomizationPath string ErrorMsg string @@ -30,6 +30,7 @@ func (ke KustomizationError) Error() string { return fmt.Sprintf("Kustomization File [%s]: %s\n", ke.KustomizationPath, ke.ErrorMsg) } +// KustomizationErrors collects all errors. type KustomizationErrors struct { kErrors []error } @@ -42,14 +43,17 @@ func (ke *KustomizationErrors) Error() string { return errormsg } +// Append adds error to a collection of errors. func (ke *KustomizationErrors) Append(e error) { ke.kErrors = append(ke.kErrors, e) } +// Get returns all collected errors. func (ke *KustomizationErrors) Get() []error { return ke.kErrors } +// BatchAppend adds all errors from another KustomizationErrors func (ke *KustomizationErrors) BatchAppend(e KustomizationErrors) { for _, err := range e.Get() { ke.kErrors = append(ke.kErrors, err) diff --git a/pkg/internal/error/patcherror.go b/pkg/internal/error/patcherror.go index fdf1c16db..60c9f80e5 100644 --- a/pkg/internal/error/patcherror.go +++ b/pkg/internal/error/patcherror.go @@ -20,6 +20,7 @@ import ( "fmt" ) +// PatchError represents error during Patch. type PatchError struct { KustomizationPath string PatchFilepath string diff --git a/pkg/internal/error/resourceerror.go b/pkg/internal/error/resourceerror.go index 44fdfcb71..ef3566dd1 100644 --- a/pkg/internal/error/resourceerror.go +++ b/pkg/internal/error/resourceerror.go @@ -18,7 +18,7 @@ package error import "fmt" -// First pass to encapsulate fields for more informative error messages. +// ResourceError represents error in a resource. type ResourceError struct { KustomizationPath string ResourceFilepath string diff --git a/pkg/internal/error/secreterror.go b/pkg/internal/error/secreterror.go index 7d437cbdc..cd72759ce 100644 --- a/pkg/internal/error/secreterror.go +++ b/pkg/internal/error/secreterror.go @@ -18,9 +18,11 @@ package error import "fmt" +// SecretError represents error with a secret. type SecretError struct { KustomizationPath string - ErrorMsg string + // ErrorMsg is an error message + ErrorMsg string } func (e SecretError) Error() string { diff --git a/pkg/internal/loadertest/fakeloader.go b/pkg/internal/loadertest/fakeloader.go index 7cc48f2c0..811c0a015 100644 --- a/pkg/internal/loadertest/fakeloader.go +++ b/pkg/internal/loadertest/fakeloader.go @@ -43,24 +43,27 @@ func NewFakeLoader(initialDir string) FakeLoader { return FakeLoader{fs: fakefs, delegate: loader} } -// Adds a fake file to the file system. +// AddFile adds a fake file to the file system. func (f FakeLoader) AddFile(fullFilePath string, content []byte) error { return f.fs.WriteFile(fullFilePath, content) } -// Adds a fake directory to the file system. +// AddDirectory adds a fake directory to the file system. func (f FakeLoader) AddDirectory(fullDirPath string, mode os.FileMode) error { return f.fs.Mkdir(fullDirPath, mode) } +// Root returns root. func (f FakeLoader) Root() string { return f.delegate.Root() } +// New creates a new loader from a new root. func (f FakeLoader) New(newRoot string) (loader.Loader, error) { return f.delegate.New(newRoot) } +// Load performs load from a given location. func (f FakeLoader) Load(location string) ([]byte, error) { return f.delegate.Load(location) } diff --git a/pkg/loader/loader.go b/pkg/loader/loader.go index 6fc5fa95e..f4b87f5cc 100644 --- a/pkg/loader/loader.go +++ b/pkg/loader/loader.go @@ -36,7 +36,7 @@ type loaderImpl struct { schemes []SchemeLoader } -// Interface for different types of loaders (e.g. fileLoader, httpLoader, etc.) +// SchemeLoader is the interface for different types of loaders (e.g. fileLoader, httpLoader, etc.) type SchemeLoader interface { // Does this location correspond to this scheme. IsScheme(root string, location string) bool diff --git a/pkg/resmap/resmap.go b/pkg/resmap/resmap.go index b39efe40e..8b82a7187 100644 --- a/pkg/resmap/resmap.go +++ b/pkg/resmap/resmap.go @@ -68,11 +68,12 @@ func (m ResMap) EncodeAsYaml() ([]byte, error) { return buf.Bytes(), nil } -func (m1 ResMap) ErrorIfNotEqual(m2 ResMap) error { - if len(m1) != len(m2) { +// ErrorIfNotEqual returns error if maps are not equal. +func (m ResMap) ErrorIfNotEqual(m2 ResMap) error { + if len(m) != len(m2) { keySet1 := []resource.ResId{} keySet2 := []resource.ResId{} - for id := range m1 { + for id := range m { keySet1 = append(keySet1, id) } for id := range m2 { @@ -80,7 +81,7 @@ func (m1 ResMap) ErrorIfNotEqual(m2 ResMap) error { } return fmt.Errorf("maps has different number of entries: %#v doesn't equals %#v", keySet1, keySet2) } - for id, obj1 := range m1 { + for id, obj1 := range m { obj2, found := m2[id] if !found { return fmt.Errorf("%#v doesn't exist in %#v", id, m2) diff --git a/pkg/resource/generationbehavior.go b/pkg/resource/generationbehavior.go index dea2254f2..943537a51 100644 --- a/pkg/resource/generationbehavior.go +++ b/pkg/resource/generationbehavior.go @@ -20,13 +20,13 @@ package resource type GenerationBehavior int const ( - // Unspecified behavior typically treated as a Create. + // BehaviorUnspecified is an Unspecified behavior; typically treated as a Create. BehaviorUnspecified GenerationBehavior = iota - // Make a new resource. + // BehaviorCreate makes a new resource. BehaviorCreate - // Replace a resource. + // BehaviorReplace replaces a resource. BehaviorReplace - // Attempt to merge a new resource with an existing resource. + // BehaviorMerge attempts to merge a new resource with an existing resource. BehaviorMerge ) diff --git a/pkg/resource/resid.go b/pkg/resource/resid.go index f7935e278..38292056f 100644 --- a/pkg/resource/resid.go +++ b/pkg/resource/resid.go @@ -30,6 +30,7 @@ type ResId struct { name string } +// NewResId creates new resource identifier func NewResId(g schema.GroupVersionKind, n string) ResId { return ResId{gvk: g, name: n} } @@ -41,10 +42,12 @@ func (n ResId) String() string { return strings.Join([]string{n.gvk.Group, n.gvk.Version, n.gvk.Kind, n.name}, "_") + ".yaml" } +// Gvk returns Group/Version/Kind of the resource. func (n ResId) Gvk() schema.GroupVersionKind { return n.gvk } +// Name returns resource name. func (n ResId) Name() string { return n.name } diff --git a/pkg/resource/resource.go b/pkg/resource/resource.go index e10b1432f..e30af5832 100644 --- a/pkg/resource/resource.go +++ b/pkg/resource/resource.go @@ -68,11 +68,13 @@ func (r *Resource) Id() ResId { return NewResId(r.GroupVersionKind(), r.GetName()) } +// Merge performs merge with other resource. func (r *Resource) Merge(other *Resource) { r.Replace(other) mergeConfigmap(r.Object, other.Object, r.Object) } +// Replace performs replace with other resource. func (r *Resource) Replace(other *Resource) { r.SetLabels(mergeStringMaps(other.GetLabels(), r.GetLabels())) r.SetAnnotations(mergeStringMaps(other.GetAnnotations(), r.GetAnnotations())) @@ -103,6 +105,7 @@ func mergeStringMaps(maps ...map[string]string) map[string]string { return result } +// GetFieldValue returns value at the given fieldpath. func (r *Resource) GetFieldValue(fieldPath string) (string, error) { return getFieldValue(r.UnstructuredContent(), strings.Split(fieldPath, ".")) } diff --git a/pkg/types/kustomization.go b/pkg/types/kustomization.go index 184d8e045..146c302ef 100644 --- a/pkg/types/kustomization.go +++ b/pkg/types/kustomization.go @@ -67,7 +67,7 @@ type Kustomization struct { Vars []Var `json:"vars,omitempty" yaml:"vars,omitempty"` } -// ConfigMapArg contains the metadata of how to generate a configmap. +// ConfigMapArgs contains the metadata of how to generate a configmap. type ConfigMapArgs struct { // Name of the configmap. // The full name should be Kustomization.NamePrefix + Configmap.Name + @@ -84,7 +84,7 @@ type ConfigMapArgs struct { DataSources `json:",inline,omitempty" yaml:",inline,omitempty"` } -// SecretGenerator contains the metadata of how to generate a secret. +// SecretArgs contains the metadata of how to generate a secret. type SecretArgs struct { // Name of the secret. // The full name should be Kustomization.NamePrefix + SecretGenerator.Name + diff --git a/pkg/types/var.go b/pkg/types/var.go index 294d4d318..d3b2e73e5 100644 --- a/pkg/types/var.go +++ b/pkg/types/var.go @@ -40,6 +40,7 @@ type Var struct { FieldRef corev1.ObjectFieldSelector `json:"fieldref,omitempty" yaml:"objref,omitempty"` } +// Defaulting sets reference to field used by default. func (v *Var) Defaulting() { if (corev1.ObjectFieldSelector{}) == v.FieldRef { v.FieldRef = corev1.ObjectFieldSelector{FieldPath: "metadata.name"} diff --git a/version/version.go b/version/version.go index 36aa6b52b..7376ef451 100644 --- a/version/version.go +++ b/version/version.go @@ -32,14 +32,21 @@ var ( buildDate = "1970-01-01T00:00:00Z" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ') ) +// Version represens kustomize version. type Version struct { + // KustomizeVersion is a kustomize binary version. KustomizeVersion string `json:"kustomizeVersion"` - GitCommit string `json:"gitCommit"` - BuildDate string `json:"buildDate"` - GoOs string `json:"goOs"` - GoArch string `json:"goArch"` + // GitCommit is a git commit + GitCommit string `json:"gitCommit"` + // BuildDate is a build date of the binary. + BuildDate string `json:"buildDate"` + // GoOs holds OS name. + GoOs string `json:"goOs"` + // GoArch holds architecture name. + GoArch string `json:"goArch"` } +// GetVersion returns version. func GetVersion() Version { return Version{ kustomizeVersion, @@ -50,6 +57,7 @@ func GetVersion() Version { } } +// Print prints version. func (v Version) Print(w io.Writer) { fmt.Fprintf(w, "Version: %+v\n", v) }