def render_chart(self, chart_dir, output_path, **kwargs): """renders helm chart located at chart_dir, and stores the output to output_path""" if kwargs.get("helm_values_file", None): helm_values_file = ffi.new("char[]", kwargs["helm_values_file"].encode("ascii")) else: # the value in kwargs can be None helm_values_file = ffi.new("char[]", "".encode("ascii")) if kwargs.get("namespace", None): namespace = ffi.new("char[]", kwargs["namespace"].encode("ascii")) else: namespace = ffi.new("char[]", "default".encode("ascii")) if kwargs.get("release_name", None): release_name = ffi.new("char[]", kwargs["release_name"].encode("ascii")) else: release_name = ffi.new("char[]", "".encode("ascii")) if kwargs.get("name_template", None): name_template = ffi.new("char[]", kwargs["name_template"].encode("ascii")) else: name_template = ffi.new("char[]", "".encode("ascii")) char_dir_buf = ffi.new("char[]", chart_dir.encode("ascii")) output_path_buf = ffi.new("char[]", output_path.encode("ascii")) kube_version = ffi.new("char[]", self.kube_version.encode("ascii")) # as noted in cffi documentation, once the reference to the pointer is out of scope, the data is freed. # to prevent that from happening with these dynamic arrays, we create a 'keep_pointers_alive' dict # https://cffi.readthedocs.io/en/latest/using.html#working-with-pointers-structures-and-arrays helm_values_files = [] keep_pointers_alive = dict() if kwargs.get("helm_values_files", []): for i in range(len(kwargs["helm_values_files"])): file_name = kwargs["helm_values_files"][i] ptr_to_encoded_file_name = ffi.new("char[]", file_name.encode("ascii")) keep_pointers_alive[file_name + str(i)] = ptr_to_encoded_file_name helm_values_files.append(ptr_to_encoded_file_name) helm_values_files_len = ffi.cast("int", len(helm_values_files)) helm_values_files = ffi.new("char *[]", helm_values_files) c_error_message = self.lib.renderChart( char_dir_buf, output_path_buf, helm_values_file, namespace, release_name, name_template, helm_values_files, helm_values_files_len, kube_version, ) error_message = ffi.string(c_error_message) # this creates a copy as bytes self.lib.free(c_error_message) # free the char* returned by go return error_message.decode("utf-8") # empty if no error
def render_chart(self, chart_dir, output_path, **kwargs): """renders helm chart located at chart_dir, and stores the output to output_path""" if kwargs.get("helm_values_file", None): helm_values_file = ffi.new( "char[]", kwargs["helm_values_file"].encode("ascii")) else: # the value in kwargs can be None helm_values_file = ffi.new("char[]", "".encode("ascii")) if kwargs.get("namespace", None): namespace = ffi.new("char[]", kwargs["namespace"].encode("ascii")) else: namespace = ffi.new("char[]", "default".encode("ascii")) if kwargs.get("release_name", None): release_name = ffi.new("char[]", kwargs["release_name"].encode("ascii")) else: release_name = ffi.new("char[]", "".encode("ascii")) if kwargs.get("name_template", None): name_template = ffi.new("char[]", kwargs["name_template"].encode("ascii")) else: name_template = ffi.new("char[]", "".encode("ascii")) char_dir_buf = ffi.new("char[]", chart_dir.encode("ascii")) output_path_buf = ffi.new("char[]", output_path.encode("ascii")) helm_values_files = [] if kwargs.get("helm_values_files", []): for file_name in kwargs["helm_values_files"]: helm_values_files.append( ffi.new("char[]", file_name.encode("ascii"))) helm_values_files_len = ffi.cast("int", len(helm_values_files)) helm_values_files = ffi.new("char *[]", helm_values_files) c_error_message = self.lib.renderChart( char_dir_buf, output_path_buf, helm_values_file, namespace, release_name, name_template, helm_values_files, helm_values_files_len, ) error_message = ffi.string( c_error_message) # this creates a copy as bytes self.lib.free(c_error_message) # free the char* returned by go return error_message.decode("utf-8") # empty if no error
def render_chart(chart_dir, output_path, **kwargs): """renders helm chart located at chart_dir, and stores the output to output_path""" try: # lib is opened inside the function to allow multiprocessing lib = ffi.dlopen( os.path.join(os.path.dirname(os.path.abspath(__file__)), "libtemplate.so")) except (NameError, OSError): raise HelmBindingUnavailableError( "Helm binding is not available. Run 'make build_helm_binding' to create it" ) if kwargs.get('helm_values_file', None): helm_values_file = ffi.new("char[]", kwargs['helm_values_file'].encode('ascii')) else: # the value in kwargs can be None helm_values_file = ffi.new("char[]", "".encode('ascii')) if kwargs.get('namespace', None): namespace = ffi.new("char[]", kwargs['namespace'].encode('ascii')) else: namespace = ffi.new("char[]", 'default'.encode('ascii')) if kwargs.get('release_name', None): release_name = ffi.new("char[]", kwargs['release_name'].encode('ascii')) else: release_name = ffi.new("char[]", ''.encode('ascii')) if kwargs.get('name_template', None): name_template = ffi.new("char[]", kwargs['name_template'].encode('ascii')) else: name_template = ffi.new("char[]", ''.encode('ascii')) char_dir_buf = ffi.new("char[]", chart_dir.encode('ascii')) output_path_buf = ffi.new("char[]", output_path.encode('ascii')) c_error_message = lib.renderChart(char_dir_buf, output_path_buf, helm_values_file, namespace, release_name, name_template) error_message = ffi.string(c_error_message) # this creates a copy as bytes lib.free(c_error_message) # free the char* returned by go return error_message.decode("utf-8") # empty if no error
def render_chart(self, chart_dir, output_path, **kwargs): """renders helm chart located at chart_dir, and stores the output to output_path""" if kwargs.get('helm_values_file', None): helm_values_file = ffi.new( "char[]", kwargs['helm_values_file'].encode('ascii')) else: # the value in kwargs can be None helm_values_file = ffi.new("char[]", "".encode('ascii')) if kwargs.get('namespace', None): namespace = ffi.new("char[]", kwargs['namespace'].encode('ascii')) else: namespace = ffi.new("char[]", 'default'.encode('ascii')) if kwargs.get('release_name', None): release_name = ffi.new("char[]", kwargs['release_name'].encode('ascii')) else: release_name = ffi.new("char[]", ''.encode('ascii')) if kwargs.get('name_template', None): name_template = ffi.new("char[]", kwargs['name_template'].encode('ascii')) else: name_template = ffi.new("char[]", ''.encode('ascii')) char_dir_buf = ffi.new("char[]", chart_dir.encode('ascii')) output_path_buf = ffi.new("char[]", output_path.encode('ascii')) c_error_message = self.lib.renderChart(char_dir_buf, output_path_buf, helm_values_file, namespace, release_name, name_template) error_message = ffi.string( c_error_message) # this creates a copy as bytes self.lib.free(c_error_message) # free the char* returned by go return error_message.decode("utf-8") # empty if no error