Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb240c37

Browse files
committed
Merge pull requestsorintlab#129 from sgotti/kubernetesdiscovery_option
stolon: add --discovery-type option.
2 parentse7f61a6 +931ecfd commitb240c37

File tree

4 files changed

+48
-17
lines changed

4 files changed

+48
-17
lines changed

‎cmd/keeper/keeper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,6 @@ func (p *PostgresKeeper) usePGRewind() bool {
285285
}
286286

287287
func (p*PostgresKeeper)publish()error {
288-
ifkubernetes.OnKubernetes() {
289-
log.Infof("running under kubernetes. Not using store discovery")
290-
returnnil
291-
}
292288
discoveryInfo:=&cluster.KeeperDiscoveryInfo{
293289
ListenAddress:p.listenAddress,
294290
Port:p.port,
@@ -1052,6 +1048,10 @@ func keeper(cmd *cobra.Command, args []string) {
10521048

10531049
log.Infof("id: %s",id)
10541050

1051+
ifkubernetes.OnKubernetes() {
1052+
log.Infof("running under kubernetes.")
1053+
}
1054+
10551055
stop:=make(chanbool,0)
10561056
end:=make(chanerror,0)
10571057
sigs:=make(chan os.Signal,1)

‎cmd/sentinel/sentinel.go

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ var cmdSentinel = &cobra.Command{
5050
Run:sentinel,
5151
}
5252

53+
const (
54+
storeDiscovery="store"
55+
kubernetesDiscovery="kubernetes"
56+
)
57+
5358
typeconfigstruct {
5459
storeBackendstring
5560
storeEndpointsstring
@@ -60,6 +65,7 @@ type config struct {
6065
keeperKubeLabelSelectorstring
6166
initialClusterConfigstring
6267
kubernetesNamespacestring
68+
discoveryTypestring
6369
debugbool
6470
}
6571

@@ -74,7 +80,8 @@ func init() {
7480
cmdSentinel.PersistentFlags().StringVar(&cfg.keeperKubeLabelSelector,"keeper-kube-label-selector","","label selector for discoverying stolon-keeper(s) under kubernetes")
7581
cmdSentinel.PersistentFlags().StringVar(&cfg.keeperPort,"keeper-port","5431","stolon-keeper(s) listening port (used by kubernetes discovery)")
7682
cmdSentinel.PersistentFlags().StringVar(&cfg.initialClusterConfig,"initial-cluster-config","","a file providing the initial cluster config, used only at cluster initialization, ignored if cluster is already initialized")
77-
cmdSentinel.PersistentFlags().StringVar(&cfg.kubernetesNamespace,"kubernetes-namespace","default","the Kubernetes namespace stolon is deployed under")
83+
cmdSentinel.PersistentFlags().StringVar(&cfg.kubernetesNamespace,"kubernetes-namespace","default","the kubernetes namespace stolon is deployed under")
84+
cmdSentinel.PersistentFlags().StringVar(&cfg.discoveryType,"discovery-type","","discovery type (store or kubernetes). Default: detected")
7885
cmdSentinel.PersistentFlags().BoolVar(&cfg.debug,"debug",false,"enable debug logging")
7986
}
8087

@@ -241,23 +248,27 @@ func (s *Sentinel) GetBestStandby(cv *cluster.ClusterView, keepersState cluster.
241248
}
242249

243250
func (s*Sentinel)discover(ctx context.Context) (cluster.KeepersDiscoveryInfo,error) {
244-
ifkubernetes.OnKubernetes() {
251+
switchs.cfg.discoveryType {
252+
casestoreDiscovery:
253+
log.Debugf("using store discovery")
254+
returns.discoverStore(ctx)
255+
casekubernetesDiscovery:
256+
log.Debugf("using kubernetes discovery")
245257
ksdi:= cluster.KeepersDiscoveryInfo{}
246-
log.Debugf("running inside kubernetes")
247258
podsIPs,err:=s.getKubernetesPodsIPs(ctx)
248259
iferr!=nil {
249260
returnnil,fmt.Errorf("failed to get running pods ips: %v",err)
250261
}
251262
for_,podIP:=rangepodsIPs {
252-
ksdi=append(ksdi,&cluster.KeeperDiscoveryInfo{ListenAddress:podIP,Port:cfg.keeperPort})
263+
ksdi=append(ksdi,&cluster.KeeperDiscoveryInfo{ListenAddress:podIP,Port:s.cfg.keeperPort})
253264
}
254265
returnksdi,nil
266+
default:
267+
returnnil,fmt.Errorf("unknown discovery type")
255268
}
256-
257-
returns.discoverEtcd(ctx)
258269
}
259270

260-
func (s*Sentinel)discoverEtcd(ctx context.Context) (cluster.KeepersDiscoveryInfo,error) {
271+
func (s*Sentinel)discoverStore(ctx context.Context) (cluster.KeepersDiscoveryInfo,error) {
261272
returns.e.GetKeepersDiscoveryInfo()
262273
}
263274

@@ -279,7 +290,7 @@ func (s *Sentinel) getKubernetesPodsIPs(ctx context.Context) ([]string, error) {
279290
returnnil,err
280291
}
281292
q:=u.Query()
282-
q.Set("labelSelector",cfg.keeperKubeLabelSelector)
293+
q.Set("labelSelector",s.cfg.keeperKubeLabelSelector)
283294
u.RawQuery=q.Encode()
284295

285296
req,err:=http.NewRequest("GET",u.String(),nil)
@@ -620,8 +631,9 @@ func (s *Sentinel) isKeeperConverged(keeperState *cluster.KeeperState, cv *clust
620631
}
621632

622633
typeSentinelstruct {
623-
idstring
624-
e*store.StoreManager
634+
idstring
635+
cfg*config
636+
e*store.StoreManager
625637

626638
candidate*leadership.Candidate
627639
stopchanbool
@@ -638,7 +650,7 @@ type Sentinel struct {
638650
leaderMutex sync.Mutex
639651
}
640652

641-
funcNewSentinel(idstring,cfgconfig,stopchanbool,endchanbool) (*Sentinel,error) {
653+
funcNewSentinel(idstring,cfg*config,stopchanbool,endchanbool) (*Sentinel,error) {
642654
varinitialClusterNilConfig*cluster.NilConfig
643655
ifcfg.initialClusterConfig!="" {
644656
configData,err:=ioutil.ReadFile(cfg.initialClusterConfig)
@@ -661,6 +673,7 @@ func NewSentinel(id string, cfg config, stop chan bool, end chan bool) (*Sentine
661673

662674
return&Sentinel{
663675
id:id,
676+
cfg:cfg,
664677
e:e,
665678
listenAddress:cfg.listenAddress,
666679
port:cfg.port,
@@ -836,7 +849,17 @@ func sentinel(cmd *cobra.Command, args []string) {
836849
ifcfg.storeBackend=="" {
837850
log.Fatalf("store backend type required")
838851
}
839-
ifkubernetes.OnKubernetes() {
852+
ifcfg.discoveryType=="" {
853+
ifkubernetes.OnKubernetes() {
854+
cfg.discoveryType=kubernetesDiscovery
855+
}else {
856+
cfg.discoveryType=storeDiscovery
857+
}
858+
}
859+
ifcfg.discoveryType!=storeDiscovery&&cfg.discoveryType!=kubernetesDiscovery {
860+
log.Fatalf("unknown discovery type: %s",cfg.discoveryType)
861+
}
862+
ifcfg.discoveryType==kubernetesDiscovery {
840863
ifcfg.keeperKubeLabelSelector=="" {
841864
log.Fatalf("keeper-kube-label-selector must be define under kubernetes")
842865
}
@@ -852,7 +875,7 @@ func sentinel(cmd *cobra.Command, args []string) {
852875
signal.Notify(sigs,os.Interrupt,os.Kill)
853876
gosigHandler(sigs,stop)
854877

855-
s,err:=NewSentinel(id,cfg,stop,end)
878+
s,err:=NewSentinel(id,&cfg,stop,end)
856879
iferr!=nil {
857880
log.Fatalf("cannot create sentinel: %v",err)
858881
}

‎examples/kubernetes/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ In the [image](examples/kubernetes/image/docker) directory you'll find the Docke
1515
`sorintlab/stolon:master` is the one used by the kubernetes definitions in this example.
1616
For a more stable testing you can use`sorintlab/stolon:latest`
1717

18+
###Keepers discovery
19+
20+
When running inside a kubernetes cluster then sentinels will use the kubernetes APIs to discover keepers members. If, on your setup, this doesn't work (for example no api service certificates configured or https api serving disabled) you can disable it using the stolon-sentinel`--discovery-type=store` or exporting the`STSENTINEL_DISCOVERY_TYPE=store` environment variable (see the commented variable in the[stolon-sentinel](stolon-sentinel.yaml) replication controller definition.
21+
1822
##Cluster setup and tests
1923

2024
These example points to a single node etcd cluster on`10.245.1.1:2379` without tls. You can change the ST${COMPONENT}_STORE_ENDPOINTS environment variables in the definitions to point to the right etcd cluster.
2125

26+
2227
###Create the sentinel(s)
2328

2429
```

‎examples/kubernetes/stolon-sentinel.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ spec:
1919
env:
2020
-name:SENTINEL
2121
value:"true"
22+
# Uncomment this if kubernetes discovery doesn't work on your kubernetes cluster (for example no api service certificates configured or https api serving disabled)
23+
#- name: STSENTINEL_DISCOVERY_TYPE
24+
# value: "store"
2225
-name:STSENTINEL_CLUSTER_NAME
2326
value:"kube-stolon"
2427
-name:STSENTINEL_STORE_BACKEND

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp