Skip to content

Commit

Permalink
feat(kubernetes): add cluster labels
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta committed Jan 25, 2024
1 parent 59b0f32 commit 0f2f12d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

### Added
- Kubernetes: support for cluster labels.

### Changed
- **Breaking** Kubernetes: the `ControlPlaneIPFilter` of `ModifyKubernetesCluster` is changed from `[]string` to `*[]string`.

### Removed
- **Breaking**, Managed Database: connection related methods in favor of session

Expand Down
1 change: 1 addition & 0 deletions upcloud/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type (

type KubernetesCluster struct {
ControlPlaneIPFilter []string `json:"control_plane_ip_filter"`
Labels []Label `json:"labels"`
Name string `json:"name"`
Network string `json:"network"`
NetworkCIDR string `json:"network_cidr"`
Expand Down
4 changes: 3 additions & 1 deletion upcloud/request/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (r *GetKubernetesClusterRequest) RequestURL() string {
// CreateKubernetesClusterRequest represents a request to create a Kubernetes cluster
type CreateKubernetesClusterRequest struct {
ControlPlaneIPFilter []string `json:"control_plane_ip_filter"`
Labels []upcloud.Label `json:"labels,omitempty"`
Name string `json:"name"`
Network string `json:"network"`
NetworkCIDR string `json:"network_cidr"`
Expand All @@ -64,7 +65,8 @@ func (r *CreateKubernetesClusterRequest) RequestURL() string {
}

type ModifyKubernetesCluster struct {
ControlPlaneIPFilter []string `json:"control_plane_ip_filter"`
ControlPlaneIPFilter *[]string `json:"control_plane_ip_filter,omitempty"`
Labels *[]upcloud.Label `json:"labels,omitempty"`
}

type ModifyKubernetesClusterRequest struct {
Expand Down
63 changes: 44 additions & 19 deletions upcloud/request/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,27 +178,52 @@ func TestKubernetes(t *testing.T) {
t.Run("ModifyKubernetesClusterRequestMarshal", func(t *testing.T) {
t.Parallel()

expected := `{ "control_plane_ip_filter": ["0.0.0.0/0"] }`

uuid := "this-is-the-uuid-you-are-looking-for"
r := ModifyKubernetesClusterRequest{
ClusterUUID: uuid,
Cluster: ModifyKubernetesCluster{
ControlPlaneIPFilter: []string{"0.0.0.0/0"},
tests := []struct {
request ModifyKubernetesClusterRequest
expected string
}{
{
request: ModifyKubernetesClusterRequest{
ClusterUUID: "set-filter-omit-labels",
Cluster: ModifyKubernetesCluster{
ControlPlaneIPFilter: &[]string{"0.0.0.0/0"},
},
},
expected: `{ "control_plane_ip_filter": ["0.0.0.0/0"] }`,
},
{
request: ModifyKubernetesClusterRequest{
ClusterUUID: "omit-filter-set-labels",
Cluster: ModifyKubernetesCluster{
Labels: &[]upcloud.Label{{Key: "tool", Value: "Go SDK"}},
},
},
expected: `{ "labels": [{"key": "tool", "value": "Go SDK"}] }`,
},
{
request: ModifyKubernetesClusterRequest{
ClusterUUID: "clear-filter-clear-labels",
Cluster: ModifyKubernetesCluster{
ControlPlaneIPFilter: &[]string{},
Labels: &[]upcloud.Label{},
},
},
expected: `{ "control_plane_ip_filter": [], "labels": [] }`,
},
}

assert.Equal(t, fmt.Sprintf("%s/%s", kubernetesClusterBasePath, uuid), r.RequestURL())

b, err := json.Marshal(&r)
actual := string(b)

assert.NoError(t, err)
assert.JSONEq(
t,
expected,
actual,
)
for _, test := range tests {
assert.Equal(t, fmt.Sprintf("%s/%s", kubernetesClusterBasePath, test.request.ClusterUUID), test.request.RequestURL())

b, err := json.Marshal(&test.request)
actual := string(b)

assert.NoError(t, err)
assert.JSONEq(
t,
test.expected,
actual,
)
}
})

t.Run("DeleteKubernetesClusterRequest", func(t *testing.T) {
Expand Down

0 comments on commit 0f2f12d

Please sign in to comment.