Skip to content

Commit 0441354

Browse files
feat(kubernetes): --disable-utility-network-access to nodegroup (#236)
1 parent 71a7636 commit 0441354

11 files changed

Lines changed: 116 additions & 69 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
### Added
10+
- Add `--disable-utility-network-access` for `kubernetes nodegroup create` command
911

1012
## [2.9.1] - 2023-07-06
1113
### Changed

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.20
44

55
require (
66
github.com/UpCloudLtd/progress v1.0.1
7-
github.com/UpCloudLtd/upcloud-go-api/v6 v6.3.2
7+
github.com/UpCloudLtd/upcloud-go-api/v6 v6.5.0
88
github.com/adrg/xdg v0.3.2
99
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
1010
github.com/gemalto/flume v0.12.0
@@ -29,7 +29,6 @@ require (
2929
github.com/gogo/protobuf v1.3.2 // indirect
3030
github.com/golang/protobuf v1.5.2 // indirect
3131
github.com/google/gofuzz v1.1.0 // indirect
32-
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
3332
github.com/hashicorp/hcl v1.0.0 // indirect
3433
github.com/imdario/mergo v0.3.6 // indirect
3534
github.com/inconshreveable/mousetrap v1.0.1 // indirect

go.sum

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN
4040
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
4141
github.com/UpCloudLtd/progress v1.0.1 h1:e0ptyD2oOGa3udRcLzgRemIN9enGx4Bc9GQ0sZ/1/EY=
4242
github.com/UpCloudLtd/progress v1.0.1/go.mod h1:hKsRsvlCffcYt/s0krpWvOFozOjpfUYjSkL6CzZztoI=
43-
github.com/UpCloudLtd/upcloud-go-api/v6 v6.3.2 h1:lxkQfdh+bY6YDwE+Qq3OCAbUhSEcdJiF1Fivmza78xE=
44-
github.com/UpCloudLtd/upcloud-go-api/v6 v6.3.2/go.mod h1:9y8kZ4o4jCagqLfexcnITY8uc/g4+uc18wbnMsDbQJI=
43+
github.com/UpCloudLtd/upcloud-go-api/v6 v6.5.0 h1:bOZY2kNRZo7J+9vgG37Z7S36Wb1SSoTNmg+RPaL6eJs=
44+
github.com/UpCloudLtd/upcloud-go-api/v6 v6.5.0/go.mod h1:I8rWmBBl+OhiY3AGzKbrobiE5TsLCLNYkCQxE4eJcTg=
4545
github.com/adrg/xdg v0.3.2 h1:GUSGQ5pHdev83AYhDSS1A/CX+0JIsxbiWtow2DSA+RU=
4646
github.com/adrg/xdg v0.3.2/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ=
4747
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
@@ -171,7 +171,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
171171
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
172172
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
173173
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
174-
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
175174
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
176175
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
177176
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=

internal/commands/database/connection/cancel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (s *cancelCommand) Execute(exec commands.Executor, uuid string) (output.Out
5050
msg := fmt.Sprintf("Cancelling connection %v to database %v", s.pid, uuid)
5151
exec.PushProgressStarted(msg)
5252

53-
if err := svc.CancelManagedDatabaseConnection(exec.Context(), &request.CancelManagedDatabaseConnection{
53+
if err := svc.CancelManagedDatabaseConnection(exec.Context(), &request.CancelManagedDatabaseConnection{ //nolint:staticcheck // Deprecated, replace in a feature PR
5454
UUID: uuid,
5555
Pid: s.pid,
5656
Terminate: s.terminate.Value(),

internal/commands/database/connection/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type listCommand struct {
2525
// Execute implements commands.MultipleArgumentCommand
2626
func (s *listCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) {
2727
svc := exec.All()
28-
connections, err := svc.GetManagedDatabaseConnections(exec.Context(), &request.GetManagedDatabaseConnectionsRequest{UUID: uuid})
28+
connections, err := svc.GetManagedDatabaseConnections(exec.Context(), &request.GetManagedDatabaseConnectionsRequest{UUID: uuid}) //nolint:staticcheck // Deprecated, replace in a feature PR
2929
if err != nil {
3030
return nil, err
3131
}

internal/commands/kubernetes/create_test.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ func TestCreateKubernetes(t *testing.T) {
2222
}
2323
networks := upcloud.Networks{Networks: []upcloud.Network{network}}
2424

25-
oneNodeGroupArgs := func(network string) []string {
25+
nodeGroupArgs := func(network string) []string {
2626
return []string{
2727
"--name", "my-cluster",
2828
"--network", network,
2929
"--node-group", "count=2,kubelet-arg=log-flush-frequency=5s,label=owner=devteam,label=env=dev,name=my-node-group,plan=2xCPU-4GB,ssh-key=ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMWq/xsiYPgA/HLsaWHcjAGnwU+pJy9BUmvIlMBpkdn2 admin@user.com,storage=01000000-0000-4000-8000-000160010100,taint=env=dev:NoSchedule,taint=env=dev2:NoSchedule",
30+
"--node-group", "count=1,name=my-node-group2,plan=2xCPU-4GB,ssh-key=ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMWq/xsiYPgA/HLsaWHcjAGnwU+pJy9BUmvIlMBpkdn2 admin@user.com,disable-utility-network-access",
3031
"--zone", "de-fra1",
3132
}
3233
}
33-
oneNodeGroupRequest := request.CreateKubernetesClusterRequest{
34+
nodeGroupRequest := request.CreateKubernetesClusterRequest{
3435
Name: "my-cluster",
3536
Network: "aa39e313-d908-418a-a959-459699bdc83a",
3637
NetworkCIDR: "172.16.1.0/24",
@@ -71,18 +72,31 @@ func TestCreateKubernetes(t *testing.T) {
7172
Value: "dev2",
7273
},
7374
},
75+
UtilityNetworkAccess: upcloud.BoolPtr(true),
76+
},
77+
{
78+
Count: 1,
79+
KubeletArgs: []upcloud.KubernetesKubeletArg{},
80+
Labels: []upcloud.Label{},
81+
Name: "my-node-group2",
82+
Plan: "2xCPU-4GB",
83+
SSHKeys: []string{
84+
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMWq/xsiYPgA/HLsaWHcjAGnwU+pJy9BUmvIlMBpkdn2 admin@user.com",
85+
},
86+
Taints: []upcloud.KubernetesTaint{},
87+
UtilityNetworkAccess: upcloud.BoolPtr(false),
7488
},
7589
},
7690
Plan: "development",
7791
Zone: "de-fra1",
7892
}
7993

8094
prodArg := []string{"--plan", "production-small"}
81-
prodPlanRequest := oneNodeGroupRequest
95+
prodPlanRequest := nodeGroupRequest
8296
prodPlanRequest.Plan = "production-small"
8397

8498
privateNodeGroupsArg := []string{"--private-node-groups"}
85-
privateNodeGroupsRequest := oneNodeGroupRequest
99+
privateNodeGroupsRequest := nodeGroupRequest
86100
privateNodeGroupsRequest.PrivateNodeGroups = true
87101

88102
for _, test := range []struct {
@@ -92,26 +106,26 @@ func TestCreateKubernetes(t *testing.T) {
92106
wantErr bool
93107
}{
94108
{
95-
name: "1 node group",
96-
args: oneNodeGroupArgs(network.UUID),
97-
request: oneNodeGroupRequest,
109+
name: "2 node groups",
110+
args: nodeGroupArgs(network.UUID),
111+
request: nodeGroupRequest,
98112
wantErr: false,
99113
},
100114
{
101115
name: "resolve network from name",
102-
args: oneNodeGroupArgs(network.Name),
103-
request: oneNodeGroupRequest,
116+
args: nodeGroupArgs(network.Name),
117+
request: nodeGroupRequest,
104118
wantErr: false,
105119
},
106120
{
107121
name: "use productions-small plan",
108-
args: append(oneNodeGroupArgs(network.Name), prodArg...),
122+
args: append(nodeGroupArgs(network.Name), prodArg...),
109123
request: prodPlanRequest,
110124
wantErr: false,
111125
},
112126
{
113127
name: "with private node groups",
114-
args: append(oneNodeGroupArgs(network.Name), privateNodeGroupsArg...),
128+
args: append(nodeGroupArgs(network.Name), privateNodeGroupsArg...),
115129
request: privateNodeGroupsRequest,
116130
wantErr: false,
117131
},

internal/commands/kubernetes/nodegroup/create.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/UpCloudLtd/upcloud-cli/v2/internal/commands"
99
"github.com/UpCloudLtd/upcloud-cli/v2/internal/completion"
10+
"github.com/UpCloudLtd/upcloud-cli/v2/internal/config"
1011
"github.com/UpCloudLtd/upcloud-cli/v2/internal/labels"
1112
"github.com/UpCloudLtd/upcloud-cli/v2/internal/output"
1213
"github.com/UpCloudLtd/upcloud-cli/v2/internal/resolver"
@@ -17,14 +18,15 @@ import (
1718
)
1819

1920
type CreateNodeGroupParams struct {
20-
Count int
21-
Name string
22-
Plan string
23-
SSHKeys []string
24-
Storage string
25-
KubeletArgs []string
26-
Labels []string
27-
Taints []string
21+
Count int
22+
Name string
23+
Plan string
24+
SSHKeys []string
25+
Storage string
26+
KubeletArgs []string
27+
Labels []string
28+
Taints []string
29+
UtilityNetworkAccess config.OptionalBoolean
2830
}
2931

3032
func GetCreateNodeGroupFlagSet(p *CreateNodeGroupParams) *pflag.FlagSet {
@@ -38,6 +40,7 @@ func GetCreateNodeGroupFlagSet(p *CreateNodeGroupParams) *pflag.FlagSet {
3840
fs.StringArrayVar(&p.SSHKeys, "ssh-key", []string{}, "SSH keys to be configured as authorized keys to the nodes.")
3941
fs.StringVar(&p.Storage, "storage", "", "Storage template to use when creating the nodes. Defaults to `UpCloud K8s` public template.")
4042
fs.StringArrayVar(&p.Taints, "taint", []string{}, "Taints to be configured to the nodes in `key=value:effect` format")
43+
config.AddEnableOrDisableFlag(fs, &p.UtilityNetworkAccess, true, "utility-network-access", "utility network access. If disabled, nodes in this group will not have access to utility network")
4144

4245
return fs
4346
}
@@ -102,14 +105,15 @@ func ProcessNodeGroupParams(p CreateNodeGroupParams) (request.KubernetesNodeGrou
102105
}
103106

104107
ng = request.KubernetesNodeGroup{
105-
Count: p.Count,
106-
Labels: labelSlice,
107-
Name: p.Name,
108-
Plan: p.Plan,
109-
SSHKeys: sshKeys,
110-
Storage: p.Storage,
111-
KubeletArgs: kubeletArgs,
112-
Taints: taints,
108+
Count: p.Count,
109+
Labels: labelSlice,
110+
Name: p.Name,
111+
Plan: p.Plan,
112+
SSHKeys: sshKeys,
113+
Storage: p.Storage,
114+
KubeletArgs: kubeletArgs,
115+
Taints: taints,
116+
UtilityNetworkAccess: upcloud.BoolPtr(p.UtilityNetworkAccess.Value()),
113117
}
114118

115119
return ng, nil

internal/commands/kubernetes/nodegroup/create_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ func TestCreateKubernetesNodeGroup(t *testing.T) {
4040
expected: request.CreateKubernetesNodeGroupRequest{
4141
ClusterUUID: clusterUUID,
4242
NodeGroup: request.KubernetesNodeGroup{
43-
Count: 2,
44-
Name: "my-node-group",
45-
Plan: "2xCPU-4GB",
46-
Labels: []upcloud.Label{},
47-
KubeletArgs: []upcloud.KubernetesKubeletArg{},
48-
Taints: []upcloud.KubernetesTaint{},
43+
Count: 2,
44+
Name: "my-node-group",
45+
Plan: "2xCPU-4GB",
46+
Labels: []upcloud.Label{},
47+
KubeletArgs: []upcloud.KubernetesKubeletArg{},
48+
Taints: []upcloud.KubernetesTaint{},
49+
UtilityNetworkAccess: upcloud.BoolPtr(true),
4950
},
5051
},
5152
},
@@ -62,8 +63,9 @@ func TestCreateKubernetesNodeGroup(t *testing.T) {
6263
{Key: "key", Value: "value"},
6364
{Key: "key-without-value", Value: ""},
6465
},
65-
KubeletArgs: []upcloud.KubernetesKubeletArg{},
66-
Taints: []upcloud.KubernetesTaint{},
66+
KubeletArgs: []upcloud.KubernetesKubeletArg{},
67+
Taints: []upcloud.KubernetesTaint{},
68+
UtilityNetworkAccess: upcloud.BoolPtr(true),
6769
},
6870
},
6971
},
@@ -81,6 +83,7 @@ func TestCreateKubernetesNodeGroup(t *testing.T) {
8183
"--storage=01000000-0000-4000-8000-000160010100",
8284
"--taint=env=dev:NoSchedule",
8385
"--taint=env=dev2:NoSchedule",
86+
"--disable-utility-network-access",
8487
},
8588
expected: request.CreateKubernetesNodeGroupRequest{
8689
ClusterUUID: clusterUUID,
@@ -120,6 +123,7 @@ func TestCreateKubernetesNodeGroup(t *testing.T) {
120123
Value: "dev2",
121124
},
122125
},
126+
UtilityNetworkAccess: upcloud.BoolPtr(false),
123127
},
124128
},
125129
},

internal/commands/kubernetes/show.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func (s *showCommand) Execute(exec commands.Executor, uuid string) (output.Outpu
9696
{Title: "Kubelet args:", Value: kubeletArgs.String()},
9797
{Title: "Labels:", Value: labels.String()},
9898
{Title: "Taints:", Value: taints.String()},
99+
{Title: "Utility network access:", Value: nodeGroup.UtilityNetworkAccess, Format: format.Boolean},
99100
},
100101
},
101102
},

internal/commands/kubernetes/show_test.go

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ func TestShowCommand(t *testing.T) {
6060
Value: "sometaintvalue",
6161
},
6262
},
63-
Storage: "storage-uuid",
64-
SSHKeys: []string{"somekey"},
63+
Storage: "storage-uuid",
64+
SSHKeys: []string{"somekey"},
65+
UtilityNetworkAccess: true,
6566
}, {
6667
Count: 8,
6768
Labels: []upcloud.Label{
@@ -90,8 +91,9 @@ func TestShowCommand(t *testing.T) {
9091
Value: "sometaintvalue2",
9192
},
9293
},
93-
Storage: "storage-uuid-2",
94-
SSHKeys: []string{"somekey2"},
94+
Storage: "storage-uuid-2",
95+
SSHKeys: []string{"somekey2"},
96+
UtilityNetworkAccess: false,
9597
},
9698
},
9799
State: upcloud.KubernetesClusterStateRunning,
@@ -112,31 +114,33 @@ func TestShowCommand(t *testing.T) {
112114
113115
114116
Node group 1 (upcloud-go-sdk-unit-test):
115-
Name: upcloud-go-sdk-unit-test
116-
Count: 4
117-
Plan: 2xCPU-4GB
118-
State: running
119-
Storage UUID: storage-uuid
120-
Storage name: Test storage
121-
Kubelet args: somekubeletkey=somekubeletvalue
122-
Labels: managedBy=upcloud-go-sdk-unit-test
123-
another=label-thing
124-
Taints: sometaintkey=sometaintvalue:NoExecute
125-
sometaintkey=sometaintvalue:NoExecute
126-
sometaintkey=sometaintvalue:NoExecute
117+
Name: upcloud-go-sdk-unit-test
118+
Count: 4
119+
Plan: 2xCPU-4GB
120+
State: running
121+
Storage UUID: storage-uuid
122+
Storage name: Test storage
123+
Kubelet args: somekubeletkey=somekubeletvalue
124+
Labels: managedBy=upcloud-go-sdk-unit-test
125+
another=label-thing
126+
Taints: sometaintkey=sometaintvalue:NoExecute
127+
sometaintkey=sometaintvalue:NoExecute
128+
sometaintkey=sometaintvalue:NoExecute
129+
Utility network access: yes
127130
128131
129132
Node group 2 (upcloud-go-sdk-unit-test-2):
130-
Name: upcloud-go-sdk-unit-test-2
131-
Count: 8
132-
Plan: 4xCPU-8GB
133-
State: pending
134-
Storage UUID: storage-uuid-2
135-
Storage name: Test storage
136-
Kubelet args: somekubeletkey2=somekubeletvalue2
137-
Labels: managedBy=upcloud-go-sdk-unit-test-2
138-
another2=label-thing-2
139-
Taints: sometaintkey2=sometaintvalue2:NoSchedule
133+
Name: upcloud-go-sdk-unit-test-2
134+
Count: 8
135+
Plan: 4xCPU-8GB
136+
State: pending
137+
Storage UUID: storage-uuid-2
138+
Storage name: Test storage
139+
Kubelet args: somekubeletkey2=somekubeletvalue2
140+
Labels: managedBy=upcloud-go-sdk-unit-test-2
141+
another2=label-thing-2
142+
Taints: sometaintkey2=sometaintvalue2:NoSchedule
143+
Utility network access: no
140144
141145
`
142146

0 commit comments

Comments
 (0)