github.com/openshift/installer@v1.4.17/pkg/asset/cluster/metadata.go (about) 1 package cluster 2 3 import ( 4 "context" 5 "encoding/json" 6 7 "github.com/pkg/errors" 8 9 configv1 "github.com/openshift/api/config/v1" 10 "github.com/openshift/installer/pkg/asset" 11 "github.com/openshift/installer/pkg/asset/cluster/aws" 12 "github.com/openshift/installer/pkg/asset/cluster/azure" 13 "github.com/openshift/installer/pkg/asset/cluster/baremetal" 14 "github.com/openshift/installer/pkg/asset/cluster/gcp" 15 "github.com/openshift/installer/pkg/asset/cluster/ibmcloud" 16 clustermetadata "github.com/openshift/installer/pkg/asset/cluster/metadata" 17 "github.com/openshift/installer/pkg/asset/cluster/nutanix" 18 "github.com/openshift/installer/pkg/asset/cluster/openstack" 19 "github.com/openshift/installer/pkg/asset/cluster/ovirt" 20 "github.com/openshift/installer/pkg/asset/cluster/powervs" 21 "github.com/openshift/installer/pkg/asset/cluster/vsphere" 22 "github.com/openshift/installer/pkg/asset/ignition/bootstrap" 23 "github.com/openshift/installer/pkg/asset/installconfig" 24 "github.com/openshift/installer/pkg/types" 25 awstypes "github.com/openshift/installer/pkg/types/aws" 26 azuretypes "github.com/openshift/installer/pkg/types/azure" 27 baremetaltypes "github.com/openshift/installer/pkg/types/baremetal" 28 externaltypes "github.com/openshift/installer/pkg/types/external" 29 "github.com/openshift/installer/pkg/types/featuregates" 30 gcptypes "github.com/openshift/installer/pkg/types/gcp" 31 ibmcloudtypes "github.com/openshift/installer/pkg/types/ibmcloud" 32 nonetypes "github.com/openshift/installer/pkg/types/none" 33 nutanixtypes "github.com/openshift/installer/pkg/types/nutanix" 34 openstacktypes "github.com/openshift/installer/pkg/types/openstack" 35 ovirttypes "github.com/openshift/installer/pkg/types/ovirt" 36 powervstypes "github.com/openshift/installer/pkg/types/powervs" 37 vspheretypes "github.com/openshift/installer/pkg/types/vsphere" 38 ) 39 40 // Metadata contains information needed to destroy clusters. 41 type Metadata struct { 42 File *asset.File 43 } 44 45 var _ asset.WritableAsset = (*Metadata)(nil) 46 47 // Name returns the human-friendly name of the asset. 48 func (m *Metadata) Name() string { 49 return "Metadata" 50 } 51 52 // Dependencies returns the direct dependencies for the metadata 53 // asset. 54 func (m *Metadata) Dependencies() []asset.Asset { 55 return []asset.Asset{ 56 &installconfig.ClusterID{}, 57 &installconfig.InstallConfig{}, 58 &bootstrap.Bootstrap{}, 59 } 60 } 61 62 // Generate generates the metadata asset. 63 func (m *Metadata) Generate(_ context.Context, parents asset.Parents) (err error) { 64 clusterID := &installconfig.ClusterID{} 65 installConfig := &installconfig.InstallConfig{} 66 parents.Get(clusterID, installConfig) 67 68 featureSet := installConfig.Config.FeatureSet 69 var customFS *configv1.CustomFeatureGates 70 if featureSet == configv1.CustomNoUpgrade { 71 customFS = featuregates.GenerateCustomFeatures(installConfig.Config.FeatureGates) 72 } 73 74 metadata := &types.ClusterMetadata{ 75 ClusterName: installConfig.Config.ObjectMeta.Name, 76 ClusterID: clusterID.UUID, 77 InfraID: clusterID.InfraID, 78 FeatureSet: featureSet, 79 CustomFeatureSet: customFS, 80 } 81 82 switch installConfig.Config.Platform.Name() { 83 case awstypes.Name: 84 metadata.ClusterPlatformMetadata.AWS = aws.Metadata(clusterID.UUID, clusterID.InfraID, installConfig.Config) 85 case openstacktypes.Name: 86 metadata.ClusterPlatformMetadata.OpenStack = openstack.Metadata(clusterID.InfraID, installConfig.Config) 87 case azuretypes.Name: 88 metadata.ClusterPlatformMetadata.Azure = azure.Metadata(installConfig.Config) 89 case gcptypes.Name: 90 metadata.ClusterPlatformMetadata.GCP = gcp.Metadata(installConfig.Config) 91 case ibmcloudtypes.Name: 92 metadata.ClusterPlatformMetadata.IBMCloud = ibmcloud.Metadata(clusterID.InfraID, installConfig.Config) 93 case baremetaltypes.Name: 94 metadata.ClusterPlatformMetadata.BareMetal = baremetal.Metadata(installConfig.Config) 95 case ovirttypes.Name: 96 metadata.ClusterPlatformMetadata.Ovirt = ovirt.Metadata(installConfig.Config) 97 case vspheretypes.Name: 98 metadata.ClusterPlatformMetadata.VSphere = vsphere.Metadata(installConfig.Config) 99 case powervstypes.Name: 100 metadata.ClusterPlatformMetadata.PowerVS = powervs.Metadata(installConfig.Config, installConfig.PowerVS) 101 case externaltypes.Name, nonetypes.Name: 102 case nutanixtypes.Name: 103 metadata.ClusterPlatformMetadata.Nutanix = nutanix.Metadata(installConfig.Config) 104 default: 105 return errors.Errorf("no known platform") 106 } 107 108 data, err := json.Marshal(metadata) 109 if err != nil { 110 return errors.Wrap(err, "failed to Marshal ClusterMetadata") 111 } 112 113 m.File = &asset.File{ 114 Filename: clustermetadata.FileName, 115 Data: data, 116 } 117 118 return nil 119 } 120 121 // Files returns the metadata file generated by the asset. 122 func (m *Metadata) Files() []*asset.File { 123 if m.File != nil { 124 return []*asset.File{m.File} 125 } 126 return []*asset.File{} 127 } 128 129 // Load is a no-op, because we never want to load broken metadata from 130 // the disk. 131 func (m *Metadata) Load(f asset.FileFetcher) (found bool, err error) { 132 return false, nil 133 }