Allow selection of network/subnetworks when creating GKE Cluster in GitLab

Problem to solve

Currently, the creation of a Kubernetes cluster on GKE requires the cluster name/id, GCP project, zone, node count and machine type. There is no provision to specify a network / subnetwork name, leading to usage of the default VPC network of the specified project according to:

By default, the cluster is created in the project's default network. See here

In use-cases where the default network is unavailable, all IPs within the network's subnet has been exhausted or some company policies prevent a user from using the default network; they will have no choice but to create the cluster on GCP and add it manually.

Further details

Take for example the internal gitlab-demos project of GitLab on GCP, the creation of Clusters automatically is currently not possible because the IPs in the default network has been exhausted. The user has to specify a different network.

Proposal

The list method of the usableSubnetworks resource of the GCP API provides the list of networks and subnetworks when a project is specified. Once the GCP project is selected, the method can be called to list available networks in the project for the user to select.

When creating the cluster, the network and subnetwork can then be specified in the GCP API Request based on the user's selection. So, in /lib/google_api/cloud_platform/client.rb, we can have:

request_body = Google::Apis::ContainerV1::CreateClusterRequest.new(
          {
            "cluster": {
              "name": cluster_name,
              "initial_node_count": cluster_size,
              "network": user_selected_network,
              "subnetwork": user_select_subnetwork,
              "node_config": {
                "machine_type": machine_type
              },
              "legacy_abac": {
                "enabled": legacy_abac
              }
            }
          }
        )

What does success look like, and how can we measure that?

Users are able to select a network and subnetwork when creating a GKE Cluster automatically from within GitLab.

Links / references

/cc @northrup @tatkins