本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/version.Get函數的典型用法代碼示例。如果您正苦於以下問題:Golang Get函數的具體用法?Golang Get怎麽用?Golang Get使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Get函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestVersion
func TestVersion(t *testing.T) {
handler := New(map[string]RESTStorage{}, codec, "/prefix/version")
server := httptest.NewServer(handler)
client := http.Client{}
request, err := http.NewRequest("GET", server.URL+"/version", nil)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
response, err := client.Do(request)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
var info version.Info
err = json.NewDecoder(response.Body).Decode(&info)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if !reflect.DeepEqual(version.Get(), info) {
t.Errorf("Expected %#v, Got %#v", version.Get(), info)
}
}
示例2: PrintAndExitIfRequested
// PrintAndExitIfRequested will check if the -version flag was passed
// and, if so, print the version and exit.
func PrintAndExitIfRequested() {
if *versionFlag == VersionRaw {
fmt.Printf("%#v\n", version.Get())
os.Exit(0)
} else if *versionFlag == VersionTrue {
fmt.Printf("Kubernetes %s\n", version.Get())
os.Exit(0)
}
}
示例3: DefaultKubernetesUserAgent
// DefaultKubernetesUserAgent returns the default user agent that clients can use.
func DefaultKubernetesUserAgent() string {
commit := version.Get().GitCommit
if len(commit) > 7 {
commit = commit[:7]
}
if len(commit) == 0 {
commit = "unknown"
}
version := version.Get().GitVersion
seg := strings.SplitN(version, "-", 2)
version = seg[0]
return fmt.Sprintf("%s/%s (%s/%s) kubernetes/%s", path.Base(os.Args[0]), version, gruntime.GOOS, gruntime.GOARCH, commit)
}
示例4: main
func main() {
openshiftCmd := &cobra.Command{
Use: "openshift",
Short: "OpenShift helps you build, deploy, and manage your applications",
Long: longDescription,
Run: func(c *cobra.Command, args []string) {
c.Help()
},
}
openshiftCmd.AddCommand(master.NewCommandStartAllInOne("start"))
openshiftCmd.AddCommand(client.NewCommandKubecfg("kube"))
openshiftCmd.AddCommand(tour.NewCommandTour("tour"))
// version information
versionCmd := &cobra.Command{
Use: "version",
Short: "Display version",
Run: func(c *cobra.Command, args []string) {
fmt.Printf("openshift %v\n", version.Get())
fmt.Printf("kubernetes %v\n", kubeversion.Get())
},
}
openshiftCmd.AddCommand(versionCmd)
if err := openshiftCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s", err)
os.Exit(1)
}
}
示例5: ServerVersion
func (c *Fake) ServerVersion() (*version.Info, error) {
c.Lock.Lock()
defer c.Lock.Unlock()
c.Actions = append(c.Actions, FakeAction{Action: "get-version", Value: nil})
versionInfo := version.Get()
return &versionInfo, nil
}
示例6: ServerVersion
func (c *Fake) ServerVersion() (*version.Info, error) {
action := ActionImpl{}
action.Verb = "get"
action.Resource = "version"
c.Invokes(action, nil)
versionInfo := version.Get()
return &versionInfo, nil
}
示例7: NewVersionCommand
// NewVersionCommand creates a command for displaying the version of this binary
func NewVersionCommand(basename string) *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Display version",
Run: func(c *cobra.Command, args []string) {
fmt.Printf("%s %v\n", basename, Get())
fmt.Printf("kubernetes %v\n", kubeversion.Get())
},
}
}
示例8: MatchesServerVersion
func MatchesServerVersion(c *Config) error {
client, err := New(c)
if err != nil {
return err
}
clientVersion := version.Get()
serverVersion, err := client.ServerVersion()
if err != nil {
return fmt.Errorf("couldn't read version from server: %v\n", err)
}
if s := *serverVersion; !reflect.DeepEqual(clientVersion, s) {
return fmt.Errorf("server version (%#v) differs from client version (%#v)!\n", s, clientVersion)
}
return nil
}
示例9: GetKubeClient
func GetKubeClient(config *client.Config, matchVersion bool) (*client.Client, error) {
// TODO: get the namespace context when kubectl ns is completed
c, err := client.New(config)
if err != nil {
return nil, err
}
if matchVersion {
clientVersion := version.Get()
serverVersion, err := c.ServerVersion()
if err != nil {
return nil, fmt.Errorf("couldn't read version from server: %v\n", err)
}
if s := *serverVersion; !reflect.DeepEqual(clientVersion, s) {
return nil, fmt.Errorf("server version (%#v) differs from client version (%#v)!\n", s, clientVersion)
}
}
return c, nil
}
示例10: Run
func (c *KubeConfig) Run() {
util.InitLogs()
defer util.FlushLogs()
var masterServer string
if len(c.HttpServer) > 0 {
masterServer = c.HttpServer
} else if len(os.Getenv("KUBERNETES_MASTER")) > 0 {
masterServer = os.Getenv("KUBERNETES_MASTER")
} else {
masterServer = "http://localhost:8080"
}
kubeClient, err := kubeclient.New(masterServer, nil)
if err != nil {
glog.Fatalf("Unable to parse %s as a URL: %v", masterServer, err)
}
client, err := osclient.New(masterServer, nil)
if err != nil {
glog.Fatalf("Unable to parse %s as a URL: %v", masterServer, err)
}
// TODO: this won't work if TLS is enabled with client cert auth, but no
// passwords are required. Refactor when we address client auth abstraction.
if kubeClient.Secure() {
auth, err := kubecfg.LoadAuthInfo(c.AuthConfig, os.Stdin)
if err != nil {
glog.Fatalf("Error loading auth: %v", err)
}
kubeClient, err = kubeclient.New(masterServer, auth)
if err != nil {
glog.Fatalf("Unable to parse %s as a URL: %v", masterServer, err)
}
client, err = osclient.New(masterServer, auth)
if err != nil {
glog.Fatalf("Unable to parse %s as a URL: %v", masterServer, err)
}
}
// check the kubernetes server version
if c.ServerVersion {
got, err := kubeClient.ServerVersion()
if err != nil {
fmt.Printf("Couldn't read version from server: %v\n", err)
os.Exit(1)
}
fmt.Printf("Server Version: %#v\n", got)
os.Exit(0)
}
if c.PreventSkew {
got, err := kubeClient.ServerVersion()
if err != nil {
fmt.Printf("Couldn't read version from server: %v\n", err)
os.Exit(1)
}
if c, s := version.Get(), *got; !reflect.DeepEqual(c, s) {
fmt.Printf("Server version (%#v) differs from client version (%#v)!\n", s, c)
os.Exit(1)
}
}
if c.Proxy {
glog.Info("Starting to serve on localhost:8001")
server := kubecfg.NewProxyServer(c.WWW, kubeClient)
glog.Fatal(server.Serve())
}
method := c.Arg(0)
clients := map[string]RESTClient{
"minions": kubeClient.RESTClient,
"pods": kubeClient.RESTClient,
"services": kubeClient.RESTClient,
"replicationControllers": kubeClient.RESTClient,
"builds": client.RESTClient,
"buildConfigs": client.RESTClient,
"images": client.RESTClient,
"imageRepositories": client.RESTClient,
"imageRepositoryMappings": client.RESTClient,
}
matchFound := c.executeAPIRequest(method, clients) || c.executeControllerRequest(method, kubeClient)
if matchFound == false {
glog.Fatalf("Unknown command %s", method)
}
}
示例11: PrintAndExitIfRequested
// PrintAndExitIfRequested will check if the -version flag was passed
// and, if so, print the version and exit.
func PrintAndExitIfRequested() {
if *versionFlag {
fmt.Printf("Kubernetes %s\n", version.Get())
os.Exit(0)
}
}
示例12: main
func main() {
flag.Usage = func() {
usage()
}
flag.Parse()
util.InitLogs()
defer util.FlushLogs()
verflag.PrintAndExitIfRequested()
secure := true
var masterServer string
if len(*httpServer) > 0 {
masterServer = *httpServer
} else if len(os.Getenv("KUBERNETES_MASTER")) > 0 {
masterServer = os.Getenv("KUBERNETES_MASTER")
} else {
masterServer = "http://localhost:8080"
}
parsedURL, err := url.Parse(masterServer)
if err != nil {
glog.Fatalf("Unable to parse %v as a URL\n", err)
}
if parsedURL.Scheme != "" && parsedURL.Scheme != "https" {
secure = false
}
var auth *kube_client.AuthInfo
if secure {
auth, err = kubecfg.LoadAuthInfo(*authConfig, os.Stdin)
if err != nil {
glog.Fatalf("Error loading auth: %v", err)
}
}
client := kube_client.New(masterServer, auth)
if *serverVersion {
got, err := client.ServerVersion()
if err != nil {
fmt.Printf("Couldn't read version from server: %v\n", err)
os.Exit(1)
}
fmt.Printf("Server Version: %#v\n", got)
os.Exit(0)
}
if *preventSkew {
got, err := client.ServerVersion()
if err != nil {
fmt.Printf("Couldn't read version from server: %v\n", err)
os.Exit(1)
}
if c, s := version.Get(), *got; !reflect.DeepEqual(c, s) {
fmt.Printf("Server version (%#v) differs from client version (%#v)!\n", s, c)
os.Exit(1)
}
}
if *proxy {
glog.Info("Starting to serve on localhost:8001")
server := kubecfg.NewProxyServer(*www, masterServer, auth)
glog.Fatal(server.Serve())
}
if len(flag.Args()) < 1 {
usage()
os.Exit(1)
}
method := flag.Arg(0)
matchFound := executeAPIRequest(method, client) || executeControllerRequest(method, client)
if matchFound == false {
glog.Fatalf("Unknown command %s", method)
}
}
示例13: handleVersion
// handleVersionReq writes the server's version information.
func handleVersion(w http.ResponseWriter, req *http.Request) {
writeRawJSON(http.StatusOK, version.Get(), w)
}
示例14: TestClient
func TestClient(t *testing.T) {
m := master.New(&master.Config{
EtcdServers: newEtcdClient().GetCluster(),
})
storage, codec := m.API_v1beta1()
s := httptest.NewServer(apiserver.Handle(storage, codec, "/api/v1beta1/"))
client := client.NewOrDie(s.URL, nil)
info, err := client.ServerVersion()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if e, a := version.Get(), *info; !reflect.DeepEqual(e, a) {
t.Errorf("expected %#v, got %#v", e, a)
}
pods, err := client.ListPods(labels.Everything())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(pods.Items) != 0 {
t.Errorf("expected no pods, got %#v", pods)
}
// get a validation error
pod := &api.Pod{
DesiredState: api.PodState{
Manifest: api.ContainerManifest{
Version: "v1beta2",
Containers: []api.Container{
{
Name: "test",
},
},
},
},
}
got, err := client.CreatePod(pod)
if err == nil {
t.Fatalf("unexpected non-error: %v", err)
}
// get a created pod
pod.DesiredState.Manifest.Containers[0].Image = "an-image"
got, err = client.CreatePod(pod)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got.ID == "" {
t.Errorf("unexpected empty pod ID %v", got)
}
// pod is shown, but not scheduled
pods, err = client.ListPods(labels.Everything())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(pods.Items) != 1 {
t.Errorf("expected one pod, got %#v", pods)
}
actual := pods.Items[0]
if actual.ID != got.ID {
t.Errorf("expected pod %#v, got %#v", got, actual)
}
if actual.CurrentState.Host != "" {
t.Errorf("expected pod to be unscheduled, got %#v", actual)
}
}
示例15: handleVersion
// handleVersion writes the server's version information.
func handleVersion(req *restful.Request, resp *restful.Response) {
// TODO: use restful's Response methods
writeRawJSON(http.StatusOK, version.Get(), resp.ResponseWriter)
}