-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(mc): Add module for Prometheus, refactor, add tests (#1294)
# Description * add module for Prometheus deployment * add example and test for Prometheus module * add tests for each testUtils.go functions * refactor ## Related Issue #1267 ## Checklist - [x] I have read the [contributing documentation](https://retina.sh/docs/contributing). - [x] I signed and signed-off the commits (`git commit -S -s ...`). See [this documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification) on signing commits. - [x] I have correctly attributed the author(s) of the code. - [x] I have tested the changes locally. - [x] I have followed the project's style guidelines. - [x] I have updated the documentation, if necessary. - [x] I have added tests, if applicable. ## Screenshots (if applicable) or Testing Completed Please add any relevant screenshots or GIFs to showcase the changes made. ## Additional Notes Add any additional notes or context about the pull request here. --- Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more information on how to contribute to this project.
- Loading branch information
Showing
20 changed files
with
533 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
test/multicloud/examples/integration/prometheus-kind/.terraform.lock.hcl
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module "kind" { | ||
source = "../../../modules/kind" | ||
prefix = var.prefix | ||
} | ||
|
||
module "prometheus" { | ||
depends_on = [module.kind] | ||
source = "../../../modules/prometheus" | ||
} |
19 changes: 19 additions & 0 deletions
19
test/multicloud/examples/integration/prometheus-kind/outputs.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
output "host" { | ||
value = module.kind.host | ||
sensitive = true | ||
} | ||
|
||
output "cluster_ca_certificate" { | ||
value = module.kind.cluster_ca_certificate | ||
sensitive = true | ||
} | ||
|
||
output "client_certificate" { | ||
value = module.kind.client_certificate | ||
sensitive = true | ||
} | ||
|
||
output "client_key" { | ||
value = module.kind.client_key | ||
sensitive = true | ||
} |
26 changes: 26 additions & 0 deletions
26
test/multicloud/examples/integration/prometheus-kind/providers.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
terraform { | ||
required_version = "1.8.3" | ||
required_providers { | ||
kind = { | ||
source = "tehcyx/kind" | ||
version = "0.7.0" | ||
} | ||
helm = { | ||
source = "hashicorp/helm" | ||
version = "2.17.0" | ||
} | ||
} | ||
} | ||
|
||
# Initialize the kind provider | ||
provider "kind" {} | ||
|
||
# Initialize the Helm provider | ||
provider "helm" { | ||
kubernetes { | ||
host = module.kind.host | ||
client_certificate = module.kind.client_certificate | ||
client_key = module.kind.client_key | ||
cluster_ca_certificate = module.kind.cluster_ca_certificate | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
test/multicloud/examples/integration/prometheus-kind/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
variable "prefix" { | ||
description = "A prefix to add to all resources." | ||
type = string | ||
default = "mc" | ||
} |
3 changes: 0 additions & 3 deletions
3
test/multicloud/examples/integration/retina-kind/test-integration-kind-config
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
test/multicloud/examples/integration/retina-kind/test-kind-config
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
resource "helm_release" "prometheus" { | ||
name = "prometheus" | ||
repository = "https://prometheus-community.github.io/helm-charts" | ||
chart = "kube-prometheus-stack" | ||
version = var.prometheus_version | ||
|
||
dynamic "set" { | ||
for_each = var.values | ||
content { | ||
name = set.value.name | ||
value = set.value.value | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
terraform { | ||
required_providers { | ||
helm = { | ||
source = "hashicorp/helm" | ||
version = "2.17.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
variable "prometheus_version" { | ||
description = "The Prometheus version to install." | ||
type = string | ||
default = "68.4.3" | ||
} | ||
|
||
variable "values" { | ||
description = "Configuration for set blocks, this corresponds to Helm values.yaml" | ||
type = list(object({ | ||
name = string | ||
value = string | ||
})) | ||
default = [ | ||
{ | ||
name = "global.prometheus.enabled" | ||
value = "true" | ||
}, | ||
{ | ||
name = "global.grafana.enabled" | ||
value = "true" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
) | ||
|
||
func TestPrometheusKindIntegration(t *testing.T) { | ||
t.Parallel() | ||
|
||
opts := &terraform.Options{ | ||
TerraformDir: examplesPath + "integration/prometheus-kind", | ||
|
||
Vars: map[string]interface{}{ | ||
"prefix": "test-integration", | ||
}, | ||
} | ||
|
||
// clean up at the end of the test | ||
defer terraform.Destroy(t, opts) | ||
terraform.InitAndApply(t, opts) | ||
|
||
// get outputs | ||
caCert := fetchSensitiveOutput(t, opts, "cluster_ca_certificate") | ||
clientCert := fetchSensitiveOutput(t, opts, "client_certificate") | ||
clientKey := fetchSensitiveOutput(t, opts, "client_key") | ||
host := fetchSensitiveOutput(t, opts, "host") | ||
|
||
// build the REST config | ||
restConfig := createRESTConfigWithClientCert(caCert, clientCert, clientKey, host) | ||
|
||
// create a Kubernetes clientset | ||
clientSet, err := buildClientSet(restConfig) | ||
if err != nil { | ||
t.Fatalf("Failed to create Kubernetes clientset: %v", err) | ||
} | ||
|
||
// test the cluster is accessible | ||
testClusterAccess(t, clientSet) | ||
|
||
podSelector := PodSelector{ | ||
Namespace: "default", | ||
LabelSelector: "app.kubernetes.io/instance=prometheus-kube-prometheus-prometheus", | ||
ContainerName: "prometheus", | ||
} | ||
|
||
timeOut := time.Duration(60) * time.Second | ||
// check the prometheus pods are running | ||
result, err := arePodsRunning(clientSet, podSelector, timeOut) | ||
if !result { | ||
t.Fatalf("Prometheus pods did not start in time: %v\n", err) | ||
} | ||
|
||
// check the retina pods logs for errors | ||
checkPodLogs(t, clientSet, podSelector) | ||
|
||
// TODO: add more tests here | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package test | ||
|
||
const examplesPath = "../examples/" | ||
|
||
type PodSelector struct { | ||
Namespace string | ||
LabelSelector string | ||
ContainerName string | ||
} |
Oops, something went wrong.