Skip to content
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

Return fatal #161

Merged
merged 3 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 7 additions & 11 deletions pkg/commands/cluster.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package commands

import (
"errors"
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -54,21 +52,21 @@ var clusterRecycleNodeCmd = &cobra.Command{
$ cloud-platform cluster recycle-node
`),
PreRun: upgradeIfNotLatest,
RunE: func(cmd *cobra.Command, args []string) error {
Run: func(cmd *cobra.Command, args []string) {
contextLogger := log.WithFields(log.Fields{"subcommand": "recycle-node"})
// Check for missing name argument. You must define either a resource
// or specify the --oldest flag.
if opt.ResourceName == "" && !opt.Oldest {
return errors.New("--name or --oldest is required")
contextLogger.Fatal("--name or --oldest is required")
}

if awsProfile == "" && awsAccessKey == "" && awsSecret == "" {
return errors.New("AWS credentials are required, please set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY or an AWS_PROFILE")
contextLogger.Fatal("AWS credentials are required, please set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY or an AWS_PROFILE")
}

clientset, err := client.GetClientset(opt.KubecfgPath)
if err != nil {
return err
contextLogger.Fatal(err)
}

recycle := &recycle.Recycler{
Expand All @@ -78,24 +76,22 @@ var clusterRecycleNodeCmd = &cobra.Command{

recycle.Cluster, err = cluster.NewCluster(recycle.Client)
if err != nil {
return fmt.Errorf("failed to get cluster: %s", err)
contextLogger.Fatal(err)
}

// Create a snapshot for comparison later.
recycle.Snapshot = recycle.Cluster.NewSnapshot()

recycle.AwsCreds, err = cluster.NewAwsCreds(opt.AwsRegion)
if err != nil {
return fmt.Errorf("failed to find credentials: %s", err)
contextLogger.Fatal(err)
}

err = recycle.Node()
if err != nil {
// Fail hard so we get an non-zero exit code.
// This is mainly for when this is run in a pipeline.
contextLogger.Error(err)
contextLogger.Fatal(err)
}

return nil
},
}
2 changes: 1 addition & 1 deletion pkg/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// This MUST match the number of the latest release on github
var Version = "1.14.5"
var Version = "1.14.6"

const owner = "ministryofjustice"
const repoName = "cloud-platform-cli"
Expand Down
2 changes: 2 additions & 0 deletions pkg/environment/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func TestGrepFile(t *testing.T) {
}

func TestMigrate(t *testing.T) {
// skip this test until the migrate command is decommissioned
t.Skip()
repoLocalPath := "./tmp/cloud-platform-environments"
repo := "https://github.com/ministryofjustice/cloud-platform-environments.git"

Expand Down