mirror of https://github.com/kubernetes/kops.git
Fix various nits when changing Protokube to run as service
This commit is contained in:
parent
1d721c3ff8
commit
77b72efe1d
|
@ -232,7 +232,7 @@ run it over SSH with the output viewable locally:
|
|||
For more complete testing though, you will likely want to do a private build of
|
||||
nodeup and launch a cluster from scratch.
|
||||
|
||||
To do this, you can repoint the nodeup source url by setting the `NODEUP_URL` env var,
|
||||
To do this, you can repoint the nodeup source url by setting the `KOPS_BASE_URL` env var,
|
||||
and then push nodeup using:
|
||||
|
||||
|
||||
|
|
|
@ -57,32 +57,34 @@ func (t *ProtokubeBuilder) Build(c *fi.ModelBuilderContext) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
protokubeBinName, protokubeBinRes, err := t.Assets.FindMatch(regexp.MustCompile("protokube$"))
|
||||
if err != nil {
|
||||
return err
|
||||
{
|
||||
name, res, err := t.Assets.FindMatch(regexp.MustCompile("protokube$"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.AddTask(&nodetasks.File{
|
||||
Path: filepath.Join("/opt/kops/bin", name),
|
||||
Contents: res,
|
||||
Type: nodetasks.FileType_File,
|
||||
Mode: fi.String("0755"),
|
||||
})
|
||||
}
|
||||
|
||||
fileTaskProtokubeBin := &nodetasks.File{
|
||||
Path: filepath.Join("/opt/kops/bin", protokubeBinName),
|
||||
Contents: protokubeBinRes,
|
||||
Type: nodetasks.FileType_File,
|
||||
Mode: fi.String("0755"),
|
||||
}
|
||||
c.AddTask(fileTaskProtokubeBin)
|
||||
{
|
||||
name, res, err := t.Assets.FindMatch(regexp.MustCompile("channels$"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
channelBinName, channelBinRes, err := t.Assets.FindMatch(regexp.MustCompile("channels$"))
|
||||
if err != nil {
|
||||
return err
|
||||
c.AddTask(&nodetasks.File{
|
||||
Path: filepath.Join("/opt/kops/bin", name),
|
||||
Contents: res,
|
||||
Type: nodetasks.FileType_File,
|
||||
Mode: fi.String("0755"),
|
||||
})
|
||||
}
|
||||
|
||||
fileTaskChannel := &nodetasks.File{
|
||||
Path: filepath.Join("/opt/kops/bin", channelBinName),
|
||||
Contents: channelBinRes,
|
||||
Type: nodetasks.FileType_File,
|
||||
Mode: fi.String("0755"),
|
||||
}
|
||||
c.AddTask(fileTaskChannel)
|
||||
|
||||
if t.IsMaster {
|
||||
name := nodetasks.PKIXName{
|
||||
CommonName: "kops",
|
||||
|
@ -112,11 +114,11 @@ func (t *ProtokubeBuilder) Build(c *fi.ModelBuilderContext) error {
|
|||
}
|
||||
}
|
||||
|
||||
envFileTask, err := t.buildProtokubeEnvironmentVariables()
|
||||
envFile, err := t.buildEnvFile()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.AddTask(envFileTask)
|
||||
c.AddTask(envFile)
|
||||
|
||||
service, err := t.buildSystemdService()
|
||||
if err != nil {
|
||||
|
@ -400,7 +402,7 @@ func (t *ProtokubeBuilder) ProtokubeFlags(k8sVersion semver.Version) (*Protokube
|
|||
return f, nil
|
||||
}
|
||||
|
||||
func (t *ProtokubeBuilder) buildProtokubeEnvironmentVariables() (*nodetasks.File, error) {
|
||||
func (t *ProtokubeBuilder) buildEnvFile() (*nodetasks.File, error) {
|
||||
var envVars = make(map[string]string)
|
||||
|
||||
envVars["KUBECONFIG"] = "/var/lib/kops/kubeconfig"
|
||||
|
|
|
@ -1227,17 +1227,19 @@ func newNodeUpConfigBuilder(cluster *kops.Cluster, assetBuilder *assets.AssetBui
|
|||
channelsAsset := map[architectures.Architecture][]*mirrors.MirroredAsset{}
|
||||
|
||||
for _, arch := range architectures.GetSupported() {
|
||||
protokubeBinAsset, err := ProtokubeBinaryAsset(assetBuilder, arch)
|
||||
asset, err := ProtokubeAsset(assetBuilder, arch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
protokubeAsset[arch] = append(protokubeAsset[arch], protokubeBinAsset)
|
||||
protokubeAsset[arch] = append(protokubeAsset[arch], asset)
|
||||
}
|
||||
|
||||
channelsBinAsset, err := ChannelsBinaryAsset(assetBuilder, arch)
|
||||
for _, arch := range architectures.GetSupported() {
|
||||
asset, err := ChannelsAsset(assetBuilder, arch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
channelsAsset[arch] = append(channelsAsset[arch], channelsBinAsset)
|
||||
channelsAsset[arch] = append(channelsAsset[arch], asset)
|
||||
}
|
||||
|
||||
for _, role := range kops.AllInstanceGroupRoles {
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/kops"
|
||||
|
@ -37,14 +36,14 @@ const (
|
|||
|
||||
var kopsBaseURL *url.URL
|
||||
|
||||
// nodeUpAsset caches the nodeup download urls/hash
|
||||
// nodeUpAsset caches the nodeup binary download url/hash
|
||||
var nodeUpAsset map[architectures.Architecture]*mirrors.MirroredAsset
|
||||
|
||||
// protokubeBinAsset caches the protokube binary download urls/hash
|
||||
var protokubeBinAsset map[architectures.Architecture]*mirrors.MirroredAsset
|
||||
// protokubeAsset caches the protokube binary download url/hash
|
||||
var protokubeAsset map[architectures.Architecture]*mirrors.MirroredAsset
|
||||
|
||||
// channelsBinAsset caches the channels binary download urls/hash
|
||||
var channelsBinAsset map[architectures.Architecture]*mirrors.MirroredAsset
|
||||
// channelsAsset caches the channels binary download url/hash
|
||||
var channelsAsset map[architectures.Architecture]*mirrors.MirroredAsset
|
||||
|
||||
// BaseURL returns the base url for the distribution of kops - in particular for nodeup & docker images
|
||||
func BaseURL() (*url.URL, error) {
|
||||
|
@ -108,86 +107,55 @@ func NodeUpAsset(assetsBuilder *assets.AssetBuilder, arch architectures.Architec
|
|||
klog.V(8).Infof("Using cached nodeup location for %s: %v", arch, nodeUpAsset[arch].Locations)
|
||||
return nodeUpAsset[arch], nil
|
||||
}
|
||||
// Use multi-arch env var, but fall back to well known env var
|
||||
env := os.Getenv(fmt.Sprintf("NODEUP_URL_%s", strings.ToUpper(string(arch))))
|
||||
if env == "" {
|
||||
env = os.Getenv("NODEUP_URL")
|
||||
|
||||
u, hash, err := KopsFileURL(fmt.Sprintf("linux/%s/nodeup", arch), assetsBuilder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var err error
|
||||
var u *url.URL
|
||||
var hash *hashing.Hash
|
||||
if env == "" {
|
||||
u, hash, err = KopsFileURL(fmt.Sprintf("linux/%s/nodeup", arch), assetsBuilder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
klog.V(8).Infof("Using default nodeup location for %s: %q", arch, u.String())
|
||||
} else {
|
||||
u, err = url.Parse(env)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse env var NODEUP_URL(_%s) %q as a url: %v", strings.ToUpper(string(arch)), env, err)
|
||||
}
|
||||
nodeUpAsset[arch] = mirrors.BuildMirroredAsset(u, hash)
|
||||
klog.V(8).Infof("Using default nodeup location for %s: %q", arch, u.String())
|
||||
|
||||
u, hash, err = assetsBuilder.RemapFileAndSHA(u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
klog.Warningf("Using nodeup location from NODEUP_URL(_%s) env var: %q", strings.ToUpper(string(arch)), u.String())
|
||||
}
|
||||
|
||||
asset := mirrors.BuildMirroredAsset(u, hash)
|
||||
|
||||
nodeUpAsset[arch] = asset
|
||||
|
||||
return asset, nil
|
||||
return nodeUpAsset[arch], nil
|
||||
}
|
||||
|
||||
// ProtokubeBinaryAsset returns the url and hash of the protokube binary. This is useful for running protokube as a
|
||||
// systemd process rather than a container.
|
||||
func ProtokubeBinaryAsset(assetsBuilder *assets.AssetBuilder, arch architectures.Architecture) (*mirrors.MirroredAsset, error) {
|
||||
if protokubeBinAsset == nil {
|
||||
protokubeBinAsset = make(map[architectures.Architecture]*mirrors.MirroredAsset)
|
||||
// ProtokubeAsset returns the url and hash of the protokube binary
|
||||
func ProtokubeAsset(assetsBuilder *assets.AssetBuilder, arch architectures.Architecture) (*mirrors.MirroredAsset, error) {
|
||||
if protokubeAsset == nil {
|
||||
protokubeAsset = make(map[architectures.Architecture]*mirrors.MirroredAsset)
|
||||
}
|
||||
if protokubeAsset[arch] != nil {
|
||||
klog.V(8).Infof("Using cached protokube binary location for %s: %v", arch, protokubeAsset[arch].Locations)
|
||||
return protokubeAsset[arch], nil
|
||||
}
|
||||
|
||||
if protokubeBinAsset[arch] != nil {
|
||||
klog.V(8).Infof("Using cached protokube binary location for %s: %v", arch, protokubeBinAsset[arch].Locations)
|
||||
return protokubeBinAsset[arch], nil
|
||||
}
|
||||
|
||||
// TODO: (bharath-123) should we allow the user to specify the binary url through an environment variable like how we do for NODEUP_URL?
|
||||
u, hash, err := KopsFileURL(fmt.Sprintf("linux/%s/protokube", arch), assetsBuilder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
protokubeAsset[arch] = mirrors.BuildMirroredAsset(u, hash)
|
||||
klog.V(8).Infof("Using default protokube location for %s: %q", arch, u.String())
|
||||
|
||||
asset := mirrors.BuildMirroredAsset(u, hash)
|
||||
|
||||
protokubeBinAsset[arch] = asset
|
||||
|
||||
return asset, nil
|
||||
return protokubeAsset[arch], nil
|
||||
}
|
||||
|
||||
// ChannelsBinaryAsset returns the url and hash of the channels binary. Protokube requires this to run as a systemd process.
|
||||
func ChannelsBinaryAsset(assetsBuilder *assets.AssetBuilder, arch architectures.Architecture) (*mirrors.MirroredAsset, error) {
|
||||
if channelsBinAsset == nil {
|
||||
channelsBinAsset = make(map[architectures.Architecture]*mirrors.MirroredAsset)
|
||||
// ChannelsAsset returns the url and hash of the channels binary
|
||||
func ChannelsAsset(assetsBuilder *assets.AssetBuilder, arch architectures.Architecture) (*mirrors.MirroredAsset, error) {
|
||||
if channelsAsset == nil {
|
||||
channelsAsset = make(map[architectures.Architecture]*mirrors.MirroredAsset)
|
||||
}
|
||||
|
||||
if channelsBinAsset[arch] != nil {
|
||||
klog.V(8).Infof("Using cached channels binary location for %s: %v", arch, channelsBinAsset[arch].Locations)
|
||||
return channelsBinAsset[arch], nil
|
||||
if channelsAsset[arch] != nil {
|
||||
klog.V(8).Infof("Using cached channels binary location for %s: %v", arch, channelsAsset[arch].Locations)
|
||||
return channelsAsset[arch], nil
|
||||
}
|
||||
|
||||
u, hash, err := KopsFileURL(fmt.Sprintf("linux/%s/channels", arch), assetsBuilder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
channelsAsset[arch] = mirrors.BuildMirroredAsset(u, hash)
|
||||
klog.V(8).Infof("Using default channels location for %s: %q", arch, u.String())
|
||||
|
||||
asset := mirrors.BuildMirroredAsset(u, hash)
|
||||
|
||||
channelsBinAsset[arch] = asset
|
||||
|
||||
return asset, nil
|
||||
return channelsAsset[arch], nil
|
||||
}
|
||||
|
||||
// KopsFileURL returns the base url for the distribution of kops - in particular for nodeup & docker images
|
||||
|
|
Loading…
Reference in New Issue