forked from rancher/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kubeadm self-hosting: unit tests and bazel
- Loading branch information
Showing
9 changed files
with
796 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) | ||
|
||
load( | ||
"@io_bazel_rules_go//go:def.bzl", | ||
"go_library", | ||
"go_test", | ||
) | ||
|
||
go_test( | ||
name = "go_default_test", | ||
srcs = [ | ||
"podspec_mutation_test.go", | ||
"selfhosting_test.go", | ||
], | ||
library = ":go_default_library", | ||
tags = ["automanaged"], | ||
deps = [ | ||
"//cmd/kubeadm/app/constants:go_default_library", | ||
"//vendor/github.com/ghodss/yaml:go_default_library", | ||
"//vendor/k8s.io/api/core/v1:go_default_library", | ||
], | ||
) | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = [ | ||
"podspec_mutation.go", | ||
"selfhosting.go", | ||
], | ||
tags = ["automanaged"], | ||
deps = [ | ||
"//cmd/kubeadm/app/constants:go_default_library", | ||
"//cmd/kubeadm/app/util:go_default_library", | ||
"//pkg/api:go_default_library", | ||
"//vendor/k8s.io/api/core/v1:go_default_library", | ||
"//vendor/k8s.io/api/extensions/v1beta1:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", | ||
"//vendor/k8s.io/client-go/kubernetes:go_default_library", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "package-srcs", | ||
srcs = glob(["**"]), | ||
tags = ["automanaged"], | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
filegroup( | ||
name = "all-srcs", | ||
srcs = [":package-srcs"], | ||
tags = ["automanaged"], | ||
) |
185 changes: 185 additions & 0 deletions
185
cmd/kubeadm/app/phases/selfhosting/podspec_mutation_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
/* | ||
Copyright 2017 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 | ||
https://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 selfhosting | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"k8s.io/api/core/v1" | ||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants" | ||
) | ||
|
||
func TestMutatePodSpec(t *testing.T) { | ||
var tests = []struct { | ||
component string | ||
podSpec *v1.PodSpec | ||
expected v1.PodSpec | ||
}{ | ||
{ | ||
component: kubeAPIServer, | ||
podSpec: &v1.PodSpec{}, | ||
expected: v1.PodSpec{ | ||
NodeSelector: map[string]string{ | ||
kubeadmconstants.LabelNodeRoleMaster: "", | ||
}, | ||
Tolerations: []v1.Toleration{ | ||
kubeadmconstants.MasterToleration, | ||
}, | ||
DNSPolicy: v1.DNSClusterFirstWithHostNet, | ||
}, | ||
}, | ||
{ | ||
component: kubeControllerManager, | ||
podSpec: &v1.PodSpec{}, | ||
expected: v1.PodSpec{ | ||
NodeSelector: map[string]string{ | ||
kubeadmconstants.LabelNodeRoleMaster: "", | ||
}, | ||
Tolerations: []v1.Toleration{ | ||
kubeadmconstants.MasterToleration, | ||
}, | ||
DNSPolicy: v1.DNSClusterFirstWithHostNet, | ||
}, | ||
}, | ||
{ | ||
component: kubeScheduler, | ||
podSpec: &v1.PodSpec{}, | ||
expected: v1.PodSpec{ | ||
NodeSelector: map[string]string{ | ||
kubeadmconstants.LabelNodeRoleMaster: "", | ||
}, | ||
Tolerations: []v1.Toleration{ | ||
kubeadmconstants.MasterToleration, | ||
}, | ||
DNSPolicy: v1.DNSClusterFirstWithHostNet, | ||
}, | ||
}, | ||
} | ||
|
||
for _, rt := range tests { | ||
mutatePodSpec(rt.component, rt.podSpec) | ||
|
||
if !reflect.DeepEqual(*rt.podSpec, rt.expected) { | ||
t.Errorf("failed mutatePodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec) | ||
} | ||
} | ||
} | ||
|
||
func TestAddNodeSelectorToPodSpec(t *testing.T) { | ||
var tests = []struct { | ||
podSpec *v1.PodSpec | ||
expected v1.PodSpec | ||
}{ | ||
{ | ||
podSpec: &v1.PodSpec{}, | ||
expected: v1.PodSpec{ | ||
NodeSelector: map[string]string{ | ||
kubeadmconstants.LabelNodeRoleMaster: "", | ||
}, | ||
}, | ||
}, | ||
{ | ||
podSpec: &v1.PodSpec{ | ||
NodeSelector: map[string]string{ | ||
"foo": "bar", | ||
}, | ||
}, | ||
expected: v1.PodSpec{ | ||
NodeSelector: map[string]string{ | ||
"foo": "bar", | ||
kubeadmconstants.LabelNodeRoleMaster: "", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, rt := range tests { | ||
addNodeSelectorToPodSpec(rt.podSpec) | ||
|
||
if !reflect.DeepEqual(*rt.podSpec, rt.expected) { | ||
t.Errorf("failed addNodeSelectorToPodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec) | ||
} | ||
} | ||
} | ||
|
||
func TestSetMasterTolerationOnPodSpec(t *testing.T) { | ||
var tests = []struct { | ||
podSpec *v1.PodSpec | ||
expected v1.PodSpec | ||
}{ | ||
{ | ||
podSpec: &v1.PodSpec{}, | ||
expected: v1.PodSpec{ | ||
Tolerations: []v1.Toleration{ | ||
kubeadmconstants.MasterToleration, | ||
}, | ||
}, | ||
}, | ||
{ | ||
podSpec: &v1.PodSpec{ | ||
Tolerations: []v1.Toleration{ | ||
{Key: "foo", Value: "bar"}, | ||
}, | ||
}, | ||
expected: v1.PodSpec{ | ||
Tolerations: []v1.Toleration{ | ||
{Key: "foo", Value: "bar"}, | ||
kubeadmconstants.MasterToleration, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, rt := range tests { | ||
setMasterTolerationOnPodSpec(rt.podSpec) | ||
|
||
if !reflect.DeepEqual(*rt.podSpec, rt.expected) { | ||
t.Errorf("failed setMasterTolerationOnPodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec) | ||
} | ||
} | ||
} | ||
|
||
func TestSetRightDNSPolicyOnPodSpec(t *testing.T) { | ||
var tests = []struct { | ||
podSpec *v1.PodSpec | ||
expected v1.PodSpec | ||
}{ | ||
{ | ||
podSpec: &v1.PodSpec{}, | ||
expected: v1.PodSpec{ | ||
DNSPolicy: v1.DNSClusterFirstWithHostNet, | ||
}, | ||
}, | ||
{ | ||
podSpec: &v1.PodSpec{ | ||
DNSPolicy: v1.DNSClusterFirst, | ||
}, | ||
expected: v1.PodSpec{ | ||
DNSPolicy: v1.DNSClusterFirstWithHostNet, | ||
}, | ||
}, | ||
} | ||
|
||
for _, rt := range tests { | ||
setRightDNSPolicyOnPodSpec(rt.podSpec) | ||
|
||
if !reflect.DeepEqual(*rt.podSpec, rt.expected) { | ||
t.Errorf("failed setRightDNSPolicyOnPodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec) | ||
} | ||
} | ||
} |
Oops, something went wrong.