Skip to content

Commit 3d1901e

Browse files
feat: [google-cloud-gke-multicloud] option to ignore_errors while deleting Azure clusters / nodepools (#12686)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 632771413 Source-Link: googleapis/googleapis@6d798dc Source-Link: googleapis/googleapis-gen@62fd424 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWdrZS1tdWx0aWNsb3VkLy5Pd2xCb3QueWFtbCIsImgiOiI2MmZkNDI0Zjg1OWYyNDA5ZTc4YjViOTgxOTEwMWIwNTRjMzM5YzQ1In0= --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 06f6453 commit 3d1901e

18 files changed

Lines changed: 7254 additions & 935 deletions

File tree

packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/async_client.py

Lines changed: 96 additions & 121 deletions
Large diffs are not rendered by default.

packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/client.py

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import re
1919
from typing import (
20+
Callable,
2021
Dict,
2122
Mapping,
2223
MutableMapping,
@@ -563,7 +564,11 @@ def __init__(
563564
self,
564565
*,
565566
credentials: Optional[ga_credentials.Credentials] = None,
566-
transport: Optional[Union[str, AttachedClustersTransport]] = None,
567+
transport: Optional[
568+
Union[
569+
str, AttachedClustersTransport, Callable[..., AttachedClustersTransport]
570+
]
571+
] = None,
567572
client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
568573
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
569574
) -> None:
@@ -575,9 +580,11 @@ def __init__(
575580
credentials identify the application to the service; if none
576581
are specified, the client will attempt to ascertain the
577582
credentials from the environment.
578-
transport (Union[str, AttachedClustersTransport]): The
579-
transport to use. If set to None, a transport is chosen
580-
automatically.
583+
transport (Optional[Union[str,AttachedClustersTransport,Callable[..., AttachedClustersTransport]]]):
584+
The transport to use, or a Callable that constructs and returns a new transport.
585+
If a Callable is given, it will be called with the same set of initialization
586+
arguments as used in the AttachedClustersTransport constructor.
587+
If set to None, a transport is chosen automatically.
581588
NOTE: "rest" transport functionality is currently in a
582589
beta state (preview). We welcome your feedback via an
583590
issue in this library's source repository.
@@ -689,8 +696,16 @@ def __init__(
689696
api_key_value
690697
)
691698

692-
Transport = type(self).get_transport_class(cast(str, transport))
693-
self._transport = Transport(
699+
transport_init: Union[
700+
Type[AttachedClustersTransport],
701+
Callable[..., AttachedClustersTransport],
702+
] = (
703+
type(self).get_transport_class(transport)
704+
if isinstance(transport, str) or transport is None
705+
else cast(Callable[..., AttachedClustersTransport], transport)
706+
)
707+
# initialize with the provided callable or the passed in class
708+
self._transport = transport_init(
694709
credentials=credentials,
695710
credentials_file=self._client_options.credentials_file,
696711
host=self._api_endpoint,
@@ -819,19 +834,17 @@ def sample_create_attached_cluster():
819834
820835
"""
821836
# Create or coerce a protobuf request object.
822-
# Quick check: If we got a request object, we should *not* have
823-
# gotten any keyword arguments that map to the request.
837+
# - Quick check: If we got a request object, we should *not* have
838+
# gotten any keyword arguments that map to the request.
824839
has_flattened_params = any([parent, attached_cluster, attached_cluster_id])
825840
if request is not None and has_flattened_params:
826841
raise ValueError(
827842
"If the `request` argument is set, then none of "
828843
"the individual field arguments should be set."
829844
)
830845

831-
# Minor optimization to avoid making a copy if the user passes
832-
# in a attached_service.CreateAttachedClusterRequest.
833-
# There's no risk of modifying the input as we've already verified
834-
# there are no flattened fields.
846+
# - Use the request object if provided (there's no risk of modifying the input as
847+
# there are no flattened fields), or create one.
835848
if not isinstance(request, attached_service.CreateAttachedClusterRequest):
836849
request = attached_service.CreateAttachedClusterRequest(request)
837850
# If we have keyword arguments corresponding to fields on the
@@ -974,19 +987,17 @@ def sample_update_attached_cluster():
974987
975988
"""
976989
# Create or coerce a protobuf request object.
977-
# Quick check: If we got a request object, we should *not* have
978-
# gotten any keyword arguments that map to the request.
990+
# - Quick check: If we got a request object, we should *not* have
991+
# gotten any keyword arguments that map to the request.
979992
has_flattened_params = any([attached_cluster, update_mask])
980993
if request is not None and has_flattened_params:
981994
raise ValueError(
982995
"If the `request` argument is set, then none of "
983996
"the individual field arguments should be set."
984997
)
985998

986-
# Minor optimization to avoid making a copy if the user passes
987-
# in a attached_service.UpdateAttachedClusterRequest.
988-
# There's no risk of modifying the input as we've already verified
989-
# there are no flattened fields.
999+
# - Use the request object if provided (there's no risk of modifying the input as
1000+
# there are no flattened fields), or create one.
9901001
if not isinstance(request, attached_service.UpdateAttachedClusterRequest):
9911002
request = attached_service.UpdateAttachedClusterRequest(request)
9921003
# If we have keyword arguments corresponding to fields on the
@@ -1129,19 +1140,17 @@ def sample_import_attached_cluster():
11291140
11301141
"""
11311142
# Create or coerce a protobuf request object.
1132-
# Quick check: If we got a request object, we should *not* have
1133-
# gotten any keyword arguments that map to the request.
1143+
# - Quick check: If we got a request object, we should *not* have
1144+
# gotten any keyword arguments that map to the request.
11341145
has_flattened_params = any([parent, fleet_membership])
11351146
if request is not None and has_flattened_params:
11361147
raise ValueError(
11371148
"If the `request` argument is set, then none of "
11381149
"the individual field arguments should be set."
11391150
)
11401151

1141-
# Minor optimization to avoid making a copy if the user passes
1142-
# in a attached_service.ImportAttachedClusterRequest.
1143-
# There's no risk of modifying the input as we've already verified
1144-
# there are no flattened fields.
1152+
# - Use the request object if provided (there's no risk of modifying the input as
1153+
# there are no flattened fields), or create one.
11451154
if not isinstance(request, attached_service.ImportAttachedClusterRequest):
11461155
request = attached_service.ImportAttachedClusterRequest(request)
11471156
# If we have keyword arguments corresponding to fields on the
@@ -1257,19 +1266,17 @@ def sample_get_attached_cluster():
12571266
12581267
"""
12591268
# Create or coerce a protobuf request object.
1260-
# Quick check: If we got a request object, we should *not* have
1261-
# gotten any keyword arguments that map to the request.
1269+
# - Quick check: If we got a request object, we should *not* have
1270+
# gotten any keyword arguments that map to the request.
12621271
has_flattened_params = any([name])
12631272
if request is not None and has_flattened_params:
12641273
raise ValueError(
12651274
"If the `request` argument is set, then none of "
12661275
"the individual field arguments should be set."
12671276
)
12681277

1269-
# Minor optimization to avoid making a copy if the user passes
1270-
# in a attached_service.GetAttachedClusterRequest.
1271-
# There's no risk of modifying the input as we've already verified
1272-
# there are no flattened fields.
1278+
# - Use the request object if provided (there's no risk of modifying the input as
1279+
# there are no flattened fields), or create one.
12731280
if not isinstance(request, attached_service.GetAttachedClusterRequest):
12741281
request = attached_service.GetAttachedClusterRequest(request)
12751282
# If we have keyword arguments corresponding to fields on the
@@ -1380,19 +1387,17 @@ def sample_list_attached_clusters():
13801387
13811388
"""
13821389
# Create or coerce a protobuf request object.
1383-
# Quick check: If we got a request object, we should *not* have
1384-
# gotten any keyword arguments that map to the request.
1390+
# - Quick check: If we got a request object, we should *not* have
1391+
# gotten any keyword arguments that map to the request.
13851392
has_flattened_params = any([parent])
13861393
if request is not None and has_flattened_params:
13871394
raise ValueError(
13881395
"If the `request` argument is set, then none of "
13891396
"the individual field arguments should be set."
13901397
)
13911398

1392-
# Minor optimization to avoid making a copy if the user passes
1393-
# in a attached_service.ListAttachedClustersRequest.
1394-
# There's no risk of modifying the input as we've already verified
1395-
# there are no flattened fields.
1399+
# - Use the request object if provided (there's no risk of modifying the input as
1400+
# there are no flattened fields), or create one.
13961401
if not isinstance(request, attached_service.ListAttachedClustersRequest):
13971402
request = attached_service.ListAttachedClustersRequest(request)
13981403
# If we have keyword arguments corresponding to fields on the
@@ -1525,19 +1530,17 @@ def sample_delete_attached_cluster():
15251530
15261531
"""
15271532
# Create or coerce a protobuf request object.
1528-
# Quick check: If we got a request object, we should *not* have
1529-
# gotten any keyword arguments that map to the request.
1533+
# - Quick check: If we got a request object, we should *not* have
1534+
# gotten any keyword arguments that map to the request.
15301535
has_flattened_params = any([name])
15311536
if request is not None and has_flattened_params:
15321537
raise ValueError(
15331538
"If the `request` argument is set, then none of "
15341539
"the individual field arguments should be set."
15351540
)
15361541

1537-
# Minor optimization to avoid making a copy if the user passes
1538-
# in a attached_service.DeleteAttachedClusterRequest.
1539-
# There's no risk of modifying the input as we've already verified
1540-
# there are no flattened fields.
1542+
# - Use the request object if provided (there's no risk of modifying the input as
1543+
# there are no flattened fields), or create one.
15411544
if not isinstance(request, attached_service.DeleteAttachedClusterRequest):
15421545
request = attached_service.DeleteAttachedClusterRequest(request)
15431546
# If we have keyword arguments corresponding to fields on the
@@ -1650,19 +1653,17 @@ def sample_get_attached_server_config():
16501653
16511654
"""
16521655
# Create or coerce a protobuf request object.
1653-
# Quick check: If we got a request object, we should *not* have
1654-
# gotten any keyword arguments that map to the request.
1656+
# - Quick check: If we got a request object, we should *not* have
1657+
# gotten any keyword arguments that map to the request.
16551658
has_flattened_params = any([name])
16561659
if request is not None and has_flattened_params:
16571660
raise ValueError(
16581661
"If the `request` argument is set, then none of "
16591662
"the individual field arguments should be set."
16601663
)
16611664

1662-
# Minor optimization to avoid making a copy if the user passes
1663-
# in a attached_service.GetAttachedServerConfigRequest.
1664-
# There's no risk of modifying the input as we've already verified
1665-
# there are no flattened fields.
1665+
# - Use the request object if provided (there's no risk of modifying the input as
1666+
# there are no flattened fields), or create one.
16661667
if not isinstance(request, attached_service.GetAttachedServerConfigRequest):
16671668
request = attached_service.GetAttachedServerConfigRequest(request)
16681669
# If we have keyword arguments corresponding to fields on the
@@ -1795,19 +1796,17 @@ def sample_generate_attached_cluster_install_manifest():
17951796
17961797
"""
17971798
# Create or coerce a protobuf request object.
1798-
# Quick check: If we got a request object, we should *not* have
1799-
# gotten any keyword arguments that map to the request.
1799+
# - Quick check: If we got a request object, we should *not* have
1800+
# gotten any keyword arguments that map to the request.
18001801
has_flattened_params = any([parent, attached_cluster_id])
18011802
if request is not None and has_flattened_params:
18021803
raise ValueError(
18031804
"If the `request` argument is set, then none of "
18041805
"the individual field arguments should be set."
18051806
)
18061807

1807-
# Minor optimization to avoid making a copy if the user passes
1808-
# in a attached_service.GenerateAttachedClusterInstallManifestRequest.
1809-
# There's no risk of modifying the input as we've already verified
1810-
# there are no flattened fields.
1808+
# - Use the request object if provided (there's no risk of modifying the input as
1809+
# there are no flattened fields), or create one.
18111810
if not isinstance(
18121811
request, attached_service.GenerateAttachedClusterInstallManifestRequest
18131812
):
@@ -1902,10 +1901,8 @@ def sample_generate_attached_cluster_agent_token():
19021901
19031902
"""
19041903
# Create or coerce a protobuf request object.
1905-
# Minor optimization to avoid making a copy if the user passes
1906-
# in a attached_service.GenerateAttachedClusterAgentTokenRequest.
1907-
# There's no risk of modifying the input as we've already verified
1908-
# there are no flattened fields.
1904+
# - Use the request object if provided (there's no risk of modifying the input as
1905+
# there are no flattened fields), or create one.
19091906
if not isinstance(
19101907
request, attached_service.GenerateAttachedClusterAgentTokenRequest
19111908
):

packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(
5252
credentials: Optional[ga_credentials.Credentials] = None,
5353
credentials_file: Optional[str] = None,
5454
scopes: Optional[Sequence[str]] = None,
55-
channel: Optional[grpc.Channel] = None,
55+
channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None,
5656
api_mtls_endpoint: Optional[str] = None,
5757
client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
5858
ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
@@ -72,14 +72,17 @@ def __init__(
7272
credentials identify the application to the service; if none
7373
are specified, the client will attempt to ascertain the
7474
credentials from the environment.
75-
This argument is ignored if ``channel`` is provided.
75+
This argument is ignored if a ``channel`` instance is provided.
7676
credentials_file (Optional[str]): A file with credentials that can
7777
be loaded with :func:`google.auth.load_credentials_from_file`.
78-
This argument is ignored if ``channel`` is provided.
78+
This argument is ignored if a ``channel`` instance is provided.
7979
scopes (Optional(Sequence[str])): A list of scopes. This argument is
80-
ignored if ``channel`` is provided.
81-
channel (Optional[grpc.Channel]): A ``Channel`` instance through
82-
which to make calls.
80+
ignored if a ``channel`` instance is provided.
81+
channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]):
82+
A ``Channel`` instance through which to make calls, or a Callable
83+
that constructs and returns one. If set to None, ``self.create_channel``
84+
is used to create the channel. If a Callable is given, it will be called
85+
with the same arguments as used in ``self.create_channel``.
8386
api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
8487
If provided, it overrides the ``host`` argument and tries to create
8588
a mutual TLS channel with client SSL credentials from
@@ -89,11 +92,11 @@ def __init__(
8992
private key bytes, both in PEM format. It is ignored if
9093
``api_mtls_endpoint`` is None.
9194
ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
92-
for the grpc channel. It is ignored if ``channel`` is provided.
95+
for the grpc channel. It is ignored if a ``channel`` instance is provided.
9396
client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
9497
A callback to provide client certificate bytes and private key bytes,
9598
both in PEM format. It is used to configure a mutual TLS channel. It is
96-
ignored if ``channel`` or ``ssl_channel_credentials`` is provided.
99+
ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
97100
quota_project_id (Optional[str]): An optional project to use for billing
98101
and quota.
99102
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
@@ -120,7 +123,7 @@ def __init__(
120123
if client_cert_source:
121124
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
122125

123-
if channel:
126+
if isinstance(channel, grpc.Channel):
124127
# Ignore credentials if a channel was passed.
125128
credentials = False
126129
# If a channel was explicitly provided, set it.
@@ -161,7 +164,9 @@ def __init__(
161164
)
162165

163166
if not self._grpc_channel:
164-
self._grpc_channel = type(self).create_channel(
167+
# initialize with the provided callable or the default channel
168+
channel_init = channel or type(self).create_channel
169+
self._grpc_channel = channel_init(
165170
self._host,
166171
# use the credentials which are saved
167172
credentials=self._credentials,

0 commit comments

Comments
 (0)