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

Add framework to init config in a plugin #182

Merged
merged 3 commits into from Jan 24, 2018

Conversation

jberkhahn
Copy link
Contributor

Hello. This is a PR of the extracted framework from the service-catalog plugins I've been writing. I discussed it with @pwittrock at Kubecon, and he expressed interest in me contributing it here for general use.

It's use is to create a config based on the system kubectl config and the environment variables passed in from the calling plugin framework. I've got most of them worked out, however the overrides for the config cluster, context, and user still need to be done. I thought I would get this out here and get some feedback on what I have so far.

Thanks,
@jberkhahn

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 15, 2017
@pwittrock
Copy link
Member

/assign @droot

@apelisse
Copy link
Member

apelisse commented Dec 18, 2017

I've not read the code, but I don't think we plan on having anything live directly into pkg/framework.

@droot
Copy link
Contributor

droot commented Jan 3, 2018

Took a quick look. A few minor comments about the code. Though I am yet to understand the motivation of the code and where it belong in pkg structure especially given that plugins are still an Alpha thing. Lets have a chat this week to go over it.

// then the value of the KUBECONFIG env var (if any), and defaulting
// to ~/.kube/config as a last resort.
home := os.Getenv("HOME")
kubeconfig := home + "/.kube/config"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filepath.Join(home, ".kube", "config") ? That will probably make the code more portable across different OS's ?

WjWmyvFisfZpuBuNGYLAi21qKIKUEItH71w120AbuR14x8YkK/Afp1+mh67gDgdL
Rcggy/IJOIuqJLvynmfb17iED+7HVw/4ujkg5LbLSC1iQLO8HjlNUu/dvSIg6oHQ
0UUz9d+Yzg==
-----END CERTIFICATE-----
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is test data. It will better to have them in directory testData to be more explicit ?

dpYw+p8tH/3ZY+RRD6B0xHlPLXuxjl/vz5rHaSVta4jigtPUJGAy81noevkwYdhq
HKK2EKK7+Q8lEYxMUm0KremgwettiVUBO+FR1xRRrsMcKX6sWNRhbH8oxfv++EmU
0h+zLBSC8GVsba27MVpjd8sy
-----END CERTIFICATE-----
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above (have them under testData dir ?)

iophhQKBgH/oS7xi2AFrGrscIVGL8V0M2GeACAhR7VKEw8PNbloH2HayfTY7fMlb
hY+kHxp52Ycinj1xiaCRIdceI/cXxENcEDyIrKny0Xs4shO3NXFzW6JhMB3hjDY7
2dPsYPzdEQTldmWHGS45XmKBMNgIOPNTXVl8i8UEZqtHIQohI1Wj
-----END RSA PRIVATE KEY-----
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

user:
as-user-extra: {}
username: foo
password: bar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

@@ -0,0 +1,176 @@
/*
Copyright 2016 The Kubernetes Authors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2018?

limitations under the License.
*/

package framework
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like it belong under framework. looks like it belongs under "pluginutils" under pkg ?


func clientFromConfig(path string) (*restclient.Config, string, error) {
if path == "-" {
cfg, err := restclient.InClusterConfig()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is useful for plugins ?

)

var _ = Describe("InitConfig", func() {
var ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@jberkhahn
Copy link
Contributor Author

@droot I took a look at your comments and did some refactoring. I would love to chat whenever you're free. I'm @jberkhahn on the kubernetes slack as well.

@apelisse
Copy link
Member

I'm sorry for all my packages comment, but Go recommends not using underscores in package names.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 10, 2018
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 17, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jberkhahn
We suggest the following additional approver: pwittrock

Assign the PR to them by writing /assign @pwittrock in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of minor nits.

@apelisse Do you think this is the right place for pluginutils pkg?

}

if len(kubeconfig) == 0 {
return nil, errors.New(fmt.Sprintf("error iniializing config. The KUBECONFIG environment variable must be defined."))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/iniializing/initializing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.New(fmt.Sprintf) ---> fmt.Errorf(....) ?


clientConfig, _, err := clientFromConfig(kubeconfig)
if err != nil {
return nil, errors.New(fmt.Sprintf("error obtaining kubectl config: %v", err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt.Errorf(...) ?


err = applyGlobalOptionsToConfig(clientConfig)
if err != nil {
return nil, errors.New(fmt.Sprintf("error processing global plugin options: %v", err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt.Errorf(...) ?

@k8s-ci-robot k8s-ci-robot merged commit 66eb14f into kubernetes:master Jan 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants