def _validate_extension_install(cmd, resource_group_name, cluster_rp, cluster_type, cluster_name, no_wait): # Validate if the extension is installed, if not, install it extension_client = k8s_configuration_extension_client(cmd.cli_ctx) extensions = extension_client.list(resource_group_name, cluster_rp, cluster_type, cluster_name) flux_extension = None for extension in extensions: if extension.extension_type.lower() == consts.FLUX_EXTENSION_TYPE: flux_extension = extension break if not flux_extension: logger.warning( "'Microsoft.Flux' extension not found on the cluster, installing it now." " This may take a few minutes...") extension = Extension( extension_type="microsoft.flux", auto_upgrade_minor_version=True, release_train=os.getenv(consts.FLUX_EXTENSION_RELEASETRAIN), version=os.getenv(consts.FLUX_EXTENSION_VERSION), ) if not is_dogfood_cluster(cmd): extension = __add_identity( cmd, extension, resource_group_name, cluster_rp, cluster_type, cluster_name, ) logger.info( "Starting extension creation on the cluster. This might take a few minutes..." ) sdk_no_wait( no_wait, extension_client.begin_create, resource_group_name, cluster_rp, cluster_type, cluster_name, "flux", extension, ).result() # Only show that we have received a success when we have --no-wait if not no_wait: logger.warning( "'Microsoft.Flux' extension was successfully installed on the cluster" ) elif flux_extension.provisioning_state == consts.CREATING: raise DeploymentError(consts.FLUX_EXTENSION_CREATING_ERROR, consts.FLUX_EXTENSION_CREATING_HELP) elif flux_extension.provisioning_state != consts.SUCCEEDED: raise DeploymentError( consts.FLUX_EXTENSION_NOT_SUCCEEDED_OR_CREATING_ERROR, consts.FLUX_EXTENSION_NOT_SUCCEEDED_OR_CREATING_HELP, )
def _wait_build_finished(self, build_result_id): ''' Wait build result finished and stream the log during the waiting ''' self.progress_bar = self.cmd.cli_ctx.get_progress_controller() result = self._get_build_result(build_result_id) build_log_streaming_available = True while result.properties.provisioning_state not in self.terminated_state: try: if build_log_streaming_available: self._stream_build_logs(result) except Exception as e: build_log_streaming_available = False logger.debug('Failed to stream log out: {}'.format(str(e))) pass sleep(5) result = self._get_build_result(build_result_id) if not build_log_streaming_available: logger.warning("Cannot show real time build logs at this moment") self._try_print_build_logs(build_result_id) if result.properties.provisioning_state != "Succeeded": log_url = self._try_get_build_log_url(build_result_id) raise DeploymentError( "Failed to build docker image, please check the build logs {} and retry." .format(log_url))
def _queue_build(self, relative_path=None, builder=None, target_module=None, app=None, **_): subscription = get_subscription_id(self.cmd.cli_ctx) service_resource_id = '/subscriptions/{}/resourceGroups/{}/providers/Microsoft.AppPlatform/Spring/{}'.format( subscription, self.resource_group, self.service) properties = models.BuildProperties( builder='{}/buildservices/default/builders/{}'.format( service_resource_id, builder), agent_pool='{}/buildservices/default/agentPools/default'.format( service_resource_id), relative_path=relative_path, env={"BP_MAVEN_BUILT_MODULE": target_module} if target_module else None) build = models.Build(properties=properties) try: return self.client.build_service.create_or_update_build( self.resource_group, self.service, self.name, app, build).properties.triggered_build_result.id except (AttributeError, CloudError) as e: raise DeploymentError( "Failed to create or update a build. Error: {}".format( e.message))
def _queue_build(self, relative_path=None, builder=None, build_env=None, build_cpu=None, build_memory=None, app=None, deployment=None, **_): subscription = get_subscription_id(self.cmd.cli_ctx) service_resource_id = '/subscriptions/{}/resourceGroups/{}/providers/Microsoft.AppPlatform/Spring/{}'.format( subscription, self.resource_group, self.service) build_resource_requests = models.BuildResourceRequests( cpu=build_cpu, memory=build_memory) properties = models.BuildProperties( builder='{}/buildservices/default/builders/{}'.format( service_resource_id, builder), agent_pool='{}/buildservices/default/agentPools/default'.format( service_resource_id), relative_path=relative_path, env=build_env if build_env else None, resource_requests=build_resource_requests) build = models.Build(properties=properties) try: return self.client.build_service.create_or_update_build( self.resource_group, self.service, self.name, app + '-' + deployment, build).properties.triggered_build_result.id except (AttributeError, CloudError) as e: raise DeploymentError( "Failed to create or update a build. Error: {}".format( e.message))
def _validate_source_control_config_not_installed(cmd, resource_group_name, cluster_rp, cluster_type, cluster_name): # Validate if we are able to install the flux configuration source_control_client = k8s_configuration_sourcecontrol_client(cmd.cli_ctx) configs = source_control_client.list(resource_group_name, cluster_rp, cluster_type, cluster_name) # configs is an iterable, no len() so we have to iterate to check for configs for _ in configs: raise DeploymentError(consts.SCC_EXISTS_ON_CLUSTER_ERROR, consts.SCC_EXISTS_ON_CLUSTER_HELP)