-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Refactor the client (again) to better support auth #1500
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,6 @@ import ( | |
"strconv" | ||
"time" | ||
|
||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" | ||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" | ||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" | ||
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller" | ||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz" | ||
|
@@ -39,25 +37,29 @@ import ( | |
) | ||
|
||
var ( | ||
master = flag.String("master", "", "The address of the Kubernetes API server") | ||
port = flag.Int("port", masterPkg.ControllerManagerPort, "The port that the controller-manager's http service runs on") | ||
address = flag.String("address", "127.0.0.1", "The address to serve from") | ||
port = flag.Int("port", masterPkg.ControllerManagerPort, "The port that the controller-manager's http service runs on") | ||
address = flag.String("address", "127.0.0.1", "The address to serve from") | ||
clientConfig = &client.Config{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How well does this approach play with the --help logic, I assume that it all just works, but I wanted to check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shows up (although currently it's sorted, so the fields are separate). In kubecfg2 we could benefit from distinct flag sets that are displayed in an order.
|
||
) | ||
|
||
func init() { | ||
client.BindClientConfigFlags(flag.CommandLine, clientConfig) | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
util.InitLogs() | ||
defer util.FlushLogs() | ||
|
||
verflag.PrintAndExitIfRequested() | ||
|
||
if len(*master) == 0 { | ||
if len(clientConfig.Host) == 0 { | ||
glog.Fatal("usage: controller-manager -master <master>") | ||
} | ||
ctx := api.NewContext() | ||
kubeClient, err := client.New(ctx, *master, latest.OldestVersion, nil) | ||
|
||
kubeClient, err := client.New(clientConfig) | ||
if err != nil { | ||
glog.Fatalf("Invalid -master: %v", err) | ||
glog.Fatalf("Invalid API configuration: %v", err) | ||
} | ||
|
||
go http.ListenAndServe(net.JoinHostPort(*address, strconv.Itoa(*port)), nil) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Copyright 2014 Google Inc. All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package testapi provides a helper for retrieving the KUBE_API_VERSION environment variable. | ||
package testapi | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" | ||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" | ||
) | ||
|
||
// Version returns the API version to test against as set by the KUBE_API_VERSION env var. | ||
func Version() string { | ||
version := os.Getenv("KUBE_API_VERSION") | ||
if version == "" { | ||
version = latest.Version | ||
} | ||
return version | ||
} | ||
|
||
func CodecForVersionOrDie() runtime.Codec { | ||
interfaces, err := latest.InterfacesFor(Version()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return interfaces.Codec | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client.New does not appear to call api.NewContext. I see it being set in kubecfg main, but not in any of the tests. Is that change intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a TODO for @derekwaynecarr to add his defaults and transports in his follow on