-
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.
cmd,pkg/destroy: add non-terraform destroy
libvirt destroyer impl is working but has been commented out because: `bazel build tarball` cannot build with `github.com/libvirt-go/libvirt` as one of the dependencies, due to some missing cgo dependencies. `go build cmd/openshift-install` works perfectly fine. revisit add libvirt destroyer when bazel is dropped.
- Loading branch information
1 parent
78c3118
commit 998ba30
Showing
7 changed files
with
386 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["destroyer.go"], | ||
importpath = "github.com/openshift/installer/pkg/destroy", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/asset/metadata:go_default_library", | ||
"//pkg/types:go_default_library", | ||
"//vendor/github.com/openshift/hive/contrib/pkg/aws_tag_deprovision:go_default_library", | ||
"//vendor/github.com/sirupsen/logrus: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,79 @@ | ||
package destroy | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
||
atd "github.com/openshift/hive/contrib/pkg/aws_tag_deprovision" | ||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/openshift/installer/pkg/asset/metadata" | ||
"github.com/openshift/installer/pkg/types" | ||
) | ||
|
||
// Destroyer allows multiple implementations of destroy | ||
// for different platforms. | ||
type Destroyer interface { | ||
Run() error | ||
} | ||
|
||
// NewDestroyer returns Destroyer based on `metadata.json` in `rootDir`. | ||
func NewDestroyer(level log.Level, rootDir string) (Destroyer, error) { | ||
raw, err := ioutil.ReadFile(filepath.Join(rootDir, metadata.MetadataFilename)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var cmetadata types.ClusterMetadata | ||
if err := json.Unmarshal(raw, &cmetadata); err != nil { | ||
return nil, err | ||
} | ||
|
||
var ret Destroyer | ||
switch { | ||
case cmetadata.ClusterPlatformMetadata.AWS != nil: | ||
ret = NewAWSDestroyer(level, &cmetadata) | ||
case cmetadata.ClusterPlatformMetadata.Libvirt != nil: | ||
// ret = NewLibvirtDestroyer(level, &cmetadata) | ||
return nil, fmt.Errorf("libvirt destroyer is not yet supported") | ||
default: | ||
return nil, fmt.Errorf("couldn't find Destroyer for %q", metadata.MetadataFilename) | ||
} | ||
return ret, nil | ||
} | ||
|
||
// // NewLibvirtDestroyer returns libvirt Uninstaller from ClusterMetadata. | ||
// func NewLibvirtDestroyer(level log.Level, metadata *types.ClusterMetadata) *lpd.ClusterUninstaller { | ||
// return &lpd.ClusterUninstaller{ | ||
// LibvirtURI: metadata.ClusterPlatformMetadata.Libvirt.URI, | ||
// Filter: lpd.AlwaysTrueFilter(), //TODO: change to ClusterNamePrefixFilter when all resources are prefixed. | ||
// Logger: log.NewEntry(&log.Logger{ | ||
// Out: os.Stdout, | ||
// Formatter: &log.TextFormatter{ | ||
// FullTimestamp: true, | ||
// }, | ||
// Hooks: make(log.LevelHooks), | ||
// Level: level, | ||
// }), | ||
// } | ||
// } | ||
|
||
// NewAWSDestroyer returns aws Uninstaller from ClusterMetadata. | ||
func NewAWSDestroyer(level log.Level, metadata *types.ClusterMetadata) *atd.ClusterUninstaller { | ||
return &atd.ClusterUninstaller{ | ||
Filters: metadata.ClusterPlatformMetadata.AWS.Identifier, | ||
Region: metadata.ClusterPlatformMetadata.AWS.Region, | ||
ClusterName: metadata.ClusterName, | ||
Logger: log.NewEntry(&log.Logger{ | ||
Out: os.Stdout, | ||
Formatter: &log.TextFormatter{ | ||
FullTimestamp: true, | ||
}, | ||
Hooks: make(log.LevelHooks), | ||
Level: level, | ||
}), | ||
} | ||
} |
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 destroy contains tools for destroying clusters based on their metadata. | ||
package destroy |
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,13 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["libvirt_prefix_deprovision.go"], | ||
importpath = "github.com/openshift/installer/pkg/destroy/libvirt", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//vendor/github.com/libvirt/libvirt-go:go_default_library", | ||
"//vendor/github.com/sirupsen/logrus:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", | ||
], | ||
) |
Oops, something went wrong.