Log line cleanup
This commit is contained in:
parent
d83a15e91f
commit
e851054740
1 changed files with 39 additions and 39 deletions
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
@ -125,8 +124,14 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bs := getBackendServices()
|
bs := getBackendServices()
|
||||||
fmt.Println("Backend Services:", len(bs))
|
fmt.Println("Backend Services:")
|
||||||
fmt.Println("Instance Groups:", len(igs))
|
for _, b := range bs {
|
||||||
|
fmt.Println(" - ", b.Name)
|
||||||
|
}
|
||||||
|
fmt.Println("Instance Groups:")
|
||||||
|
for z, g := range igs {
|
||||||
|
fmt.Printf(" - %v (%v)\n", g.Name, z)
|
||||||
|
}
|
||||||
|
|
||||||
// Early return for special cases
|
// Early return for special cases
|
||||||
switch len(bs) {
|
switch len(bs) {
|
||||||
|
@ -156,6 +161,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateMultipleBackends() {
|
func updateMultipleBackends() {
|
||||||
|
fmt.Println("Creating temporary instance groups in relevant zones")
|
||||||
// Create temoprary instance groups
|
// Create temoprary instance groups
|
||||||
for zone, ig := range igs {
|
for zone, ig := range igs {
|
||||||
_, err := s.InstanceGroups.Get(projectID, zone, instanceGroupTemp).Do()
|
_, err := s.InstanceGroups.Get(projectID, zone, instanceGroupTemp).Do()
|
||||||
|
@ -165,7 +171,7 @@ func updateMultipleBackends() {
|
||||||
Zone: zone,
|
Zone: zone,
|
||||||
NamedPorts: ig.NamedPorts,
|
NamedPorts: ig.NamedPorts,
|
||||||
}
|
}
|
||||||
fmt.Println("Creating", instanceGroupTemp, "zone:", zone)
|
fmt.Printf(" - %v (%v)\n", instanceGroupTemp, zone)
|
||||||
op, err := s.InstanceGroups.Insert(projectID, zone, newIg).Do()
|
op, err := s.InstanceGroups.Insert(projectID, zone, newIg).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -178,28 +184,29 @@ func updateMultipleBackends() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Straddle both groups
|
// Straddle both groups
|
||||||
fmt.Println("Straddle both groups in backend services")
|
fmt.Println("Update backend services to point to original and temporary instance groups")
|
||||||
setBackendsTo(true, balancingModeInverse(targetBalancingMode), true, balancingModeInverse(targetBalancingMode))
|
setBackendsTo(true, balancingModeInverse(targetBalancingMode), true, balancingModeInverse(targetBalancingMode))
|
||||||
|
|
||||||
fmt.Println("Migrate instances to temporary group")
|
fmt.Println("Migrate instances to temporary group")
|
||||||
migrateInstances(instanceGroupName, instanceGroupTemp)
|
migrateInstances(instanceGroupName, instanceGroupTemp)
|
||||||
|
|
||||||
// Remove original backends to get rid of old balancing mode
|
// Remove original backends to get rid of old balancing mode
|
||||||
fmt.Println("Remove original backends")
|
fmt.Println("Update backend services to point only to temporary instance groups")
|
||||||
setBackendsTo(false, "", true, balancingModeInverse(targetBalancingMode))
|
setBackendsTo(false, "", true, balancingModeInverse(targetBalancingMode))
|
||||||
|
|
||||||
// Straddle both groups (creates backend services to original groups with target mode)
|
// Straddle both groups (creates backend services to original groups with target mode)
|
||||||
fmt.Println("Create backends pointing to original instance groups")
|
fmt.Println("Update backend services to point to both temporary and original (with new balancing mode) instance groups")
|
||||||
setBackendsTo(true, targetBalancingMode, true, balancingModeInverse(targetBalancingMode))
|
setBackendsTo(true, targetBalancingMode, true, balancingModeInverse(targetBalancingMode))
|
||||||
|
|
||||||
fmt.Println("Migrate instances back to original groups")
|
fmt.Println("Migrate instances back to original groups")
|
||||||
migrateInstances(instanceGroupTemp, instanceGroupName)
|
migrateInstances(instanceGroupTemp, instanceGroupName)
|
||||||
|
|
||||||
fmt.Println("Remove temporary backends")
|
fmt.Println("Update backend services to point only to original instance groups")
|
||||||
setBackendsTo(true, targetBalancingMode, false, "")
|
setBackendsTo(true, targetBalancingMode, false, "")
|
||||||
|
|
||||||
fmt.Println("Delete temporary instance groups")
|
fmt.Println("Delete temporary instance groups")
|
||||||
for z := range igs {
|
for z := range igs {
|
||||||
|
fmt.Printf(" - %v (%v)\n", instanceGroupTemp, z)
|
||||||
op, err := s.InstanceGroups.Delete(projectID, z, instanceGroupTemp).Do()
|
op, err := s.InstanceGroups.Delete(projectID, z, instanceGroupTemp).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Couldn't delete temporary instance group", instanceGroupTemp)
|
fmt.Println("Couldn't delete temporary instance group", instanceGroupTemp)
|
||||||
|
@ -211,11 +218,6 @@ func updateMultipleBackends() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sleep(d time.Duration) {
|
|
||||||
fmt.Println("Sleeping for", d.String())
|
|
||||||
time.Sleep(d)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setBackendsTo(orig bool, origMode string, temp bool, tempMode string) {
|
func setBackendsTo(orig bool, origMode string, temp bool, tempMode string) {
|
||||||
bs := getBackendServices()
|
bs := getBackendServices()
|
||||||
for _, bsi := range bs {
|
for _, bsi := range bs {
|
||||||
|
@ -241,6 +243,7 @@ func setBackendsTo(orig bool, origMode string, temp bool, tempMode string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bsi.Backends = union
|
bsi.Backends = union
|
||||||
|
fmt.Printf(" - %v\n", bsi.Name)
|
||||||
op, err := s.BackendServices.Update(projectID, bsi.Name, bsi).Do()
|
op, err := s.BackendServices.Update(projectID, bsi.Name, bsi).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -286,38 +289,33 @@ func typeOfBackends(bs []*compute.BackendService) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func migrateInstances(fromIG, toIG string) error {
|
func migrateInstances(fromIG, toIG string) error {
|
||||||
wg := sync.WaitGroup{}
|
|
||||||
for _, i := range instances {
|
for _, i := range instances {
|
||||||
wg.Add(1)
|
z := getResourceName(i.Zone, "zones")
|
||||||
go func(i *compute.Instance) {
|
fmt.Printf(" - %s (%s): ", i.Name, z)
|
||||||
z := getResourceName(i.Zone, "zones")
|
rr := &compute.InstanceGroupsRemoveInstancesRequest{Instances: []*compute.InstanceReference{{Instance: i.SelfLink}}}
|
||||||
fmt.Printf(" - %s (%s)\n", i.Name, z)
|
op, err := s.InstanceGroups.RemoveInstances(projectID, z, fromIG, rr).Do()
|
||||||
rr := &compute.InstanceGroupsRemoveInstancesRequest{Instances: []*compute.InstanceReference{{Instance: i.SelfLink}}}
|
if err != nil {
|
||||||
op, err := s.InstanceGroups.RemoveInstances(projectID, z, fromIG, rr).Do()
|
fmt.Println("Skipping error when removing instance from group", err)
|
||||||
if err != nil {
|
}
|
||||||
fmt.Println("Skipping error when removing instance from group", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = waitForZoneOp(op, z); err != nil {
|
if err = waitForZoneOp(op, z); err != nil {
|
||||||
fmt.Println("Failed to wait for operation: removing instance from group", err)
|
fmt.Println("Failed to wait for operation: removing instance from group", err)
|
||||||
}
|
}
|
||||||
|
fmt.Printf("removed from %v, ", fromIG)
|
||||||
|
|
||||||
ra := &compute.InstanceGroupsAddInstancesRequest{Instances: []*compute.InstanceReference{{Instance: i.SelfLink}}}
|
ra := &compute.InstanceGroupsAddInstancesRequest{Instances: []*compute.InstanceReference{{Instance: i.SelfLink}}}
|
||||||
op, err = s.InstanceGroups.AddInstances(projectID, z, toIG, ra).Do()
|
op, err = s.InstanceGroups.AddInstances(projectID, z, toIG, ra).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !strings.Contains(err.Error(), "memberAlreadyExists") { // GLBC already added the instance back to the IG
|
if !strings.Contains(err.Error(), "memberAlreadyExists") { // GLBC already added the instance back to the IG
|
||||||
fmt.Println("failed to add instance to new IG", i.Name, err)
|
fmt.Println("failed to add instance to new IG", i.Name, err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err = waitForZoneOp(op, z); err != nil {
|
if err = waitForZoneOp(op, z); err != nil {
|
||||||
fmt.Println("Failed to wait for operation: adding instance to group", err)
|
fmt.Println("Failed to wait for operation: adding instance to group", err)
|
||||||
}
|
}
|
||||||
wg.Done()
|
fmt.Printf("added to %v\n", toIG)
|
||||||
}(i)
|
|
||||||
time.Sleep(10 * time.Second)
|
|
||||||
}
|
}
|
||||||
wg.Wait()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,6 +382,8 @@ func getIGClusterIds() []string {
|
||||||
return ids
|
return ids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Below operations are copied from the GCE CloudProvider and modified to be static
|
||||||
|
|
||||||
func waitForOp(op *compute.Operation, getOperation func(operationName string) (*compute.Operation, error)) error {
|
func waitForOp(op *compute.Operation, getOperation func(operationName string) (*compute.Operation, error)) error {
|
||||||
if op == nil {
|
if op == nil {
|
||||||
return fmt.Errorf("operation must not be nil")
|
return fmt.Errorf("operation must not be nil")
|
||||||
|
|
Loading…
Reference in a new issue