run hack/update-bazel.sh and go fmt and BUILD.bazel file in addons

This commit is contained in:
David Siecinski 2019-11-22 12:37:37 +01:00
parent 013f8799fa
commit 5bc52c08c0
4 changed files with 132 additions and 113 deletions

View File

@ -0,0 +1,5 @@
filegroup(
name = "exported_testdata",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)

View File

@ -105,6 +105,7 @@ go_test(
"populateinstancegroup_test.go",
"subnets_test.go",
"tagbuilder_test.go",
"template_functions_test.go",
"validation_test.go",
],
data = [
@ -116,6 +117,7 @@ go_test(
"//pkg/apis/kops/validation:go_default_library",
"//pkg/assets:go_default_library",
"//pkg/client/simple/vfsclientset:go_default_library",
"//pkg/featureflag:go_default_library",
"//pkg/kopscodecs:go_default_library",
"//pkg/model:go_default_library",
"//pkg/templates:go_default_library",
@ -127,5 +129,6 @@ go_test(
"//util/pkg/vfs:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
"//vendor/k8s.io/kubernetes/pkg/controller/nodeipam/ipam:go_default_library",
],
)

View File

@ -208,7 +208,7 @@ func (tf *TemplateFunctions) CloudControllerConfigArgv() ([]string, error) {
} else {
argv = append(argv, "--v=2")
}
if tf.cluster.Spec.ExternalCloudControllerManager.CloudProvider !=""{
if tf.cluster.Spec.ExternalCloudControllerManager.CloudProvider != "" {
argv = append(argv, fmt.Sprintf("--cloud-provider=%s", tf.cluster.Spec.ExternalCloudControllerManager.CloudProvider))
} else if tf.cluster.Spec.CloudProvider != "" {
argv = append(argv, fmt.Sprintf("--cloud-provider=%s", tf.cluster.Spec.CloudProvider))
@ -227,13 +227,13 @@ func (tf *TemplateFunctions) CloudControllerConfigArgv() ([]string, error) {
if tf.cluster.Spec.ExternalCloudControllerManager.ConfigureCloudRoutes != nil {
argv = append(argv, fmt.Sprintf("--configure-cloud-routes=%t", *tf.cluster.Spec.ExternalCloudControllerManager.ConfigureCloudRoutes))
}
if tf.cluster.Spec.ExternalCloudControllerManager.CIDRAllocatorType != nil && *tf.cluster.Spec.ExternalCloudControllerManager.CIDRAllocatorType != ""{
if tf.cluster.Spec.ExternalCloudControllerManager.CIDRAllocatorType != nil && *tf.cluster.Spec.ExternalCloudControllerManager.CIDRAllocatorType != "" {
argv = append(argv, fmt.Sprintf("--cidr-allocator-type=%s", *tf.cluster.Spec.ExternalCloudControllerManager.CIDRAllocatorType))
}
if tf.cluster.Spec.ExternalCloudControllerManager.UseServiceAccountCredentials != nil {
argv = append(argv, fmt.Sprintf("--use-service-account-credentials=%t", *tf.cluster.Spec.ExternalCloudControllerManager.UseServiceAccountCredentials ))
argv = append(argv, fmt.Sprintf("--use-service-account-credentials=%t", *tf.cluster.Spec.ExternalCloudControllerManager.UseServiceAccountCredentials))
} else {
argv = append(argv, fmt.Sprintf("--use-service-account-credentials=%t", true ))
argv = append(argv, fmt.Sprintf("--use-service-account-credentials=%t", true))
}
return argv, nil

View File

@ -1,18 +1,34 @@
/*
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 (
"k8s.io/kops/pkg/featureflag"
"path/filepath"
"io/ioutil"
"bytes"
"text/template"
"k8s.io/kops/pkg/apis/kops"
"reflect"
"testing"
"fmt"
"strings"
"io/ioutil"
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/featureflag"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kubernetes/pkg/controller/nodeipam/ipam"
"path/filepath"
"reflect"
"strings"
"testing"
"text/template"
)
func Test_TemplateFunctions_CloudControllerConfigArgv(t *testing.T) {
@ -27,7 +43,6 @@ func Test_TemplateFunctions_CloudControllerConfigArgv(t *testing.T) {
cluster: &kops.Cluster{Spec: kops.ClusterSpec{
CloudProvider: string(kops.CloudProviderOpenstack),
ExternalCloudControllerManager: &kops.CloudControllerManagerConfig{},
}},
expectedArgv: []string{
"--v=2",
@ -85,8 +100,6 @@ func Test_TemplateFunctions_CloudControllerConfigArgv(t *testing.T) {
ExternalCloudControllerManager: &kops.CloudControllerManagerConfig{
ClusterName: "k8s",
},
}},
expectedArgv: []string{
"--v=2",
@ -138,7 +151,6 @@ func Test_TemplateFunctions_CloudControllerConfigArgv(t *testing.T) {
"--cloud-provider=openstack",
"--allocate-node-cidrs=true",
"--use-service-account-credentials=true",
},
},
{
@ -202,9 +214,8 @@ func Test_TemplateFunctions_CloudControllerConfigArgv(t *testing.T) {
}
}
func Test_executeTemplate(t *testing.T ) {
tests := []struct{
func Test_executeTemplate(t *testing.T) {
tests := []struct {
desc string
cluster *kops.Cluster
templateFilename string
@ -222,8 +233,8 @@ func Test_executeTemplate(t *testing.T ) {
},
templateFilename: "../../../models/cloudup/resources/addons/openstack.addons.k8s.io/k8s-1.13.yaml.template",
expectedManifestPath: "./tests/manifests/k8s-1.13.yaml",
},
{
},
{
desc: "test cloud controller template",
cluster: &kops.Cluster{Spec: kops.ClusterSpec{
CloudProvider: string(kops.CloudProviderOpenstack),
@ -236,7 +247,7 @@ func Test_executeTemplate(t *testing.T ) {
templateFilename: "../../../models/cloudup/resources/addons/openstack.addons.k8s.io/k8s-1.11.yaml.template",
expectedManifestPath: "./tests/manifests/k8s-1.11.yaml",
},
}
}
for _, testCase := range tests {
t.Run(testCase.desc, func(t *testing.T) {
@ -266,12 +277,12 @@ func Test_executeTemplate(t *testing.T ) {
}
actualManifest := buffer.Bytes()
expectedFileAbsolutePath, _ := filepath.Abs(testCase.expectedManifestPath)
expectedManifest, _ := ioutil.ReadFile( expectedFileAbsolutePath )
expectedManifest, _ := ioutil.ReadFile(expectedFileAbsolutePath)
actualString := strings.TrimSpace(string(actualManifest))
expectedString := strings.TrimSpace(string(expectedManifest))
if !reflect.DeepEqual(actualString,expectedString,) {
t.Fatalf("Manifests differs: %+v instead of %+v", actualString, expectedString )
if !reflect.DeepEqual(actualString, expectedString) {
t.Fatalf("Manifests differs: %+v instead of %+v", actualString, expectedString)
}
})
}