def create_nodegroup(ctx, name, node_name, region, verbosity, node_subnets, tags, kubeconf, node_min, node_max, node_role, node_type, node_sg_ingress, keyname, ssh_public_key, ami, bootstrap_opt, no_user_data, yes): """Create a node group in an existing EKS cluster""" cp = ControlPlane(name, region=region) cluster_info = cp.query() if not kubeconf: files = os.environ.get('KUBECONFIG', '~/.kube/config') kubeconf = os.path.expanduser(files.split(':')[0]) if not yes: if not click.confirm('Are you sure to create the EKS cluster in ' 'region[{}] with kubeconfig[{}]'.format( region, kubeconf)): exit(0) ng = NodeGroup(node_name, cluster_info=cluster_info, region=region, ami=ami, keypair=keyname, subnets=node_subnets, role=node_role, sg_ingresses=node_sg_ingress, ssh_public_key=ssh_public_key, tags=tags, kubeconf=kubeconf, min_nodes=node_min, max_nodes=node_max, instance_type=node_type, no_user_data=no_user_data) ng.create()
def test_create_control_plane(): cp = ControlPlane('poc', role='eks-test') ci = cp.create() assert ControlPlane.RESOURCE_EKS_VPC.status == Status.created assert ci is not None assert ci.name == 'poc' assert ci.endpoint == cluster_endpoint
def create_cluster(ctx, name, region, verbosity, cp_role, subnets, tags, vpc_cidr, zones, kubeconf, username, heptio_auth, cp_only, node_name, node_role, node_sg_ingress, node_min, node_max, node_subnets, node_type, keyname, ssh_public_key, ami, no_user_data, yes): """Create an EKS cluster""" if node_subnets and not subnets: print( 'If node subnets are specified, the cluster subnets must appear!') exit(1) elif node_subnets and subnets: s = [ns for ns in node_subnets if ns not in subnets] if s: print('[{}] not one of the cluster subnets.'.format(','.join(s))) exit(1) if not kubeconf: files = os.environ.get('KUBECONFIG', '~/.kube/config') kubeconf = os.path.expanduser(files.split(':')[0]) if not yes: if not click.confirm('Are you sure to create the EKS cluster in ' 'region[{}] with kubeconfig[{}]'.format( region, kubeconf)): exit(0) cp = ControlPlane(name, subnets=subnets, role=cp_role, region=region, tags=tags, vpc_cidr=vpc_cidr, zones=zones) cluster_info = cp.create() kc = KubeConfig(cluster_info, kubeconf, user=username, heptio_auth=heptio_auth) kc.create() if cp_only: LOG.info('To create EKS cluster control plane only.') return ng = NodeGroup(node_name, cluster_info=cluster_info, keypair=keyname, region=region, ami=ami, subnets=node_subnets, kubeconf=kubeconf, role=node_role, sg_ingresses=node_sg_ingress, min_nodes=node_min, max_nodes=node_max, instance_type=node_type, ssh_public_key=ssh_public_key, no_user_data=no_user_data) ng.create()
def get_cluster(ctx, name, region, verbosity): """Display the information about the EKS cluster's control plane. """ cp = ControlPlane(name, region=region) ci = cp.query() headers = ['NAME', 'ENDPOINT', 'VPC', 'SUBNETS'] print( tabulate([[ci.name, ci.endpoint, ci.vpc, ','.join(ci.subnets)]], headers, tablefmt='plain'))
def export_kubeconfig(ctx, name, region, verbosity, kubeconf, username, heptio_auth): """Export Kubernetes configuration for kubectl""" cp = ControlPlane(name, region=region) cluster_info = cp.query() kc = KubeConfig(cluster_info, kubeconf, user=username, heptio_auth=heptio_auth) kc.create()
def test_create_cluster(tmpdir): cp = ControlPlane('test', role='eks-test', region='us-east-1') ci = cp.create() config = tmpdir.join('config') heptio = tmpdir.join('heptio') kc = KubeConfig(ci, config.strpath, user='******', heptio_auth=heptio) kc.create() o = yaml.load(config.read()) assert 'clusters' in o assert len(o['clusters']) == 1
def get_ng(ctx, name, region, verbosity, node_group_names): """Display one or more node groups by names. If no node group names specified, ekscli will display all node groups in the current EKS cluster """ cp = ControlPlane(name, region=region) ci = cp.query() if node_group_names: ngis = [ NodeGroup(name, ci).query().to_list() for name in node_group_names ] else: stacks = cp.get_all_nodegroup_stacks() ngis = [ NodeGroup(name, ci).query(s).to_list() for (name, s) in list(iteritems(stacks)) ] headers = ['NAME', 'INSTANCETYPE', 'MIN', 'MAX', 'ROLE'] print(tabulate(ngis, headers, tablefmt='plain'))
def delete_cluster(ctx, name, region, verbosity): """Delete an EKS cluster (including its node groups)""" cp = ControlPlane(name, region=region) cp.delete()