Skip to content

Commit

Permalink
[CLC-291] Add prerelease and development tags to create cluster (haze…
Browse files Browse the repository at this point in the history
…lcast#355)

Add prerelease and development tags to create cluster
  • Loading branch information
mtyazici authored Sep 4, 2023
1 parent f4a1883 commit 761876b
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 106 deletions.
7 changes: 7 additions & 0 deletions base/commands/viridian/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,10 @@ func fixClusterState(state string) string {
state = strings.Replace(state, "STOP", "PAUSE", 1)
return state
}

func ClusterType(isDev bool) string {
if isDev {
return "Development"
}
return "Production"
}
3 changes: 2 additions & 1 deletion base/commands/viridian/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ package viridian

const (
flagName = "name"
flagClusterType = "cluster-type"
flagPrerelease = "prerelease"
flagDevelopment = "development"
flagOutputDir = "output-dir"
flagHazelcastVersion = "hazelcast-version"
fmtSecretFileName = "%s-%s.secret"
Expand Down
15 changes: 12 additions & 3 deletions base/commands/viridian/viridian_cluster_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Make sure you login before running this command.
cc.SetPositionalArgCount(0, 0)
cc.AddStringFlag(propAPIKey, "", "", false, "Viridian API Key")
cc.AddStringFlag(flagName, "", "", false, "specify the cluster name; if not given an auto-generated name is used.")
cc.AddStringFlag(flagClusterType, "", viridian.ClusterTypeServerless, false, "type for the cluster")
cc.AddBoolFlag(flagDevelopment, "", false, false, "create a development cluster")
cc.AddBoolFlag(flagPrerelease, "", false, false, "create a prerelease cluster")
return nil
}

Expand All @@ -38,15 +39,16 @@ func (cm ClusterCreateCmd) Exec(ctx context.Context, ec plug.ExecContext) error
return err
}
name := ec.Props().GetString(flagName)
clusterType := ec.Props().GetString(flagClusterType)
dev := ec.Props().GetBool(flagDevelopment)
prerelease := ec.Props().GetBool(flagPrerelease)
hzVersion := ec.Props().GetString(flagHazelcastVersion)
csi, stop, err := ec.ExecuteBlocking(ctx, func(ctx context.Context, sp clc.Spinner) (any, error) {
sp.SetText("Creating the cluster")
k8sCluster, err := getFirstAvailableK8sCluster(ctx, api)
if err != nil {
return nil, err
}
cs, err := api.CreateCluster(ctx, name, clusterType, k8sCluster.ID, hzVersion)
cs, err := api.CreateCluster(ctx, name, getClusterType(dev), k8sCluster.ID, prerelease, hzVersion)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -89,6 +91,13 @@ func (cm ClusterCreateCmd) Exec(ctx context.Context, ec plug.ExecContext) error
return nil
}

func getClusterType(dev bool) string {
if dev {
return viridian.ClusterTypeDevMode
}
return viridian.ClusterTypeServerless
}

func getFirstAvailableK8sCluster(ctx context.Context, api *viridian.API) (viridian.K8sCluster, error) {
clusters, err := api.ListAvailableK8sClusters(ctx)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions base/commands/viridian/viridian_cluster_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func (cm ClusterGetCmd) Exec(ctx context.Context, ec plug.ExecContext) error {
Type: serialization.TypeStringArray,
Value: regionTitleSlice(c.Regions),
},
output.Column{
Name: "Cluster Type",
Type: serialization.TypeString,
Value: ClusterType(c.ClusterType.DevMode),
},
)
}
return ec.AddOutputRows(ctx, row)
Expand Down
10 changes: 10 additions & 0 deletions base/commands/viridian/viridian_cluster_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (cm ClusterListCmd) Exec(ctx context.Context, ec plug.ExecContext) error {
ec.PrintlnUnnecessary("No clusters found")
}
rows := make([]output.Row, len(cs))
verbose := ec.Props().GetBool(clc.PropertyVerbose)
for i, c := range cs {
rows[i] = output.Row{
output.Column{
Expand All @@ -73,6 +74,15 @@ func (cm ClusterListCmd) Exec(ctx context.Context, ec plug.ExecContext) error {
Value: c.HazelcastVersion,
},
}
if verbose {
rows[i] = append(rows[i],
output.Column{
Name: "Cluster Type",
Type: serialization.TypeString,
Value: ClusterType(c.ClusterType.DevMode),
},
)
}
}
return ec.AddOutputRows(ctx, rows...)
}
Expand Down
68 changes: 0 additions & 68 deletions base/commands/viridian/viridian_cluster_types.go

This file was deleted.

2 changes: 1 addition & 1 deletion base/commands/viridian/viridian_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func createCluster_InteractiveTest(t *testing.T) {
ensureNoClusterRunning(ctx, tcx)
tcx.WithReset(func() {
clusterName := it.UniqueClusterName()
tcx.WriteStdinf("\\viridian create-cluster --cluster-type devmode --verbose --name %s \n", clusterName)
tcx.WriteStdinf("\\viridian create-cluster --development --verbose --name %s \n", clusterName)
time.Sleep(10 * time.Second)
check.Must(waitState(ctx, tcx, "", "RUNNING"))
tcx.AssertStdoutContains(fmt.Sprintf("Imported configuration: %s", clusterName))
Expand Down
36 changes: 7 additions & 29 deletions docs/modules/ROOT/pages/clc-viridian.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ clc viridian [command] [options]
== Commands

* <<clc-viridian-login, clc viridian login>>
* <<clc-viridian-list-cluster-types, clc viridian list-cluster-types>>
* <<clc-viridian-create-cluster, clc viridian create-cluster>>
* <<clc-viridian-get-cluster, clc viridian get-cluster>>
* <<clc-viridian-list-clusters, clc viridian list-clusters>>
Expand Down Expand Up @@ -65,32 +64,6 @@ Parameters:

|===

== clc viridian list-cluster-types

Lists available cluster types that can be used while creating a {hazelcast-cloud} cluster.

Make sure you authenticate with the {hazelcast-cloud} API using `viridian login` before running this command.

Usage:

[source,bash]
----
clc viridian list-cluster-types [flags]
----

Parameters:

[cols="1m,1a,2a,1a"]
|===
|Parameter|Required|Description|Default

|`--api-key`
|Optional
|Sets the API key. Overrides the `CLC_VIRIDIAN_API_KEY` environment variable. If not given, one of the existing API keys will be used.
|

|===

== clc viridian create-cluster

Creates a {hazelcast-cloud} cluster.
Expand Down Expand Up @@ -120,9 +93,14 @@ Parameters:
|Sets the name of the created cluster. If not given, an auto-generated name will be used.
|

|`--cluster-type`
|`--development`
|Optional
|Creates a development cluster.
|

|`--prerelease`
|Optional
|Sets the cluster-type for the created cluster.
|Creates the cluster with a prerelease image.
|

|===
Expand Down
4 changes: 3 additions & 1 deletion internal/viridian/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ type createClusterRequest struct {
Name string `json:"name"`
ClusterTypeID int64 `json:"clusterTypeId"`
PlanName string `json:"planName"`
Prerelease bool `json:"preRelease"`
}

type createClusterResponse Cluster

func (a *API) CreateCluster(ctx context.Context, name string, clusterType string, k8sClusterID int, hzVersion string) (Cluster, error) {
func (a *API) CreateCluster(ctx context.Context, name string, clusterType string, k8sClusterID int, prerelease bool, hzVersion string) (Cluster, error) {
if name == "" {
name = clusterName()
}
Expand All @@ -41,6 +42,7 @@ func (a *API) CreateCluster(ctx context.Context, name string, clusterType string
Name: name,
ClusterTypeID: clusterTypeID,
PlanName: planName,
Prerelease: prerelease,
}
cluster, err := RetryOnAuthFail(ctx, a, func(ctx context.Context, token string) (Cluster, error) {
u := a.makeURL("/cluster")
Expand Down
7 changes: 4 additions & 3 deletions internal/viridian/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ type K8sCluster struct {
}

type ClusterType struct {
ID int64 `json:"id"`
Name string `json:"name"`
ID int64 `json:"id"`
Name string `json:"name"`
DevMode bool `json:"devMode"`
}

type Region struct {
Expand All @@ -48,5 +49,5 @@ type Region struct {
type IP struct {
ID int `json:"id"`
IP string `json:"ip"`
Description string `json:"description",omitempty`
Description string `json:"description,omitempty"`
}

0 comments on commit 761876b

Please sign in to comment.