From d9a6468d095cf75bea83b8d3c3cbe87447c245f4 Mon Sep 17 00:00:00 2001 From: Yann Hamon Date: Sat, 6 Jun 2020 18:42:44 +0200 Subject: [PATCH] add a few comments on exported vars --- pkg/output/json.go | 2 ++ pkg/registry/local.go | 2 ++ pkg/resource/signature.go | 5 +++-- pkg/validator/validator.go | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/output/json.go b/pkg/output/json.go index 3e3f7cf..d5abe86 100644 --- a/pkg/output/json.go +++ b/pkg/output/json.go @@ -36,6 +36,7 @@ func JSON(w io.Writer, withSummary bool, verbose bool) Output { } } +// JSON.Write will only write when JSON.Flush has been called func (o *jsono) Write(filename, kind, version string, err error, skipped bool) error { msg, st := "", "" @@ -65,6 +66,7 @@ func (o *jsono) Write(filename, kind, version string, err error, skipped bool) e return nil } +// Flush outputs the results as JSON func (o *jsono) Flush() error { var err error var res []byte diff --git a/pkg/registry/local.go b/pkg/registry/local.go index 4de8040..60fc733 100644 --- a/pkg/registry/local.go +++ b/pkg/registry/local.go @@ -12,6 +12,7 @@ type LocalSchemas struct { schemas map[string]string } +// NewLocalSchemas creates a new "registry", that will serve schemas from files, given a list of schema filenames func NewLocalSchemas(schemaFiles []string) (*LocalSchemas, error) { schemas := &LocalSchemas{ schemas: map[string]string{}, @@ -46,6 +47,7 @@ func NewLocalSchemas(schemaFiles []string) (*LocalSchemas, error) { return schemas, nil } +// DownloadSchema retrieves the schema from a file for the resource func (r LocalSchemas) DownloadSchema(resourceKind, resourceAPIVersion, k8sVersion string) ([]byte, error) { schemaFile, ok := r.schemas[resourceKind] if !ok { diff --git a/pkg/resource/signature.go b/pkg/resource/signature.go index acfacf9..d85b7d8 100644 --- a/pkg/resource/signature.go +++ b/pkg/resource/signature.go @@ -8,7 +8,8 @@ type Signature struct { Kind, Version, Namespace string } -func SignatureFromBytes(s []byte) (Signature, error) { +// SignatureFromBytes returns key identifying elements from a []byte representing the resource +func SignatureFromBytes(res []byte) (Signature, error) { resource := struct { APIVersion string `yaml:"apiVersion"` Kind string `yaml:"kind"` @@ -16,7 +17,7 @@ func SignatureFromBytes(s []byte) (Signature, error) { Namespace string `yaml:"Namespace"` } `yaml:"Metadata"` }{} - err := yaml.Unmarshal(s, &resource) + err := yaml.Unmarshal(res, &resource) return Signature{Kind: resource.Kind, Version: resource.APIVersion, Namespace: resource.Metadata.Namespace}, err } diff --git a/pkg/validator/validator.go b/pkg/validator/validator.go index bc6fc8d..d8b2551 100644 --- a/pkg/validator/validator.go +++ b/pkg/validator/validator.go @@ -32,7 +32,7 @@ func (f ValidFormat) IsFormat(input interface{}) bool { // gojsonschema.FormatCheckers.Add("int-or-string", ValidFormat{}) // } -// Validates a single Kubernetes resource against a Json Schema +// Validate validates a single Kubernetes resource against a Json Schema func Validate(rawResource []byte, schema *gojsonschema.Schema) error { if schema == nil { return nil