Skip to content

Commit

Permalink
Added new functions
Browse files Browse the repository at this point in the history
setClusterLocation, createCluster, deleteCluster
  • Loading branch information
RhysJackson committed Jan 21, 2018
1 parent dd993a3 commit 7beb212
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 3 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Generated by roxygen2: do not edit by hand

export(completeIpRotation)
export(createCluster)
export(deleteCluster)
export(getCluster)
export(getServerConfig)
export(listClusters)
export(setAddons)
export(setClusterLocation)
importFrom(googleAuthR,gar_api_generator)
1 change: 1 addition & 0 deletions R/completeIpRotation.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' @param zone The name of the Google Compute Engine zone in which the cluster resides.
#' @param clusterId The name of the cluster.
#' @keywords projects.locations.getServerConfig
#' @importFrom googleAuthR gar_api_generator
#' @export
#' @examples
#' completeIpRotation(projectId = "myProjectId", zone = "europe-west1-d", clusterId = "cluster-1")
Expand Down
42 changes: 42 additions & 0 deletions R/createCluster.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' createCluster
#'
#' Creates a cluster, consisting of the specified number and type of Google Compute Engine instances.
#' By default, the cluster is created in the project's default network.
#' One firewall is added for the cluster. After cluster creation, the cluster creates routes for each node to allow the containers on that node to communicate with all other instances in the cluster.
#' Finally, an entry is added to the project's global metadata indicating which CIDR range is being used by the cluster.
#' @param projectId The Google Developers Console project ID or project number.
#' @param zone The name of the Google Compute Engine zone in which the cluster resides.
#' @param clusterSpec A cluster specification. If no specification is provided, a 3 node, 100Gb disk, n1-standard-1 cluster will be created with the name "r-cluster". See here for specification: https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.zones.clusters
#' @keywords projects.zones.clusters.create
#' @importFrom googleAuthR gar_api_generator
#' @export
#' @examples
#' createCluster(projectId = "myProjectId", zone = "europe-west1-d")

createCluster <- function(projectId, zone, clusterSpec = NULL) {

if(is.null(clusterSpec)) {
clusterSpec <- list(
name = "r-cluster",
initialNodeCount = 3,
nodeConfig = list(
machineType = "n1-standard-1",
diskSizeGb = 100,
oauthScopes = c("https://www.googleapis.com/auth/compute", "https://www.googleapis.com/auth/devstorage.read_only"),
imageType = ""
)
)
}

body <- list(
cluster = clusterSpec
)

f <- gar_api_generator("https://container.googleapis.com/v1beta1",
"POST",
path_args = list(projects = projectId, zones = zone, clusters = ""))

f(the_body = body)

}

24 changes: 24 additions & 0 deletions R/deleteCluster.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#' deleteCluster
#'
#' Deletes the cluster, including the Kubernetes endpoint and all worker nodes.
#' Firewalls and routes that were configured during cluster creation are also deleted.
#' Other Google Compute Engine resources that might be in use by the cluster (e.g. load balancer resources) will not be deleted if they weren't present at the initial create time.
#' @param projectId The Google Developers Console project ID or project number.
#' @param zone The name of the Google Compute Engine zone in which the cluster resides.
#' @param clusterId The name of the cluster to delete.
#' @keywords projects.zones.clusters.delete
#' @importFrom googleAuthR gar_api_generator
#' @export
#' @examples
#' deleteCluster(projectId = "myProjectId", zone = "europe-west1-d", clusterId = "r-cluster")

deleteCluster <- function(projectId, zone, clusterId) {

f <- gar_api_generator("https://container.googleapis.com/v1beta1",
"DELETE",
path_args = list(projects = projectId, zones = zone, clusters = clusterId))

f()

}

1 change: 1 addition & 0 deletions R/getCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' @param zone The name of the Google Compute Engine zone in which the cluster resides.
#' @param clusterId The name of the cluster to retrieve.
#' @keywords projects.locations.clusters.get
#' @importFrom googleAuthR gar_api_generator
#' @export
#' @examples
#' getCluster(projectId = "myProjectId", zone = "europe-west1-d", clusterId = "cluster-1")
Expand Down
1 change: 1 addition & 0 deletions R/getServerConfig.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#' @param projectId The Google Developers Console project ID or project number.
#' @param zone The name of the Google Compute Engine zone in which the cluster resides.
#' @keywords projects.locations.getServerConfig
#' @importFrom googleAuthR gar_api_generator
#' @export
#' @examples
#' getServerConfig(projectId = "myProjectId", zone = "europe-west1-d")
Expand Down
1 change: 1 addition & 0 deletions R/listClusters.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#' @param projectId The Google Developers Console project ID or project number.
#' @param zone The name of the Google Compute Engine zone in which the cluster resides, or "-" for all zones. Defaults to all zones.
#' @keywords projects.locations.clusters.get
#' @importFrom googleAuthR gar_api_generator
#' @export
#' @examples
#' listClusters(projectId = "myProjectId", location = "europe-west1-d")
Expand Down
12 changes: 10 additions & 2 deletions R/setAddons.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
#' @param zone The name of the Google Compute Engine zone in which the cluster resides.
#' @param clusterId The name of the cluster to retrieve.
#' @keywords projects.zones.clusters.addons
#' @importFrom googleAuthR gar_api_generator
#' @export
#' @examples
#' setAddons(projectId = "myProjectId", location = "europe-west1-d", clusterId = "cluster-1", addonsConfig = list(httpLoadBalancing = list(disabled = FALSE)))
#' @examples setAddons(projectId = "myProjectId",
#' location = "europe-west1-d",
#' clusterId = "cluster-1",
#' addonsConfig = list(
#' httpLoadBalancing = list(
#' disabled = FALSE
#' )
#' )
#' )

setAddons <- function(projectId, zone, clusterId, addonsConfig) {
body <- list(
Expand Down
34 changes: 34 additions & 0 deletions R/setClusterLocation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' setClusterLocation
#'
#' Sets the locations of a specific cluster.
#' @param projectId The Google Developers Console project ID or project number.
#' @param zone The name of the Google Compute Engine zone in which the cluster resides.
#' @param clusterId The name of the cluster to upgrade.
#' @param locations The desired list of Google Compute Engine locations in which the cluster's nodes should be located. Changing the locations a cluster is in will result in nodes being either created or removed from the cluster, depending on whether locations are being added or removed. This list must always include the cluster's primary zone.
#' @keywords projects.zones.clusters.locations
#' @importFrom googleAuthR gar_api_generator
#' @export
#' @examples
#' setClusterLocation(projectId = "myProjectId",
#' zone = "europe-west1-d",
#' clusterId = "r-cluster",
#' locations = c("europe-west1-d",
#' "europe-west1-b"))

setClusterLocation <- function(projectId, zone, clusterId, locations) {

body <- list(
locations = locations
)

f <- gar_api_generator("https://container.googleapis.com/v1beta1",
"POST",
path_args = list(projects = projectId,
zones = zone,
clusters = clusterId,
locations = ""))

f(the_body = body)

}

25 changes: 25 additions & 0 deletions man/createCluster.Rd

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

24 changes: 24 additions & 0 deletions man/deleteCluster.Rd

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

11 changes: 10 additions & 1 deletion man/setAddons.Rd

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

28 changes: 28 additions & 0 deletions man/setClusterLocation.Rd

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

0 comments on commit 7beb212

Please sign in to comment.