From 8826ed2194a76b9261d574be2565a6584b558d10 Mon Sep 17 00:00:00 2001 From: Simon Dahlbacka Date: Wed, 11 Oct 2023 13:56:39 +0300 Subject: [PATCH 1/4] Make it possible to add annotations to the keys secret --- .../KubernetesActions/KubernetesDeployAction.cs | 9 +++++++-- .../Kubernetes/KubernetesHelpers.cs | 10 ++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs b/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs index f58d70449..104df4c75 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 KeySecretsAnnotations { 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 true, 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 => KeySecretsAnnotations = 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, + KeySecretsAnnotations + ); if (DryRun) { @@ -295,4 +300,4 @@ private static Dictionary ReadFunctionJsons(string functionsPat throw new CliArgumentsException("either --image-name or --registry is required."); } } -} \ No newline at end of file +} diff --git a/src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs b/src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs index dc12ae96b..1d1f7cd68 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++; } @@ -642,7 +643,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 +652,8 @@ private static SecretsV1 GetSecret(string name, string @namespace, IDictionary k.Key, v => Convert.ToBase64String(Encoding.UTF8.GetBytes(v.Value))) }; From 93860efce3ef1b97d9710a49fb44ad0811eb8507 Mon Sep 17 00:00:00 2001 From: Simon Dahlbacka Date: Wed, 11 Oct 2023 14:41:47 +0300 Subject: [PATCH 2/4] fix inconsistent naming --- .../Actions/KubernetesActions/KubernetesDeployAction.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs b/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs index 69d891f91..be7417cd4 100644 --- a/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs +++ b/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs @@ -50,7 +50,7 @@ class KubernetesDeployAction : BaseAction public string HashFilesPattern { get; set; } = ""; public bool BuildImage { get; set; } = true; - public IDictionary KeySecretsAnnotations { get; private set; } + public IDictionary KeysSecretAnnotations { get; private set; } public KubernetesDeployAction(ISecretsManager secretsManager) { @@ -149,7 +149,7 @@ public override async Task RunAsync() KeysSecretCollectionName, MountFuncKeysAsContainerVolume, KedaVersion, - KeySecretsAnnotations + KeysSecretAnnotations ); if (DryRun) From 25a9a25024a12600b7e8ced527938c8cc2fa70ce Mon Sep 17 00:00:00 2001 From: Simon Dahlbacka Date: Wed, 11 Oct 2023 14:42:23 +0300 Subject: [PATCH 3/4] we need to quote booleans as well --- src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs b/src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs index 1d1f7cd68..d10e04a89 100644 --- a/src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs +++ b/src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs @@ -482,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); } } From 0c9c5a18810df73b5245e827eb4c508fc7af521f Mon Sep 17 00:00:00 2001 From: Simon Dahlbacka Date: Mon, 28 Oct 2024 19:24:32 +0200 Subject: [PATCH 4/4] fix naming --- .../Actions/KubernetesActions/KubernetesDeployAction.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs b/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs index be7417cd4..ad5b73d53 100644 --- a/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs +++ b/src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs @@ -95,7 +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 => KeySecretsAnnotations = a.Split(',').Select(s => s.Split('=')).ToDictionary(k => k[0], v => v[1])); + 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); }