feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

View File

@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

View File

@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Instance creation request modifier."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
def Messages(api_version):
return apis.GetMessagesModule('krmapihosting', api_version)
def CreateUpdateRequest(release_track, ref, args):
"""Returns an updated request formatted to the right URI endpoint."""
messages = Messages(ref.GetCollectionInfo().api_version)
# krmapihosting create endpoint uses a different uri from the one generated,
# we will need to construct it manually
custom_uri = 'projects/{project_id}/locations/{location}'.format(
project_id=ref.projectsId, location=args.location)
# We don't expose the bundle in this surface.
bundles_config = messages.BundlesConfig(
configControllerConfig=messages.ConfigControllerConfig(enabled=True))
if release_track == base.ReleaseTrack.ALPHA and args.IsSpecified(
'experimental_features'):
bundles_config.configControllerConfig.experimentalFeatures = args.experimental_features
krm_api_host = messages.KrmApiHost(
bundlesConfig=bundles_config)
if args.use_private_endpoint:
# Omit on False to make wired format cleaner.
krm_api_host.usePrivateEndpoint = args.use_private_endpoint
# Populate man blocks if provided
multiple_cidr_blocks = []
if args.IsSpecified('man_block') and args.IsSpecified('man_blocks'):
raise Exception('man_block and man_blocks can not be set at the same time')
if args.IsSpecified('man_blocks'):
for cidr_block in args.man_blocks:
cur_cidr_block = messages.CidrBlock(cidrBlock=cidr_block)
multiple_cidr_blocks.append(cur_cidr_block)
man_blocks = messages.MasterAuthorizedNetworksConfig(
cidrBlocks=multiple_cidr_blocks)
if args.full_management:
full_mgmt_config = messages.FullManagementConfig(
clusterCidrBlock=args.cluster_ipv4_cidr_block,
clusterNamedRange=args.cluster_named_range,
manBlock=args.man_block,
masterIpv4CidrBlock=args.master_ipv4_cidr_block,
network=args.network,
subnet=args.subnet,
servicesCidrBlock=args.services_ipv4_cidr_block,
servicesNamedRange=args.services_named_range)
if args.IsSpecified('man_blocks'):
full_mgmt_config.masterAuthorizedNetworksConfig = man_blocks
mgmt_config = messages.ManagementConfig(
fullManagementConfig=full_mgmt_config)
krm_api_host.managementConfig = mgmt_config
else:
# BUG(xiaoweim): moved the default value up to be a const
# Default master ipv4 cidr block address if not provided
master_ipv4_cidr_block = '172.16.0.128/28'
if args.master_ipv4_cidr_block is not None:
master_ipv4_cidr_block = args.master_ipv4_cidr_block
std_mgmt_config = messages.StandardManagementConfig(
clusterCidrBlock=args.cluster_ipv4_cidr_block,
clusterNamedRange=args.cluster_named_range,
manBlock=args.man_block,
masterIpv4CidrBlock=master_ipv4_cidr_block,
network=args.network,
subnet=args.subnet,
servicesCidrBlock=args.services_ipv4_cidr_block,
servicesNamedRange=args.services_named_range)
if args.IsSpecified('man_blocks'):
std_mgmt_config.masterAuthorizedNetworksConfig = man_blocks
mgmt_config = messages.ManagementConfig(
standardManagementConfig=std_mgmt_config)
krm_api_host.managementConfig = mgmt_config
request = (
messages.KrmapihostingProjectsLocationsKrmApiHostsCreateRequest(
parent=custom_uri,
krmApiHostId=ref.krmApiHostsId,
krmApiHost=krm_api_host))
return request

View File

@@ -0,0 +1,160 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Flags for the config controller command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import actions
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
def AddAsyncFlag(parser):
"""Adds --async flag."""
base.ASYNC_FLAG.AddToParser(parser)
def AddMasterIPv4CIDRBlock(parser):
"""Adds --master-ipv4-cidr-block flag."""
parser.add_argument(
"--master-ipv4-cidr-block",
help=("The /28 network that the control plane will use. "
"Defaults to '172.16.0.128/28' if flag is not provided."))
def AddNetworkFlag(parser):
"""Adds --network flag."""
parser.add_argument(
"--network",
help=("Existing VPC Network to put the GKE cluster and nodes in. "
"Defaults to 'default' if flag is not provided. If "
"`--subnet=SUBNET` is also specified, subnet must be a subnetwork "
"of the network specified by this `--network=NETWORK` flag."))
def AddSubnetFlag(parser):
"""Adds --subnet flag."""
parser.add_argument(
"--subnet",
help=("Specifies the subnet that the VM instances are a part of. "
"`--network=NETWORK` must also be specified, subnet must be a "
"subnetwork of the network specified by the `--network=NETWORK` "
"flag."))
def AddManBlockFlag(parser):
"""Adds --man-block flag."""
parser.add_argument(
"--man-block",
help=("Master Authorized Network. "
"Allows access to the Kubernetes control plane from this block. "
"Defaults to '0.0.0.0/0' if flag is not provided."))
def AddManBlockFlagDeprecated(parser):
"""Adds --man-block flag."""
parser.add_argument(
"--man-block",
help=("Master Authorized Network. "
"Allows access to the Kubernetes control plane from this block. "
"Defaults to `0.0.0.0/0` if flag is not provided."),
action=actions.DeprecationAction(
"--man-block",
warn="The {flag_name} option is deprecated; use --man-blocks instead.",
removed=False))
def AddManBlocksFlag(parser):
"""Adds --man-blocks flag."""
parser.add_argument(
"--man-blocks",
type=arg_parsers.ArgList(),
metavar="BLOCK",
help=("Master Authorized Network. "
"Allows users to specify multiple blocks to access the Kubernetes"
"control plane from this block. "
"Defaults to `0.0.0.0/0` if flag is not provided."))
def AddClusterIPv4CIDRBlock(parser):
"""Adds --cluster-ipv4-cidr-block flag."""
parser.add_argument(
"--cluster-ipv4-cidr-block",
help=("The IP address range for the cluster pod IPs. "
"Can be specified as a netmask size (e.g. '/14') or as in CIDR "
"notation (e.g. '10.100.0.0/20'). Defaults to '/20' if flag is "
"not provided."))
def AddServicesIPv4CIDRBlack(parser):
"""Adds --services-ipv4-cidr-block flag."""
parser.add_argument(
"--services-ipv4-cidr-block",
help=("The IP address range for the cluster service IPs. Can be "
"specified as a netmask size (e.g. '/14') or as in CIDR "
"notation (e.g. '10.100.0.0/20'). Defaults to '/24' if flag is "
"not provided."))
def AddClusterNamedRangeFlag(parser):
"""Adds --cluster-named-range flag."""
parser.add_argument(
"--cluster-named-range",
help=("The name of the existing secondary range in the clusters "
"subnetwork to use for pod IP addresses. Alternatively, "
"`--cluster_cidr_block` can be used to automatically create a "
"GKE-managed one."))
def AddServicesNamedRange(parser):
"""Adds --services-named-range flag."""
parser.add_argument(
"--services-named-range",
help=("The name of the existing secondary range in the clusters "
"subnetwork to use for service ClusterIPs. Alternatively, "
"`--services_cidr_block` can be used to automatically create a "
"GKE-managed one."))
def AddFullManagement(parser):
"""Adds --full-management flag."""
parser.add_argument(
"--full-management",
# Use store_const so that gcloud doesn't generate a hidden
# --no-full-management flag. See yaqs/4400496223010684928 for more
# details.
action="store_const",
const=True,
help=("Enable full cluster management type."))
def AddUsePrivateEndpoint(parser):
"""Adds --use-private-endpoint flag."""
parser.add_argument(
"--use-private-endpoint",
action="store_true",
help=("Only allow access to the master's private endpoint IP."))
def AddExperimentalFeaturesFlag(parser):
"""Adds --experimental-features flag."""
parser.add_argument(
"--experimental-features",
type=arg_parsers.ArgList(),
metavar="FEATURE",
help=("Enable experimental features. It can only be enabled in ALPHA "
"version."))

View File

@@ -0,0 +1,69 @@
project:
name: project
collection: krmapihosting.projects
attributes:
- &project
parameter_name: projectsId
attribute_name: project
help: The name of the Anthos Config Controller instance project ID.
disable_auto_completers: false
location:
name: location
collection: krmapihosting.projects.locations
attributes:
- &location
parameter_name: locationsId
attribute_name: location
help: The name of the Anthos Config Controller instance location. Currently, only `us-central1`, `us-east1`, `us-east4`, `us-east5`, `us-west2`, `northamerica-northeast1`, `northamerica-northeast2`, `europe-north1`, `europe-west1`, `europe-west3`, `europe-west6`, `australia-southeast1`, `australia-southeast2`, `asia-northeast1`, `asia-northeast2` and `asia-southeast1` are supported.
disable_auto_completers: false
instance:
name: instance
collection: krmapihosting.projects.locations.krmApiHosts
attributes:
- *project
- *location
- &instance
parameter_name: krmApiHostsId
attribute_name: name
help: The name of the Anthos Config Controller instance.
disable_auto_completers: false
location-list:
name: location
collection: krmapihosting.projects.locations
attributes:
- &location-list
parameter_name: locationsId
attribute_name: location
fallthroughs:
- hook: googlecloudsdk.command_lib.anthos.config.controller.utils:SetLocation
hint: use global location
help: The name of the Anthos Config Controller instance location. Currently, only `us-central1`, `us-east1`, `us-east4`, `us-east5`, `us-west2`, `northamerica-northeast1`, `northamerica-northeast2`, `europe-north1`, `europe-west1`, `europe-west3`, `europe-west6`, `australia-southeast1`, `australia-southeast2`, `asia-northeast1`, `asia-northeast2` and `asia-southeast1` are supported.
disable_auto_completers: false
instance-list:
name: instance-list
collection: krmapihosting.projects.locations
attributes:
- *project
- *location-list
operation:
name: operation
collection: krmapihosting.projects.locations.operations
attributes:
- *location
- &operation:
parameter_name: operationsId
attribute_name: operation
help: The name of the Anthos Config Controller operation.
disable_auto_completers: false
operation-list:
name: operation-list
collection: krmapihosting.projects.locations
attributes:
- *project
- *location-list

View File

@@ -0,0 +1,146 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utils for Config Controller commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container import api_adapter as container_api_adapter
from googlecloudsdk.api_lib.krmapihosting import util
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope.concepts import concepts
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.core import log
NOT_RUNNING_MSG = ('Config Controller {0} is not running. '
'The kubernetes API may not be available.')
def SetLocation():
"""Sets default location to '-' for list command."""
return '-'
def InstanceAttributeConfig():
return concepts.ResourceParameterAttributeConfig(
name='name',
help_text='The name of the Config Controller instance.')
def LocationAttributeConfig():
return concepts.ResourceParameterAttributeConfig(
name='location',
help_text=(
'The name of the Config Controller instance location. Currently, only'
" ``us-central1'', ``us-east1'', ``us-east4'', ``us-east5'',"
" ``us-west2'', ``northamerica-northeast1'',"
" ``northamerica-northeast2'', ``europe-north1'', ``europe-west1'',"
" ``europe-west3'', ``europe-west6'', ``australia-southeast1'',"
" ``australia-southeast2'', ``asia-northeast1'', ``asia-northeast2''"
" and ``asia-southeast1'' are supported."
),
)
def GetInstanceResourceSpec(api_version):
return concepts.ResourceSpec(
'krmapihosting.projects.locations.krmApiHosts',
resource_name='instance',
api_version=api_version,
krmApiHostsId=InstanceAttributeConfig(),
locationsId=LocationAttributeConfig(),
projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
disable_auto_completers=False)
def AddInstanceResourceArg(parser, api_version):
concept_parsers.ConceptParser.ForResource(
'name',
GetInstanceResourceSpec(api_version),
'The identifier for a Config Controller instance.',
required=True).AddToParser(parser)
def GetGKECluster(name, location):
"""Fetches the information about the GKE cluster backing the Config Controller."""
cluster_id = 'krmapihost-' + name
location_id = location
project = None
gke_api = container_api_adapter.NewAPIAdapter('v1')
log.status.Print('Fetching cluster endpoint and auth data.')
cluster_ref = gke_api.ParseCluster(cluster_id, location_id, project)
cluster = gke_api.GetCluster(cluster_ref)
if not gke_api.IsRunning(cluster):
log.warning(NOT_RUNNING_MSG.format(cluster_ref.clusterId))
return cluster, cluster_ref
def AsyncLog(operation):
"""Print log messages for async commands."""
log.status.Print(
"""
Check operation [{}] for status.
To describe the operation, run:
$ gcloud anthos config operations describe {}"""
.format(operation.name, operation.name))
return operation
def PatchRequest(args):
"""Construct a patch request based on the args."""
instance = args.CONCEPTS.name.Parse()
messages = apis.GetMessagesModule('krmapihosting',
instance.GetCollectionInfo().api_version)
# Get the current instance to determine whether full management config is
# used.
current = util.GetKrmApiHost(instance.RelativeName())
# Construct the patch instance and the update mask.
update_masks = []
management_config = messages.ManagementConfig()
bundles_config = messages.BundlesConfig(
configControllerConfig=messages.ConfigControllerConfig())
if args.experimental_features:
update_masks.append(
'bundles_config.config_controller_config.experimental_features')
bundles_config.configControllerConfig.experimentalFeatures = args.experimental_features # pylint: disable=line-too-long
if current.managementConfig.fullManagementConfig:
full_management_config = messages.FullManagementConfig()
if args.man_block:
full_management_config.manBlock = args.man_block
update_masks.append('management_config.full_management_config.man_block')
management_config.fullManagementConfig = full_management_config
else:
standard_management_config = messages.StandardManagementConfig()
if args.man_block:
standard_management_config.manBlock = args.man_block
update_masks.append(
'management_config.standard_management_config.man_block')
management_config.standardManagementConfig = standard_management_config
patch = messages.KrmApiHost(managementConfig=management_config,
bundlesConfig=bundles_config)
return messages.KrmapihostingProjectsLocationsKrmApiHostsPatchRequest(
krmApiHost=patch,
name=instance.RelativeName(),
updateMask=','.join(update_masks))