Skip to content

Commit

Permalink
feat(etcd): support external standalone etcd (#595)
Browse files Browse the repository at this point in the history
* feat(etcd): init

* fix(statuscontroller): remove log

* fix(option): add comment

* fix(chart): fix typo

* style(option): revert break line
  • Loading branch information
aniaan authored and localvar committed Jun 13, 2022
1 parent de7ebb6 commit fc4762e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 13 deletions.
7 changes: 7 additions & 0 deletions helm-charts/easegress/templates/ConfigMap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@ data:
eg-secondary.yaml: |
cluster-name: easegress
cluster-role: secondary
use-standalone-etcd: {{ .Values.cluster.useStandaloneEtcd }}
cluster:
primary-listen-peer-urls:
{{ if .Values.cluster.useStandaloneEtcd }}
{{- range $i, $endpoint := .Values.cluster.standaloneEtcdEndpoints }}
- {{ $endpoint }}
{{ end }}
{{ else }}
- http:https://{{ .Release.Name }}-0.easegress-hs.{{ .Release.Namespace }}:2380
{{ end }}
api-addr: 0.0.0.0:2381
data-dir: /opt/easegress/data
wal-dir: ""
Expand Down
3 changes: 3 additions & 0 deletions helm-charts/easegress/templates/Service.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if not .Values.cluster.useStandaloneEtcd }}
apiVersion: v1
kind: Service
metadata:
Expand All @@ -24,6 +25,8 @@ spec:

---

{{- end }}

apiVersion: v1
kind: Service
metadata:
Expand Down
11 changes: 7 additions & 4 deletions helm-charts/easegress/templates/StatefulSet.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{{- if eq .Values.cluster.volumeType "emptyDir" }}
{{- if ne (int .Values.cluster.primaryReplicas) 1 }}
{{- fail "When .Values.cluster.volumeType is 'emptyDir', .Values.cluster.primaryReplicas should be 1" }}
{{- if not .Values.cluster.useStandaloneEtcd }}
{{- if eq .Values.cluster.volumeType "emptyDir" }}
{{- if ne (int .Values.cluster.primaryReplicas) 1 }}
{{- fail "When .Values.cluster.volumeType is 'emptyDir', .Values.cluster.primaryReplicas should be 1" }}
{{- end }}
{{- end }}
{{- end }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
Expand Down Expand Up @@ -96,3 +97,5 @@ spec:
storageClassName: easegress-storage
volumeMode: Filesystem
{{- end }}

{{- end }}
4 changes: 4 additions & 0 deletions helm-charts/easegress/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ cluster:

secondaryReplicas: 0

useStandaloneEtcd: false
standaloneEtcdEndpoints:
# - endpoint-1

# log path inside container
log:
path: /opt/easegress/log
23 changes: 14 additions & 9 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,23 @@ func (c *cluster) checkClusterName() error {
return fmt.Errorf("failed to check cluster name: %v", err)
}

if value == nil {
if value != nil {
if c.opt.ClusterName != *value {
err := fmt.Errorf("cluster names mismatch, local(%s) != existed(%s)",
c.opt.ClusterName, *value)
logger.Errorf("%v", err)
panic(err)
}
} else if c.opt.UseStandaloneEtcd {
err := c.Put(c.Layout().ClusterNameKey(), c.opt.ClusterName)
if err != nil {
return fmt.Errorf("register cluster name %s failed: %v",
c.opt.ClusterName, err)
}
} else {
return fmt.Errorf("key %s not found", c.Layout().ClusterNameKey())
}

if c.opt.ClusterName != *value {
err := fmt.Errorf("cluster names mismatch, local(%s) != existed(%s)",
c.opt.ClusterName, *value)
logger.Errorf("%v", err)
panic(err)
}

return nil
}

Expand Down Expand Up @@ -447,7 +453,6 @@ func (c *cluster) initLease() error {

}
return c.grantNewLease()

}

func (c *cluster) grantNewLease() error {
Expand Down
7 changes: 7 additions & 0 deletions pkg/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type Options struct {
InitialObjectConfigFiles []string `yaml:"initial-object-config-files"`

// cluster options
UseStandaloneEtcd bool `yaml:"use-standalone-etcd"`
ClusterName string `yaml:"cluster-name"`
ClusterRole string `yaml:"cluster-role"`
ClusterRequestTimeout string `yaml:"cluster-request-timeout"`
Expand Down Expand Up @@ -137,6 +138,7 @@ func New() *Options {
opt.flags.BoolVar(&opt.SignalUpgrade, "signal-upgrade", false, "Send an upgrade signal to the server based on the local pid file, then exit. The original server will start a graceful upgrade after signal received.")
opt.flags.StringVar(&opt.Name, "name", "eg-default-name", "Human-readable name for this member.")
opt.flags.StringToStringVar(&opt.Labels, "labels", nil, "The labels for the instance of Easegress.")
opt.flags.BoolVar(&opt.UseStandaloneEtcd, "use-standalone-etcd", false, "Use standalone etcd instead of embedded .")
addClusterVars(opt)
opt.flags.StringVar(&opt.APIAddr, "api-addr", "localhost:2381", "Address([host]:port) to listen on for administration traffic.")
opt.flags.BoolVar(&opt.Debug, "debug", false, "Flag to set lowest log level from INFO downgrade DEBUG.")
Expand Down Expand Up @@ -232,6 +234,11 @@ func (opt *Options) Parse() (string, error) {
}

opt.renameLegacyClusterRoles()

if opt.UseStandaloneEtcd {
opt.ClusterRole = "secondary" // when using external standalone etcd, the cluster role cannot be "primary"
}

err = opt.validate()
if err != nil {
return "", err
Expand Down

0 comments on commit fc4762e

Please sign in to comment.