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

Migrate to kyaml #412

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix bats tests
  • Loading branch information
ultram4rine committed Dec 26, 2023
commit 608b90a332e5a5e94b8e4491efc8dc5ab3a34410
6 changes: 5 additions & 1 deletion internal/kubeconfig/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ func (k *Kubeconfig) contextsNode() (*yaml.RNode, error) {
}

func (k *Kubeconfig) contextNode(name string) (*yaml.RNode, error) {
context, err := k.config.Pipe(yaml.Lookup("contexts", "[name="+name+"]"))
contexts, err := k.contextsNode()
if err != nil {
return nil, err
}
context, err := contexts.Pipe(yaml.Lookup("[name=" + name + "]"))
if err != nil {
return nil, err
}
Expand Down
8 changes: 1 addition & 7 deletions internal/kubeconfig/currentcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package kubeconfig

import (
"strings"

"sigs.k8s.io/kustomize/kyaml/yaml"
)

Expand All @@ -27,11 +25,7 @@ func (k *Kubeconfig) GetCurrentContext() string {
if err != nil {
return ""
}
str, err := v.String()
if err != nil {
return ""
}
return strings.TrimSpace(str)
return yaml.GetValue(v)
}

func (k *Kubeconfig) UnsetCurrentContext() error {
Expand Down
8 changes: 1 addition & 7 deletions internal/kubeconfig/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package kubeconfig

import (
"strings"

"sigs.k8s.io/kustomize/kyaml/yaml"
)

Expand All @@ -33,11 +31,7 @@ func (k *Kubeconfig) NamespaceOfContext(contextName string) (string, error) {
if namespace == nil || err != nil {
return defaultNamespace, err
}
nsStr, err := namespace.String()
if nsStr == "" || err != nil {
return defaultNamespace, err
}
return strings.TrimSpace(nsStr), nil
return yaml.GetValue(namespace), nil
}

func (k *Kubeconfig) SetNamespace(ctxName string, ns string) error {
Expand Down