Skip to content

Commit

Permalink
Merge pull request #6 from SchwarzIT/fix/ske-cluster-list
Browse files Browse the repository at this point in the history
Fix/ske cluster list
  • Loading branch information
do87 authored Sep 30, 2022
2 parents 13b9e06 + 319658a commit 24c5cf7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func main() {

Another usage example can be found in [`terraform-provider-stackit`](https://github.com/SchwarzIT/terraform-provider-stackit) which is built using the community client

[^1]: In order to use the client, a Service Account and Token must be created [using the Service Account API](https://api.stackit.schwarz/service-account/openapi.v1.html#operation/post-projects-projectId-service-accounts-v2)<br />
[^1]: In order to use the client, a Service Account and Token must be created using [Service Account API](https://api.stackit.schwarz/service-account/openapi.v1.html#operation/post-projects-projectId-service-accounts-v2)<br />
After creation, assign roles to the Service Account using [Membership API](https://api.stackit.schwarz/membership-service/openapi.v1.html#operation/post-organizations-organizationId-projects-projectId-roles-roleName-service-accounts)<br />
If your Service Account needs to operate outside the scope of your project, you may need to contact STACKIT to assign further permissions

Expand Down
7 changes: 6 additions & 1 deletion pkg/api/v1/kubernetes/clusters/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func New(c common.Client) *KubernetesClusterService {
// CRUD functionality for SKE clusters
type KubernetesClusterService common.Service

// ClusterList is the response for listing clusters
type ClusterList struct {
Items []Cluster `json:"items"`
}

// Cluster is a struct representation of a cluster in STACKIT api
type Cluster struct {
Name string `json:"name"` // 11 lowercase letters, numbers, or hyphens
Expand Down Expand Up @@ -146,7 +151,7 @@ type Status struct {

// List returns the clusters in the project
// See also https://api.stackit.schwarz/ske-service/openapi.v1.html#operation/SkeService_ListClusters
func (svc *KubernetesClusterService) List(ctx context.Context, projectID string) (res []Cluster, err error) {
func (svc *KubernetesClusterService) List(ctx context.Context, projectID string) (res ClusterList, err error) {
req, err := svc.Client.Request(ctx, http.MethodGet, fmt.Sprintf(apiPath, projectID), nil)
if err != nil {
return
Expand Down
20 changes: 11 additions & 9 deletions pkg/api/v1/kubernetes/clusters/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"reflect"
"testing"

"github.com/SchwarzIT/community-stackit-go-client"
client "github.com/SchwarzIT/community-stackit-go-client"
"github.com/SchwarzIT/community-stackit-go-client/pkg/api/v1/kubernetes"
"github.com/SchwarzIT/community-stackit-go-client/pkg/api/v1/kubernetes/clusters"
"github.com/SchwarzIT/community-stackit-go-client/pkg/consts"
Expand Down Expand Up @@ -256,13 +256,15 @@ func TestKubernetesClusterService_List(t *testing.T) {

projectID := "5dae0612-f5b1-4615-b7ca-b18796aa7e78"
clusterName := "cname"
want := []clusters.Cluster{{
Name: clusterName,
Kubernetes: k_ok,
Nodepools: np_ok,
Maintenance: m_ok,
Hibernation: h_ok,
}}
want := clusters.ClusterList{
Items: []clusters.Cluster{{
Name: clusterName,
Kubernetes: k_ok,
Nodepools: np_ok,
Maintenance: m_ok,
Hibernation: h_ok,
}},
}

mux.HandleFunc("/ske/v1/projects/"+projectID+"/clusters", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
Expand All @@ -286,7 +288,7 @@ func TestKubernetesClusterService_List(t *testing.T) {
tests := []struct {
name string
args args
wantRes []clusters.Cluster
wantRes clusters.ClusterList
wantErr bool
}{
{"ctx is canceled", args{ctx_bad, projectID}, want, true},
Expand Down

0 comments on commit 24c5cf7

Please sign in to comment.