mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-28 21:55:48 +00:00
Previously we'd just tear everything down and recreate it, which makes for a pretty bad experience because it causes downtime whenever the service controller restarts and has to make sure everything is in the desired state. This adds more code than I'd prefer, but makes it much cleaner and more organized than it was before, in my opinion. I didn't bother parallelizing anything because it's complex enough as it is, right now. It's consistently passing the existing e2es and worked when I tested manually, but this could definitely use additional e2e tests and/or some serious refactoring to make real unit tests feasible. I'll follow up with one or two e2e tests that make sense (updating an LB or killing the controller manager, perhaps).
99 lines
3.1 KiB
Go
99 lines
3.1 KiB
Go
/*
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
|
|
|
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 gce_cloud
|
|
|
|
import "testing"
|
|
|
|
func TestGetRegion(t *testing.T) {
|
|
gce := &GCECloud{
|
|
zone: "us-central1-b",
|
|
}
|
|
zones, ok := gce.Zones()
|
|
if !ok {
|
|
t.Fatalf("Unexpected missing zones impl")
|
|
}
|
|
zone, err := zones.GetZone()
|
|
if err != nil {
|
|
t.Fatalf("unexpected error %v", err)
|
|
}
|
|
if zone.Region != "us-central1" {
|
|
t.Errorf("Unexpected region: %s", zone.Region)
|
|
}
|
|
}
|
|
|
|
func TestComparingHostURLs(t *testing.T) {
|
|
tests := []struct {
|
|
host1 string
|
|
zone string
|
|
name string
|
|
expectEqual bool
|
|
}{
|
|
{
|
|
host1: "https://www.googleapis.com/compute/v1/projects/1234567/zones/us-central1-f/instances/kubernetes-node-fhx1",
|
|
zone: "us-central1-f",
|
|
name: "kubernetes-node-fhx1",
|
|
expectEqual: true,
|
|
},
|
|
{
|
|
host1: "https://www.googleapis.com/compute/v1/projects/cool-project/zones/us-central1-f/instances/kubernetes-node-fhx1",
|
|
zone: "us-central1-f",
|
|
name: "kubernetes-node-fhx1",
|
|
expectEqual: true,
|
|
},
|
|
{
|
|
host1: "https://www.googleapis.com/compute/v23/projects/1234567/zones/us-central1-f/instances/kubernetes-node-fhx1",
|
|
zone: "us-central1-f",
|
|
name: "kubernetes-node-fhx1",
|
|
expectEqual: true,
|
|
},
|
|
{
|
|
host1: "https://www.googleapis.com/compute/v24/projects/1234567/regions/us-central1/zones/us-central1-f/instances/kubernetes-node-fhx1",
|
|
zone: "us-central1-f",
|
|
name: "kubernetes-node-fhx1",
|
|
expectEqual: true,
|
|
},
|
|
{
|
|
host1: "https://www.googleapis.com/compute/v1/projects/1234567/zones/us-central1-f/instances/kubernetes-node-fhx1",
|
|
zone: "us-central1-c",
|
|
name: "kubernetes-node-fhx1",
|
|
expectEqual: false,
|
|
},
|
|
{
|
|
host1: "https://www.googleapis.com/compute/v1/projects/1234567/zones/us-central1-f/instances/kubernetes-node-fhx",
|
|
zone: "us-central1-f",
|
|
name: "kubernetes-node-fhx1",
|
|
expectEqual: false,
|
|
},
|
|
{
|
|
host1: "https://www.googleapis.com/compute/v1/projects/1234567/zones/us-central1-f/instances/kubernetes-node-fhx1",
|
|
zone: "us-central1-f",
|
|
name: "kubernetes-node-fhx",
|
|
expectEqual: false,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
link1 := hostURLToComparablePath(test.host1)
|
|
link2 := makeComparableHostPath(test.zone, test.name)
|
|
if test.expectEqual && link1 != link2 {
|
|
t.Errorf("expected link1 and link2 to be equal, got %s and %s", link1, link2)
|
|
} else if !test.expectEqual && link1 == link2 {
|
|
t.Errorf("expected link1 and link2 not to be equal, got %s and %s", link1, link2)
|
|
}
|
|
}
|
|
}
|