Skip to content

Commit 7686aea

Browse files
fix(deps): updated reloader helm chart to 2.0.0 (#56)
1 parent 7fd5938 commit 7686aea

File tree

4 files changed

+147
-13
lines changed

4 files changed

+147
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,12 @@ module "es_kubernetes_secret" {
526526
| <a name="input_eso_pod_configuration"></a> [eso\_pod\_configuration](#input\_eso\_pod\_configuration) | Configuration to use to customise ESO deployment on specific pods. Setting appropriate values will result in customising ESO helm release. Default value is {} to keep ESO standard deployment. Ignore the key if not required. | <pre>object({<br/> annotations = optional(object({<br/> # The annotations for external secret controller pods.<br/> external_secrets = optional(map(string), {})<br/> # The annotations for external secret cert controller pods.<br/> external_secrets_cert_controller = optional(map(string), {})<br/> # The annotations for external secret controller pods.<br/> external_secrets_webhook = optional(map(string), {})<br/> }), {})<br/><br/> labels = optional(object({<br/> # The labels for external secret controller pods.<br/> external_secrets = optional(map(string), {})<br/> # The labels for external secret cert controller pods.<br/> external_secrets_cert_controller = optional(map(string), {})<br/> # The labels for external secret controller pods.<br/> external_secrets_webhook = optional(map(string), {})<br/> }), {})<br/> })</pre> | `{}` | no |
527527
| <a name="input_existing_eso_namespace"></a> [existing\_eso\_namespace](#input\_existing\_eso\_namespace) | Existing Namespace to be used to install ESO components including helm releases. If eso\_store\_scope == cluster, this will also be used to deploy ClusterSecretStore/cluster\_store in it | `string` | `null` | no |
528528
| <a name="input_reloader_chart_location"></a> [reloader\_chart\_location](#input\_reloader\_chart\_location) | The location of the Reloader Helm chart. | `string` | `"https://stakater.github.io/stakater-charts"` | no |
529-
| <a name="input_reloader_chart_version"></a> [reloader\_chart\_version](#input\_reloader\_chart\_version) | The version of the Reloader Helm chart. Ensure that the chart version is compatible with the image version specified in reloader\_image\_version. | `string` | `"1.3.0"` | no |
529+
| <a name="input_reloader_chart_version"></a> [reloader\_chart\_version](#input\_reloader\_chart\_version) | The version of the Reloader Helm chart. Ensure that the chart version is compatible with the image version specified in reloader\_image\_version. | `string` | `"2.0.0"` | no |
530530
| <a name="input_reloader_custom_values"></a> [reloader\_custom\_values](#input\_reloader\_custom\_values) | String containing custom values to be used for reloader helm chart. See https://github.com/stakater/Reloader/blob/master/deployments/kubernetes/chart/reloader/values.yaml | `string` | `null` | no |
531531
| <a name="input_reloader_deployed"></a> [reloader\_deployed](#input\_reloader\_deployed) | Whether to deploy reloader or not https://github.com/stakater/Reloader | `bool` | `true` | no |
532532
| <a name="input_reloader_ignore_configmaps"></a> [reloader\_ignore\_configmaps](#input\_reloader\_ignore\_configmaps) | Whether to ignore configmap changes or not | `bool` | `false` | no |
533533
| <a name="input_reloader_ignore_secrets"></a> [reloader\_ignore\_secrets](#input\_reloader\_ignore\_secrets) | Whether to ignore secret changes or not | `bool` | `false` | no |
534-
| <a name="input_reloader_image"></a> [reloader\_image](#input\_reloader\_image) | The reloader image in the format of `[registry-url]/[namespace]/[image]`. | `string` | `"ghcr.io/stakater/reloader"` | no |
534+
| <a name="input_reloader_image"></a> [reloader\_image](#input\_reloader\_image) | The reloader image repository in the format of `[registry-url]/[namespace]/[image]`. | `string` | `"ghcr.io/stakater/reloader"` | no |
535535
| <a name="input_reloader_image_version"></a> [reloader\_image\_version](#input\_reloader\_image\_version) | The version or digest for the reloader image to deploy. If changing the value, ensure it is compatible with the chart version set in reloader\_chart\_version. | `string` | `"v1.3.0-ubi@sha256:21bb83e9cf5641620b6a48de1a7e1a0676f438f3b32004c19ea03b55a98bc756"` | no |
536536
| <a name="input_reloader_is_argo_rollouts"></a> [reloader\_is\_argo\_rollouts](#input\_reloader\_is\_argo\_rollouts) | Enable Argo Rollouts | `bool` | `false` | no |
537537
| <a name="input_reloader_is_openshift"></a> [reloader\_is\_openshift](#input\_reloader\_is\_openshift) | Enable OpenShift DeploymentConfigs | `bool` | `true` | no |

main.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,14 @@ resource "helm_release" "pod_reloader" {
228228
version = var.reloader_chart_version
229229
wait = true
230230

231-
# Set the deployment image name and tag
232231
set {
233-
name = "reloader.deployment.image.name"
232+
name = "image.repository"
234233
type = "string"
235234
value = var.reloader_image
236235
}
237236

238237
set {
239-
name = "reloader.deployment.image.tag"
238+
name = "image.tag"
240239
type = "string"
241240
value = var.reloader_image_version
242241
}

tests/pr_test.go

Lines changed: 139 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ package test
44
import (
55
"log"
66
"os"
7+
"path/filepath"
8+
"regexp"
9+
"strings"
710
"testing"
811
"time"
912

@@ -188,9 +191,10 @@ func TestRunDefaultExample(t *testing.T) {
188191
defer func() {
189192
options.TestTearDown()
190193
}()
191-
output, err := options.RunTestConsistency()
194+
_, err := options.RunTestConsistency()
192195

193196
if assert.Nil(t, err, "Consistency test should not have errored") {
197+
194198
outputs := options.LastTestTerraformOutputs
195199
_, tfOutputsErr := testhelper.ValidateTerraformOutputs(outputs, "cluster_id")
196200
if assert.Nil(t, tfOutputsErr, tfOutputsErr) {
@@ -243,10 +247,9 @@ func TestRunDefaultExample(t *testing.T) {
243247
}
244248
}
245249
}
250+
246251
}
247252
}
248-
249-
assert.NotNil(t, output, "Expected some output")
250253
}
251254

252255
func TestRunUpgradeExample(t *testing.T) {
@@ -290,6 +293,82 @@ func TestReloaderOperational(t *testing.T) {
290293
_ = os.Remove(clusterConfigPath)
291294
}()
292295
if assert.Nil(t, err, "Error getting cluster config path") {
296+
// check Reloader is installed with the correct image and version
297+
// assert reloader image
298+
// get the image and version from the variables.tf in options.TerraformDir
299+
// read the file
300+
variablesFile := options.TerraformDir + "/variables.tf"
301+
data, err := os.ReadFile(variablesFile)
302+
if assert.Nil(t, err, "Error reading variables file") {
303+
// parse the file
304+
lines := strings.Split(string(data), "\n")
305+
// find the line with the reloader image
306+
var reloaderImage string
307+
var reloaderVersion string
308+
309+
// Get values from TerraformVars if provided
310+
if options.TerraformVars["reloader_image"] != nil {
311+
reloaderImage = options.TerraformVars["reloader_image"].(string)
312+
} else {
313+
// Check for both reloader_image variables
314+
reloaderImage = extractDefaultValueFromFile(lines, "reloader_image")
315+
316+
// If still not found, check the root variables.tf file
317+
if reloaderImage == "" {
318+
rootVariablesPath := filepath.Join(options.TerraformDir, "..", "..", "variables.tf")
319+
if rootData, err := os.ReadFile(rootVariablesPath); err == nil {
320+
rootLines := strings.Split(string(rootData), "\n")
321+
reloaderImage = extractDefaultValueFromFile(rootLines, "reloader_image")
322+
}
323+
}
324+
}
325+
326+
if options.TerraformVars["reloader_image_version"] != nil {
327+
reloaderVersion = options.TerraformVars["reloader_image_version"].(string)
328+
} else {
329+
// Find the line with the reloader version
330+
reloaderVersion = extractDefaultValueFromFile(lines, "reloader_image_version")
331+
// If not found, check the root variables.tf file
332+
if reloaderVersion == "" {
333+
rootVariablesPath := filepath.Join(options.TerraformDir, "..", "..", "variables.tf")
334+
if rootData, err := os.ReadFile(rootVariablesPath); err == nil {
335+
rootLines := strings.Split(string(rootData), "\n")
336+
reloaderVersion = extractDefaultValueFromFile(rootLines, "reloader_image_version")
337+
}
338+
}
339+
}
340+
341+
// Check the image and version
342+
// Get reloader pods - use the correct labels and namespace
343+
esoNamespace := "apikeynspace1" // staticly set in locals of basic example
344+
345+
// assert all values are set
346+
if !assert.NotEmpty(t, reloaderImage, "Reloader image is empty") {
347+
t.Log("FAILURE: Reloader image is empty - could not find value in variables")
348+
}
349+
350+
if !assert.NotEmpty(t, reloaderVersion, "Reloader version is empty") {
351+
t.Log("FAILURE: Reloader version is empty - could not find value in variables")
352+
}
353+
354+
// Get the reloader pods
355+
reloaderPods, err := k8s.ListPodsE(t, k8s.NewKubectlOptions("", clusterConfigPath, esoNamespace), metav1.ListOptions{
356+
LabelSelector: "provider=stakater,group=com.stakater.platform",
357+
})
358+
if assert.Nil(t, err, "Error getting reloader pods") {
359+
if assert.GreaterOrEqual(t, len(reloaderPods), 1, "Expected at least one reloader pod") {
360+
reloaderPod := reloaderPods[0]
361+
// Check the image of the reloader pod
362+
actualImage := reloaderPod.Spec.Containers[0].Image
363+
expectedImage := reloaderImage + ":" + reloaderVersion
364+
if !assert.Equal(t, expectedImage, actualImage, "Reloader image does not match expected image") {
365+
t.Logf("FAILURE: Reloader image does not match expected image. Expected: %s, Actual: %s", expectedImage, actualImage)
366+
}
367+
}
368+
}
369+
}
370+
371+
// test reloader functionality
293372
sampleApp := "./samples/sample.yaml"
294373
deploymentName := "example-deployment"
295374
namespace := "reloader-test-ns"
@@ -319,6 +398,7 @@ func TestReloaderOperational(t *testing.T) {
319398
t.Log("Initial secret value found in logs")
320399
t.Log(logs)
321400
}
401+
322402
// update secret with updated secret
323403
applyError = k8s.KubectlApplyE(t, ocOptions, updatedSecret)
324404
if assert.Nil(t, applyError, "Error applying updated secret") {
@@ -347,7 +427,8 @@ func TestReloaderOperational(t *testing.T) {
347427
currentPods, err := GetPodNamesFromDeployment(t, ocOptions, deploymentName)
348428
if err != nil {
349429
t.Log("Error getting initialPod names")
350-
break
430+
// Use the labeled break to exit the outer loop
431+
continue Loop
351432
}
352433

353434
for _, pod := range currentPods {
@@ -407,3 +488,57 @@ func GetPodNamesFromDeployment(t *testing.T, options *k8s.KubectlOptions, deploy
407488

408489
return podNames, nil
409490
}
491+
492+
// Helper function to extract default value from terraform variable definitions
493+
func extractDefaultValueFromFile(lines []string, variableName string) string {
494+
inTargetVariable := false
495+
for _, line := range lines {
496+
line = strings.TrimSpace(line)
497+
if strings.HasPrefix(line, "variable") && strings.Contains(line, "\""+variableName+"\"") {
498+
inTargetVariable = true
499+
continue
500+
}
501+
502+
// We're in the target variable block, look for the default value
503+
if inTargetVariable {
504+
if strings.HasPrefix(line, "default") {
505+
// Extract the value between = and either # or end of line
506+
parts := strings.Split(line, "=")
507+
if len(parts) > 1 {
508+
value := strings.TrimSpace(parts[1])
509+
510+
// Remove trailing comment if exists
511+
if strings.Contains(value, "#") {
512+
value = strings.Split(value, "#")[0]
513+
value = strings.TrimSpace(value)
514+
}
515+
516+
// Handle quoted strings properly
517+
if strings.HasPrefix(value, "\"") {
518+
// Extract the string using proper quote handling
519+
// This handles any content in quotes, even if it contains special characters
520+
re := regexp.MustCompile(`"((?:\\"|[^"])*)"`)
521+
matches := re.FindStringSubmatch(value)
522+
if len(matches) >= 2 {
523+
// Get the content inside the quotes and unescape any quotes
524+
value = strings.ReplaceAll(matches[1], "\\\"", "\"")
525+
} else {
526+
// Fallback to simple trim if regex didn't work
527+
value = strings.Trim(value, "\"")
528+
}
529+
}
530+
531+
// Remove trailing spaces or commas
532+
value = strings.TrimRight(value, " ,")
533+
return value
534+
}
535+
}
536+
537+
// If we hit a closing brace, we've exited the variable block
538+
if line == "}" {
539+
inTargetVariable = false
540+
}
541+
}
542+
}
543+
return ""
544+
}

variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@ variable "reloader_custom_values" {
196196

197197
variable "reloader_image" {
198198
type = string
199-
description = "The reloader image in the format of `[registry-url]/[namespace]/[image]`."
199+
description = "The reloader image repository in the format of `[registry-url]/[namespace]/[image]`."
200200
default = "ghcr.io/stakater/reloader"
201201
nullable = false
202+
202203
}
203204

204205
variable "reloader_image_version" {
@@ -222,7 +223,6 @@ variable "reloader_chart_location" {
222223
variable "reloader_chart_version" {
223224
type = string
224225
description = "The version of the Reloader Helm chart. Ensure that the chart version is compatible with the image version specified in reloader_image_version."
225-
# renovate: datasource=github-releases depName=stakater/Reloader
226-
default = "1.3.0"
227-
nullable = false
226+
default = "2.0.0"
227+
nullable = false
228228
}

0 commit comments

Comments
 (0)