Skip to content

Commit

Permalink
etcd: allow changing listening address
Browse files Browse the repository at this point in the history
Change-Id: I921f9ff41c48af3e88f6d6130c024a1d37b88691
Reviewed-on: https://softwarefactory-project.io/r/7498
Reviewed-by: Sylvain Afchain <safchain@gmail.com>
Tested-by: Sylvain Afchain <safchain@gmail.com>
Workflow: Sylvain Afchain <safchain@gmail.com>
Tested-by: Jenkins CI <jenkins@softwarefactory-project.io>
  • Loading branch information
lebauce authored and Jenkins CI committed Apr 25, 2017
1 parent c56cf49 commit e23c80a
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func init() {
cfg.SetDefault("netns.run_path", "/var/run/netns")
cfg.SetDefault("etcd.data_dir", "/var/lib/skydive/etcd")
cfg.SetDefault("etcd.embedded", true)
cfg.SetDefault("etcd.port", 2379)
cfg.SetDefault("etcd.listen", "localhost:2379")
cfg.SetDefault("auth.type", "noauth")
cfg.SetDefault("auth.keystone.tenant", "admin")
cfg.SetDefault("storage.orientdb.addr", "http://localhost:2480")
Expand Down
1 change: 1 addition & 0 deletions contrib/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
- SKYDIVE_STORAGE_ELASTICSEARCH_HOST=elasticsearch:9200
- SKYDIVE_ANALYZER_STORAGE_BACKEND=elasticsearch
- SKYDIVE_GRAPH_BACKEND=elasticsearch
- SKYDIVE_ETCD_LISTEN=0.0.0.0:2379

skydive-agent:
image: skydive/skydive
Expand Down
8 changes: 5 additions & 3 deletions contrib/kubernetes/skydive.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ spec:
value: elasticsearch
- name: SKYDIVE_GRAPH_BACKEND
value: elasticsearch
- name: SKYDIVE_ETCD_LISTEN
value: 0.0.0.0:2379
- name: skydive-elasticsearch
image: elasticsearch:2
ports:
Expand Down Expand Up @@ -92,6 +94,6 @@ spec:
- name: run
hostPath:
path: /var/run/netns
# - name: ovsdb
# hostPath:
# path: /var/run/openvswitch/db.sock
- name: ovsdb
hostPath:
path: /var/run/openvswitch/db.sock
2 changes: 2 additions & 0 deletions contrib/openshift/skydive-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ objects:
value: elasticsearch
- name: SKYDIVE_GRAPH_BACKEND
value: elasticsearch
- name: SKYDIVE_ETCD_LISTEN
value: 0.0.0.0:2379
image: skydive/skydive
imagePullPolicy: Always
livenessProbe:
Expand Down
1 change: 1 addition & 0 deletions contrib/vagrant/setup-analyzer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ analyzer:
- TOR1_PORT2 -> *[Type=host,Name=agent2]/eth1
etcd:
client_timeout: 100
listen: 0.0.0.0:2379
graph:
backend: elasticsearch
elasticsearch:
Expand Down
5 changes: 3 additions & 2 deletions devstack/plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SKYDIVE_ANALYZER_LISTEN=${SKYDIVE_ANALYZER_LISTEN:-$SERVICE_HOST:8082}
SKYDIVE_ANALYZERS=${SKYDIVE_ANALYZERS:-$SKYDIVE_ANALYZER_LISTEN}

# Configure the skydive agent with the etcd server address
SKYDIVE_AGENT_ETCD=${SKYDIVE_AGENT_ETCD:-http://$SERVICE_HOST:2379}
SKYDIVE_AGENT_ETCD=${SKYDIVE_AGENT_ETCD:-$SERVICE_HOST:2379}

# ip:port address on which skydive agent listens for connections.
SKYDIVE_AGENT_LISTEN=${SKYDIVE_AGENT_LISTEN:-"127.0.0.1:8081"}
Expand Down Expand Up @@ -165,8 +165,9 @@ openstack:
etcd:
servers:
- $SKYDIVE_AGENT_ETCD
- http://$SKYDIVE_AGENT_ETCD
data_dir: /tmp/skydive-etcd
listen: $SKYDIVE_AGENT_ETCD
graph:
backend: elasticsearch
Expand Down
1 change: 1 addition & 0 deletions etc/skydive.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ auth:
etcd:
# when 'embedded' is set to true, the analyzer will start an embedded etcd server
# embedded: true
# listen: localhost:2379

# both the analyzers and the agents make use of etcd
# servers:
Expand Down
24 changes: 13 additions & 11 deletions etcd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/coreos/etcd/pkg/osutil"
"github.com/coreos/etcd/pkg/types"

"github.com/skydive-project/skydive/common"
"github.com/skydive-project/skydive/config"

"golang.org/x/net/context"
Expand All @@ -45,9 +46,6 @@ import (
const (
memberName = "skydive"
startTimeout = 10 * time.Second
// No peer URL exists but etcd doesn't allow the value to be empty.
peerURL = "http://localhost:2379"
clusterCfg = memberName + "=" + peerURL
)

// EmbeddedEtcd provides a single node etcd server.
Expand All @@ -58,10 +56,10 @@ type EmbeddedEtcd struct {
dataDir string
}

func NewEmbeddedEtcd(port int, dataDir string) (*EmbeddedEtcd, error) {
func NewEmbeddedEtcd(sa common.ServiceAddress, dataDir string) (*EmbeddedEtcd, error) {
var err error
se := &EmbeddedEtcd{Port: port}
se.listener, err = net.Listen("tcp", fmt.Sprintf(":%d", port))
se := &EmbeddedEtcd{Port: sa.Port}
se.listener, err = net.Listen("tcp", fmt.Sprintf("%s:%d", sa.Addr, sa.Port))
if err != nil {
return nil, err
}
Expand All @@ -73,7 +71,8 @@ func NewEmbeddedEtcd(port int, dataDir string) (*EmbeddedEtcd, error) {
return nil, err
}

peerURLs, err := types.NewURLs([]string{peerURL})
endpoint := fmt.Sprintf("http://%s:%d", sa.Addr, sa.Port)
peerURLs, err := types.NewURLs([]string{endpoint})
if err != nil {
se.Stop()
return nil, err
Expand Down Expand Up @@ -106,7 +105,7 @@ func NewEmbeddedEtcd(port int, dataDir string) (*EmbeddedEtcd, error) {
// Wait for etcd server to be ready
t := time.Now().Add(startTimeout)
etcdClient, err := etcd.New(etcd.Config{
Endpoints: []string{fmt.Sprintf("http://localhost:%d", port)},
Endpoints: []string{endpoint},
Transport: etcd.DefaultTransport,
HeaderTimeoutPerRequest: time.Second,
})
Expand All @@ -130,9 +129,12 @@ func NewEmbeddedEtcd(port int, dataDir string) (*EmbeddedEtcd, error) {

func NewEmbeddedEtcdFromConfig() (*EmbeddedEtcd, error) {
dataDir := config.GetConfig().GetString("etcd.data_dir")
port := config.GetConfig().GetInt("etcd.port")

return NewEmbeddedEtcd(port, dataDir)
listen := config.GetConfig().GetString("etcd.listen")
sa, err := common.ServiceAddressFromString(listen)
if err != nil {
return nil, err
}
return NewEmbeddedEtcd(sa, dataDir)
}

func (se *EmbeddedEtcd) Stop() error {
Expand Down
1 change: 1 addition & 0 deletions scripts/scale.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ etcd:
data_dir: $TEMP_DIR/$NAME-etcd
servers:
- http://$ETCD
listen: $ETCD
storage:
elasticsearch:
host: $ELASTICSEARCH
Expand Down

0 comments on commit e23c80a

Please sign in to comment.