k8s icon indicating copy to clipboard operation
k8s copied to clipboard

Sync kubeconfig structure as part of generate

Open LukeShu opened this issue 6 years ago • 4 comments

config.go is copied from client-go/tools/clientcmd/api/v1/types.go, and then modified a bit to kinda-sorta make gopkg.in/yaml.v2 happy (modified in #71 for #60, but still kinda broken #81).

Since it's still broken with gopkg.in/yaml.v2, let's just ditch the modifications in #71, so that we can copy the file as part of generate, instead of trying to keep it in-sync manually. This has the potential to break users who use gopkg.in/yaml.v2 (and rely on no -data fields being set in the YAML they're parsing). I figure since it's already kinda broken, most users aren't using gopkg.in/yaml.v2, especially since the docs point them toward github.com/ghodss/yaml.

When we "generate" it, put it in ./config/v1/, to make it clear that it is a versioned type imported from client-go. I think it's cleaner that way.

But, to avoid totally breaking existing users, don't entirely remove config.go, but replace it with a list of Go 1.9 type aliases, so that github.com/ericchiang/k8s.Config is an alias for github.com/ericchiang/k8s/client/v1.Config and so on. This bumps the required Go version from 1.7 to 1.9. This bump could be avoided at the cost of breaking existing users.

Alternatively, the generate script could be edited to keep it in the current package.

I'm not sure what your feelings are on breaking changes at the expense of clarity, or whether this type of change is welcome in general.

LukeShu avatar Feb 05 '19 03:02 LukeShu

What part of the kubeconfig parsing is broken exactly?

ericchiang avatar Feb 05 '19 03:02 ericchiang

What #81 says, that gopkg.in/yaml.v2 refuses to unmarshal certificate-authority-data as a []byte instead of as a string.

As you recommend, github.com/ghodss/yaml does not have that issue, and also totally ignores the yaml: struct tags added in #71, instead paying attention to the json: struct tags. The yaml: struct tags only serve to try to make gopkg.in/yaml.v2 happy.

LukeShu avatar Feb 05 '19 04:02 LukeShu

My main concern is that we're going to break users using github.com/ghodss/yaml. Can we commit the generated config then provide a convince to convert from the generated one to the existing one?

ericchiang avatar Feb 05 '19 17:02 ericchiang

This should not break users using github.com/ghodss/yaml.

LukeShu avatar Feb 05 '19 17:02 LukeShu