Skip to content

Commit

Permalink
Adding delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
luizbafilho committed Nov 25, 2020
1 parent c136af2 commit 140ceab
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
13 changes: 13 additions & 0 deletions lokustctl/cmd/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cmd

import "fmt"

func buildResourceName(testName string, resourceType ...string) string {
name := fmt.Sprintf("lokust-%s", testName)

if len(resourceType) > 1 {
name += "-" + resourceType[0]
}

return name
}
10 changes: 0 additions & 10 deletions lokustctl/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,6 @@ func buildConfigmapFromFile(filename string) (map[string]string, error) {
return configMapData, nil
}

func buildResourceName(testName string, resourceType ...string) string {
name := fmt.Sprintf("lokust-%s", testName)

if len(resourceType) > 1 {
name += "-" + resourceType[0]
}

return name
}

func ConvertToCoreV1ResourceList(resourceList map[string]string) corev1.ResourceList {
capacity := make(corev1.ResourceList)

Expand Down
38 changes: 29 additions & 9 deletions lokustctl/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,44 @@ limitations under the License.
package cmd

import (
"errors"
"fmt"
"os"

"github.com/spf13/cobra"
)

// deleteCmd represents the delete command
var deleteCmd = &cobra.Command{
Use: "delete",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("delete called")
Short: "Delete a lokust test",
Long: `Delete a lokust test by name
lokust delete [test-name]
`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("requires the locust test name")
}

return nil
},
Run: deleteRun,
}

func deleteRun(cmd *cobra.Command, args []string) {
testName := args[0]
err := kclientset.CoreV1().ConfigMaps(config.Namespace).Delete(buildResourceName(testName, "configmap"), nil)
if err != nil {
fmt.Printf("Failed deleting %s locustfile configmap. err: %s\n", testName, err)
os.Exit(1)
}

err = ltclientset.LoadtestsV1beta1().LocustTests(config.Namespace).Delete(testName, nil)
if err != nil {
fmt.Printf("Failed deleting %s test. err: %s\n", testName, err)
os.Exit(1)
}
}

func init() {
Expand Down

0 comments on commit 140ceab

Please # to comment.