-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg: add ClusterMetadata asset,type that can be used for destroy
- Loading branch information
1 parent
008b619
commit 78c3118
Showing
12 changed files
with
169 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,18 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = [ | ||
"doc.go", | ||
"metadata.go", | ||
"stock.go", | ||
], | ||
importpath = "github.com/openshift/installer/pkg/asset/metadata", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/asset:go_default_library", | ||
"//pkg/asset/cluster:go_default_library", | ||
"//pkg/asset/installconfig:go_default_library", | ||
"//pkg/types:go_default_library", | ||
], | ||
) |
This file contains 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,2 @@ | ||
// Package metadata contains asset targets that generates the metadata.yaml | ||
package metadata |
This file contains 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,74 @@ | ||
package metadata | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/openshift/installer/pkg/asset" | ||
"github.com/openshift/installer/pkg/asset/installconfig" | ||
"github.com/openshift/installer/pkg/types" | ||
) | ||
|
||
const ( | ||
// MetadataFilename is name of the file where clustermetadata is stored. | ||
MetadataFilename = "metadata.json" | ||
metadataAssetName = "Cluster Metadata" | ||
) | ||
|
||
// Metadata depends on cluster and installconfig, | ||
type Metadata struct { | ||
installConfig asset.Asset | ||
cluster asset.Asset | ||
} | ||
|
||
var _ asset.Asset = (*Metadata)(nil) | ||
|
||
// Name returns the human-friendly name of the asset. | ||
func (m *Metadata) Name() string { | ||
return metadataAssetName | ||
} | ||
|
||
// Dependencies returns the dependency of the MetaData. | ||
func (m *Metadata) Dependencies() []asset.Asset { | ||
return []asset.Asset{m.installConfig, m.cluster} | ||
} | ||
|
||
// Generate generates the metadata.yaml file. | ||
func (m *Metadata) Generate(parents map[asset.Asset]*asset.State) (*asset.State, error) { | ||
installCfg, err := installconfig.GetInstallConfig(m.installConfig, parents) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cm := &types.ClusterMetadata{ | ||
ClusterName: installCfg.Name, | ||
} | ||
switch { | ||
case installCfg.Platform.AWS != nil: | ||
cm.ClusterPlatformMetadata.AWS = &types.ClusterAWSPlatformMetadata{ | ||
Region: installCfg.Platform.AWS.Region, | ||
Identifier: map[string]string{ | ||
"tectonicClusterID": installCfg.ClusterID, | ||
}, | ||
} | ||
case installCfg.Platform.Libvirt != nil: | ||
cm.ClusterPlatformMetadata.Libvirt = &types.ClusterLibvirtPlatformMetadata{ | ||
URI: installCfg.Platform.Libvirt.URI, | ||
} | ||
default: | ||
return nil, fmt.Errorf("no known platform") | ||
} | ||
|
||
data, err := json.Marshal(cm) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &asset.State{ | ||
Contents: []asset.Content{ | ||
{ | ||
Name: MetadataFilename, | ||
Data: []byte(data), | ||
}, | ||
}, | ||
}, nil | ||
} |
This file contains 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,31 @@ | ||
package metadata | ||
|
||
import ( | ||
"github.com/openshift/installer/pkg/asset" | ||
"github.com/openshift/installer/pkg/asset/cluster" | ||
"github.com/openshift/installer/pkg/asset/installconfig" | ||
) | ||
|
||
// Stock is the stock of the cluster assets that can be generated. | ||
type Stock interface { | ||
// Metadata is the asset that generates the metadata.json file | ||
Metadata() asset.Asset | ||
} | ||
|
||
// StockImpl is the implementation of the cluster asset stock. | ||
type StockImpl struct { | ||
metadata asset.Asset | ||
} | ||
|
||
var _ Stock = (*StockImpl)(nil) | ||
|
||
// EstablishStock establishes the stock of assets in the specified directory. | ||
func (s *StockImpl) EstablishStock(installConfigStock installconfig.Stock, clusterStock cluster.Stock) { | ||
s.metadata = &Metadata{ | ||
installConfig: installConfigStock.InstallConfig(), | ||
cluster: clusterStock.Cluster(), | ||
} | ||
} | ||
|
||
// Metadata returns the terraform tfvar asset. | ||
func (s *StockImpl) Metadata() asset.Asset { return s.metadata } |
This file contains 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 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 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 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 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,26 @@ | ||
package types | ||
|
||
// ClusterMetadata contains information | ||
// regarding the cluster that was created by installer. | ||
type ClusterMetadata struct { | ||
ClusterName string `json:"clusterName"` | ||
ClusterPlatformMetadata `json:",inline"` | ||
} | ||
|
||
// ClusterPlatformMetadata contains metadata for platfrom. | ||
type ClusterPlatformMetadata struct { | ||
AWS *ClusterAWSPlatformMetadata `json:"aws,omitempty"` | ||
Libvirt *ClusterLibvirtPlatformMetadata `json:"libvirt,omitempty"` | ||
} | ||
|
||
// ClusterAWSPlatformMetadata contains AWS metadata. | ||
type ClusterAWSPlatformMetadata struct { | ||
Region string `json:"region"` | ||
// Most AWS resources are tagged with these tags as identifier. | ||
Identifier map[string]string `json:"identifier"` | ||
} | ||
|
||
// ClusterLibvirtPlatformMetadata contains libvirt metadata. | ||
type ClusterLibvirtPlatformMetadata struct { | ||
URI string `json:"uri"` | ||
} |