From 288ce6c2996fc598eb3ad57464b37f1cb7d7e691 Mon Sep 17 00:00:00 2001 From: scaleway-bot Date: Thu, 19 Dec 2019 16:20:04 +0000 Subject: [PATCH] feat: update generated apis --- api/baremetal/v1alpha1/baremetal_sdk.go | 880 ++++++++++- api/instance/v1/instance_sdk.go | 97 +- api/k8s/v1beta3/k8s_sdk.go | 2 + api/k8s/v1beta4/k8s_sdk.go | 1914 +++++++++++++++++++++++ api/lb/v1/lb_sdk.go | 500 +++++- api/test/v1/test_sdk.go | 18 + 6 files changed, 3215 insertions(+), 196 deletions(-) create mode 100644 api/k8s/v1beta4/k8s_sdk.go diff --git a/api/baremetal/v1alpha1/baremetal_sdk.go b/api/baremetal/v1alpha1/baremetal_sdk.go index 2c73ee1ca..1f92993e7 100644 --- a/api/baremetal/v1alpha1/baremetal_sdk.go +++ b/api/baremetal/v1alpha1/baremetal_sdk.go @@ -49,6 +49,126 @@ func NewAPI(client *scw.Client) *API { } } +type IPFailoverEventAction string + +const ( + // IPFailoverEventActionUnknown is [insert doc]. + IPFailoverEventActionUnknown = IPFailoverEventAction("unknown") + // IPFailoverEventActionBillingStart is [insert doc]. + IPFailoverEventActionBillingStart = IPFailoverEventAction("billing_start") + // IPFailoverEventActionBillingStop is [insert doc]. + IPFailoverEventActionBillingStop = IPFailoverEventAction("billing_stop") + // IPFailoverEventActionOrderFail is [insert doc]. + IPFailoverEventActionOrderFail = IPFailoverEventAction("order_fail") + // IPFailoverEventActionUpdateIP is [insert doc]. + IPFailoverEventActionUpdateIP = IPFailoverEventAction("update_ip") + // IPFailoverEventActionUpdateIPFail is [insert doc]. + IPFailoverEventActionUpdateIPFail = IPFailoverEventAction("update_ip_fail") +) + +func (enum IPFailoverEventAction) String() string { + if enum == "" { + // return default value if empty + return "unknown" + } + return string(enum) +} + +func (enum IPFailoverEventAction) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *IPFailoverEventAction) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = IPFailoverEventAction(IPFailoverEventAction(tmp).String()) + return nil +} + +type IPFailoverMACType string + +const ( + // IPFailoverMACTypeUnknownMacType is [insert doc]. + IPFailoverMACTypeUnknownMacType = IPFailoverMACType("unknown_mac_type") + // IPFailoverMACTypeNone is [insert doc]. + IPFailoverMACTypeNone = IPFailoverMACType("none") + // IPFailoverMACTypeDuplicate is [insert doc]. + IPFailoverMACTypeDuplicate = IPFailoverMACType("duplicate") + // IPFailoverMACTypeVmware is [insert doc]. + IPFailoverMACTypeVmware = IPFailoverMACType("vmware") + // IPFailoverMACTypeXen is [insert doc]. + IPFailoverMACTypeXen = IPFailoverMACType("xen") + // IPFailoverMACTypeKvm is [insert doc]. + IPFailoverMACTypeKvm = IPFailoverMACType("kvm") +) + +func (enum IPFailoverMACType) String() string { + if enum == "" { + // return default value if empty + return "unknown_mac_type" + } + return string(enum) +} + +func (enum IPFailoverMACType) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *IPFailoverMACType) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = IPFailoverMACType(IPFailoverMACType(tmp).String()) + return nil +} + +type IPFailoverStatus string + +const ( + // IPFailoverStatusUnknown is [insert doc]. + IPFailoverStatusUnknown = IPFailoverStatus("unknown") + // IPFailoverStatusDelivering is [insert doc]. + IPFailoverStatusDelivering = IPFailoverStatus("delivering") + // IPFailoverStatusReady is [insert doc]. + IPFailoverStatusReady = IPFailoverStatus("ready") + // IPFailoverStatusUpdating is [insert doc]. + IPFailoverStatusUpdating = IPFailoverStatus("updating") + // IPFailoverStatusError is [insert doc]. + IPFailoverStatusError = IPFailoverStatus("error") + // IPFailoverStatusDeleting is [insert doc]. + IPFailoverStatusDeleting = IPFailoverStatus("deleting") +) + +func (enum IPFailoverStatus) String() string { + if enum == "" { + // return default value if empty + return "unknown" + } + return string(enum) +} + +func (enum IPFailoverStatus) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *IPFailoverStatus) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = IPFailoverStatus(IPFailoverStatus(tmp).String()) + return nil +} + type IPReverseStatus string const ( @@ -117,6 +237,70 @@ func (enum *IPVersion) UnmarshalJSON(data []byte) error { return nil } +type ListIPFailoverEventsRequestOrderBy string + +const ( + // ListIPFailoverEventsRequestOrderByCreatedAtAsc is [insert doc]. + ListIPFailoverEventsRequestOrderByCreatedAtAsc = ListIPFailoverEventsRequestOrderBy("created_at_asc") + // ListIPFailoverEventsRequestOrderByCreatedAtDesc is [insert doc]. + ListIPFailoverEventsRequestOrderByCreatedAtDesc = ListIPFailoverEventsRequestOrderBy("created_at_desc") +) + +func (enum ListIPFailoverEventsRequestOrderBy) String() string { + if enum == "" { + // return default value if empty + return "created_at_asc" + } + return string(enum) +} + +func (enum ListIPFailoverEventsRequestOrderBy) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *ListIPFailoverEventsRequestOrderBy) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = ListIPFailoverEventsRequestOrderBy(ListIPFailoverEventsRequestOrderBy(tmp).String()) + return nil +} + +type ListIPFailoversRequestOrderBy string + +const ( + // ListIPFailoversRequestOrderByCreatedAtAsc is [insert doc]. + ListIPFailoversRequestOrderByCreatedAtAsc = ListIPFailoversRequestOrderBy("created_at_asc") + // ListIPFailoversRequestOrderByCreatedAtDesc is [insert doc]. + ListIPFailoversRequestOrderByCreatedAtDesc = ListIPFailoversRequestOrderBy("created_at_desc") +) + +func (enum ListIPFailoversRequestOrderBy) String() string { + if enum == "" { + // return default value if empty + return "created_at_asc" + } + return string(enum) +} + +func (enum ListIPFailoversRequestOrderBy) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *ListIPFailoversRequestOrderBy) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = ListIPFailoversRequestOrderBy(ListIPFailoversRequestOrderBy(tmp).String()) + return nil +} + type ListServerEventsRequestOrderBy string const ( @@ -363,6 +547,12 @@ func (enum *ServerStatus) UnmarshalJSON(data []byte) error { return nil } +// AttachIPFailoversResponse attach ip failovers response +type AttachIPFailoversResponse struct { + // Failovers list of the attached IP failovers + Failovers []*IPFailover `json:"failovers"` +} + // CPU cpu type CPU struct { // Name name of the CPU @@ -375,6 +565,12 @@ type CPU struct { Frequency uint32 `json:"frequency"` } +// DetachIPFailoversResponse detach ip failovers response +type DetachIPFailoversResponse struct { + // Failovers list of the detached IP failovers + Failovers []*IPFailover `json:"failovers"` +} + // Disk disk type Disk struct { // Capacity capacity of the disk in GB @@ -403,6 +599,74 @@ type IP struct { ReverseStatusMessage *string `json:"reverse_status_message"` } +// IPFailover ip failover +type IPFailover struct { + // ID iD of the IP failover + ID string `json:"id"` + // OrganizationID organization ID the IP failover is attached to + OrganizationID string `json:"organization_id"` + // Description description of the IP failover + Description string `json:"description"` + // Tags tags associated to the IP failover + Tags []string `json:"tags"` + // UpdatedAt date of last update of the IP failover + UpdatedAt time.Time `json:"updated_at"` + // CreatedAt date of creation of the IP failover + CreatedAt time.Time `json:"created_at"` + // Status status of the IP failover + // + // Default value: unknown + Status IPFailoverStatus `json:"status"` + // IPAddress iP of the IP failover + IPAddress net.IP `json:"ip_address"` + // MacAddress mac address of the IP failover + MacAddress string `json:"mac_address"` + // ServerID serverID linked to the IP failover + ServerID string `json:"server_id"` + // MacType type of the MAC generated of the IP failover + // + // Default value: unknown_mac_type + MacType IPFailoverMACType `json:"mac_type"` + // Reverse reverse IP value + Reverse string `json:"reverse"` + // ReverseStatus status of the reverse + // + // Default value: unknown + ReverseStatus IPReverseStatus `json:"reverse_status"` + // ReverseStatusMessage a message related to the reverse status, in case of an error for example + ReverseStatusMessage *string `json:"reverse_status_message"` +} + +// IPFailoverEvent ip failover event +type IPFailoverEvent struct { + // ID iD of the IP failover for whom the action will be applied + ID string `json:"id"` + // Action the action that will be applied to the IP failover + // + // Default value: unknown + Action IPFailoverEventAction `json:"action"` + // UpdatedAt date of last modification of the action + UpdatedAt time.Time `json:"updated_at"` + // CreatedAt date of creation of the action + CreatedAt time.Time `json:"created_at"` +} + +// ListIPFailoverEventsResponse list ip failover events response +type ListIPFailoverEventsResponse struct { + // TotalCount total count of matching IP failover events + TotalCount uint32 `json:"total_count"` + // Event iP failover events that match filters + Event []*IPFailoverEvent `json:"event"` +} + +// ListIPFailoversResponse list ip failovers response +type ListIPFailoversResponse struct { + // TotalCount total count of matching IP failovers + TotalCount uint32 `json:"total_count"` + // Failovers listing of failovers + Failovers []*IPFailover `json:"failovers"` +} + // ListOffersResponse list offers response type ListOffersResponse struct { // TotalCount total count of matching offers @@ -580,6 +844,8 @@ type ListServersRequest struct { Status []string `json:"-"` // Name filter servers by name Name *string `json:"-"` + // OrganizationID filter servers by organization ID + OrganizationID *string `json:"-"` } // ListServers list servers @@ -605,6 +871,7 @@ func (s *API) ListServers(req *ListServersRequest, opts ...scw.RequestOption) (* parameter.AddToQuery(query, "tags", req.Tags) parameter.AddToQuery(query, "status", req.Status) parameter.AddToQuery(query, "name", req.Name) + parameter.AddToQuery(query, "organization_id", req.OrganizationID) if fmt.Sprint(req.Zone) == "" { return nil, errors.New("field Zone cannot be empty in request") @@ -1278,46 +1545,54 @@ func (s *API) UpdateIP(req *UpdateIPRequest, opts ...scw.RequestOption) (*IP, er return &resp, nil } -type ListOffersRequest struct { +type CreateIPFailoverRequest struct { Zone scw.Zone `json:"-"` - // Page page number - Page *int32 `json:"-"` - // PageSize number of offers per page - PageSize *uint32 `json:"-"` + // OrganizationID iD of the organization to associate to the IP failover + OrganizationID string `json:"organization_id"` + // Description description to associate to the IP failover, max 255 characters + Description string `json:"description"` + // Tags tags to associate to the IP failover + Tags []string `json:"tags"` + // MacType mAC type to use for the IP failover + // + // Default value: unknown_mac_type + MacType IPFailoverMACType `json:"mac_type"` + // DuplicateMacFrom iD of the IP failover which must be duplicate + DuplicateMacFrom *string `json:"duplicate_mac_from"` } -// ListOffers list offers +// CreateIPFailover create IP failover // -// List all available server offers. -func (s *API) ListOffers(req *ListOffersRequest, opts ...scw.RequestOption) (*ListOffersResponse, error) { +// Create an IP failover. Once the IP failover is created, you probably want to attach it to a server. +func (s *API) CreateIPFailover(req *CreateIPFailoverRequest, opts ...scw.RequestOption) (*IPFailover, error) { var err error + if req.OrganizationID == "" { + defaultOrganizationID, _ := s.client.GetDefaultOrganizationID() + req.OrganizationID = defaultOrganizationID + } + if req.Zone == "" { defaultZone, _ := s.client.GetDefaultZone() req.Zone = defaultZone } - defaultPageSize, exist := s.client.GetDefaultPageSize() - if (req.PageSize == nil || *req.PageSize == 0) && exist { - req.PageSize = &defaultPageSize - } - - query := url.Values{} - parameter.AddToQuery(query, "page", req.Page) - parameter.AddToQuery(query, "page_size", req.PageSize) - if fmt.Sprint(req.Zone) == "" { return nil, errors.New("field Zone cannot be empty in request") } scwReq := &scw.ScalewayRequest{ - Method: "GET", - Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/offers", - Query: query, + Method: "POST", + Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/ip-failovers", Headers: http.Header{}, } - var resp ListOffersResponse + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp IPFailover err = s.client.Do(scwReq, &resp, opts...) if err != nil { @@ -1326,37 +1601,70 @@ func (s *API) ListOffers(req *ListOffersRequest, opts ...scw.RequestOption) (*Li return &resp, nil } -// UnsafeGetTotalCount should not be used -// Internal usage only -func (r *ListOffersResponse) UnsafeGetTotalCount() uint32 { - return r.TotalCount +type GetIPFailoverRequest struct { + Zone scw.Zone `json:"-"` + // IPFailoverID iD of the IP failover + IPFailoverID string `json:"-"` } -// UnsafeAppend should not be used -// Internal usage only -func (r *ListOffersResponse) UnsafeAppend(res interface{}) (uint32, error) { - results, ok := res.(*ListOffersResponse) - if !ok { - return 0, errors.New("%T type cannot be appended to type %T", res, r) +// GetIPFailover get IP failover +// +// Get the IP failover associated with the given ID. +func (s *API) GetIPFailover(req *GetIPFailoverRequest, opts ...scw.RequestOption) (*IPFailover, error) { + var err error + + if req.Zone == "" { + defaultZone, _ := s.client.GetDefaultZone() + req.Zone = defaultZone } - r.Offers = append(r.Offers, results.Offers...) - r.TotalCount += uint32(len(results.Offers)) - return uint32(len(results.Offers)), nil + if fmt.Sprint(req.Zone) == "" { + return nil, errors.New("field Zone cannot be empty in request") + } + + if fmt.Sprint(req.IPFailoverID) == "" { + return nil, errors.New("field IPFailoverID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/ip-failovers/" + fmt.Sprint(req.IPFailoverID) + "", + Headers: http.Header{}, + } + + var resp IPFailover + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil } -type ListOsRequest struct { +type ListIPFailoversRequest struct { Zone scw.Zone `json:"-"` // Page page number Page *int32 `json:"-"` - // PageSize number of OS per page + // PageSize number of IP failover per page PageSize *uint32 `json:"-"` + // OrderBy order of the IP failovers + // + // Default value: created_at_asc + OrderBy ListIPFailoversRequestOrderBy `json:"-"` + // Tags filter IP failovers by tags + Tags []string `json:"-"` + // Status filter IP failovers by status + Status []string `json:"-"` + // ServerIDs filter IP failovers by server IDs + ServerIDs []string `json:"-"` + // OrganizationID filter servers by organization ID + OrganizationID *string `json:"-"` } -// ListOs list OS +// ListIPFailovers list IP failovers // -// List all available OS that can be install on a baremetal server. -func (s *API) ListOs(req *ListOsRequest, opts ...scw.RequestOption) (*ListOsResponse, error) { +// List all created IP failovers. +func (s *API) ListIPFailovers(req *ListIPFailoversRequest, opts ...scw.RequestOption) (*ListIPFailoversResponse, error) { var err error if req.Zone == "" { @@ -1372,6 +1680,11 @@ func (s *API) ListOs(req *ListOsRequest, opts ...scw.RequestOption) (*ListOsResp query := url.Values{} parameter.AddToQuery(query, "page", req.Page) parameter.AddToQuery(query, "page_size", req.PageSize) + parameter.AddToQuery(query, "order_by", req.OrderBy) + parameter.AddToQuery(query, "tags", req.Tags) + parameter.AddToQuery(query, "status", req.Status) + parameter.AddToQuery(query, "server_ids", req.ServerIDs) + parameter.AddToQuery(query, "organization_id", req.OrganizationID) if fmt.Sprint(req.Zone) == "" { return nil, errors.New("field Zone cannot be empty in request") @@ -1379,12 +1692,12 @@ func (s *API) ListOs(req *ListOsRequest, opts ...scw.RequestOption) (*ListOsResp scwReq := &scw.ScalewayRequest{ Method: "GET", - Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/os", + Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/ip-failovers", Query: query, Headers: http.Header{}, } - var resp ListOsResponse + var resp ListIPFailoversResponse err = s.client.Do(scwReq, &resp, opts...) if err != nil { @@ -1395,19 +1708,492 @@ func (s *API) ListOs(req *ListOsRequest, opts ...scw.RequestOption) (*ListOsResp // UnsafeGetTotalCount should not be used // Internal usage only -func (r *ListOsResponse) UnsafeGetTotalCount() uint32 { +func (r *ListIPFailoversResponse) UnsafeGetTotalCount() uint32 { return r.TotalCount } // UnsafeAppend should not be used // Internal usage only -func (r *ListOsResponse) UnsafeAppend(res interface{}) (uint32, error) { - results, ok := res.(*ListOsResponse) +func (r *ListIPFailoversResponse) UnsafeAppend(res interface{}) (uint32, error) { + results, ok := res.(*ListIPFailoversResponse) if !ok { return 0, errors.New("%T type cannot be appended to type %T", res, r) } - r.Os = append(r.Os, results.Os...) - r.TotalCount += uint32(len(results.Os)) - return uint32(len(results.Os)), nil + r.Failovers = append(r.Failovers, results.Failovers...) + r.TotalCount += uint32(len(results.Failovers)) + return uint32(len(results.Failovers)), nil +} + +type DeleteIPFailoverRequest struct { + Zone scw.Zone `json:"-"` + // IPFailoverID iD of the IP failover to delete + IPFailoverID string `json:"-"` +} + +// DeleteIPFailover delete IP failover +// +// Delete the IP failover associated with the given IP. +func (s *API) DeleteIPFailover(req *DeleteIPFailoverRequest, opts ...scw.RequestOption) (*IPFailover, error) { + var err error + + if req.Zone == "" { + defaultZone, _ := s.client.GetDefaultZone() + req.Zone = defaultZone + } + + if fmt.Sprint(req.Zone) == "" { + return nil, errors.New("field Zone cannot be empty in request") + } + + if fmt.Sprint(req.IPFailoverID) == "" { + return nil, errors.New("field IPFailoverID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "DELETE", + Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/ip-failovers/" + fmt.Sprint(req.IPFailoverID) + "", + Headers: http.Header{}, + } + + var resp IPFailover + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type UpdateIPFailoverRequest struct { + Zone scw.Zone `json:"-"` + // IPFailoverID iD of the IP failover to update + IPFailoverID string `json:"-"` + // Description description to associate to the IP failover, max 255 characters, not updated if null + Description *string `json:"description"` + // Tags tags to associate to the IP failover, not updated if null + Tags *[]string `json:"tags"` + // MacType mAC type to use for the IP failover, not updated if null + // + // Default value: unknown_mac_type + MacType IPFailoverMACType `json:"mac_type"` + // DuplicateMacFrom iD of the IP failover which must be duplicate, not updated if null + DuplicateMacFrom *string `json:"duplicate_mac_from"` + // Reverse new reverse IP to update, not updated if null + Reverse *string `json:"reverse"` +} + +// UpdateIPFailover update IP failover +// +// Update the IP failover associated with the given IP. +func (s *API) UpdateIPFailover(req *UpdateIPFailoverRequest, opts ...scw.RequestOption) (*IPFailover, error) { + var err error + + if req.Zone == "" { + defaultZone, _ := s.client.GetDefaultZone() + req.Zone = defaultZone + } + + if fmt.Sprint(req.Zone) == "" { + return nil, errors.New("field Zone cannot be empty in request") + } + + if fmt.Sprint(req.IPFailoverID) == "" { + return nil, errors.New("field IPFailoverID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "PATCH", + Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/ip-failovers/" + fmt.Sprint(req.IPFailoverID) + "", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp IPFailover + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type AttachIPFailoversRequest struct { + Zone scw.Zone `json:"-"` + // IPFailoverIDs iP failover IDs to attach to the server + IPFailoverIDs []string `json:"ip_failover_ids"` + // ServerID iD of the server to attach to the IP failovers + ServerID string `json:"server_id"` +} + +// AttachIPFailovers attach IP failovers +// +// Attach IP failovers to the given server ID. +func (s *API) AttachIPFailovers(req *AttachIPFailoversRequest, opts ...scw.RequestOption) (*AttachIPFailoversResponse, error) { + var err error + + if req.Zone == "" { + defaultZone, _ := s.client.GetDefaultZone() + req.Zone = defaultZone + } + + if fmt.Sprint(req.Zone) == "" { + return nil, errors.New("field Zone cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/ip-failovers/attach", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp AttachIPFailoversResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type DetachIPFailoversRequest struct { + Zone scw.Zone `json:"-"` + // IPFailoverIDs iP failover IDs to detach to the server + IPFailoverIDs []string `json:"ip_failover_ids"` +} + +// DetachIPFailovers detach IP failovers +// +// Detach IP failovers to the given server ID. +func (s *API) DetachIPFailovers(req *DetachIPFailoversRequest, opts ...scw.RequestOption) (*DetachIPFailoversResponse, error) { + var err error + + if req.Zone == "" { + defaultZone, _ := s.client.GetDefaultZone() + req.Zone = defaultZone + } + + if fmt.Sprint(req.Zone) == "" { + return nil, errors.New("field Zone cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/ip-failovers/detach", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp DetachIPFailoversResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type ListIPFailoverEventsRequest struct { + Zone scw.Zone `json:"-"` + // IPFailoverID iD of the IP failover events searched + IPFailoverID string `json:"-"` + // Page page number + Page *int32 `json:"-"` + // PageSize number of IP failover events per page + PageSize *uint32 `json:"-"` + // OrderBy order of the IP failover events + // + // Default value: created_at_asc + OrderBy ListIPFailoverEventsRequestOrderBy `json:"-"` +} + +// ListIPFailoverEvents list IP failover events +// +// List IP failover events associated with the given ID. +func (s *API) ListIPFailoverEvents(req *ListIPFailoverEventsRequest, opts ...scw.RequestOption) (*ListIPFailoverEventsResponse, error) { + var err error + + if req.Zone == "" { + defaultZone, _ := s.client.GetDefaultZone() + req.Zone = defaultZone + } + + defaultPageSize, exist := s.client.GetDefaultPageSize() + if (req.PageSize == nil || *req.PageSize == 0) && exist { + req.PageSize = &defaultPageSize + } + + query := url.Values{} + parameter.AddToQuery(query, "page", req.Page) + parameter.AddToQuery(query, "page_size", req.PageSize) + parameter.AddToQuery(query, "order_by", req.OrderBy) + + if fmt.Sprint(req.Zone) == "" { + return nil, errors.New("field Zone cannot be empty in request") + } + + if fmt.Sprint(req.IPFailoverID) == "" { + return nil, errors.New("field IPFailoverID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/ip-failovers/" + fmt.Sprint(req.IPFailoverID) + "/events", + Query: query, + Headers: http.Header{}, + } + + var resp ListIPFailoverEventsResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// UnsafeGetTotalCount should not be used +// Internal usage only +func (r *ListIPFailoverEventsResponse) UnsafeGetTotalCount() uint32 { + return r.TotalCount +} + +// UnsafeAppend should not be used +// Internal usage only +func (r *ListIPFailoverEventsResponse) UnsafeAppend(res interface{}) (uint32, error) { + results, ok := res.(*ListIPFailoverEventsResponse) + if !ok { + return 0, errors.New("%T type cannot be appended to type %T", res, r) + } + + r.Event = append(r.Event, results.Event...) + r.TotalCount += uint32(len(results.Event)) + return uint32(len(results.Event)), nil +} + +type ListOffersRequest struct { + Zone scw.Zone `json:"-"` + // Page page number + Page *int32 `json:"-"` + // PageSize number of offers per page + PageSize *uint32 `json:"-"` +} + +// ListOffers list offers +// +// List all available server offers. +func (s *API) ListOffers(req *ListOffersRequest, opts ...scw.RequestOption) (*ListOffersResponse, error) { + var err error + + if req.Zone == "" { + defaultZone, _ := s.client.GetDefaultZone() + req.Zone = defaultZone + } + + defaultPageSize, exist := s.client.GetDefaultPageSize() + if (req.PageSize == nil || *req.PageSize == 0) && exist { + req.PageSize = &defaultPageSize + } + + query := url.Values{} + parameter.AddToQuery(query, "page", req.Page) + parameter.AddToQuery(query, "page_size", req.PageSize) + + if fmt.Sprint(req.Zone) == "" { + return nil, errors.New("field Zone cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/offers", + Query: query, + Headers: http.Header{}, + } + + var resp ListOffersResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// UnsafeGetTotalCount should not be used +// Internal usage only +func (r *ListOffersResponse) UnsafeGetTotalCount() uint32 { + return r.TotalCount +} + +// UnsafeAppend should not be used +// Internal usage only +func (r *ListOffersResponse) UnsafeAppend(res interface{}) (uint32, error) { + results, ok := res.(*ListOffersResponse) + if !ok { + return 0, errors.New("%T type cannot be appended to type %T", res, r) + } + + r.Offers = append(r.Offers, results.Offers...) + r.TotalCount += uint32(len(results.Offers)) + return uint32(len(results.Offers)), nil +} + +type GetOfferRequest struct { + Zone scw.Zone `json:"-"` + // OfferID iD of the researched Offer + OfferID string `json:"-"` +} + +// GetOffer get offer +// +// Return specific offer for the given ID. +func (s *API) GetOffer(req *GetOfferRequest, opts ...scw.RequestOption) (*Offer, error) { + var err error + + if req.Zone == "" { + defaultZone, _ := s.client.GetDefaultZone() + req.Zone = defaultZone + } + + if fmt.Sprint(req.Zone) == "" { + return nil, errors.New("field Zone cannot be empty in request") + } + + if fmt.Sprint(req.OfferID) == "" { + return nil, errors.New("field OfferID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/offers/" + fmt.Sprint(req.OfferID) + "", + Headers: http.Header{}, + } + + var resp Offer + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type ListOsRequest struct { + Zone scw.Zone `json:"-"` + // Page page number + Page *int32 `json:"-"` + // PageSize number of OS per page + PageSize *uint32 `json:"-"` +} + +// ListOs list OS +// +// List all available OS that can be install on a baremetal server. +func (s *API) ListOs(req *ListOsRequest, opts ...scw.RequestOption) (*ListOsResponse, error) { + var err error + + if req.Zone == "" { + defaultZone, _ := s.client.GetDefaultZone() + req.Zone = defaultZone + } + + defaultPageSize, exist := s.client.GetDefaultPageSize() + if (req.PageSize == nil || *req.PageSize == 0) && exist { + req.PageSize = &defaultPageSize + } + + query := url.Values{} + parameter.AddToQuery(query, "page", req.Page) + parameter.AddToQuery(query, "page_size", req.PageSize) + + if fmt.Sprint(req.Zone) == "" { + return nil, errors.New("field Zone cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/os", + Query: query, + Headers: http.Header{}, + } + + var resp ListOsResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// UnsafeGetTotalCount should not be used +// Internal usage only +func (r *ListOsResponse) UnsafeGetTotalCount() uint32 { + return r.TotalCount +} + +// UnsafeAppend should not be used +// Internal usage only +func (r *ListOsResponse) UnsafeAppend(res interface{}) (uint32, error) { + results, ok := res.(*ListOsResponse) + if !ok { + return 0, errors.New("%T type cannot be appended to type %T", res, r) + } + + r.Os = append(r.Os, results.Os...) + r.TotalCount += uint32(len(results.Os)) + return uint32(len(results.Os)), nil +} + +type GetOsRequest struct { + Zone scw.Zone `json:"-"` + // OsID iD of the researched OS + OsID string `json:"-"` +} + +// GetOs get OS +// +// Return specific OS for the given ID. +func (s *API) GetOs(req *GetOsRequest, opts ...scw.RequestOption) (*Os, error) { + var err error + + if req.Zone == "" { + defaultZone, _ := s.client.GetDefaultZone() + req.Zone = defaultZone + } + + if fmt.Sprint(req.Zone) == "" { + return nil, errors.New("field Zone cannot be empty in request") + } + + if fmt.Sprint(req.OsID) == "" { + return nil, errors.New("field OsID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/baremetal/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/os/" + fmt.Sprint(req.OsID) + "", + Headers: http.Header{}, + } + + var resp Os + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil } diff --git a/api/instance/v1/instance_sdk.go b/api/instance/v1/instance_sdk.go index e9505ef2d..c486c644b 100644 --- a/api/instance/v1/instance_sdk.go +++ b/api/instance/v1/instance_sdk.go @@ -1706,15 +1706,15 @@ func (s *API) setServer(req *setServerRequest, opts ...scw.RequestOption) (*setS type UpdateServerRequest struct { Zone scw.Zone `json:"-"` - + // ServerID uUID of the server ServerID string `json:"-"` - + // Name name of the server Name *string `json:"name,omitempty"` // BootType // // Default value: local BootType *BootType `json:"boot_type,omitempty"` - + // Tags tags of the server Tags *[]string `json:"tags,omitempty"` Volumes *map[string]*VolumeTemplate `json:"volumes,omitempty"` @@ -2310,9 +2310,9 @@ func (r *ListSnapshotsResponse) UnsafeAppend(res interface{}) (uint32, error) { type CreateSnapshotRequest struct { Zone scw.Zone `json:"-"` - + // Name name of the snapshot Name string `json:"name,omitempty"` - + // VolumeID uUID of the volume VolumeID string `json:"volume_id,omitempty"` Organization string `json:"organization,omitempty"` @@ -2607,18 +2607,6 @@ type CreateVolumeRequest struct { BaseSnapshot *string `json:"base_snapshot,omitempty"` } -func (m *CreateVolumeRequest) GetFrom() From { - switch { - case m.Size != nil: - return FromSize{*m.Size} - case m.BaseVolume != nil: - return FromBaseVolume{*m.BaseVolume} - case m.BaseSnapshot != nil: - return FromBaseSnapshot{*m.BaseSnapshot} - } - return nil -} - // CreateVolume create volume func (s *API) CreateVolume(req *CreateVolumeRequest, opts ...scw.RequestOption) (*CreateVolumeResponse, error) { var err error @@ -2737,14 +2725,16 @@ func (s *API) DeleteVolume(req *DeleteVolumeRequest, opts ...scw.RequestOption) type ListSecurityGroupsRequest struct { Zone scw.Zone `json:"-"` - + // Name name of the security group + Name *string `json:"-"` + // Organization the security group organization ID Organization *string `json:"-"` - + // PerPage a positive integer lower or equal to 100 to select the number of items to display + // + // Default value: 20 PerPage *uint32 `json:"-"` - + // Page a positive integer to choose the page to display Page *int32 `json:"-"` - - Name *string `json:"-"` } // ListSecurityGroups list security groups @@ -2764,10 +2754,10 @@ func (s *API) ListSecurityGroups(req *ListSecurityGroupsRequest, opts ...scw.Req } query := url.Values{} + parameter.AddToQuery(query, "name", req.Name) parameter.AddToQuery(query, "organization", req.Organization) parameter.AddToQuery(query, "per_page", req.PerPage) parameter.AddToQuery(query, "page", req.Page) - parameter.AddToQuery(query, "name", req.Name) if fmt.Sprint(req.Zone) == "" { return nil, errors.New("field Zone cannot be empty in request") @@ -2810,7 +2800,7 @@ func (r *ListSecurityGroupsResponse) UnsafeAppend(res interface{}) (uint32, erro type CreateSecurityGroupRequest struct { Zone scw.Zone `json:"-"` - + // Name name of the security group Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` @@ -3030,11 +3020,13 @@ func (s *API) setSecurityGroup(req *setSecurityGroupRequest, opts ...scw.Request type ListSecurityGroupRulesRequest struct { Zone scw.Zone `json:"-"` - + // SecurityGroupID uUID of the security group SecurityGroupID string `json:"-"` - + // PerPage a positive integer lower or equal to 100 to select the number of items to display + // + // Default value: 20 PerPage *uint32 `json:"-"` - + // Page a positive integer to choose the page to display Page *int32 `json:"-"` } @@ -3101,7 +3093,7 @@ func (r *ListSecurityGroupRulesResponse) UnsafeAppend(res interface{}) (uint32, type CreateSecurityGroupRuleRequest struct { Zone scw.Zone `json:"-"` - + // SecurityGroupID uUID of the security group SecurityGroupID string `json:"-"` // Protocol // @@ -3404,7 +3396,7 @@ func (r *ListPlacementGroupsResponse) UnsafeAppend(res interface{}) (uint32, err type CreatePlacementGroupRequest struct { Zone scw.Zone `json:"-"` - + // Name name of the placement group Name string `json:"name,omitempty"` Organization string `json:"organization,omitempty"` @@ -3566,9 +3558,9 @@ func (s *API) SetPlacementGroup(req *SetPlacementGroupRequest, opts ...scw.Reque type UpdatePlacementGroupRequest struct { Zone scw.Zone `json:"-"` - + // PlacementGroupID uUID of the placement group PlacementGroupID string `json:"-"` - + // Name name of the placement group Name *string `json:"name,omitempty"` Organization *string `json:"organization,omitempty"` @@ -3748,7 +3740,7 @@ func (s *API) SetPlacementGroupServers(req *SetPlacementGroupServersRequest, opt type UpdatePlacementGroupServersRequest struct { Zone scw.Zone `json:"-"` - + // PlacementGroupID uUID of the placement group PlacementGroupID string `json:"-"` Servers []string `json:"servers,omitempty"` @@ -3795,13 +3787,15 @@ func (s *API) UpdatePlacementGroupServers(req *UpdatePlacementGroupServersReques type ListIPsRequest struct { Zone scw.Zone `json:"-"` - + // Organization the organization ID the IPs are reserved in Organization *string `json:"-"` - + // Name filter on the IP address (Works as a LIKE operation on the IP address) Name *string `json:"-"` - + // PerPage a positive integer lower or equal to 100 to select the number of items to display + // + // Default value: 20 PerPage *uint32 `json:"-"` - + // Page a positive integer to choose the page to display Page *int32 `json:"-"` } @@ -3866,9 +3860,9 @@ func (r *ListIPsResponse) UnsafeAppend(res interface{}) (uint32, error) { type CreateIPRequest struct { Zone scw.Zone `json:"-"` - + // Organization the organization ID the IP is reserved in Organization string `json:"organization,omitempty"` - + // Server uUID of the server you want to attach the IP to Server *string `json:"server,omitempty"` } @@ -4009,7 +4003,7 @@ type updateIPRequest struct { Zone scw.Zone `json:"-"` // IP iP ID or IP address IP string `json:"-"` - + // Reverse reverse domain name Reverse *NullableStringValue `json:"reverse,omitempty"` Server *NullableStringValue `json:"server,omitempty"` @@ -4243,28 +4237,3 @@ func (s *API) GetDashboard(req *GetDashboardRequest, opts ...scw.RequestOption) } return &resp, nil } - -type From interface { - isFrom() -} - -type FromSize struct { - Value scw.Size -} - -func (FromSize) isFrom() { -} - -type FromBaseVolume struct { - Value string -} - -func (FromBaseVolume) isFrom() { -} - -type FromBaseSnapshot struct { - Value string -} - -func (FromBaseSnapshot) isFrom() { -} diff --git a/api/k8s/v1beta3/k8s_sdk.go b/api/k8s/v1beta3/k8s_sdk.go index aeb77bf42..94c1f7cfc 100644 --- a/api/k8s/v1beta3/k8s_sdk.go +++ b/api/k8s/v1beta3/k8s_sdk.go @@ -409,6 +409,8 @@ type Cluster struct { Ingress string `json:"ingress"` AutoUpgrade *ClusterAutoUpgrade `json:"auto_upgrade"` + // UpgradeAvailable true if a new Kubernetes version is available + UpgradeAvailable bool `json:"upgrade_available"` } type ClusterAutoUpgrade struct { diff --git a/api/k8s/v1beta4/k8s_sdk.go b/api/k8s/v1beta4/k8s_sdk.go new file mode 100644 index 000000000..1b91818e6 --- /dev/null +++ b/api/k8s/v1beta4/k8s_sdk.go @@ -0,0 +1,1914 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. + +// Package k8s provides methods and message types of the k8s v1beta4 API. +package k8s + +import ( + "bytes" + "encoding/json" + "fmt" + "net" + "net/http" + "net/url" + "time" + + "github.com/scaleway/scaleway-sdk-go/internal/errors" + "github.com/scaleway/scaleway-sdk-go/internal/marshaler" + "github.com/scaleway/scaleway-sdk-go/internal/parameter" + "github.com/scaleway/scaleway-sdk-go/namegenerator" + "github.com/scaleway/scaleway-sdk-go/scw" +) + +// always import dependencies +var ( + _ fmt.Stringer + _ json.Unmarshaler + _ url.URL + _ net.IP + _ http.Header + _ bytes.Reader + _ time.Time + + _ scw.ScalewayRequest + _ marshaler.Duration + _ scw.File + _ = parameter.AddToQuery + _ = namegenerator.GetRandomName +) + +// API this API allows you to manage your kapsule clusters +type API struct { + client *scw.Client +} + +// NewAPI returns a API object from a Scaleway client. +func NewAPI(client *scw.Client) *API { + return &API{ + client: client, + } +} + +type AutoscalerEstimator string + +const ( + // AutoscalerEstimatorUnknownEstimator is [insert doc]. + AutoscalerEstimatorUnknownEstimator = AutoscalerEstimator("unknown_estimator") + // AutoscalerEstimatorBinpacking is [insert doc]. + AutoscalerEstimatorBinpacking = AutoscalerEstimator("binpacking") + // AutoscalerEstimatorOldbinpacking is [insert doc]. + AutoscalerEstimatorOldbinpacking = AutoscalerEstimator("oldbinpacking") +) + +func (enum AutoscalerEstimator) String() string { + if enum == "" { + // return default value if empty + return "unknown_estimator" + } + return string(enum) +} + +func (enum AutoscalerEstimator) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *AutoscalerEstimator) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = AutoscalerEstimator(AutoscalerEstimator(tmp).String()) + return nil +} + +type AutoscalerExpander string + +const ( + // AutoscalerExpanderUnknownExpander is [insert doc]. + AutoscalerExpanderUnknownExpander = AutoscalerExpander("unknown_expander") + // AutoscalerExpanderRandom is [insert doc]. + AutoscalerExpanderRandom = AutoscalerExpander("random") + // AutoscalerExpanderMostPods is [insert doc]. + AutoscalerExpanderMostPods = AutoscalerExpander("most_pods") + // AutoscalerExpanderLeastWaste is [insert doc]. + AutoscalerExpanderLeastWaste = AutoscalerExpander("least_waste") + // AutoscalerExpanderPriority is [insert doc]. + AutoscalerExpanderPriority = AutoscalerExpander("priority") +) + +func (enum AutoscalerExpander) String() string { + if enum == "" { + // return default value if empty + return "unknown_expander" + } + return string(enum) +} + +func (enum AutoscalerExpander) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *AutoscalerExpander) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = AutoscalerExpander(AutoscalerExpander(tmp).String()) + return nil +} + +type CNI string + +const ( + // CNIUnknownCni is [insert doc]. + CNIUnknownCni = CNI("unknown_cni") + // CNICilium is [insert doc]. + CNICilium = CNI("cilium") + // CNICalico is [insert doc]. + CNICalico = CNI("calico") + // CNIWeave is [insert doc]. + CNIWeave = CNI("weave") + // CNIFlannel is [insert doc]. + CNIFlannel = CNI("flannel") +) + +func (enum CNI) String() string { + if enum == "" { + // return default value if empty + return "unknown_cni" + } + return string(enum) +} + +func (enum CNI) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *CNI) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = CNI(CNI(tmp).String()) + return nil +} + +type ClusterStatus string + +const ( + // ClusterStatusUnknown is [insert doc]. + ClusterStatusUnknown = ClusterStatus("unknown") + // ClusterStatusCreating is [insert doc]. + ClusterStatusCreating = ClusterStatus("creating") + // ClusterStatusReady is [insert doc]. + ClusterStatusReady = ClusterStatus("ready") + // ClusterStatusDeleting is [insert doc]. + ClusterStatusDeleting = ClusterStatus("deleting") + // ClusterStatusDeleted is [insert doc]. + ClusterStatusDeleted = ClusterStatus("deleted") + // ClusterStatusUpdating is [insert doc]. + ClusterStatusUpdating = ClusterStatus("updating") + // ClusterStatusWarning is [insert doc]. + ClusterStatusWarning = ClusterStatus("warning") + // ClusterStatusError is [insert doc]. + ClusterStatusError = ClusterStatus("error") + // ClusterStatusLocked is [insert doc]. + ClusterStatusLocked = ClusterStatus("locked") +) + +func (enum ClusterStatus) String() string { + if enum == "" { + // return default value if empty + return "unknown" + } + return string(enum) +} + +func (enum ClusterStatus) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *ClusterStatus) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = ClusterStatus(ClusterStatus(tmp).String()) + return nil +} + +type Ingress string + +const ( + // IngressUnknownIngress is [insert doc]. + IngressUnknownIngress = Ingress("unknown_ingress") + // IngressNone is [insert doc]. + IngressNone = Ingress("none") + // IngressNginx is [insert doc]. + IngressNginx = Ingress("nginx") + // IngressTraefik is [insert doc]. + IngressTraefik = Ingress("traefik") +) + +func (enum Ingress) String() string { + if enum == "" { + // return default value if empty + return "unknown_ingress" + } + return string(enum) +} + +func (enum Ingress) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *Ingress) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = Ingress(Ingress(tmp).String()) + return nil +} + +type ListClustersRequestOrderBy string + +const ( + // ListClustersRequestOrderByCreatedAtAsc is [insert doc]. + ListClustersRequestOrderByCreatedAtAsc = ListClustersRequestOrderBy("created_at_asc") + // ListClustersRequestOrderByCreatedAtDesc is [insert doc]. + ListClustersRequestOrderByCreatedAtDesc = ListClustersRequestOrderBy("created_at_desc") + // ListClustersRequestOrderByUpdatedAtAsc is [insert doc]. + ListClustersRequestOrderByUpdatedAtAsc = ListClustersRequestOrderBy("updated_at_asc") + // ListClustersRequestOrderByUpdatedAtDesc is [insert doc]. + ListClustersRequestOrderByUpdatedAtDesc = ListClustersRequestOrderBy("updated_at_desc") + // ListClustersRequestOrderByNameAsc is [insert doc]. + ListClustersRequestOrderByNameAsc = ListClustersRequestOrderBy("name_asc") + // ListClustersRequestOrderByNameDesc is [insert doc]. + ListClustersRequestOrderByNameDesc = ListClustersRequestOrderBy("name_desc") + // ListClustersRequestOrderByStatusAsc is [insert doc]. + ListClustersRequestOrderByStatusAsc = ListClustersRequestOrderBy("status_asc") + // ListClustersRequestOrderByStatusDesc is [insert doc]. + ListClustersRequestOrderByStatusDesc = ListClustersRequestOrderBy("status_desc") + // ListClustersRequestOrderByVersionAsc is [insert doc]. + ListClustersRequestOrderByVersionAsc = ListClustersRequestOrderBy("version_asc") + // ListClustersRequestOrderByVersionDesc is [insert doc]. + ListClustersRequestOrderByVersionDesc = ListClustersRequestOrderBy("version_desc") +) + +func (enum ListClustersRequestOrderBy) String() string { + if enum == "" { + // return default value if empty + return "created_at_asc" + } + return string(enum) +} + +func (enum ListClustersRequestOrderBy) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *ListClustersRequestOrderBy) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = ListClustersRequestOrderBy(ListClustersRequestOrderBy(tmp).String()) + return nil +} + +type ListNodesRequestOrderBy string + +const ( + // ListNodesRequestOrderByCreatedAtAsc is [insert doc]. + ListNodesRequestOrderByCreatedAtAsc = ListNodesRequestOrderBy("created_at_asc") + // ListNodesRequestOrderByCreatedAtDesc is [insert doc]. + ListNodesRequestOrderByCreatedAtDesc = ListNodesRequestOrderBy("created_at_desc") +) + +func (enum ListNodesRequestOrderBy) String() string { + if enum == "" { + // return default value if empty + return "created_at_asc" + } + return string(enum) +} + +func (enum ListNodesRequestOrderBy) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *ListNodesRequestOrderBy) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = ListNodesRequestOrderBy(ListNodesRequestOrderBy(tmp).String()) + return nil +} + +type ListPoolsRequestOrderBy string + +const ( + // ListPoolsRequestOrderByCreatedAtAsc is [insert doc]. + ListPoolsRequestOrderByCreatedAtAsc = ListPoolsRequestOrderBy("created_at_asc") + // ListPoolsRequestOrderByCreatedAtDesc is [insert doc]. + ListPoolsRequestOrderByCreatedAtDesc = ListPoolsRequestOrderBy("created_at_desc") + // ListPoolsRequestOrderByUpdatedAtAsc is [insert doc]. + ListPoolsRequestOrderByUpdatedAtAsc = ListPoolsRequestOrderBy("updated_at_asc") + // ListPoolsRequestOrderByUpdatedAtDesc is [insert doc]. + ListPoolsRequestOrderByUpdatedAtDesc = ListPoolsRequestOrderBy("updated_at_desc") + // ListPoolsRequestOrderByNameAsc is [insert doc]. + ListPoolsRequestOrderByNameAsc = ListPoolsRequestOrderBy("name_asc") + // ListPoolsRequestOrderByNameDesc is [insert doc]. + ListPoolsRequestOrderByNameDesc = ListPoolsRequestOrderBy("name_desc") + // ListPoolsRequestOrderByStatusAsc is [insert doc]. + ListPoolsRequestOrderByStatusAsc = ListPoolsRequestOrderBy("status_asc") + // ListPoolsRequestOrderByStatusDesc is [insert doc]. + ListPoolsRequestOrderByStatusDesc = ListPoolsRequestOrderBy("status_desc") + // ListPoolsRequestOrderByVersionAsc is [insert doc]. + ListPoolsRequestOrderByVersionAsc = ListPoolsRequestOrderBy("version_asc") + // ListPoolsRequestOrderByVersionDesc is [insert doc]. + ListPoolsRequestOrderByVersionDesc = ListPoolsRequestOrderBy("version_desc") +) + +func (enum ListPoolsRequestOrderBy) String() string { + if enum == "" { + // return default value if empty + return "created_at_asc" + } + return string(enum) +} + +func (enum ListPoolsRequestOrderBy) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *ListPoolsRequestOrderBy) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = ListPoolsRequestOrderBy(ListPoolsRequestOrderBy(tmp).String()) + return nil +} + +type MaintenanceWindowDayOfTheWeek string + +const ( + // MaintenanceWindowDayOfTheWeekAny is [insert doc]. + MaintenanceWindowDayOfTheWeekAny = MaintenanceWindowDayOfTheWeek("any") + // MaintenanceWindowDayOfTheWeekMonday is [insert doc]. + MaintenanceWindowDayOfTheWeekMonday = MaintenanceWindowDayOfTheWeek("monday") + // MaintenanceWindowDayOfTheWeekTuesday is [insert doc]. + MaintenanceWindowDayOfTheWeekTuesday = MaintenanceWindowDayOfTheWeek("tuesday") + // MaintenanceWindowDayOfTheWeekWednesday is [insert doc]. + MaintenanceWindowDayOfTheWeekWednesday = MaintenanceWindowDayOfTheWeek("wednesday") + // MaintenanceWindowDayOfTheWeekThursday is [insert doc]. + MaintenanceWindowDayOfTheWeekThursday = MaintenanceWindowDayOfTheWeek("thursday") + // MaintenanceWindowDayOfTheWeekFriday is [insert doc]. + MaintenanceWindowDayOfTheWeekFriday = MaintenanceWindowDayOfTheWeek("friday") + // MaintenanceWindowDayOfTheWeekSaturday is [insert doc]. + MaintenanceWindowDayOfTheWeekSaturday = MaintenanceWindowDayOfTheWeek("saturday") + // MaintenanceWindowDayOfTheWeekSunday is [insert doc]. + MaintenanceWindowDayOfTheWeekSunday = MaintenanceWindowDayOfTheWeek("sunday") +) + +func (enum MaintenanceWindowDayOfTheWeek) String() string { + if enum == "" { + // return default value if empty + return "any" + } + return string(enum) +} + +func (enum MaintenanceWindowDayOfTheWeek) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *MaintenanceWindowDayOfTheWeek) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = MaintenanceWindowDayOfTheWeek(MaintenanceWindowDayOfTheWeek(tmp).String()) + return nil +} + +type NodeStatus string + +const ( + // NodeStatusUnknown is [insert doc]. + NodeStatusUnknown = NodeStatus("unknown") + // NodeStatusCreating is [insert doc]. + NodeStatusCreating = NodeStatus("creating") + // NodeStatusRebuilding is [insert doc]. + NodeStatusRebuilding = NodeStatus("rebuilding") + // NodeStatusNotready is [insert doc]. + NodeStatusNotready = NodeStatus("notready") + // NodeStatusReady is [insert doc]. + NodeStatusReady = NodeStatus("ready") + // NodeStatusDeleting is [insert doc]. + NodeStatusDeleting = NodeStatus("deleting") + // NodeStatusDeleted is [insert doc]. + NodeStatusDeleted = NodeStatus("deleted") + // NodeStatusWarning is [insert doc]. + NodeStatusWarning = NodeStatus("warning") + // NodeStatusError is [insert doc]. + NodeStatusError = NodeStatus("error") + // NodeStatusLocked is [insert doc]. + NodeStatusLocked = NodeStatus("locked") + // NodeStatusRebooting is [insert doc]. + NodeStatusRebooting = NodeStatus("rebooting") +) + +func (enum NodeStatus) String() string { + if enum == "" { + // return default value if empty + return "unknown" + } + return string(enum) +} + +func (enum NodeStatus) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *NodeStatus) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = NodeStatus(NodeStatus(tmp).String()) + return nil +} + +type PoolStatus string + +const ( + // PoolStatusUnknown is [insert doc]. + PoolStatusUnknown = PoolStatus("unknown") + // PoolStatusCreating is [insert doc]. + PoolStatusCreating = PoolStatus("creating") + // PoolStatusReady is [insert doc]. + PoolStatusReady = PoolStatus("ready") + // PoolStatusDeleting is [insert doc]. + PoolStatusDeleting = PoolStatus("deleting") + // PoolStatusDeleted is [insert doc]. + PoolStatusDeleted = PoolStatus("deleted") + // PoolStatusUpdating is [insert doc]. + PoolStatusUpdating = PoolStatus("updating") + // PoolStatusScalling is [insert doc]. + PoolStatusScalling = PoolStatus("scalling") + // PoolStatusWarning is [insert doc]. + PoolStatusWarning = PoolStatus("warning") + // PoolStatusError is [insert doc]. + PoolStatusError = PoolStatus("error") + // PoolStatusLocked is [insert doc]. + PoolStatusLocked = PoolStatus("locked") +) + +func (enum PoolStatus) String() string { + if enum == "" { + // return default value if empty + return "unknown" + } + return string(enum) +} + +func (enum PoolStatus) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *PoolStatus) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = PoolStatus(PoolStatus(tmp).String()) + return nil +} + +type Runtime string + +const ( + // RuntimeUnknownRuntime is [insert doc]. + RuntimeUnknownRuntime = Runtime("unknown_runtime") + // RuntimeDocker is [insert doc]. + RuntimeDocker = Runtime("docker") + // RuntimeContainerd is [insert doc]. + RuntimeContainerd = Runtime("containerd") + // RuntimeCrio is [insert doc]. + RuntimeCrio = Runtime("crio") +) + +func (enum Runtime) String() string { + if enum == "" { + // return default value if empty + return "unknown_runtime" + } + return string(enum) +} + +func (enum Runtime) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *Runtime) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = Runtime(Runtime(tmp).String()) + return nil +} + +// Cluster cluster +type Cluster struct { + // ID the ID of the cluster + ID string `json:"id"` + // Region the region in which is the cluster + Region scw.Region `json:"region"` + // Name the name of the cluster + Name string `json:"name"` + // Description the description of the cluster + Description string `json:"description"` + // OrganizationID the ID of the organization owning the cluster + OrganizationID string `json:"organization_id"` + // Tags the tags associated to the cluster + Tags []string `json:"tags"` + // Status the status of the cluster + // + // Default value: unknown + Status ClusterStatus `json:"status"` + // Version the Kubernetes version of the cluster + Version string `json:"version"` + // Cni the Container Network Interface (CNI) plugin running in the cluster + // + // Default value: unknown_cni + Cni CNI `json:"cni"` + // ClusterURL the Kubernetes API server URL of the cluster + ClusterURL string `json:"cluster_url"` + // DNSWildcard the DNS wildcard resovling all the ready nodes of the cluster + DNSWildcard string `json:"dns_wildcard"` + // CreatedAt the date at which the cluster was created + CreatedAt time.Time `json:"created_at"` + // UpdatedAt the date at which the cluster was last updated + UpdatedAt time.Time `json:"updated_at"` + // CurrentCoreCount the total number of cores of all the nodes in the cluster + CurrentCoreCount uint32 `json:"current_core_count"` + // CurrentNodeCount the total number of nodes in the cluster + CurrentNodeCount uint32 `json:"current_node_count"` + // CurrentMemCount the total amount of memory of all the nodes in the cluster + CurrentMemCount uint64 `json:"current_mem_count"` + // AutoscalerConfig the autoscaler config for the cluster + AutoscalerConfig *ClusterAutoscalerConfig `json:"autoscaler_config"` + // DashboardEnabled the enablement of the Kubernetes Dashboard in the cluster + DashboardEnabled bool `json:"dashboard_enabled"` + // Ingress the ingress controller used in the cluster + // + // Default value: unknown_ingress + Ingress Ingress `json:"ingress"` + // AutoUpgrade the auo upgrade configuration of the cluster + AutoUpgrade *ClusterAutoUpgrade `json:"auto_upgrade"` + // UpgradeAvailable true if a new Kubernetes version is available + UpgradeAvailable bool `json:"upgrade_available"` +} + +type ClusterAutoUpgrade struct { + Enabled bool `json:"enabled"` + + MaintenanceWindow *MaintenanceWindow `json:"maintenance_window"` +} + +type ClusterAutoscalerConfig struct { + ScaleDownDisabled bool `json:"scale_down_disabled"` + + ScaleDownDelayAfterAdd string `json:"scale_down_delay_after_add"` + // Estimator + // + // Default value: unknown_estimator + Estimator AutoscalerEstimator `json:"estimator"` + // Expander + // + // Default value: unknown_expander + Expander AutoscalerExpander `json:"expander"` + + IgnoreDaemonsetsUtilization bool `json:"ignore_daemonsets_utilization"` + + BalanceSimilarNodeGroups bool `json:"balance_similar_node_groups"` + + ExpendablePodsPriorityCutoff int32 `json:"expendable_pods_priority_cutoff"` +} + +type CreateClusterRequestAutoUpgrade struct { + Enable bool `json:"enable"` + + MaintenanceWindow *MaintenanceWindow `json:"maintenance_window"` +} + +type CreateClusterRequestAutoscalerConfig struct { + ScaleDownDisabled *bool `json:"scale_down_disabled"` + + ScaleDownDelayAfterAdd *string `json:"scale_down_delay_after_add"` + // Estimator + // + // Default value: unknown_estimator + Estimator AutoscalerEstimator `json:"estimator"` + // Expander + // + // Default value: unknown_expander + Expander AutoscalerExpander `json:"expander"` + + IgnoreDaemonsetsUtilization *bool `json:"ignore_daemonsets_utilization"` + + BalanceSimilarNodeGroups *bool `json:"balance_similar_node_groups"` + + ExpendablePodsPriorityCutoff *int32 `json:"expendable_pods_priority_cutoff"` +} + +type CreateClusterRequestDefaultPoolConfig struct { + NodeType string `json:"node_type"` + + PlacementGroupID *string `json:"placement_group_id"` + + Autoscaling bool `json:"autoscaling"` + + Size uint32 `json:"size"` + + MinSize *uint32 `json:"min_size"` + + MaxSize *uint32 `json:"max_size"` + // ContainerRuntime + // + // Default value: unknown_runtime + ContainerRuntime Runtime `json:"container_runtime"` + + Autohealing bool `json:"autohealing"` + + Tags []string `json:"tags"` +} + +// ListClusterAvailableVersionsResponse list cluster available versions response +type ListClusterAvailableVersionsResponse struct { + // Versions the available Kubernetes version for the cluster + Versions []*Version `json:"versions"` +} + +// ListClustersResponse list clusters response +type ListClustersResponse struct { + // TotalCount the total number of clusters + TotalCount uint32 `json:"total_count"` + // Clusters the paginated returned clusters + Clusters []*Cluster `json:"clusters"` +} + +// ListNodesResponse list nodes response +type ListNodesResponse struct { + // TotalCount the total number of nodes + TotalCount uint32 `json:"total_count"` + // Nodes the paginated returned nodes + Nodes []*Node `json:"nodes"` +} + +// ListPoolsResponse list pools response +type ListPoolsResponse struct { + // TotalCount the total number of pools that exists for the cluster + TotalCount uint32 `json:"total_count"` + // Pools the paginated returned pools + Pools []*Pool `json:"pools"` +} + +// ListVersionsResponse list versions response +type ListVersionsResponse struct { + // Versions the available Kubernetes versions + Versions []*Version `json:"versions"` +} + +type MaintenanceWindow struct { + StartHour uint32 `json:"start_hour"` + // Day + // + // Default value: any + Day MaintenanceWindowDayOfTheWeek `json:"day"` +} + +// Node node +type Node struct { + // ID the ID of the node + ID string `json:"id"` + // PoolID the pool ID of the node + PoolID string `json:"pool_id"` + // ClusterID the cluster ID of the node + ClusterID string `json:"cluster_id"` + // Region the cluster region of the node + Region scw.Region `json:"region"` + // Name the name of the node + Name string `json:"name"` + // PublicIPV4 the public IPv4 address of the node + PublicIPV4 *net.IP `json:"public_ip_v4"` + // PublicIPV6 the public IPv6 address of the node + PublicIPV6 *net.IP `json:"public_ip_v6"` + // Conditions the conditions of the node + // + // These conditions contains the Node Problem Detector conditions, as well as some in house conditions. + Conditions map[string]string `json:"conditions"` + // Status the status of the node + // + // Default value: unknown + Status NodeStatus `json:"status"` + // CreatedAt the date at which the node was created + CreatedAt time.Time `json:"created_at"` + // UpdatedAt the date at which the node was last updated + UpdatedAt time.Time `json:"updated_at"` +} + +// Pool pool +type Pool struct { + // ID the ID of the pool + ID string `json:"id"` + // ClusterID the cluster ID of the pool + ClusterID string `json:"cluster_id"` + // CreatedAt the date at which the pool was created + CreatedAt time.Time `json:"created_at"` + // UpdatedAt the date at which the pool was last updated + UpdatedAt time.Time `json:"updated_at"` + // Name the name of the pool + Name string `json:"name"` + // CurrentNodeCount the total number of nodes in the pool + CurrentNodeCount uint32 `json:"current_node_count"` + // Status the status of the pool + // + // Default value: unknown + Status PoolStatus `json:"status"` + // Version the version of the pool + Version string `json:"version"` + // NodeType the node type is the type of Scaleway Instance wanted for the pool + NodeType string `json:"node_type"` + // Autoscaling the enablement of the autoscaling feature for the pool + Autoscaling bool `json:"autoscaling"` + // Size the size (number of nodes) of the pool + Size uint32 `json:"size"` + // MinSize the minimun size of the pool + // + // The minimun size of the pool. Note that this fields will be used only when autoscaling is enabled. + MinSize uint32 `json:"min_size"` + // MaxSize the maximum size of the pool + // + // The maximum size of the pool. Note that this fields will be used only when autoscaling is enabled. + MaxSize uint32 `json:"max_size"` + // CurrentCoreCount the total number of cores of all the nodes in the pool + CurrentCoreCount uint32 `json:"current_core_count"` + // CurrentMemCount the total amount of memory of all the nodes in the pool + CurrentMemCount uint64 `json:"current_mem_count"` + // ContainerRuntime the container runtime for the nodes of the pool + // + // The customization of the container runtime is available for each pool. Note that `docker` is the only supporter runtime at the moment. Others are to be considered experimental. + // + // Default value: unknown_runtime + ContainerRuntime Runtime `json:"container_runtime"` + // Autohealing the enablement of the autohealing feature for the pool + Autohealing bool `json:"autohealing"` + // Tags the tags associated with the pool + Tags []string `json:"tags"` + // PlacementGroupID the placement group ID in which all the nodes of the pool will be created + PlacementGroupID *string `json:"placement_group_id"` + // Region the cluster region of the pool + Region scw.Region `json:"region"` +} + +type UpdateClusterRequestAutoUpgrade struct { + Enable *bool `json:"enable"` + + MaintenanceWindow *MaintenanceWindow `json:"maintenance_window"` +} + +type UpdateClusterRequestAutoscalerConfig struct { + ScaleDownDisabled *bool `json:"scale_down_disabled"` + + ScaleDownDelayAfterAdd *string `json:"scale_down_delay_after_add"` + // Estimator + // + // Default value: unknown_estimator + Estimator AutoscalerEstimator `json:"estimator"` + // Expander + // + // Default value: unknown_expander + Expander AutoscalerExpander `json:"expander"` + + IgnoreDaemonsetsUtilization *bool `json:"ignore_daemonsets_utilization"` + + BalanceSimilarNodeGroups *bool `json:"balance_similar_node_groups"` + + ExpendablePodsPriorityCutoff *int32 `json:"expendable_pods_priority_cutoff"` +} + +// Version version +type Version struct { + // Region the regions in which this version is available + Region scw.Region `json:"region"` + // Name the name of the Kubernetes version + Name string `json:"name"` + // Label the label of the Kubernetes version + Label string `json:"label"` + // AvailableCnis the supported Container Network Interface (CNI) plugins for this version + AvailableCnis []CNI `json:"available_cnis"` + // AvailableIngresses the supported Ingress Controllers for this version + AvailableIngresses []Ingress `json:"available_ingresses"` + // AvailableContainerRuntimes the supported container runtimes for this version + AvailableContainerRuntimes []Runtime `json:"available_container_runtimes"` +} + +// Service API + +type ListClustersRequest struct { + Region scw.Region `json:"-"` + // OrganizationID the organization ID on which to filter the returned clusters + OrganizationID *string `json:"-"` + // OrderBy the sort order of the returned clusters + // + // Default value: created_at_asc + OrderBy ListClustersRequestOrderBy `json:"-"` + // Page the page number for the returned clusters + Page *int32 `json:"-"` + // PageSize the maximum number of clusters per page + PageSize *uint32 `json:"-"` + // Name the name on which to filter the retured clusters + Name *string `json:"-"` + // Status the status on which to filter the returned clusters + // + // Default value: unknown + Status ClusterStatus `json:"-"` +} + +// ListClusters list all the clusters +// +// This method allows to list all the existing Kubernetes clusters in an account. +func (s *API) ListClusters(req *ListClustersRequest, opts ...scw.RequestOption) (*ListClustersResponse, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + defaultPageSize, exist := s.client.GetDefaultPageSize() + if (req.PageSize == nil || *req.PageSize == 0) && exist { + req.PageSize = &defaultPageSize + } + + query := url.Values{} + parameter.AddToQuery(query, "organization_id", req.OrganizationID) + parameter.AddToQuery(query, "order_by", req.OrderBy) + parameter.AddToQuery(query, "page", req.Page) + parameter.AddToQuery(query, "page_size", req.PageSize) + parameter.AddToQuery(query, "name", req.Name) + parameter.AddToQuery(query, "status", req.Status) + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/clusters", + Query: query, + Headers: http.Header{}, + } + + var resp ListClustersResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// UnsafeGetTotalCount should not be used +// Internal usage only +func (r *ListClustersResponse) UnsafeGetTotalCount() uint32 { + return r.TotalCount +} + +// UnsafeAppend should not be used +// Internal usage only +func (r *ListClustersResponse) UnsafeAppend(res interface{}) (uint32, error) { + results, ok := res.(*ListClustersResponse) + if !ok { + return 0, errors.New("%T type cannot be appended to type %T", res, r) + } + + r.Clusters = append(r.Clusters, results.Clusters...) + r.TotalCount += uint32(len(results.Clusters)) + return uint32(len(results.Clusters)), nil +} + +type CreateClusterRequest struct { + Region scw.Region `json:"-"` + // OrganizationID the organization ID where the cluster will be created + OrganizationID string `json:"organization_id"` + // Name the name of the cluster + Name string `json:"name"` + // Description the description of the cluster + Description string `json:"description"` + // Tags the tags associated with the cluster + Tags []string `json:"tags"` + // Version the Kubernetes version of the cluster + Version string `json:"version"` + // Cni the Container Network Interface (CNI) plugin that will run in the cluster + // + // Default value: unknown_cni + Cni CNI `json:"cni"` + // EnableDashboard the enablement of the Kubernetes Dashboard in the cluster + EnableDashboard bool `json:"enable_dashboard"` + // Ingress the Ingress Controller that will run in the cluster + // + // Default value: unknown_ingress + Ingress Ingress `json:"ingress"` + // DefaultPoolConfig the config of the defaul pool of the cluster + DefaultPoolConfig *CreateClusterRequestDefaultPoolConfig `json:"default_pool_config"` + // AutoscalerConfig the autoscaler config for the cluster + // + // This field allows to specify some configuration for the autoscaler, which is an implementation of the [cluster-autoscaler](https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler/). + AutoscalerConfig *CreateClusterRequestAutoscalerConfig `json:"autoscaler_config"` + // AutoUpgrade the auo upgrade configuration of the cluster + // + // This configuratiom enables to set a speicific 2-hour time window in which the cluster can be automatically updated to the latest patch version in the current minor one. + AutoUpgrade *CreateClusterRequestAutoUpgrade `json:"auto_upgrade"` +} + +// CreateCluster create a new cluster +// +// This method allows to create a new Kubernetes cluster on an account. +func (s *API) CreateCluster(req *CreateClusterRequest, opts ...scw.RequestOption) (*Cluster, error) { + var err error + + if req.OrganizationID == "" { + defaultOrganizationID, _ := s.client.GetDefaultOrganizationID() + req.OrganizationID = defaultOrganizationID + } + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/clusters", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Cluster + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type GetClusterRequest struct { + Region scw.Region `json:"-"` + // ClusterID the ID of the requested cluster + ClusterID string `json:"-"` +} + +// GetCluster get a cluster +// +// This method allows to get details about a specific Kubernetes cluster. +func (s *API) GetCluster(req *GetClusterRequest, opts ...scw.RequestOption) (*Cluster, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.ClusterID) == "" { + return nil, errors.New("field ClusterID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/clusters/" + fmt.Sprint(req.ClusterID) + "", + Headers: http.Header{}, + } + + var resp Cluster + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type UpdateClusterRequest struct { + Region scw.Region `json:"-"` + // ClusterID the ID of the cluster to update + ClusterID string `json:"-"` + // Description the new description of the cluster + Description *string `json:"description"` + // Tags the new tags associated with the cluster + Tags *[]string `json:"tags"` + // AutoscalerConfig the new autoscaler config for the cluster + // + // This field allows to update some configuration for the autoscaler, which is an implementation of the [cluster-autoscaler](https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler/). + AutoscalerConfig *UpdateClusterRequestAutoscalerConfig `json:"autoscaler_config"` + // EnableDashboard the new value of the Kubernetes Dashboard enablement + EnableDashboard *bool `json:"enable_dashboard"` + // Ingress the new Ingress Controller for the cluster + // + // Default value: unknown_ingress + Ingress Ingress `json:"ingress"` + // AutoUpgrade the new auo upgrade configuration of the cluster + // + // The new auo upgrade configuration of the cluster. Note that all the fields needs to be set. + AutoUpgrade *UpdateClusterRequestAutoUpgrade `json:"auto_upgrade"` +} + +// UpdateCluster update a cluster +// +// This method allows to update a specific Kubernetes cluster. Note that this method is not made to upgrade a Kubernetes cluster. +func (s *API) UpdateCluster(req *UpdateClusterRequest, opts ...scw.RequestOption) (*Cluster, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.ClusterID) == "" { + return nil, errors.New("field ClusterID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "PATCH", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/clusters/" + fmt.Sprint(req.ClusterID) + "", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Cluster + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type DeleteClusterRequest struct { + Region scw.Region `json:"-"` + // ClusterID the ID of the cluster to delete + ClusterID string `json:"-"` +} + +// DeleteCluster delete a cluster +// +// This method allows to delete a specific cluster and all its associated pools and nodes. Note that this method will not delete any Load Balancers or Block Volumes that are associated with the cluster. +func (s *API) DeleteCluster(req *DeleteClusterRequest, opts ...scw.RequestOption) (*Cluster, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.ClusterID) == "" { + return nil, errors.New("field ClusterID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "DELETE", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/clusters/" + fmt.Sprint(req.ClusterID) + "", + Headers: http.Header{}, + } + + var resp Cluster + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type UpgradeClusterRequest struct { + Region scw.Region `json:"-"` + // ClusterID the ID of the cluster to upgrade + ClusterID string `json:"-"` + // Version the new Kubernetes version of the cluster + // + // The new Kubernetes version of the cluster. Note that the version shoud either be a higher patch version of the same minor version or the direct minor version after the current one. + Version string `json:"version"` + // UpgradePools the enablement of the pools upgrade + // + // This field makes the upgrade upgrades the pool once the Kubernetes master in upgrade. + UpgradePools bool `json:"upgrade_pools"` +} + +// UpgradeCluster upgrade a cluster +// +// This method allows to upgrade a specific Kubernetes cluster and/or its associated pools to a specific and supported Kubernetes version. +func (s *API) UpgradeCluster(req *UpgradeClusterRequest, opts ...scw.RequestOption) (*Cluster, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.ClusterID) == "" { + return nil, errors.New("field ClusterID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/clusters/" + fmt.Sprint(req.ClusterID) + "/upgrade", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Cluster + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type ListClusterAvailableVersionsRequest struct { + Region scw.Region `json:"-"` + // ClusterID the ID of the cluster which the available Kuberentes versions will be listed from + ClusterID string `json:"-"` +} + +// ListClusterAvailableVersions list available versions for a cluster +// +// This method allows to list the versions that a specific Kubernetes cluster is allowed to upgrade to. Note that it will be every patch version greater than the actual one as well a one minor version ahead of the actual one. Upgrades skipping a minor version will not work. +func (s *API) ListClusterAvailableVersions(req *ListClusterAvailableVersionsRequest, opts ...scw.RequestOption) (*ListClusterAvailableVersionsResponse, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.ClusterID) == "" { + return nil, errors.New("field ClusterID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/clusters/" + fmt.Sprint(req.ClusterID) + "/available-versions", + Headers: http.Header{}, + } + + var resp ListClusterAvailableVersionsResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type GetClusterKubeConfigRequest struct { + Region scw.Region `json:"-"` + // ClusterID the ID of the cluster to download the kubeconfig from + ClusterID string `json:"-"` +} + +// getClusterKubeConfig download the kubeconfig for a cluster +// +// This method allows to download the Kubernetes cluster config file (AKA kubeconfig) for a specific cluster in order to use it with, for instance, `kubectl`. Tips: add `?dl=1` at the end of the URL to directly get the base64 decoded kubeconfig. If not, the kubeconfig will be base64 encoded. +// +func (s *API) getClusterKubeConfig(req *GetClusterKubeConfigRequest, opts ...scw.RequestOption) (*scw.File, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.ClusterID) == "" { + return nil, errors.New("field ClusterID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/clusters/" + fmt.Sprint(req.ClusterID) + "/kubeconfig", + Headers: http.Header{}, + } + + var resp scw.File + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type ResetClusterAdminTokenRequest struct { + Region scw.Region `json:"-"` + // ClusterID the ID of the cluster of which the admin token will be renewed + ClusterID string `json:"-"` +} + +// ResetClusterAdminToken reset the admin token of a cluster +// +// This method allows to reset the admin token for a specific Kubernetes cluster. This will invalidate the old admin token (which will not be usable after) and create a new one. Note that the redownload of the kubeconfig will be necessary to keep interacting with the cluster (if the old admin token was used). +func (s *API) ResetClusterAdminToken(req *ResetClusterAdminTokenRequest, opts ...scw.RequestOption) error { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.ClusterID) == "" { + return errors.New("field ClusterID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/clusters/" + fmt.Sprint(req.ClusterID) + "/reset-admin-token", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return err + } + + err = s.client.Do(scwReq, nil, opts...) + if err != nil { + return err + } + return nil +} + +type ListPoolsRequest struct { + Region scw.Region `json:"-"` + // ClusterID the ID of the cluster from which the pools will be listed from + ClusterID string `json:"-"` + // OrderBy the sort order of the returned pools + // + // Default value: created_at_asc + OrderBy ListPoolsRequestOrderBy `json:"-"` + // Page the page number for the returned pools + Page *int32 `json:"-"` + // PageSize the maximum number of pools per page + PageSize *uint32 `json:"-"` + // Name the name on which to filter the retured clusters + Name *string `json:"-"` +} + +// ListPools list all the pools in a cluster +// +// This method allows to list all the existing pools for a specific Kubernetes cluster. +func (s *API) ListPools(req *ListPoolsRequest, opts ...scw.RequestOption) (*ListPoolsResponse, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + defaultPageSize, exist := s.client.GetDefaultPageSize() + if (req.PageSize == nil || *req.PageSize == 0) && exist { + req.PageSize = &defaultPageSize + } + + query := url.Values{} + parameter.AddToQuery(query, "order_by", req.OrderBy) + parameter.AddToQuery(query, "page", req.Page) + parameter.AddToQuery(query, "page_size", req.PageSize) + parameter.AddToQuery(query, "name", req.Name) + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.ClusterID) == "" { + return nil, errors.New("field ClusterID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/clusters/" + fmt.Sprint(req.ClusterID) + "/pools", + Query: query, + Headers: http.Header{}, + } + + var resp ListPoolsResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// UnsafeGetTotalCount should not be used +// Internal usage only +func (r *ListPoolsResponse) UnsafeGetTotalCount() uint32 { + return r.TotalCount +} + +// UnsafeAppend should not be used +// Internal usage only +func (r *ListPoolsResponse) UnsafeAppend(res interface{}) (uint32, error) { + results, ok := res.(*ListPoolsResponse) + if !ok { + return 0, errors.New("%T type cannot be appended to type %T", res, r) + } + + r.Pools = append(r.Pools, results.Pools...) + r.TotalCount += uint32(len(results.Pools)) + return uint32(len(results.Pools)), nil +} + +type CreatePoolRequest struct { + Region scw.Region `json:"-"` + // ClusterID the ID of the cluster in which the pool will be created + ClusterID string `json:"-"` + // Name the name of the pool + Name string `json:"name"` + // NodeType the node type is the type of Scaleway Instance wanted for the pool + NodeType string `json:"node_type"` + // PlacementGroupID the placement group ID in which all the nodes of the pool will be created + PlacementGroupID *string `json:"placement_group_id"` + // Autoscaling the enablement of the autoscaling feature for the pool + Autoscaling bool `json:"autoscaling"` + // Size the size (number of nodes) of the pool + Size uint32 `json:"size"` + // MinSize the minimun size of the pool + // + // The minimun size of the pool. Note that this fields will be used only when autoscaling is enabled. + MinSize *uint32 `json:"min_size"` + // MaxSize the maximum size of the pool + // + // The maximum size of the pool. Note that this fields will be used only when autoscaling is enabled. + MaxSize *uint32 `json:"max_size"` + // ContainerRuntime the container runtime for the nodes of the pool + // + // The customization of the container runtime is available for each pool. Note that `docker` is the only supporter runtime at the moment. Others are to be considered experimental. + // + // Default value: unknown_runtime + ContainerRuntime Runtime `json:"container_runtime"` + // Autohealing the enablement of the autohealing feature for the pool + Autohealing bool `json:"autohealing"` + // Tags the tags associated with the pool + Tags []string `json:"tags"` +} + +// CreatePool create a new pool in a cluster +// +// This method allows to create a new pool in a specific Kubernetes cluster. +func (s *API) CreatePool(req *CreatePoolRequest, opts ...scw.RequestOption) (*Pool, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.ClusterID) == "" { + return nil, errors.New("field ClusterID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/clusters/" + fmt.Sprint(req.ClusterID) + "/pools", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Pool + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type GetPoolRequest struct { + Region scw.Region `json:"-"` + // PoolID the ID of the requested pool + PoolID string `json:"-"` +} + +// GetPool get a pool in a cluster +// +// This method allows to get details about a specific pool. +func (s *API) GetPool(req *GetPoolRequest, opts ...scw.RequestOption) (*Pool, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.PoolID) == "" { + return nil, errors.New("field PoolID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/pools/" + fmt.Sprint(req.PoolID) + "", + Headers: http.Header{}, + } + + var resp Pool + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type UpgradePoolRequest struct { + Region scw.Region `json:"-"` + // PoolID the ID of the pool to upgrade + PoolID string `json:"-"` + // Version the new Kubernetes version for the pool + Version string `json:"version"` +} + +// UpgradePool upgrade a pool in a cluster +// +// This method allows to upgrade a specific pool. Note that this will work when the targeted version is the same than the version of the cluster. +func (s *API) UpgradePool(req *UpgradePoolRequest, opts ...scw.RequestOption) (*Pool, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.PoolID) == "" { + return nil, errors.New("field PoolID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/pools/" + fmt.Sprint(req.PoolID) + "/upgrade", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Pool + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type UpdatePoolRequest struct { + Region scw.Region `json:"-"` + // PoolID the ID of the pool to update + PoolID string `json:"-"` + // Autoscaling the new value for the enablement of autoscaling for the pool + Autoscaling *bool `json:"autoscaling"` + // Size the new size for the pool + Size *uint32 `json:"size"` + // MinSize the new minimun size for the pool + MinSize *uint32 `json:"min_size"` + // MaxSize the new maximum size for the pool + MaxSize *uint32 `json:"max_size"` + // Autohealing the new value for the enablement of autohealing for the pool + Autohealing *bool `json:"autohealing"` + // Tags the new tags associated with the pool + Tags *[]string `json:"tags"` +} + +// UpdatePool update a pool in a cluster +// +// This method allows to update a specific pool. +func (s *API) UpdatePool(req *UpdatePoolRequest, opts ...scw.RequestOption) (*Pool, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.PoolID) == "" { + return nil, errors.New("field PoolID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "PATCH", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/pools/" + fmt.Sprint(req.PoolID) + "", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Pool + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type DeletePoolRequest struct { + Region scw.Region `json:"-"` + // PoolID the ID of the pool to delete + PoolID string `json:"-"` +} + +// DeletePool delete a pool in a cluster +// +// This method allows to delete a specific pool from a cluster, deleting all the nodes associated with it. +func (s *API) DeletePool(req *DeletePoolRequest, opts ...scw.RequestOption) (*Pool, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.PoolID) == "" { + return nil, errors.New("field PoolID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "DELETE", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/pools/" + fmt.Sprint(req.PoolID) + "", + Headers: http.Header{}, + } + + var resp Pool + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type ListNodesRequest struct { + Region scw.Region `json:"-"` + // ClusterID the cluster ID from which the nodes will be listed from + ClusterID string `json:"-"` + // PoolID the pool ID on which to filter the returned nodes + PoolID *string `json:"-"` + // OrderBy the sort order of the returned nodes + // + // Default value: created_at_asc + OrderBy ListNodesRequestOrderBy `json:"-"` + // Page the page number for the returned nodes + Page *int32 `json:"-"` + // PageSize the maximum number of nodes per page + PageSize *uint32 `json:"-"` + // Name the name on which to filter the retured nodes + Name *string `json:"-"` + // Status the status on which to filter the returned nodes + // + // Default value: unknown + Status NodeStatus `json:"-"` +} + +// ListNodes list all the nodes in a cluster +// +// This method allows to list all the existing nodes for a specific Kubernetes cluster. +func (s *API) ListNodes(req *ListNodesRequest, opts ...scw.RequestOption) (*ListNodesResponse, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + defaultPageSize, exist := s.client.GetDefaultPageSize() + if (req.PageSize == nil || *req.PageSize == 0) && exist { + req.PageSize = &defaultPageSize + } + + query := url.Values{} + parameter.AddToQuery(query, "pool_id", req.PoolID) + parameter.AddToQuery(query, "order_by", req.OrderBy) + parameter.AddToQuery(query, "page", req.Page) + parameter.AddToQuery(query, "page_size", req.PageSize) + parameter.AddToQuery(query, "name", req.Name) + parameter.AddToQuery(query, "status", req.Status) + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.ClusterID) == "" { + return nil, errors.New("field ClusterID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/clusters/" + fmt.Sprint(req.ClusterID) + "/nodes", + Query: query, + Headers: http.Header{}, + } + + var resp ListNodesResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// UnsafeGetTotalCount should not be used +// Internal usage only +func (r *ListNodesResponse) UnsafeGetTotalCount() uint32 { + return r.TotalCount +} + +// UnsafeAppend should not be used +// Internal usage only +func (r *ListNodesResponse) UnsafeAppend(res interface{}) (uint32, error) { + results, ok := res.(*ListNodesResponse) + if !ok { + return 0, errors.New("%T type cannot be appended to type %T", res, r) + } + + r.Nodes = append(r.Nodes, results.Nodes...) + r.TotalCount += uint32(len(results.Nodes)) + return uint32(len(results.Nodes)), nil +} + +type GetNodeRequest struct { + Region scw.Region `json:"-"` + // NodeID the ID of the requested node + NodeID string `json:"-"` +} + +// GetNode get a node in a cluster +// +// This method allows to get details about a specific Kubernetes node. +func (s *API) GetNode(req *GetNodeRequest, opts ...scw.RequestOption) (*Node, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.NodeID) == "" { + return nil, errors.New("field NodeID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/nodes/" + fmt.Sprint(req.NodeID) + "", + Headers: http.Header{}, + } + + var resp Node + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type ReplaceNodeRequest struct { + Region scw.Region `json:"-"` + // NodeID the ID of the node to replace + NodeID string `json:"-"` +} + +// ReplaceNode replace a node in a cluster +// +// This method allows to replace a specific node. The node will be set cordoned, meaning that scheduling will be disabled. Then the existing pods on the node will be drained and reschedule onto another schedulable node. Then the node will be deleted, and a new one will be created after the deletion. Note that when there is not enough space to reschedule all the pods (in a one node cluster for instance), you may experience some disruption of your applications. +func (s *API) ReplaceNode(req *ReplaceNodeRequest, opts ...scw.RequestOption) (*Node, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.NodeID) == "" { + return nil, errors.New("field NodeID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/nodes/" + fmt.Sprint(req.NodeID) + "/replace", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Node + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type RebootNodeRequest struct { + Region scw.Region `json:"-"` + // NodeID the ID of the node to reboot + NodeID string `json:"-"` +} + +// RebootNode reboot a node in a cluster +// +// This method allows to reboot a specific node. This node will frist be cordoned, meaning that scheduling will be disabled. Then the existing pods on the node will be drained and reschedule onto another schedulable node. Note that when there is not enough space to reschedule all the pods (in a one node cluster for instance), you may experience some disruption of your applications. +func (s *API) RebootNode(req *RebootNodeRequest, opts ...scw.RequestOption) (*Node, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.NodeID) == "" { + return nil, errors.New("field NodeID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/nodes/" + fmt.Sprint(req.NodeID) + "/reboot", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Node + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +type ListVersionsRequest struct { + Region scw.Region `json:"-"` +} + +// ListVersions list all available versions +// +// This method allows to list all available versions for the creation of a new Kubernetes cluster. +func (s *API) ListVersions(req *ListVersionsRequest, opts ...scw.RequestOption) (*ListVersionsResponse, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/k8s/v1beta4/regions/" + fmt.Sprint(req.Region) + "/versions", + Headers: http.Header{}, + } + + var resp ListVersionsResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} diff --git a/api/lb/v1/lb_sdk.go b/api/lb/v1/lb_sdk.go index c710df07e..62a747793 100644 --- a/api/lb/v1/lb_sdk.go +++ b/api/lb/v1/lb_sdk.go @@ -585,6 +585,42 @@ func (enum *ListLbsRequestOrderBy) UnmarshalJSON(data []byte) error { return nil } +type ListSubscriberRequestOrderBy string + +const ( + // ListSubscriberRequestOrderByCreatedAtAsc is [insert doc]. + ListSubscriberRequestOrderByCreatedAtAsc = ListSubscriberRequestOrderBy("created_at_asc") + // ListSubscriberRequestOrderByCreatedAtDesc is [insert doc]. + ListSubscriberRequestOrderByCreatedAtDesc = ListSubscriberRequestOrderBy("created_at_desc") + // ListSubscriberRequestOrderByNameAsc is [insert doc]. + ListSubscriberRequestOrderByNameAsc = ListSubscriberRequestOrderBy("name_asc") + // ListSubscriberRequestOrderByNameDesc is [insert doc]. + ListSubscriberRequestOrderByNameDesc = ListSubscriberRequestOrderBy("name_desc") +) + +func (enum ListSubscriberRequestOrderBy) String() string { + if enum == "" { + // return default value if empty + return "created_at_asc" + } + return string(enum) +} + +func (enum ListSubscriberRequestOrderBy) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, enum)), nil +} + +func (enum *ListSubscriberRequestOrderBy) UnmarshalJSON(data []byte) error { + tmp := "" + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + *enum = ListSubscriberRequestOrderBy(ListSubscriberRequestOrderBy(tmp).String()) + return nil +} + type OnMarkedDownAction string const ( @@ -946,26 +982,6 @@ type HealthCheck struct { CheckDelay *time.Duration `json:"check_delay"` } -func (m *HealthCheck) GetConfig() Config { - switch { - case m.MysqlConfig != nil: - return ConfigMysqlConfig{*m.MysqlConfig} - case m.LdapConfig != nil: - return ConfigLdapConfig{*m.LdapConfig} - case m.RedisConfig != nil: - return ConfigRedisConfig{*m.RedisConfig} - case m.TCPConfig != nil: - return ConfigTCPConfig{*m.TCPConfig} - case m.PgsqlConfig != nil: - return ConfigPgsqlConfig{*m.PgsqlConfig} - case m.HTTPConfig != nil: - return ConfigHTTPConfig{*m.HTTPConfig} - case m.HTTPSConfig != nil: - return ConfigHTTPSConfig{*m.HTTPSConfig} - } - return nil -} - func (m *HealthCheck) UnmarshalJSON(b []byte) error { type tmpType HealthCheck tmp := struct { @@ -1088,6 +1104,8 @@ type Lb struct { Type string `json:"type"` + Subscriber *Subscriber `json:"subscriber"` + Region scw.Region `json:"region"` } @@ -1168,6 +1186,40 @@ type ListLbsResponse struct { TotalCount uint32 `json:"total_count"` } +// ListSubscriberResponse list subscriber response +type ListSubscriberResponse struct { + // Subscribers list of Subscribers object + Subscribers []*Subscriber `json:"subscribers"` + // TotalCount the total number of items + TotalCount uint32 `json:"total_count"` +} + +// Subscriber subscriber +type Subscriber struct { + // ID subscriber ID + ID string `json:"id"` + // Name subscriber name + Name string `json:"name"` + // EmailConfig email address of subscriber + // Precisely one of EmailConfig, WebhookConfig must be set. + EmailConfig *SubscriberEmailConfig `json:"email_config,omitempty"` + // WebhookConfig webHook URI of subscriber + // Precisely one of EmailConfig, WebhookConfig must be set. + WebhookConfig *SubscriberWebhookConfig `json:"webhook_config,omitempty"` +} + +// SubscriberEmailConfig email alert of subscriber +type SubscriberEmailConfig struct { + // Email email who receive alert + Email string `json:"email"` +} + +// SubscriberWebhookConfig webhook alert of subscriber +type SubscriberWebhookConfig struct { + // URI uRI who receive POST request + URI string `json:"uri"` +} + // Service API type GetServiceInfoRequest struct { @@ -1602,6 +1654,49 @@ func (s *API) ReleaseIP(req *ReleaseIPRequest, opts ...scw.RequestOption) error return nil } +type UpdateIPRequest struct { + Region scw.Region `json:"-"` + // IPID iP address ID + IPID string `json:"-"` + // Reverse reverse DNS + Reverse *string `json:"-"` +} + +func (s *API) UpdateIP(req *UpdateIPRequest, opts ...scw.RequestOption) (*IP, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + query := url.Values{} + parameter.AddToQuery(query, "reverse", req.Reverse) + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.IPID) == "" { + return nil, errors.New("field IPID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "PATCH", + Path: "/lb/v1/regions/" + fmt.Sprint(req.Region) + "/ips/" + fmt.Sprint(req.IPID) + "", + Query: query, + Headers: http.Header{}, + } + + var resp IP + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + type ListBackendsRequest struct { Region scw.Region `json:"-"` // LbID load Balancer ID @@ -2147,26 +2242,6 @@ type UpdateHealthCheckRequest struct { HTTPSConfig *HealthCheckHTTPSConfig `json:"https_config,omitempty"` } -func (m *UpdateHealthCheckRequest) GetConfig() Config { - switch { - case m.MysqlConfig != nil: - return ConfigMysqlConfig{*m.MysqlConfig} - case m.LdapConfig != nil: - return ConfigLdapConfig{*m.LdapConfig} - case m.RedisConfig != nil: - return ConfigRedisConfig{*m.RedisConfig} - case m.PgsqlConfig != nil: - return ConfigPgsqlConfig{*m.PgsqlConfig} - case m.TCPConfig != nil: - return ConfigTCPConfig{*m.TCPConfig} - case m.HTTPConfig != nil: - return ConfigHTTPConfig{*m.HTTPConfig} - case m.HTTPSConfig != nil: - return ConfigHTTPSConfig{*m.HTTPSConfig} - } - return nil -} - func (m *UpdateHealthCheckRequest) UnmarshalJSON(b []byte) error { type tmpType UpdateHealthCheckRequest tmp := struct { @@ -2928,16 +3003,6 @@ type CreateCertificateRequest struct { CustomCertificate *CreateCertificateRequestCustomCertificate `json:"custom_certificate,omitempty"` } -func (m *CreateCertificateRequest) GetType() Type { - switch { - case m.Letsencrypt != nil: - return TypeLetsencrypt{*m.Letsencrypt} - case m.CustomCertificate != nil: - return TypeCustomCertificate{*m.CustomCertificate} - } - return nil -} - // CreateCertificate create Certificate // // Generate a new SSL certificate using Let's Encrypt or import your certificate. @@ -3240,73 +3305,338 @@ func (r *ListLbTypesResponse) UnsafeAppend(res interface{}) (uint32, error) { return uint32(len(results.LbTypes)), nil } -type Config interface { - isConfig() +type CreateSubscriberRequest struct { + Region scw.Region `json:"-"` + // Name subscriber name + Name string `json:"name"` + // EmailConfig email address configuration + // Precisely one of EmailConfig, WebhookConfig must be set. + EmailConfig *SubscriberEmailConfig `json:"email_config,omitempty"` + // WebhookConfig webHook URI configuration + // Precisely one of EmailConfig, WebhookConfig must be set. + WebhookConfig *SubscriberWebhookConfig `json:"webhook_config,omitempty"` + // OrganizationID owner of resources + OrganizationID string `json:"organization_id"` } -type ConfigMysqlConfig struct { - Value HealthCheckMysqlConfig -} +// CreateSubscriber create a subscriber, webhook or email +func (s *API) CreateSubscriber(req *CreateSubscriberRequest, opts ...scw.RequestOption) (*Subscriber, error) { + var err error -func (ConfigMysqlConfig) isConfig() { -} + if req.OrganizationID == "" { + defaultOrganizationID, _ := s.client.GetDefaultOrganizationID() + req.OrganizationID = defaultOrganizationID + } -type ConfigLdapConfig struct { - Value HealthCheckLdapConfig -} + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } -func (ConfigLdapConfig) isConfig() { -} + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/lb/v1/regions/" + fmt.Sprint(req.Region) + "/subscribers", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Subscriber -type ConfigRedisConfig struct { - Value HealthCheckRedisConfig + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil } -func (ConfigRedisConfig) isConfig() { +type GetSubscriberRequest struct { + Region scw.Region `json:"-"` + // SubscriberID subscriber ID + SubscriberID string `json:"-"` } -type ConfigPgsqlConfig struct { - Value HealthCheckPgsqlConfig +// GetSubscriber get a subscriber +func (s *API) GetSubscriber(req *GetSubscriberRequest, opts ...scw.RequestOption) (*Subscriber, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.SubscriberID) == "" { + return nil, errors.New("field SubscriberID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/lb/v1/regions/" + fmt.Sprint(req.Region) + "/subscribers/" + fmt.Sprint(req.SubscriberID) + "", + Headers: http.Header{}, + } + + var resp Subscriber + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil } -func (ConfigPgsqlConfig) isConfig() { +type ListSubscriberRequest struct { + Region scw.Region `json:"-"` + // OrderBy you can order the response by created_at asc/desc or name asc/desc + // + // Default value: created_at_asc + OrderBy ListSubscriberRequestOrderBy `json:"-"` + // Page page number + Page *int32 `json:"-"` + // PageSize the number of items to return + PageSize *uint32 `json:"-"` + // Name use this to search by name + Name *string `json:"-"` + // OrganizationID owner of resources + OrganizationID *string `json:"-"` } -type ConfigTCPConfig struct { - Value HealthCheckTCPConfig +// ListSubscriber list all subscriber +func (s *API) ListSubscriber(req *ListSubscriberRequest, opts ...scw.RequestOption) (*ListSubscriberResponse, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + defaultPageSize, exist := s.client.GetDefaultPageSize() + if (req.PageSize == nil || *req.PageSize == 0) && exist { + req.PageSize = &defaultPageSize + } + + query := url.Values{} + parameter.AddToQuery(query, "order_by", req.OrderBy) + parameter.AddToQuery(query, "page", req.Page) + parameter.AddToQuery(query, "page_size", req.PageSize) + parameter.AddToQuery(query, "name", req.Name) + parameter.AddToQuery(query, "organization_id", req.OrganizationID) + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/lb/v1/regions/" + fmt.Sprint(req.Region) + "/subscribers", + Query: query, + Headers: http.Header{}, + } + + var resp ListSubscriberResponse + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil } -func (ConfigTCPConfig) isConfig() { +// UnsafeGetTotalCount should not be used +// Internal usage only +func (r *ListSubscriberResponse) UnsafeGetTotalCount() uint32 { + return r.TotalCount } -type ConfigHTTPConfig struct { - Value HealthCheckHTTPConfig +// UnsafeAppend should not be used +// Internal usage only +func (r *ListSubscriberResponse) UnsafeAppend(res interface{}) (uint32, error) { + results, ok := res.(*ListSubscriberResponse) + if !ok { + return 0, errors.New("%T type cannot be appended to type %T", res, r) + } + + r.Subscribers = append(r.Subscribers, results.Subscribers...) + r.TotalCount += uint32(len(results.Subscribers)) + return uint32(len(results.Subscribers)), nil } -func (ConfigHTTPConfig) isConfig() { +type UpdateSubscriberRequest struct { + Region scw.Region `json:"-"` + // SubscriberID subscriber ID + SubscriberID string `json:"-"` + // Name subscriber name + Name string `json:"name"` + // EmailConfig email address configuration + // Precisely one of EmailConfig, WebhookConfig must be set. + EmailConfig *SubscriberEmailConfig `json:"email_config,omitempty"` + // WebhookConfig webHook URI configuration + // Precisely one of EmailConfig, WebhookConfig must be set. + WebhookConfig *SubscriberWebhookConfig `json:"webhook_config,omitempty"` } -type ConfigHTTPSConfig struct { - Value HealthCheckHTTPSConfig +// UpdateSubscriber update a subscriber +func (s *API) UpdateSubscriber(req *UpdateSubscriberRequest, opts ...scw.RequestOption) (*Subscriber, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.SubscriberID) == "" { + return nil, errors.New("field SubscriberID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "PUT", + Path: "/lb/v1/regions/" + fmt.Sprint(req.Region) + "/subscribers/" + fmt.Sprint(req.SubscriberID) + "", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Subscriber + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil } -func (ConfigHTTPSConfig) isConfig() { +type DeleteSubscriberRequest struct { + Region scw.Region `json:"-"` + // SubscriberID subscriber ID + SubscriberID string `json:"-"` } -type Type interface { - isType() +// DeleteSubscriber delete a subscriber +func (s *API) DeleteSubscriber(req *DeleteSubscriberRequest, opts ...scw.RequestOption) error { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.SubscriberID) == "" { + return errors.New("field SubscriberID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "DELETE", + Path: "/lb/v1/regions/" + fmt.Sprint(req.Region) + "/lb/subscription/" + fmt.Sprint(req.SubscriberID) + "", + Headers: http.Header{}, + } + + err = s.client.Do(scwReq, nil, opts...) + if err != nil { + return err + } + return nil } -type TypeLetsencrypt struct { - Value CreateCertificateRequestLetsencryptConfig +type SubscribeToLbRequest struct { + Region scw.Region `json:"-"` + // LbID load Balancer ID + LbID string `json:"-"` + // SubscriberID subscriber ID + SubscriberID string `json:"subscriber_id"` } -func (TypeLetsencrypt) isType() { +// SubscribeToLb link Load Balancer to a subscriber +func (s *API) SubscribeToLb(req *SubscribeToLbRequest, opts ...scw.RequestOption) (*Lb, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.LbID) == "" { + return nil, errors.New("field LbID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/lb/v1/regions/" + fmt.Sprint(req.Region) + "/lb/" + fmt.Sprint(req.LbID) + "/subscribe", + Headers: http.Header{}, + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Lb + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil } -type TypeCustomCertificate struct { - Value CreateCertificateRequestCustomCertificate +type UnsubscribeFromLbRequest struct { + Region scw.Region `json:"-"` + // LbID load Balancer ID + LbID string `json:"-"` } -func (TypeCustomCertificate) isType() { +// UnsubscribeFromLb remove link between Load Balancer and subscriber +func (s *API) UnsubscribeFromLb(req *UnsubscribeFromLbRequest, opts ...scw.RequestOption) (*Lb, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.LbID) == "" { + return nil, errors.New("field LbID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "DELETE", + Path: "/lb/v1/regions/" + fmt.Sprint(req.Region) + "/lb/" + fmt.Sprint(req.LbID) + "/unsubscribe", + Headers: http.Header{}, + } + + var resp Lb + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil } diff --git a/api/test/v1/test_sdk.go b/api/test/v1/test_sdk.go index df7c67065..342967aa1 100644 --- a/api/test/v1/test_sdk.go +++ b/api/test/v1/test_sdk.go @@ -38,6 +38,15 @@ var ( ) // API no Auth Service for end-to-end testing +// +// Test is a fake service that aim to manage fake humans. It is used for internal and public end-to-end tests. +// +// This service don't use the Scaleway authentication service but a fake one. It allows to use this test +// service publicly without requiring a Scaleway account. +// +// First, you need to register a user with `scw test human register` to get an access-key. Then, you can use +// other test commands by setting the SCW_SECRET_KEY env variable. +// type API struct { client *scw.Client } @@ -223,6 +232,12 @@ type RegisterRequest struct { Username string `json:"username"` } +// Register register a user +// +// Register a human and return a access-key and a secret-key that must be used in all other commands. +// +// Hint: you can use other test commands by setting the SCW_SECRET_KEY env variable. +// func (s *API) Register(req *RegisterRequest, opts ...scw.RequestOption) (*RegisterResponse, error) { var err error @@ -539,6 +554,9 @@ type RunHumanRequest struct { HumanID string `json:"-"` } +// RunHuman start a 1h running for the given human +// +// Start a one hour running for the given human. func (s *API) RunHuman(req *RunHumanRequest, opts ...scw.RequestOption) (*Human, error) { var err error