Skip to content

Commit c29c427

Browse files
committed
etcd opsfile
1 parent 4eb298f commit c29c427

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

clusters/kind/opsfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tasks:
3232
create:
3333
desc: create
3434
cmds:
35-
- kind create cluster --name "{{.NAME}}" #--config kind.yaml
35+
- kind create cluster --name "{{.NAME}}" --config kind.yaml
3636
- kind get kubeconfig --name="{{.NAME}}" >{{.KUBEFILE}}
3737
- cp "{{.KUBEFILE}}" "$OPS_TMP/kubeconfig"
3838
- kubectl --namespace=ingress-nginx --kubeconfig "{{.KUBEFILE}}" apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml

nuvolaris/etcd.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@
1616
# under the License.
1717
#
1818

19+
import nuvolaris.operator_util as operator_util
1920
import nuvolaris.kustomize as kus
2021
import nuvolaris.kube as kube
2122
import nuvolaris.config as cfg
2223
import nuvolaris.template as ntp
2324
import nuvolaris.util as util
25+
import sys
2426
import os.path
2527
import logging
2628
import kopf
2729

30+
2831
from nuvolaris.util import get_etcd_replica
2932

3033
def create(owner=None):
@@ -42,7 +45,10 @@ def create(owner=None):
4245
spec_templates.append("etcd-policy.yaml")
4346

4447
kust = kus.patchTemplates("etcd",tplp , data)
45-
kust += kus.patchGenericEntry("Secret","nuvolaris-etcd-secret","/data/rootPassword",util.b64_encode(data['root_password']))
48+
kust += kus.patchGenericEntry("Secret","nuvolaris-etcd-secret","/data/rootPassword",util.b64_encode(data['root_password']))
49+
# change prefix
50+
if prefix is not None and prefix != "":
51+
kust += kus.namePrefix(prefix)
4652
spec = kus.kustom_list("etcd", kust, templates=spec_templates, data=data)
4753

4854
if owner:
@@ -76,7 +82,6 @@ def exec_etcd_script(pod_name,path_to_etcd_script):
7682
os.remove(path_to_etcd_script)
7783
return res
7884

79-
8085
def create_etcd_user(username:str, password:str, prefix:str):
8186
"""
8287
Creates a new ETCD username with the given password and assign redwrite permission on the given prefix
@@ -109,7 +114,7 @@ def create_etcd_user(username:str, password:str, prefix:str):
109114

110115
def delete_db_user(username):
111116
"""
112-
Reomves the specified user from the ETCD instance.
117+
Removes the specified user from the ETCD instance.
113118
"""
114119
logging.info(f"removing ETCD user {username}")
115120
try:
@@ -174,21 +179,27 @@ def patch(status, action, owner=None):
174179
else:
175180
status['whisk_create']['etcd']='error'
176181

177-
import fire
178-
from nuvolaris.operator_util import LoadConfig
179-
180-
class Etcd(LoadConfig):
181-
def create(self, replicas: int = 0):
182-
"""
183-
[<replicas>]
184-
"""
185-
if replicas > 0:
186-
print("setting replicas to:", replicas)
187-
cfg.put("etcd.replicas", replicas)
188-
print(create(self.owner))
189-
190-
def delete(self):
191-
print(delete(self.owner))
192182

193183
if __name__ == "__main__":
194-
fire.Fire(Etcd)
184+
[_create, _delete, replicas, prefix, storageClass] = sys.argv[1:]
185+
186+
owner = kube.get("wsk/controller")
187+
if not owner:
188+
print("cannot find a config in kubernetes\nplease use ops setup kubernetes configure")
189+
sys.exit(1)
190+
spec = owner.get("spec")
191+
operator_util.config_from_spec(spec)
192+
193+
if _create == "true":
194+
print("etcd create")
195+
if replicas != "":
196+
print("setting replicas to:", replicas)
197+
cfg.put("etcd.replicas", int(replicas))
198+
if storageClass != "":
199+
print("setting storage class to:", storageClass)
200+
cfg.put("nuvolaris.storage", storageClass)
201+
202+
print(create(owner))
203+
if _delete == "true":
204+
print(delete(owner))
205+

nuvolaris/opsfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ tasks:
88
desc: etcd
99
dir: ..
1010
cmds:
11-
- uv run nuvolaris/etcd.py {{.CLI_ARGS}}
11+
- uv run nuvolaris/etcd.py "{{.create}}" "{{.delete}}" "{{.__replicas}}" "{{.__prefix}}" "{{.__storageclass}}"

0 commit comments

Comments
 (0)