Azure / Azure/azure-functions-core-tools

func kubernetes deploy should not overwrite spec.containers.envfrom

Open
#3,284 1 comment 0 reactions 0 assignees View on GitHub
area: kubernetes enhancement investigate
Dominant language
C#
Stars
1.5k
Forks
498
Avg merge
5d 4h
Merged PRs (30d)
15

Description

func kubernetes deploy overwrites the spec.containers.envfrom path and does not provide a way to supply references to existing secrets or configmaps as per the visual exhibit

```

spec:
containers:
- name: somefunc-http
image: docker.io/repo/image:latest
ports:
- containerPort: 80
protocol: TCP
envFrom:
- secretRef:
name: somefunc
- configMapRef:
name: no_way_to_supply_as_option_and_overwritten_on_subsequent_deploy
env:

```

instead, func kubernetes deploiy should
* patch spec.containers.envFrom
* permit additional envFrom references to be supplied during deployment

currently [this ](https://github.com/Azure/azure-functions-core-tools/blob/v4.x/src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs)seems to be the the applicable code

this code is annotated with some triage
```
int resourceIndex = 0;
if (useConfigMap)
{
var configMap = GetConfigMap(name, @namespace, secrets);
result.Insert(resourceIndex, configMap);
resourceIndex++;
foreach (var deployment in deployments)
{
#region will need
// will need different code paths for patch vs put
// will need to read the existing deployment and get array of current envFrom
var svc = await KubectlHelper.KubectlGet($"{deployment.Metadata.Name}-deployment --namespace {deployment.Metadata.Namespace}");
// will need to diff the existing envFrom with what's about to be rendered

var endpoint = svc.SelectToken("spec.template.spec.containers.envFrom ")?.ToString();
#endregion will need

// looks like there's a need for an inner loop or some clever linq set operation here that iterates the array of existing envfrom
// minus the below keys being rendered - patch vs put
deployment.Spec.Template.Spec.Containers.First().EnvFrom = new ContainerEnvironmentFromV1[]
{
new ContainerEnvironmentFromV1
{
ConfigMapRef = new NamedObjectV1
{
Name = configMap.Metadata.Name
}
}
};
}
}
```
the current workflow is hampered by the need to patch this field after each redeployment
regards

Contributor guide

Open the contributing guide

Research direction

Start in src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs and inspect the deployment workflow around the config-map handling and KubectlHelper.KubectlGet call. Determine how existing spec.template.spec.containers.envFrom entries can be preserved while adding deployment-supplied references. Done means redeployment no longer overwrites existing secret or config-map references and additional envFrom references can be supplied.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, kubernetes
Domain
cli, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.