mirror of https://github.com/kubernetes/kops.git
Merge pull request #522 from justinsb/channels_default_to_localhost
channels: default to localhost if cluster config not found
This commit is contained in:
commit
0884e474f1
|
@ -4,6 +4,7 @@ import (
|
|||
goflag "flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/release_1_3"
|
||||
|
@ -63,14 +64,23 @@ func (c *RootCmd) AddCommand(cmd *cobra.Command) {
|
|||
}
|
||||
|
||||
func (c *RootCmd) KubernetesClient() (*release_1_3.Clientset, error) {
|
||||
config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
||||
config := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
||||
clientcmd.NewDefaultClientConfigLoadingRules(),
|
||||
&clientcmd.ConfigOverrides{}).ClientConfig()
|
||||
&clientcmd.ConfigOverrides{})
|
||||
clientConfig, err := config.ClientConfig()
|
||||
if err != nil {
|
||||
if clientcmd.IsEmptyConfig(err) {
|
||||
glog.V(2).Infof("No client config found; will use default config")
|
||||
clientConfig, err = clientcmd.DefaultClientConfig.ClientConfig()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot build default kube config settings: %v", err)
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("cannot load kubecfg settings: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
k8sClient, err := release_1_3.NewForConfig(config)
|
||||
k8sClient, err := release_1_3.NewForConfig(clientConfig)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot build kube client: %v", err)
|
||||
}
|
||||
|
|
|
@ -20,6 +20,10 @@ func LoadAddons(location *url.URL) (*Addons, error) {
|
|||
return nil, fmt.Errorf("error reading addons from %q: %v", location, err)
|
||||
}
|
||||
|
||||
return ParseAddons(location, data)
|
||||
}
|
||||
|
||||
func ParseAddons(location *url.URL, data []byte) (*Addons, error) {
|
||||
// Yaml can't parse empty strings
|
||||
configString := string(data)
|
||||
configString = strings.TrimSpace(configString)
|
||||
|
@ -36,18 +40,13 @@ func LoadAddons(location *url.URL) (*Addons, error) {
|
|||
}
|
||||
|
||||
func (a *Addons) GetCurrent() ([]*Addon, error) {
|
||||
all, err := a.All()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
specs := make(map[string]*Addon)
|
||||
for _, s := range a.APIObject.Spec.Addons {
|
||||
name := a.APIObject.Name
|
||||
if s.Name != nil {
|
||||
name = *s.Name
|
||||
}
|
||||
|
||||
addon := &Addon{
|
||||
Channel: a.Channel,
|
||||
Spec: s,
|
||||
Name: name,
|
||||
}
|
||||
for _, addon := range all {
|
||||
name := addon.Name
|
||||
existing := specs[name]
|
||||
if existing == nil || addon.ChannelVersion().Replaces(existing.ChannelVersion()) {
|
||||
specs[name] = addon
|
||||
|
@ -60,3 +59,22 @@ func (a *Addons) GetCurrent() ([]*Addon, error) {
|
|||
}
|
||||
return addons, nil
|
||||
}
|
||||
|
||||
func (a *Addons) All() ([]*Addon, error) {
|
||||
var addons []*Addon
|
||||
for _, s := range a.APIObject.Spec.Addons {
|
||||
name := a.APIObject.Name
|
||||
if s.Name != nil {
|
||||
name = *s.Name
|
||||
}
|
||||
|
||||
addon := &Addon{
|
||||
Channel: a.Channel,
|
||||
Spec: s,
|
||||
Name: name,
|
||||
}
|
||||
|
||||
addons = append(addons, addon)
|
||||
}
|
||||
return addons, nil
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func execKubectl(args ...string) (string, error) {
|
|||
glog.V(2).Infof("Running command: %s", human)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
glog.Infof("error running %s:", human)
|
||||
glog.Infof("error running %s", human)
|
||||
glog.Info(string(output))
|
||||
return string(output), fmt.Errorf("error running kubectl")
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ package channels
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/blang/semver"
|
||||
"github.com/golang/glog"
|
||||
"github.com/kopeio/route-controller/_vendor/github.com/blang/semver"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/release_1_3"
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"k8s.io/kops/upup/pkg/api"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup"
|
||||
"k8s.io/kops/util/pkg/tables"
|
||||
"k8s.io/kops/util/pkg/vfs"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue