-
Notifications
You must be signed in to change notification settings - Fork 1.5k
cmd/openshift-install/create: Add metadata.json to ignition-configs #1070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| package cluster | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "io/ioutil" | ||
| "path/filepath" | ||
|
|
||
| "github.com/openshift/installer/pkg/asset" | ||
| "github.com/openshift/installer/pkg/asset/cluster/aws" | ||
| "github.com/openshift/installer/pkg/asset/cluster/libvirt" | ||
| "github.com/openshift/installer/pkg/asset/cluster/openstack" | ||
| "github.com/openshift/installer/pkg/asset/installconfig" | ||
| "github.com/openshift/installer/pkg/types" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| const ( | ||
| metadataFileName = "metadata.json" | ||
| ) | ||
|
|
||
| // Metadata contains information needed to destroy clusters. | ||
| type Metadata struct { | ||
| file *asset.File | ||
| } | ||
|
|
||
| var _ asset.WritableAsset = (*Metadata)(nil) | ||
|
|
||
| // Name returns the human-friendly name of the asset. | ||
| func (m *Metadata) Name() string { | ||
| return "Metadata" | ||
| } | ||
|
|
||
| // Dependencies returns the direct dependencies for the metadata | ||
| // asset. | ||
| func (m *Metadata) Dependencies() []asset.Asset { | ||
| return []asset.Asset{ | ||
| &installconfig.ClusterID{}, | ||
| &installconfig.InstallConfig{}, | ||
| } | ||
| } | ||
|
|
||
| // Generate generates the metadata asset. | ||
| func (m *Metadata) Generate(parents asset.Parents) (err error) { | ||
| clusterID := &installconfig.ClusterID{} | ||
| installConfig := &installconfig.InstallConfig{} | ||
| parents.Get(clusterID, installConfig) | ||
|
|
||
| if installConfig.Config.Platform.None != nil { | ||
| return nil | ||
| } | ||
|
|
||
| metadata := &types.ClusterMetadata{ | ||
| ClusterName: installConfig.Config.ObjectMeta.Name, | ||
| ClusterID: clusterID.ClusterID, | ||
| } | ||
|
|
||
| switch { | ||
| case installConfig.Config.Platform.AWS != nil: | ||
| metadata.ClusterPlatformMetadata.AWS = aws.Metadata(clusterID.ClusterID, installConfig.Config) | ||
| case installConfig.Config.Platform.Libvirt != nil: | ||
| metadata.ClusterPlatformMetadata.Libvirt = libvirt.Metadata(installConfig.Config) | ||
| case installConfig.Config.Platform.OpenStack != nil: | ||
| metadata.ClusterPlatformMetadata.OpenStack = openstack.Metadata(clusterID.ClusterID, installConfig.Config) | ||
| default: | ||
wking marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return errors.Errorf("no known platform") | ||
| } | ||
|
|
||
| data, err := json.Marshal(metadata) | ||
| if err != nil { | ||
| return errors.Wrap(err, "failed to Marshal ClusterMetadata") | ||
| } | ||
|
|
||
| m.file = &asset.File{ | ||
| Filename: metadataFileName, | ||
| Data: data, | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Files returns the FileList generated by the asset. | ||
| func (m *Metadata) Files() []*asset.File { | ||
| if m.file != nil { | ||
| return []*asset.File{m.file} | ||
| } | ||
| return []*asset.File{} | ||
| } | ||
|
|
||
| // Load is a no-op, because we never want to load broken metadata from | ||
| // the disk. | ||
| func (m *Metadata) Load(f asset.FileFetcher) (found bool, err error) { | ||
| return false, nil | ||
| } | ||
|
|
||
| // LoadMetadata loads the cluster metadata from an asset directory. | ||
| func LoadMetadata(dir string) (*types.ClusterMetadata, error) { | ||
staebler marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| path := filepath.Join(dir, metadataFileName) | ||
| raw, err := ioutil.ReadFile(path) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var metadata *types.ClusterMetadata | ||
| if err = json.Unmarshal(raw, &metadata); err != nil { | ||
| return nil, errors.Wrapf(err, "failed to Unmarshal data from %q to types.ClusterMetadata", path) | ||
| } | ||
|
|
||
| return metadata, err | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With these changes,
metadata.jsonhas become information and not just a file used by thedestroycommand. It would rather see consistency where the file is generated even when the platform isNone. With that said, I can live with the changes as they are, and we can address what to do about theNoneplatform for later releases.