Skip to content

Commit

Permalink
Merge pull request #11 from QingCloudAppcenter/etcd-v3.4.16-2.0.4
Browse files Browse the repository at this point in the history
Etcd v3.4.16 2.0.4
  • Loading branch information
yongchuanzhou authored Jun 7, 2023
2 parents 86159e3 + 3798cb7 commit d1e0663
Show file tree
Hide file tree
Showing 24 changed files with 1,462 additions and 117 deletions.
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/etcd.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<img src="./logo.png" alt="Logo" />
</p>
<h1 align="center">etcd on QingCloud</h1>
<h1 align="center">etcd on QingCloud </h1>

- [Product Page](https://appcenter.qingcloud.com/apps/app-fdyvu2wk)
1 change: 1 addition & 0 deletions ansible/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/files/tmp
/make.retry

2 changes: 1 addition & 1 deletion ansible/files/etc/confd/conf.d/make.sh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ mode = "0700"
keys = [
"/",
]
reload_cmd = "/opt/app/bin/make.sh; /opt/app/bin/ctl.sh update"
reload_cmd = "/opt/app/bin/make.sh; /opt/app/bin/ctl.sh configureDomainName; /opt/app/bin/ctl.sh update"

8 changes: 8 additions & 0 deletions ansible/files/etc/confd/conf.d/nodeexporter.sh.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[template]
src = "nodeexporter.sh.tmpl"
dest = "/opt/app/bin/nodeexporter.sh"
mode = "0700"
keys = [
"/",
]
reload_cmd = "/opt/app/bin/ctl.sh updateNodeexporterServer"
9 changes: 9 additions & 0 deletions ansible/files/etc/confd/conf.d/tls.sh.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[template]
src = "tls.sh.tmpl"
dest = "/opt/app/bin/tls.sh"
mode = "0700"
keys = [
"/",
]


59 changes: 58 additions & 1 deletion ansible/files/etc/confd/templates/01.header.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ set -e
{{- $myRole := replace (getv "/host/role") "_" "-" -1 }}
{{- $mySid := getv "/host/sid" }}
{{- $myIp := getv "/host/ip" }}
{{- $clusterDNS := getv "/env/cluster_DNS" ".etcdsvc.common" }}


{{- $addedInstances := ls "/adding-hosts/etcd_node" }}
{{- $deletedInstances := ls "/deleting-hosts/etcd_node" }}

{{- $addedProxyInstances := ls "/adding-hosts/etcd_proxy" }}
{{- $deletedProxyInstances := ls "/deleting-hosts/etcd_proxy" }}

{{- $isAdded := eq (len ($addedInstances | filter (getv "/host/instance_id"))) 1 }}
{{- $isDeleted := eq (len ($deletedInstances | filter (getv "/host/instance_id"))) 1 }}

Expand All @@ -28,8 +33,14 @@ map() {
done
}

{{- $enableTLS := getv "/env/enable_TLS" }}

buildEndpoint() {
echo -n http://${1#*=}:2379
{{- if eq "true" $enableTLS }}
echo -n https://${1#*=}:2379
{{- else }}
echo -n http://${1#*=}:2379
{{- end }}
}

allNodes="$(sort -V - << ALL_NODES_EOF
Expand All @@ -38,6 +49,14 @@ allNodes="$(sort -V - << ALL_NODES_EOF
{{- end }}
ALL_NODES_EOF
)"
allNodesDomain="$(sort -V - << ALL_NODES_EOF
{{- range ls "/hosts/etcd_node" }}
{{ getv (printf "/hosts/etcd_node/%s/sid" .) }}=etcd{{ getv (printf "/hosts/etcd_node/%s/sid" .) }}{{ $clusterDNS }}
{{- end }}
ALL_NODES_EOF
)"



stableNodes="$(sort -V - << STABLE_NODES_EOF
{{- range ls "/hosts/etcd_node" }}
Expand All @@ -51,3 +70,41 @@ STABLE_NODES_EOF
)"
stableEndpointLines=$(map buildEndpoint "$stableNodes")
stableEndpoints=$(echo $stableEndpointLines | tr " " ",")


stableNodesDomainName="$(sort -V - << STABLE_NODES_EOF
{{- range ls "/hosts/etcd_node" }}
{{- if not (len ($addedInstances | filter .)) }}
{{- if not (len ($deletedInstances | filter .)) }}
{{ getv (printf "/hosts/etcd_node/%s/sid" .) }}=etcd{{ getv (printf "/hosts/etcd_node/%s/sid" .) }}{{ $clusterDNS }}
{{- end }}
{{- end }}
{{- end }}
STABLE_NODES_EOF
)"


hostsDomainName="$(sort -V - << STABLE_NODES_EOF
{{- range ls "/hosts/etcd_node" }}
{{- if not (len ($addedInstances | filter .)) }}
{{- if not (len ($deletedInstances | filter .)) }}
{{ getv (printf "/hosts/etcd_node/%s/ip" .) }} etcd{{ getv (printf "/hosts/etcd_node/%s/sid" .) }}{{ $clusterDNS }}
{{- end }}
{{- end }}
{{- end }}
STABLE_NODES_EOF
)"


proxyHostsDomainName="$(sort -V - << STABLE_NODES_EOF
{{- range ls "/hosts/etcd_proxy" }}
{{ getv (printf "/hosts/etcd_proxy/%s/ip" .) }} proxy{{ getv (printf "/hosts/etcd_proxy/%s/sid" .) }}{{ $clusterDNS }}
{{- end }}
STABLE_NODES_EOF
)"






39 changes: 39 additions & 0 deletions ansible/files/etc/confd/templates/02.app.env.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,65 @@ addedNodes="$(sort -V - << ADDED_NODES_ASC_EOF
{{- end }}
ADDED_NODES_ASC_EOF
)"
addedNodesDomain="$(sort -V - << ADDED_NODES_ASC_EOF
{{- range $addedInstances }}
{{ getv (printf "/adding-hosts/etcd_node/%s/sid" .) }}=etcd{{ getv (printf "/hosts/etcd_node/%s/sid" .) }}{{ $clusterDNS }}
{{- end }}
ADDED_NODES_ASC_EOF
)"
addedNodesHostsDomainName="$(sort -V - << ADDED_NODES_ASC_EOF
{{- range $addedInstances }}
{{ getv (printf "/adding-hosts/etcd_node/%s/ip" .) }} etcd{{ getv (printf "/hosts/etcd_node/%s/sid" .) }}{{ $clusterDNS }}
{{- end }}
ADDED_NODES_ASC_EOF
)"
deletedNodes="$(sort -Vr - << DELETED_NODES_DESC_EOF
{{- range $deletedInstances }}
{{ getv (printf "/deleting-hosts/etcd_node/%s/sid" .) }}={{ getv (printf "/deleting-hosts/etcd_node/%s/ip" .) }}
{{- end }}
DELETED_NODES_DESC_EOF
)"
deletedNodesDomain="$(sort -Vr - << DELETED_NODES_DESC_EOF
{{- range $deletedInstances }}
{{ getv (printf "/deleting-hosts/etcd_node/%s/sid" .) }}=etcd{{ getv (printf "/hosts/etcd_node/%s/sid" .) }}{{ $clusterDNS }}
{{- end }}
DELETED_NODES_DESC_EOF
)"
deletedNodesHostsDomain="$(sort -Vr - << DELETED_NODES_DESC_EOF
{{- range $deletedInstances }}
{{ getv (printf "/deleting-hosts/etcd_node/%s/ip" .) }} etcd{{ getv (printf "/hosts/etcd_node/%s/sid" .) }}{{ $clusterDNS }}
{{- end }}
DELETED_NODES_DESC_EOF
)"
{{- end }}

changedVariables=$(updateAndCompareFile /opt/app/bin/.env << APP_ENV_FILE
CLUSTER_ID={{ getv "/cluster/cluster_id" }}
ETCD_COMPACT_INTERVAL={{ getv "/env/etcautocompact" "0" }}
ETCD_QUOTA_BYTES={{ getv "/env/etcd.quota.backend.bytes" "2147483648" }}
ETCD_HEARTBEAT_INTERVAL={{ getv "/env/etcdheartbeatinterval" "100" }}
ETCD_ELECTION_TIMEOUT={{ getv "/env/etcdelectiontimeout" "1000" }}
ETCD_AUTO_COMPACTION_MODE="periodic"
# ETCD_MAX_REQUEST_BYTES=1572864
ETCD_ENABLE_V2="true"
ETCD_ENABLE_TLS={{ $enableTLS }}
MY_ROLE={{ $myRole }}
MY_SID={{ $mySid }}
MY_IP={{ getv "/host/ip" }}
ETCD_CLUSTER_DNS={{ $clusterDNS }}
STABLE_NODES="$(echo $stableNodes)"
STABLE_NODES_DOMAIN_NAME="$(echo $stableNodesDomainName)"
HOSTS_DOMAIN_NAME="$(echo $hostsDomainName)"
PROXY_HOSTS_DOMAIN_NAME="$(echo $proxyHostsDomainName)"
{{- if eq $myRole "etcd-node" }}
ADDED_NODES="$(echo $addedNodes)"
ADDED_NODES_DOMAIN="$(echo $addedNodesDomain)"
ADDED_NODES_HOSTS_DOMAIN="$(echo $addedNodesHostsDomainName)"
DELETED_NODES="$(echo $deletedNodes)"
DELETED_NODES_DOMAIN="$(echo $deletedNodesDomain)"
DELETED_NODES_HOSTS_DOMAIN="$(echo $deletedNodesHostsDomain)"
ALL_NODES="$(echo $allNodes)"
ALL_NODES_DOMAIN="$(echo $allNodesDomain)"
IS_ADDED={{ $isAdded }}
IS_DELETED={{ $isDeleted }}
{{- end }}
Expand Down
1 change: 1 addition & 0 deletions ansible/files/etc/confd/templates/nodeexporter.sh.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_EXPORTER={{ getv "/env/nodeexporter" "false" }}
1 change: 1 addition & 0 deletions ansible/files/etc/confd/templates/tls.sh.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENABLE_TLS={{ getv "/env/enable_TLS" "false" }}
5 changes: 4 additions & 1 deletion ansible/files/opt/app/bin/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ EC_MEMBER_EXISTS=15 # scale: member still exists
EC_REPAIR_ILLEGAL_NODE=16 # repair: source node is outside cluster
EC_UNHEALTHY=17 # check: cluster is unhealthy
EC_NO_MEMBER_ID=18 # member: failed to find ID
EC_NO_CA=19 # ca: failed to CA
EC_REPAIR_FAILED=20 # repair: failed to repair
EC_REPAIR_IP_FAILED=21 # repair: Normal node input error or Abnormal node input error

workingDir=/var/lib/etcd
appctlDir=$workingDir/appctl
appctlDir=$workingDir/appctl # Log Dir

log() {
logger -t $MY_ROLE.appctl --id=$$ [cmd=$command role=$MY_ROLE] "$@" || return $EC_LOGGING
Expand Down
Loading

0 comments on commit d1e0663

Please sign in to comment.