Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doks: add custom subnets flags #1586

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const (
ArgVPCUUID = "vpc-uuid"
// ArgClusterVPCUUID is a cluster vpc-uuid argument.
ArgClusterVPCUUID = "vpc-uuid"
// ArgClusterSubnet is a cluster pod CIDR argument.
ArgClusterSubnet = "cluster-subnet"
// ArgServiceSubnet is a cluster service CIDR argument.
ArgServiceSubnet = "service-subnet"
// ArgClusterNodePool are a cluster's node pools arguments.
ArgClusterNodePool = "node-pool"
// ArgClusterUpdateKubeconfig updates the local kubeconfig.
Expand Down
20 changes: 20 additions & 0 deletions commands/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ After creating a cluster, a configuration context is added to kubectl and made a
"A `slug` indicating which Kubernetes version to use when creating the cluster. Use the `doctl kubernetes options versions` command for a list of options")
AddStringFlag(cmdKubeClusterCreate, doctl.ArgClusterVPCUUID, "", "",
"The UUID of a VPC network to create the cluster in. Must be the UUID of a valid VPC in the same region specified for the cluster. If a VPC is not specified, the cluster is placed in the default VPC network for the region.")
AddStringFlag(cmdKubeClusterCreate, doctl.ArgClusterSubnet, "", "",
"The CIDR block to use for the pod network. Must be a valid CIDR block. Defaults to `10.244.0.0/16`. If left empty/default the cluster will be created with a virtual network. If a custom one is provided, the cluster will be created as vpc-native cluster. VPC-native CIDR blocks cannot overlap within an account.")
AddStringFlag(cmdKubeClusterCreate, doctl.ArgServiceSubnet, "", "",
"The CIDR block to use for the service network. Must be a valid CIDR block. Defaults to `10.245.0.0/16`. If left empty/default the cluster will be created with a virtual network. If a custom one is provided, the cluster will be created as vpc-native cluster. VPC-native CIDR blocks cannot overlap within an account.")
AddBoolFlag(cmdKubeClusterCreate, doctl.ArgAutoUpgrade, "", false,
"Enables automatic upgrades to new patch releases during the cluster's maintenance window. Defaults to `false`. To enable automatic upgrade, supply `--auto-upgrade=true`.")
AddBoolFlag(cmdKubeClusterCreate, doctl.ArgSurgeUpgrade, "", true,
Expand Down Expand Up @@ -1633,6 +1637,22 @@ func buildClusterCreateRequestFromArgs(c *CmdConfig, r *godo.KubernetesClusterCr
// empty "" is fine, the default region VPC will be resolved
r.VPCUUID = vpcUUID

podCIDR, err := c.Doit.GetString(c.NS, doctl.ArgClusterSubnet)
if err != nil {
return err
}
r.ClusterSubnet = podCIDR
svcCIDR, err := c.Doit.GetString(c.NS, doctl.ArgServiceSubnet)
if err != nil {
return err
}
r.ServiceSubnet = svcCIDR
// empty "" is fine, the default is still to use a virtual network and not be vpc-native.
// either both have to be set (vpc-native) or none (virtual network)
if c.Doit.IsSet(doctl.ArgClusterSubnet) != c.Doit.IsSet(doctl.ArgServiceSubnet) {
return fmt.Errorf("flags %q and %q both have to be set for vpc-native clusters or both unset for virtual network clusters", doctl.ArgClusterSubnet, doctl.ArgServiceSubnet)
}

version, err := getVersionOrLatest(c)
if err != nil {
return err
Expand Down
13 changes: 13 additions & 0 deletions commands/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,19 @@ func TestKubernetesCreate(t *testing.T) {
err = testK8sCmdService().RunKubernetesClusterCreate("c-8", 3)(config)
assert.NoError(t, err)

// Test vpc-native
const podNetwork = "10.100.0.0/16"
const serviceNetwork = "10.101.0.0/16"
config.Doit.Set(config.NS, doctl.ArgClusterSubnet, podNetwork)
config.Doit.Set(config.NS, doctl.ArgServiceSubnet, serviceNetwork)
r.ClusterSubnet = podNetwork
r.ServiceSubnet = serviceNetwork
testCluster.ClusterSubnet = podNetwork
testCluster.ServiceSubnet = serviceNetwork
tm.kubernetes.EXPECT().Create(&r).Return(&testCluster, nil)
err = testK8sCmdService().RunKubernetesClusterCreate("c-8", 3)(config)
assert.NoError(t, err)

// Test with 1-clicks specified
config.Doit.Set(config.NS, doctl.ArgOneClicks, []string{"slug1", "slug2"})
tm.kubernetes.EXPECT().Create(&r).Return(&testCluster, nil)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22
require (
github.com/blang/semver v3.5.1+incompatible
github.com/creack/pty v1.1.21
github.com/digitalocean/godo v1.125.0
github.com/digitalocean/godo v1.126.0
github.com/docker/cli v24.0.5+incompatible
github.com/docker/docker v25.0.6+incompatible
github.com/docker/docker-credential-helpers v0.7.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/digitalocean/godo v1.125.0 h1:wGPBQRX9Wjo0qCF0o8d25mT3A84Iw8rfHnZOPyvHcMQ=
github.com/digitalocean/godo v1.125.0/go.mod h1:PU8JB6I1XYkQIdHFop8lLAY9ojp6M0XcU0TWaQSxbrc=
github.com/digitalocean/godo v1.125.1-0.20240925184037-40ea734536f0 h1:hEi5W+TPrYUjq1PLt1lJmhrt+ezpzUrAvwYr9f1Xo4U=
github.com/digitalocean/godo v1.125.1-0.20240925184037-40ea734536f0/go.mod h1:PU8JB6I1XYkQIdHFop8lLAY9ojp6M0XcU0TWaQSxbrc=
github.com/digitalocean/godo v1.126.0 h1:+Znh7VMQj/E8ArbjWnc7OKGjWfzC+I8OCSRp7r1MdD8=
github.com/digitalocean/godo v1.126.0/go.mod h1:PU8JB6I1XYkQIdHFop8lLAY9ojp6M0XcU0TWaQSxbrc=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/cli v24.0.5+incompatible h1:WeBimjvS0eKdH4Ygx+ihVq1Q++xg36M/rMi4aXAvodc=
Expand Down
5 changes: 5 additions & 0 deletions vendor/github.com/digitalocean/godo/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions vendor/github.com/digitalocean/godo/databases.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/digitalocean/godo/godo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions vendor/github.com/digitalocean/godo/kubernetes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ github.com/creack/pty
# github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
## explicit
github.com/davecgh/go-spew/spew
# github.com/digitalocean/godo v1.125.0
# github.com/digitalocean/godo v1.126.0
## explicit; go 1.22
github.com/digitalocean/godo
github.com/digitalocean/godo/metrics
Expand Down
Loading