From 26e53501e40fe4e1e647c69378c824366b7ca6c2 Mon Sep 17 00:00:00 2001 From: "user.email" Date: Tue, 27 Aug 2024 16:51:17 +0200 Subject: [PATCH] Update more python templates to use dictionary literals With type checking for dictionary literals, we now prefer this style over args classes https://github.com/pulumi/pulumi/issues/12689 --- helm-kubernetes-python/__main__.py | 6 +-- kubernetes-azure-python/__main__.py | 82 ++++++++++++++--------------- kubernetes-gcp-python/__main__.py | 66 +++++++++++------------ kubernetes-python/__main__.py | 20 ++++--- 4 files changed, 86 insertions(+), 88 deletions(-) diff --git a/helm-kubernetes-python/__main__.py b/helm-kubernetes-python/__main__.py index 9be4b6359..e9b86baf4 100644 --- a/helm-kubernetes-python/__main__.py +++ b/helm-kubernetes-python/__main__.py @@ -21,9 +21,9 @@ "ingresscontroller", chart="nginx-ingress", namespace=ingress_ns.metadata.name, - repository_opts=kubernetes.helm.v3.RepositoryOptsArgs( - repo="https://helm.nginx.com/stable", - ), + repository_opts={ + "repo": "https://helm.nginx.com/stable", + }, skip_crds=True, values={ "controller": { diff --git a/kubernetes-azure-python/__main__.py b/kubernetes-azure-python/__main__.py index e1eb4e9d4..7f49c7488 100644 --- a/kubernetes-azure-python/__main__.py +++ b/kubernetes-azure-python/__main__.py @@ -24,9 +24,9 @@ # Create an Azure Virtual Network virtual_network = network.VirtualNetwork( "virtual_network", - address_space=network.AddressSpaceArgs( - address_prefixes=["10.0.0.0/16"], - ), + address_space={ + "address_prefixes": ["10.0.0.0/16"], + }, resource_group_name=resource_group.name ) @@ -53,51 +53,51 @@ # Create an Azure Kubernetes Service cluster managed_cluster = containerservice.ManagedCluster( "managed_cluster", - aad_profile=containerservice.ManagedClusterAADProfileArgs( - enable_azure_rbac=True, - managed=True, - admin_group_object_ids=[mgmt_group_id], - ), + aad_profile={ + "enable_azure_rbac": True, + "managed": True, + "admin_group_object_ids": [mgmt_group_id], + }, # Use multiple agent/node pools to distribute nodes across subnets - agent_pool_profiles=[containerservice.ManagedClusterAgentPoolProfileArgs( - availability_zones=["1","2","3",], - count=3, - enable_node_public_ip=False, - mode="System", - name="systempool", - os_type="Linux", - os_disk_size_gb=30, - type="VirtualMachineScaleSets", - vm_size=node_vm_size, + agent_pool_profiles=[{ + "availability_zones": ["1","2","3",], + "count": 3, + "enable_node_public_ip": False, + "mode": "System", + "name": "systempool", + "os_type": "Linux", + "os_disk_size_gb": 30, + "type": "VirtualMachineScaleSets", + "vm_size": node_vm_size, # Change next line for additional node pools to distribute across subnets - vnet_subnet_id=subnet1.id - )], + "vnet_subnet_id": subnet1.id + }], # Change authorized_ip_ranges to limit access to API server # Changing enable_private_cluster requires alternate access to API server (VPN or similar) - api_server_access_profile=containerservice.ManagedClusterAPIServerAccessProfileArgs( - authorized_ip_ranges=["0.0.0.0/0"], - enable_private_cluster=False - ), + api_server_access_profile={ + "authorized_ip_ranges": ["0.0.0.0/0"], + "enable_private_cluster": False + }, dns_prefix=prefix_for_dns, enable_rbac=True, - identity=containerservice.ManagedClusterIdentityArgs( - type=containerservice.ResourceIdentityType.SYSTEM_ASSIGNED, - ), + identity={ + "type": containerservice.ResourceIdentityType.SYSTEM_ASSIGNED, + }, kubernetes_version=k8s_version, - linux_profile=containerservice.ContainerServiceLinuxProfileArgs( - admin_username="azureuser", - ssh=containerservice.ContainerServiceSshConfigurationArgs( - public_keys=[containerservice.ContainerServiceSshPublicKeyArgs( - key_data=ssh_pub_key, - )], - ), - ), - network_profile=containerservice.ContainerServiceNetworkProfileArgs( - network_plugin="azure", - network_policy="azure", - service_cidr="10.96.0.0/16", - dns_service_ip="10.96.0.10", - ), + linux_profile={ + "admin_username": "azureuser", + "ssh": { + "public_keys": [{ + "key_data": ssh_pub_key, + }], + }, + }, + network_profile={ + "network_plugin": "azure", + "network_policy": "azure", + "service_cidr": "10.96.0.0/16", + "dns_service_ip": "10.96.0.10", + }, resource_group_name=resource_group.name ) diff --git a/kubernetes-gcp-python/__main__.py b/kubernetes-gcp-python/__main__.py index 6f1762d09..b8c37992b 100644 --- a/kubernetes-gcp-python/__main__.py +++ b/kubernetes-gcp-python/__main__.py @@ -27,43 +27,43 @@ # Create a cluster in the new network and subnet gke_cluster = gcp.container.Cluster( "gke-cluster", - addons_config=gcp.container.ClusterAddonsConfigArgs( - dns_cache_config=gcp.container.ClusterAddonsConfigDnsCacheConfigArgs( - enabled=True - ), - ), - binary_authorization=gcp.container.ClusterBinaryAuthorizationArgs( - evaluation_mode="PROJECT_SINGLETON_POLICY_ENFORCE" - ), + addons_config={ + "dns_cache_config": { + "enabled": True + }, + }, + binary_authorization={ + "evaluation_mode": "PROJECT_SINGLETON_POLICY_ENFORCE" + }, datapath_provider="ADVANCED_DATAPATH", description="A GKE cluster", initial_node_count=1, - ip_allocation_policy=gcp.container.ClusterIpAllocationPolicyArgs( - cluster_ipv4_cidr_block="/14", - services_ipv4_cidr_block="/20" - ), + ip_allocation_policy={ + "cluster_ipv4_cidr_block": "/14", + "services_ipv4_cidr_block": "/20" + }, location=gcp_region, - master_authorized_networks_config=gcp.container.ClusterMasterAuthorizedNetworksConfigArgs( - cidr_blocks=[gcp.container.ClusterMasterAuthorizedNetworksConfigCidrBlockArgs( - cidr_block="0.0.0.0/0", - display_name="All networks" - )] - ), + master_authorized_networks_config={ + "cidr_blocks": [{ + "cidr_block": "0.0.0.0/0", + "display_name": "All networks" + }] + }, network=gke_network.name, networking_mode="VPC_NATIVE", - private_cluster_config=gcp.container.ClusterPrivateClusterConfigArgs( - enable_private_nodes=True, - enable_private_endpoint=False, - master_ipv4_cidr_block="10.100.0.0/28" - ), + private_cluster_config={ + "enable_private_nodes": True, + "enable_private_endpoint": False, + "master_ipv4_cidr_block": "10.100.0.0/28" + }, remove_default_node_pool=True, - release_channel=gcp.container.ClusterReleaseChannelArgs( - channel="STABLE" - ), + release_channel={ + "channel": "STABLE" + }, subnetwork=gke_subnet.name, - workload_identity_config=gcp.container.ClusterWorkloadIdentityConfigArgs( - workload_pool=f"{gcp_project}.svc.id.goog" - ) + workload_identity_config={ + "workload_pool": f"{gcp_project}.svc.id.goog" + } ) # Create a GCP service account for the nodepool @@ -78,10 +78,10 @@ "gke-nodepool", cluster=gke_cluster.id, node_count=nodes_per_zone, - node_config=gcp.container.NodePoolNodeConfigArgs( - oauth_scopes=["https://www.googleapis.com/auth/cloud-platform"], - service_account=gke_nodepool_sa.email - ) + node_config={ + "oauth_scopes": ["https://www.googleapis.com/auth/cloud-platform"], + "service_account": gke_nodepool_sa.email + } ) # Build a Kubeconfig to access the cluster diff --git a/kubernetes-python/__main__.py b/kubernetes-python/__main__.py index 17aff3a52..abcde57cb 100644 --- a/kubernetes-python/__main__.py +++ b/kubernetes-python/__main__.py @@ -1,21 +1,19 @@ """A Kubernetes Python Pulumi program""" import pulumi -from pulumi_kubernetes.apps.v1 import Deployment, DeploymentSpecArgs -from pulumi_kubernetes.meta.v1 import LabelSelectorArgs, ObjectMetaArgs -from pulumi_kubernetes.core.v1 import ContainerArgs, PodSpecArgs, PodTemplateSpecArgs +from pulumi_kubernetes.apps.v1 import Deployment app_labels = { "app": "nginx" } deployment = Deployment( "nginx", - spec=DeploymentSpecArgs( - selector=LabelSelectorArgs(match_labels=app_labels), - replicas=1, - template=PodTemplateSpecArgs( - metadata=ObjectMetaArgs(labels=app_labels), - spec=PodSpecArgs(containers=[ContainerArgs(name="nginx", image="nginx")]) - ), - )) + spec={ + "selector": { "match_labels": app_labels }, + "replicas": 1, + "template": { + "metadata": { "labels": app_labels }, + "spec": { "containers": [{ "name": "nginx", "image": "nginx" }] } + }, + }) pulumi.export("name", deployment.metadata["name"])