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,37 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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 gcloud anthos command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA,
base.ReleaseTrack.BETA,
base.ReleaseTrack.GA,
)
class Anthos(base.Group):
"""Anthos command Group."""
category = base.ANTHOS_CLI_CATEGORY
def Filter(self, context, args):
# TODO(b/190523915): Determine if command group works with project number
base.RequireProjectID(args)
del context, args

View File

@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Apply an Anthos configuration package."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.anthos import anthoscli_backend
from googlecloudsdk.command_lib.anthos import flags
from googlecloudsdk.command_lib.util.args import common_args
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Apply(base.BinaryBackedCommand):
"""Apply configuration changes for Anthos infrastructure."""
detailed_help = {
'EXAMPLES': """
To apply Anthos package to a Google Kubernetes Engine cluster in
project `my-project`:
$ {command} my-config --project=my-project
""",
}
@staticmethod
def Args(parser):
flags.GetLocalDirFlag(
help_override='Directory of package to apply.').AddToParser(parser)
common_args.ProjectArgument(
help_text_to_overwrite='Project ID.').AddToParser(parser)
def Run(self, args):
command_executor = anthoscli_backend.AnthosCliWrapper()
apply_project = properties.VALUES.core.project.Get()
auth_cred = anthoscli_backend.GetAuthToken(
account=properties.VALUES.core.account.Get(), operation='apply')
log.status.Print('Starting apply of package [{}] using '
'project [{}]'.format(args.LOCAL_DIR, apply_project))
response = command_executor(command='apply',
apply_dir=args.LOCAL_DIR,
project=apply_project,
show_exec_error=args.show_exec_error,
env=anthoscli_backend.GetEnvArgsForCommand(
extra_vars={'GCLOUD_AUTH_PLUGIN': 'true'}),
stdin=auth_cred)
return self._DefaultOperationResponseHandler(response)

View File

@@ -0,0 +1,31 @@
# -*- 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.
"""The gcloud anthos auth command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Auth(base.Group):
"""Authenticate clusters using the Anthos client.
Authenticate clusters using the Anthos client.
For more details on Anthos, see https://cloud.google.com/anthos/.
"""
category = base.ANTHOS_AUTH_CATEGORY

View File

@@ -0,0 +1,139 @@
# -*- 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.
"""Authenticate clusters using the Anthos client.."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.anthos import anthoscli_backend
from googlecloudsdk.command_lib.anthos import flags
from googlecloudsdk.command_lib.anthos.common import kube_flags
from googlecloudsdk.command_lib.anthos.common import messages
from googlecloudsdk.core import log
@base.DefaultUniverseOnly
class Login(base.BinaryBackedCommand):
"""Authenticate clusters using the Anthos client."""
detailed_help = {
'EXAMPLES': """
To add credentials to default kubeconfig file:
$ {command} --cluster=testcluster --login-config=kubectl-anthos-config.yaml
To add credentials to custom kubeconfig file:
$ {command} --cluster=testcluster --login-config=kubectl-anthos-config.yaml --kubeconfig=my.kubeconfig
To generate the commands without executing them:
$ {command} --cluster=testcluster --login-config=kubectl-anthos-config.yaml --dry-run
To add credentials to default kubeconfig file using server side login:
$ {command} --cluster=testcluster --server=<server-url>
To add credentials to custom kubeconfig file using server side login:
$ {command} --cluster=testcluster --server=<server-url> --kubeconfig=my.kubeconfig
To add credentials to custom kubeconfig file with server side login using a remote-device for login:
$ {command} --cluster=testcluster --server=<server-url> --kubeconfig=my.kubeconfig --no-browser
""",
}
@staticmethod
def Args(parser):
kube_flags.GetKubeConfigFlag(
'Specifies the destination kubeconfig file '
'where credentials will be stored.').AddToParser(parser)
flags.GetUserFlag().AddToParser(parser)
flags.GetClusterFlag().AddToParser(parser)
flags.GetLoginConfigFlag().AddToParser(parser)
flags.GetLoginConfigCertFlag().AddToParser(parser)
flags.GetDryRunFlag('Print out the generated kubectl commands '
'but do not execute them.').AddToParser(parser)
flags.GetSetPreferredAuthenticationFlag().AddToParser(parser)
flags.GetServerFlag().AddToParser(parser)
flags.GetNoBrowserFlag().AddToParser(parser)
flags.GetRemoteBootstrapFlag().AddToParser(parser)
def Run(self, args):
command_executor = anthoscli_backend.AnthosAuthWrapper()
cluster = args.CLUSTER
# If "server" flag is used, skip reading local config file.
if args.server:
# Log and execute binary command with flags.
log.status.Print(messages.LOGIN_CONFIG_MESSAGE)
response = command_executor(
command='login',
cluster=cluster,
kube_config=args.kubeconfig,
login_config_cert=args.login_config_cert,
dry_run=args.dry_run,
server_url=args.server,
no_browser=args.no_browser,
remote_bootstrap=args.remote_bootstrap,
env=anthoscli_backend.GetEnvArgsForCommand(
extra_vars={'GCLOUD_AUTH_PLUGIN': 'true'}
),
)
return anthoscli_backend.LoginResponseHandler(response)
# Get Default Path if flag not provided.
login_config = args.login_config or command_executor.default_config_path
# Get contents of config, parsing either URL or File.
login_config, config_contents, is_url = anthoscli_backend.GetFileOrURL(
login_config, args.login_config_cert)
# Get Preferred Auth Method and handle prompting.
force_update = args.set_preferred_auth
authmethod, ldapuser, ldappass = (
anthoscli_backend.GetPreferredAuthForCluster(
cluster=cluster,
login_config=login_config,
config_contents=config_contents,
force_update=force_update,
is_url=is_url,
)
)
# Log and execute binary command with flags.
log.status.Print(messages.LOGIN_CONFIG_MESSAGE)
response = command_executor(
command='login',
cluster=cluster,
kube_config=args.kubeconfig,
user=args.user,
login_config=login_config,
login_config_cert=args.login_config_cert,
dry_run=args.dry_run,
show_exec_error=args.show_exec_error,
ldap_user=ldapuser,
ldap_pass=ldappass,
preferred_auth=authmethod,
env=anthoscli_backend.GetEnvArgsForCommand(
extra_vars={'GCLOUD_AUTH_PLUGIN': 'true'}
),
)
return anthoscli_backend.LoginResponseHandler(
response, list_clusters_only=(cluster is None))

View File

@@ -0,0 +1,65 @@
# -*- 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.
"""Authenticate clusters using the Anthos client."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.anthos import anthoscli_backend
from googlecloudsdk.command_lib.anthos import flags
@base.Hidden
class Token(base.BinaryBackedCommand):
"""Creates a token for authentication."""
@staticmethod
def Args(parser):
flags.GetTypeFlag().AddToParser(parser)
flags.GetAwsStsRegionFlag().AddToParser(parser)
flags.GetTokenClusterFlag().AddToParser(parser)
flags.GetIdTokenFlag().AddToParser(parser)
flags.GetAccessTokenFlag().AddToParser(parser)
flags.GetAccessTokenExpiryFlag().AddToParser(parser)
flags.GetRefreshTokenFlag().AddToParser(parser)
flags.GetClientIdFlag().AddToParser(parser)
flags.GetClientSecretFlag().AddToParser(parser)
flags.GetIdpCertificateAuthorityDataFlag().AddToParser(parser)
flags.GetIdpIssuerUrlFlag().AddToParser(parser)
flags.GetKubeconfigPathFlag().AddToParser(parser)
flags.GetTokenUserFlag().AddToParser(parser)
def Run(self, args):
command_executor = anthoscli_backend.AnthosAuthWrapper()
# Log and execute binary command with flags.
response = command_executor(
command="token",
token_type=args.type,
cluster=args.cluster,
aws_sts_region=args.aws_sts_region,
id_token=args.id_token,
access_token=args.access_token,
access_token_expiry=args.access_token_expiry,
refresh_token=args.refresh_token,
client_id=args.client_id,
client_secret=args.client_secret,
idp_certificate_authority_data=args.idp_certificate_authority_data,
idp_issuer_url=args.idp_issuer_url,
kubeconfig_path=args.kubeconfig_path,
user=args.user,
env=anthoscli_backend.GetEnvArgsForCommand())
return self._DefaultOperationResponseHandler(response)

View File

@@ -0,0 +1,42 @@
# -*- 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.
"""Authenticate clusters using the Anthos client.."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.anthos import anthoscli_backend
@base.Hidden
class Version(base.BinaryBackedCommand):
"""Get version info for the Anthos Auth client."""
detailed_help = {
'EXAMPLES': """
To display version info:
$ {command}
""",
}
def Run(self, args):
command_executor = anthoscli_backend.AnthosAuthWrapper()
response = command_executor(
command='version',
show_exec_error=args.show_exec_error,
env=anthoscli_backend.GetEnvArgsForCommand())
return self._DefaultOperationResponseHandler(response)

View File

@@ -0,0 +1,27 @@
# -*- 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 gcloud anthos config command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class AnthosConfig(base.Group):
"""Anthos configuration command group."""
category = base.ANTHOS_CLI_CATEGORY

View File

@@ -0,0 +1,29 @@
# -*- 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 gcloud anthos config controller command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class AnthosConfig(base.Group):
"""Manage Anthos Config Controller instances.
Commands for managing Anthos Config Controller Instances.
"""

View File

@@ -0,0 +1,123 @@
# -*- 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.
"""Command to create new Config Controller instances."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container import util as container_util
from googlecloudsdk.api_lib.krmapihosting import util as krmapihosting_api
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.anthos.config.controller import create_utils
from googlecloudsdk.command_lib.anthos.config.controller import flags
from googlecloudsdk.command_lib.anthos.config.controller import utils
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create Anthos Config Controller instances."""
_API_VERSION = "v1"
detailed_help = {
"DESCRIPTION":
"Create an Anthos Config Controller instance.",
"EXAMPLES": ("""
To create an Anthos Config Controller instance with the name ``acc-default'', run:
$ {command} acc-default --location=us-central1
""")
}
@staticmethod
def Args(parser):
utils.AddInstanceResourceArg(parser, Create._API_VERSION)
flags.AddAsyncFlag(parser)
flags.AddMasterIPv4CIDRBlock(parser)
flags.AddNetworkFlag(parser)
flags.AddSubnetFlag(parser)
flags.AddManBlockFlagDeprecated(parser)
flags.AddManBlocksFlag(parser)
flags.AddClusterIPv4CIDRBlock(parser)
flags.AddServicesIPv4CIDRBlack(parser)
flags.AddClusterNamedRangeFlag(parser)
flags.AddServicesNamedRange(parser)
flags.AddUsePrivateEndpoint(parser)
flags.AddFullManagement(parser)
def Run(self, args):
client = krmapihosting_api.GetClientInstance(api_version=self._API_VERSION)
instance_ref = args.CONCEPTS.name.Parse()
release_track = args.calliope_command.ReleaseTrack()
op_ref = client.projects_locations_krmApiHosts.Create(
create_utils.CreateUpdateRequest(release_track, instance_ref, args))
log.status.Print("Create request issued for: [{}]".format(
instance_ref.krmApiHostsId))
if args.async_:
ops = op_ref.name.split("/")
log.status.Print("Check operation [{}] for status.\n"
"To describe the operation, run:\n\n"
"$ gcloud anthos config operations describe {} "
"--location {}"
.format(op_ref.name, ops[-1], args.location))
return op_ref
op_resource = resources.REGISTRY.ParseRelativeName(
op_ref.name, collection="krmapihosting.projects.locations.operations",
api_version=self._API_VERSION)
poller = waiter.CloudOperationPoller(client.projects_locations_krmApiHosts,
client.projects_locations_operations)
result = waiter.WaitFor(
poller, op_resource,
"Waiting for operation [{}] to complete".format(op_ref.name))
log.status.Print("Created instance [{}].".format(
instance_ref.krmApiHostsId))
container_util.CheckKubectlInstalled()
cluster, cluster_ref = utils.GetGKECluster(instance_ref.krmApiHostsId,
instance_ref.locationsId)
container_util.ClusterConfig.Persist(cluster, cluster_ref.projectId)
return result
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateAlpha(Create):
"""Create Anthos Config Controller instances."""
_API_VERSION = "v1alpha1"
@staticmethod
def Args(parser):
utils.AddInstanceResourceArg(parser, CreateAlpha._API_VERSION)
flags.AddAsyncFlag(parser)
flags.AddMasterIPv4CIDRBlock(parser)
flags.AddNetworkFlag(parser)
flags.AddSubnetFlag(parser)
flags.AddManBlockFlagDeprecated(parser)
flags.AddManBlocksFlag(parser)
flags.AddClusterIPv4CIDRBlock(parser)
flags.AddServicesIPv4CIDRBlack(parser)
flags.AddClusterNamedRangeFlag(parser)
flags.AddServicesNamedRange(parser)
flags.AddFullManagement(parser)
flags.AddUsePrivateEndpoint(parser)
flags.AddExperimentalFeaturesFlag(parser)

View File

@@ -0,0 +1,19 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: Delete Anthos Config Controller instances
description: Delete an Anthos Config Controller instance.
examples: |
To delete an Anthos Config Controller instance, run:
$ {command} NAME --location=LOCATION
request:
collection: krmapihosting.projects.locations.krmApiHosts
method: delete
async:
collection: krmapihosting.projects.locations.operations
arguments:
resource:
help_text: The identifier for an Anthos Config Controller instance.
spec: !REF googlecloudsdk.command_lib.anthos.config.controller.resources:instance

View File

@@ -0,0 +1,17 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: Describe Anthos Config Controller instances.
description: Describe an Anthos Config Controller instance.
examples: |
To describe an Anthos Config Controller instance named default in the location ``us-central1'', run:
$ {command} default --location=us-central1
request:
collection: krmapihosting.projects.locations.krmApiHosts
arguments:
resource:
help_text: The identifier for an Anthos Config Controller instance.
spec: !REF googlecloudsdk.command_lib.anthos.config.controller.resources:instance

View File

@@ -0,0 +1,102 @@
# -*- 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.
"""Fetch default Config Connector identity."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import io
from googlecloudsdk.api_lib.container import util as container_util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.composer import util as composer_util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
def _BaseRun(args):
"""Base operations for `get-config-connector-identity` run command."""
container_util.CheckKubectlInstalled()
cluster_id = 'krmapihost-' + args.name
location = args.location
project_id = args.project or properties.VALUES.core.project.GetOrFail()
GetConfigConnectorIdentityForCluster(location, cluster_id, project_id)
def GetConfigConnectorIdentityForCluster(location, cluster_id, project_id):
"""Get Config Connector identity for the given cluster."""
with composer_util.TemporaryKubeconfig(location, cluster_id):
output = io.StringIO()
composer_util.RunKubectlCommand([
'get', 'ConfigConnectorContext', '-o',
'jsonpath="{.items[0].spec.googleServiceAccount}"'
],
out_func=output.write,
err_func=log.err.write,
namespace='config-control')
identity = output.getvalue().replace('"', '')
log.status.Print(
'Default Config Connector identity: [{identity}].\n'
'\n'
'For example, to give Config Connector permission to manage Google Cloud resources in the same project:\n'
'gcloud projects add-iam-policy-binding {project_id} \\\n'
' --member \"serviceAccount:{identity}\" \\\n'
' --role \"roles/owner\" \\\n'
' --project {project_id}\n'.format(
identity=identity, project_id=project_id))
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class GetConfigConnectorIdentity(base.Command):
"""Fetch default Config Connector identity.
{command} prints the default Config Connector Google Service Account in
a specific Anthos Config Controller.
"""
detailed_help = {
'EXAMPLES':
"""\
To print the default Config Connector identity used by your
Config Controller 'main' in the location 'us-central1', run:
$ {command} main --location=us-central1
""",
}
@staticmethod
def Args(parser):
"""Register flags for this command.
Args:
parser: An argparse.ArgumentParser-like object. It is mocked out in order
to capture some information, but behaves like an ArgumentParser.
"""
parser.add_argument('name', help='Name of the Anthos Config Controller.')
parser.add_argument(
'--location',
required=True,
help='The location (region) of the Anthos Config Controller.')
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
"""
_BaseRun(args)

View File

@@ -0,0 +1,91 @@
# -*- 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.
"""Fetch Config Controller credentials."""
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.container import util as container_util
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
NOT_RUNNING_MSG = """\
Config Controller {0} is not running. The kubernetes API may not be available."""
def _BaseRun(args):
"""Base operations for `get-credentials` run command."""
container_util.CheckKubectlInstalled()
cluster_id = 'krmapihost-' + args.name
location_id = args.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
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class GetCredentialsAlpha(base.Command):
"""Fetch credentials for a running Anthos Config Controller.
{command} updates a `kubeconfig` file with appropriate credentials and
endpoint information to point `kubectl` at a specific
Anthos Config Controller.
"""
detailed_help = {
'EXAMPLES':
"""\
To switch to working on your Config Controller 'main', run:
$ {command} main --location=us-central1
""",
}
@staticmethod
def Args(parser):
"""Register flags for this command.
Args:
parser: An argparse.ArgumentParser-like object. It is mocked out in order
to capture some information, but behaves like an ArgumentParser.
"""
parser.add_argument('name', help='Name of the Anthos Config Controller.')
parser.add_argument(
'--location',
required=True,
help='The location (region) of the Anthos Config Controller.')
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Raises:
container_util.Error: if the cluster is unreachable or not running.
"""
cluster, cluster_ref = _BaseRun(args)
container_util.ClusterConfig.Persist(cluster, cluster_ref.projectId)

View File

@@ -0,0 +1,39 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: List Anthos Config Controller instances
description: List Anthos Config Controller instances.
examples: |
To list all Anthos Config Controller instances in the region 'us-central1', run:
$ {command} --location=us-central1
To list all Anthos Config Controller instances in all regions with their fully specified name, run:
$ {command} --full-name
To list all Anthos Config Controller instances in all regions, run:
$ {command}
request:
collection: krmapihosting.projects.locations.krmApiHosts
arguments:
resource:
help_text: List of Anthos Config Controller instances.
spec: !REF googlecloudsdk.command_lib.anthos.config.controller.resources:instance-list
params:
- arg_name: full-name
action: store_true
default: false
disable_unused_arg_check: true
help_text: |
Print the fully specified name of the instance.
output:
format: table(
name.scope("krmApiHosts").if(NOT full_name),
name.if(full_name),
name.scope("locations").segment(0):label=LOCATION,
state)

View File

@@ -0,0 +1,65 @@
# -*- 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 to update an Anthos Config Controller instance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.krmapihosting import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.anthos.config.controller import flags
from googlecloudsdk.command_lib.anthos.config.controller import utils
# TODO(b/234495254): promote the update command to GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Update(base.UpdateCommand):
"""Update an Anthos Config Controller instance."""
_API_VERSION = "v1alpha1"
detailed_help = {
"DESCRIPTION":
"Update an Anthos Config Controller instance.",
"EXAMPLES":
"""
To update the master authorized network for an existing Anthos Config
Controller instance, run:
$ {command} sample-instance --man-block=MAN_BLOCK
"""
}
@staticmethod
def Args(parser):
utils.AddInstanceResourceArg(parser, Update._API_VERSION)
flags.AddAsyncFlag(parser)
flags.AddExperimentalFeaturesFlag(parser)
flags.AddManBlockFlag(parser)
def Run(self, args):
op = util.GetClientInstance(
api_version=self._API_VERSION).projects_locations_krmApiHosts.Patch(
utils.PatchRequest(args))
if args.async_:
return utils.AsyncLog(op)
return util.WaitForCreateKrmApiHostOperation(
op,
progress_message="Waiting for operation [{}] to complete".format(
op.name))

View File

@@ -0,0 +1,26 @@
# -*- 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.
"""The gcloud anthos config operations command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Operations(base.Group):
"""Get and list operations for Anthos Config Controller instances."""

View File

@@ -0,0 +1,17 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: Describe Anthos Config Controller operations.
description: Describe an Anthos Config Controller operation.
examples: |
To describe an Anthos Config Controller operation named my-operation in the location ``us-central1'', run:
$ {command} my-operation --location=us-central1
request:
collection: krmapihosting.projects.locations.operations
arguments:
resource:
help_text: The identifier for an Anthos Config Controller operation.
spec: !REF googlecloudsdk.command_lib.anthos.config.controller.resources:operation

View File

@@ -0,0 +1,31 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: List Anthos Config Controller operations
description: List Anthos Config Controller operations.
examples: |
To list all Anthos Config Controller operations in the region 'us-central1', run:
$ {command} --location=us-central1
To list all Anthos Config Controller operations in all regions, run:
$ {command}
request:
collection: krmapihosting.projects.locations.operations
arguments:
resource:
help_text: List of Anthos Config Controller operations.
spec: !REF googlecloudsdk.command_lib.anthos.config.controller.resources:operation-list
output:
format: |
table(
name.scope("operations").segment(0),
name.scope("locations").segment(0):label=LOCATION,
done,
metadata.createTime.date(unit=1000, tz_default=UTC),
metadata.endTime.date(unit=1000, tz_default=UTC)
)

View File

@@ -0,0 +1,64 @@
# -*- 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.
"""Authenticate clusters using the Anthos client.."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.anthos import anthoscli_backend
from googlecloudsdk.command_lib.anthos import flags
from googlecloudsdk.command_lib.anthos.common import kube_flags
class CreateLoginConfig(base.BinaryBackedCommand):
"""Generates a login configuration file.
Generates the file containing configuration information developers
will use to authenticate to an AWS Anthos cluster.
"""
detailed_help = {
'EXAMPLES': """
To generate the default login config file (kubectl-anthos-config.yaml) using
the kubeconfig file 'my-kube-config.yaml':
$ {command} --kubeconfig 'my-kube-config.yaml'
To generate a config named 'myconfg.yaml' the --kubeconfig file 'my-kube-config.yaml':
$ {command} --kubeconfig 'my-kube-config.yaml' --output 'myconfg.yaml'
""",
}
@staticmethod
def Args(parser):
kube_flags.GetKubeConfigFlag('Specifies the input kubeconfig '
'file to access user cluster for '
'login configuration data.',
required=True).AddToParser(parser)
flags.GetConfigOutputFileFlag().AddToParser(parser)
flags.GetMergeFromFlag().AddToParser(parser)
def Run(self, args):
command_executor = anthoscli_backend.AnthosAuthWrapper()
response = command_executor(
command='create-login-config',
kube_config=args.kubeconfig,
output_file=args.output,
merge_from=args.merge_from,
show_exec_error=args.show_exec_error,
env=anthoscli_backend.GetEnvArgsForCommand())
return anthoscli_backend.LoginResponseHandler(response)

View File

@@ -0,0 +1,73 @@
# -*- 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.
"""Export current configuration of an Anthos cluster."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.anthos import anthoscli_backend
from googlecloudsdk.command_lib.anthos import flags
from googlecloudsdk.command_lib.util.args import common_args
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Export(base.BinaryBackedCommand):
"""Export current configuration of an Anthos cluster."""
detailed_help = {
'EXAMPLES': """
To export configuration from cluster 'my-cluster' to the local directory
`my-dir` using project 'my-project':
$ {command} my-cluster --project=my-project --output-directory=my-dir
""",
}
@staticmethod
def Args(parser):
flags.GetClusterFlag(positional=True,
help_override='The cluster name from '
'which to export the '
'configurations.').AddToParser(parser)
flags.GetLocationFlag().AddToParser(parser)
flags.GetOutputDirFlag().AddToParser(parser)
common_args.ProjectArgument(
help_text_to_overwrite='Project ID.').AddToParser(parser)
def Run(self, args):
command_executor = anthoscli_backend.AnthosCliWrapper()
export_project = args.project or properties.VALUES.core.project.Get()
cluster = args.CLUSTER or properties.VALUES.compute.zone.Get()
location = args.location
output_dir = args.OUTPUT_DIRECTORY
auth_cred = anthoscli_backend.GetAuthToken(
account=properties.VALUES.core.account.Get(), operation='export')
log.status.Print('Starting export of cluster [{}] using '
'project [{}]'.format(cluster, export_project))
response = command_executor(command='export',
cluster=cluster,
project=export_project,
location=location,
output_dir=output_dir,
show_exec_error=args.show_exec_error,
env=anthoscli_backend.GetEnvArgsForCommand(
extra_vars={'GCLOUD_AUTH_PLUGIN': 'true'}),
stdin=auth_cred)
return self._DefaultOperationResponseHandler(response)

View File

@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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 gcloud anthos packages command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Packages(base.Group):
"""Anthos packages command group.
Manage Anthos configuration file packages using git.
Fetch, update, and publish packages of Resource configuration as
subdirectories of git repositories.
"""

View File

@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Describe local Anthos package."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.anthos import anthoscli_backend
from googlecloudsdk.command_lib.anthos import flags
class Describe(base.BinaryBackedCommand):
"""Describe local Anthos package.
Display package description.
"""
detailed_help = {
'EXAMPLES': """
To describe current directory:
$ {command}
To describe package `my-foo` in user HOME dir:
$ {command} ~/my-foo
""",
}
@staticmethod
def Args(parser):
flags.GetLocalDirFlag(
help_override='The local of package directory.').AddToParser(parser)
def Run(self, args):
command_executor = anthoscli_backend.AnthosCliWrapper()
response = command_executor(command='desc',
local_dir=args.LOCAL_DIR,
env=anthoscli_backend.GetEnvArgsForCommand(),
show_exec_error=args.show_exec_error)
return self._DefaultOperationResponseHandler(response)

View File

@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Fetch Anthos package from a git repository."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.anthos import anthoscli_backend
from googlecloudsdk.command_lib.anthos import flags
class Get(base.BinaryBackedCommand):
"""Fetch Anthos package from a git repository."""
detailed_help = {
'EXAMPLES': """
To fetch package FOO from github into local package dir
`my-foo`:
$ {command} https://github.com/myaccount/foo.git --local-dir my-foo
To fetch package myaccount/foo.git/other_package from github,
with tag 'v123' into local package dir 'my-foo':
$ {command} https://github.com/myaccount/foo.git/other_package@v123 --local-dir my-foo
""",
}
@staticmethod
def Args(parser):
flags.GetRepoURIFlag().AddToParser(parser)
flags.GetLocalDirFlag(positional=False).AddToParser(parser)
flags.GetFilePatternFlag().AddToParser(parser)
def Run(self, args):
command_executor = anthoscli_backend.AnthosCliWrapper()
response = command_executor(command='get',
repo_uri=args.REPO_URI,
local_dest=args.LOCAL_DIR,
env=anthoscli_backend.GetEnvArgsForCommand(),
show_exec_error=args.show_exec_error,
file_pattern=args.PATTERN)
return self._DefaultOperationResponseHandler(response)

View File

@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Update a local package with changes from a remote source repo."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.anthos import anthoscli_backend
from googlecloudsdk.command_lib.anthos import flags
from googlecloudsdk.core import log
_LOCAL_DIR_HELP = ('The local package directory to update. Can optionally '
'include a git reference (GIT_REF) to a tag, branch or '
'commit hash to update to. '
'Defaults to last fetched git-ref.')
_LOCAL_DIR_META = 'LOCAL_DIR[@GIT_REF]'
class Update(base.BinaryBackedCommand):
"""Update a local package with changes from a remote source repo."""
detailed_help = {
'EXAMPLES': """
To update local package `~/my-package-dir`:
$ {command} ~/my-package-dir
To update my-package-dir/ to match the v1.3 tag at git URL
https://github.com/my-other-account/foo.git:
$ {command} my-package-dir@v1.3 --repo-uri https://github.com/my-other-account/foo.git
To update by applying a git patch:
$ git add my-package-dir/
$ git commit -m "package updates"
$ {command} my-package-dir/@main --strategy alpha-git-patch
""",
}
@staticmethod
def Args(parser):
flags.GetLocalDirFlag(help_override=_LOCAL_DIR_HELP,
metavar=_LOCAL_DIR_META).AddToParser(parser)
flags.GetRepoURIFlag(positional=False, required=False, metavar='REPO_URI',
help_override='git repo url for updating contents. '
'Defaults to the url the package was '
'fetched from.').AddToParser(parser)
flags.GetStrategyFlag().AddToParser(parser)
flags.GetDryRunFlag().AddToParser(parser)
def Run(self, args):
is_verbose = args.verbosity == 'debug'
command_executor = anthoscli_backend.AnthosCliWrapper()
log.status.Print('Syncing dir [{}]'.format(args.LOCAL_DIR))
# kpt update requires relative path
work_dir, at_symbol, git_ref = args.LOCAL_DIR.partition('@')
pkg_dir = at_symbol.join(['.', git_ref]) if git_ref else '.'
response = command_executor(command='update',
local_dir=pkg_dir,
repo_uri=args.REPO_URI,
strategy=args.strategy,
dry_run=args.dry_run,
verbose=is_verbose,
show_exec_error=args.show_exec_error,
env=anthoscli_backend.GetEnvArgsForCommand(),
execution_dir=work_dir)
return self._DefaultOperationResponseHandler(response)