@@ -3683,6 +3683,7 @@ func ParseKVLines(output, key string) string {
3683
3683
return ""
3684
3684
}
3685
3685
3686
+ // RestartKubeProxy restarts kube-proxy on the given host.
3686
3687
func RestartKubeProxy (host string ) error {
3687
3688
// TODO: Make it work for all providers.
3688
3689
if ! ProviderIs ("gce" , "gke" , "aws" ) {
@@ -3719,6 +3720,7 @@ func RestartKubeProxy(host string) error {
3719
3720
return nil
3720
3721
}
3721
3722
3723
+ // RestartKubelet restarts kubelet on the given host.
3722
3724
func RestartKubelet (host string ) error {
3723
3725
// TODO: Make it work for all providers and distros.
3724
3726
supportedProviders := []string {"gce" , "aws" , "vsphere" }
@@ -3762,6 +3764,7 @@ func RestartKubelet(host string) error {
3762
3764
return nil
3763
3765
}
3764
3766
3767
+ // WaitForKubeletUp waits for the kubelet on the given host to be up.
3765
3768
func WaitForKubeletUp (host string ) error {
3766
3769
cmd := "curl http://localhost:" + strconv .Itoa (ports .KubeletReadOnlyPort ) + "/healthz"
3767
3770
for start := time .Now (); time .Since (start ) < time .Minute ; time .Sleep (5 * time .Second ) {
@@ -3776,6 +3779,7 @@ func WaitForKubeletUp(host string) error {
3776
3779
return fmt .Errorf ("waiting for kubelet timed out" )
3777
3780
}
3778
3781
3782
+ // RestartApiserver restarts the kube-apiserver.
3779
3783
func RestartApiserver (cs clientset.Interface ) error {
3780
3784
// TODO: Make it work for all providers.
3781
3785
if ! ProviderIs ("gce" , "gke" , "aws" ) {
@@ -3819,6 +3823,7 @@ func sshRestartMaster() error {
3819
3823
return nil
3820
3824
}
3821
3825
3826
+ // WaitForApiserverUp waits for the kube-apiserver to be up.
3822
3827
func WaitForApiserverUp (c clientset.Interface ) error {
3823
3828
for start := time .Now (); time .Since (start ) < time .Minute ; time .Sleep (5 * time .Second ) {
3824
3829
body , err := c .CoreV1 ().RESTClient ().Get ().AbsPath ("/healthz" ).Do ().Raw ()
@@ -3865,6 +3870,7 @@ func getApiserverRestartCount(c clientset.Interface) (int32, error) {
3865
3870
return - 1 , fmt .Errorf ("Failed to find kube-apiserver container in pod" )
3866
3871
}
3867
3872
3873
+ // RestartControllerManager restarts the kube-controller-manager.
3868
3874
func RestartControllerManager () error {
3869
3875
// TODO: Make it work for all providers and distros.
3870
3876
if ! ProviderIs ("gce" , "aws" ) {
@@ -3883,6 +3889,7 @@ func RestartControllerManager() error {
3883
3889
return nil
3884
3890
}
3885
3891
3892
+ // WaitForControllerManagerUp waits for the kube-controller-manager to be up.
3886
3893
func WaitForControllerManagerUp () error {
3887
3894
cmd := "curl http://localhost:" + strconv .Itoa (ports .InsecureKubeControllerManagerPort ) + "/healthz"
3888
3895
for start := time .Now (); time .Since (start ) < time .Minute ; time .Sleep (5 * time .Second ) {
@@ -3986,11 +3993,12 @@ func WaitForReadyNodes(c clientset.Interface, size int, timeout time.Duration) e
3986
3993
return err
3987
3994
}
3988
3995
3996
+ // GenerateMasterRegexp returns a regex for matching master node name.
3989
3997
func GenerateMasterRegexp (prefix string ) string {
3990
3998
return prefix + "(-...)?"
3991
3999
}
3992
4000
3993
- // waitForMasters waits until the cluster has the desired number of ready masters in it.
4001
+ // WaitForMasters waits until the cluster has the desired number of ready masters in it.
3994
4002
func WaitForMasters (masterPrefix string , c clientset.Interface , size int , timeout time.Duration ) error {
3995
4003
for start := time .Now (); time .Since (start ) < timeout ; time .Sleep (20 * time .Second ) {
3996
4004
nodes , err := c .CoreV1 ().Nodes ().List (metav1.ListOptions {})
@@ -4099,21 +4107,21 @@ func OpenWebSocketForURL(url *url.URL, config *restclient.Config, protocols []st
4099
4107
return websocket .DialConfig (cfg )
4100
4108
}
4101
4109
4102
- // Looks for the given string in the log of a specific pod container
4110
+ // LookForStringInLog looks for the given string in the log of a specific pod container
4103
4111
func LookForStringInLog (ns , podName , container , expectedString string , timeout time.Duration ) (result string , err error ) {
4104
4112
return LookForString (expectedString , timeout , func () string {
4105
4113
return RunKubectlOrDie ("logs" , podName , container , fmt .Sprintf ("--namespace=%v" , ns ))
4106
4114
})
4107
4115
}
4108
4116
4109
- // Looks for the given string in a file in a specific pod container
4117
+ // LookForStringInFile looks for the given string in a file in a specific pod container
4110
4118
func LookForStringInFile (ns , podName , container , file , expectedString string , timeout time.Duration ) (result string , err error ) {
4111
4119
return LookForString (expectedString , timeout , func () string {
4112
4120
return RunKubectlOrDie ("exec" , podName , "-c" , container , fmt .Sprintf ("--namespace=%v" , ns ), "--" , "cat" , file )
4113
4121
})
4114
4122
}
4115
4123
4116
- // Looks for the given string in the output of a command executed in a specific pod container
4124
+ // LookForStringInPodExec looks for the given string in the output of a command executed in a specific pod container
4117
4125
func LookForStringInPodExec (ns , podName string , command []string , expectedString string , timeout time.Duration ) (result string , err error ) {
4118
4126
return LookForString (expectedString , timeout , func () string {
4119
4127
// use the first container
@@ -4123,7 +4131,7 @@ func LookForStringInPodExec(ns, podName string, command []string, expectedString
4123
4131
})
4124
4132
}
4125
4133
4126
- // Looks for the given string in the output of fn, repeatedly calling fn until
4134
+ // LookForString looks for the given string in the output of fn, repeatedly calling fn until
4127
4135
// the timeout is reached or the string is found. Returns last log and possibly
4128
4136
// error if the string was not found.
4129
4137
func LookForString (expectedString string , timeout time.Duration , fn func () string ) (result string , err error ) {
@@ -4179,7 +4187,7 @@ func GetNodePortURL(client clientset.Interface, ns, name string, svcPort int) (s
4179
4187
return "" , err
4180
4188
}
4181
4189
if len (nodes .Items ) == 0 {
4182
- return "" , fmt .Errorf ("Unable to list nodes in cluster. " )
4190
+ return "" , fmt .Errorf ("Unable to list nodes in cluster" )
4183
4191
}
4184
4192
for _ , node := range nodes .Items {
4185
4193
for _ , address := range node .Status .Addresses {
@@ -4193,6 +4201,7 @@ func GetNodePortURL(client clientset.Interface, ns, name string, svcPort int) (s
4193
4201
return "" , fmt .Errorf ("Failed to find external address for service %v" , name )
4194
4202
}
4195
4203
4204
+ // GetPodLogs returns the logs of the specified container (namespace/pod/container).
4196
4205
// TODO(random-liu): Change this to be a member function of the framework.
4197
4206
func GetPodLogs (c clientset.Interface , namespace , podName , containerName string ) (string , error ) {
4198
4207
return getPodLogsInternal (c , namespace , podName , containerName , false )
@@ -4216,7 +4225,7 @@ func getPodLogsInternal(c clientset.Interface, namespace, podName, containerName
4216
4225
return "" , err
4217
4226
}
4218
4227
if err == nil && strings .Contains (string (logs ), "Internal Error" ) {
4219
- return "" , fmt .Errorf ("Fetched log contains \" Internal Error\" : %q. " , string (logs ))
4228
+ return "" , fmt .Errorf ("Fetched log contains \" Internal Error\" : %q" , string (logs ))
4220
4229
}
4221
4230
return string (logs ), err
4222
4231
}
@@ -4227,6 +4236,7 @@ func EnsureLoadBalancerResourcesDeleted(ip, portRange string) error {
4227
4236
return TestContext .CloudConfig .Provider .EnsureLoadBalancerResourcesDeleted (ip , portRange )
4228
4237
}
4229
4238
4239
+ // BlockNetwork blocks network between the given from value and the given to value.
4230
4240
// The following helper functions can block/unblock network from source
4231
4241
// host to destination host by manipulating iptable rules.
4232
4242
// This function assumes it can ssh to the source host.
@@ -4254,6 +4264,7 @@ func BlockNetwork(from string, to string) {
4254
4264
}
4255
4265
}
4256
4266
4267
+ // UnblockNetwork unblocks network between the given from value and the given to value.
4257
4268
func UnblockNetwork (from string , to string ) {
4258
4269
Logf ("Unblock network traffic from %s to %s" , from , to )
4259
4270
iptablesRule := fmt .Sprintf ("OUTPUT --destination %s --jump REJECT" , to )
@@ -4341,10 +4352,13 @@ func getKubeletPods(c clientset.Interface, node, resource string) (*v1.PodList,
4341
4352
return result , nil
4342
4353
}
4343
4354
4355
+ // PingCommand is the type to hold ping command.
4344
4356
type PingCommand string
4345
4357
4346
4358
const (
4359
+ // IPv4PingCommand is a ping command for IPv4.
4347
4360
IPv4PingCommand PingCommand = "ping"
4361
+ // IPv6PingCommand is a ping command for IPv6.
4348
4362
IPv6PingCommand PingCommand = "ping6"
4349
4363
)
4350
4364
@@ -4428,6 +4442,7 @@ func parseSystemdServices(services string) string {
4428
4442
return strings .TrimSpace (strings .Replace (services , "," , " " , - 1 ))
4429
4443
}
4430
4444
4445
+ // GetPodsInNamespace returns the pods in the given namespace.
4431
4446
func GetPodsInNamespace (c clientset.Interface , ns string , ignoreLabels map [string ]string ) ([]* v1.Pod , error ) {
4432
4447
pods , err := c .CoreV1 ().Pods (ns ).List (metav1.ListOptions {})
4433
4448
if err != nil {
@@ -4561,6 +4576,7 @@ func GetMasterAndWorkerNodesOrDie(c clientset.Interface) (sets.String, *v1.NodeL
4561
4576
return masters , nodes
4562
4577
}
4563
4578
4579
+ // ListNamespaceEvents lists the events in the given namespace.
4564
4580
func ListNamespaceEvents (c clientset.Interface , ns string ) error {
4565
4581
ls , err := c .CoreV1 ().Events (ns ).List (metav1.ListOptions {})
4566
4582
if err != nil {
@@ -4583,6 +4599,7 @@ type E2ETestNodePreparer struct {
4583
4599
nodeToAppliedStrategy map [string ]testutils.PrepareNodeStrategy
4584
4600
}
4585
4601
4602
+ // NewE2ETestNodePreparer returns a new instance of E2ETestNodePreparer.
4586
4603
func NewE2ETestNodePreparer (client clientset.Interface , countToStrategy []testutils.CountToStrategy ) testutils.TestNodePreparer {
4587
4604
return & E2ETestNodePreparer {
4588
4605
client : client ,
@@ -4591,14 +4608,15 @@ func NewE2ETestNodePreparer(client clientset.Interface, countToStrategy []testut
4591
4608
}
4592
4609
}
4593
4610
4611
+ // PrepareNodes prepares nodes in the cluster.
4594
4612
func (p * E2ETestNodePreparer ) PrepareNodes () error {
4595
4613
nodes := GetReadySchedulableNodesOrDie (p .client )
4596
4614
numTemplates := 0
4597
4615
for _ , v := range p .countToStrategy {
4598
4616
numTemplates += v .Count
4599
4617
}
4600
4618
if numTemplates > len (nodes .Items ) {
4601
- return fmt .Errorf ("Can't prepare Nodes. Got more templates than existing Nodes. " )
4619
+ return fmt .Errorf ("Can't prepare Nodes. Got more templates than existing Nodes" )
4602
4620
}
4603
4621
index := 0
4604
4622
sum := 0
@@ -4615,6 +4633,7 @@ func (p *E2ETestNodePreparer) PrepareNodes() error {
4615
4633
return nil
4616
4634
}
4617
4635
4636
+ // CleanupNodes cleanups nodes in the cluster.
4618
4637
func (p * E2ETestNodePreparer ) CleanupNodes () error {
4619
4638
var encounteredError error
4620
4639
nodes := GetReadySchedulableNodesOrDie (p .client )
@@ -4758,12 +4777,13 @@ func PollURL(route, host string, timeout time.Duration, interval time.Duration,
4758
4777
return ! expectUnreachable , nil
4759
4778
})
4760
4779
if pollErr != nil {
4761
- return fmt .Errorf ("Failed to execute a successful GET within %v, Last response body for %v, host %v:\n %v\n \n %v\n " ,
4780
+ return fmt .Errorf ("Failed to execute a successful GET within %v, Last response body for %v, host %v:\n %v\n \n %v" ,
4762
4781
timeout , route , host , lastBody , pollErr )
4763
4782
}
4764
4783
return nil
4765
4784
}
4766
4785
4786
+ // DescribeIng describes information of ingress by running kubectl describe ing.
4767
4787
func DescribeIng (ns string ) {
4768
4788
Logf ("\n Output of kubectl describe ing:\n " )
4769
4789
desc , _ := RunKubectl (
@@ -4792,12 +4812,13 @@ func (f *Framework) NewTestPod(name string, requests v1.ResourceList, limits v1.
4792
4812
}
4793
4813
}
4794
4814
4795
- // create empty file at given path on the pod.
4815
+ // CreateEmptyFileOnPod creates empty file at given path on the pod.
4796
4816
func CreateEmptyFileOnPod (namespace string , podName string , filePath string ) error {
4797
4817
_ , err := RunKubectl ("exec" , fmt .Sprintf ("--namespace=%s" , namespace ), podName , "--" , "/bin/sh" , "-c" , fmt .Sprintf ("touch %s" , filePath ))
4798
4818
return err
4799
4819
}
4800
4820
4821
+ // PrintSummaries prints summaries of tests.
4801
4822
func PrintSummaries (summaries []TestDataSummary , testBaseName string ) {
4802
4823
now := time .Now ()
4803
4824
for i := range summaries {
@@ -4834,6 +4855,7 @@ func PrintSummaries(summaries []TestDataSummary, testBaseName string) {
4834
4855
}
4835
4856
}
4836
4857
4858
+ // DumpDebugInfo dumps debug info of tests.
4837
4859
func DumpDebugInfo (c clientset.Interface , ns string ) {
4838
4860
sl , _ := c .CoreV1 ().Pods (ns ).List (metav1.ListOptions {LabelSelector : labels .Everything ().String ()})
4839
4861
for _ , s := range sl .Items {
@@ -4924,6 +4946,7 @@ func WaitForPersistentVolumeClaimDeleted(c clientset.Interface, ns string, pvcNa
4924
4946
return fmt .Errorf ("PersistentVolumeClaim %s is not removed from the system within %v" , pvcName , timeout )
4925
4947
}
4926
4948
4949
+ // GetClusterZones returns the values of zone label collected from all nodes.
4927
4950
func GetClusterZones (c clientset.Interface ) (sets.String , error ) {
4928
4951
nodes , err := c .CoreV1 ().Nodes ().List (metav1.ListOptions {})
4929
4952
if err != nil {
0 commit comments