Skip to content

Commit

Permalink
setting up etcd to use asset builder for its container
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislovecnm committed Oct 17, 2017
1 parent b4c4afb commit c8eea0d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions nodeup/pkg/model/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ go_library(
"//pkg/apis/kops:go_default_library",
"//pkg/apis/kops/util:go_default_library",
"//pkg/apis/nodeup:go_default_library",
"//pkg/assets:go_default_library",
"//pkg/dns:go_default_library",
"//pkg/flagbuilder:go_default_library",
"//pkg/k8scodecs:go_default_library",
Expand Down
15 changes: 14 additions & 1 deletion nodeup/pkg/model/protokube.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

"github.com/blang/semver"
"github.com/golang/glog"
"k8s.io/kops/pkg/assets"
)

// ProtokubeBuilder configures protokube
Expand Down Expand Up @@ -219,11 +220,23 @@ func (t *ProtokubeBuilder) ProtokubeFlags(k8sVersion semver.Version) *ProtokubeF
f := &ProtokubeFlags{
Channels: t.NodeupConfig.Channels,
Containerized: fi.Bool(true),
EtcdImage: s(fmt.Sprintf("gcr.io/google_containers/etcd:%s", imageVersion)),
LogLevel: fi.Int32(4),
Master: b(t.IsMaster),
}

// TODO this is dupicate code with etcd model
image := fmt.Sprintf("gcr.io/google_containers/etcd:%s", imageVersion)
assets := assets.NewAssetBuilder(nil)
remapped, err := assets.RemapImage(image)
if err != nil {
glog.Errorf("unable to remap container %q: %v", image, err)
glog.Errorf("using default %s", image)
} else {
image = remapped
}

f.EtcdImage = s(image)

// initialize rbac on Kubernetes >= 1.6 and master
if k8sVersion.Major == 1 && k8sVersion.Minor >= 6 {
f.InitializeRBAC = fi.Bool(true)
Expand Down
20 changes: 20 additions & 0 deletions pkg/model/components/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package components

import (
"fmt"

"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi/loader"
)
Expand All @@ -32,13 +34,31 @@ var _ loader.OptionsBuilder = &EtcdOptionsBuilder{}
func (b *EtcdOptionsBuilder) BuildOptions(o interface{}) error {
spec := o.(*kops.ClusterSpec)

imageVersion := ""
// @check the version are set and if not preset the defaults
for _, x := range spec.EtcdClusters {
// @TODO if nothing is set, set the defaults. At a late date once we have a way of detecting a 'new' cluster
// we can default all clusters to v3
if x.Version == "" {
x.Version = "2.2.1"
}

if imageVersion != "" {
if imageVersion != x.Version {
return fmt.Errorf("you cannot have two different versions of etcd %q and %q set", x.Version, imageVersion)
}
} else {
imageVersion = x.Version
}
}

// TODO we do not have a API place to put this. Do we use version or get another
// TODO API value?
// TODO code is duplicated in nodeup
image := fmt.Sprintf("gcr.io/google_containers/etcd:%s", imageVersion)
image, err := b.Context.AssetBuilder.RemapImage(image)
if err != nil {
return fmt.Errorf("unable to remap container %q: %v", image, err)
}

return nil
Expand Down

0 comments on commit c8eea0d

Please sign in to comment.