Skip to content

Commit

Permalink
Merge pull request #324 from abhinavdahiya/core
Browse files Browse the repository at this point in the history
Destroy: based on `openshift/hive/contrib: aws_tag_deprovision`
  • Loading branch information
openshift-merge-robot authored Sep 25, 2018
2 parents 238a0ed + 998ba30 commit d8844be
Show file tree
Hide file tree
Showing 209 changed files with 125,583 additions and 39 deletions.
3 changes: 2 additions & 1 deletion cmd/openshift-install/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ go_library(
deps = [
"//pkg/asset:go_default_library",
"//pkg/asset/stock:go_default_library",
"//vendor/github.com/Sirupsen/logrus:go_default_library",
"//pkg/destroy:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
"//vendor/gopkg.in/alecthomas/kingpin.v2:go_default_library",
],
)
Expand Down
49 changes: 35 additions & 14 deletions cmd/openshift-install/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"os"

log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/stock"
"github.com/openshift/installer/pkg/destroy"
)

var (
Expand All @@ -16,12 +17,20 @@ var (
manifestsCommand = kingpin.Command("manifests", "Generate the Kubernetes manifests")
clusterCommand = kingpin.Command("cluster", "Create an OpenShift cluster")

destroyCommand = kingpin.Command("destroy-cluster", "Destroy an OpenShift cluster")

dirFlag = kingpin.Flag("dir", "assets directory").Default(".").String()
logLevel = kingpin.Flag("log-level", "log level (e.g. \"debug\")").Default("warn").Enum("debug", "info", "warn", "error", "fatal", "panic")
)

func main() {
command := kingpin.Parse()
l, err := log.ParseLevel(*logLevel)
if err != nil {
// By definition we should never enter this condition since kingpin should be guarding against incorrect values.
log.Fatalf("invalid log-level: %v", err)
}
log.SetLevel(l)

assetStock := stock.EstablishStock()

Expand All @@ -45,27 +54,39 @@ func main() {
assetStock.TFVars(),
assetStock.KubeconfigAdmin(),
assetStock.Cluster(),
assetStock.Metadata(),
}
}

l, err := log.ParseLevel(*logLevel)
if err != nil {
// By definition we should never enter this condition since kingpin should be guarding against incorrect values.
log.Fatalf("invalid log-level: %v", err)
}
log.SetLevel(l)
switch command {
case installConfigCommand.FullCommand(),
ignitionConfigsCommand.FullCommand(),
manifestsCommand.FullCommand(),
clusterCommand.FullCommand():
assetStore := &asset.StoreImpl{}
for _, asset := range targetAssets {
st, err := assetStore.Fetch(asset)
if err != nil {
log.Fatalf("failed to generate asset: %v", err)
os.Exit(1)
}

assetStore := &asset.StoreImpl{}
for _, asset := range targetAssets {
st, err := assetStore.Fetch(asset)
if err := st.PersistToFile(*dirFlag); err != nil {
log.Fatalf("failed to write target to disk: %v", err)
os.Exit(1)
}
}
case destroyCommand.FullCommand():
destroyer, err := destroy.NewDestroyer(l, *dirFlag)
if err != nil {
log.Fatalf("failed to generate asset: %v", err)
log.Fatalf("failed to create destroyer: %v", err)
os.Exit(1)
}

if err := st.PersistToFile(*dirFlag); err != nil {
log.Fatalf("failed to write target to disk: %v", err)
if err := destroyer.Run(); err != nil {
log.Fatalf("destroy failed: %v", err)
os.Exit(1)
}

}

}
28 changes: 24 additions & 4 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ excludeDirs:
import:
- package: github.com/ghodss/yaml
version: 73d445a93680fa1a78ae23a5839bad48f32ba1ee
- package: github.com/Sirupsen/logrus
- package: github.com/sirupsen/logrus
version: 081307d9bc1364753142d5962fc1d795c742baaf
- package: gopkg.in/yaml.v2
version: 53feefa2559fb8dfa8d81baad31be332c97d6c77
Expand All @@ -28,6 +28,12 @@ import:
version: 1.6.2
- package: github.com/aws/aws-sdk-go
version: ^1.15.39
- package: github.com/libvirt/libvirt-go
version: ^v4.7.0
- package: github.com/openshift/hive
version: 296cb990171c6da62e134f3590c120bd16ef4d43
subpackages:
- contrib/pkg/aws_tag_deprovision
testImport:
- package: github.com/stretchr/testify
version: ^1.2.2
Expand Down
2 changes: 1 addition & 1 deletion installer/cmd/tectonic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//installer/pkg/workflow:go_default_library",
"//vendor/github.com/Sirupsen/logrus:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
"//vendor/gopkg.in/alecthomas/kingpin.v2:go_default_library",
],
)
Expand Down
2 changes: 1 addition & 1 deletion installer/cmd/tectonic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"os"

log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"

"github.com/openshift/installer/installer/pkg/workflow"
Expand Down
2 changes: 1 addition & 1 deletion installer/pkg/workflow/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ go_library(
"//installer/pkg/config-generator:go_default_library",
"//pkg/terraform:go_default_library",
"//pkg/types/config:go_default_library",
"//vendor/github.com/Sirupsen/logrus:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
"//vendor/gopkg.in/yaml.v2:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion installer/pkg/workflow/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"path/filepath"
"time"

log "github.com/Sirupsen/logrus"
"github.com/openshift/installer/pkg/terraform"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down
2 changes: 1 addition & 1 deletion installer/pkg/workflow/workflow.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package workflow

import (
log "github.com/Sirupsen/logrus"
"github.com/openshift/installer/pkg/types/config"
log "github.com/sirupsen/logrus"
)

// metadata is the state store of the current workflow execution.
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/AlecAivazis/survey:go_default_library",
"//vendor/github.com/Sirupsen/logrus:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
],
)

Expand Down
1 change: 1 addition & 0 deletions pkg/asset/cluster/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ go_library(
"//pkg/asset/kubeconfig:go_default_library",
"//pkg/terraform:go_default_library",
"//pkg/types/config:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
],
)
9 changes: 6 additions & 3 deletions pkg/asset/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

state, ok := parents[c.tfvars]
Expand All @@ -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
Expand All @@ -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.
log.Errorf("terraform failed: %v", err)
}

data, err := ioutil.ReadFile(stateFile)
Expand Down
18 changes: 18 additions & 0 deletions pkg/asset/metadata/BUILD.bazel
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",
],
)
2 changes: 2 additions & 0 deletions pkg/asset/metadata/doc.go
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
74 changes: 74 additions & 0 deletions pkg/asset/metadata/metadata.go
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
}
Loading

0 comments on commit d8844be

Please sign in to comment.