Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
6.8 kB
2
Indexable
Never
service_config = {"cluster-sepy-02": {"addons": {"cni_addon": {"use_prefix_delegation": "true", "version": "v1.11.2-eksbuild.1"}, "coredns_addon": {"install": "true", "version": "v1.8.4-eksbuild.1"}, "kube-proxy_addon": {"install": "true", "version": "v1.21.2-eksbuild.2"}}, "admin_role_list": ["NC_Admins", "NC_EnvAdmins", "OrganizationAccountAccessRole"], "admin_user_list": [], "api": {"private": "true", "public": "false"}, "cert": {"acm_store": "false", "certificate": "configuration/altice-eks-sb-ssl-cert/certnew.cer", "key": "configuration/altice-eks-sb-ssl-cert/ssl.key", "name": "altice-eks-sb-ssl-cert"}, "helm": {"autoscaler": {"install": "true", "namespace": "autoscaler", "registry": "artifactorycn.netcracker.com:17115", "replicas": 2, "sa_name": "my-cluster-autoscaller-sa", "tag": "v1.22.2"}, "aws_lb": {"install": "true", "registry": "artifactorycn.netcracker.com:17064", "replicas": 2, "tag": "v2.4.1"}, "dashboard": {"install": "true", "registry": "artifactorycn.netcracker.com:17064", "tag": "v2.5.1"}, "ebs": {"install": "true", "registry": "artifactorycn.netcracker.com:17064", "replicas": 2, "sidecar_registry": "artifactorycn.netcracker.com:17125", "tag": "v1.6.2"}, "efs": {"install": "true", "registry": "artifactorycn.netcracker.com:17064", "replicas": 2, "sidecar_registry": "artifactorycn.netcracker.com:17125", "tag": "v1.3.8"}, "metrics": {"install": "true", "registry": "artifactorycn.netcracker.com:17115", "tag": "v0.6.1"}, "nginx": {"install": "true", "regitry": "artifactorycn.netcracker.com:17115", "replicas": 2, "tag": "v1.2.0", "webhook_tag": "v1.5.2"}, "term_handler": {"install": "true", "registry": "artifactorycn.netcracker.com:17064"}}, "irsa": {"enable": "false"}, "managed_node_group_defaults": {"max_pods": 110, "mng_desired_size": 3, "mng_max_size": 5, "mng_min_size": 1, "root_volume_size": 50, "root_volume_type": "gp3", "use_node_termination_handler": "true"}, "managed_node_groups": {"sepy-node-pool-01": {"additional_ebs_volumes": [{"block_device_name": "sdb", "delete_on_termination": "true", "volume_size": 60, "volume_type": "gp3"}, {"block_device_name": "sdc", "delete_on_termination": "true", "throughput": 125, "volume_size": 120, "volume_type": "gp3"}], "capacity_type": "ON_DEMAND", "instance_type": "t3.medium", "kubelet_extra_args": ["--kube-reserved cpu=200m,memory=512Mi,ephemeral-storage=1Gi", "--system-reserved cpu=200m,memory=512Mi,ephemeral-storage=1Gi", "--eviction-hard=memory.available\u003c500Mi,nodefs.available\u003c10%"], "labels": {"label1": "value1", "label2": "value_2"}, "mng_allowed_az": ["c", "b"], "mng_desired_size": 2, "mng_labels": {"Environment": "preprod", "Zone": "dev"}, "mng_max_size": 4, "mng_min_size": 1, "override_instance_types": ["t3.medium", "t3a.medium"], "platform": "linux", "pre_userdata": "# Allow user supplied pre userdata code\nmkfs -t xfs /dev/nvme1n1\nmkfs -t xfs /dev/nvme2n1\ncp -R /var/lib/kubelet /var/kubelettemp\nexport EBS1=$(lsblk | grep 60G | awk \u0027{print $1}\u0027)\nexport EBS2=$(lsblk | grep 120G | awk \u0027{print $1}\u0027)\nmount /dev/$EBS1 /var/lib/kubelet\nmount /dev/$EBS2 /var/lib/docker\ncp -R /var/kubelettemp/* /var/lib/kubelet\nexport UUID1=$(blkid | grep $EBS1 | awk \u0027{print $2}\u0027 | sed \u0027s/UUID=\"//;s/.$//\u0027)\nexport UUID1=$(blkid | grep $EBS2 | awk \u0027{print $2}\u0027 | sed \u0027s/UUID=\"//;s/.$//\u0027)\necho UUID=$UUID1 /var/lib/kubelet xfs defaults,nofail 1 2 \u003e\u003e /etc/fstab\necho UUID=$UUID2 /var/lib/docker xfs defaults,nofail 1 2 \u003e\u003e /etc/fstab \n", "root_encrypted": "false", "root_volume_size": 50, "root_volume_type": "gp3", "taint_install": "false", "timeout_create": "25m", "timeout_delete": "30m", "timeout_update": "1h", "update_config_max_unavailable_percentage": "25", "use_custom_launch_template": "true"},  "sepy-node-pool-02": {"capacity_type": "ON_DEMAND", "instance_type": "t3.medium", "kubelet_extra_args": ["--kube-reserved cpu=200m,memory=512Mi,ephemeral-storage=1Gi", "--system-reserved cpu=200m,memory=512Mi,ephemeral-storage=1Gi", "--eviction-hard=memory.available\u003c500Mi,nodefs.available\u003c10%"], "labels": {"label1": "value1", "label2": "value_2"}, "mng_allowed_az": ["c", "b"], "mng_desired_size": 2, "mng_labels": {"Environment": "preprod", "Zone": "dev"}, "mng_max_size": 4, "mng_min_size": 1, "override_instance_types": ["t3.medium", "t3a.medium"], "platform": "linux", "root_encrypted": "false", "root_volume_size": 50, "root_volume_type": "gp3", "taint_install": "false", "timeout_create": "25m", "timeout_delete": "30m", "timeout_update": "1h", "update_config_max_unavailable_percentage": "25", "use_custom_launch_template": "true"}},  "mgmt_cidrs": ["10.0.0.0/8"], "ssh_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZe1KOErmDpGJqdsmT9wf1fUzTW7zs/9+p6Oy3aIUGeD2xLCspal/Ne6Tkv9XbXzx03TanLzkyaQ6G3KvT6fUNj/CLa4ftFeGn/g5cR2UedaZyp9zgwtdixvullK9a15vRDe5+jlvqvdfM9HcmG8sq65xRnTiDTzU98Y+IdwhY7emd5crS7XZUENCnGA5UD8S9CN7d80aGZ8RlRwpC4TxBLhbkMhf5ux4YiJzI8mpnoYQs5lLbL2jn5lqJE9alu/k1WAETSe6zWhP3R9gjbVWBNnAccP0kj7EeYeDhCVAHEOBzD6YYGpXl9SUAiUPI9obvFQA2/+Qc71Kkpha++Chl for_instance", "subnets": {"search_tags": {"eks_subnet_tag_key": "subnet/eks_node", "eks_subnet_tag_value": "true", "pod_subnet_tag_key": "subnet/eks_pods", "pod_subnet_tag_value": "true"}}, "tags": {"business_owner_email": "my@no-reply", "env_type": "dev", "gp_code": "NC.TF", "project": "my_project"}, "version": 1.22, "vpc": "VPC-SVT-stand" }}


cluster_name_key = list(service_config.keys())
cluster_name = cluster_name_key[0]
#print(cluster_name)

managed_node_groups_names = list(service_config[cluster_name]['managed_node_groups'].keys())
#print(managed_node_groups_names)

for name in managed_node_groups_names:
    mng_kubelet_final_extra_args = [f'--node-labels=node.kubernetes.io/lifecycle=`curl -s http://169.254.169.254/latest/meta-data/instance-life-cycle` --node-labels=node.kubernetes.io/nodeGroupName={name}']
    #print(mng_kubelet_final_extra_args)
    for i in service_config[cluster_name]['managed_node_groups'][name]['kubelet_extra_args']:
        mng_kubelet_final_extra_args.append(i)
        #print(mng_kubelet_final_extra_args)
    for k, v in service_config[cluster_name]['managed_node_groups'][name]['labels'].items():
        node_labels = f'--node-labels={k}={v}'
        #print(node_labels)
        mng_kubelet_final_extra_args.append(node_labels)
    service_config[cluster_name]['managed_node_groups'][name].update({'mng_kubelet_final_extra_args': mng_kubelet_final_extra_args} )
    if service_config[cluster_name]['managed_node_group_defaults']['use_node_termination_handler'] == 'true':
        use_node_termination_handler = '--node-labels=aws-node-termination-handler/managed=true'
        mng_kubelet_final_extra_args.append(use_node_termination_handler)
        
print(service_config)