Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subnet: Move etcd files into their own package. #631

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ TAG?=$(shell git describe --tags --dirty)
ARCH?=amd64

# These variables can be overridden by setting an environment variable.
TEST_PACKAGES?=pkg/ip subnet
TEST_PACKAGES?=pkg/ip subnet subnet/etcdv2
TEST_PACKAGES_EXPANDED=$(TEST_PACKAGES:%=github.com/coreos/flannel/%)
PACKAGES?=$(TEST_PACKAGES) network
PACKAGES_EXPANDED=$(PACKAGES:%=github.com/coreos/flannel/%)
Expand Down
27 changes: 14 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,31 @@ import (

"github.com/coreos/flannel/network"
"github.com/coreos/flannel/subnet"
"github.com/coreos/flannel/subnet/etcdv2"
"github.com/coreos/flannel/subnet/kube"
"github.com/coreos/flannel/version"

// Backends need to be imported for their init() to get executed and them to register
_ "github.com/coreos/flannel/backend/alivpc"
_ "github.com/coreos/flannel/backend/alloc"
_ "github.com/coreos/flannel/backend/awsvpc"
_ "github.com/coreos/flannel/backend/gce"
_ "github.com/coreos/flannel/backend/hostgw"
_ "github.com/coreos/flannel/backend/udp"
_ "github.com/coreos/flannel/backend/vxlan"
_ "github.com/coreos/flannel/backend/alivpc"
)

type CmdLineOpts struct {
etcdEndpoints string
etcdPrefix string
etcdKeyfile string
etcdCertfile string
etcdCAFile string
etcdUsername string
etcdPassword string
help bool
version bool
kubeSubnetMgr bool
etcdEndpoints string
etcdPrefix string
etcdKeyfile string
etcdCertfile string
etcdCAFile string
etcdUsername string
etcdPassword string
help bool
version bool
kubeSubnetMgr bool
}

var opts CmdLineOpts
Expand All @@ -75,7 +76,7 @@ func newSubnetManager() (subnet.Manager, error) {
return kube.NewSubnetManager()
}

cfg := &subnet.EtcdConfig{
cfg := &etcdv2.EtcdConfig{
Endpoints: strings.Split(opts.etcdEndpoints, ","),
Keyfile: opts.etcdKeyfile,
Certfile: opts.etcdCertfile,
Expand All @@ -85,7 +86,7 @@ func newSubnetManager() (subnet.Manager, error) {
Password: opts.etcdPassword,
}

return subnet.NewLocalManager(cfg)
return etcdv2.NewLocalManager(cfg)
}

func main() {
Expand Down
19 changes: 0 additions & 19 deletions subnet/clock.go

This file was deleted.

3 changes: 2 additions & 1 deletion subnet/local_manager.go → subnet/etcdv2/local_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package subnet
package etcdv2

import (
"errors"
Expand All @@ -22,6 +22,7 @@ import (

etcd "github.com/coreos/etcd/client"
"github.com/coreos/flannel/pkg/ip"
. "github.com/coreos/flannel/subnet"
log "github.com/golang/glog"
"golang.org/x/net/context"
)
Expand Down
2 changes: 1 addition & 1 deletion subnet/mock_etcd.go → subnet/etcdv2/mock_etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package subnet
package etcdv2

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package subnet
package etcdv2

import (
"fmt"
Expand Down
14 changes: 9 additions & 5 deletions subnet/mock_registry.go → subnet/etcdv2/mock_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package subnet
package etcdv2

import (
"fmt"
Expand All @@ -21,11 +21,15 @@ import (
"time"

etcd "github.com/coreos/etcd/client"
"github.com/jonboulle/clockwork"
"golang.org/x/net/context"

"github.com/coreos/flannel/pkg/ip"
. "github.com/coreos/flannel/subnet"
)

var clock clockwork.Clock = clockwork.NewRealClock()

type netwk struct {
config string
subnets []Lease
Expand Down Expand Up @@ -168,7 +172,7 @@ func (msr *MockSubnetRegistry) createSubnet(ctx context.Context, network string,
Subnet: sn,
Attrs: *attrs,
Expiration: exp,
asof: msr.index,
Asof: msr.index,
}
n.subnets = append(n.subnets, l)

Expand Down Expand Up @@ -205,7 +209,7 @@ func (msr *MockSubnetRegistry) updateSubnet(ctx context.Context, network string,
}

sub.Attrs = *attrs
sub.asof = msr.index
sub.Asof = msr.index
sub.Expiration = exp
n.subnets[i] = sub
n.sendSubnetEvent(sn, event{
Expand Down Expand Up @@ -237,7 +241,7 @@ func (msr *MockSubnetRegistry) deleteSubnet(ctx context.Context, network string,

n.subnets[i] = n.subnets[len(n.subnets)-1]
n.subnets = n.subnets[:len(n.subnets)-1]
sub.asof = msr.index
sub.Asof = msr.index
n.sendSubnetEvent(sn, event{
Event{
Type: EventRemoved,
Expand Down Expand Up @@ -332,7 +336,7 @@ func (msr *MockSubnetRegistry) expireSubnet(network string, sn ip.IP4Net) {
msr.index += 1
n.subnets[i] = n.subnets[len(n.subnets)-1]
n.subnets = n.subnets[:len(n.subnets)-1]
sub.asof = msr.index
sub.Asof = msr.index
n.sendSubnetEvent(sn, event{
Event{
Type: EventRemoved,
Expand Down
8 changes: 6 additions & 2 deletions subnet/mock_subnet.go → subnet/etcdv2/mock_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package subnet
package etcdv2

func NewMockManager(registry *MockSubnetRegistry) Manager {
import (
"github.com/coreos/flannel/subnet"
)

func NewMockManager(registry *MockSubnetRegistry) subnet.Manager {
return newLocalManager(registry)
}
2 changes: 1 addition & 1 deletion subnet/rand.go → subnet/etcdv2/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package subnet
package etcdv2

import (
"math/rand"
Expand Down
8 changes: 4 additions & 4 deletions subnet/registry.go → subnet/etcdv2/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package subnet
package etcdv2

import (
"encoding/json"
Expand All @@ -29,11 +29,11 @@ import (
"golang.org/x/net/context"

"github.com/coreos/flannel/pkg/ip"
. "github.com/coreos/flannel/subnet"
)

var (
subnetRegex *regexp.Regexp = regexp.MustCompile(`(\d+\.\d+.\d+.\d+)-(\d+)`)
errTryAgain = errors.New("try again")
errTryAgain = errors.New("try again")
)

type Registry interface {
Expand Down Expand Up @@ -414,7 +414,7 @@ func nodeToLease(node *etcd.Node) (*Lease, error) {
Subnet: *sn,
Attrs: *attrs,
Expiration: exp,
asof: node.ModifiedIndex,
Asof: node.ModifiedIndex,
}

return &lease, nil
Expand Down
3 changes: 2 additions & 1 deletion subnet/registry_test.go → subnet/etcdv2/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package subnet
package etcdv2

import (
"fmt"
Expand All @@ -24,6 +24,7 @@ import (
"golang.org/x/net/context"

"github.com/coreos/flannel/pkg/ip"
. "github.com/coreos/flannel/subnet"
)

func newTestEtcdRegistry(t *testing.T) (Registry, *mockEtcd) {
Expand Down
6 changes: 3 additions & 3 deletions subnet/subnet_test.go → subnet/etcdv2/subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package subnet
package etcdv2

import (
"encoding/json"
Expand All @@ -21,10 +21,10 @@ import (
"time"

etcd "github.com/coreos/etcd/client"
"github.com/coreos/flannel/pkg/ip"
. "github.com/coreos/flannel/subnet"
"github.com/jonboulle/clockwork"
"golang.org/x/net/context"

"github.com/coreos/flannel/pkg/ip"
)

func newDummyRegistry() *MockSubnetRegistry {
Expand Down
8 changes: 5 additions & 3 deletions subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"net"
"regexp"
"strconv"
"time"

Expand All @@ -27,8 +28,9 @@ import (
)

var (
ErrLeaseTaken = errors.New("subnet: lease already taken")
ErrNoMoreTries = errors.New("subnet: no more tries")
ErrLeaseTaken = errors.New("subnet: lease already taken")
ErrNoMoreTries = errors.New("subnet: no more tries")
subnetRegex *regexp.Regexp = regexp.MustCompile(`(\d+\.\d+.\d+.\d+)-(\d+)`)
)

type LeaseAttrs struct {
Expand All @@ -42,7 +44,7 @@ type Lease struct {
Attrs LeaseAttrs
Expiration time.Time

asof uint64
Asof uint64
}

func (l *Lease) Key() string {
Expand Down