Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for maintenance windows #28

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading