From eeb5e972e62b1922ac32b28e12a4caaa7ccb3da0 Mon Sep 17 00:00:00 2001 From: Alessandro Valcepina Date: Thu, 2 May 2019 11:48:54 +0200 Subject: [PATCH 1/2] Allowed to specify the canary release type, also fixed port parsing in canary release --- client/client_test.go | 2 +- cmd/release.go | 39 +++++++++++++++++++++++++++++++++++---- models/models.go | 8 +++++++- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index 0042326..ce17e99 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -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" ) diff --git a/cmd/release.go b/cmd/release.go index a03c7c5..66e0cd9 100644 --- a/cmd/release.go +++ b/cmd/release.go @@ -18,6 +18,7 @@ import ( "encoding/json" "errors" "fmt" + "strconv" "github.com/magneticio/vampkubistcli/client" "github.com/magneticio/vampkubistcli/logging" @@ -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 { @@ -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 { @@ -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 } @@ -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") } diff --git a/models/models.go b/models/models.go index 7a7c31f..89de38d 100644 --- a/models/models.go +++ b/models/models.go @@ -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"` } From 629c730abb0c29224076cc69227b9cd6b1cbf585 Mon Sep 17 00:00:00 2001 From: Alessandro Valcepina Date: Thu, 2 May 2019 11:49:41 +0200 Subject: [PATCH 2/2] Increased version --- cmd/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index 90c4f42..052c6cc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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()