diff --git a/cmd/kube-linter/kube-linter.go b/cmd/kube-linter/kube-linter.go index bcf660b8b..26f86d56d 100644 --- a/cmd/kube-linter/kube-linter.go +++ b/cmd/kube-linter/kube-linter.go @@ -4,9 +4,9 @@ import ( "fmt" "os" - "golang.stackrox.io/kube-linter/internal/command/root" + "golang.stackrox.io/kube-linter/pkg/command/root" // Register templates - _ "golang.stackrox.io/kube-linter/internal/templates/all" + _ "golang.stackrox.io/kube-linter/pkg/templates/all" ) func main() { diff --git a/internal/defaultchecks/default_test.go b/internal/defaultchecks/default_test.go index cf388eb54..4f9343b99 100644 --- a/internal/defaultchecks/default_test.go +++ b/internal/defaultchecks/default_test.go @@ -5,8 +5,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.stackrox.io/kube-linter/internal/builtinchecks" "golang.stackrox.io/kube-linter/internal/set" + "golang.stackrox.io/kube-linter/pkg/builtinchecks" ) func TestListReferencesOnlyValidChecks(t *testing.T) { diff --git a/internal/templates/all/all.go b/internal/templates/all/all.go deleted file mode 100644 index d5213358b..000000000 --- a/internal/templates/all/all.go +++ /dev/null @@ -1,25 +0,0 @@ -package all - -import ( - // Import all check templates. - _ "golang.stackrox.io/kube-linter/internal/templates/antiaffinity" - _ "golang.stackrox.io/kube-linter/internal/templates/containercapabilities" - _ "golang.stackrox.io/kube-linter/internal/templates/cpurequirements" - _ "golang.stackrox.io/kube-linter/internal/templates/danglingservice" - _ "golang.stackrox.io/kube-linter/internal/templates/deprecatedserviceaccount" - _ "golang.stackrox.io/kube-linter/internal/templates/disallowedgvk" - _ "golang.stackrox.io/kube-linter/internal/templates/envvar" - _ "golang.stackrox.io/kube-linter/internal/templates/livenessprobe" - _ "golang.stackrox.io/kube-linter/internal/templates/memoryrequirements" - _ "golang.stackrox.io/kube-linter/internal/templates/mismatchingselector" - _ "golang.stackrox.io/kube-linter/internal/templates/nonexistentserviceaccount" - _ "golang.stackrox.io/kube-linter/internal/templates/ports" - _ "golang.stackrox.io/kube-linter/internal/templates/privileged" - _ "golang.stackrox.io/kube-linter/internal/templates/readinessprobe" - _ "golang.stackrox.io/kube-linter/internal/templates/readonlyrootfs" - _ "golang.stackrox.io/kube-linter/internal/templates/requiredannotation" - _ "golang.stackrox.io/kube-linter/internal/templates/requiredlabel" - _ "golang.stackrox.io/kube-linter/internal/templates/runasnonroot" - _ "golang.stackrox.io/kube-linter/internal/templates/serviceaccount" - _ "golang.stackrox.io/kube-linter/internal/templates/writablehostmount" -) diff --git a/internal/templates/nonexistentserviceaccount/internal/params/gen-params.go b/internal/templates/nonexistentserviceaccount/internal/params/gen-params.go deleted file mode 100644 index 09ac1a6c7..000000000 --- a/internal/templates/nonexistentserviceaccount/internal/params/gen-params.go +++ /dev/null @@ -1,52 +0,0 @@ -// Code generated by kube-linter template codegen. DO NOT EDIT. -// +build !templatecodegen - -package params - -import ( - "fmt" - "strings" - - "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" -) - -var ( - // Use some imports in case they don't get used otherwise. - _ = util.MustParseParameterDesc - _ = fmt.Sprintf - - ParamDescs = []check.ParameterDesc{ - } -) - -func (p *Params) Validate() error { - var validationErrors []string - if len(validationErrors) > 0 { - return errors.Errorf("invalid parameters: %s", strings.Join(validationErrors, ", ")) - } - return nil -} - -// ParseAndValidate instantiates a Params object out of the passed map[string]interface{}, -// validates it, and returns it. -// The return type is interface{} to satisfy the type in the Template struct. -func ParseAndValidate(m map[string]interface{}) (interface{}, error) { - var p Params - if err := util.DecodeMapStructure(m, &p); err != nil { - return nil, err - } - if err := p.Validate(); err != nil { - return nil, err - } - return p, nil -} - -// WrapInstantiateFunc is a convenience wrapper that wraps an untyped instantiate function -// into a typed one. -func WrapInstantiateFunc(f func(p Params) (check.Func, error)) func (interface{}) (check.Func, error) { - return func(paramsInt interface{}) (check.Func, error) { - return f(paramsInt.(Params)) - } -} diff --git a/internal/templates/privileged/internal/params/gen-params.go b/internal/templates/privileged/internal/params/gen-params.go deleted file mode 100644 index 09ac1a6c7..000000000 --- a/internal/templates/privileged/internal/params/gen-params.go +++ /dev/null @@ -1,52 +0,0 @@ -// Code generated by kube-linter template codegen. DO NOT EDIT. -// +build !templatecodegen - -package params - -import ( - "fmt" - "strings" - - "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" -) - -var ( - // Use some imports in case they don't get used otherwise. - _ = util.MustParseParameterDesc - _ = fmt.Sprintf - - ParamDescs = []check.ParameterDesc{ - } -) - -func (p *Params) Validate() error { - var validationErrors []string - if len(validationErrors) > 0 { - return errors.Errorf("invalid parameters: %s", strings.Join(validationErrors, ", ")) - } - return nil -} - -// ParseAndValidate instantiates a Params object out of the passed map[string]interface{}, -// validates it, and returns it. -// The return type is interface{} to satisfy the type in the Template struct. -func ParseAndValidate(m map[string]interface{}) (interface{}, error) { - var p Params - if err := util.DecodeMapStructure(m, &p); err != nil { - return nil, err - } - if err := p.Validate(); err != nil { - return nil, err - } - return p, nil -} - -// WrapInstantiateFunc is a convenience wrapper that wraps an untyped instantiate function -// into a typed one. -func WrapInstantiateFunc(f func(p Params) (check.Func, error)) func (interface{}) (check.Func, error) { - return func(paramsInt interface{}) (check.Func, error) { - return f(paramsInt.(Params)) - } -} diff --git a/internal/templates/readinessprobe/internal/params/gen-params.go b/internal/templates/readinessprobe/internal/params/gen-params.go deleted file mode 100644 index 09ac1a6c7..000000000 --- a/internal/templates/readinessprobe/internal/params/gen-params.go +++ /dev/null @@ -1,52 +0,0 @@ -// Code generated by kube-linter template codegen. DO NOT EDIT. -// +build !templatecodegen - -package params - -import ( - "fmt" - "strings" - - "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" -) - -var ( - // Use some imports in case they don't get used otherwise. - _ = util.MustParseParameterDesc - _ = fmt.Sprintf - - ParamDescs = []check.ParameterDesc{ - } -) - -func (p *Params) Validate() error { - var validationErrors []string - if len(validationErrors) > 0 { - return errors.Errorf("invalid parameters: %s", strings.Join(validationErrors, ", ")) - } - return nil -} - -// ParseAndValidate instantiates a Params object out of the passed map[string]interface{}, -// validates it, and returns it. -// The return type is interface{} to satisfy the type in the Template struct. -func ParseAndValidate(m map[string]interface{}) (interface{}, error) { - var p Params - if err := util.DecodeMapStructure(m, &p); err != nil { - return nil, err - } - if err := p.Validate(); err != nil { - return nil, err - } - return p, nil -} - -// WrapInstantiateFunc is a convenience wrapper that wraps an untyped instantiate function -// into a typed one. -func WrapInstantiateFunc(f func(p Params) (check.Func, error)) func (interface{}) (check.Func, error) { - return func(paramsInt interface{}) (check.Func, error) { - return f(paramsInt.(Params)) - } -} diff --git a/internal/templates/readonlyrootfs/internal/params/gen-params.go b/internal/templates/readonlyrootfs/internal/params/gen-params.go deleted file mode 100644 index 09ac1a6c7..000000000 --- a/internal/templates/readonlyrootfs/internal/params/gen-params.go +++ /dev/null @@ -1,52 +0,0 @@ -// Code generated by kube-linter template codegen. DO NOT EDIT. -// +build !templatecodegen - -package params - -import ( - "fmt" - "strings" - - "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" -) - -var ( - // Use some imports in case they don't get used otherwise. - _ = util.MustParseParameterDesc - _ = fmt.Sprintf - - ParamDescs = []check.ParameterDesc{ - } -) - -func (p *Params) Validate() error { - var validationErrors []string - if len(validationErrors) > 0 { - return errors.Errorf("invalid parameters: %s", strings.Join(validationErrors, ", ")) - } - return nil -} - -// ParseAndValidate instantiates a Params object out of the passed map[string]interface{}, -// validates it, and returns it. -// The return type is interface{} to satisfy the type in the Template struct. -func ParseAndValidate(m map[string]interface{}) (interface{}, error) { - var p Params - if err := util.DecodeMapStructure(m, &p); err != nil { - return nil, err - } - if err := p.Validate(); err != nil { - return nil, err - } - return p, nil -} - -// WrapInstantiateFunc is a convenience wrapper that wraps an untyped instantiate function -// into a typed one. -func WrapInstantiateFunc(f func(p Params) (check.Func, error)) func (interface{}) (check.Func, error) { - return func(paramsInt interface{}) (check.Func, error) { - return f(paramsInt.(Params)) - } -} diff --git a/internal/templates/runasnonroot/internal/params/gen-params.go b/internal/templates/runasnonroot/internal/params/gen-params.go deleted file mode 100644 index 09ac1a6c7..000000000 --- a/internal/templates/runasnonroot/internal/params/gen-params.go +++ /dev/null @@ -1,52 +0,0 @@ -// Code generated by kube-linter template codegen. DO NOT EDIT. -// +build !templatecodegen - -package params - -import ( - "fmt" - "strings" - - "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" -) - -var ( - // Use some imports in case they don't get used otherwise. - _ = util.MustParseParameterDesc - _ = fmt.Sprintf - - ParamDescs = []check.ParameterDesc{ - } -) - -func (p *Params) Validate() error { - var validationErrors []string - if len(validationErrors) > 0 { - return errors.Errorf("invalid parameters: %s", strings.Join(validationErrors, ", ")) - } - return nil -} - -// ParseAndValidate instantiates a Params object out of the passed map[string]interface{}, -// validates it, and returns it. -// The return type is interface{} to satisfy the type in the Template struct. -func ParseAndValidate(m map[string]interface{}) (interface{}, error) { - var p Params - if err := util.DecodeMapStructure(m, &p); err != nil { - return nil, err - } - if err := p.Validate(); err != nil { - return nil, err - } - return p, nil -} - -// WrapInstantiateFunc is a convenience wrapper that wraps an untyped instantiate function -// into a typed one. -func WrapInstantiateFunc(f func(p Params) (check.Func, error)) func (interface{}) (check.Func, error) { - return func(paramsInt interface{}) (check.Func, error) { - return f(paramsInt.(Params)) - } -} diff --git a/internal/templates/writablehostmount/internal/params/gen-params.go b/internal/templates/writablehostmount/internal/params/gen-params.go deleted file mode 100644 index 09ac1a6c7..000000000 --- a/internal/templates/writablehostmount/internal/params/gen-params.go +++ /dev/null @@ -1,52 +0,0 @@ -// Code generated by kube-linter template codegen. DO NOT EDIT. -// +build !templatecodegen - -package params - -import ( - "fmt" - "strings" - - "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" -) - -var ( - // Use some imports in case they don't get used otherwise. - _ = util.MustParseParameterDesc - _ = fmt.Sprintf - - ParamDescs = []check.ParameterDesc{ - } -) - -func (p *Params) Validate() error { - var validationErrors []string - if len(validationErrors) > 0 { - return errors.Errorf("invalid parameters: %s", strings.Join(validationErrors, ", ")) - } - return nil -} - -// ParseAndValidate instantiates a Params object out of the passed map[string]interface{}, -// validates it, and returns it. -// The return type is interface{} to satisfy the type in the Template struct. -func ParseAndValidate(m map[string]interface{}) (interface{}, error) { - var p Params - if err := util.DecodeMapStructure(m, &p); err != nil { - return nil, err - } - if err := p.Validate(); err != nil { - return nil, err - } - return p, nil -} - -// WrapInstantiateFunc is a convenience wrapper that wraps an untyped instantiate function -// into a typed one. -func WrapInstantiateFunc(f func(p Params) (check.Func, error)) func (interface{}) (check.Func, error) { - return func(paramsInt interface{}) (check.Func, error) { - return f(paramsInt.(Params)) - } -} diff --git a/internal/builtinchecks/built_in_checks.go b/pkg/builtinchecks/built_in_checks.go similarity index 91% rename from internal/builtinchecks/built_in_checks.go rename to pkg/builtinchecks/built_in_checks.go index dc0749957..e97cf5724 100644 --- a/internal/builtinchecks/built_in_checks.go +++ b/pkg/builtinchecks/built_in_checks.go @@ -6,8 +6,8 @@ import ( "github.com/ghodss/yaml" "github.com/gobuffalo/packr" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/checkregistry" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/checkregistry" ) var ( diff --git a/internal/builtinchecks/built_in_checks_test.go b/pkg/builtinchecks/built_in_checks_test.go similarity index 100% rename from internal/builtinchecks/built_in_checks_test.go rename to pkg/builtinchecks/built_in_checks_test.go diff --git a/internal/builtinchecks/yamls/dangling-service.yaml b/pkg/builtinchecks/yamls/dangling-service.yaml similarity index 100% rename from internal/builtinchecks/yamls/dangling-service.yaml rename to pkg/builtinchecks/yamls/dangling-service.yaml diff --git a/internal/builtinchecks/yamls/default-service-account.yaml b/pkg/builtinchecks/yamls/default-service-account.yaml similarity index 100% rename from internal/builtinchecks/yamls/default-service-account.yaml rename to pkg/builtinchecks/yamls/default-service-account.yaml diff --git a/internal/builtinchecks/yamls/deprecated-service-account.yaml b/pkg/builtinchecks/yamls/deprecated-service-account.yaml similarity index 100% rename from internal/builtinchecks/yamls/deprecated-service-account.yaml rename to pkg/builtinchecks/yamls/deprecated-service-account.yaml diff --git a/internal/builtinchecks/yamls/drop-net-raw-capability.yaml b/pkg/builtinchecks/yamls/drop-net-raw-capability.yaml similarity index 100% rename from internal/builtinchecks/yamls/drop-net-raw-capability.yaml rename to pkg/builtinchecks/yamls/drop-net-raw-capability.yaml diff --git a/internal/builtinchecks/yamls/env-var-secret.yaml b/pkg/builtinchecks/yamls/env-var-secret.yaml similarity index 100% rename from internal/builtinchecks/yamls/env-var-secret.yaml rename to pkg/builtinchecks/yamls/env-var-secret.yaml diff --git a/internal/builtinchecks/yamls/mismatching-selector.yaml b/pkg/builtinchecks/yamls/mismatching-selector.yaml similarity index 100% rename from internal/builtinchecks/yamls/mismatching-selector.yaml rename to pkg/builtinchecks/yamls/mismatching-selector.yaml diff --git a/internal/builtinchecks/yamls/no-anti-affinity.yaml b/pkg/builtinchecks/yamls/no-anti-affinity.yaml similarity index 100% rename from internal/builtinchecks/yamls/no-anti-affinity.yaml rename to pkg/builtinchecks/yamls/no-anti-affinity.yaml diff --git a/internal/builtinchecks/yamls/no-extensions-v1beta.yaml b/pkg/builtinchecks/yamls/no-extensions-v1beta.yaml similarity index 100% rename from internal/builtinchecks/yamls/no-extensions-v1beta.yaml rename to pkg/builtinchecks/yamls/no-extensions-v1beta.yaml diff --git a/internal/builtinchecks/yamls/no-liveness-probe.yaml b/pkg/builtinchecks/yamls/no-liveness-probe.yaml similarity index 100% rename from internal/builtinchecks/yamls/no-liveness-probe.yaml rename to pkg/builtinchecks/yamls/no-liveness-probe.yaml diff --git a/internal/builtinchecks/yamls/no-readiness-probe.yaml b/pkg/builtinchecks/yamls/no-readiness-probe.yaml similarity index 100% rename from internal/builtinchecks/yamls/no-readiness-probe.yaml rename to pkg/builtinchecks/yamls/no-readiness-probe.yaml diff --git a/internal/builtinchecks/yamls/non-existent-service-account.yaml b/pkg/builtinchecks/yamls/non-existent-service-account.yaml similarity index 100% rename from internal/builtinchecks/yamls/non-existent-service-account.yaml rename to pkg/builtinchecks/yamls/non-existent-service-account.yaml diff --git a/internal/builtinchecks/yamls/privileged.yaml b/pkg/builtinchecks/yamls/privileged.yaml similarity index 100% rename from internal/builtinchecks/yamls/privileged.yaml rename to pkg/builtinchecks/yamls/privileged.yaml diff --git a/internal/builtinchecks/yamls/read-only-root-fs.yaml b/pkg/builtinchecks/yamls/read-only-root-fs.yaml similarity index 100% rename from internal/builtinchecks/yamls/read-only-root-fs.yaml rename to pkg/builtinchecks/yamls/read-only-root-fs.yaml diff --git a/internal/builtinchecks/yamls/required-annotation-email.yaml b/pkg/builtinchecks/yamls/required-annotation-email.yaml similarity index 100% rename from internal/builtinchecks/yamls/required-annotation-email.yaml rename to pkg/builtinchecks/yamls/required-annotation-email.yaml diff --git a/internal/builtinchecks/yamls/required-label-owner.yaml b/pkg/builtinchecks/yamls/required-label-owner.yaml similarity index 100% rename from internal/builtinchecks/yamls/required-label-owner.yaml rename to pkg/builtinchecks/yamls/required-label-owner.yaml diff --git a/internal/builtinchecks/yamls/run-as-non-root.yaml b/pkg/builtinchecks/yamls/run-as-non-root.yaml similarity index 100% rename from internal/builtinchecks/yamls/run-as-non-root.yaml rename to pkg/builtinchecks/yamls/run-as-non-root.yaml diff --git a/internal/builtinchecks/yamls/ssh-port.yaml b/pkg/builtinchecks/yamls/ssh-port.yaml similarity index 100% rename from internal/builtinchecks/yamls/ssh-port.yaml rename to pkg/builtinchecks/yamls/ssh-port.yaml diff --git a/internal/builtinchecks/yamls/unset-cpu-requirements.yaml b/pkg/builtinchecks/yamls/unset-cpu-requirements.yaml similarity index 100% rename from internal/builtinchecks/yamls/unset-cpu-requirements.yaml rename to pkg/builtinchecks/yamls/unset-cpu-requirements.yaml diff --git a/internal/builtinchecks/yamls/unset-memory-requirements.yaml b/pkg/builtinchecks/yamls/unset-memory-requirements.yaml similarity index 100% rename from internal/builtinchecks/yamls/unset-memory-requirements.yaml rename to pkg/builtinchecks/yamls/unset-memory-requirements.yaml diff --git a/internal/builtinchecks/yamls/writable-host-mount.yaml b/pkg/builtinchecks/yamls/writable-host-mount.yaml similarity index 100% rename from internal/builtinchecks/yamls/writable-host-mount.yaml rename to pkg/builtinchecks/yamls/writable-host-mount.yaml diff --git a/internal/check/check.go b/pkg/check/check.go similarity index 100% rename from internal/check/check.go rename to pkg/check/check.go diff --git a/internal/check/parameter_desc.go b/pkg/check/parameter_desc.go similarity index 100% rename from internal/check/parameter_desc.go rename to pkg/check/parameter_desc.go diff --git a/internal/check/template.go b/pkg/check/template.go similarity index 90% rename from internal/check/template.go rename to pkg/check/template.go index f0e5b35c0..5afbd4bb4 100644 --- a/internal/check/template.go +++ b/pkg/check/template.go @@ -1,8 +1,8 @@ package check import ( - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/lintcontext" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/lintcontext" ) // A Func is a specific lint-check, which runs on a specific objects, and emits diagnostics if problems are found. diff --git a/internal/checkregistry/check_registry.go b/pkg/checkregistry/check_registry.go similarity index 90% rename from internal/checkregistry/check_registry.go rename to pkg/checkregistry/check_registry.go index 0cec1aca5..c6ed083ee 100644 --- a/internal/checkregistry/check_registry.go +++ b/pkg/checkregistry/check_registry.go @@ -2,8 +2,8 @@ package checkregistry import ( "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/instantiatedcheck" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/instantiatedcheck" ) // A CheckRegistry is a registry of checks. diff --git a/internal/command/checks/command.go b/pkg/command/checks/command.go similarity index 94% rename from internal/command/checks/command.go rename to pkg/command/checks/command.go index 2da5613c5..597cea622 100644 --- a/internal/command/checks/command.go +++ b/pkg/command/checks/command.go @@ -8,11 +8,11 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" - "golang.stackrox.io/kube-linter/internal/builtinchecks" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/command/common" "golang.stackrox.io/kube-linter/internal/defaultchecks" "golang.stackrox.io/kube-linter/internal/stringutils" + "golang.stackrox.io/kube-linter/pkg/builtinchecks" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/command/common" ) var ( diff --git a/internal/command/checks/command_test.go b/pkg/command/checks/command_test.go similarity index 86% rename from internal/command/checks/command_test.go rename to pkg/command/checks/command_test.go index 00efce6e6..0e471bef0 100644 --- a/internal/command/checks/command_test.go +++ b/pkg/command/checks/command_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/assert" - "golang.stackrox.io/kube-linter/internal/command/common" "golang.stackrox.io/kube-linter/internal/set" + "golang.stackrox.io/kube-linter/pkg/command/common" ) func TestAllFormatsSupported(t *testing.T) { diff --git a/internal/command/common/format_wrapper.go b/pkg/command/common/format_wrapper.go similarity index 100% rename from internal/command/common/format_wrapper.go rename to pkg/command/common/format_wrapper.go diff --git a/internal/command/common/markdown.go b/pkg/command/common/markdown.go similarity index 100% rename from internal/command/common/markdown.go rename to pkg/command/common/markdown.go diff --git a/internal/command/common/markdown_test.go b/pkg/command/common/markdown_test.go similarity index 95% rename from internal/command/common/markdown_test.go rename to pkg/command/common/markdown_test.go index 1f8949ec2..c6b5487da 100644 --- a/internal/command/common/markdown_test.go +++ b/pkg/command/common/markdown_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" - "golang.stackrox.io/kube-linter/internal/command/common" + "golang.stackrox.io/kube-linter/pkg/command/common" ) func TestMarkdownFunctions(t *testing.T) { diff --git a/internal/command/lint/command.go b/pkg/command/lint/command.go similarity index 88% rename from internal/command/lint/command.go rename to pkg/command/lint/command.go index f64dcdf60..c26bf1f95 100644 --- a/internal/command/lint/command.go +++ b/pkg/command/lint/command.go @@ -5,12 +5,12 @@ import ( "os" "golang.org/x/crypto/ssh/terminal" - "golang.stackrox.io/kube-linter/internal/builtinchecks" - "golang.stackrox.io/kube-linter/internal/checkregistry" - "golang.stackrox.io/kube-linter/internal/config" - "golang.stackrox.io/kube-linter/internal/configresolver" - "golang.stackrox.io/kube-linter/internal/lintcontext" - "golang.stackrox.io/kube-linter/internal/run" + "golang.stackrox.io/kube-linter/pkg/builtinchecks" + "golang.stackrox.io/kube-linter/pkg/checkregistry" + "golang.stackrox.io/kube-linter/pkg/config" + "golang.stackrox.io/kube-linter/pkg/configresolver" + "golang.stackrox.io/kube-linter/pkg/lintcontext" + "golang.stackrox.io/kube-linter/pkg/run" "github.com/pkg/errors" "github.com/spf13/cobra" diff --git a/internal/command/root/command.go b/pkg/command/root/command.go similarity index 58% rename from internal/command/root/command.go rename to pkg/command/root/command.go index e758d2380..58edaf68f 100644 --- a/internal/command/root/command.go +++ b/pkg/command/root/command.go @@ -4,10 +4,10 @@ import ( "os" "github.com/spf13/cobra" - "golang.stackrox.io/kube-linter/internal/command/checks" - "golang.stackrox.io/kube-linter/internal/command/lint" - "golang.stackrox.io/kube-linter/internal/command/templates" - "golang.stackrox.io/kube-linter/internal/command/version" + "golang.stackrox.io/kube-linter/pkg/command/checks" + "golang.stackrox.io/kube-linter/pkg/command/lint" + "golang.stackrox.io/kube-linter/pkg/command/templates" + "golang.stackrox.io/kube-linter/pkg/command/version" ) // Command is the root command. diff --git a/internal/command/templates/command.go b/pkg/command/templates/command.go similarity index 95% rename from internal/command/templates/command.go rename to pkg/command/templates/command.go index abcf5b4ca..31ffdc968 100644 --- a/internal/command/templates/command.go +++ b/pkg/command/templates/command.go @@ -11,10 +11,10 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/command/common" "golang.stackrox.io/kube-linter/internal/stringutils" - "golang.stackrox.io/kube-linter/internal/templates" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/command/common" + "golang.stackrox.io/kube-linter/pkg/templates" ) var ( diff --git a/internal/command/templates/command_test.go b/pkg/command/templates/command_test.go similarity index 86% rename from internal/command/templates/command_test.go rename to pkg/command/templates/command_test.go index c5447fe72..e1235206d 100644 --- a/internal/command/templates/command_test.go +++ b/pkg/command/templates/command_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/assert" - "golang.stackrox.io/kube-linter/internal/command/common" "golang.stackrox.io/kube-linter/internal/set" + "golang.stackrox.io/kube-linter/pkg/command/common" ) func TestAllFormatsSupported(t *testing.T) { diff --git a/internal/command/version/command.go b/pkg/command/version/command.go similarity index 100% rename from internal/command/version/command.go rename to pkg/command/version/command.go diff --git a/internal/config/config.go b/pkg/config/config.go similarity index 97% rename from internal/config/config.go rename to pkg/config/config.go index 671065514..2c6265db4 100644 --- a/internal/config/config.go +++ b/pkg/config/config.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/viper" - "golang.stackrox.io/kube-linter/internal/check" + "golang.stackrox.io/kube-linter/pkg/check" ) // ChecksConfig is the config that determines which checks to run. diff --git a/internal/config/flags.go b/pkg/config/flags.go similarity index 100% rename from internal/config/flags.go rename to pkg/config/flags.go diff --git a/internal/config/gen.go b/pkg/config/gen.go similarity index 100% rename from internal/config/gen.go rename to pkg/config/gen.go diff --git a/internal/config/main/parse.go b/pkg/config/main/parse.go similarity index 100% rename from internal/config/main/parse.go rename to pkg/config/main/parse.go diff --git a/internal/configresolver/config_resolver.go b/pkg/configresolver/config_resolver.go similarity index 91% rename from internal/configresolver/config_resolver.go rename to pkg/configresolver/config_resolver.go index 844c326bf..cadb4fab6 100644 --- a/internal/configresolver/config_resolver.go +++ b/pkg/configresolver/config_resolver.go @@ -1,12 +1,12 @@ package configresolver import ( - "golang.stackrox.io/kube-linter/internal/builtinchecks" - "golang.stackrox.io/kube-linter/internal/checkregistry" - "golang.stackrox.io/kube-linter/internal/config" "golang.stackrox.io/kube-linter/internal/defaultchecks" "golang.stackrox.io/kube-linter/internal/errorhelpers" "golang.stackrox.io/kube-linter/internal/set" + "golang.stackrox.io/kube-linter/pkg/builtinchecks" + "golang.stackrox.io/kube-linter/pkg/checkregistry" + "golang.stackrox.io/kube-linter/pkg/config" ) // LoadCustomChecksInto loads the custom checks from the config into the check registry. diff --git a/internal/diagnostic/diagnostic.go b/pkg/diagnostic/diagnostic.go similarity index 96% rename from internal/diagnostic/diagnostic.go rename to pkg/diagnostic/diagnostic.go index a28258fbc..db8d5f5a0 100644 --- a/internal/diagnostic/diagnostic.go +++ b/pkg/diagnostic/diagnostic.go @@ -8,8 +8,8 @@ import ( "github.com/acarl005/stripansi" "github.com/fatih/color" "golang.stackrox.io/kube-linter/internal/k8sutil" - "golang.stackrox.io/kube-linter/internal/lintcontext" "golang.stackrox.io/kube-linter/internal/stringutils" + "golang.stackrox.io/kube-linter/pkg/lintcontext" ) // A Diagnostic represents one specific problem diagnosed by a check. diff --git a/internal/extract/gvk.go b/pkg/extract/gvk.go similarity index 100% rename from internal/extract/gvk.go rename to pkg/extract/gvk.go diff --git a/internal/extract/metadata.go b/pkg/extract/metadata.go similarity index 100% rename from internal/extract/metadata.go rename to pkg/extract/metadata.go diff --git a/internal/extract/pod_spec.go b/pkg/extract/pod_spec.go similarity index 100% rename from internal/extract/pod_spec.go rename to pkg/extract/pod_spec.go diff --git a/internal/ignore/ignore.go b/pkg/ignore/ignore.go similarity index 100% rename from internal/ignore/ignore.go rename to pkg/ignore/ignore.go diff --git a/internal/ignore/ignore_test.go b/pkg/ignore/ignore_test.go similarity index 100% rename from internal/ignore/ignore_test.go rename to pkg/ignore/ignore_test.go diff --git a/internal/instantiatedcheck/instantiated_check.go b/pkg/instantiatedcheck/instantiated_check.go similarity index 91% rename from internal/instantiatedcheck/instantiated_check.go rename to pkg/instantiatedcheck/instantiated_check.go index 8cc49e1e8..3968a3c24 100644 --- a/internal/instantiatedcheck/instantiated_check.go +++ b/pkg/instantiatedcheck/instantiated_check.go @@ -4,10 +4,10 @@ import ( "regexp" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" "golang.stackrox.io/kube-linter/internal/errorhelpers" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" ) // An InstantiatedCheck is the runtime instantiation of a check, which fuses the metadata in a check diff --git a/internal/lintcontext/context.go b/pkg/lintcontext/context.go similarity index 100% rename from internal/lintcontext/context.go rename to pkg/lintcontext/context.go diff --git a/internal/lintcontext/create_contexts.go b/pkg/lintcontext/create_contexts.go similarity index 100% rename from internal/lintcontext/create_contexts.go rename to pkg/lintcontext/create_contexts.go diff --git a/internal/lintcontext/mocks/container.go b/pkg/lintcontext/mocks/container.go similarity index 100% rename from internal/lintcontext/mocks/container.go rename to pkg/lintcontext/mocks/container.go diff --git a/internal/lintcontext/mocks/context.go b/pkg/lintcontext/mocks/context.go similarity index 94% rename from internal/lintcontext/mocks/context.go rename to pkg/lintcontext/mocks/context.go index abf8b3526..583d13765 100644 --- a/internal/lintcontext/mocks/context.go +++ b/pkg/lintcontext/mocks/context.go @@ -2,7 +2,7 @@ package mocks import ( "golang.stackrox.io/kube-linter/internal/k8sutil" - "golang.stackrox.io/kube-linter/internal/lintcontext" + "golang.stackrox.io/kube-linter/pkg/lintcontext" ) // MockLintContext is mock implementation of the LintContext used in unit tests diff --git a/internal/lintcontext/mocks/pod.go b/pkg/lintcontext/mocks/pod.go similarity index 100% rename from internal/lintcontext/mocks/pod.go rename to pkg/lintcontext/mocks/pod.go diff --git a/internal/lintcontext/parse_yaml.go b/pkg/lintcontext/parse_yaml.go similarity index 100% rename from internal/lintcontext/parse_yaml.go rename to pkg/lintcontext/parse_yaml.go diff --git a/internal/matcher/string.go b/pkg/matcher/string.go similarity index 100% rename from internal/matcher/string.go rename to pkg/matcher/string.go diff --git a/internal/objectkinds/any.go b/pkg/objectkinds/any.go similarity index 100% rename from internal/objectkinds/any.go rename to pkg/objectkinds/any.go diff --git a/internal/objectkinds/deployment_like.go b/pkg/objectkinds/deployment_like.go similarity index 100% rename from internal/objectkinds/deployment_like.go rename to pkg/objectkinds/deployment_like.go diff --git a/internal/objectkinds/registry.go b/pkg/objectkinds/registry.go similarity index 100% rename from internal/objectkinds/registry.go rename to pkg/objectkinds/registry.go diff --git a/internal/objectkinds/service.go b/pkg/objectkinds/service.go similarity index 100% rename from internal/objectkinds/service.go rename to pkg/objectkinds/service.go diff --git a/internal/objectkinds/types.go b/pkg/objectkinds/types.go similarity index 100% rename from internal/objectkinds/types.go rename to pkg/objectkinds/types.go diff --git a/internal/run/run.go b/pkg/run/run.go similarity index 83% rename from internal/run/run.go rename to pkg/run/run.go index 827b8a2c7..f3bff7d4b 100644 --- a/internal/run/run.go +++ b/pkg/run/run.go @@ -2,11 +2,11 @@ package run import ( "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/checkregistry" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/ignore" - "golang.stackrox.io/kube-linter/internal/instantiatedcheck" - "golang.stackrox.io/kube-linter/internal/lintcontext" + "golang.stackrox.io/kube-linter/pkg/checkregistry" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/ignore" + "golang.stackrox.io/kube-linter/pkg/instantiatedcheck" + "golang.stackrox.io/kube-linter/pkg/lintcontext" ) // Result represents the result from a run of the linter. diff --git a/pkg/templates/all/all.go b/pkg/templates/all/all.go new file mode 100644 index 000000000..3efc8b0d7 --- /dev/null +++ b/pkg/templates/all/all.go @@ -0,0 +1,25 @@ +package all + +import ( + // Import all check templates. + _ "golang.stackrox.io/kube-linter/pkg/templates/antiaffinity" + _ "golang.stackrox.io/kube-linter/pkg/templates/containercapabilities" + _ "golang.stackrox.io/kube-linter/pkg/templates/cpurequirements" + _ "golang.stackrox.io/kube-linter/pkg/templates/danglingservice" + _ "golang.stackrox.io/kube-linter/pkg/templates/deprecatedserviceaccount" + _ "golang.stackrox.io/kube-linter/pkg/templates/disallowedgvk" + _ "golang.stackrox.io/kube-linter/pkg/templates/envvar" + _ "golang.stackrox.io/kube-linter/pkg/templates/livenessprobe" + _ "golang.stackrox.io/kube-linter/pkg/templates/memoryrequirements" + _ "golang.stackrox.io/kube-linter/pkg/templates/mismatchingselector" + _ "golang.stackrox.io/kube-linter/pkg/templates/nonexistentserviceaccount" + _ "golang.stackrox.io/kube-linter/pkg/templates/ports" + _ "golang.stackrox.io/kube-linter/pkg/templates/privileged" + _ "golang.stackrox.io/kube-linter/pkg/templates/readinessprobe" + _ "golang.stackrox.io/kube-linter/pkg/templates/readonlyrootfs" + _ "golang.stackrox.io/kube-linter/pkg/templates/requiredannotation" + _ "golang.stackrox.io/kube-linter/pkg/templates/requiredlabel" + _ "golang.stackrox.io/kube-linter/pkg/templates/runasnonroot" + _ "golang.stackrox.io/kube-linter/pkg/templates/serviceaccount" + _ "golang.stackrox.io/kube-linter/pkg/templates/writablehostmount" +) diff --git a/internal/templates/all/all_test.go b/pkg/templates/all/all_test.go similarity index 92% rename from internal/templates/all/all_test.go rename to pkg/templates/all/all_test.go index 2d1fdf7fd..cb106a743 100644 --- a/internal/templates/all/all_test.go +++ b/pkg/templates/all/all_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" - "golang.stackrox.io/kube-linter/internal/templates" + "golang.stackrox.io/kube-linter/pkg/templates" ) func TestTemplatesAreValid(t *testing.T) { diff --git a/internal/templates/antiaffinity/internal/params/gen-params.go b/pkg/templates/antiaffinity/internal/params/gen-params.go similarity index 95% rename from internal/templates/antiaffinity/internal/params/gen-params.go rename to pkg/templates/antiaffinity/internal/params/gen-params.go index 46b9dd5a4..75358d80e 100644 --- a/internal/templates/antiaffinity/internal/params/gen-params.go +++ b/pkg/templates/antiaffinity/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/antiaffinity/internal/params/params.go b/pkg/templates/antiaffinity/internal/params/params.go similarity index 100% rename from internal/templates/antiaffinity/internal/params/params.go rename to pkg/templates/antiaffinity/internal/params/params.go diff --git a/internal/templates/antiaffinity/template.go b/pkg/templates/antiaffinity/template.go similarity index 87% rename from internal/templates/antiaffinity/template.go rename to pkg/templates/antiaffinity/template.go index e565cbde1..688681db2 100644 --- a/internal/templates/antiaffinity/template.go +++ b/pkg/templates/antiaffinity/template.go @@ -3,15 +3,15 @@ package antiaffinity import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/extract" - "golang.stackrox.io/kube-linter/internal/lintcontext" - "golang.stackrox.io/kube-linter/internal/matcher" - "golang.stackrox.io/kube-linter/internal/objectkinds" "golang.stackrox.io/kube-linter/internal/stringutils" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/antiaffinity/internal/params" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/extract" + "golang.stackrox.io/kube-linter/pkg/lintcontext" + "golang.stackrox.io/kube-linter/pkg/matcher" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/antiaffinity/internal/params" coreV1 "k8s.io/api/core/v1" metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" diff --git a/internal/templates/antiaffinity/template_test.go b/pkg/templates/antiaffinity/template_test.go similarity index 94% rename from internal/templates/antiaffinity/template_test.go rename to pkg/templates/antiaffinity/template_test.go index b64c229dc..57fe1e147 100644 --- a/internal/templates/antiaffinity/template_test.go +++ b/pkg/templates/antiaffinity/template_test.go @@ -4,11 +4,11 @@ import ( "testing" "github.com/stretchr/testify/suite" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/lintcontext/mocks" "golang.stackrox.io/kube-linter/internal/pointers" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/antiaffinity/internal/params" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/lintcontext/mocks" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/antiaffinity/internal/params" appsV1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/internal/templates/codegen/main.go b/pkg/templates/codegen/main.go similarity index 98% rename from internal/templates/codegen/main.go rename to pkg/templates/codegen/main.go index 800256eaf..2264743d3 100644 --- a/internal/templates/codegen/main.go +++ b/pkg/templates/codegen/main.go @@ -13,10 +13,10 @@ import ( "github.com/Masterminds/sprig/v3" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" "golang.stackrox.io/kube-linter/internal/set" "golang.stackrox.io/kube-linter/internal/stringutils" "golang.stackrox.io/kube-linter/internal/utils" + "golang.stackrox.io/kube-linter/pkg/check" "k8s.io/gengo/parser" "k8s.io/gengo/types" ) @@ -47,8 +47,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/containercapabilities/internal/params/gen-params.go b/pkg/templates/containercapabilities/internal/params/gen-params.go similarity index 95% rename from internal/templates/containercapabilities/internal/params/gen-params.go rename to pkg/templates/containercapabilities/internal/params/gen-params.go index 1e019a7d5..56b790165 100644 --- a/internal/templates/containercapabilities/internal/params/gen-params.go +++ b/pkg/templates/containercapabilities/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/containercapabilities/internal/params/params.go b/pkg/templates/containercapabilities/internal/params/params.go similarity index 100% rename from internal/templates/containercapabilities/internal/params/params.go rename to pkg/templates/containercapabilities/internal/params/params.go diff --git a/internal/templates/containercapabilities/template.go b/pkg/templates/containercapabilities/template.go similarity index 94% rename from internal/templates/containercapabilities/template.go rename to pkg/templates/containercapabilities/template.go index 8b22122aa..c56630296 100644 --- a/internal/templates/containercapabilities/template.go +++ b/pkg/templates/containercapabilities/template.go @@ -4,14 +4,14 @@ import ( "fmt" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/matcher" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/containercapabilities/internal/params" - "golang.stackrox.io/kube-linter/internal/templates/util" "golang.stackrox.io/kube-linter/internal/utils" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/matcher" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/containercapabilities/internal/params" + "golang.stackrox.io/kube-linter/pkg/templates/util" v1 "k8s.io/api/core/v1" ) diff --git a/internal/templates/containercapabilities/template_test.go b/pkg/templates/containercapabilities/template_test.go similarity index 95% rename from internal/templates/containercapabilities/template_test.go rename to pkg/templates/containercapabilities/template_test.go index e706fc03b..4c5e47cf5 100644 --- a/internal/templates/containercapabilities/template_test.go +++ b/pkg/templates/containercapabilities/template_test.go @@ -5,10 +5,10 @@ import ( "testing" "github.com/stretchr/testify/suite" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/lintcontext/mocks" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/containercapabilities/internal/params" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/lintcontext/mocks" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/containercapabilities/internal/params" v1 "k8s.io/api/core/v1" ) diff --git a/internal/templates/cpurequirements/internal/params/gen-params.go b/pkg/templates/cpurequirements/internal/params/gen-params.go similarity index 96% rename from internal/templates/cpurequirements/internal/params/gen-params.go rename to pkg/templates/cpurequirements/internal/params/gen-params.go index f568b35d6..0fb8ac17c 100644 --- a/internal/templates/cpurequirements/internal/params/gen-params.go +++ b/pkg/templates/cpurequirements/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/cpurequirements/internal/params/params.go b/pkg/templates/cpurequirements/internal/params/params.go similarity index 100% rename from internal/templates/cpurequirements/internal/params/params.go rename to pkg/templates/cpurequirements/internal/params/params.go diff --git a/internal/templates/cpurequirements/template.go b/pkg/templates/cpurequirements/template.go similarity index 81% rename from internal/templates/cpurequirements/template.go rename to pkg/templates/cpurequirements/template.go index 8363cee8b..0af51c8ea 100644 --- a/internal/templates/cpurequirements/template.go +++ b/pkg/templates/cpurequirements/template.go @@ -3,12 +3,12 @@ package cpurequirements import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/cpurequirements/internal/params" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/cpurequirements/internal/params" + "golang.stackrox.io/kube-linter/pkg/templates/util" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" ) diff --git a/internal/templates/danglingservice/internal/params/gen-params.go b/pkg/templates/danglingservice/internal/params/gen-params.go similarity index 92% rename from internal/templates/danglingservice/internal/params/gen-params.go rename to pkg/templates/danglingservice/internal/params/gen-params.go index 09ac1a6c7..21bb3aa5c 100644 --- a/internal/templates/danglingservice/internal/params/gen-params.go +++ b/pkg/templates/danglingservice/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/danglingservice/internal/params/params.go b/pkg/templates/danglingservice/internal/params/params.go similarity index 100% rename from internal/templates/danglingservice/internal/params/params.go rename to pkg/templates/danglingservice/internal/params/params.go diff --git a/internal/templates/danglingservice/template.go b/pkg/templates/danglingservice/template.go similarity index 82% rename from internal/templates/danglingservice/template.go rename to pkg/templates/danglingservice/template.go index 704886d78..2a053c16e 100644 --- a/internal/templates/danglingservice/template.go +++ b/pkg/templates/danglingservice/template.go @@ -3,13 +3,13 @@ package danglingservice import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/extract" - "golang.stackrox.io/kube-linter/internal/lintcontext" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/danglingservice/internal/params" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/extract" + "golang.stackrox.io/kube-linter/pkg/lintcontext" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/danglingservice/internal/params" v1 "k8s.io/api/core/v1" metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" diff --git a/internal/templates/mismatchingselector/internal/params/gen-params.go b/pkg/templates/deprecatedserviceaccount/internal/params/gen-params.go similarity index 92% rename from internal/templates/mismatchingselector/internal/params/gen-params.go rename to pkg/templates/deprecatedserviceaccount/internal/params/gen-params.go index 09ac1a6c7..21bb3aa5c 100644 --- a/internal/templates/mismatchingselector/internal/params/gen-params.go +++ b/pkg/templates/deprecatedserviceaccount/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/deprecatedserviceaccount/internal/params/params.go b/pkg/templates/deprecatedserviceaccount/internal/params/params.go similarity index 100% rename from internal/templates/deprecatedserviceaccount/internal/params/params.go rename to pkg/templates/deprecatedserviceaccount/internal/params/params.go diff --git a/internal/templates/deprecatedserviceaccount/template.go b/pkg/templates/deprecatedserviceaccount/template.go similarity index 72% rename from internal/templates/deprecatedserviceaccount/template.go rename to pkg/templates/deprecatedserviceaccount/template.go index ebe7f4556..eff99e1b9 100644 --- a/internal/templates/deprecatedserviceaccount/template.go +++ b/pkg/templates/deprecatedserviceaccount/template.go @@ -3,13 +3,13 @@ package deprecatedserviceaccount import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/extract" - "golang.stackrox.io/kube-linter/internal/lintcontext" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/deprecatedserviceaccount/internal/params" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/extract" + "golang.stackrox.io/kube-linter/pkg/lintcontext" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/deprecatedserviceaccount/internal/params" ) func init() { diff --git a/internal/templates/disallowedgvk/internal/params/gen-params.go b/pkg/templates/disallowedgvk/internal/params/gen-params.go similarity index 95% rename from internal/templates/disallowedgvk/internal/params/gen-params.go rename to pkg/templates/disallowedgvk/internal/params/gen-params.go index a9a72113b..dd88cab30 100644 --- a/internal/templates/disallowedgvk/internal/params/gen-params.go +++ b/pkg/templates/disallowedgvk/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/disallowedgvk/internal/params/params.go b/pkg/templates/disallowedgvk/internal/params/params.go similarity index 100% rename from internal/templates/disallowedgvk/internal/params/params.go rename to pkg/templates/disallowedgvk/internal/params/params.go diff --git a/internal/templates/disallowedgvk/template.go b/pkg/templates/disallowedgvk/template.go similarity index 73% rename from internal/templates/disallowedgvk/template.go rename to pkg/templates/disallowedgvk/template.go index 59c2832e4..9b703891d 100644 --- a/internal/templates/disallowedgvk/template.go +++ b/pkg/templates/disallowedgvk/template.go @@ -4,14 +4,14 @@ import ( "fmt" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/extract" - "golang.stackrox.io/kube-linter/internal/lintcontext" - "golang.stackrox.io/kube-linter/internal/matcher" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/disallowedgvk/internal/params" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/extract" + "golang.stackrox.io/kube-linter/pkg/lintcontext" + "golang.stackrox.io/kube-linter/pkg/matcher" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/disallowedgvk/internal/params" ) func init() { diff --git a/internal/templates/envvar/internal/params/gen-params.go b/pkg/templates/envvar/internal/params/gen-params.go similarity index 95% rename from internal/templates/envvar/internal/params/gen-params.go rename to pkg/templates/envvar/internal/params/gen-params.go index 37734b22d..0eba584aa 100644 --- a/internal/templates/envvar/internal/params/gen-params.go +++ b/pkg/templates/envvar/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/envvar/internal/params/params.go b/pkg/templates/envvar/internal/params/params.go similarity index 100% rename from internal/templates/envvar/internal/params/params.go rename to pkg/templates/envvar/internal/params/params.go diff --git a/internal/templates/envvar/template.go b/pkg/templates/envvar/template.go similarity index 76% rename from internal/templates/envvar/template.go rename to pkg/templates/envvar/template.go index f7a492574..45071c6ba 100644 --- a/internal/templates/envvar/template.go +++ b/pkg/templates/envvar/template.go @@ -4,13 +4,13 @@ import ( "fmt" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/matcher" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/envvar/internal/params" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/matcher" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/envvar/internal/params" + "golang.stackrox.io/kube-linter/pkg/templates/util" v1 "k8s.io/api/core/v1" ) diff --git a/internal/templates/gen.go b/pkg/templates/gen.go similarity index 100% rename from internal/templates/gen.go rename to pkg/templates/gen.go diff --git a/internal/templates/livenessprobe/internal/params/gen-params.go b/pkg/templates/livenessprobe/internal/params/gen-params.go similarity index 92% rename from internal/templates/livenessprobe/internal/params/gen-params.go rename to pkg/templates/livenessprobe/internal/params/gen-params.go index 09ac1a6c7..21bb3aa5c 100644 --- a/internal/templates/livenessprobe/internal/params/gen-params.go +++ b/pkg/templates/livenessprobe/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/livenessprobe/internal/params/params.go b/pkg/templates/livenessprobe/internal/params/params.go similarity index 100% rename from internal/templates/livenessprobe/internal/params/params.go rename to pkg/templates/livenessprobe/internal/params/params.go diff --git a/internal/templates/livenessprobe/template.go b/pkg/templates/livenessprobe/template.go similarity index 70% rename from internal/templates/livenessprobe/template.go rename to pkg/templates/livenessprobe/template.go index 8d0c77c64..80410c3d7 100644 --- a/internal/templates/livenessprobe/template.go +++ b/pkg/templates/livenessprobe/template.go @@ -3,12 +3,12 @@ package livenessprobe import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/livenessprobe/internal/params" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/livenessprobe/internal/params" + "golang.stackrox.io/kube-linter/pkg/templates/util" v1 "k8s.io/api/core/v1" ) diff --git a/internal/templates/memoryrequirements/internal/params/gen-params.go b/pkg/templates/memoryrequirements/internal/params/gen-params.go similarity index 96% rename from internal/templates/memoryrequirements/internal/params/gen-params.go rename to pkg/templates/memoryrequirements/internal/params/gen-params.go index 291a75ce6..73e66dc1a 100644 --- a/internal/templates/memoryrequirements/internal/params/gen-params.go +++ b/pkg/templates/memoryrequirements/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/memoryrequirements/internal/params/params.go b/pkg/templates/memoryrequirements/internal/params/params.go similarity index 100% rename from internal/templates/memoryrequirements/internal/params/params.go rename to pkg/templates/memoryrequirements/internal/params/params.go diff --git a/internal/templates/memoryrequirements/template.go b/pkg/templates/memoryrequirements/template.go similarity index 83% rename from internal/templates/memoryrequirements/template.go rename to pkg/templates/memoryrequirements/template.go index 71bc6e2d4..f775587f9 100644 --- a/internal/templates/memoryrequirements/template.go +++ b/pkg/templates/memoryrequirements/template.go @@ -3,13 +3,13 @@ package memoryrequirements import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/objectkinds" "golang.stackrox.io/kube-linter/internal/pointers" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/memoryrequirements/internal/params" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/memoryrequirements/internal/params" + "golang.stackrox.io/kube-linter/pkg/templates/util" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" ) diff --git a/internal/templates/deprecatedserviceaccount/internal/params/gen-params.go b/pkg/templates/mismatchingselector/internal/params/gen-params.go similarity index 92% rename from internal/templates/deprecatedserviceaccount/internal/params/gen-params.go rename to pkg/templates/mismatchingselector/internal/params/gen-params.go index 09ac1a6c7..21bb3aa5c 100644 --- a/internal/templates/deprecatedserviceaccount/internal/params/gen-params.go +++ b/pkg/templates/mismatchingselector/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/mismatchingselector/internal/params/params.go b/pkg/templates/mismatchingselector/internal/params/params.go similarity index 100% rename from internal/templates/mismatchingselector/internal/params/params.go rename to pkg/templates/mismatchingselector/internal/params/params.go diff --git a/internal/templates/mismatchingselector/template.go b/pkg/templates/mismatchingselector/template.go similarity index 82% rename from internal/templates/mismatchingselector/template.go rename to pkg/templates/mismatchingselector/template.go index ffd00aa9f..8c0e67e61 100644 --- a/internal/templates/mismatchingselector/template.go +++ b/pkg/templates/mismatchingselector/template.go @@ -3,13 +3,13 @@ package mismatchingselector import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/extract" - "golang.stackrox.io/kube-linter/internal/lintcontext" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/mismatchingselector/internal/params" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/extract" + "golang.stackrox.io/kube-linter/pkg/lintcontext" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/mismatchingselector/internal/params" v1 "k8s.io/api/batch/v1" "k8s.io/api/batch/v1beta1" metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/templates/nonexistentserviceaccount/internal/params/gen-params.go b/pkg/templates/nonexistentserviceaccount/internal/params/gen-params.go new file mode 100644 index 000000000..21bb3aa5c --- /dev/null +++ b/pkg/templates/nonexistentserviceaccount/internal/params/gen-params.go @@ -0,0 +1,52 @@ +// Code generated by kube-linter template codegen. DO NOT EDIT. +// +build !templatecodegen + +package params + +import ( + "fmt" + "strings" + + "github.com/pkg/errors" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" +) + +var ( + // Use some imports in case they don't get used otherwise. + _ = util.MustParseParameterDesc + _ = fmt.Sprintf + + ParamDescs = []check.ParameterDesc{ + } +) + +func (p *Params) Validate() error { + var validationErrors []string + if len(validationErrors) > 0 { + return errors.Errorf("invalid parameters: %s", strings.Join(validationErrors, ", ")) + } + return nil +} + +// ParseAndValidate instantiates a Params object out of the passed map[string]interface{}, +// validates it, and returns it. +// The return type is interface{} to satisfy the type in the Template struct. +func ParseAndValidate(m map[string]interface{}) (interface{}, error) { + var p Params + if err := util.DecodeMapStructure(m, &p); err != nil { + return nil, err + } + if err := p.Validate(); err != nil { + return nil, err + } + return p, nil +} + +// WrapInstantiateFunc is a convenience wrapper that wraps an untyped instantiate function +// into a typed one. +func WrapInstantiateFunc(f func(p Params) (check.Func, error)) func (interface{}) (check.Func, error) { + return func(paramsInt interface{}) (check.Func, error) { + return f(paramsInt.(Params)) + } +} diff --git a/internal/templates/nonexistentserviceaccount/internal/params/params.go b/pkg/templates/nonexistentserviceaccount/internal/params/params.go similarity index 100% rename from internal/templates/nonexistentserviceaccount/internal/params/params.go rename to pkg/templates/nonexistentserviceaccount/internal/params/params.go diff --git a/internal/templates/nonexistentserviceaccount/template.go b/pkg/templates/nonexistentserviceaccount/template.go similarity index 80% rename from internal/templates/nonexistentserviceaccount/template.go rename to pkg/templates/nonexistentserviceaccount/template.go index 4f9554a5c..ada4ab43b 100644 --- a/internal/templates/nonexistentserviceaccount/template.go +++ b/pkg/templates/nonexistentserviceaccount/template.go @@ -3,15 +3,15 @@ package nonexistentserviceaccount import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/extract" - "golang.stackrox.io/kube-linter/internal/lintcontext" - "golang.stackrox.io/kube-linter/internal/objectkinds" "golang.stackrox.io/kube-linter/internal/set" "golang.stackrox.io/kube-linter/internal/stringutils" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/nonexistentserviceaccount/internal/params" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/extract" + "golang.stackrox.io/kube-linter/pkg/lintcontext" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/nonexistentserviceaccount/internal/params" v1 "k8s.io/api/core/v1" ) diff --git a/internal/templates/ports/internal/params/gen-params.go b/pkg/templates/ports/internal/params/gen-params.go similarity index 94% rename from internal/templates/ports/internal/params/gen-params.go rename to pkg/templates/ports/internal/params/gen-params.go index fd25325e1..f59176c53 100644 --- a/internal/templates/ports/internal/params/gen-params.go +++ b/pkg/templates/ports/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/ports/internal/params/params.go b/pkg/templates/ports/internal/params/params.go similarity index 100% rename from internal/templates/ports/internal/params/params.go rename to pkg/templates/ports/internal/params/params.go diff --git a/internal/templates/ports/template.go b/pkg/templates/ports/template.go similarity index 75% rename from internal/templates/ports/template.go rename to pkg/templates/ports/template.go index d001dd716..f70368c70 100644 --- a/internal/templates/ports/template.go +++ b/pkg/templates/ports/template.go @@ -4,14 +4,14 @@ import ( "fmt" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/matcher" + "golang.stackrox.io/kube-linter/pkg/matcher" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/ports/internal/params" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/ports/internal/params" + "golang.stackrox.io/kube-linter/pkg/templates/util" v1 "k8s.io/api/core/v1" ) diff --git a/pkg/templates/privileged/internal/params/gen-params.go b/pkg/templates/privileged/internal/params/gen-params.go new file mode 100644 index 000000000..21bb3aa5c --- /dev/null +++ b/pkg/templates/privileged/internal/params/gen-params.go @@ -0,0 +1,52 @@ +// Code generated by kube-linter template codegen. DO NOT EDIT. +// +build !templatecodegen + +package params + +import ( + "fmt" + "strings" + + "github.com/pkg/errors" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" +) + +var ( + // Use some imports in case they don't get used otherwise. + _ = util.MustParseParameterDesc + _ = fmt.Sprintf + + ParamDescs = []check.ParameterDesc{ + } +) + +func (p *Params) Validate() error { + var validationErrors []string + if len(validationErrors) > 0 { + return errors.Errorf("invalid parameters: %s", strings.Join(validationErrors, ", ")) + } + return nil +} + +// ParseAndValidate instantiates a Params object out of the passed map[string]interface{}, +// validates it, and returns it. +// The return type is interface{} to satisfy the type in the Template struct. +func ParseAndValidate(m map[string]interface{}) (interface{}, error) { + var p Params + if err := util.DecodeMapStructure(m, &p); err != nil { + return nil, err + } + if err := p.Validate(); err != nil { + return nil, err + } + return p, nil +} + +// WrapInstantiateFunc is a convenience wrapper that wraps an untyped instantiate function +// into a typed one. +func WrapInstantiateFunc(f func(p Params) (check.Func, error)) func (interface{}) (check.Func, error) { + return func(paramsInt interface{}) (check.Func, error) { + return f(paramsInt.(Params)) + } +} diff --git a/internal/templates/privileged/internal/params/params.go b/pkg/templates/privileged/internal/params/params.go similarity index 100% rename from internal/templates/privileged/internal/params/params.go rename to pkg/templates/privileged/internal/params/params.go diff --git a/internal/templates/privileged/template.go b/pkg/templates/privileged/template.go similarity index 72% rename from internal/templates/privileged/template.go rename to pkg/templates/privileged/template.go index 85bdaffc6..09460bd70 100644 --- a/internal/templates/privileged/template.go +++ b/pkg/templates/privileged/template.go @@ -3,12 +3,12 @@ package privileged import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/privileged/internal/params" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/privileged/internal/params" + "golang.stackrox.io/kube-linter/pkg/templates/util" v1 "k8s.io/api/core/v1" ) diff --git a/pkg/templates/readinessprobe/internal/params/gen-params.go b/pkg/templates/readinessprobe/internal/params/gen-params.go new file mode 100644 index 000000000..21bb3aa5c --- /dev/null +++ b/pkg/templates/readinessprobe/internal/params/gen-params.go @@ -0,0 +1,52 @@ +// Code generated by kube-linter template codegen. DO NOT EDIT. +// +build !templatecodegen + +package params + +import ( + "fmt" + "strings" + + "github.com/pkg/errors" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" +) + +var ( + // Use some imports in case they don't get used otherwise. + _ = util.MustParseParameterDesc + _ = fmt.Sprintf + + ParamDescs = []check.ParameterDesc{ + } +) + +func (p *Params) Validate() error { + var validationErrors []string + if len(validationErrors) > 0 { + return errors.Errorf("invalid parameters: %s", strings.Join(validationErrors, ", ")) + } + return nil +} + +// ParseAndValidate instantiates a Params object out of the passed map[string]interface{}, +// validates it, and returns it. +// The return type is interface{} to satisfy the type in the Template struct. +func ParseAndValidate(m map[string]interface{}) (interface{}, error) { + var p Params + if err := util.DecodeMapStructure(m, &p); err != nil { + return nil, err + } + if err := p.Validate(); err != nil { + return nil, err + } + return p, nil +} + +// WrapInstantiateFunc is a convenience wrapper that wraps an untyped instantiate function +// into a typed one. +func WrapInstantiateFunc(f func(p Params) (check.Func, error)) func (interface{}) (check.Func, error) { + return func(paramsInt interface{}) (check.Func, error) { + return f(paramsInt.(Params)) + } +} diff --git a/internal/templates/readinessprobe/internal/params/params.go b/pkg/templates/readinessprobe/internal/params/params.go similarity index 100% rename from internal/templates/readinessprobe/internal/params/params.go rename to pkg/templates/readinessprobe/internal/params/params.go diff --git a/internal/templates/readinessprobe/template.go b/pkg/templates/readinessprobe/template.go similarity index 70% rename from internal/templates/readinessprobe/template.go rename to pkg/templates/readinessprobe/template.go index e37273b55..5b0481640 100644 --- a/internal/templates/readinessprobe/template.go +++ b/pkg/templates/readinessprobe/template.go @@ -3,12 +3,12 @@ package readinessprobe import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/readinessprobe/internal/params" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/readinessprobe/internal/params" + "golang.stackrox.io/kube-linter/pkg/templates/util" v1 "k8s.io/api/core/v1" ) diff --git a/pkg/templates/readonlyrootfs/internal/params/gen-params.go b/pkg/templates/readonlyrootfs/internal/params/gen-params.go new file mode 100644 index 000000000..21bb3aa5c --- /dev/null +++ b/pkg/templates/readonlyrootfs/internal/params/gen-params.go @@ -0,0 +1,52 @@ +// Code generated by kube-linter template codegen. DO NOT EDIT. +// +build !templatecodegen + +package params + +import ( + "fmt" + "strings" + + "github.com/pkg/errors" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" +) + +var ( + // Use some imports in case they don't get used otherwise. + _ = util.MustParseParameterDesc + _ = fmt.Sprintf + + ParamDescs = []check.ParameterDesc{ + } +) + +func (p *Params) Validate() error { + var validationErrors []string + if len(validationErrors) > 0 { + return errors.Errorf("invalid parameters: %s", strings.Join(validationErrors, ", ")) + } + return nil +} + +// ParseAndValidate instantiates a Params object out of the passed map[string]interface{}, +// validates it, and returns it. +// The return type is interface{} to satisfy the type in the Template struct. +func ParseAndValidate(m map[string]interface{}) (interface{}, error) { + var p Params + if err := util.DecodeMapStructure(m, &p); err != nil { + return nil, err + } + if err := p.Validate(); err != nil { + return nil, err + } + return p, nil +} + +// WrapInstantiateFunc is a convenience wrapper that wraps an untyped instantiate function +// into a typed one. +func WrapInstantiateFunc(f func(p Params) (check.Func, error)) func (interface{}) (check.Func, error) { + return func(paramsInt interface{}) (check.Func, error) { + return f(paramsInt.(Params)) + } +} diff --git a/internal/templates/readonlyrootfs/internal/params/params.go b/pkg/templates/readonlyrootfs/internal/params/params.go similarity index 100% rename from internal/templates/readonlyrootfs/internal/params/params.go rename to pkg/templates/readonlyrootfs/internal/params/params.go diff --git a/internal/templates/readonlyrootfs/template.go b/pkg/templates/readonlyrootfs/template.go similarity index 72% rename from internal/templates/readonlyrootfs/template.go rename to pkg/templates/readonlyrootfs/template.go index 8ae299deb..4033a5b6b 100644 --- a/internal/templates/readonlyrootfs/template.go +++ b/pkg/templates/readonlyrootfs/template.go @@ -3,12 +3,12 @@ package readonlyrootfs import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/readonlyrootfs/internal/params" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/readonlyrootfs/internal/params" + "golang.stackrox.io/kube-linter/pkg/templates/util" v1 "k8s.io/api/core/v1" ) diff --git a/internal/templates/registry.go b/pkg/templates/registry.go similarity index 94% rename from internal/templates/registry.go rename to pkg/templates/registry.go index 470397146..767c3f8c9 100644 --- a/internal/templates/registry.go +++ b/pkg/templates/registry.go @@ -4,7 +4,7 @@ import ( "fmt" "sort" - "golang.stackrox.io/kube-linter/internal/check" + "golang.stackrox.io/kube-linter/pkg/check" ) var ( diff --git a/internal/templates/requiredlabel/internal/params/gen-params.go b/pkg/templates/requiredannotation/internal/params/gen-params.go similarity index 95% rename from internal/templates/requiredlabel/internal/params/gen-params.go rename to pkg/templates/requiredannotation/internal/params/gen-params.go index 7061919c5..ded2dceb0 100644 --- a/internal/templates/requiredlabel/internal/params/gen-params.go +++ b/pkg/templates/requiredannotation/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/requiredannotation/internal/params/params.go b/pkg/templates/requiredannotation/internal/params/params.go similarity index 100% rename from internal/templates/requiredannotation/internal/params/params.go rename to pkg/templates/requiredannotation/internal/params/params.go diff --git a/internal/templates/requiredannotation/template.go b/pkg/templates/requiredannotation/template.go similarity index 67% rename from internal/templates/requiredannotation/template.go rename to pkg/templates/requiredannotation/template.go index 90bec093e..6653ccf30 100644 --- a/internal/templates/requiredannotation/template.go +++ b/pkg/templates/requiredannotation/template.go @@ -1,11 +1,11 @@ package requiredannotation import ( - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/requiredannotation/internal/params" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/requiredannotation/internal/params" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) func init() { diff --git a/internal/templates/requiredannotation/internal/params/gen-params.go b/pkg/templates/requiredlabel/internal/params/gen-params.go similarity index 95% rename from internal/templates/requiredannotation/internal/params/gen-params.go rename to pkg/templates/requiredlabel/internal/params/gen-params.go index 7061919c5..ded2dceb0 100644 --- a/internal/templates/requiredannotation/internal/params/gen-params.go +++ b/pkg/templates/requiredlabel/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/requiredlabel/internal/params/params.go b/pkg/templates/requiredlabel/internal/params/params.go similarity index 100% rename from internal/templates/requiredlabel/internal/params/params.go rename to pkg/templates/requiredlabel/internal/params/params.go diff --git a/internal/templates/requiredlabel/template.go b/pkg/templates/requiredlabel/template.go similarity index 66% rename from internal/templates/requiredlabel/template.go rename to pkg/templates/requiredlabel/template.go index 5f8149706..56d06e284 100644 --- a/internal/templates/requiredlabel/template.go +++ b/pkg/templates/requiredlabel/template.go @@ -1,11 +1,11 @@ package requiredlabel import ( - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/requiredlabel/internal/params" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/requiredlabel/internal/params" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) func init() { diff --git a/pkg/templates/runasnonroot/internal/params/gen-params.go b/pkg/templates/runasnonroot/internal/params/gen-params.go new file mode 100644 index 000000000..21bb3aa5c --- /dev/null +++ b/pkg/templates/runasnonroot/internal/params/gen-params.go @@ -0,0 +1,52 @@ +// Code generated by kube-linter template codegen. DO NOT EDIT. +// +build !templatecodegen + +package params + +import ( + "fmt" + "strings" + + "github.com/pkg/errors" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" +) + +var ( + // Use some imports in case they don't get used otherwise. + _ = util.MustParseParameterDesc + _ = fmt.Sprintf + + ParamDescs = []check.ParameterDesc{ + } +) + +func (p *Params) Validate() error { + var validationErrors []string + if len(validationErrors) > 0 { + return errors.Errorf("invalid parameters: %s", strings.Join(validationErrors, ", ")) + } + return nil +} + +// ParseAndValidate instantiates a Params object out of the passed map[string]interface{}, +// validates it, and returns it. +// The return type is interface{} to satisfy the type in the Template struct. +func ParseAndValidate(m map[string]interface{}) (interface{}, error) { + var p Params + if err := util.DecodeMapStructure(m, &p); err != nil { + return nil, err + } + if err := p.Validate(); err != nil { + return nil, err + } + return p, nil +} + +// WrapInstantiateFunc is a convenience wrapper that wraps an untyped instantiate function +// into a typed one. +func WrapInstantiateFunc(f func(p Params) (check.Func, error)) func (interface{}) (check.Func, error) { + return func(paramsInt interface{}) (check.Func, error) { + return f(paramsInt.(Params)) + } +} diff --git a/internal/templates/runasnonroot/internal/params/params.go b/pkg/templates/runasnonroot/internal/params/params.go similarity index 100% rename from internal/templates/runasnonroot/internal/params/params.go rename to pkg/templates/runasnonroot/internal/params/params.go diff --git a/internal/templates/runasnonroot/template.go b/pkg/templates/runasnonroot/template.go similarity index 84% rename from internal/templates/runasnonroot/template.go rename to pkg/templates/runasnonroot/template.go index c24700b0f..0c7b81996 100644 --- a/internal/templates/runasnonroot/template.go +++ b/pkg/templates/runasnonroot/template.go @@ -3,13 +3,13 @@ package runasnonroot import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/extract" - "golang.stackrox.io/kube-linter/internal/lintcontext" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/runasnonroot/internal/params" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/extract" + "golang.stackrox.io/kube-linter/pkg/lintcontext" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/runasnonroot/internal/params" v1 "k8s.io/api/core/v1" ) diff --git a/internal/templates/serviceaccount/internal/params/gen-params.go b/pkg/templates/serviceaccount/internal/params/gen-params.go similarity index 94% rename from internal/templates/serviceaccount/internal/params/gen-params.go rename to pkg/templates/serviceaccount/internal/params/gen-params.go index 9a2e0895c..a4e4c95f8 100644 --- a/internal/templates/serviceaccount/internal/params/gen-params.go +++ b/pkg/templates/serviceaccount/internal/params/gen-params.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/templates/util" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" ) var ( diff --git a/internal/templates/serviceaccount/internal/params/params.go b/pkg/templates/serviceaccount/internal/params/params.go similarity index 100% rename from internal/templates/serviceaccount/internal/params/params.go rename to pkg/templates/serviceaccount/internal/params/params.go diff --git a/internal/templates/serviceaccount/template.go b/pkg/templates/serviceaccount/template.go similarity index 71% rename from internal/templates/serviceaccount/template.go rename to pkg/templates/serviceaccount/template.go index e6fae0c30..fe537a98a 100644 --- a/internal/templates/serviceaccount/template.go +++ b/pkg/templates/serviceaccount/template.go @@ -3,15 +3,15 @@ package serviceaccount import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/extract" - "golang.stackrox.io/kube-linter/internal/lintcontext" - "golang.stackrox.io/kube-linter/internal/matcher" - "golang.stackrox.io/kube-linter/internal/objectkinds" "golang.stackrox.io/kube-linter/internal/stringutils" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/serviceaccount/internal/params" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/extract" + "golang.stackrox.io/kube-linter/pkg/lintcontext" + "golang.stackrox.io/kube-linter/pkg/matcher" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/serviceaccount/internal/params" ) func init() { diff --git a/internal/templates/templates_testutils.go b/pkg/templates/templates_testutils.go similarity index 92% rename from internal/templates/templates_testutils.go rename to pkg/templates/templates_testutils.go index f6488dbff..e09c40e8b 100644 --- a/internal/templates/templates_testutils.go +++ b/pkg/templates/templates_testutils.go @@ -4,9 +4,9 @@ import ( "fmt" "github.com/stretchr/testify/suite" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/lintcontext" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/lintcontext" ) // TemplateTestSuite is a basic testing suite for all templates diff --git a/internal/templates/util/json.go b/pkg/templates/util/json.go similarity index 89% rename from internal/templates/util/json.go rename to pkg/templates/util/json.go index b5b762fa2..eb774d7d6 100644 --- a/internal/templates/util/json.go +++ b/pkg/templates/util/json.go @@ -4,7 +4,7 @@ import ( "encoding/json" "strings" - "golang.stackrox.io/kube-linter/internal/check" + "golang.stackrox.io/kube-linter/pkg/check" ) // MustParseParameterDesc unmarshals the given JSON into a templates.ParameterDesc. diff --git a/internal/templates/util/map_structure.go b/pkg/templates/util/map_structure.go similarity index 100% rename from internal/templates/util/map_structure.go rename to pkg/templates/util/map_structure.go diff --git a/internal/templates/util/per_container_check.go b/pkg/templates/util/per_container_check.go similarity index 77% rename from internal/templates/util/per_container_check.go rename to pkg/templates/util/per_container_check.go index 514bc2241..099588284 100644 --- a/internal/templates/util/per_container_check.go +++ b/pkg/templates/util/per_container_check.go @@ -1,10 +1,10 @@ package util import ( - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/extract" - "golang.stackrox.io/kube-linter/internal/lintcontext" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/extract" + "golang.stackrox.io/kube-linter/pkg/lintcontext" v1 "k8s.io/api/core/v1" ) diff --git a/internal/templates/util/required_matcher.go b/pkg/templates/util/required_matcher.go similarity index 82% rename from internal/templates/util/required_matcher.go rename to pkg/templates/util/required_matcher.go index 387f36297..ff5197839 100644 --- a/internal/templates/util/required_matcher.go +++ b/pkg/templates/util/required_matcher.go @@ -4,13 +4,13 @@ import ( "fmt" "github.com/pkg/errors" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/extract" "golang.stackrox.io/kube-linter/internal/k8sutil" - "golang.stackrox.io/kube-linter/internal/lintcontext" - "golang.stackrox.io/kube-linter/internal/matcher" "golang.stackrox.io/kube-linter/internal/stringutils" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/extract" + "golang.stackrox.io/kube-linter/pkg/lintcontext" + "golang.stackrox.io/kube-linter/pkg/matcher" ) // ConstructRequiredMapMatcher constructs a check function that requires that a k-v pair is present in the map. diff --git a/internal/templates/util/value_in_range.go b/pkg/templates/util/value_in_range.go similarity index 100% rename from internal/templates/util/value_in_range.go rename to pkg/templates/util/value_in_range.go diff --git a/internal/templates/util/value_in_range_test.go b/pkg/templates/util/value_in_range_test.go similarity index 100% rename from internal/templates/util/value_in_range_test.go rename to pkg/templates/util/value_in_range_test.go diff --git a/pkg/templates/writablehostmount/internal/params/gen-params.go b/pkg/templates/writablehostmount/internal/params/gen-params.go new file mode 100644 index 000000000..21bb3aa5c --- /dev/null +++ b/pkg/templates/writablehostmount/internal/params/gen-params.go @@ -0,0 +1,52 @@ +// Code generated by kube-linter template codegen. DO NOT EDIT. +// +build !templatecodegen + +package params + +import ( + "fmt" + "strings" + + "github.com/pkg/errors" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/templates/util" +) + +var ( + // Use some imports in case they don't get used otherwise. + _ = util.MustParseParameterDesc + _ = fmt.Sprintf + + ParamDescs = []check.ParameterDesc{ + } +) + +func (p *Params) Validate() error { + var validationErrors []string + if len(validationErrors) > 0 { + return errors.Errorf("invalid parameters: %s", strings.Join(validationErrors, ", ")) + } + return nil +} + +// ParseAndValidate instantiates a Params object out of the passed map[string]interface{}, +// validates it, and returns it. +// The return type is interface{} to satisfy the type in the Template struct. +func ParseAndValidate(m map[string]interface{}) (interface{}, error) { + var p Params + if err := util.DecodeMapStructure(m, &p); err != nil { + return nil, err + } + if err := p.Validate(); err != nil { + return nil, err + } + return p, nil +} + +// WrapInstantiateFunc is a convenience wrapper that wraps an untyped instantiate function +// into a typed one. +func WrapInstantiateFunc(f func(p Params) (check.Func, error)) func (interface{}) (check.Func, error) { + return func(paramsInt interface{}) (check.Func, error) { + return f(paramsInt.(Params)) + } +} diff --git a/internal/templates/writablehostmount/internal/params/params.go b/pkg/templates/writablehostmount/internal/params/params.go similarity index 100% rename from internal/templates/writablehostmount/internal/params/params.go rename to pkg/templates/writablehostmount/internal/params/params.go diff --git a/internal/templates/writablehostmount/template.go b/pkg/templates/writablehostmount/template.go similarity index 78% rename from internal/templates/writablehostmount/template.go rename to pkg/templates/writablehostmount/template.go index 5f4e14ae4..bf12eb7b9 100644 --- a/internal/templates/writablehostmount/template.go +++ b/pkg/templates/writablehostmount/template.go @@ -3,13 +3,13 @@ package writablehostmount import ( "fmt" - "golang.stackrox.io/kube-linter/internal/check" - "golang.stackrox.io/kube-linter/internal/diagnostic" - "golang.stackrox.io/kube-linter/internal/extract" - "golang.stackrox.io/kube-linter/internal/lintcontext" - "golang.stackrox.io/kube-linter/internal/objectkinds" - "golang.stackrox.io/kube-linter/internal/templates" - "golang.stackrox.io/kube-linter/internal/templates/writablehostmount/internal/params" + "golang.stackrox.io/kube-linter/pkg/check" + "golang.stackrox.io/kube-linter/pkg/diagnostic" + "golang.stackrox.io/kube-linter/pkg/extract" + "golang.stackrox.io/kube-linter/pkg/lintcontext" + "golang.stackrox.io/kube-linter/pkg/objectkinds" + "golang.stackrox.io/kube-linter/pkg/templates" + "golang.stackrox.io/kube-linter/pkg/templates/writablehostmount/internal/params" ) func init() {