Skip to content

Commit 4b4bb03

Browse files
authored
feat(kubernetes): add cluster labels (#289)
1 parent eb75efb commit 4b4bb03

File tree

4 files changed

+50
-20
lines changed

4 files changed

+50
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)
77

88
### Added
99
- Managed Load Balancer: `MaintenanceDOW` and `MaintenanceTime` fields for controlling maintenance window occurrence
10+
- Kubernetes: support for cluster labels.
1011

1112
### Changed
1213
- **Breaking**, Managed Database: `ManagedDatabaseUserOpernSearchAccessControl` fields changed to pointers
@@ -15,6 +16,7 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)
1516
- **Breaking**, Managed Load Balancer: `LoadBalancerFrontendProperties` field `InboundProxyProtocol` to pointer
1617
- **Breaking**, Managed Object Storage: `CreateManagedObjectStorageUserAccessKeyRequest` field `Enabled` to pointer
1718
- **Breaking**, Managed Object Storage: `ModifyManagedObjectStorageUserAccessKeyRequest` field `Enabled` to pointer
19+
- **Breaking** Kubernetes: the `ControlPlaneIPFilter` of `ModifyKubernetesCluster` is changed from `[]string` to `*[]string`.
1820

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

upcloud/kubernetes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type (
3737

3838
type KubernetesCluster struct {
3939
ControlPlaneIPFilter []string `json:"control_plane_ip_filter"`
40+
Labels []Label `json:"labels"`
4041
Name string `json:"name"`
4142
Network string `json:"network"`
4243
NetworkCIDR string `json:"network_cidr"`

upcloud/request/kubernetes.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func (r *GetKubernetesClusterRequest) RequestURL() string {
4848
// CreateKubernetesClusterRequest represents a request to create a Kubernetes cluster
4949
type CreateKubernetesClusterRequest struct {
5050
ControlPlaneIPFilter []string `json:"control_plane_ip_filter"`
51+
Labels []upcloud.Label `json:"labels,omitempty"`
5152
Name string `json:"name"`
5253
Network string `json:"network"`
5354
NetworkCIDR string `json:"network_cidr"`
@@ -63,7 +64,8 @@ func (r *CreateKubernetesClusterRequest) RequestURL() string {
6364
}
6465

6566
type ModifyKubernetesCluster struct {
66-
ControlPlaneIPFilter []string `json:"control_plane_ip_filter"`
67+
ControlPlaneIPFilter *[]string `json:"control_plane_ip_filter,omitempty"`
68+
Labels *[]upcloud.Label `json:"labels,omitempty"`
6769
}
6870

6971
type ModifyKubernetesClusterRequest struct {

upcloud/request/kubernetes_test.go

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -178,27 +178,52 @@ func TestKubernetes(t *testing.T) {
178178
t.Run("ModifyKubernetesClusterRequestMarshal", func(t *testing.T) {
179179
t.Parallel()
180180

181-
expected := `{ "control_plane_ip_filter": ["0.0.0.0/0"] }`
182-
183-
uuid := "this-is-the-uuid-you-are-looking-for"
184-
r := ModifyKubernetesClusterRequest{
185-
ClusterUUID: uuid,
186-
Cluster: ModifyKubernetesCluster{
187-
ControlPlaneIPFilter: []string{"0.0.0.0/0"},
181+
tests := []struct {
182+
request ModifyKubernetesClusterRequest
183+
expected string
184+
}{
185+
{
186+
request: ModifyKubernetesClusterRequest{
187+
ClusterUUID: "set-filter-omit-labels",
188+
Cluster: ModifyKubernetesCluster{
189+
ControlPlaneIPFilter: &[]string{"0.0.0.0/0"},
190+
},
191+
},
192+
expected: `{ "control_plane_ip_filter": ["0.0.0.0/0"] }`,
193+
},
194+
{
195+
request: ModifyKubernetesClusterRequest{
196+
ClusterUUID: "omit-filter-set-labels",
197+
Cluster: ModifyKubernetesCluster{
198+
Labels: &[]upcloud.Label{{Key: "tool", Value: "Go SDK"}},
199+
},
200+
},
201+
expected: `{ "labels": [{"key": "tool", "value": "Go SDK"}] }`,
202+
},
203+
{
204+
request: ModifyKubernetesClusterRequest{
205+
ClusterUUID: "clear-filter-clear-labels",
206+
Cluster: ModifyKubernetesCluster{
207+
ControlPlaneIPFilter: &[]string{},
208+
Labels: &[]upcloud.Label{},
209+
},
210+
},
211+
expected: `{ "control_plane_ip_filter": [], "labels": [] }`,
188212
},
189213
}
190-
191-
assert.Equal(t, fmt.Sprintf("%s/%s", kubernetesClusterBasePath, uuid), r.RequestURL())
192-
193-
b, err := json.Marshal(&r)
194-
actual := string(b)
195-
196-
assert.NoError(t, err)
197-
assert.JSONEq(
198-
t,
199-
expected,
200-
actual,
201-
)
214+
for _, test := range tests {
215+
assert.Equal(t, fmt.Sprintf("%s/%s", kubernetesClusterBasePath, test.request.ClusterUUID), test.request.RequestURL())
216+
217+
b, err := json.Marshal(&test.request)
218+
actual := string(b)
219+
220+
assert.NoError(t, err)
221+
assert.JSONEq(
222+
t,
223+
test.expected,
224+
actual,
225+
)
226+
}
202227
})
203228

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

0 commit comments

Comments
 (0)