Skip to content

Commit

Permalink
feat: add support for maintenance windows (#28)
Browse files Browse the repository at this point in the history
* feat: add support for maintenance windows

* chore(deps): update module github.com/go-resty/resty/v2 to v2.15.2
# Conflicts:
#	go.sum

* chore: go mod tidy

* chore(deps): update module github.com/go-resty/resty/v2 to v2.15.2
# Conflicts:
#	go.sum

* feat(cluster): add maintenanceScheduleIdentity

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
idebeijer and renovate[bot] authored Sep 24, 2024
1 parent 875ab6a commit 17cc873
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,6 @@ vendor
.idea

# Golang
.netrc
.netrc

go-client
3 changes: 3 additions & 0 deletions pkg/acloudapi/apitypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ type CreateCluster struct {
NodePools []NodePools `json:"nodePools" yaml:"NodePools"`
IPWhitelist []IPWhitelistEntry `json:"ipWhitelist,omitempty" yaml:"IpWhitelist,omitempty"`
Addons map[string]APIAddon `json:"addons,omitempty" yaml:"Addons,omitempty"`

MaintenanceScheduleIdentity string `json:"maintenanceScheduleIdentity,omitempty" yaml:"MaintenanceScheduleIdentity,omitempty"`
}

// IPWhitelistEntry represents an entry in the IP whitelist.
Expand All @@ -176,6 +178,7 @@ type UpdateCluster struct {
DeleteProtection *bool `json:"deleteProtection,omitempty" yaml:"DeleteProtection,omitempty"`
IPWhitelist []string `json:"ipWhitelist,omitempty" yaml:"IpWhitelist,omitempty"`
Addons map[string]APIAddon `json:"addons,omitempty" yaml:"Addons,omitempty"`
MaintenanceScheduleIdentity *string `json:"maintenanceScheduleIdentity,omitempty" yaml:"MaintenanceScheduleIdentity,omitempty"`
}

// NodePools is used by CreateCluster
Expand Down
9 changes: 9 additions & 0 deletions pkg/acloudapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ type UserAPI interface {
AddUser(ctx context.Context) (AddUserResponse, error)
}

type MaintenanceAPI interface {
GetMaintenanceSchedules(ctx context.Context, org string) ([]MaintenanceSchedule, error)
GetMaintenanceSchedule(ctx context.Context, org, maintenanceScheduleID string) (*MaintenanceSchedule, error)
CreateMaintenanceSchedule(ctx context.Context, org string, createMaintenanceSchedule CreateMaintenanceSchedule) (*MaintenanceSchedule, error)
DeleteMaintenanceSchedule(ctx context.Context, org, maintenanceScheduleID string) error
UpdateMaintenanceSchedule(ctx context.Context, org, maintenanceScheduleID string, updateMaintenanceSchedule UpdateMaintenanceSchedule) (*MaintenanceSchedule, error)
}

type Client interface {
CloudAccountAPI
CloudProvidersAPI
Expand All @@ -110,6 +118,7 @@ type Client interface {
OrganisationAPI
CloudAccountsAPI
UserAPI
MaintenanceAPI

Resty() *resty.Client
}
Expand Down
77 changes: 77 additions & 0 deletions pkg/acloudapi/maintenanceschedules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package acloudapi

import (
"context"
"fmt"
)

func (c *clientImpl) GetMaintenanceSchedules(ctx context.Context, org string) ([]MaintenanceSchedule, error) {
var result []MaintenanceSchedule
response, err := c.R().
SetContext(ctx).
SetResult(&result).
Get(fmt.Sprintf("/api/v1/organisations/%s/maintenance-schedule", org))
if err := c.CheckResponse(response, err); err != nil {
return nil, err
}
return result, nil
}

func (c *clientImpl) GetMaintenanceSchedule(ctx context.Context, org, maintenanceScheduleID string) (*MaintenanceSchedule, error) {
maintenanceSchedule := MaintenanceSchedule{}
response, err := c.R().
SetContext(ctx).
SetResult(&maintenanceSchedule).
Get(fmt.Sprintf("/api/v1/organisations/%s/maintenance-schedule/%s", org, maintenanceScheduleID))
if err := c.CheckResponse(response, err); err != nil {
return nil, err
}
return &maintenanceSchedule, nil
}

type CreateMaintenanceSchedule struct {
Name string `json:"name"`
Windows []MaintenanceWindow `json:"windows"`
}

func (c *clientImpl) CreateMaintenanceSchedule(ctx context.Context, org string, createMaintenanceSchedule CreateMaintenanceSchedule) (*MaintenanceSchedule, error) {
maintenanceSchedule := MaintenanceSchedule{}
response, err := c.R().
SetContext(ctx).
SetResult(&maintenanceSchedule).
SetBody(&createMaintenanceSchedule).
Post(fmt.Sprintf("/api/v1/organisations/%s/maintenance-schedule", org))

if err := c.CheckResponse(response, err); err != nil {
return nil, err
}
return &maintenanceSchedule, nil
}

func (c *clientImpl) DeleteMaintenanceSchedule(ctx context.Context, org, maintenanceScheduleID string) error {
response, err := c.R().
SetContext(ctx).
Delete(fmt.Sprintf("/api/v1/organisations/%s/maintenance-schedule/%s", org, maintenanceScheduleID))
if err := c.CheckResponse(response, err); err != nil {
return err
}
return nil
}

type UpdateMaintenanceSchedule struct {
Name string `json:"name"`
Windows []MaintenanceWindow `json:"windows"`
}

func (c *clientImpl) UpdateMaintenanceSchedule(ctx context.Context, org, maintenanceScheduleID string, updateMaintenanceSchedule UpdateMaintenanceSchedule) (*MaintenanceSchedule, error) {
maintenanceSchedule := MaintenanceSchedule{}
response, err := c.R().
SetContext(ctx).
SetResult(&maintenanceSchedule).
SetBody(&updateMaintenanceSchedule).
Patch(fmt.Sprintf("/api/v1/organisations/%s/maintenance-schedule/%s", org, maintenanceScheduleID))
if err := c.CheckResponse(response, err); err != nil {
return nil, err
}
return &maintenanceSchedule, nil
}

0 comments on commit 17cc873

Please sign in to comment.