paasta-tools 1.21.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- k8s_itests/__init__.py +0 -0
- k8s_itests/test_autoscaling.py +23 -0
- k8s_itests/utils.py +38 -0
- paasta_tools/__init__.py +20 -0
- paasta_tools/adhoc_tools.py +142 -0
- paasta_tools/api/__init__.py +13 -0
- paasta_tools/api/api.py +330 -0
- paasta_tools/api/api_docs/swagger.json +2323 -0
- paasta_tools/api/client.py +106 -0
- paasta_tools/api/settings.py +33 -0
- paasta_tools/api/tweens/__init__.py +6 -0
- paasta_tools/api/tweens/auth.py +125 -0
- paasta_tools/api/tweens/profiling.py +108 -0
- paasta_tools/api/tweens/request_logger.py +124 -0
- paasta_tools/api/views/__init__.py +13 -0
- paasta_tools/api/views/autoscaler.py +100 -0
- paasta_tools/api/views/exception.py +45 -0
- paasta_tools/api/views/flink.py +73 -0
- paasta_tools/api/views/instance.py +395 -0
- paasta_tools/api/views/pause_autoscaler.py +71 -0
- paasta_tools/api/views/remote_run.py +113 -0
- paasta_tools/api/views/resources.py +76 -0
- paasta_tools/api/views/service.py +35 -0
- paasta_tools/api/views/version.py +25 -0
- paasta_tools/apply_external_resources.py +79 -0
- paasta_tools/async_utils.py +109 -0
- paasta_tools/autoscaling/__init__.py +0 -0
- paasta_tools/autoscaling/autoscaling_service_lib.py +57 -0
- paasta_tools/autoscaling/forecasting.py +106 -0
- paasta_tools/autoscaling/max_all_k8s_services.py +41 -0
- paasta_tools/autoscaling/pause_service_autoscaler.py +77 -0
- paasta_tools/autoscaling/utils.py +52 -0
- paasta_tools/bounce_lib.py +184 -0
- paasta_tools/broadcast_log_to_services.py +62 -0
- paasta_tools/cassandracluster_tools.py +210 -0
- paasta_tools/check_autoscaler_max_instances.py +212 -0
- paasta_tools/check_cassandracluster_services_replication.py +35 -0
- paasta_tools/check_flink_services_health.py +203 -0
- paasta_tools/check_kubernetes_api.py +57 -0
- paasta_tools/check_kubernetes_services_replication.py +141 -0
- paasta_tools/check_oom_events.py +244 -0
- paasta_tools/check_services_replication_tools.py +324 -0
- paasta_tools/check_spark_jobs.py +234 -0
- paasta_tools/cleanup_kubernetes_cr.py +138 -0
- paasta_tools/cleanup_kubernetes_crd.py +145 -0
- paasta_tools/cleanup_kubernetes_jobs.py +344 -0
- paasta_tools/cleanup_tron_namespaces.py +96 -0
- paasta_tools/cli/__init__.py +13 -0
- paasta_tools/cli/authentication.py +85 -0
- paasta_tools/cli/cli.py +260 -0
- paasta_tools/cli/cmds/__init__.py +13 -0
- paasta_tools/cli/cmds/autoscale.py +143 -0
- paasta_tools/cli/cmds/check.py +334 -0
- paasta_tools/cli/cmds/cook_image.py +147 -0
- paasta_tools/cli/cmds/get_docker_image.py +76 -0
- paasta_tools/cli/cmds/get_image_version.py +172 -0
- paasta_tools/cli/cmds/get_latest_deployment.py +93 -0
- paasta_tools/cli/cmds/info.py +155 -0
- paasta_tools/cli/cmds/itest.py +117 -0
- paasta_tools/cli/cmds/list.py +66 -0
- paasta_tools/cli/cmds/list_clusters.py +42 -0
- paasta_tools/cli/cmds/list_deploy_queue.py +171 -0
- paasta_tools/cli/cmds/list_namespaces.py +84 -0
- paasta_tools/cli/cmds/local_run.py +1396 -0
- paasta_tools/cli/cmds/logs.py +1601 -0
- paasta_tools/cli/cmds/mark_for_deployment.py +1988 -0
- paasta_tools/cli/cmds/mesh_status.py +174 -0
- paasta_tools/cli/cmds/pause_service_autoscaler.py +107 -0
- paasta_tools/cli/cmds/push_to_registry.py +275 -0
- paasta_tools/cli/cmds/remote_run.py +252 -0
- paasta_tools/cli/cmds/rollback.py +347 -0
- paasta_tools/cli/cmds/secret.py +549 -0
- paasta_tools/cli/cmds/security_check.py +59 -0
- paasta_tools/cli/cmds/spark_run.py +1400 -0
- paasta_tools/cli/cmds/start_stop_restart.py +401 -0
- paasta_tools/cli/cmds/status.py +2302 -0
- paasta_tools/cli/cmds/validate.py +1012 -0
- paasta_tools/cli/cmds/wait_for_deployment.py +275 -0
- paasta_tools/cli/fsm/__init__.py +13 -0
- paasta_tools/cli/fsm/autosuggest.py +82 -0
- paasta_tools/cli/fsm/template/README.md +8 -0
- paasta_tools/cli/fsm/template/cookiecutter.json +7 -0
- paasta_tools/cli/fsm/template/{{cookiecutter.service}}/kubernetes-PROD.yaml +91 -0
- paasta_tools/cli/fsm/template/{{cookiecutter.service}}/monitoring.yaml +20 -0
- paasta_tools/cli/fsm/template/{{cookiecutter.service}}/service.yaml +8 -0
- paasta_tools/cli/fsm/template/{{cookiecutter.service}}/smartstack.yaml +6 -0
- paasta_tools/cli/fsm_cmd.py +121 -0
- paasta_tools/cli/paasta_tabcomplete.sh +23 -0
- paasta_tools/cli/schemas/adhoc_schema.json +199 -0
- paasta_tools/cli/schemas/autoscaling_schema.json +91 -0
- paasta_tools/cli/schemas/autotuned_defaults/cassandracluster_schema.json +37 -0
- paasta_tools/cli/schemas/autotuned_defaults/kubernetes_schema.json +89 -0
- paasta_tools/cli/schemas/deploy_schema.json +173 -0
- paasta_tools/cli/schemas/eks_schema.json +970 -0
- paasta_tools/cli/schemas/kubernetes_schema.json +970 -0
- paasta_tools/cli/schemas/rollback_schema.json +160 -0
- paasta_tools/cli/schemas/service_schema.json +25 -0
- paasta_tools/cli/schemas/smartstack_schema.json +322 -0
- paasta_tools/cli/schemas/tron_schema.json +699 -0
- paasta_tools/cli/utils.py +1118 -0
- paasta_tools/clusterman.py +21 -0
- paasta_tools/config_utils.py +385 -0
- paasta_tools/contrib/__init__.py +0 -0
- paasta_tools/contrib/bounce_log_latency_parser.py +68 -0
- paasta_tools/contrib/check_manual_oapi_changes.sh +24 -0
- paasta_tools/contrib/check_orphans.py +306 -0
- paasta_tools/contrib/create_dynamodb_table.py +35 -0
- paasta_tools/contrib/create_paasta_playground.py +105 -0
- paasta_tools/contrib/emit_allocated_cpu_metrics.py +50 -0
- paasta_tools/contrib/get_running_task_allocation.py +346 -0
- paasta_tools/contrib/habitat_fixer.py +86 -0
- paasta_tools/contrib/ide_helper.py +316 -0
- paasta_tools/contrib/is_pod_healthy_in_proxy.py +139 -0
- paasta_tools/contrib/is_pod_healthy_in_smartstack.py +50 -0
- paasta_tools/contrib/kill_bad_containers.py +109 -0
- paasta_tools/contrib/mass-deploy-tag.sh +44 -0
- paasta_tools/contrib/mock_patch_checker.py +86 -0
- paasta_tools/contrib/paasta_update_soa_memcpu.py +520 -0
- paasta_tools/contrib/render_template.py +129 -0
- paasta_tools/contrib/rightsizer_soaconfigs_update.py +348 -0
- paasta_tools/contrib/service_shard_remove.py +157 -0
- paasta_tools/contrib/service_shard_update.py +373 -0
- paasta_tools/contrib/shared_ip_check.py +77 -0
- paasta_tools/contrib/timeouts_metrics_prom.py +64 -0
- paasta_tools/delete_kubernetes_deployments.py +89 -0
- paasta_tools/deployment_utils.py +44 -0
- paasta_tools/docker_wrapper.py +234 -0
- paasta_tools/docker_wrapper_imports.py +13 -0
- paasta_tools/drain_lib.py +351 -0
- paasta_tools/dump_locally_running_services.py +71 -0
- paasta_tools/eks_tools.py +119 -0
- paasta_tools/envoy_tools.py +373 -0
- paasta_tools/firewall.py +504 -0
- paasta_tools/firewall_logging.py +154 -0
- paasta_tools/firewall_update.py +172 -0
- paasta_tools/flink_tools.py +345 -0
- paasta_tools/flinkeks_tools.py +90 -0
- paasta_tools/frameworks/__init__.py +0 -0
- paasta_tools/frameworks/adhoc_scheduler.py +71 -0
- paasta_tools/frameworks/constraints.py +87 -0
- paasta_tools/frameworks/native_scheduler.py +652 -0
- paasta_tools/frameworks/native_service_config.py +301 -0
- paasta_tools/frameworks/task_store.py +245 -0
- paasta_tools/generate_all_deployments +9 -0
- paasta_tools/generate_authenticating_services.py +94 -0
- paasta_tools/generate_deployments_for_service.py +255 -0
- paasta_tools/generate_services_file.py +114 -0
- paasta_tools/generate_services_yaml.py +30 -0
- paasta_tools/hacheck.py +76 -0
- paasta_tools/instance/__init__.py +0 -0
- paasta_tools/instance/hpa_metrics_parser.py +122 -0
- paasta_tools/instance/kubernetes.py +1362 -0
- paasta_tools/iptables.py +240 -0
- paasta_tools/kafkacluster_tools.py +143 -0
- paasta_tools/kubernetes/__init__.py +0 -0
- paasta_tools/kubernetes/application/__init__.py +0 -0
- paasta_tools/kubernetes/application/controller_wrappers.py +476 -0
- paasta_tools/kubernetes/application/tools.py +90 -0
- paasta_tools/kubernetes/bin/__init__.py +0 -0
- paasta_tools/kubernetes/bin/kubernetes_remove_evicted_pods.py +164 -0
- paasta_tools/kubernetes/bin/paasta_cleanup_remote_run_resources.py +135 -0
- paasta_tools/kubernetes/bin/paasta_cleanup_stale_nodes.py +181 -0
- paasta_tools/kubernetes/bin/paasta_secrets_sync.py +758 -0
- paasta_tools/kubernetes/remote_run.py +558 -0
- paasta_tools/kubernetes_tools.py +4679 -0
- paasta_tools/list_kubernetes_service_instances.py +128 -0
- paasta_tools/list_tron_namespaces.py +60 -0
- paasta_tools/long_running_service_tools.py +678 -0
- paasta_tools/mac_address.py +44 -0
- paasta_tools/marathon_dashboard.py +0 -0
- paasta_tools/mesos/__init__.py +0 -0
- paasta_tools/mesos/cfg.py +46 -0
- paasta_tools/mesos/cluster.py +60 -0
- paasta_tools/mesos/exceptions.py +59 -0
- paasta_tools/mesos/framework.py +77 -0
- paasta_tools/mesos/log.py +48 -0
- paasta_tools/mesos/master.py +306 -0
- paasta_tools/mesos/mesos_file.py +169 -0
- paasta_tools/mesos/parallel.py +52 -0
- paasta_tools/mesos/slave.py +115 -0
- paasta_tools/mesos/task.py +94 -0
- paasta_tools/mesos/util.py +69 -0
- paasta_tools/mesos/zookeeper.py +37 -0
- paasta_tools/mesos_maintenance.py +848 -0
- paasta_tools/mesos_tools.py +1051 -0
- paasta_tools/metrics/__init__.py +0 -0
- paasta_tools/metrics/metastatus_lib.py +1110 -0
- paasta_tools/metrics/metrics_lib.py +217 -0
- paasta_tools/monitoring/__init__.py +13 -0
- paasta_tools/monitoring/check_k8s_api_performance.py +110 -0
- paasta_tools/monitoring_tools.py +652 -0
- paasta_tools/monkrelaycluster_tools.py +146 -0
- paasta_tools/nrtsearchservice_tools.py +143 -0
- paasta_tools/nrtsearchserviceeks_tools.py +68 -0
- paasta_tools/oom_logger.py +321 -0
- paasta_tools/paasta_deploy_tron_jobs +3 -0
- paasta_tools/paasta_execute_docker_command.py +123 -0
- paasta_tools/paasta_native_serviceinit.py +21 -0
- paasta_tools/paasta_service_config_loader.py +201 -0
- paasta_tools/paastaapi/__init__.py +29 -0
- paasta_tools/paastaapi/api/__init__.py +3 -0
- paasta_tools/paastaapi/api/autoscaler_api.py +302 -0
- paasta_tools/paastaapi/api/default_api.py +569 -0
- paasta_tools/paastaapi/api/remote_run_api.py +604 -0
- paasta_tools/paastaapi/api/resources_api.py +157 -0
- paasta_tools/paastaapi/api/service_api.py +1736 -0
- paasta_tools/paastaapi/api_client.py +818 -0
- paasta_tools/paastaapi/apis/__init__.py +22 -0
- paasta_tools/paastaapi/configuration.py +455 -0
- paasta_tools/paastaapi/exceptions.py +137 -0
- paasta_tools/paastaapi/model/__init__.py +5 -0
- paasta_tools/paastaapi/model/adhoc_launch_history.py +176 -0
- paasta_tools/paastaapi/model/autoscaler_count_msg.py +176 -0
- paasta_tools/paastaapi/model/deploy_queue.py +178 -0
- paasta_tools/paastaapi/model/deploy_queue_service_instance.py +194 -0
- paasta_tools/paastaapi/model/envoy_backend.py +185 -0
- paasta_tools/paastaapi/model/envoy_location.py +184 -0
- paasta_tools/paastaapi/model/envoy_status.py +181 -0
- paasta_tools/paastaapi/model/flink_cluster_overview.py +188 -0
- paasta_tools/paastaapi/model/flink_config.py +173 -0
- paasta_tools/paastaapi/model/flink_job.py +186 -0
- paasta_tools/paastaapi/model/flink_job_details.py +192 -0
- paasta_tools/paastaapi/model/flink_jobs.py +175 -0
- paasta_tools/paastaapi/model/float_and_error.py +173 -0
- paasta_tools/paastaapi/model/hpa_metric.py +176 -0
- paasta_tools/paastaapi/model/inline_object.py +170 -0
- paasta_tools/paastaapi/model/inline_response200.py +170 -0
- paasta_tools/paastaapi/model/inline_response2001.py +170 -0
- paasta_tools/paastaapi/model/instance_bounce_status.py +200 -0
- paasta_tools/paastaapi/model/instance_mesh_status.py +186 -0
- paasta_tools/paastaapi/model/instance_status.py +220 -0
- paasta_tools/paastaapi/model/instance_status_adhoc.py +187 -0
- paasta_tools/paastaapi/model/instance_status_cassandracluster.py +173 -0
- paasta_tools/paastaapi/model/instance_status_flink.py +173 -0
- paasta_tools/paastaapi/model/instance_status_kafkacluster.py +173 -0
- paasta_tools/paastaapi/model/instance_status_kubernetes.py +263 -0
- paasta_tools/paastaapi/model/instance_status_kubernetes_autoscaling_status.py +187 -0
- paasta_tools/paastaapi/model/instance_status_kubernetes_v2.py +197 -0
- paasta_tools/paastaapi/model/instance_status_tron.py +204 -0
- paasta_tools/paastaapi/model/instance_tasks.py +182 -0
- paasta_tools/paastaapi/model/integer_and_error.py +173 -0
- paasta_tools/paastaapi/model/kubernetes_container.py +178 -0
- paasta_tools/paastaapi/model/kubernetes_container_v2.py +219 -0
- paasta_tools/paastaapi/model/kubernetes_healthcheck.py +176 -0
- paasta_tools/paastaapi/model/kubernetes_pod.py +201 -0
- paasta_tools/paastaapi/model/kubernetes_pod_event.py +176 -0
- paasta_tools/paastaapi/model/kubernetes_pod_v2.py +213 -0
- paasta_tools/paastaapi/model/kubernetes_replica_set.py +185 -0
- paasta_tools/paastaapi/model/kubernetes_version.py +202 -0
- paasta_tools/paastaapi/model/remote_run_outcome.py +189 -0
- paasta_tools/paastaapi/model/remote_run_start.py +185 -0
- paasta_tools/paastaapi/model/remote_run_stop.py +176 -0
- paasta_tools/paastaapi/model/remote_run_token.py +173 -0
- paasta_tools/paastaapi/model/resource.py +187 -0
- paasta_tools/paastaapi/model/resource_item.py +187 -0
- paasta_tools/paastaapi/model/resource_value.py +176 -0
- paasta_tools/paastaapi/model/smartstack_backend.py +191 -0
- paasta_tools/paastaapi/model/smartstack_location.py +181 -0
- paasta_tools/paastaapi/model/smartstack_status.py +181 -0
- paasta_tools/paastaapi/model/task_tail_lines.py +176 -0
- paasta_tools/paastaapi/model_utils.py +1879 -0
- paasta_tools/paastaapi/models/__init__.py +62 -0
- paasta_tools/paastaapi/rest.py +287 -0
- paasta_tools/prune_completed_pods.py +220 -0
- paasta_tools/puppet_service_tools.py +59 -0
- paasta_tools/py.typed +1 -0
- paasta_tools/remote_git.py +127 -0
- paasta_tools/run-paasta-api-in-dev-mode.py +57 -0
- paasta_tools/run-paasta-api-playground.py +51 -0
- paasta_tools/secret_providers/__init__.py +66 -0
- paasta_tools/secret_providers/vault.py +214 -0
- paasta_tools/secret_tools.py +277 -0
- paasta_tools/setup_istio_mesh.py +353 -0
- paasta_tools/setup_kubernetes_cr.py +412 -0
- paasta_tools/setup_kubernetes_crd.py +138 -0
- paasta_tools/setup_kubernetes_internal_crd.py +154 -0
- paasta_tools/setup_kubernetes_job.py +353 -0
- paasta_tools/setup_prometheus_adapter_config.py +1028 -0
- paasta_tools/setup_tron_namespace.py +248 -0
- paasta_tools/slack.py +75 -0
- paasta_tools/smartstack_tools.py +676 -0
- paasta_tools/spark_tools.py +283 -0
- paasta_tools/synapse_srv_namespaces_fact.py +42 -0
- paasta_tools/tron/__init__.py +0 -0
- paasta_tools/tron/client.py +158 -0
- paasta_tools/tron/tron_command_context.py +194 -0
- paasta_tools/tron/tron_timeutils.py +101 -0
- paasta_tools/tron_tools.py +1448 -0
- paasta_tools/utils.py +4307 -0
- paasta_tools/yaml_tools.py +44 -0
- paasta_tools-1.21.3.data/scripts/apply_external_resources.py +79 -0
- paasta_tools-1.21.3.data/scripts/bounce_log_latency_parser.py +68 -0
- paasta_tools-1.21.3.data/scripts/check_autoscaler_max_instances.py +212 -0
- paasta_tools-1.21.3.data/scripts/check_cassandracluster_services_replication.py +35 -0
- paasta_tools-1.21.3.data/scripts/check_flink_services_health.py +203 -0
- paasta_tools-1.21.3.data/scripts/check_kubernetes_api.py +57 -0
- paasta_tools-1.21.3.data/scripts/check_kubernetes_services_replication.py +141 -0
- paasta_tools-1.21.3.data/scripts/check_manual_oapi_changes.sh +24 -0
- paasta_tools-1.21.3.data/scripts/check_oom_events.py +244 -0
- paasta_tools-1.21.3.data/scripts/check_orphans.py +306 -0
- paasta_tools-1.21.3.data/scripts/check_spark_jobs.py +234 -0
- paasta_tools-1.21.3.data/scripts/cleanup_kubernetes_cr.py +138 -0
- paasta_tools-1.21.3.data/scripts/cleanup_kubernetes_crd.py +145 -0
- paasta_tools-1.21.3.data/scripts/cleanup_kubernetes_jobs.py +344 -0
- paasta_tools-1.21.3.data/scripts/create_dynamodb_table.py +35 -0
- paasta_tools-1.21.3.data/scripts/create_paasta_playground.py +105 -0
- paasta_tools-1.21.3.data/scripts/delete_kubernetes_deployments.py +89 -0
- paasta_tools-1.21.3.data/scripts/emit_allocated_cpu_metrics.py +50 -0
- paasta_tools-1.21.3.data/scripts/generate_all_deployments +9 -0
- paasta_tools-1.21.3.data/scripts/generate_authenticating_services.py +94 -0
- paasta_tools-1.21.3.data/scripts/generate_deployments_for_service.py +255 -0
- paasta_tools-1.21.3.data/scripts/generate_services_file.py +114 -0
- paasta_tools-1.21.3.data/scripts/generate_services_yaml.py +30 -0
- paasta_tools-1.21.3.data/scripts/get_running_task_allocation.py +346 -0
- paasta_tools-1.21.3.data/scripts/habitat_fixer.py +86 -0
- paasta_tools-1.21.3.data/scripts/ide_helper.py +316 -0
- paasta_tools-1.21.3.data/scripts/is_pod_healthy_in_proxy.py +139 -0
- paasta_tools-1.21.3.data/scripts/is_pod_healthy_in_smartstack.py +50 -0
- paasta_tools-1.21.3.data/scripts/kill_bad_containers.py +109 -0
- paasta_tools-1.21.3.data/scripts/kubernetes_remove_evicted_pods.py +164 -0
- paasta_tools-1.21.3.data/scripts/mass-deploy-tag.sh +44 -0
- paasta_tools-1.21.3.data/scripts/mock_patch_checker.py +86 -0
- paasta_tools-1.21.3.data/scripts/paasta_cleanup_remote_run_resources.py +135 -0
- paasta_tools-1.21.3.data/scripts/paasta_cleanup_stale_nodes.py +181 -0
- paasta_tools-1.21.3.data/scripts/paasta_deploy_tron_jobs +3 -0
- paasta_tools-1.21.3.data/scripts/paasta_execute_docker_command.py +123 -0
- paasta_tools-1.21.3.data/scripts/paasta_secrets_sync.py +758 -0
- paasta_tools-1.21.3.data/scripts/paasta_tabcomplete.sh +23 -0
- paasta_tools-1.21.3.data/scripts/paasta_update_soa_memcpu.py +520 -0
- paasta_tools-1.21.3.data/scripts/render_template.py +129 -0
- paasta_tools-1.21.3.data/scripts/rightsizer_soaconfigs_update.py +348 -0
- paasta_tools-1.21.3.data/scripts/service_shard_remove.py +157 -0
- paasta_tools-1.21.3.data/scripts/service_shard_update.py +373 -0
- paasta_tools-1.21.3.data/scripts/setup_istio_mesh.py +353 -0
- paasta_tools-1.21.3.data/scripts/setup_kubernetes_cr.py +412 -0
- paasta_tools-1.21.3.data/scripts/setup_kubernetes_crd.py +138 -0
- paasta_tools-1.21.3.data/scripts/setup_kubernetes_internal_crd.py +154 -0
- paasta_tools-1.21.3.data/scripts/setup_kubernetes_job.py +353 -0
- paasta_tools-1.21.3.data/scripts/setup_prometheus_adapter_config.py +1028 -0
- paasta_tools-1.21.3.data/scripts/shared_ip_check.py +77 -0
- paasta_tools-1.21.3.data/scripts/synapse_srv_namespaces_fact.py +42 -0
- paasta_tools-1.21.3.data/scripts/timeouts_metrics_prom.py +64 -0
- paasta_tools-1.21.3.dist-info/LICENSE +201 -0
- paasta_tools-1.21.3.dist-info/METADATA +74 -0
- paasta_tools-1.21.3.dist-info/RECORD +348 -0
- paasta_tools-1.21.3.dist-info/WHEEL +5 -0
- paasta_tools-1.21.3.dist-info/entry_points.txt +20 -0
- paasta_tools-1.21.3.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
# Copyright 2015-2018 Yelp Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
Usage: ./setup_kubernetes_cr.py [options]
|
|
17
|
+
|
|
18
|
+
Command line options:
|
|
19
|
+
|
|
20
|
+
- -d <SOA_DIR>, --soa-dir <SOA_DIR>: Specify a SOA config dir to read from
|
|
21
|
+
- -v, --verbose: Verbose output
|
|
22
|
+
"""
|
|
23
|
+
import argparse
|
|
24
|
+
import logging
|
|
25
|
+
import sys
|
|
26
|
+
from typing import Any
|
|
27
|
+
from typing import Mapping
|
|
28
|
+
from typing import Optional
|
|
29
|
+
from typing import Sequence
|
|
30
|
+
|
|
31
|
+
from kubernetes.client.exceptions import ApiException
|
|
32
|
+
|
|
33
|
+
from paasta_tools import yaml_tools as yaml
|
|
34
|
+
from paasta_tools.cli.utils import LONG_RUNNING_INSTANCE_TYPE_HANDLERS
|
|
35
|
+
from paasta_tools.flink_tools import get_flink_ingress_url_root
|
|
36
|
+
from paasta_tools.kubernetes_tools import create_custom_resource
|
|
37
|
+
from paasta_tools.kubernetes_tools import CustomResourceDefinition
|
|
38
|
+
from paasta_tools.kubernetes_tools import ensure_namespace
|
|
39
|
+
from paasta_tools.kubernetes_tools import KubeClient
|
|
40
|
+
from paasta_tools.kubernetes_tools import KubeCustomResource
|
|
41
|
+
from paasta_tools.kubernetes_tools import KubeKind
|
|
42
|
+
from paasta_tools.kubernetes_tools import list_custom_resources
|
|
43
|
+
from paasta_tools.kubernetes_tools import load_custom_resource_definitions
|
|
44
|
+
from paasta_tools.kubernetes_tools import paasta_prefixed
|
|
45
|
+
from paasta_tools.kubernetes_tools import sanitise_kubernetes_name
|
|
46
|
+
from paasta_tools.kubernetes_tools import update_custom_resource
|
|
47
|
+
from paasta_tools.utils import DEFAULT_SOA_DIR
|
|
48
|
+
from paasta_tools.utils import get_config_hash
|
|
49
|
+
from paasta_tools.utils import get_git_sha_from_dockerurl
|
|
50
|
+
from paasta_tools.utils import load_all_configs
|
|
51
|
+
from paasta_tools.utils import load_system_paasta_config
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
log = logging.getLogger(__name__)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class StdoutKubeClient:
|
|
58
|
+
"""Replace all destructive operations in Kubernetes APIs with
|
|
59
|
+
writing out YAML to stdout."""
|
|
60
|
+
|
|
61
|
+
class StdoutWrapper:
|
|
62
|
+
def __init__(self, target) -> None:
|
|
63
|
+
self.target = target
|
|
64
|
+
|
|
65
|
+
def __getattr__(self, attr):
|
|
66
|
+
if attr.startswith("create") or attr.startswith("replace"):
|
|
67
|
+
return self.yaml_dump
|
|
68
|
+
return getattr(self.target, attr)
|
|
69
|
+
|
|
70
|
+
def yaml_dump(self, **kwargs):
|
|
71
|
+
body = kwargs.get("body")
|
|
72
|
+
if not body:
|
|
73
|
+
return
|
|
74
|
+
ns = kwargs.get("namespace")
|
|
75
|
+
if ns:
|
|
76
|
+
if "metadata" not in body:
|
|
77
|
+
body["metadata"] = {}
|
|
78
|
+
body["metadata"]["namespace"] = ns
|
|
79
|
+
yaml.safe_dump(body, sys.stdout, indent=4, explicit_start=True)
|
|
80
|
+
|
|
81
|
+
def __init__(self, kube_client) -> None:
|
|
82
|
+
self.deployments = StdoutKubeClient.StdoutWrapper(kube_client.deployments)
|
|
83
|
+
self.core = StdoutKubeClient.StdoutWrapper(kube_client.core)
|
|
84
|
+
self.policy = StdoutKubeClient.StdoutWrapper(kube_client.policy)
|
|
85
|
+
self.apiextensions = StdoutKubeClient.StdoutWrapper(kube_client.apiextensions)
|
|
86
|
+
self.custom = StdoutKubeClient.StdoutWrapper(kube_client.custom)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def parse_args() -> argparse.Namespace:
|
|
90
|
+
parser = argparse.ArgumentParser(description="Creates custom_resources.")
|
|
91
|
+
parser.add_argument(
|
|
92
|
+
"-d",
|
|
93
|
+
"--soa-dir",
|
|
94
|
+
dest="soa_dir",
|
|
95
|
+
metavar="SOA_DIR",
|
|
96
|
+
default=DEFAULT_SOA_DIR,
|
|
97
|
+
help="define a different soa config directory",
|
|
98
|
+
)
|
|
99
|
+
parser.add_argument(
|
|
100
|
+
"-v", "--verbose", action="store_true", dest="verbose", default=False
|
|
101
|
+
)
|
|
102
|
+
parser.add_argument(
|
|
103
|
+
"-s", "--service", default=None, help="Service to setup CRs for"
|
|
104
|
+
)
|
|
105
|
+
parser.add_argument(
|
|
106
|
+
"-i", "--instance", default=None, help="Service instance to setup CR for"
|
|
107
|
+
)
|
|
108
|
+
parser.add_argument(
|
|
109
|
+
"-D",
|
|
110
|
+
"--dry-run",
|
|
111
|
+
action="store_true",
|
|
112
|
+
default=False,
|
|
113
|
+
help="Output kubernetes configuration instead of applying it",
|
|
114
|
+
)
|
|
115
|
+
parser.add_argument(
|
|
116
|
+
"-c", "--cluster", default=None, help="Cluster to setup CRs for"
|
|
117
|
+
)
|
|
118
|
+
args = parser.parse_args()
|
|
119
|
+
return args
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def main() -> None:
|
|
123
|
+
args = parse_args()
|
|
124
|
+
soa_dir = args.soa_dir
|
|
125
|
+
if args.verbose:
|
|
126
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
127
|
+
else:
|
|
128
|
+
logging.basicConfig(level=logging.INFO)
|
|
129
|
+
|
|
130
|
+
kube_client: Any = KubeClient()
|
|
131
|
+
if args.dry_run:
|
|
132
|
+
kube_client = StdoutKubeClient(kube_client)
|
|
133
|
+
|
|
134
|
+
system_paasta_config = load_system_paasta_config()
|
|
135
|
+
cluster = args.cluster or system_paasta_config.get_cluster()
|
|
136
|
+
custom_resource_definitions = load_custom_resource_definitions(system_paasta_config)
|
|
137
|
+
setup_kube_succeeded = setup_all_custom_resources(
|
|
138
|
+
kube_client=kube_client,
|
|
139
|
+
soa_dir=soa_dir,
|
|
140
|
+
cluster=cluster,
|
|
141
|
+
custom_resource_definitions=custom_resource_definitions,
|
|
142
|
+
service=args.service,
|
|
143
|
+
instance=args.instance,
|
|
144
|
+
)
|
|
145
|
+
sys.exit(0 if setup_kube_succeeded else 1)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def setup_all_custom_resources(
|
|
149
|
+
kube_client: KubeClient,
|
|
150
|
+
soa_dir: str,
|
|
151
|
+
cluster: str,
|
|
152
|
+
custom_resource_definitions: Sequence[CustomResourceDefinition],
|
|
153
|
+
service: str = None,
|
|
154
|
+
instance: str = None,
|
|
155
|
+
) -> bool:
|
|
156
|
+
|
|
157
|
+
got_results = False
|
|
158
|
+
succeeded = False
|
|
159
|
+
# We support two versions due to our upgrade to 1.22
|
|
160
|
+
# this functions runs succefully when any of the two apiextensions
|
|
161
|
+
# succeed to update the CRDs as the cluster could be in any version
|
|
162
|
+
# we need to try both possibilities
|
|
163
|
+
for apiextension in [
|
|
164
|
+
kube_client.apiextensions,
|
|
165
|
+
]:
|
|
166
|
+
|
|
167
|
+
try:
|
|
168
|
+
crds_list = apiextension.list_custom_resource_definition(
|
|
169
|
+
label_selector=paasta_prefixed("service")
|
|
170
|
+
).items
|
|
171
|
+
except ApiException:
|
|
172
|
+
log.debug(
|
|
173
|
+
"Listing CRDs with apiextensions/v1 not supported on this cluster"
|
|
174
|
+
)
|
|
175
|
+
crds_list = []
|
|
176
|
+
|
|
177
|
+
cluster_crds = {crd.spec.names.kind for crd in crds_list}
|
|
178
|
+
log.debug(f"CRDs found: {cluster_crds}")
|
|
179
|
+
results = []
|
|
180
|
+
for crd in custom_resource_definitions:
|
|
181
|
+
if crd.kube_kind.singular not in cluster_crds:
|
|
182
|
+
# TODO: kube_kind.singular seems to correspond to `crd.names.kind`
|
|
183
|
+
# and not `crd.names.singular`
|
|
184
|
+
log.warning(f"CRD {crd.kube_kind.singular} " f"not found in {cluster}")
|
|
185
|
+
continue
|
|
186
|
+
|
|
187
|
+
# by convention, entries where key begins with _ are used as templates
|
|
188
|
+
# and will be filter out here
|
|
189
|
+
config_dicts = load_all_configs(
|
|
190
|
+
cluster=cluster, file_prefix=crd.file_prefix, soa_dir=soa_dir
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
ensure_namespace(
|
|
194
|
+
kube_client=kube_client, namespace=f"paasta-{crd.kube_kind.plural}"
|
|
195
|
+
)
|
|
196
|
+
results.append(
|
|
197
|
+
setup_custom_resources(
|
|
198
|
+
kube_client=kube_client,
|
|
199
|
+
kind=crd.kube_kind,
|
|
200
|
+
crd=crd,
|
|
201
|
+
config_dicts=config_dicts,
|
|
202
|
+
version=crd.version,
|
|
203
|
+
group=crd.group,
|
|
204
|
+
cluster=cluster,
|
|
205
|
+
service=service,
|
|
206
|
+
instance=instance,
|
|
207
|
+
)
|
|
208
|
+
)
|
|
209
|
+
if results:
|
|
210
|
+
got_results = True
|
|
211
|
+
if any(results):
|
|
212
|
+
succeeded = True
|
|
213
|
+
# we want to return True if we never called `setup_custom_resources`
|
|
214
|
+
# (i.e., we noop'd) or if any call to `setup_custom_resources`
|
|
215
|
+
# succeed (handled above) - otherwise, we want to return False
|
|
216
|
+
return succeeded or not got_results
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def setup_custom_resources(
|
|
220
|
+
kube_client: KubeClient,
|
|
221
|
+
kind: KubeKind,
|
|
222
|
+
version: str,
|
|
223
|
+
crd: CustomResourceDefinition,
|
|
224
|
+
config_dicts: Mapping[str, Mapping[str, Any]],
|
|
225
|
+
group: str,
|
|
226
|
+
cluster: str,
|
|
227
|
+
service: str = None,
|
|
228
|
+
instance: str = None,
|
|
229
|
+
) -> bool:
|
|
230
|
+
succeded = True
|
|
231
|
+
if config_dicts:
|
|
232
|
+
crs = list_custom_resources(
|
|
233
|
+
kube_client=kube_client, kind=kind, version=version, group=group
|
|
234
|
+
)
|
|
235
|
+
for svc, config in config_dicts.items():
|
|
236
|
+
if service is not None and service != svc:
|
|
237
|
+
continue
|
|
238
|
+
if not reconcile_kubernetes_resource(
|
|
239
|
+
kube_client=kube_client,
|
|
240
|
+
service=svc,
|
|
241
|
+
instance=instance,
|
|
242
|
+
instance_configs=config,
|
|
243
|
+
kind=kind,
|
|
244
|
+
custom_resources=crs,
|
|
245
|
+
version=version,
|
|
246
|
+
group=group,
|
|
247
|
+
cluster=cluster,
|
|
248
|
+
crd=crd,
|
|
249
|
+
):
|
|
250
|
+
succeded = False
|
|
251
|
+
return succeded
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def get_dashboard_base_url(kind: str, cluster: str, is_eks: bool) -> Optional[str]:
|
|
255
|
+
system_paasta_config = load_system_paasta_config()
|
|
256
|
+
dashboard_links = system_paasta_config.get_dashboard_links()
|
|
257
|
+
if kind.lower() == "flink":
|
|
258
|
+
flink_link = dashboard_links.get(cluster, {}).get("Flink")
|
|
259
|
+
if flink_link is None:
|
|
260
|
+
flink_link = get_flink_ingress_url_root(cluster, is_eks)
|
|
261
|
+
if flink_link[-1:] != "/":
|
|
262
|
+
flink_link += "/"
|
|
263
|
+
return flink_link
|
|
264
|
+
return None
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def get_cr_owner(kind: str) -> Optional[str]:
|
|
268
|
+
system_paasta_config = load_system_paasta_config()
|
|
269
|
+
owners = system_paasta_config.get_cr_owners()
|
|
270
|
+
return owners.get(kind.lower())
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def format_custom_resource(
|
|
274
|
+
instance_config: Mapping[str, Any],
|
|
275
|
+
service: str,
|
|
276
|
+
instance: str,
|
|
277
|
+
cluster: str,
|
|
278
|
+
kind: str,
|
|
279
|
+
version: str,
|
|
280
|
+
group: str,
|
|
281
|
+
namespace: str,
|
|
282
|
+
git_sha: str,
|
|
283
|
+
is_eks: bool,
|
|
284
|
+
) -> Mapping[str, Any]:
|
|
285
|
+
sanitised_service = sanitise_kubernetes_name(service)
|
|
286
|
+
sanitised_instance = sanitise_kubernetes_name(instance)
|
|
287
|
+
resource: Mapping[str, Any] = {
|
|
288
|
+
"apiVersion": f"{group}/{version}",
|
|
289
|
+
"kind": kind,
|
|
290
|
+
"metadata": {
|
|
291
|
+
"name": f"{sanitised_service}-{sanitised_instance}",
|
|
292
|
+
"namespace": namespace,
|
|
293
|
+
"labels": {
|
|
294
|
+
"yelp.com/paasta_service": service,
|
|
295
|
+
"yelp.com/paasta_instance": instance,
|
|
296
|
+
"yelp.com/paasta_cluster": cluster,
|
|
297
|
+
paasta_prefixed("service"): service,
|
|
298
|
+
paasta_prefixed("instance"): instance,
|
|
299
|
+
paasta_prefixed("cluster"): cluster,
|
|
300
|
+
},
|
|
301
|
+
"annotations": {},
|
|
302
|
+
},
|
|
303
|
+
"spec": instance_config,
|
|
304
|
+
}
|
|
305
|
+
if is_eks:
|
|
306
|
+
resource["metadata"]["labels"][paasta_prefixed("eks")] = str(is_eks)
|
|
307
|
+
|
|
308
|
+
url = get_dashboard_base_url(kind, cluster, is_eks)
|
|
309
|
+
if url:
|
|
310
|
+
resource["metadata"]["annotations"][paasta_prefixed("dashboard_base_url")] = url
|
|
311
|
+
owner = get_cr_owner(kind)
|
|
312
|
+
if owner:
|
|
313
|
+
resource["metadata"]["labels"]["yelp.com/owner"] = owner
|
|
314
|
+
config_hash = get_config_hash(resource)
|
|
315
|
+
|
|
316
|
+
resource["metadata"]["annotations"]["yelp.com/desired_state"] = "running"
|
|
317
|
+
resource["metadata"]["annotations"][paasta_prefixed("desired_state")] = "running"
|
|
318
|
+
resource["metadata"]["labels"]["yelp.com/paasta_config_sha"] = config_hash
|
|
319
|
+
resource["metadata"]["labels"][paasta_prefixed("config_sha")] = config_hash
|
|
320
|
+
resource["metadata"]["labels"][paasta_prefixed("git_sha")] = git_sha
|
|
321
|
+
return resource
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def reconcile_kubernetes_resource(
|
|
325
|
+
kube_client: KubeClient,
|
|
326
|
+
service: str,
|
|
327
|
+
instance_configs: Mapping[str, Any],
|
|
328
|
+
custom_resources: Sequence[KubeCustomResource],
|
|
329
|
+
kind: KubeKind,
|
|
330
|
+
version: str,
|
|
331
|
+
group: str,
|
|
332
|
+
crd: CustomResourceDefinition,
|
|
333
|
+
cluster: str,
|
|
334
|
+
instance: str = None,
|
|
335
|
+
) -> bool:
|
|
336
|
+
succeeded = True
|
|
337
|
+
config_handler = LONG_RUNNING_INSTANCE_TYPE_HANDLERS[crd.file_prefix]
|
|
338
|
+
|
|
339
|
+
is_eks = False
|
|
340
|
+
if crd.file_prefix.endswith("eks"):
|
|
341
|
+
is_eks = True
|
|
342
|
+
|
|
343
|
+
for inst, config in instance_configs.items():
|
|
344
|
+
if instance is not None and instance != inst:
|
|
345
|
+
continue
|
|
346
|
+
try:
|
|
347
|
+
soa_config = config_handler.loader(
|
|
348
|
+
service=service,
|
|
349
|
+
instance=inst,
|
|
350
|
+
cluster=cluster,
|
|
351
|
+
load_deployments=True,
|
|
352
|
+
soa_dir=DEFAULT_SOA_DIR,
|
|
353
|
+
)
|
|
354
|
+
git_sha = get_git_sha_from_dockerurl(soa_config.get_docker_url(), long=True)
|
|
355
|
+
formatted_resource = format_custom_resource(
|
|
356
|
+
instance_config=config,
|
|
357
|
+
service=service,
|
|
358
|
+
instance=inst,
|
|
359
|
+
cluster=cluster,
|
|
360
|
+
kind=kind.singular,
|
|
361
|
+
version=version,
|
|
362
|
+
group=group,
|
|
363
|
+
namespace=f"paasta-{kind.plural}",
|
|
364
|
+
git_sha=git_sha,
|
|
365
|
+
is_eks=is_eks,
|
|
366
|
+
)
|
|
367
|
+
desired_resource = KubeCustomResource(
|
|
368
|
+
service=service,
|
|
369
|
+
instance=inst,
|
|
370
|
+
config_sha=formatted_resource["metadata"]["labels"][
|
|
371
|
+
paasta_prefixed("config_sha")
|
|
372
|
+
],
|
|
373
|
+
git_sha=formatted_resource["metadata"]["labels"].get(
|
|
374
|
+
paasta_prefixed("git_sha")
|
|
375
|
+
),
|
|
376
|
+
kind=kind.singular,
|
|
377
|
+
name=formatted_resource["metadata"]["name"],
|
|
378
|
+
namespace=f"paasta-{kind.plural}",
|
|
379
|
+
)
|
|
380
|
+
if not (service, inst, kind.singular) in [
|
|
381
|
+
(c.service, c.instance, c.kind) for c in custom_resources
|
|
382
|
+
]:
|
|
383
|
+
log.info(f"{desired_resource} does not exist so creating")
|
|
384
|
+
create_custom_resource(
|
|
385
|
+
kube_client=kube_client,
|
|
386
|
+
version=version,
|
|
387
|
+
kind=kind,
|
|
388
|
+
formatted_resource=formatted_resource,
|
|
389
|
+
group=group,
|
|
390
|
+
)
|
|
391
|
+
elif desired_resource not in custom_resources:
|
|
392
|
+
sanitised_service = sanitise_kubernetes_name(service)
|
|
393
|
+
sanitised_instance = sanitise_kubernetes_name(inst)
|
|
394
|
+
log.info(f"{desired_resource} exists but config_sha doesn't match")
|
|
395
|
+
update_custom_resource(
|
|
396
|
+
kube_client=kube_client,
|
|
397
|
+
name=f"{sanitised_service}-{sanitised_instance}",
|
|
398
|
+
version=version,
|
|
399
|
+
kind=kind,
|
|
400
|
+
formatted_resource=formatted_resource,
|
|
401
|
+
group=group,
|
|
402
|
+
)
|
|
403
|
+
else:
|
|
404
|
+
log.info(f"{desired_resource} is up to date, no action taken")
|
|
405
|
+
except Exception as e:
|
|
406
|
+
log.error(str(e))
|
|
407
|
+
succeeded = False
|
|
408
|
+
return succeeded
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
if __name__ == "__main__":
|
|
412
|
+
main()
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
# Copyright 2015-2019 Yelp Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
Usage: ./setup_kubernetes_crd.py <service.crd> [options]
|
|
17
|
+
|
|
18
|
+
Command line options:
|
|
19
|
+
|
|
20
|
+
- -d <SOA_DIR>, --soa-dir <SOA_DIR>: Specify a SOA config dir to read from
|
|
21
|
+
- -c <cluster>, --cluster <cluster>: Specify a kubernetes cluster name
|
|
22
|
+
- -v, --verbose: Verbose output
|
|
23
|
+
"""
|
|
24
|
+
import argparse
|
|
25
|
+
import logging
|
|
26
|
+
import sys
|
|
27
|
+
from typing import Sequence
|
|
28
|
+
|
|
29
|
+
import service_configuration_lib
|
|
30
|
+
from kubernetes.client import V1CustomResourceDefinition
|
|
31
|
+
|
|
32
|
+
from paasta_tools.kubernetes_tools import KubeClient
|
|
33
|
+
from paasta_tools.kubernetes_tools import paasta_prefixed
|
|
34
|
+
from paasta_tools.kubernetes_tools import update_crds
|
|
35
|
+
from paasta_tools.utils import DEFAULT_SOA_DIR
|
|
36
|
+
from paasta_tools.utils import load_system_paasta_config
|
|
37
|
+
|
|
38
|
+
log = logging.getLogger(__name__)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def parse_args() -> argparse.Namespace:
|
|
42
|
+
parser = argparse.ArgumentParser(description="Creates/updates kubernetes CRDs.")
|
|
43
|
+
parser.add_argument(
|
|
44
|
+
"service_list",
|
|
45
|
+
nargs="+",
|
|
46
|
+
help="The list of services to create or update CRDs for",
|
|
47
|
+
metavar="SERVICE",
|
|
48
|
+
)
|
|
49
|
+
parser.add_argument(
|
|
50
|
+
"-c",
|
|
51
|
+
"--cluster",
|
|
52
|
+
dest="cluster",
|
|
53
|
+
metavar="CLUSTER",
|
|
54
|
+
default=None,
|
|
55
|
+
help="Kubernetes cluster name",
|
|
56
|
+
)
|
|
57
|
+
parser.add_argument(
|
|
58
|
+
"-d",
|
|
59
|
+
"--soa-dir",
|
|
60
|
+
dest="soa_dir",
|
|
61
|
+
metavar="SOA_DIR",
|
|
62
|
+
default=DEFAULT_SOA_DIR,
|
|
63
|
+
help="define a different soa config directory",
|
|
64
|
+
)
|
|
65
|
+
parser.add_argument(
|
|
66
|
+
"-v", "--verbose", action="store_true", dest="verbose", default=False
|
|
67
|
+
)
|
|
68
|
+
args = parser.parse_args()
|
|
69
|
+
return args
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def main() -> None:
|
|
73
|
+
args = parse_args()
|
|
74
|
+
soa_dir = args.soa_dir
|
|
75
|
+
if args.verbose:
|
|
76
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
77
|
+
else:
|
|
78
|
+
logging.basicConfig(level=logging.WARNING)
|
|
79
|
+
|
|
80
|
+
if args.cluster:
|
|
81
|
+
cluster = args.cluster
|
|
82
|
+
else:
|
|
83
|
+
system_paasta_config = load_system_paasta_config()
|
|
84
|
+
cluster = system_paasta_config.get_cluster()
|
|
85
|
+
|
|
86
|
+
kube_client = KubeClient()
|
|
87
|
+
|
|
88
|
+
success = setup_kube_crd(
|
|
89
|
+
kube_client=kube_client,
|
|
90
|
+
cluster=cluster,
|
|
91
|
+
services=args.service_list,
|
|
92
|
+
soa_dir=soa_dir,
|
|
93
|
+
)
|
|
94
|
+
sys.exit(0 if success else 1)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def setup_kube_crd(
|
|
98
|
+
kube_client: KubeClient,
|
|
99
|
+
cluster: str,
|
|
100
|
+
services: Sequence[str],
|
|
101
|
+
soa_dir: str = DEFAULT_SOA_DIR,
|
|
102
|
+
) -> bool:
|
|
103
|
+
existing_crds = kube_client.apiextensions.list_custom_resource_definition(
|
|
104
|
+
label_selector=paasta_prefixed("service")
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
desired_crds = []
|
|
108
|
+
for service in services:
|
|
109
|
+
crd_config = service_configuration_lib.read_extra_service_information(
|
|
110
|
+
service, f"crd-{cluster}", soa_dir=soa_dir
|
|
111
|
+
)
|
|
112
|
+
if not crd_config:
|
|
113
|
+
log.info("nothing to deploy")
|
|
114
|
+
continue
|
|
115
|
+
|
|
116
|
+
metadata = crd_config.get("metadata", {})
|
|
117
|
+
if "labels" not in metadata:
|
|
118
|
+
metadata["labels"] = {}
|
|
119
|
+
metadata["labels"]["yelp.com/paasta_service"] = service
|
|
120
|
+
metadata["labels"][paasta_prefixed("service")] = service
|
|
121
|
+
|
|
122
|
+
desired_crd = V1CustomResourceDefinition(
|
|
123
|
+
api_version=crd_config.get("apiVersion"),
|
|
124
|
+
kind=crd_config.get("kind"),
|
|
125
|
+
metadata=metadata,
|
|
126
|
+
spec=crd_config.get("spec"),
|
|
127
|
+
)
|
|
128
|
+
desired_crds.append(desired_crd)
|
|
129
|
+
|
|
130
|
+
return update_crds(
|
|
131
|
+
kube_client=kube_client,
|
|
132
|
+
desired_crds=desired_crds,
|
|
133
|
+
existing_crds=existing_crds,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
if __name__ == "__main__":
|
|
138
|
+
main()
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
# Copyright 2015-2019 Yelp Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
Usage: ./setup_kubernetes_internal_crd.py [options]
|
|
17
|
+
|
|
18
|
+
Command line options:
|
|
19
|
+
|
|
20
|
+
- -v, --verbose: Verbose output
|
|
21
|
+
"""
|
|
22
|
+
import argparse
|
|
23
|
+
import logging
|
|
24
|
+
import sys
|
|
25
|
+
|
|
26
|
+
from kubernetes.client import V1CustomResourceDefinition
|
|
27
|
+
|
|
28
|
+
from paasta_tools.kubernetes_tools import KubeClient
|
|
29
|
+
from paasta_tools.kubernetes_tools import paasta_prefixed
|
|
30
|
+
from paasta_tools.kubernetes_tools import update_crds
|
|
31
|
+
|
|
32
|
+
log = logging.getLogger(__name__)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
INTERNAL_CRDS = [
|
|
36
|
+
V1CustomResourceDefinition(
|
|
37
|
+
api_version="apiextensions.k8s.io/v1",
|
|
38
|
+
kind="CustomResourceDefinition",
|
|
39
|
+
metadata={
|
|
40
|
+
"name": "deploygroups.paasta.yelp.com",
|
|
41
|
+
"labels": {
|
|
42
|
+
paasta_prefixed("internal"): "true",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
spec={
|
|
46
|
+
"group": "paasta.yelp.com",
|
|
47
|
+
"versions": [
|
|
48
|
+
{
|
|
49
|
+
"name": "v1beta1",
|
|
50
|
+
"served": True,
|
|
51
|
+
"storage": True,
|
|
52
|
+
"schema": {
|
|
53
|
+
"openAPIV3Schema": {
|
|
54
|
+
"type": "object",
|
|
55
|
+
"properties": {
|
|
56
|
+
"service": {"type": "string"},
|
|
57
|
+
"deploy_group": {"type": "string"},
|
|
58
|
+
"git_sha": {"type": "string"},
|
|
59
|
+
"image_version": {"type": "string"},
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"scope": "Namespaced",
|
|
66
|
+
"names": {
|
|
67
|
+
"plural": "deploygroups",
|
|
68
|
+
"singular": "deploygroup",
|
|
69
|
+
"kind": "DeployGroup",
|
|
70
|
+
"shortNames": ["dg"],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
),
|
|
74
|
+
V1CustomResourceDefinition(
|
|
75
|
+
api_version="apiextensions.k8s.io/v1",
|
|
76
|
+
kind="CustomResourceDefinition",
|
|
77
|
+
metadata={
|
|
78
|
+
"name": "startstopcontrols.paasta.yelp.com",
|
|
79
|
+
"labels": {
|
|
80
|
+
paasta_prefixed("internal"): "true",
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
spec={
|
|
84
|
+
"group": "paasta.yelp.com",
|
|
85
|
+
"versions": [
|
|
86
|
+
{
|
|
87
|
+
"name": "v1beta1",
|
|
88
|
+
"served": True,
|
|
89
|
+
"storage": True,
|
|
90
|
+
"schema": {
|
|
91
|
+
"openAPIV3Schema": {
|
|
92
|
+
"type": "object",
|
|
93
|
+
"properties": {
|
|
94
|
+
"service": {"type": "string"},
|
|
95
|
+
"instance": {"type": "string"},
|
|
96
|
+
"desired_state": {"type": "string"},
|
|
97
|
+
"force_bounce": {"type": "string"},
|
|
98
|
+
},
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
"scope": "Namespaced",
|
|
104
|
+
"names": {
|
|
105
|
+
"plural": "startstopcontrols",
|
|
106
|
+
"singular": "startstopcontrol",
|
|
107
|
+
"kind": "StartStopControl",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
),
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def parse_args() -> argparse.Namespace:
|
|
115
|
+
parser = argparse.ArgumentParser(
|
|
116
|
+
description="Creates/updates Paasta-internal kubernetes CRDs."
|
|
117
|
+
)
|
|
118
|
+
parser.add_argument(
|
|
119
|
+
"-v", "--verbose", action="store_true", dest="verbose", default=False
|
|
120
|
+
)
|
|
121
|
+
args = parser.parse_args()
|
|
122
|
+
return args
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def main() -> None:
|
|
126
|
+
args = parse_args()
|
|
127
|
+
if args.verbose:
|
|
128
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
129
|
+
else:
|
|
130
|
+
logging.basicConfig(level=logging.WARNING)
|
|
131
|
+
|
|
132
|
+
kube_client = KubeClient()
|
|
133
|
+
|
|
134
|
+
success = setup_kube_internal_crd(
|
|
135
|
+
kube_client=kube_client,
|
|
136
|
+
)
|
|
137
|
+
sys.exit(0 if success else 1)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def setup_kube_internal_crd(
|
|
141
|
+
kube_client: KubeClient,
|
|
142
|
+
) -> bool:
|
|
143
|
+
existing_crds = kube_client.apiextensions.list_custom_resource_definition(
|
|
144
|
+
label_selector=paasta_prefixed("internal")
|
|
145
|
+
)
|
|
146
|
+
return update_crds(
|
|
147
|
+
kube_client=kube_client,
|
|
148
|
+
desired_crds=INTERNAL_CRDS,
|
|
149
|
+
existing_crds=existing_crds,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
if __name__ == "__main__":
|
|
154
|
+
main()
|