mirror of https://github.com/kubernetes/kops.git
Switch to use sets.String
This commit is contained in:
parent
6c66d18a9c
commit
a3fa83ac34
|
@ -27,6 +27,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/loader"
|
"k8s.io/kops/upup/pkg/fi/loader"
|
||||||
"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"
|
||||||
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -45,7 +46,7 @@ type Loader struct {
|
||||||
|
|
||||||
ModelStore vfs.Path
|
ModelStore vfs.Path
|
||||||
|
|
||||||
Tags map[string]struct{}
|
Tags sets.String
|
||||||
TemplateFunctions template.FuncMap
|
TemplateFunctions template.FuncMap
|
||||||
|
|
||||||
typeMap map[string]reflect.Type
|
typeMap map[string]reflect.Type
|
||||||
|
|
|
@ -23,12 +23,13 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/loader"
|
"k8s.io/kops/upup/pkg/fi/loader"
|
||||||
"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"
|
||||||
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SpecBuilder struct {
|
type SpecBuilder struct {
|
||||||
OptionsLoader *loader.OptionsLoader
|
OptionsLoader *loader.OptionsLoader
|
||||||
|
|
||||||
Tags map[string]struct{}
|
Tags sets.String
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *SpecBuilder) BuildCompleteSpec(clusterSpec *api.ClusterSpec, modelStore vfs.Path, models []string) (*api.ClusterSpec, error) {
|
func (l *SpecBuilder) BuildCompleteSpec(clusterSpec *api.ClusterSpec, modelStore vfs.Path, models []string) (*api.ClusterSpec, error) {
|
||||||
|
|
|
@ -28,49 +28,45 @@ import (
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
api "k8s.io/kops/pkg/apis/kops"
|
api "k8s.io/kops/pkg/apis/kops"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
)
|
)
|
||||||
|
|
||||||
//
|
func buildCloudupTags(cluster *api.Cluster) (sets.String, error) {
|
||||||
//
|
|
||||||
func buildCloudupTags(cluster *api.Cluster) (map[string]struct{}, error) {
|
|
||||||
// TODO: Make these configurable?
|
// TODO: Make these configurable?
|
||||||
useMasterASG := true
|
useMasterASG := true
|
||||||
useMasterLB := false
|
useMasterLB := false
|
||||||
|
|
||||||
tags := make(map[string]struct{})
|
tags := sets.NewString()
|
||||||
|
|
||||||
networking := cluster.Spec.Networking
|
networking := cluster.Spec.Networking
|
||||||
glog.Infof("networking: %s", networking)
|
|
||||||
|
|
||||||
if networking == nil || networking.Classic != nil {
|
if networking == nil || networking.Classic != nil {
|
||||||
tags["_networking_classic"] = struct{}{}
|
tags.Insert("_networking_classic")
|
||||||
} else if networking.Kubenet != nil {
|
} else if networking.Kubenet != nil {
|
||||||
tags["_networking_kubenet"] = struct{}{}
|
tags.Insert("_networking_kubenet")
|
||||||
} else if networking.External != nil {
|
} else if networking.External != nil {
|
||||||
// external is based on kubenet
|
// external is based on kubenet
|
||||||
tags["_networking_kubenet"] = struct{}{}
|
tags.Insert("_networking_kubenet", "_networking_external")
|
||||||
tags["_networking_external"] = struct{}{}
|
|
||||||
} else if networking.CNI != nil || networking.Weave != nil {
|
} else if networking.CNI != nil || networking.Weave != nil {
|
||||||
tags["_networking_cni"] = struct{}{}
|
tags.Insert("_networking_cni")
|
||||||
// TODO combine with the External
|
|
||||||
} else if networking.Kopeio != nil {
|
} else if networking.Kopeio != nil {
|
||||||
// Kopeio is based on kubenet / external
|
// Kopeio is based on kubenet / external
|
||||||
tags["_networking_kubenet"] = struct{}{}
|
// TODO combine with External
|
||||||
tags["_networking_external"] = struct{}{}
|
tags.Insert("_networking_kubenet", "_networking_external")
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("No networking mode set")
|
return nil, fmt.Errorf("No networking mode set")
|
||||||
}
|
}
|
||||||
|
|
||||||
if useMasterASG {
|
if useMasterASG {
|
||||||
tags["_master_asg"] = struct{}{}
|
tags.Insert("_master_asg")
|
||||||
} else {
|
} else {
|
||||||
tags["_master_single"] = struct{}{}
|
tags.Insert("_master_single")
|
||||||
}
|
}
|
||||||
|
|
||||||
if useMasterLB {
|
if useMasterLB {
|
||||||
tags["_master_lb"] = struct{}{}
|
tags.Insert("_master_lb")
|
||||||
} else if cluster.Spec.Topology.Masters == api.TopologyPublic {
|
} else if cluster.Spec.Topology.Masters == api.TopologyPublic {
|
||||||
tags["_not_master_lb"] = struct{}{}
|
tags.Insert("_not_master_lb")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Network Topologies
|
// Network Topologies
|
||||||
|
@ -78,27 +74,27 @@ func buildCloudupTags(cluster *api.Cluster) (map[string]struct{}, error) {
|
||||||
return nil, fmt.Errorf("missing topology spec")
|
return nil, fmt.Errorf("missing topology spec")
|
||||||
}
|
}
|
||||||
if cluster.Spec.Topology.Masters == api.TopologyPublic && cluster.Spec.Topology.Nodes == api.TopologyPublic {
|
if cluster.Spec.Topology.Masters == api.TopologyPublic && cluster.Spec.Topology.Nodes == api.TopologyPublic {
|
||||||
tags["_topology_public"] = struct{}{}
|
tags.Insert("_topology_public")
|
||||||
} else if cluster.Spec.Topology.Masters == api.TopologyPrivate && cluster.Spec.Topology.Nodes == api.TopologyPrivate {
|
} else if cluster.Spec.Topology.Masters == api.TopologyPrivate && cluster.Spec.Topology.Nodes == api.TopologyPrivate {
|
||||||
tags["_topology_private"] = struct{}{}
|
tags.Insert("_topology_private")
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("Unable to parse topology. Unsupported topology configuration. Masters and nodes must match!")
|
return nil, fmt.Errorf("Unable to parse topology. Unsupported topology configuration. Masters and nodes must match!")
|
||||||
}
|
}
|
||||||
|
|
||||||
if fi.BoolValue(cluster.Spec.IsolateMasters) {
|
if fi.BoolValue(cluster.Spec.IsolateMasters) {
|
||||||
tags["_isolate_masters"] = struct{}{}
|
tags.Insert("_isolate_masters")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch cluster.Spec.CloudProvider {
|
switch cluster.Spec.CloudProvider {
|
||||||
case "gce":
|
case "gce":
|
||||||
{
|
{
|
||||||
glog.Fatalf("GCE is (probably) not working currently - please ping @justinsb for cleanup")
|
glog.Fatalf("GCE is (probably) not working currently - please ping @justinsb for cleanup")
|
||||||
tags["_gce"] = struct{}{}
|
tags.Insert("_gce")
|
||||||
}
|
}
|
||||||
|
|
||||||
case "aws":
|
case "aws":
|
||||||
{
|
{
|
||||||
tags["_aws"] = struct{}{}
|
tags.Insert("_aws")
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -124,15 +120,15 @@ func buildCloudupTags(cluster *api.Cluster) (map[string]struct{}, error) {
|
||||||
if versionTag == "" {
|
if versionTag == "" {
|
||||||
return nil, fmt.Errorf("unable to determine kubernetes version from %q", cluster.Spec.KubernetesVersion)
|
return nil, fmt.Errorf("unable to determine kubernetes version from %q", cluster.Spec.KubernetesVersion)
|
||||||
} else {
|
} else {
|
||||||
tags[versionTag] = struct{}{}
|
tags.Insert(versionTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof("tags: %s", tags)
|
glog.Infof("tags: %s", tags.List())
|
||||||
|
|
||||||
return tags, nil
|
return tags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildNodeupTags(role api.InstanceGroupRole, cluster *api.Cluster, clusterTags map[string]struct{}) ([]string, error) {
|
func buildNodeupTags(role api.InstanceGroupRole, cluster *api.Cluster, clusterTags sets.String) ([]string, error) {
|
||||||
var tags []string
|
var tags []string
|
||||||
|
|
||||||
networking := cluster.Spec.Networking
|
networking := cluster.Spec.Networking
|
||||||
|
|
|
@ -35,6 +35,7 @@ import (
|
||||||
api "k8s.io/kops/pkg/apis/kops"
|
api "k8s.io/kops/pkg/apis/kops"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/util/pkg/vfs"
|
"k8s.io/kops/util/pkg/vfs"
|
||||||
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -46,7 +47,7 @@ type TemplateFunctions struct {
|
||||||
cluster *api.Cluster
|
cluster *api.Cluster
|
||||||
instanceGroups []*api.InstanceGroup
|
instanceGroups []*api.InstanceGroup
|
||||||
|
|
||||||
tags map[string]struct{}
|
tags sets.String
|
||||||
region string
|
region string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"k8s.io/kops/util/pkg/vfs"
|
"k8s.io/kops/util/pkg/vfs"
|
||||||
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -29,7 +30,7 @@ type TreeWalker struct {
|
||||||
Contexts map[string]Handler
|
Contexts map[string]Handler
|
||||||
Extensions map[string]Handler
|
Extensions map[string]Handler
|
||||||
DefaultHandler Handler
|
DefaultHandler Handler
|
||||||
Tags map[string]struct{}
|
Tags sets.String
|
||||||
}
|
}
|
||||||
|
|
||||||
type TreeWalkItem struct {
|
type TreeWalkItem struct {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/utils"
|
"k8s.io/kops/upup/pkg/fi/utils"
|
||||||
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
@ -30,7 +31,7 @@ import (
|
||||||
type CloudInitTarget struct {
|
type CloudInitTarget struct {
|
||||||
Config *CloudConfig
|
Config *CloudConfig
|
||||||
out io.Writer
|
out io.Writer
|
||||||
Tags map[string]struct{}
|
Tags sets.String
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddBehaviour int
|
type AddBehaviour int
|
||||||
|
@ -40,7 +41,7 @@ const (
|
||||||
Once
|
Once
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCloudInitTarget(out io.Writer, tags map[string]struct{}) *CloudInitTarget {
|
func NewCloudInitTarget(out io.Writer, tags sets.String) *CloudInitTarget {
|
||||||
t := &CloudInitTarget{
|
t := &CloudInitTarget{
|
||||||
Config: &CloudConfig{},
|
Config: &CloudConfig{},
|
||||||
out: out,
|
out: out,
|
||||||
|
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
|
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
|
||||||
"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"
|
||||||
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -174,13 +175,9 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
|
||||||
return fmt.Errorf("error determining OS tags: %v", err)
|
return fmt.Errorf("error determining OS tags: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := make(map[string]struct{})
|
tags := sets.NewString()
|
||||||
for _, tag := range osTags {
|
tags.Insert(osTags...)
|
||||||
tags[tag] = struct{}{}
|
tags.Insert(c.config.Tags...)
|
||||||
}
|
|
||||||
for _, tag := range c.config.Tags {
|
|
||||||
tags[tag] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/loader"
|
"k8s.io/kops/upup/pkg/fi/loader"
|
||||||
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
|
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
|
||||||
"k8s.io/kops/util/pkg/vfs"
|
"k8s.io/kops/util/pkg/vfs"
|
||||||
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
@ -38,11 +39,11 @@ type Loader struct {
|
||||||
assets *fi.AssetStore
|
assets *fi.AssetStore
|
||||||
tasks map[string]fi.Task
|
tasks map[string]fi.Task
|
||||||
|
|
||||||
tags map[string]struct{}
|
tags sets.String
|
||||||
TemplateFunctions template.FuncMap
|
TemplateFunctions template.FuncMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLoader(config *NodeUpConfig, cluster *api.Cluster, assets *fi.AssetStore, tags map[string]struct{}) *Loader {
|
func NewLoader(config *NodeUpConfig, cluster *api.Cluster, assets *fi.AssetStore, tags sets.String) *Loader {
|
||||||
l := &Loader{}
|
l := &Loader{}
|
||||||
l.assets = assets
|
l.assets = assets
|
||||||
l.tasks = make(map[string]fi.Task)
|
l.tasks = make(map[string]fi.Task)
|
||||||
|
|
|
@ -16,11 +16,14 @@ limitations under the License.
|
||||||
|
|
||||||
package local
|
package local
|
||||||
|
|
||||||
import "k8s.io/kops/upup/pkg/fi"
|
import (
|
||||||
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
|
)
|
||||||
|
|
||||||
type LocalTarget struct {
|
type LocalTarget struct {
|
||||||
CacheDir string
|
CacheDir string
|
||||||
Tags map[string]struct{}
|
Tags sets.String
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ fi.Target = &LocalTarget{}
|
var _ fi.Target = &LocalTarget{}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/secrets"
|
"k8s.io/kops/upup/pkg/fi/secrets"
|
||||||
"k8s.io/kops/util/pkg/vfs"
|
"k8s.io/kops/util/pkg/vfs"
|
||||||
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,14 +46,14 @@ type templateFunctions struct {
|
||||||
// secretStore is populated with a SecretStore, if SecretStore is set
|
// secretStore is populated with a SecretStore, if SecretStore is set
|
||||||
secretStore fi.SecretStore
|
secretStore fi.SecretStore
|
||||||
|
|
||||||
tags map[string]struct{}
|
tags sets.String
|
||||||
|
|
||||||
// kubeletConfig is the kubelet config for the current node
|
// kubeletConfig is the kubelet config for the current node
|
||||||
kubeletConfig *api.KubeletConfigSpec
|
kubeletConfig *api.KubeletConfigSpec
|
||||||
}
|
}
|
||||||
|
|
||||||
// newTemplateFunctions is the constructor for templateFunctions
|
// newTemplateFunctions is the constructor for templateFunctions
|
||||||
func newTemplateFunctions(nodeupConfig *NodeUpConfig, cluster *api.Cluster, instanceGroup *api.InstanceGroup, tags map[string]struct{}) (*templateFunctions, error) {
|
func newTemplateFunctions(nodeupConfig *NodeUpConfig, cluster *api.Cluster, instanceGroup *api.InstanceGroup, tags sets.String) (*templateFunctions, error) {
|
||||||
t := &templateFunctions{
|
t := &templateFunctions{
|
||||||
nodeupConfig: nodeupConfig,
|
nodeupConfig: nodeupConfig,
|
||||||
cluster: cluster,
|
cluster: cluster,
|
||||||
|
|
Loading…
Reference in New Issue