func (l *L7) checkForwardingRule(name, proxyLink, ip, portRange string) (fw *compute.ForwardingRule, err error) { fw, _ = l.cloud.GetGlobalForwardingRule(name) if fw != nil && (ip != "" && fw.IPAddress != ip || fw.PortRange != portRange) { glog.Warningf("Recreating forwarding rule %v(%v), so it has %v(%v)", fw.IPAddress, fw.PortRange, ip, portRange) if err := l.cloud.DeleteGlobalForwardingRule(name); err != nil { if !utils.IsHTTPErrorCode(err, http.StatusNotFound) { return nil, err } } fw = nil } if fw == nil { parts := strings.Split(proxyLink, "/") glog.Infof("Creating forwarding rule for proxy %v and ip %v:%v", parts[len(parts)-1:], ip, portRange) fw, err = l.cloud.CreateGlobalForwardingRule(proxyLink, ip, name, portRange) if err != nil { return nil, err } } // TODO: If the port range and protocol don't match, recreate the rule if utils.CompareLinks(fw.Target, proxyLink) { glog.V(3).Infof("Forwarding rule %v already exists", fw.Name) } else { glog.Infof("Forwarding rule %v has the wrong proxy, setting %v overwriting %v", fw.Name, fw.Target, proxyLink) if err := l.cloud.SetProxyForGlobalForwardingRule(fw, proxyLink); err != nil { return nil, err } } return fw, nil }
func (l *L7) checkProxy() (err error) { if l.um == nil { return fmt.Errorf("Cannot create proxy without urlmap.") } proxyName := l.namer.Truncate(fmt.Sprintf("%v-%v", targetProxyPrefix, l.Name)) proxy, _ := l.cloud.GetTargetHttpProxy(proxyName) if proxy == nil { glog.Infof("Creating new http proxy for urlmap %v", l.um.Name) proxy, err = l.cloud.CreateTargetHttpProxy(l.um, proxyName) if err != nil { return err } l.tp = proxy return nil } if !utils.CompareLinks(proxy.UrlMap, l.um.SelfLink) { glog.Infof("Proxy %v has the wrong url map, setting %v overwriting %v", proxy.Name, l.um, proxy.UrlMap) if err := l.cloud.SetUrlMapForTargetHttpProxy(proxy, l.um); err != nil { return err } } l.tp = proxy return nil }
func (l *L7) checkForwardingRule() (err error) { if l.tp == nil { return fmt.Errorf("Cannot create forwarding rule without proxy.") } forwardingRuleName := l.namer.Truncate(fmt.Sprintf("%v-%v", forwardingRulePrefix, l.Name)) fw, _ := l.cloud.GetGlobalForwardingRule(forwardingRuleName) if fw == nil { glog.Infof("Creating forwarding rule for proxy %v", l.tp.Name) fw, err = l.cloud.CreateGlobalForwardingRule( l.tp, forwardingRuleName, defaultPortRange) if err != nil { return err } l.fw = fw return nil } // TODO: If the port range and protocol don't match, recreate the rule if utils.CompareLinks(fw.Target, l.tp.SelfLink) { glog.Infof("Forwarding rule %v already exists", fw.Name) l.fw = fw return nil } glog.Infof("Forwarding rule %v has the wrong proxy, setting %v overwriting %v", fw.Name, fw.Target, l.tp.SelfLink) if err := l.cloud.SetProxyForGlobalForwardingRule(fw, l.tp); err != nil { return err } l.fw = fw return nil }
func (l *L7) checkHttpsProxy() (err error) { if l.sslCert == nil { glog.V(3).Infof("No SSL certificates for %v, will not create HTTPS proxy.", l.Name) return nil } if l.um == nil { return fmt.Errorf("No UrlMap for %v, will not create HTTPS proxy.", l.Name) } proxyName := l.namer.Truncate(fmt.Sprintf("%v-%v", targetHTTPSProxyPrefix, l.Name)) proxy, _ := l.cloud.GetTargetHttpsProxy(proxyName) if proxy == nil { glog.Infof("Creating new https proxy for urlmap %v", l.um.Name) proxy, err = l.cloud.CreateTargetHttpsProxy(l.um, l.sslCert, proxyName) if err != nil { return err } l.tps = proxy return nil } if !utils.CompareLinks(proxy.UrlMap, l.um.SelfLink) { glog.Infof("Https proxy %v has the wrong url map, setting %v overwriting %v", proxy.Name, l.um, proxy.UrlMap) if err := l.cloud.SetUrlMapForTargetHttpsProxy(proxy, l.um); err != nil { return err } } cert := proxy.SslCertificates[0] if !utils.CompareLinks(cert, l.sslCert.SelfLink) { glog.Infof("Https proxy %v has the wrong ssl certs, setting %v overwriting %v", proxy.Name, l.sslCert.SelfLink, cert) if err := l.cloud.SetSslCertificateForTargetHttpsProxy(proxy, l.sslCert); err != nil { return err } } glog.V(3).Infof("Created target https proxy %v", proxy.Name) l.tps = proxy return nil }
// edgeHop checks the links of the given backend by executing an edge hop. // It fixes broken links. func (b *Backends) edgeHop(be *compute.BackendService, ig *compute.InstanceGroup) error { if len(be.Backends) == 1 && utils.CompareLinks(be.Backends[0].Group, ig.SelfLink) { return nil } glog.Infof("Backend %v has a broken edge, adding link to %v", be.Name, ig.Name) be.Backends = []*compute.Backend{ {Group: ig.SelfLink}, } if err := b.cloud.UpdateBackendService(be); err != nil { return err } return nil }