Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(kubernetes): do not fail on nil receiver #56

Merged
merged 1 commit into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/jpath/jpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

var (
// ErrorNoRoot means no rootDir was found in the parents
ErrorNoRoot = errors.New("could not locate a jsonnetfile.json in the parent directories, which is required to identify the project root")
ErrorNoRoot = errors.New("could not locate a jsonnetfile.json in the parent directories, which is required to identify the project root. Refer to https://tanka.dev/directory-structure for more information")

// ErrorNoBase means no baseDir was found in the parents
ErrorNoBase = errors.New("could not locate a main.jsonnet in the parent directories, which is required as the entrypoint for the evaluation")
ErrorNoBase = errors.New("could not locate a main.jsonnet in the parent directories, which is required as the entrypoint for the evaluation. Refer to https://tanka.dev/directory-structure for more information")
)

// ErrorFileNotFound means that the searched file was not found
Expand Down
8 changes: 8 additions & 0 deletions pkg/kubernetes/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ type ErrorNotFound struct {
func (e ErrorNotFound) Error() string {
return fmt.Sprintf(`error from server (NotFound): secrets "%s" not found`, e.resource)
}

type ErrorMissingConfig struct {
verb string
}

func (e ErrorMissingConfig) Error() string {
return fmt.Sprintf("%s requires additional configuration. Refer to https://tanka.dev/environments for that.", e.verb)
}
11 changes: 10 additions & 1 deletion pkg/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func (k *Kubernetes) Reconcile(raw map[string]interface{}, objectspecs ...string
}
for _, d := range docs {
m := objx.New(d)
m.Set("metadata.namespace", k.Spec.Namespace)
if k != nil {
m.Set("metadata.namespace", k.Spec.Namespace)
}
out = append(out, Manifest(m))
}

Expand Down Expand Up @@ -106,6 +108,10 @@ func (k *Kubernetes) Fmt(state []Manifest) (string, error) {

// Apply receives a state object generated using `Reconcile()` and may apply it to the target system
func (k *Kubernetes) Apply(state []Manifest, opts ApplyOpts) error {
if k == nil {
return ErrorMissingConfig{"apply"}
}

yaml, err := k.Fmt(state)
if err != nil {
return err
Expand All @@ -115,6 +121,9 @@ func (k *Kubernetes) Apply(state []Manifest, opts ApplyOpts) error {

// Diff takes the desired state and returns the differences from the cluster
func (k *Kubernetes) Diff(state []Manifest) (*string, error) {
if k == nil {
return nil, ErrorMissingConfig{"diff"}
}
yaml, err := k.Fmt(state)
if err != nil {
return nil, err
Expand Down