Skip to content

Commit d3c9138

Browse files
authored
Merge pull request #561 from abhinandanpb/service_link
Fix for service ref count issue
2 parents 7cefca8 + 9ae1d06 commit d3c9138

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

netmaster/master/servicelb.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ limitations under the License.
1616
package master
1717

1818
import (
19+
"reflect"
20+
"strings"
21+
1922
log "github.com/Sirupsen/logrus"
2023
"github.com/contiv/netplugin/core"
2124
"github.com/contiv/netplugin/netmaster/intent"
2225
"github.com/contiv/netplugin/netmaster/mastercfg"
2326
"github.com/contiv/netplugin/utils"
24-
"reflect"
25-
"strings"
2627
)
2728

2829
//CreateServiceLB adds to the etcd state

netmaster/objApi/apiController.go

+50
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,12 @@ func (ac *APIController) NetworkDelete(network *contivModel.Network) error {
10471047
network.NetworkName, epgCount)
10481048
}
10491049

1050+
svcCount := len(network.LinkSets.Servicelbs)
1051+
if svcCount != 0 {
1052+
return core.Errorf("cannot delete %s has %d services ",
1053+
network.NetworkName, svcCount)
1054+
}
1055+
10501056
// Remove link
10511057
modeldb.RemoveLinkSet(&tenant.LinkSets.Networks, network)
10521058

@@ -1868,6 +1874,20 @@ func (ac *APIController) ServiceLBCreate(serviceCfg *contivModel.ServiceLB) erro
18681874
return core.Errorf("Invalid Port maping . Port format is - Port:TargetPort:Protocol")
18691875
}
18701876

1877+
if serviceCfg.TenantName == "" {
1878+
return core.Errorf("Invalid tenant name")
1879+
}
1880+
1881+
tenant := contivModel.FindTenant(serviceCfg.TenantName)
1882+
if tenant == nil {
1883+
return core.Errorf("Tenant %s not found", serviceCfg.TenantName)
1884+
}
1885+
1886+
network := contivModel.FindNetwork(serviceCfg.TenantName + ":" + serviceCfg.NetworkName)
1887+
if network == nil {
1888+
return core.Errorf("Network %s not found", serviceCfg.NetworkName)
1889+
}
1890+
18711891
// Get the state driver
18721892
stateDriver, err := utils.GetStateDriver()
18731893
if err != nil {
@@ -1900,6 +1920,19 @@ func (ac *APIController) ServiceLBCreate(serviceCfg *contivModel.ServiceLB) erro
19001920
log.Errorf("Error creating service {%+v}. Err: %v", serviceIntentCfg.ServiceName, err)
19011921
return err
19021922
}
1923+
// Setup links
1924+
if tenant != nil {
1925+
modeldb.AddLink(&serviceCfg.Links.Tenant, tenant)
1926+
modeldb.AddLinkSet(&tenant.LinkSets.Servicelbs, serviceCfg)
1927+
tenant.Write()
1928+
}
1929+
1930+
// Setup links
1931+
if network != nil {
1932+
modeldb.AddLink(&serviceCfg.Links.Network, network)
1933+
modeldb.AddLinkSet(&network.LinkSets.Servicelbs, serviceCfg)
1934+
network.Write()
1935+
}
19031936
return nil
19041937

19051938
}
@@ -1943,6 +1976,23 @@ func (ac *APIController) ServiceLBDelete(serviceCfg *contivModel.ServiceLB) erro
19431976
log.Errorf("Error deleting Service Load Balancer object {%+v}. Err: %v", serviceCfg.ServiceName, err)
19441977
return err
19451978
}
1979+
// Find the tenant
1980+
tenant := contivModel.FindTenant(serviceCfg.TenantName)
1981+
if tenant == nil {
1982+
return core.Errorf("Tenant %s not found", serviceCfg.TenantName)
1983+
}
1984+
1985+
modeldb.RemoveLinkSet(&tenant.LinkSets.Servicelbs, serviceCfg)
1986+
tenant.Write()
1987+
1988+
nwKey := serviceCfg.TenantName + ":" + serviceCfg.NetworkName
1989+
network := contivModel.FindNetwork(nwKey)
1990+
if network == nil {
1991+
return core.Errorf("Network %s not found in tenant %s", serviceCfg.NetworkName, serviceCfg.TenantName)
1992+
}
1993+
modeldb.RemoveLinkSet(&network.LinkSets.Servicelbs, serviceCfg)
1994+
network.Write()
1995+
19461996
return nil
19471997

19481998
}

0 commit comments

Comments
 (0)