Skip to content

Commit

Permalink
feat (ocean/gke): Added respectPdb field in clusterRoll under par…
Browse files Browse the repository at this point in the history
…ameters. (#239)
  • Loading branch information
sharadkesarwani authored Mar 20, 2023
1 parent 1539882 commit a5fcc53
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 8 deletions.
97 changes: 97 additions & 0 deletions examples/service/ocean/providers/gcp/create/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package main

import (
"context"
"github.com/spotinst/spotinst-sdk-go/service/ocean"
"github.com/spotinst/spotinst-sdk-go/service/ocean/providers/gcp"
"github.com/spotinst/spotinst-sdk-go/spotinst"
"github.com/spotinst/spotinst-sdk-go/spotinst/session"
"github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil"
"log"
)

func main() {
// All clients require a Session. The Session provides the client with
// shared configuration such as account and credentials.
// A Session should be shared where possible to take advantage of
// configuration and credential caching. See the session package for
// more information.
sess := session.New()

// Create a new instance of the service's client with a Session.
// Optional spotinst.Config values can also be provided as variadic
// arguments to the New function. This option allows you to provide
// service specific configuration.
svc := ocean.New(sess)

// Create a new context.
ctx := context.Background()

// Create a new cluster.
out, err := svc.CloudProviderGCP().CreateCluster(ctx, &gcp.CreateClusterInput{
Cluster: &gcp.Cluster{
Name: spotinst.String("foo"),
ControllerClusterID: spotinst.String("foo"),
Scheduling: &gcp.Scheduling{
Tasks: []*gcp.Task{
{
IsEnabled: spotinst.Bool(true),
Type: spotinst.String("clusterRoll"),
CronExpression: spotinst.String("0 1 * * *"),
Parameters: &gcp.Parameters{
ClusterRoll: &gcp.ClusterRoll{
BatchSizePercentage: spotinst.Int(20),
Comment: spotinst.String("reason for cluster roll"),
BatchMinHealthyPercentage: spotinst.Int(100),
RespectPdb: spotinst.Bool(true),
},
},
},
},
},
Capacity: &gcp.Capacity{
Minimum: spotinst.Int(0),
Maximum: spotinst.Int(1000),
Target: spotinst.Int(1),
},
Compute: &gcp.Compute{
SubnetName: spotinst.String("default"),
InstanceTypes: &gcp.InstanceTypes{
Whitelist: []string{"e2-micro"},
},
LaunchSpecification: &gcp.LaunchSpecification{
ServiceAccount: spotinst.String("serviceAccount"),
SourceImage: spotinst.String("sourceImage"),
Tags: []string{"tags"},
Metadata: []*gcp.Metadata{
{
Key: spotinst.String("key"),
Value: spotinst.String("true")},
},
},
NetworkInterfaces: []*gcp.NetworkInterface{
{
AccessConfigs: []*gcp.AccessConfig{
{
Name: spotinst.String("name"),
Type: spotinst.String("type"),
},
},
Network: spotinst.String("default"),
},
},
AvailabilityZones: []string{"us-east1-c"},
},
},
})
if err != nil {
log.Fatalf("spotinst: failed to create cluster: %v", err)
}

// Output.
if out.Cluster != nil {
log.Printf("Cluster %q: %s",
spotinst.StringValue(out.Cluster.ID),
stringutil.Stringify(out.Cluster))
}
}
83 changes: 75 additions & 8 deletions service/ocean/providers/gcp/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,27 @@ type ShutdownHours struct {
}

type Task struct {
IsEnabled *bool `json:"isEnabled,omitempty"`
Type *string `json:"taskType,omitempty"`
CronExpression *string `json:"cronExpression,omitempty"`
BatchSizePercentage *int `json:"batchSizePercentage,omitempty"`
IsEnabled *bool `json:"isEnabled,omitempty"`
Type *string `json:"taskType,omitempty"`
CronExpression *string `json:"cronExpression,omitempty"`
Parameters *Parameters `json:"parameters,omitempty"`

forceSendFields []string
nullFields []string
}

type Parameters struct {
ClusterRoll *ClusterRoll `json:"clusterRoll,omitempty"`

forceSendFields []string
nullFields []string
}

type ClusterRoll struct {
BatchMinHealthyPercentage *int `json:"batchMinHealthyPercentage,omitempty"`
BatchSizePercentage *int `json:"batchSizePercentage,omitempty"`
Comment *string `json:"comment,omitempty"`
RespectPdb *bool `json:"respectPdb,omitempty"`

forceSendFields []string
nullFields []string
Expand Down Expand Up @@ -798,10 +815,9 @@ func (o *Task) SetCronExpression(v *string) *Task {
}
return o
}

func (o *Task) SetBatchSizePercentage(v *int) *Task {
if o.BatchSizePercentage = v; o.BatchSizePercentage == nil {
o.nullFields = append(o.nullFields, "BatchSizePercentage")
func (o *Task) SetParameters(v *Parameters) *Task {
if o.Parameters = v; o.Parameters == nil {
o.nullFields = append(o.nullFields, "Parameters")
}
return o
}
Expand Down Expand Up @@ -1420,3 +1436,54 @@ func (o *LaunchSpecShieldedInstanceConfig) SetEnableSecureBoot(v *bool) *LaunchS
}

//endregion

//region cluster/scheduling/task/parameters

func (o *Parameters) SetClusterRoll(v *ClusterRoll) *Parameters {
if o.ClusterRoll = v; o.ClusterRoll == nil {
o.nullFields = append(o.nullFields, "RespectPdb")
}
return o
}
func (o Parameters) MarshalJSON() ([]byte, error) {
type noMethod Parameters
raw := noMethod(o)
return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields)
}

// endregion

//region cluster/scheduling/task/parameters/clusterRoll

func (o *ClusterRoll) SetBatchMinHealthyPercentage(v *int) *ClusterRoll {
if o.BatchMinHealthyPercentage = v; o.BatchMinHealthyPercentage == nil {
o.nullFields = append(o.nullFields, "BatchMinHealthyPercentage")
}
return o
}
func (o *ClusterRoll) SetBatchSizePercentage(v *int) *ClusterRoll {
if o.BatchSizePercentage = v; o.BatchSizePercentage == nil {
o.nullFields = append(o.nullFields, "BatchSizePercentage")
}
return o
}

func (o *ClusterRoll) SetComment(v *string) *ClusterRoll {
if o.Comment = v; o.Comment == nil {
o.nullFields = append(o.nullFields, "Comment")
}
return o
}
func (o *ClusterRoll) SetRespectPdb(v *bool) *ClusterRoll {
if o.RespectPdb = v; o.RespectPdb == nil {
o.nullFields = append(o.nullFields, "RespectPdb")
}
return o
}
func (o ClusterRoll) MarshalJSON() ([]byte, error) {
type noMethod ClusterRoll
raw := noMethod(o)
return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields)
}

// endregion

0 comments on commit a5fcc53

Please sign in to comment.