def get_inputs(self, params, these_input_keys=[]): params_input = Params({}) # for each standard input for standard_input in self.standard: param_key = standard_input.get_key() # if we should gather all inputs (i.e. no specific input keys were # specified), or # if this param keys is one of the specific keys to be # gathered if (not these_input_keys or param_key in these_input_keys): # handle this input value, user_prompted = standard_input.process(params) # accumulate this input if user_prompted: params_input.set(param_key, value, standard_input.get_help()) params.add(params_input) # for each conditional input for conditional_input in self.conditional: param_key = conditional_input.get_key() # if we should gather all inputs (i.e. no specific input keys were # specified), or # if this param keys is one of the specific keys to be # gathered if (not these_input_keys or param_key in these_input_keys): # handle this input value, user_prompted = conditional_input.process(params) # accumulate this input if user_prompted: params_input.set(param_key, value, conditional_input.get_help()) return params_input
def _get_logger_configs(logs_full_path, log_level="INFO"): logs_path = os.path.dirname(logs_full_path) if not os.path.exists(logs_path): os.makedirs(logs_path) logger_configs_with_refs = {} with open(os.path.join(get_root_path(), "config/logger.conf"), 'r') as config_file: logger_configs_with_refs = json.load(config_file) key_values = Params({}) key_values.set("log-level", log_level) key_values.set("deploy-log-path", logs_full_path) # render log level and log path into logger configs return apply_intrinsics(logger_configs_with_refs, key_values)
def install_kube_config(self, params): # use .kubeconfig.yaml as a template with open(os.path.join(get_root_path(), "lib/stacks/k8s/configs/.kubeconfig.yaml"), 'r') as config_file: file_contents = config_file.read() # render mustaches in the file ... # first worry about how to render the 'token' token in the # file # use placeholder values (o.w. apply_stemplate will raise TemplateError). # the user will need to use kubelogin to overwrite stock_tokens = ["via kubelogin", "via kubelogin", "via kubelogin"] if not self.tokens: # no tokens are provided via servicefile. this is a typical pattern # for servicefiles that are meant to be run from a developer desktop. tokens = stock_tokens else: tmp_tokens = stock_tokens # make sure there is one token per cluster tmp_tokens[0:len(self.tokens)] = self.tokens # tokens were specified in the servicefile # these will typically include secrets that are referenced # via a yac-ref intrinstric, so render intrinsics in the tokens tokens = apply_intrinsics(tmp_tokens, params) # build the params for each variable in the file local_params = Params({}) # set variables for each of the cluster tokens cluster_keys = ["nonprod-token","prod1-token","prod2-token"] for i,token in enumerate(tokens): local_params.set(cluster_keys[i],token) # the namespace params supports intrinsics (so that it can be set via an input) namespace = apply_intrinsics(self.namespace, params) # set namespace variable for template rendering local_params.set("namespace", namespace) if self.is_desktop: # use the private api to avoid the limitations of the public # api endpoint, per: # * https://gitlab.nordstrom.com/k8s/platform-bootstrap/wikis/Onboard-to-AWS-Kubernetes-Clusters local_params.set("nonprod-api-url",NONPROD_PRIVATE_API) else: # pipelines must use the public to avoid v2 account peering # contraints local_params.set("nonprod-api-url",NONPROD_PUBLIC_API) # do the actual mustache rendering rendered_file_contents = apply_stemplate(file_contents,local_params) # take backup of any existing .kube/config files self.backup_existing(".kube/config") # write file self.write_home_file(rendered_file_contents,".kube/config")
def get_meta_params(self): # get meta data about this service service_metadata = Params({}) service_metadata.set("service-default-alias",self.description.default_alias, "service default alias") service_metadata.set("service-alias",self.description.alias, "service alias") service_metadata.set("service-name",self.description.name, "service name") service_metadata.set("servicefile-path",self.path, "path to the servicefile") # add service summary and repo service_metadata.set('service-summary',self.description.summary, "service summary") service_metadata.set('service-repo',self.description.repo, "repo containing this service") # add the command that was run against this service service_metadata.set("yac-command",sys.argv[0], 'the yac command being run') return service_metadata