Skip to content

Commit

Permalink
the image name reported is now the one of the container actually bein…
Browse files Browse the repository at this point in the history
…g injected instead of the first container of the pod
  • Loading branch information
svevia committed Apr 30, 2024
1 parent 27e1742 commit e237ca9
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void ApplyPatches(PatchingContext context, V1Pod pod, IAgentPatcher? age
var writableVolumeMount = new V1VolumeMount(context.WritableMountPath, writableVolume.Name, readOnlyProperty: false);
container.VolumeMounts.AddOrUpdate(writableVolumeMount.Name, writableVolumeMount);

var genericPatches = GenerateEnvVars(context, pod);
var genericPatches = GenerateEnvVars(context, pod, container);
var agentPatches = agentPatcher?.GenerateEnvVars(context) ?? Array.Empty<V1EnvVar>();

foreach (var envVar in genericPatches.Concat(agentPatches))
Expand All @@ -132,10 +132,10 @@ private void ApplyPatches(PatchingContext context, V1Pod pod, IAgentPatcher? age
}
}

private string GetVarsFromCluster(string value, V1Pod pod, PatchingContext context)
private string GetVarsFromCluster(string value, V1Pod pod, PatchingContext context, V1Container container)
{
value = value.Replace("%namespace%", context.WorkloadNamespace);
value = value.Replace("%image%", pod.Spec.Containers[0].Image);
value = value.Replace("%image%", container.Image);

//labels
string pattern = @"%labels.(.*?)%";
Expand Down Expand Up @@ -293,7 +293,7 @@ private IEnumerable<V1Container> GetMatchingContainers(PatchingContext context,
}
}

private IEnumerable<V1EnvVar> GenerateEnvVars(PatchingContext context, V1Pod pod)
private IEnumerable<V1EnvVar> GenerateEnvVars(PatchingContext context, V1Pod pod, V1Container container)
{
var (workloadName, workloadNamespace, _, connection, configuration, agentMountPath, writableMountPath) = context;

Expand Down Expand Up @@ -333,7 +333,7 @@ private IEnumerable<V1EnvVar> GenerateEnvVars(PatchingContext context, V1Pod pod
//if value contains % then call a new function called getVarsFromCluster
if (value.Contains("%"))
{
yield return new V1EnvVar($"CONTRAST__{key.Replace(".", "__").ToUpperInvariant()}", GetVarsFromCluster(value, pod, context));
yield return new V1EnvVar($"CONTRAST__{key.Replace(".", "__").ToUpperInvariant()}", GetVarsFromCluster(value, pod, context, container));
}
else
{
Expand Down

0 comments on commit e237ca9

Please sign in to comment.