Skip to content

Commit

Permalink
Fix ztunnel controller to apply values.ztunnel config
Browse files Browse the repository at this point in the history
In the Sail Operator, any config specified under values.ztunnel
in the ZTunnel resource was being ignored. This fix ensures that
the ztunnel controller correctly applies these values.

Fixes: istio-ecosystem#567
Signed-off-by: Sridhar Gaddam <[email protected]>
  • Loading branch information
sridhargaddam committed Jan 21, 2025
1 parent e27e1be commit fc16652
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
11 changes: 10 additions & 1 deletion controllers/ztunnel/ztunnel_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,16 @@ func (r *Reconciler) installHelmChart(ctx context.Context, ztunnel *v1alpha1.ZTu
return fmt.Errorf("failed to apply profile: %w", err)
}

_, err = r.ChartManager.UpgradeOrInstallChart(ctx, r.getChartDir(ztunnel), mergedHelmValues, ztunnel.Spec.Namespace, ztunnelChart, ownerReference)
// Apply any user Overrides configured as part of values.ztunnel
// This step was not required for the IstioCNI resource because the Helm templates[*] automatically override values.cni
// [*]https://github.com/istio/istio/blob/0200fd0d4c3963a72f36987c2e8c2887df172abf/manifests/charts/istio-cni/templates/zzy_descope_legacy.yaml#L3
// However, ztunnel charts do not have such a file, hence we are manually applying the mergeOperation here.
finalHelmValues, err := istiovalues.ApplyUserValues(helm.FromValues(mergedHelmValues), helm.FromValues(userValues.ZTunnel))
if err != nil {
return fmt.Errorf("failed to apply user overrides: %w", err)
}

_, err = r.ChartManager.UpgradeOrInstallChart(ctx, r.getChartDir(ztunnel), finalHelmValues, ztunnel.Spec.Namespace, ztunnelChart, ownerReference)
if err != nil {
return fmt.Errorf("failed to install/update Helm chart %q: %w", ztunnelChart, err)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/istiovalues/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func ApplyProfilesAndPlatform(
return values, nil
}

func ApplyUserValues(mergedValues, userValues helm.Values,
) (helm.Values, error) {
values := helm.Values(mergeOverwrite(mergedValues, userValues))
return values, nil
}

func resolve(defaultProfile, userProfile string) []string {
switch {
case userProfile != "" && userProfile != "default":
Expand Down
10 changes: 9 additions & 1 deletion tests/e2e/ambient/ambient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ metadata:
spec:
profile: ambient
version: %s
namespace: %s`
namespace: %s
values:
ztunnel:
env:
CUSTOM_ENV_VAR: "true"`
ztunnelYaml = fmt.Sprintf(ztunnelYaml, version.Name, ztunnelNamespace)
Log("ZTunnel YAML:", ztunnelYaml)
Expect(k.CreateFromString(ztunnelYaml)).To(Succeed(), "ZTunnel creation failed")
Expand Down Expand Up @@ -210,6 +214,10 @@ spec:
Expect(ztunnelObj).To(HaveContainersThat(ContainElement(WithTransform(getEnvVars,
ContainElement(corev1.EnvVar{Name: "ISTIO_META_ENABLE_HBONE", Value: "true"})))),
"Expected ISTIO_META_ENABLE_HBONE to be set to true, but not found")

Expect(ztunnelObj).To(HaveContainersThat(ContainElement(WithTransform(getEnvVars,
ContainElement(corev1.EnvVar{Name: "CUSTOM_ENV_VAR", Value: "true"})))),
"Expected CUSTOM_ENV_VAR to be set to true, but not found")
})
})

Expand Down

0 comments on commit fc16652

Please sign in to comment.