github.com/openshift/installer@v1.4.17/pkg/asset/templates/content/helper.go (about)

     1  package content
     2  
     3  import (
     4  	"io"
     5  	"path"
     6  
     7  	"github.com/openshift/installer/data"
     8  )
     9  
    10  const (
    11  	// TemplateDir is the target directory for all template assets' files
    12  	TemplateDir      = "templates"
    13  	bootkubeDataDir  = "manifests/bootkube/"
    14  	openshiftDataDir = "manifests/openshift/"
    15  )
    16  
    17  // GetBootkubeTemplate returns the contents of the file in bootkube data dir
    18  func GetBootkubeTemplate(uri string) ([]byte, error) {
    19  	return getFileContents(path.Join(bootkubeDataDir, uri))
    20  }
    21  
    22  // GetOpenshiftTemplate returns the contents of the file in openshift data dir
    23  func GetOpenshiftTemplate(uri string) ([]byte, error) {
    24  	return getFileContents(path.Join(openshiftDataDir, uri))
    25  }
    26  
    27  // getFileContents the content of the given URI, assuming that it's a file
    28  func getFileContents(uri string) ([]byte, error) {
    29  	file, err := data.Assets.Open(uri)
    30  	if err != nil {
    31  		return []byte{}, err
    32  	}
    33  	defer file.Close()
    34  
    35  	return io.ReadAll(file)
    36  }