Skip to content

Commit

Permalink
Merge pull request #146 from dobesv/ipd-conflict-avoidance
Browse files Browse the repository at this point in the history
Fix IP address calculation when there are multiple services in the same namespace
  • Loading branch information
cjimti committed Sep 23, 2020
2 parents 16c7eeb + 332f6be commit 8137f22
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cmd/kubefwd/services/services.go
Expand Up @@ -222,7 +222,6 @@ Try:
// ipD is the class D for the local IP address
// increment this for each service in each cluster
ipC := 27
ipD := 1

stopListenCh := make(chan struct{})

Expand Down Expand Up @@ -276,9 +275,11 @@ Try:
log.Fatalf("Error creating k8s RestClient: %s\n", err.Error())
}

for ii, namespace := range namespaces {
ipD := 1

for _, namespace := range namespaces {
nsWatchesDone.Add(1)
go func(ctx string, namespace string, ipC int, ipD int) {
go func(ctx string, namespace string, ipC int) {
nameSpaceOpts := NamespaceOpts{
ClientSet: clientSet,
Context: ctx,
Expand All @@ -290,13 +291,13 @@ Try:
RESTClient: restClient,
ShortName: !useFullName,
IpC: byte(ipC),
IpD: ipD,
IpD: &ipD,
Domain: domain,
ManualStopChannel: stopListenCh,
}
nameSpaceOpts.watchServiceEvents(stopListenCh)
nsWatchesDone.Done()
}(ctx, namespace, ipC+i, ipD+ii)
}(ctx, namespace, ipC+i)
}
}

Expand All @@ -320,7 +321,7 @@ type NamespaceOpts struct {
RESTClient *restclient.RESTClient
ShortName bool
IpC byte
IpD int
IpD *int
Domain string
ManualStopChannel chan struct{}
}
Expand Down Expand Up @@ -386,7 +387,7 @@ func (opts *NamespaceOpts) AddServiceHandler(obj interface{}) {
RESTClient: opts.RESTClient,
ShortName: opts.ShortName,
IpC: opts.IpC,
IpD: &opts.IpD,
IpD: opts.IpD,
Domain: opts.Domain,
PodLabelSelector: selector,
NamespaceIPLock: opts.NamespaceIPLock,
Expand Down

0 comments on commit 8137f22

Please sign in to comment.