def load_config(self, url): snapshot = url.split('/')[-1] ss_path = os.path.join(app.snapshot_path, "snapshot-%s.yaml" % snapshot) self.logger.info("copying configuration from %s to %s" % (url, ss_path)) # Grab the serialization, and save it to disk too. serialization = load_url_contents(self.logger, "%s/services" % url, stream2=open(ss_path, "w")) if not serialization: self.logger.info("no data loaded from snapshot %s?" % snapshot) return scc = SecretSaver(app.logger, url, app.snapshot_path) aconf = Config() fetcher = ResourceFetcher(app.logger, aconf) fetcher.parse_yaml(serialization, k8s=True) if not fetcher.elements: self.logger.info("no configuration found in snapshot %s?" % snapshot) return self._load_ir(aconf, fetcher, scc.url_reader, snapshot)
def load_config_fs(self, path: str) -> None: snapshot = re.sub(r'[^A-Za-z0-9_-]', '_', path) self.logger.info("loading configuration from disk: %s" % path) scc = SecretSaver(app.logger, path, app.snapshot_path) aconf = Config() fetcher = ResourceFetcher(app.logger, aconf) fetcher.load_from_filesystem(path, k8s=False, recurse=True) if not fetcher.elements: self.logger.info("no configuration found at %s" % path) return self._load_ir(aconf, fetcher, scc.null_reader, snapshot)
def load_config(self, url): snapshot = url.split('/')[-1] aconf_path = os.path.join(app.config_dir_prefix, "snapshot-%s.yaml" % snapshot) ir_path = os.path.join(app.config_dir_prefix, "ir-%s.json" % snapshot) self.logger.info("copying configuration from %s to %s" % (url, aconf_path)) saved = save_url_contents(self.logger, "%s/services" % url, aconf_path) if saved: scc = SecretSaver(app.logger, url, app.config_dir_prefix) aconf = Config() # Yeah yeah yeah. It's not really a directory. Whatever. aconf.load_from_directory(aconf_path, k8s=app.k8s, recurse=True) ir = IR(aconf, secret_reader=scc.url_reader) open(ir_path, "w").write(ir.as_json()) check_scout(app, "update", ir) econf = EnvoyConfig.generate(ir, "V2") diag = Diagnostics(ir, econf) bootstrap_config, ads_config = econf.split_config() self.logger.info("saving Envoy configuration for snapshot %s" % snapshot) with open(app.bootstrap_path, "w") as output: output.write( json.dumps(bootstrap_config, sort_keys=True, indent=4)) with open(app.ads_path, "w") as output: output.write(json.dumps(ads_config, sort_keys=True, indent=4)) app.aconf = aconf app.ir = ir app.econf = econf app.diag = diag if app.ambex_pid != 0: self.logger.info("notifying PID %d ambex" % app.ambex_pid) os.kill(app.ambex_pid, signal.SIGHUP) self.logger.info("configuration updated")
def load_config_fs(self, rqueue: queue.Queue, path: str) -> None: self.logger.info("loading configuration from disk: %s" % path) snapshot = re.sub(r'[^A-Za-z0-9_-]', '_', path) scc = SecretSaver(app.logger, path, app.snapshot_path) aconf = Config() fetcher = ResourceFetcher(app.logger, aconf) fetcher.load_from_filesystem(path, k8s=app.k8s, recurse=True) if not fetcher.elements: self.logger.debug("no configuration resources found at %s" % path) # self._respond(rqueue, 204, 'ignoring empty configuration') # return self._load_ir(rqueue, aconf, fetcher, scc.null_reader, snapshot)
def load_config(self, rqueue: queue.Queue, url): snapshot = url.split('/')[-1] ss_path = os.path.join(app.snapshot_path, "snapshot-tmp.yaml") self.logger.info("copying configuration from %s to %s" % (url, ss_path)) # Grab the serialization, and save it to disk too. elements: List[str] = [] serialization = load_url_contents(self.logger, "%s/services" % url, stream2=open(ss_path, "w")) if serialization: elements.append(serialization) else: self.logger.debug("no services loaded from snapshot %s" % snapshot) if os.environ.get('AMBASSADOR_ENABLE_ENDPOINTS'): serialization = load_url_contents(self.logger, "%s/endpoints" % url, stream2=open(ss_path, "a")) if serialization: elements.append(serialization) else: self.logger.debug("no endpoints loaded from snapshot %s" % snapshot) serialization = "---\n".join(elements) if not serialization: self.logger.debug("no data loaded from snapshot %s" % snapshot) # We never used to return here. I'm not sure if that's really correct? # self._respond(rqueue, 204, 'ignoring: no data loaded from snapshot %s' % snapshot) # return scc = SecretSaver(app.logger, url, app.snapshot_path) aconf = Config() fetcher = ResourceFetcher(app.logger, aconf) fetcher.parse_yaml(serialization, k8s=True) if not fetcher.elements: self.logger.debug("no configuration found in snapshot %s" % snapshot) # Don't actually bail here. If they send over a valid config that happens # to have nothing for us, it's still a legit config. # self._respond(rqueue, 204, 'ignoring: no configuration found in snapshot %s' % snapshot) # return self._load_ir(rqueue, aconf, fetcher, scc.url_reader, snapshot)