Skip to content

Commit

Permalink
adding RestorePlan to Backup for GKE (GoogleCloudPlatform#8803)
Browse files Browse the repository at this point in the history
* adding RestorePlan to Backup for GKE

* fixed spacing issue

* fixed more spacing issue

* adding newline end of file

* fixed trailing spaces

* fixed test file names

* added test gaps

* adding description adn labels

* fixed tests

* fixed protected application name length

* fixed protected app test

* fix restore all namespaces test names

* removed bp prefix from resource names

* removed last bp ref
  • Loading branch information
neha-vellanki12 authored and RileyHYZ committed Sep 15, 2023
1 parent 6ea1986 commit 762efe6
Show file tree
Hide file tree
Showing 7 changed files with 757 additions and 0 deletions.
455 changes: 455 additions & 0 deletions mmv1/products/gkebackup/RestorePlan.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
resource "google_container_cluster" "primary" {
name = "<%= ctx[:vars]['name'] %>-cluster"
location = "us-central1"
initial_node_count = 1
workload_identity_config {
workload_pool = "<%= ctx[:test_env_vars]['project'] %>.svc.id.goog"
}
addons_config {
gke_backup_agent_config {
enabled = true
}
}
}

resource "google_gke_backup_backup_plan" "basic" {
name = "<%= ctx[:vars]['name'] %>"
cluster = google_container_cluster.primary.id
location = "us-central1"
backup_config {
include_volume_data = true
include_secrets = true
all_namespaces = true
}
}

resource "google_gke_backup_restore_plan" "all_cluster_resources" {
name = "<%= ctx[:vars]['name'] %>-rp"
location = "us-central1"
backup_plan = google_gke_backup_backup_plan.basic.id
cluster = google_container_cluster.primary.id
restore_config {
no_namespaces = true
namespaced_resource_restore_mode = "FAIL_ON_CONFLICT"
cluster_resource_restore_scope {
all_group_kinds = true
}
cluster_resource_conflict_policy = "USE_EXISTING_VERSION"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
resource "google_container_cluster" "primary" {
name = "<%= ctx[:vars]['name'] %>-cluster"
location = "us-central1"
initial_node_count = 1
workload_identity_config {
workload_pool = "<%= ctx[:test_env_vars]['project'] %>.svc.id.goog"
}
addons_config {
gke_backup_agent_config {
enabled = true
}
}
}

resource "google_gke_backup_backup_plan" "basic" {
name = "<%= ctx[:vars]['name'] %>"
cluster = google_container_cluster.primary.id
location = "us-central1"
backup_config {
include_volume_data = true
include_secrets = true
all_namespaces = true
}
}

resource "google_gke_backup_restore_plan" "all_ns" {
name = "<%= ctx[:vars]['name'] %>"
location = "us-central1"
backup_plan = google_gke_backup_backup_plan.basic.id
cluster = google_container_cluster.primary.id
restore_config {
all_namespaces = true
namespaced_resource_restore_mode = "FAIL_ON_CONFLICT"
volume_data_restore_policy = "RESTORE_VOLUME_DATA_FROM_BACKUP"
cluster_resource_restore_scope {
all_group_kinds = true
}
cluster_resource_conflict_policy = "USE_EXISTING_VERSION"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
resource "google_container_cluster" "primary" {
name = "<%= ctx[:vars]['name'] %>-cluster"
location = "us-central1"
initial_node_count = 1
workload_identity_config {
workload_pool = "<%= ctx[:test_env_vars]['project'] %>.svc.id.goog"
}
addons_config {
gke_backup_agent_config {
enabled = true
}
}
}

resource "google_gke_backup_backup_plan" "basic" {
name = "<%= ctx[:vars]['name'] %>"
cluster = google_container_cluster.primary.id
location = "us-central1"
backup_config {
include_volume_data = true
include_secrets = true
all_namespaces = true
}
}

resource "google_gke_backup_restore_plan" "rollback_app" {
name = "<%= ctx[:vars]['name'] %>-rp"
location = "us-central1"
backup_plan = google_gke_backup_backup_plan.basic.id
cluster = google_container_cluster.primary.id
restore_config {
selected_applications {
namespaced_names {
name = "my-app"
namespace = "my-ns"
}
}
namespaced_resource_restore_mode = "DELETE_AND_RESTORE"
volume_data_restore_policy = "REUSE_VOLUME_HANDLE_FROM_BACKUP"
cluster_resource_restore_scope {
no_group_kinds = true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
resource "google_container_cluster" "primary" {
name = "<%= ctx[:vars]['name'] %>-cluster"
location = "us-central1"
initial_node_count = 1
workload_identity_config {
workload_pool = "<%= ctx[:test_env_vars]['project'] %>.svc.id.goog"
}
addons_config {
gke_backup_agent_config {
enabled = true
}
}
}

resource "google_gke_backup_backup_plan" "basic" {
name = "<%= ctx[:vars]['name'] %>"
cluster = google_container_cluster.primary.id
location = "us-central1"
backup_config {
include_volume_data = true
include_secrets = true
all_namespaces = true
}
}

resource "google_gke_backup_restore_plan" "rename_ns" {
name = "<%= ctx[:vars]['name'] %>-rp"
location = "us-central1"
backup_plan = google_gke_backup_backup_plan.basic.id
cluster = google_container_cluster.primary.id
restore_config {
selected_namespaces {
namespaces = ["ns1"]
}
namespaced_resource_restore_mode = "FAIL_ON_CONFLICT"
volume_data_restore_policy = "REUSE_VOLUME_HANDLE_FROM_BACKUP"
cluster_resource_restore_scope {
no_group_kinds = true
}
transformation_rules {
description = "rename namespace from ns1 to ns2"
resource_filter {
group_kinds {
resource_kind = "Namespace"
}
json_path = ".metadata[?(@.name == 'ns1')]"
}
field_actions {
op = "REPLACE"
path = "/metadata/name"
value = "ns2"
}
}
transformation_rules {
description = "move all resources from ns1 to ns2"
resource_filter {
namespaces = ["ns1"]
}
field_actions {
op = "REPLACE"
path = "/metadata/namespace"
value = "ns2"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
resource "google_container_cluster" "primary" {
name = "<%= ctx[:vars]['name'] %>-cluster"
location = "us-central1"
initial_node_count = 1
workload_identity_config {
workload_pool = "<%= ctx[:test_env_vars]['project'] %>.svc.id.goog"
}
addons_config {
gke_backup_agent_config {
enabled = true
}
}
}

resource "google_gke_backup_backup_plan" "basic" {
name = "<%= ctx[:vars]['name'] %>"
cluster = google_container_cluster.primary.id
location = "us-central1"
backup_config {
include_volume_data = true
include_secrets = true
all_namespaces = true
}
}

resource "google_gke_backup_restore_plan" "rollback_ns" {
name = "<%= ctx[:vars]['name'] %>-rp"
location = "us-central1"
backup_plan = google_gke_backup_backup_plan.basic.id
cluster = google_container_cluster.primary.id
restore_config {
selected_namespaces {
namespaces = ["my-ns"]
}
namespaced_resource_restore_mode = "DELETE_AND_RESTORE"
volume_data_restore_policy = "RESTORE_VOLUME_DATA_FROM_BACKUP"
cluster_resource_restore_scope {
selected_group_kinds {
resource_group = "apiextension.k8s.io"
resource_kind = "CustomResourceDefinition"
}
selected_group_kinds {
resource_group = "storage.k8s.io"
resource_kind = "StorageClass"
}
}
cluster_resource_conflict_policy = "USE_EXISTING_VERSION"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
resource "google_container_cluster" "primary" {
name = "<%= ctx[:vars]['name'] %>-cluster"
location = "us-central1"
initial_node_count = 1
workload_identity_config {
workload_pool = "<%= ctx[:test_env_vars]['project'] %>.svc.id.goog"
}
addons_config {
gke_backup_agent_config {
enabled = true
}
}
}

resource "google_gke_backup_backup_plan" "basic" {
name = "<%= ctx[:vars]['name'] %>"
cluster = google_container_cluster.primary.id
location = "us-central1"
backup_config {
include_volume_data = true
include_secrets = true
all_namespaces = true
}
}

resource "google_gke_backup_restore_plan" "transform_rule" {
name = "<%= ctx[:vars]['name'] %>-rp"
description = "copy nginx env variables"
labels = {
"app" = "nginx"
}
location = "us-central1"
backup_plan = google_gke_backup_backup_plan.basic.id
cluster = google_container_cluster.primary.id
restore_config {
excluded_namespaces {
namespaces = ["my-ns"]
}
namespaced_resource_restore_mode = "DELETE_AND_RESTORE"
volume_data_restore_policy = "RESTORE_VOLUME_DATA_FROM_BACKUP"
cluster_resource_restore_scope {
excluded_group_kinds {
resource_group = "apiextension.k8s.io"
resource_kind = "CustomResourceDefinition"
}
}
cluster_resource_conflict_policy = "USE_EXISTING_VERSION"
transformation_rules {
description = "Copy environment variables from the nginx container to the install init container."
resource_filter {
group_kinds {
resource_kind = "Pod"
resource_group = ""
}
json_path = ".metadata[?(@.name == 'nginx')]"
}
field_actions {
op = "COPY"
path = "/spec/initContainers/0/env"
from_path = "/spec/containers/0/env"
}
}
}
}

0 comments on commit 762efe6

Please sign in to comment.