From 732652830fb5b02604a45fce4d96ab62b63d366b Mon Sep 17 00:00:00 2001 From: alexandredevely <12896316+alexandredevely@users.noreply.github.com> Date: Wed, 11 Oct 2023 20:58:28 +0200 Subject: [PATCH] add dry_run_desktop --- oc/od/orchestrator.py | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/oc/od/orchestrator.py b/oc/od/orchestrator.py index 3618c10..fed7b64 100755 --- a/oc/od/orchestrator.py +++ b/oc/od/orchestrator.py @@ -1224,6 +1224,7 @@ def build_volumes_home( self, authinfo:AuthInfo, userinfo:AuthUser, volume_type: 'mountPath':user_homedirectory } + self.logger.debug( f"volumes_mount['home']: {volumes_mount.get('home')}" ) self.logger.debug( f"volumes['home']: {volumes.get('home')}") self.logger.debug( f"volumes_mount['cache']: {volumes_mount.get('cache')}" ) @@ -1275,6 +1276,7 @@ def get_volumes_localaccount_name( self, authinfo:AuthInfo, userinfo:AuthUser )- self.logger.debug('') assert isinstance(authinfo, AuthInfo), f"authinfo has invalid type {type(authinfo)}" assert isinstance(userinfo, AuthUser), f"userinfo has invalid type {type(userinfo)}" + localaccount_name = None mysecretdict = self.list_dict_secret_data( authinfo, userinfo, access_type='localaccount' ) if isinstance(mysecretdict, dict ) and len(mysecretdict)>0: @@ -1380,11 +1382,6 @@ def build_volumes( self, authinfo:AuthInfo, userinfo:AuthUser, volume_type, secr volumes.update( localaccount_volumes ) volumes_mount.update( localaccount_volumes_mount ) - - if kwargs.get('dry_run') == 'All': - # do not add volume secrets or external resources - return (volumes, volumes_mount) - # # mount vnc secret in /var/secrets/abcdesktop # always add vnc secret for 'pod_desktop' @@ -2889,11 +2886,10 @@ def create_vnc_secret( self, authinfo:AuthInfo, userinfo:AuthUser, kwargs:dict ) """ self.logger.debug('vnc kubernetes secret checking') plaintext_vnc_password = ODVncPassword().getplain() - if kwargs.get('dry_run') != 'All': - vnc_secret = oc.od.secret.ODSecretVNC( self.namespace, self.kubeapi ) - vnc_secret_password = vnc_secret.create( authinfo=authinfo, userinfo=userinfo, data={ 'password' : plaintext_vnc_password } ) - if not isinstance( vnc_secret_password, V1Secret ): - raise ODAPIError( f"create vnc kubernetes secret {plaintext_vnc_password} failed" ) + vnc_secret = oc.od.secret.ODSecretVNC( self.namespace, self.kubeapi ) + vnc_secret_password = vnc_secret.create( authinfo=authinfo, userinfo=userinfo, data={ 'password' : plaintext_vnc_password } ) + if not isinstance( vnc_secret_password, V1Secret ): + raise ODAPIError( f"create vnc kubernetes secret {plaintext_vnc_password} failed" ) self.logger.debug(f"vnc kubernetes secret set to {plaintext_vnc_password}") def createdesktop(self, authinfo:AuthInfo, userinfo:AuthUser, **kwargs)-> ODDesktop : @@ -2915,7 +2911,8 @@ def createdesktop(self, authinfo:AuthInfo, userinfo:AuthUser, **kwargs)-> ODDesk assert isinstance(userinfo, AuthUser), f"userinfo has invalid type {type(userinfo)}" myDesktop = None # default return object - env = kwargs.get('env', {} ) + env = kwargs.get('env', {} ) + dry_run = kwargs.get('dry_run') # get the execute class if user has a executeclassname tag executeclasse = self.get_executeclasse( authinfo, userinfo ) @@ -3164,13 +3161,17 @@ def createdesktop(self, authinfo:AuthInfo, userinfo:AuthUser, **kwargs)-> ODDesk pod_manifest['spec']['containers'].append( graphical_container ) self.logger.debug(f"pod container created {currentcontainertype}" ) - - localaccount_volume_name = self.get_volumes_localaccount_name( authinfo=authinfo, userinfo=userinfo) - containers = { + + localaccount_volume_name = self.get_volumes_localaccount_name( authinfo=authinfo, userinfo=userinfo ) + assert isinstance(localaccount_volume_name, str), f"localaccount_volume_name has invalid type {type(localaccount_volume_name)}" + containers = { # printer uses tmp volume - 'printer': { 'list_volumeMounts': [ pod_allvolumeMounts['tmp'] ] }, + 'printer': { 'list_volumeMounts': [ pod_allvolumeMounts.get('tmp') ] }, # sound uses tmp, home, log volumes - 'sound': { 'list_volumeMounts': [ pod_allvolumeMounts[localaccount_volume_name], pod_allvolumeMounts['tmp'], pod_allvolumeMounts['home'], pod_allvolumeMounts['log'] ] }, + 'sound': { 'list_volumeMounts': [ pod_allvolumeMounts.get(localaccount_volume_name), + pod_allvolumeMounts.get('tmp'), + pod_allvolumeMounts.get('home'), + pod_allvolumeMounts.get('log') ] }, # ssh uses default user volumes 'ssh': { 'list_volumeMounts': list_volumeMounts }, # filter uses default user volumes @@ -3178,9 +3179,11 @@ def createdesktop(self, authinfo:AuthInfo, userinfo:AuthUser, **kwargs)-> ODDesk # storage uses default user volumes 'storage': { 'list_volumeMounts': list_pod_allvolumeMounts }, # rdp uses default user volumes - 'rdp': { 'list_volumeMounts': [ pod_allvolumeMounts['x11socket']] } , + 'rdp': { 'list_volumeMounts': [ pod_allvolumeMounts.get('x11socket') ] } , # x11overlay uses default user volumes - 'x11overlay' : { 'list_volumeMounts': [ pod_allvolumeMounts[localaccount_volume_name], pod_allvolumeMounts['x11socket']] } + 'x11overlay' : { 'list_volumeMounts': [ + pod_allvolumeMounts.get(localaccount_volume_name), + pod_allvolumeMounts.get('x11socket') ] } } for currentcontainertype in containers.keys(): @@ -3201,7 +3204,6 @@ def createdesktop(self, authinfo:AuthInfo, userinfo:AuthUser, **kwargs)-> ODDesk self.on_desktoplaunchprogress('b.Creating your desktop') jsonpod_manifest = json.dumps( pod_manifest, indent=2 ) self.logger.info( 'dump yaml %s', jsonpod_manifest ) - dry_run = kwargs.get('dry_run') pod = None try: