github.com/openshift/installer@v1.4.17/pkg/asset/cluster/metadata/metadata.go (about)

     1  package metadata
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"os"
     7  	"path/filepath"
     8  
     9  	"github.com/openshift/installer/pkg/types"
    10  )
    11  
    12  const (
    13  	// FileName is the filename for the cluster metadata.json file.
    14  	FileName = "metadata.json"
    15  )
    16  
    17  // Load loads the cluster metadata from an asset directory.
    18  func Load(dir string) (*types.ClusterMetadata, error) {
    19  	path := filepath.Join(dir, FileName)
    20  	raw, err := os.ReadFile(path)
    21  	if err != nil {
    22  		return nil, err
    23  	}
    24  
    25  	var metadata *types.ClusterMetadata
    26  	if err = json.Unmarshal(raw, &metadata); err != nil {
    27  		return nil, fmt.Errorf("failed to Unmarshal data from %q to types.ClusterMetadata: %w", path, err)
    28  	}
    29  
    30  	return metadata, err
    31  }