mirror of https://github.com/kubernetes/kops.git
Accept relative URLs in addon channels
This commit is contained in:
parent
d4e659811b
commit
f339d272d9
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/kops/channels/pkg/channels"
|
"k8s.io/kops/channels/pkg/channels"
|
||||||
"k8s.io/kops/util/pkg/tables"
|
"k8s.io/kops/util/pkg/tables"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -37,9 +38,25 @@ func (c *ApplyChannelCmd) Run(args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error getting current directory: %v", err)
|
||||||
|
}
|
||||||
|
baseURL, err := url.Parse(cwd + string(os.PathSeparator))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error building url for current directory %q: %v", cwd, err)
|
||||||
|
}
|
||||||
|
|
||||||
var addons []*channels.Addon
|
var addons []*channels.Addon
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
o, err := channels.LoadAddons(arg)
|
channel, err := url.Parse(arg)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to parse argument %q as url", arg)
|
||||||
|
}
|
||||||
|
if !channel.IsAbs() {
|
||||||
|
channel = baseURL.ResolveReference(channel)
|
||||||
|
}
|
||||||
|
o, err := channels.LoadAddons(channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error loading file %q: %v", arg, err)
|
return fmt.Errorf("error loading file %q: %v", arg, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,12 @@ import (
|
||||||
"k8s.io/kops/channels/pkg/api"
|
"k8s.io/kops/channels/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/client/clientset_generated/release_1_3"
|
"k8s.io/kubernetes/pkg/client/clientset_generated/release_1_3"
|
||||||
"k8s.io/kubernetes/pkg/util/validation/field"
|
"k8s.io/kubernetes/pkg/util/validation/field"
|
||||||
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Addon struct {
|
type Addon struct {
|
||||||
Name string
|
Name string
|
||||||
Channel string
|
Channel url.URL
|
||||||
Spec *api.AddonSpec
|
Spec *api.AddonSpec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,8 +22,9 @@ type AddonUpdate struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Addon) ChannelVersion() *ChannelVersion {
|
func (a *Addon) ChannelVersion() *ChannelVersion {
|
||||||
|
channel := a.Channel.String()
|
||||||
return &ChannelVersion{
|
return &ChannelVersion{
|
||||||
Channel: &a.Channel,
|
Channel: &channel,
|
||||||
Version: a.Spec.Version,
|
Version: a.Spec.Version,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,9 +76,16 @@ func (a *Addon) EnsureUpdated(k8sClient *release_1_3.Clientset) (*AddonUpdate, e
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest := *a.Spec.Manifest
|
manifest := *a.Spec.Manifest
|
||||||
glog.Infof("Applying update from %q", manifest)
|
manifestURL, err := url.Parse(manifest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, field.Invalid(field.NewPath("Spec", "Manifest"), manifest, "Not a valid URL")
|
||||||
|
}
|
||||||
|
if !manifestURL.IsAbs() {
|
||||||
|
manifestURL = a.Channel.ResolveReference(manifestURL)
|
||||||
|
}
|
||||||
|
glog.Infof("Applying update from %q", manifestURL)
|
||||||
|
|
||||||
err = Apply(manifest)
|
err = Apply(manifestURL.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error applying update from %q: %v", manifest, err)
|
return nil, fmt.Errorf("error applying update from %q: %v", manifest, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,16 +5,17 @@ import (
|
||||||
"k8s.io/kops/channels/pkg/api"
|
"k8s.io/kops/channels/pkg/api"
|
||||||
"k8s.io/kops/upup/pkg/fi/utils"
|
"k8s.io/kops/upup/pkg/fi/utils"
|
||||||
"k8s.io/kops/util/pkg/vfs"
|
"k8s.io/kops/util/pkg/vfs"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Addons struct {
|
type Addons struct {
|
||||||
Channel string
|
Channel url.URL
|
||||||
APIObject *api.Addons
|
APIObject *api.Addons
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadAddons(location string) (*Addons, error) {
|
func LoadAddons(location *url.URL) (*Addons, error) {
|
||||||
data, err := vfs.Context.ReadFile(location)
|
data, err := vfs.Context.ReadFile(location.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error reading addons from %q: %v", location, err)
|
return nil, fmt.Errorf("error reading addons from %q: %v", location, err)
|
||||||
}
|
}
|
||||||
|
@ -31,7 +32,7 @@ func LoadAddons(location string) (*Addons, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Addons{Channel: location, APIObject: apiObject}, nil
|
return &Addons{Channel: *location, APIObject: apiObject}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Addons) GetCurrent() ([]*Addon, error) {
|
func (a *Addons) GetCurrent() ([]*Addon, error) {
|
||||||
|
@ -42,7 +43,11 @@ func (a *Addons) GetCurrent() ([]*Addon, error) {
|
||||||
name = *s.Name
|
name = *s.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
addon := &Addon{Channel: a.Channel, Spec: s, Name: name}
|
addon := &Addon{
|
||||||
|
Channel: a.Channel,
|
||||||
|
Spec: s,
|
||||||
|
Name: name,
|
||||||
|
}
|
||||||
existing := specs[name]
|
existing := specs[name]
|
||||||
if existing == nil || addon.ChannelVersion().Replaces(existing.ChannelVersion()) {
|
if existing == nil || addon.ChannelVersion().Replaces(existing.ChannelVersion()) {
|
||||||
specs[name] = addon
|
specs[name] = addon
|
||||||
|
|
Loading…
Reference in New Issue