Remove nodeup templating

As it is now unused
This commit is contained in:
Justin Santa Barbara 2017-11-25 16:55:50 -05:00
parent db09337e42
commit 6cedbbf456
3 changed files with 30 additions and 158 deletions

View File

@ -28,21 +28,19 @@ When defining a new function:
package cloudup package cloudup
import ( import (
"encoding/base64"
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
"strings" "strings"
"text/template" "text/template"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kops/pkg/apis/kops" "k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/dns" "k8s.io/kops/pkg/dns"
"k8s.io/kops/pkg/model" "k8s.io/kops/pkg/model"
"k8s.io/kops/upup/pkg/fi" "k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/gce" "k8s.io/kops/upup/pkg/fi/cloudup/gce"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/sets"
) )
type TemplateFunctions struct { type TemplateFunctions struct {
@ -64,9 +62,6 @@ func (tf *TemplateFunctions) AddTo(dest template.FuncMap) {
// Remember that we may be on a different arch from the target. Hard-code for now. // Remember that we may be on a different arch from the target. Hard-code for now.
dest["Arch"] = func() string { return "amd64" } dest["Arch"] = func() string { return "amd64" }
dest["Base64Encode"] = func(s string) string {
return base64.StdEncoding.EncodeToString([]byte(s))
}
dest["replace"] = func(s, find, replace string) string { dest["replace"] = func(s, find, replace string) string {
return strings.Replace(s, find, replace, -1) return strings.Replace(s, find, replace, -1)
} }

View File

@ -37,6 +37,7 @@ import (
"k8s.io/kops/upup/pkg/fi/nodeup/cloudinit" "k8s.io/kops/upup/pkg/fi/nodeup/cloudinit"
"k8s.io/kops/upup/pkg/fi/nodeup/local" "k8s.io/kops/upup/pkg/fi/nodeup/local"
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks" "k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
"k8s.io/kops/upup/pkg/fi/secrets"
"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"
) )
@ -44,6 +45,8 @@ import (
// MaxTaskDuration is the amount of time to keep trying for; we retry for a long time - there is not really any great fallback // MaxTaskDuration is the amount of time to keep trying for; we retry for a long time - there is not really any great fallback
const MaxTaskDuration = 365 * 24 * time.Hour const MaxTaskDuration = 365 * 24 * time.Hour
const TagMaster = "_kubernetes_master"
// NodeUpCommand the configiruation for nodeup // NodeUpCommand the configiruation for nodeup
type NodeUpCommand struct { type NodeUpCommand struct {
CacheDir string CacheDir string
@ -171,11 +174,6 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
glog.Infof("Config tags: %v", c.config.Tags) glog.Infof("Config tags: %v", c.config.Tags)
glog.Infof("OS tags: %v", osTags) glog.Infof("OS tags: %v", osTags)
tf, err := newTemplateFunctions(c.config, c.cluster, c.instanceGroup, nodeTags)
if err != nil {
return fmt.Errorf("error initializing: %v", err)
}
modelContext := &model.NodeupModelContext{ modelContext := &model.NodeupModelContext{
Architecture: model.ArchitectureAmd64, Architecture: model.ArchitectureAmd64,
Assets: assetStore, Assets: assetStore,
@ -183,10 +181,33 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
Distribution: distribution, Distribution: distribution,
InstanceGroup: c.instanceGroup, InstanceGroup: c.instanceGroup,
IsMaster: nodeTags.Has(TagMaster), IsMaster: nodeTags.Has(TagMaster),
KeyStore: tf.keyStore,
NodeupConfig: c.config, NodeupConfig: c.config,
SecretStore: tf.secretStore,
} }
if c.cluster.Spec.SecretStore != "" {
glog.Infof("Building SecretStore at %q", c.cluster.Spec.SecretStore)
p, err := vfs.Context.BuildVfsPath(c.cluster.Spec.SecretStore)
if err != nil {
return fmt.Errorf("error building secret store path: %v", err)
}
modelContext.SecretStore = secrets.NewVFSSecretStore(c.cluster, p)
} else {
return fmt.Errorf("SecretStore not set")
}
if c.cluster.Spec.KeyStore != "" {
glog.Infof("Building KeyStore at %q", c.cluster.Spec.KeyStore)
p, err := vfs.Context.BuildVfsPath(c.cluster.Spec.KeyStore)
if err != nil {
return fmt.Errorf("error building key store path: %v", err)
}
modelContext.KeyStore = fi.NewVFSCAStore(c.cluster, p)
} else {
return fmt.Errorf("KeyStore not set")
}
if err := modelContext.Init(); err != nil { if err := modelContext.Init(); err != nil {
return err return err
} }
@ -216,8 +237,6 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
loader.Builders = append(loader.Builders, &model.KubeRouterBuilder{NodeupModelContext: modelContext}) loader.Builders = append(loader.Builders, &model.KubeRouterBuilder{NodeupModelContext: modelContext})
} }
tf.populate(loader.TemplateFunctions)
taskMap, err := loader.Build(c.ModelDir) taskMap, err := loader.Build(c.ModelDir)
if err != nil { if err != nil {
return fmt.Errorf("error building loader: %v", err) return fmt.Errorf("error building loader: %v", err)

View File

@ -1,142 +0,0 @@
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package nodeup
import (
"encoding/base64"
"fmt"
"runtime"
"text/template"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/sets"
api "k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/apis/nodeup"
"k8s.io/kops/pkg/flagbuilder"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/secrets"
"k8s.io/kops/util/pkg/vfs"
)
const TagMaster = "_kubernetes_master"
// templateFunctions is a simple helper-class for the functions accessible to templates
type templateFunctions struct {
nodeupConfig *nodeup.Config
// cluster is populated with the current cluster
cluster *api.Cluster
// instanceGroup is populated with this node's instance group
instanceGroup *api.InstanceGroup
// keyStore is populated with a KeyStore, if KeyStore is set
keyStore fi.CAStore
// secretStore is populated with a SecretStore, if SecretStore is set
secretStore fi.SecretStore
tags sets.String
}
// newTemplateFunctions is the constructor for templateFunctions
func newTemplateFunctions(nodeupConfig *nodeup.Config, cluster *api.Cluster, instanceGroup *api.InstanceGroup, tags sets.String) (*templateFunctions, error) {
t := &templateFunctions{
nodeupConfig: nodeupConfig,
cluster: cluster,
instanceGroup: instanceGroup,
tags: tags,
}
if cluster.Spec.SecretStore != "" {
glog.Infof("Building SecretStore at %q", cluster.Spec.SecretStore)
p, err := vfs.Context.BuildVfsPath(cluster.Spec.SecretStore)
if err != nil {
return nil, fmt.Errorf("error building secret store path: %v", err)
}
t.secretStore = secrets.NewVFSSecretStore(cluster, p)
} else {
return nil, fmt.Errorf("SecretStore not set")
}
if cluster.Spec.KeyStore != "" {
glog.Infof("Building KeyStore at %q", cluster.Spec.KeyStore)
p, err := vfs.Context.BuildVfsPath(cluster.Spec.KeyStore)
if err != nil {
return nil, fmt.Errorf("error building key store path: %v", err)
}
t.keyStore = fi.NewVFSCAStore(cluster, p)
} else {
return nil, fmt.Errorf("KeyStore not set")
}
return t, nil
}
func (t *templateFunctions) populate(dest template.FuncMap) {
dest["Arch"] = func() string {
return runtime.GOARCH
}
dest["GetToken"] = t.GetToken
dest["BuildFlags"] = flagbuilder.BuildFlags
dest["Base64Encode"] = func(s string) string {
return base64.StdEncoding.EncodeToString([]byte(s))
}
// TODO: We may want to move these to a nodeset / masterset specific thing
dest["KubeDNS"] = func() *api.KubeDNSConfig {
return t.cluster.Spec.KubeDNS
}
dest["KubeScheduler"] = func() *api.KubeSchedulerConfig {
return t.cluster.Spec.KubeScheduler
}
dest["KubeAPIServer"] = func() *api.KubeAPIServerConfig {
return t.cluster.Spec.KubeAPIServer
}
dest["KubeControllerManager"] = func() *api.KubeControllerManagerConfig {
return t.cluster.Spec.KubeControllerManager
}
dest["ClusterName"] = func() string {
return t.cluster.ObjectMeta.Name
}
}
// GetToken returns the specified token
func (t *templateFunctions) GetToken(key string) (string, error) {
token, err := t.secretStore.FindSecret(key)
if err != nil {
return "", err
}
if token == nil {
return "", fmt.Errorf("token not found: %q", key)
}
return string(token.Data), nil
}
// IsMaster returns true if we are tagged as a master
func (t *templateFunctions) isMaster() bool {
return t.hasTag(TagMaster)
}
// Tag returns true if we are tagged with the specified tag
func (t *templateFunctions) hasTag(tag string) bool {
_, found := t.tags[tag]
return found
}