Skip to content

Commit 40be904

Browse files
author
Oleg Sucharevich
committed
fix endpiont to mark runtime as default
support in example cli
1 parent 5479620 commit 40be904

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.0
1+
0.8.1

cmd/create_runtime_environment.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"github.com/spf13/viper"
2525
)
2626

27+
var setDefault bool
28+
2729
// createRuntimeEnvironmentCmd represents the createRuntimeEnvironment command
2830
var createRuntimeEnvironmentCmd = &cobra.Command{
2931
Use: "runtime-environment",
@@ -44,6 +46,15 @@ var createRuntimeEnvironmentCmd = &cobra.Command{
4446
if err == nil {
4547
fmt.Printf("Runtime-Environment %s created\n", re.Metadata.Name)
4648
}
49+
50+
if setDefault {
51+
fmt.Printf("Setting runtime as default")
52+
_, err := codefreshClient.RuntimeEnvironments().Default(re.Metadata.Name)
53+
if err != nil {
54+
fmt.Printf("Error during setting runtime to be default: %s", err.Error())
55+
}
56+
fmt.Printf("Done")
57+
}
4758
},
4859
}
4960

@@ -54,4 +65,5 @@ func init() {
5465
createRuntimeEnvironmentCmd.Flags().String("namespace", "", "Set name of the namespace (required)")
5566
createRuntimeEnvironmentCmd.MarkFlagRequired("namespace")
5667
createRuntimeEnvironmentCmd.Flags().Bool("has-agent", false, "Set if the runtime environment is managed by Codefresh agent")
68+
createRuntimeEnvironmentCmd.Flags().BoolVar(&setDefault, "set-default", false, "Set the runtime as deault after creation")
5769
}

pkg/codefresh/runtime_enrionment.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (r *runtimeEnvironment) Delete(name string) (bool, error) {
204204
}
205205

206206
func (r *runtimeEnvironment) Default(name string) (bool, error) {
207-
path := fmt.Sprintf("/api/runtime-environments/%s/default", url.PathEscape(name))
207+
path := fmt.Sprintf("/api/runtime-environments/default/%s", url.PathEscape(name))
208208
resp, err := r.codefresh.requestAPI(&requestOptions{
209209
path: path,
210210
method: "PUT",
@@ -215,6 +215,10 @@ func (r *runtimeEnvironment) Default(name string) (bool, error) {
215215
if resp.StatusCode == 201 {
216216
return true, nil
217217
} else {
218-
return false, fmt.Errorf("Unknown error: %v", resp.Body)
218+
res, err := r.codefresh.getBodyAsString(resp)
219+
if err != nil {
220+
return false, err
221+
}
222+
return false, fmt.Errorf("Unknown error: %v", res)
219223
}
220224
}

0 commit comments

Comments
 (0)