Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to add annotations to the keys secret #3484

Open
wants to merge 2 commits into
base: v4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class KubernetesDeployAction : BaseAction
public string HashFilesPattern { get; set; } = "";
public bool BuildImage { get; set; } = true;

public IDictionary<string, string> KeySecretsAnnotations { get; private set; }

public KubernetesDeployAction(ISecretsManager secretsManager)
{
_secretsManager = secretsManager;
Expand Down Expand Up @@ -93,6 +95,7 @@ public override ICommandLineParserResult ParseArgs(string[] args)
SetFlag<string>("config-file", "if --write-configs is true, write configs to this file (default: 'functions.yaml')", f => ConfigFile = f);
SetFlag<string>("hash-files", "Files to hash to determine the image version", f => HashFilesPattern = f);
SetFlag<bool>("image-build", "If true, skip the docker build", f => BuildImage = f);
SetFlag<string>("keys-secret-annotations", "The annotations to add to the keys secret e.g. key1=val1,key2=val2", a => KeySecretsAnnotations = a.Split(',').Select(s => s.Split('=')).ToDictionary(k => k[0], v => v[1]));

return base.ParseArgs(args);
}
Expand Down Expand Up @@ -145,7 +148,9 @@ public override async Task RunAsync()
MaxReplicaCount,
KeysSecretCollectionName,
MountFuncKeysAsContainerVolume,
KedaVersion);
KedaVersion,
KeySecretsAnnotations
);

if (DryRun)
{
Expand Down Expand Up @@ -295,4 +300,4 @@ private static Dictionary<string, JObject> ReadFunctionJsons(string functionsPat
throw new CliArgumentsException("either --image-name or --registry is required.");
}
}
}
}
10 changes: 6 additions & 4 deletions src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ internal static async Task CreateNamespace(string @namespace)
int? maxReplicas = null,
string keysSecretCollectionName = null,
bool mountKeysAsContainerVolume = false,
KedaVersion? kedaVersion = null)
KedaVersion? kedaVersion = null,
IDictionary<string, string> keySecretsAnnotations = null)
{
IKubernetesResource scaledObject = null;
var result = new List<IKubernetesResource>();
Expand Down Expand Up @@ -224,7 +225,7 @@ internal static async Task CreateNamespace(string @namespace)
resultantFunctionKeys = GetFunctionKeys(currentImageFuncKeys, await GetExistingFunctionKeys(keysSecretCollectionName, @namespace));
if (resultantFunctionKeys.Any())
{
result.Insert(resourceIndex, GetSecret(keysSecretCollectionName, @namespace, resultantFunctionKeys));
result.Insert(resourceIndex, GetSecret(keysSecretCollectionName, @namespace, resultantFunctionKeys, annotations: keySecretsAnnotations));
resourceIndex++;
}

Expand Down Expand Up @@ -642,7 +643,7 @@ private static ServiceV1 GetService(string name, string @namespace, DeploymentV1
};
}

private static SecretsV1 GetSecret(string name, string @namespace, IDictionary<string, string> secrets)
private static SecretsV1 GetSecret(string name, string @namespace, IDictionary<string, string> secrets, IDictionary<string, string> annotations = null)
{
return new SecretsV1
{
Expand All @@ -651,7 +652,8 @@ private static SecretsV1 GetSecret(string name, string @namespace, IDictionary<s
Metadata = new ObjectMetadataV1
{
Name = name,
Namespace = @namespace
Namespace = @namespace,
Annotations = annotations
},
Data = secrets.ToDictionary(k => k.Key, v => Convert.ToBase64String(Encoding.UTF8.GetBytes(v.Value)))
};
Expand Down