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

add terraform for utility cluster. Add name override to gke #30847

Merged
merged 18 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ metadata:
name: beam-testing-cluster
spec:
kafka:
version: 3.4.0
version: 3.6.0
replicas: 3
config:
offsets.topic.replication.factor: 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
# This overlay patches the base strimzi kafka cluster with a GKE TCP
# internal load balancer ingress

namespace: strimzi

resources:
- ../../base/v0.33.2
patchesStrategicMerge:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ in [.test-infra/terraform/google-cloud-platform/google-kubernetes-engine](.).
Edit with your IDE terraform plugin installed and it will autocomplete the
variable names.

## Name override
If you need a predictable name (omit the suffix) you can set the `cluster_name_override` in order to set the name. Keep in mind that you can cause conflicts so use with care. Using this option still needs `cluster_name_prefix` but its not use so set it to the same value.

# Step 2. Initialize and apply the terraform module.

## If you are provisioning in `apache-beam-testing`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ resource "random_string" "postfix" {
resource "google_container_cluster" "default" {
depends_on = [google_project_service.required]
deletion_protection = false
name = "${var.cluster_name_prefix}-${random_string.postfix.result}"
name = coalesce(var.cluster_name_override,"${var.cluster_name_prefix}-${random_string.postfix.result}")
location = var.region
enable_autopilot = true
network = data.google_compute_network.default.id
Expand All @@ -34,7 +34,14 @@ resource "google_container_cluster" "default" {
enable_private_nodes = true
enable_private_endpoint = false
}
node_config {
service_account = data.google_service_account.default.email

cluster_autoscaling {
damondouglas marked this conversation as resolved.
Show resolved Hide resolved
auto_provisioning_defaults {
service_account = var.service_account_id
oauth_scopes = [
"https://www.googleapis.com/auth/cloud-platform"
]

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

output kubernetes_api_endpoint {
value = google_container_cluster.default.endpoint
}

output cluster_ca_certificate {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding outputs :-). Could you tell me what this output is needed for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the provisioning of the Kubernetes cluster and any workloads that depend on it should be in separate terraform modules. Then one would just follow typical gcloud command to connect.

value = google_container_cluster.default.master_auth[0].cluster_ca_certificate
sensitive = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ variable "cluster_name_prefix" {
description = "The prefix to assign the provisioned Google Kubernetes Engine (GKE) cluster; a random string is appended to this value"
}

variable "cluster_name_override" {
type = string
description = "Use this to override naming and omit the postfix. Leave empty to use prefix-suffix format"
default = ""
}

Comment on lines +34 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove this variable and just have the prefix to keep it simple?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a predictable name so we dont have to change x number of workflows each time we redeploy for any reason. I would like to keep it this way

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just keep the kafka cluster running continually and delete the topics after the workflows execute?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've had flakey tests in this repository due to waiting on spinning up new clusters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way we ensure its fresh each time which is easier then to maintain a kafka instance and make sure it does not break between different tests. We could delete topics but still there could be issues.

variable "network" {
type = string
description = "The Google Cloud Virtual Private Cloud (VPC) network name"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

# Overview
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add more details about what the intent is to use this cluster instead of "datastores"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


This module will provision a utility cluster which is used to run infrastructure needed for tests running in beam CI.

The purpose of this cluster is to run the necessary tooling that the tests in CI require. Right now it will run Kafka clusters but in the future plan is to have hadoop, flink and any other utility that the test might need which was historically the purpose of `datastores-io` cluster. Unlike `datastores-io` this cluster will be managed by code with Terraform.

# Deployment

# Step 1. Initialize and apply the terraform module.

Make sure you have set the prefix in terraform block in the provider.tf file. Change it if trying to deploy another cluster.

For initialization make sure you use the `beam-infra-terraform-state`
```
terraform init -backend-config="bucket=beam-infra-terraform-state"
```
## Step 2. Plan the module. Make sure that terraform is not replacing or deleting resrouces unless expected:
```
terraform plan
```
## Step 3. Apply the module.
```
terraform apply
```
29 changes: 29 additions & 0 deletions .test-infra/terraform/google-cloud-platform/utility-cluster/gke.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module "gke" {
source = "../google-kubernetes-engine"
project = "apache-beam-testing"
network = "default"
subnetwork = "default-f91f013bcf8bd369"
region = "us-central1"
cluster_name_prefix = "beam-utility"
service_account_id = "beam-github-actions@apache-beam-testing.iam.gserviceaccount.com"
cluster_name_override = "beam-utility"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe one can just create a new tfvars file storing these values and have the workflow involve provisioning the Kubernetes cluster first, separate from the strimzi workload.


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

terraform {
backend "gcs" {
prefix = "beam-utility"
}

required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.22.0"
}
}
}

provider "helm" {
kubernetes {
host = "https://${module.gke.kubernetes_api_endpoint}"
token = data.google_client_config.provider.access_token
cluster_ca_certificate = base64decode(module.gke.cluster_ca_certificate)
}
}

data "google_client_config" "provider" {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

resource "helm_release" "strimzi-helm-release" {
name = "strimzi"
namespace = "strimzi"
create_namespace = true
repository = "https://strimzi.io/charts/"
chart = "strimzi-kafka-operator"
version = "0.40.0"

atomic = "true"
timeout = 500

set {
name = "watchAnyNamespace"
value = "true"
}
depends_on = [ module.gke.google_container_cluster ]
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be in its own module separate from the GKE cluster provisioning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is possible to put it in its own module but the idea behind the utility-cluster folder is to use the GKE module and install everything that is needed for that exact purpose via terraform and in one step. It does not make sense for me to separate out a module as there is no intetion to reuse this due to its specific purpose. Other clusters can crate different folders for different purposes.
Let me know if this is fine and if not ill try to come up with different structure

Copy link
Contributor

@damondouglas damondouglas Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my experience, I find co-mingling GKE provisioning with Kubernetes workload provisioning in the same terraform module to lead to problems in the future. I personally would like to see it in a separate module. I'm more than willing to defer to another Apache Beam committer's opinion, if they think the co-mingling design is ok and have a logical well articulated reason. Otherwise, I'm not comfortable approving this PR with the current design.

In summary, my design preference is:

  1. separate GKE provisioning module - a version controlled tfvars file in the existing .test-infra/terraform/google-cloud-platform/google-kubernetes-engine folder could work
  2. separate folder responsible for provisioning the strimzi cluster

Loading