diff --git a/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs b/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs index f4b40b2d5..ad5b73d53 100644 --- a/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs +++ b/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs @@ -50,6 +50,8 @@ class KubernetesDeployAction : BaseAction public string HashFilesPattern { get; set; } = ""; public bool BuildImage { get; set; } = true; + public IDictionary KeysSecretAnnotations { get; private set; } + public KubernetesDeployAction(ISecretsManager secretsManager) { _secretsManager = secretsManager; @@ -93,6 +95,7 @@ public override ICommandLineParserResult ParseArgs(string[] args) SetFlag("config-file", "if --write-configs is true, write configs to this file (default: 'functions.yaml')", f => ConfigFile = f); SetFlag("hash-files", "Files to hash to determine the image version", f => HashFilesPattern = f); SetFlag("image-build", "If false, skip the docker build", f => BuildImage = f); + SetFlag("keys-secret-annotations", "The annotations to add to the keys secret e.g. key1=val1,key2=val2", a => KeysSecretAnnotations = a.Split(',').Select(s => s.Split('=')).ToDictionary(k => k[0], v => v[1])); return base.ParseArgs(args); } @@ -145,7 +148,9 @@ public override async Task RunAsync() MaxReplicaCount, KeysSecretCollectionName, MountFuncKeysAsContainerVolume, - KedaVersion); + KedaVersion, + KeysSecretAnnotations + ); if (DryRun) { diff --git a/src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs b/src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs index dc12ae96b..d10e04a89 100644 --- a/src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs +++ b/src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs @@ -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 keySecretsAnnotations = null) { IKubernetesResource scaledObject = null; var result = new List(); @@ -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++; } @@ -481,9 +482,13 @@ public QuoteNumbersEventEmitter(IEventEmitter nextEmitter) public override void Emit(ScalarEventInfo eventInfo, IEmitter emitter) { if (eventInfo.Source.Type == typeof(string) && double.TryParse(eventInfo.Source.Value.ToString(), out _)) + { + eventInfo.Style = ScalarStyle.DoubleQuoted; + } else if (eventInfo.Source.Type == typeof(string) && bool.TryParse(eventInfo.Source.Value.ToString(), out _)) { eventInfo.Style = ScalarStyle.DoubleQuoted; } + base.Emit(eventInfo, emitter); } } @@ -642,7 +647,7 @@ private static ServiceV1 GetService(string name, string @namespace, DeploymentV1 }; } - private static SecretsV1 GetSecret(string name, string @namespace, IDictionary secrets) + private static SecretsV1 GetSecret(string name, string @namespace, IDictionary secrets, IDictionary annotations = null) { return new SecretsV1 { @@ -651,7 +656,8 @@ private static SecretsV1 GetSecret(string name, string @namespace, IDictionary k.Key, v => Convert.ToBase64String(Encoding.UTF8.GetBytes(v.Value))) };