Skip to content
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into feature/setdefaulttimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
bgokden authored May 2, 2019
2 parents b4da2bf + 91f5958 commit 2b79c05
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"reflect"
"testing"

"github.com/magneticio/forklift/logging"
"github.com/magneticio/vampkubistcli/client"
"github.com/magneticio/vampkubistcli/logging"
"gopkg.in/resty.v1"
)

Expand Down
39 changes: 35 additions & 4 deletions cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/json"
"errors"
"fmt"
"strconv"

"github.com/magneticio/vampkubistcli/client"
"github.com/magneticio/vampkubistcli/logging"
Expand All @@ -30,13 +31,14 @@ var Subset string
var Port string
var Destination string
var SubsetLabels map[string]string
var ReleaseType string

// releaseCmd represents the release command
var releaseCmd = &cobra.Command{
Use: "release",
Short: "Release a new subset with labels",
Long: AddAppName(`eg.:
$AppName release shop-vamp-service --destination shop-destination --port port --subset subset2 -l version=version2`),
$AppName release shop-vamp-service --destination shop-destination --port port --subset subset2 -l version=version2 --type time`),
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -45,15 +47,43 @@ $AppName release shop-vamp-service --destination shop-destination --port port --
}
Type := "canary_release"
VampService := args[0]
Name := VampService + "-" + Destination + "-" + Subset

policies := []models.PolicyReference{}

allowedReleaseTypes := map[string]string{"time": "TimedCanaryReleasePolicy", "health": "HealthBasedCanaryReleasePolicy"}

if ReleaseType != "" {

logging.Info("Release type is %v", allowedReleaseTypes[ReleaseType])

if allowedReleaseTypes[ReleaseType] == "" {
return errors.New("Release type is not valid")
}

policies = []models.PolicyReference{models.PolicyReference{
Name: allowedReleaseTypes[ReleaseType],
}}

}

var portReference *int

if Port != "" {
portInt, convErr := strconv.Atoi(Port)
if convErr != nil {
return convErr
}
portReference = &portInt
}

// fmt.Printf("%v %v %v\n", Type, Name, SubsetLabels)
canaryRelease := models.CanaryRelease{
VampService: VampService,
Destination: Destination,
Port: Port,
Port: portReference,
Subset: Subset,
SubsetLabels: SubsetLabels,
Policies: policies,
}
SourceRaw, marshallError := json.Marshal(canaryRelease)
if marshallError != nil {
Expand All @@ -68,7 +98,7 @@ $AppName release shop-vamp-service --destination shop-destination --port port --
values["cluster"] = Config.Cluster
values["virtual_cluster"] = Config.VirtualCluster
values["application"] = Application
isCreated, createError := restClient.Create(Type, Name, Source, SourceFileType, values)
isCreated, createError := restClient.Create(Type, VampService, Source, SourceFileType, values)
if !isCreated {
return createError
}
Expand All @@ -83,6 +113,7 @@ func init() {
releaseCmd.Flags().StringVarP(&Destination, "destination", "", "", "Destination to use in the release")
releaseCmd.Flags().StringVarP(&Port, "port", "", "", "Port to use in the release")
releaseCmd.Flags().StringVarP(&Subset, "subset", "", "", "Subset to use in the release")
releaseCmd.Flags().StringVarP(&ReleaseType, "type", "", "", "Type of canary release to use")
releaseCmd.Flags().StringToStringVarP(&SubsetLabels, "label", "l", map[string]string{}, "Subset labels, multiple labels are allowed")

}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var Hosts []string
var kubeConfigPath string

// version should be in format d.d.d where d is a decimal number
const Version string = "v0.0.24"
const Version string = "v0.0.25"

var AppName string = InitAppName()

Expand Down
8 changes: 7 additions & 1 deletion models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ type Weight struct {
type CanaryRelease struct {
VampService string `json:"vampService"`
Destination string `json:"destination,omitempty"`
Port string `json:"port,omitempty"`
Port *int `json:"port,omitempty"`
Subset string `json:"subset,omitempty"`
SubsetLabels map[string]string `json:"subsetLabels,omitempty"`
Policies []PolicyReference `json:"policies,omitempty"`
}

type PolicyReference struct {
Name string `json:"name,omitempty"`
Parameters map[string]string `json:"parameters,omitempty"`
}

0 comments on commit 2b79c05

Please sign in to comment.