Skip to content

Commit

Permalink
test(mc): prometheus integration test to fetch local yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
SRodi committed Feb 11, 2025
1 parent d0f04c3 commit 22afb98
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 4 deletions.
15 changes: 14 additions & 1 deletion test/multicloud/examples/integration/prometheus-kind/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ module "kind" {
prefix = var.prefix
}

module "prometheus" {
module "retina" {
depends_on = [module.kind]
source = "../../../modules/helm-release"
release_name = var.retina_release_name
repository_url = var.retina_repository_url
chart_version = var.retina_chart_version
chart_name = var.retina_chart_name
values = var.retina_values
}

module "prometheus" {
depends_on = [
module.kind,
module.retina
]
source = "../../../modules/helm-release"
release_name = var.prometheus_release_name
repository_url = var.prometheus_repository_url
chart_version = var.prometheus_chart_version
Expand Down
29 changes: 29 additions & 0 deletions test/multicloud/examples/integration/prometheus-kind/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,32 @@ variable "prometheus_values" {
description = "This corresponds to Helm values.yaml"
type = any
}

variable "retina_release_name" {
description = "The name of the Helm release."
type = string
default = "retina"
}

variable "retina_repository_url" {
description = "The URL of the Helm repository."
type = string
default = "oci://ghcr.io/microsoft/retina/charts"
}

variable "retina_chart_version" {
description = "The version of the Helm chart to install."
type = string
default = "v0.0.24"
}

variable "retina_chart_name" {
description = "The name of the Helm chart to install."
type = string
default = "retina"
}

variable "retina_values" {
description = "This corresponds to Helm values.yaml"
type = any
}
14 changes: 13 additions & 1 deletion test/multicloud/test/integration/prometheus_kind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@ import (
func TestPrometheusKindIntegration(t *testing.T) {
t.Parallel()

jsonValues := utils.SerializeYAMLtoJSONstring(t, utils.PrometheusHelmValuesStandard)

opts := &terraform.Options{
TerraformDir: utils.ExamplesPath + "integration/prometheus-kind",

Vars: map[string]interface{}{
"prefix": "test-integration",
"prefix": "test-integration",
"prometheus_values": jsonValues,
"retina_values": map[string]interface{}{
"image": map[string]interface{}{
"tag": "v0.0.24",
},
"operator": map[string]interface{}{
"tag": "v0.0.24",
},
"logLevel": "debug",
},
},
}

Expand Down
5 changes: 3 additions & 2 deletions test/multicloud/test/utils/types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package utils

const (
ExamplesPath = "../../examples/"
RetinaVersion = "v0.0.24"
ExamplesPath = "../../examples/"
RetinaVersion = "v0.0.24"
PrometheusHelmValuesStandard = "../../../../deploy/standard/prometheus/values.yaml"
)

type PodSelector struct {
Expand Down
32 changes: 32 additions & 0 deletions test/multicloud/test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"bufio"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"os"
"strings"
"testing"
"time"
Expand All @@ -15,6 +17,7 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
Expand Down Expand Up @@ -165,3 +168,32 @@ func ArePodsRunning(clientset kubernetes.Interface, podSelector PodSelector, tim
}
return true, nil
}

// readYAMLFile reads a YAML file from the given filename and unmarshals it into a map[string]interface{}.
// It returns the unmarshaled map and any error encountered during the process.
func readYAMLFile(filename string) (map[string]interface{}, error) {
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}

var result map[string]interface{}
err = yaml.Unmarshal(data, &result)
if err != nil {
return nil, err
}
return result, nil
}

func SerializeYAMLtoJSONstring(t *testing.T, fileName string) string {
values, err := readYAMLFile(fileName)
if err != nil {
t.Fatalf("Failed to read values.yaml: %v", err)
}

jsonValues, err := json.Marshal(values)
if err != nil {
t.Fatalf("Failed to serialize YAML to JSON: %v", err)
}
return string(jsonValues)
}

0 comments on commit 22afb98

Please sign in to comment.