def invoke(self): if not self.ctx.obj.get('api', False): doc_data = ReferenceResolver.resolve_reference(self.locations) documents = list() for d in doc_data: documents.extend(list(yaml.safe_load_all(d.decode()))) manifest_obj = Manifest(documents).get_manifest() obj_check = validate_armada_object(manifest_obj) doc_check = validate_armada_documents(documents) try: if doc_check and obj_check: self.logger.info('Successfully validated: %s', self.locations) except Exception: raise Exception('Failed to validate: %s', self.locations) else: if len(self.locations) > 1: self.logger.error("Cannot specify multiple locations " "when using validate API.") return client = self.ctx.obj.get('CLIENT') resp = client.post_validate(self.locations[0]) if resp.get('code') == 200: self.logger.info('Successfully validated: %s', self.locations) else: self.logger.error("Failed to validate: %s", self.locations)
def validateYaml(args): documents = yaml.safe_load_all(open(args.file).read()) manifest_obj = Manifest(documents).get_manifest() obj_check = validate_armada_object(manifest_obj) doc_check = validate_armada_documents(documents) try: if doc_check and obj_check: LOG.info('Successfully validated: %s', args.file) except Exception: raise Exception('Failed to validate: %s', args.file)
def pre_flight_ops(self): ''' Perform a series of checks and operations to ensure proper deployment ''' # Ensure tiller is available and manifest is valid if not self.tiller.tiller_status(): raise tiller_exceptions.TillerServicesUnavailableException() if not lint.validate_armada_documents(self.documents): raise lint_exceptions.InvalidManifestException() # Override manifest values if --set flag is used if self.overrides or self.values: self.documents = Override(self.documents, overrides=self.overrides, values=self.values).update_manifests() # Get config and validate self.config = self.get_armada_manifest() if not lint.validate_armada_object(self.config): raise lint_exceptions.InvalidArmadaObjectException() # Purge known releases that have failed and are in the current yaml prefix = self.config.get(const.KEYWORD_ARMADA).get( const.KEYWORD_PREFIX) failed_releases = self.get_releases_by_status(const.STATUS_FAILED) for release in failed_releases: for group in self.config.get(const.KEYWORD_ARMADA).get( const.KEYWORD_GROUPS): for ch in group.get(const.KEYWORD_CHARTS): ch_release_name = release_prefix( prefix, ch.get('chart').get('chart_name')) if release[0] == ch_release_name: LOG.info( 'Purging failed release %s ' 'before deployment', release[0]) self.tiller.uninstall_release(release[0]) # Clone the chart sources # # We only support a git source type right now, which can also # handle git:// local paths as well repos = {} for group in self.config.get(const.KEYWORD_ARMADA).get( const.KEYWORD_GROUPS): for ch in group.get(const.KEYWORD_CHARTS): self.tag_cloned_repo(ch, repos) for dep in ch.get('chart').get('dependencies'): self.tag_cloned_repo(dep, repos)
def invoke(self): if not self.ctx.obj.get('api', False): documents = yaml.safe_load_all(open(self.filename).read()) manifest_obj = Manifest(documents).get_manifest() obj_check = validate_armada_object(manifest_obj) doc_check = validate_armada_documents(documents) try: if doc_check and obj_check: self.logger.info('Successfully validated: %s', self.filename) except Exception: raise Exception('Failed to validate: %s', self.filename) else: client = self.ctx.obj.get('CLIENT') with open(self.filename, 'r') as f: resp = client.post_validate(f.read()) if resp.get('valid', False): self.logger.info('Successfully validated: %s', self.filename) else: self.logger.error("Failed to validate: %s", self.filename)