postfinance/kubectl-vault_sync

"Error: could not create namespace api client: resource name may not be empty"

bbortt opened this issue ยท 7 comments

Hi guys

I'm kind of stuck with the following error:

+ vault_sync
+ kubectl vault_sync --namespace=$K8S_NAMESPACE --wait
Error: could not create namespace api client: resource name may not be empty

I think this means you do not support --namespace yet, right? Sadly, my $KUBECONFIG is readonly (using GitHub Actions).
Edit: Or could it be something else? :/

Hi bbortt

You're right, it gets the namespace according to the kubeconfig and ignores the cli arguments:

currentNs := o.rawConfig.Contexts[o.rawConfig.CurrentContext].Namespace
restConfig, err := o.configFlags.ToRESTConfig()
if err != nil {
return err
}
clientset, err := kubernetes.NewForConfig(restConfig)
if err != nil {
return err
}
nsClient := clientset.CoreV1().Namespaces()
ns, err := nsClient.Get(currentNs, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("could not create namespace api client: %s", err)
}

So currentNs will be empty and it returns an error while trying to fetch that namespace ressource.

To understand you correctly, your context in kubeconfig doesn't contain a namespace like this?

contexts:
- context:
    cluster: example
    namespace: you-mean-this-key
    user: djboris9
  name: example

Implemented namespace overriding by cli args with 4ea2ed2, can you please try the version from master and give me feedback if it works for you

Hi @djboris9

Exactly, I cannot set the active namespace via kubectl.

Just wanted to suggest that I look at the implementation of --wait and see what I can do. But you were a lot faster :D

Thank you very much. I'll try it this evening.

I'm sorry.. but how do I compile this on localhost?
I'm not fluent in go.. tried to look at the Travis-CI build, no chance :D I just navigated into pkg/plugin and executed go build. That results in (when executing the plugin):

+ kubectl vault_sync --namespace=qdrakeboo-alpha --wait
exec format error

Do it that way (with a recent Go version):

export GO111MODULE=on
go build -o kubectl-bbortt ./cmd/
export PATH="$(pwd):$PATH"
kubectl bbortt ... # the plugin is registered as bbortt

awesome, works like a charm! thank you very much.

+ kubectl vault_sync --namespace=${K8S_NAMESPACE} --wait
creating sync batch job to synchronize 'secret/k8s/${K8S_NAMESPACE}/' vault key

btw. will you release the update? makes my dockerfile look much cleaner ;)