Remove unused tags functionality

This commit is contained in:
John Gardiner Myers 2020-08-14 14:29:30 -07:00
parent a243cc190f
commit 2472e75bbf
5 changed files with 0 additions and 267 deletions

View File

@ -15,7 +15,6 @@ go_library(
"populate_instancegroup_spec.go",
"spec_builder.go",
"subnets.go",
"tagbuilder.go",
"target.go",
"template_functions.go",
"urls.go",
@ -103,7 +102,6 @@ go_test(
"populatecluster_test.go",
"populateinstancegroup_test.go",
"subnets_test.go",
"tagbuilder_test.go",
"template_functions_test.go",
"validation_test.go",
],

View File

@ -456,14 +456,8 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
}
}
clusterTags, err := buildCloudupTags(cluster)
if err != nil {
return err
}
tf := &TemplateFunctions{
KopsModelContext: *modelContext,
tags: clusterTags,
}
{

View File

@ -1,67 +0,0 @@
/*
Copyright 2019 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.
*/
/******************************************************************************
* The Kops Tag Builder
*
* Tags are how we manage kops functionality.
*
******************************************************************************/
package cloudup
import (
"fmt"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog"
api "k8s.io/kops/pkg/apis/kops"
)
func buildCloudupTags(cluster *api.Cluster) (sets.String, error) {
tags := sets.NewString()
switch api.CloudProviderID(cluster.Spec.CloudProvider) {
case api.CloudProviderGCE:
{
tags.Insert("_gce")
}
case api.CloudProviderAWS:
{
tags.Insert("_aws")
}
case api.CloudProviderDO:
{
tags.Insert("_do")
}
case api.CloudProviderOpenstack:
case api.CloudProviderALI:
{
tags.Insert("_ali")
}
default:
return nil, fmt.Errorf("unknown CloudProvider %q", cluster.Spec.CloudProvider)
}
tags.Insert("_k8s_1_6")
klog.V(4).Infof("tags: %s", tags.List())
return tags, nil
}

View File

@ -1,183 +0,0 @@
/*
Copyright 2019 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 cloudup
import (
"testing"
api "k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi"
)
type ClusterParams struct {
CloudProvider string
KubernetesVersion string
UpdatePolicy string
}
func buildCluster(clusterArgs interface{}) *api.Cluster {
if clusterArgs == nil {
clusterArgs = ClusterParams{CloudProvider: "aws", KubernetesVersion: "1.4.0"}
}
cParams := clusterArgs.(ClusterParams)
if cParams.CloudProvider == "" {
cParams.CloudProvider = "aws"
}
if cParams.KubernetesVersion == "" {
cParams.KubernetesVersion = "v1.4.0"
}
networking := &api.NetworkingSpec{
CNI: &api.CNINetworkingSpec{},
}
return &api.Cluster{
Spec: api.ClusterSpec{
CloudProvider: cParams.CloudProvider,
KubernetesVersion: cParams.KubernetesVersion,
Networking: networking,
UpdatePolicy: fi.String(cParams.UpdatePolicy),
Topology: &api.TopologySpec{
Masters: api.TopologyPublic,
Nodes: api.TopologyPublic,
},
},
}
}
func TestBuildTags_CloudProvider_AWS_Weave(t *testing.T) {
c := buildCluster(nil)
networking := &api.NetworkingSpec{Weave: &api.WeaveNetworkingSpec{}}
c.Spec.Networking = networking
tags, err := buildCloudupTags(c)
if err != nil {
t.Fatalf("buildCloudupTags error: %v", err)
}
if !tags.Has("_aws") {
t.Fatal("tag _aws not found")
}
}
func TestBuildTags_CloudProvider_AWS_Flannel(t *testing.T) {
c := buildCluster(nil)
networking := &api.NetworkingSpec{Flannel: &api.FlannelNetworkingSpec{}}
c.Spec.Networking = networking
tags, err := buildCloudupTags(c)
if err != nil {
t.Fatalf("buildCloudupTags error: %v", err)
}
if !tags.Has("_aws") {
t.Fatal("tag _aws not found")
}
}
func TestBuildTags_CloudProvider_AWS_Calico(t *testing.T) {
c := buildCluster(nil)
networking := &api.NetworkingSpec{Calico: &api.CalicoNetworkingSpec{}}
c.Spec.Networking = networking
tags, err := buildCloudupTags(c)
if err != nil {
t.Fatalf("buildCloudupTags error: %v", err)
}
if !tags.Has("_aws") {
t.Fatal("tag _aws not found")
}
}
func TestBuildTags_CloudProvider_AWS_Canal(t *testing.T) {
c := buildCluster(nil)
networking := &api.NetworkingSpec{Canal: &api.CanalNetworkingSpec{}}
c.Spec.Networking = networking
tags, err := buildCloudupTags(c)
if err != nil {
t.Fatalf("buildCloudupTags error: %v", err)
}
if !tags.Has("_aws") {
t.Fatal("tag _aws not found")
}
}
func TestBuildTags_CloudProvider_AWS(t *testing.T) {
c := buildCluster(nil)
tags, err := buildCloudupTags(c)
if err != nil {
t.Fatalf("buildCloudupTags error: %v", err)
}
if !tags.Has("_aws") {
t.Fatal("tag _aws not found")
}
}
func TestBuildTags_KubernetesVersions(t *testing.T) {
grid := map[string]string{
"v1.14.0-beta.8": "_k8s_1_6",
"1.15.0": "_k8s_1_6",
"https://storage.googleapis.com/kubernetes-release-dev/ci/v1.14.0-alpha.2.677+ea69570f61af8e/": "_k8s_1_6",
}
for version, tag := range grid {
c := buildCluster(ClusterParams{KubernetesVersion: version})
tags, err := buildCloudupTags(c)
if err != nil {
t.Fatalf("buildCloudupTags error: %v", err)
}
if !tags.Has(tag) {
t.Fatalf("tag %q not found for %q: %v", tag, version, tags)
}
}
}
func TestBuildTags_CloudProvider_AWS_Cilium(t *testing.T) {
c := buildCluster(nil)
networking := &api.NetworkingSpec{Cilium: &api.CiliumNetworkingSpec{}}
c.Spec.Networking = networking
tags, err := buildCloudupTags(c)
if err != nil {
t.Fatalf("buildCloudupTags error: %v", err)
}
if !tags.Has("_aws") {
t.Fatal("tag _aws not found")
}
}

View File

@ -37,7 +37,6 @@ import (
"github.com/Masterminds/sprig"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog"
kopscontrollerconfig "k8s.io/kops/cmd/kops-controller/pkg/config"
"k8s.io/kops/pkg/apis/kops"
@ -55,7 +54,6 @@ import (
// TemplateFunctions provides a collection of methods used throughout the templates
type TemplateFunctions struct {
model.KopsModelContext
tags sets.String
}
// AddTo defines the available functions we can use in our YAML models.
@ -82,7 +80,6 @@ func (tf *TemplateFunctions) AddTo(dest template.FuncMap, secretStore fi.SecretS
dest["contains"] = sprigTxtFuncMap["contains"]
dest["ClusterName"] = tf.ClusterName
dest["HasTag"] = tf.HasTag
dest["WithDefaultBool"] = func(v *bool, defaultValue bool) bool {
if v != nil {
return *v
@ -204,12 +201,6 @@ func (tf *TemplateFunctions) SharedVPC() bool {
return tf.Cluster.SharedVPC()
}
// HasTag returns true if the specified tag is set
func (tf *TemplateFunctions) HasTag(tag string) bool {
_, found := tf.tags[tag]
return found
}
// GetInstanceGroup returns the instance group with the specified name
func (tf *TemplateFunctions) GetInstanceGroup(name string) (*kops.InstanceGroup, error) {
ig := tf.KopsModelContext.FindInstanceGroup(name)