Skip to content

Commit 8866bd0

Browse files
feat(k8s): add project support (#517)
Co-authored-by: Jerome Quere <[email protected]>
1 parent aaf77f0 commit 8866bd0

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

api/k8s/v1/k8s_sdk.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,8 @@ type Cluster struct {
555555
Region scw.Region `json:"region"`
556556
// OrganizationID: the ID of the organization owning the cluster
557557
OrganizationID string `json:"organization_id"`
558+
// ProjectID: the ID of the project owning the cluster
559+
ProjectID string `json:"project_id"`
558560
// Tags: the tags associated with the cluster
559561
Tags []string `json:"tags"`
560562
// Cni: the Container Network Interface (CNI) plugin running in the cluster
@@ -872,6 +874,8 @@ type ListClustersRequest struct {
872874
Region scw.Region `json:"-"`
873875
// OrganizationID: the organization ID on which to filter the returned clusters
874876
OrganizationID *string `json:"-"`
877+
// ProjectID: the project ID on which to filter the returned clusters
878+
ProjectID *string `json:"-"`
875879
// OrderBy: the sort order of the returned clusters
876880
//
877881
// Default value: created_at_asc
@@ -906,6 +910,7 @@ func (s *API) ListClusters(req *ListClustersRequest, opts ...scw.RequestOption)
906910

907911
query := url.Values{}
908912
parameter.AddToQuery(query, "organization_id", req.OrganizationID)
913+
parameter.AddToQuery(query, "project_id", req.ProjectID)
909914
parameter.AddToQuery(query, "order_by", req.OrderBy)
910915
parameter.AddToQuery(query, "page", req.Page)
911916
parameter.AddToQuery(query, "page_size", req.PageSize)
@@ -954,7 +959,11 @@ func (r *ListClustersResponse) UnsafeAppend(res interface{}) (uint32, error) {
954959
type CreateClusterRequest struct {
955960
Region scw.Region `json:"-"`
956961
// OrganizationID: the organization ID where the cluster will be created
957-
OrganizationID string `json:"organization_id"`
962+
// Precisely one of OrganizationID, ProjectID must be set.
963+
OrganizationID *string `json:"organization_id,omitempty"`
964+
// ProjectID: the project ID where the cluster will be created
965+
// Precisely one of OrganizationID, ProjectID must be set.
966+
ProjectID *string `json:"project_id,omitempty"`
958967
// Name: the name of the cluster
959968
Name string `json:"name"`
960969
// Description: the description of the cluster
@@ -995,9 +1004,14 @@ type CreateClusterRequest struct {
9951004
func (s *API) CreateCluster(req *CreateClusterRequest, opts ...scw.RequestOption) (*Cluster, error) {
9961005
var err error
9971006

998-
if req.OrganizationID == "" {
999-
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
1000-
req.OrganizationID = defaultOrganizationID
1007+
defaultProjectID, exist := s.client.GetDefaultProjectID()
1008+
if exist && req.OrganizationID == nil && req.ProjectID == nil {
1009+
req.ProjectID = &defaultProjectID
1010+
}
1011+
1012+
defaultOrganizationID, exist := s.client.GetDefaultOrganizationID()
1013+
if exist && req.OrganizationID == nil && req.ProjectID == nil {
1014+
req.OrganizationID = &defaultOrganizationID
10011015
}
10021016

10031017
if req.Region == "" {

0 commit comments

Comments
 (0)