-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Destroy: based on openshift/hive/contrib: aws_tag_deprovision
#324
Changes from all commits
a8fc89b
c6f02ba
008b619
78c3118
998ba30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ import ( | |
"os" | ||
"path/filepath" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/openshift/installer/pkg/asset" | ||
"github.com/openshift/installer/pkg/terraform" | ||
"github.com/openshift/installer/pkg/types/config" | ||
|
@@ -42,7 +44,7 @@ func (c *Cluster) Dependencies() []asset.Asset { | |
func (c *Cluster) Generate(parents map[asset.Asset]*asset.State) (*asset.State, error) { | ||
dir, err := terraform.BaseLocation() | ||
if err != nil { | ||
return nil, err | ||
return nil, fmt.Errorf("error finding baselocation for terraform: %v", err) | ||
wking marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
state, ok := parents[c.tfvars] | ||
|
@@ -68,7 +70,7 @@ func (c *Cluster) Generate(parents map[asset.Asset]*asset.State) (*asset.State, | |
|
||
templateDir, err := terraform.FindStepTemplates(dir, terraform.InfraStep, tfvars.Platform) | ||
if err != nil { | ||
return nil, err | ||
return nil, fmt.Errorf("error finding terraform templates: %v", err) | ||
} | ||
|
||
// This runs the terraform in a temp directory, the tfstate file will be returned | ||
|
@@ -79,7 +81,8 @@ func (c *Cluster) Generate(parents map[asset.Asset]*asset.State) (*asset.State, | |
|
||
stateFile, err := terraform.Apply(tmpDir, terraform.InfraStep, templateDir) | ||
if err != nil { | ||
return nil, err | ||
// we should try to fetch the terraform state file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For cleanup? For a later retry? I'm fine just leaving the dead cluster and using the new tag/prefix cleanup you're adding to prune it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. terrafrom always writes tfstate file, even if if was failed midway. It can be used for debugging to fix errors and use terraform to continue from where it left. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This sounds useful.
This sounds like something we don't want to support. Hopefully install/destroy are both quick enough that the caller can just start clean. |
||
log.Errorf("terraform failed: %v", err) | ||
} | ||
|
||
data, err := ioutil.ReadFile(stateFile) | ||
|
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", | ||
], | ||
) |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package metadata | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golint comments: should have a package comment, unless it's in another file for this package. More info. |
||
|
||
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") | ||
} | ||
wking marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
data, err := json.Marshal(cm) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &asset.State{ | ||
Contents: []asset.Content{ | ||
{ | ||
Name: MetadataFilename, | ||
Data: []byte(data), | ||
}, | ||
}, | ||
}, nil | ||
} |
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.
Minor note but Fatalf will os.Exit(1) for you I think.