def resize(self, node_count, **kwargs): agent_pool_profiles = copy.copy(self.agent_pool_profiles) agent_pool_profiles[0]['count'] = node_count managed_cluster = ManagedCluster( self.location, dns_prefix=self.resource_group_name, kubernetes_version='1.7.7', agent_pool_profiles=agent_pool_profiles, linux_profile=self.linux_profile, service_principal_profile=self.service_principal_profile ) try: self.client.managed_clusters.create_or_update(self.resource_group_name, self.cluster.id, managed_cluster) # TODO: check if resizing response is healthy except Exception as e: msg = 'Resizing cluster {} failed with the following reason: '\ .format(self.cluster.id) logger.exception(msg) return False, repr(e) self.cluster.metadata['node_count'] = node_count self.cluster.save() return True, None
def build(self): cluster_params = {} cluster_params["location"] = self.location cluster_params["dns_prefix"] = self.dns_prefix cluster_params["linux_profile"] = self.linux_profile cluster_params["network_profile"] = self.network_profile cluster_params["service_principal_profile"] = self.cluster_sp cluster_params["kubernetes_version"] = self.cluster_version cluster_params["agent_pool_profiles"] = self.node_pools self.cluster_config = ManagedCluster(**cluster_params) return self.clusters_client.managed_clusters.create_or_update( self.resource_group, self.name, self.cluster_config)
def create_update_aks(self): ''' Creates or updates a managed Azure container service (AKS) with the specified configuration of agents. :return: deserialized AKS instance state dictionary ''' self.log("Creating / Updating the AKS instance {0}".format(self.name)) agentpools = [] if self.agent_pool_profiles: agentpools = [ create_agent_pool_profile_instance(profile) for profile in self.agent_pool_profiles ] service_principal_profile = create_service_principal_profile_instance( self.service_principal) parameters = ManagedCluster( location=self.location, dns_prefix=self.dns_prefix, kubernetes_version=self.kubernetes_version, tags=self.tags, service_principal_profile=service_principal_profile, agent_pool_profiles=agentpools, linux_profile=create_linux_profile_instance(self.linux_profile), enable_rbac=self.enable_rbac) # self.log("service_principal_profile : {0}".format(parameters.service_principal_profile)) # self.log("linux_profile : {0}".format(parameters.linux_profile)) # self.log("ssh from yaml : {0}".format(results.get('linux_profile')[0])) # self.log("ssh : {0}".format(parameters.linux_profile.ssh)) # self.log("agent_pool_profiles : {0}".format(parameters.agent_pool_profiles)) try: poller = self.containerservice_client.managed_clusters.create_or_update( self.resource_group, self.name, parameters) response = self.get_poller_result(poller) response.kube_config = self.get_aks_kubeconfig() return create_aks_dict(response) except CloudError as exc: self.log('Error attempting to create the AKS instance.') self.fail("Error creating the AKS instance: {0}".format( exc.message))
def provision(self, **kwargs): """ Implementation of :func:`~kqueen.engines.base.BaseEngine.provision` """ managed_cluster = ManagedCluster( self.location, dns_prefix=self.resource_group_name, kubernetes_version='1.7.7', agent_pool_profiles=self.agent_pool_profiles, linux_profile=self.linux_profile, service_principal_profile=self.service_principal_profile ) try: self.client.managed_clusters.create_or_update(self.resource_group_name, self.cluster.id, managed_cluster) # TODO: check if provisioning response is healthy except Exception as e: msg = 'Creating cluster {} failed with following reason:'.format(self.cluster.id) logger.exception(msg) return False, msg return True, None
def build(self): cluster_params = {} cluster_params["location"] = self.location cluster_params["dns_prefix"] = self.dns_prefix cluster_params["linux_profile"] = self.linux_profile cluster_params["network_profile"] = self.network_profile cluster_params["node_resource_group"] = self.node_resource_group cluster_params["service_principal_profile"] = self.cluster_sp cluster_params["identity"] = self.identity cluster_params["identity_profile"] = self.identity_profile cluster_params["kubernetes_version"] = self.cluster_version cluster_params["agent_pool_profiles"] = self.node_pools cluster_params["tags"] = self.tags if self.private_access: cluster_params["api_server_access_profile"] = self.private_access self.cluster_config = ManagedCluster(**cluster_params) future = self.clusters_client.managed_clusters.begin_create_or_update( self.resource_group, self.name, self.cluster_config) return future
def create_cluster(node_count): """ Azure requires node pool name to be 9 alphanumeric characters, and lowercase. """ profile = get_service_profile() container_client = get_container_client() cluster_resource = container_client.managed_clusters.create_or_update( resource_group, CLUSTER_NAME, parameters=ManagedCluster( location=location, tags=None, dns_prefix=dns_prefix.lower(), service_principal_profile=profile, agent_pool_profiles=[{ 'name': agent_pool_name.lower()[:9], 'vm_size': 'Standard_DS2_v2', 'count': node_count, }], ), ) return cluster_resource