def GetConnectionContext(args): """Gets the regional, kubeconfig, or GKE connection context. Args: args: Namespace, the args namespace. Raises: ArgumentError if region or cluster is not specified. Returns: A GKE or regional ConnectionInfo object. """ if flags.IsKubernetes(args): kubeconfig = flags.GetKubeconfig(args) return _KubeconfigConnectionContext(kubeconfig, args.context) if flags.IsGKE(args): cluster_ref = args.CONCEPTS.cluster.Parse() if not cluster_ref: raise flags.ArgumentError( 'You must specify a cluster in a given location. ' 'Either use the `--cluster` and `--cluster-location` flags ' 'or set the run/cluster and run/cluster_location properties.') return _GKEConnectionContext(cluster_ref) if flags.IsManaged(args): region = flags.GetRegion(args, prompt=True) if not region: raise flags.ArgumentError( 'You must specify a region. Either use the `--region` flag ' 'or set the run/region property.') return _RegionalConnectionContext(region)
def _Call(self, parsed_args): if flags.IsGKE(parsed_args) or flags.IsKubernetes(parsed_args): return 'default' elif not (getattr(parsed_args, 'project', None) or properties.VALUES.core.project.Get()): # HACK: Compensate for how "namespace" is actually "project" in Cloud Run # by providing an error message explicitly early here. raise flags.ArgumentError( 'The [project] resource is not properly specified. ' 'Please specify the argument [--project] on the command line or ' 'set the property [core/project].') return None
def GetConnectionContext(args, track=base.ReleaseTrack.BETA): """Gets the regional, kubeconfig, or GKE connection context. Args: args: Namespace, the args namespace. track: ReleaseTrack, the release track. Raises: ArgumentError if region or cluster is not specified. Returns: A GKE or regional ConnectionInfo object. """ if flags.IsKubernetes(args): kubeconfig = flags.GetKubeconfig(args) return _KubeconfigConnectionContext(kubeconfig, args.context) if flags.IsGKE(args): cluster_ref = args.CONCEPTS.cluster.Parse() if not cluster_ref: raise flags.ArgumentError( 'You must specify a cluster in a given location. ' 'Either use the `--cluster` and `--cluster-location` flags ' 'or set the run/cluster and run/cluster_location properties.') return _GKEConnectionContext(cluster_ref) if flags.IsManaged(args): region = flags.GetRegion(args, prompt=True) if not region: raise flags.ArgumentError( 'You must specify a region. Either use the `--region` flag ' 'or set the run/region property.') if track == base.ReleaseTrack.ALPHA: version = 'v1' else: version = global_methods.SERVERLESS_API_VERSION return _RegionalConnectionContext(region, version)