Skip to content

Commit

Permalink
Merge pull request #827 from pulumi/julienp/typeddicts
Browse files Browse the repository at this point in the history
Update more python templates to use dictionary literals
  • Loading branch information
julienp authored Aug 28, 2024
2 parents e5bd1c3 + 26e5350 commit 170e2b3
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 88 deletions.
6 changes: 3 additions & 3 deletions helm-kubernetes-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
82 changes: 41 additions & 41 deletions kubernetes-azure-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
)

Expand Down
66 changes: 33 additions & 33 deletions kubernetes-gcp-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 9 additions & 11 deletions kubernetes-python/__main__.py
Original file line number Diff line number Diff line change
@@ -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"])

0 comments on commit 170e2b3

Please sign in to comment.