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,30 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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.
"""Command group for CloudRun feature."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base as calliope_base
@calliope_base.ReleaseTracks(calliope_base.ReleaseTrack.ALPHA,
calliope_base.ReleaseTrack.BETA,
calliope_base.ReleaseTrack.GA)
class CloudRun(calliope_base.Group):
"""Manage the CloudRun feature."""
category = calliope_base.COMPUTE_CATEGORY

View File

@@ -0,0 +1,139 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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.
"""The command to deploy or update the Cloud Run for Anthos feature."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.container.fleet import kube_util
from googlecloudsdk.command_lib.container.fleet import util as hub_util
from googlecloudsdk.core import exceptions
from googlecloudsdk.core import log
from googlecloudsdk.core import yaml
from googlecloudsdk.core.util import files
# Pull out the example text so the example command can be one line without the
# py linter complaining. The docgen tool properly breaks it into multiple lines.
EXAMPLES = """\
To apply the CloudRun YAML file, run:
$ {command} --kubeconfig=/path/to/kubeconfig --config=/path/to/cloud-run-cr.yaml
"""
class Apply(base.CreateCommand):
"""Deploy or update the CloudRun feature.
Deploy or update a user-specified config file of the CloudRun custom resource.
The config file should be a YAML file.
"""
detailed_help = {'EXAMPLES': EXAMPLES}
feature_name = 'appdevexperience'
@staticmethod
def Args(parser):
hub_util.AddClusterConnectionCommonArgs(parser)
parser.add_argument(
'--config',
type=str,
help='The path to CloudRun custom resource config file.',
required=False)
def Run(self, args):
kube_client = kube_util.KubernetesClient(
gke_uri=getattr(args, 'gke_uri', None),
gke_cluster=getattr(args, 'gke_cluster', None),
kubeconfig=getattr(args, 'kubeconfig', None),
context=getattr(args, 'context', None),
public_issuer_url=getattr(args, 'public_issuer_url', None),
enable_workload_identity=getattr(args, 'enable_workload_identity',
False),
)
kube_util.ValidateClusterIdentifierFlags(kube_client, args)
yaml_string = files.ReadFileContents(
args.config) if args.config is not None else _default_cr()
_validate_cr(yaml_string)
_apply_cr_to_membership_cluster(kube_client, yaml_string)
log.status.Print('Added CloudRun CR')
def _apply_cr_to_membership_cluster(kube_client, yaml_string):
"""Apply the CloudRun custom resource to the cluster.
Args:
kube_client: A Kubernetes client.
yaml_string: the CloudRun YAML file.
"""
_, err = kube_client.Apply(yaml_string)
if err:
raise exceptions.Error(
'Failed to apply manifest to cluster: {}'.format(err))
def _validate_cr(yaml_string):
"""Validate the parsed cloudrun YAML.
Args:
yaml_string: The YAML string to validate.
"""
try:
cloudrun_cr = yaml.load(yaml_string)
except yaml.Error as e:
raise exceptions.Error('Invalid cloudrun yaml {}'.format(yaml_string), e)
if not isinstance(cloudrun_cr, dict):
raise exceptions.Error('Invalid CloudRun template.')
if 'apiVersion' not in cloudrun_cr:
raise exceptions.Error(
'The resource is missing a required field "apiVersion".')
if cloudrun_cr['apiVersion'] != 'operator.run.cloud.google.com/v1alpha1':
raise exceptions.Error(
'The resource "apiVersion" field must be set to: "operator.run.cloud.google.com/v1alpha1". If you believe the apiVersion is correct, you may need to upgrade your gcloud installation.'
)
if 'kind' not in cloudrun_cr:
raise exceptions.Error('The resource is missing a required field "kind".')
if cloudrun_cr['kind'] != 'CloudRun':
raise exceptions.Error(
'The resource "kind" field must be set to: "CloudRun".')
if 'metadata' not in cloudrun_cr:
raise cloudrun_cr.Error(
'The resource is missing a required field "metadata".')
metadata = cloudrun_cr['metadata']
if ('name' not in metadata or metadata['name'] != 'cloud-run'):
raise exceptions.Error(
'The resource "metadata.name" field must be set to "cloud-run"')
def _default_cr():
return r"""
apiVersion: operator.run.cloud.google.com/v1alpha1
kind: CloudRun
metadata:
name: cloud-run
"""

View File

@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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.
"""The command to get the status of the CloudRun feature."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.command_lib.container.fleet.features import base
class Describe(base.DescribeCommand):
"""Describe the status of the CloudRun feature.
## EXAMPLES
To get the detailed current status of the CloudRun Feature in Anthos clusters,
run:
$ {command}
"""
feature_name = 'appdevexperience'

View File

@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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.
"""The command to disable the CloudRun feature."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.command_lib.container.fleet.features import base
class Disable(base.DisableCommand):
"""Disable the CloudRun feature.
This command disables the CloudRun feature in Anthos clusters.
## EXAMPLES
To disable the CloudRun Feature, run:
$ {command}
"""
feature_name = 'appdevexperience'

View File

@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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.
"""The command to enable the CloudRun feature."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.command_lib.container.fleet.features import base
class Enable(base.EnableCommand):
"""Enable the CloudRun feature.
This command enables the CloudRun feature in Anthos clusters.
## EXAMPLES
To enable the CloudRun Feature, run:
$ {command}
"""
feature_name = 'appdevexperience'