Skip to content

Commit

Permalink
Merge pull request #161 from ministryofjustice/return-fatal
Browse files Browse the repository at this point in the history
Return fatal
  • Loading branch information
poornima-krishnasamy committed Mar 17, 2022
2 parents 5e87bca + 1eb08cf commit 20070c5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
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

0 comments on commit 20070c5

Please sign in to comment.