1616# under the License.
1717#
1818
19+ import nuvolaris .operator_util as operator_util
1920import nuvolaris .kustomize as kus
2021import nuvolaris .kube as kube
2122import nuvolaris .config as cfg
2223import nuvolaris .template as ntp
2324import nuvolaris .util as util
25+ import sys
2426import os .path
2527import logging
2628import kopf
2729
30+
2831from nuvolaris .util import get_etcd_replica
2932
3033def 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-
8085def 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
110115def 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
193183if __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\n please 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+
0 commit comments