Skip to content

Commit 2cc8779

Browse files
Make it possible to add annotations to the keys secret (#3484)
* Make it possible to add annotations to the keys secret * fix inconsistent naming * we need to quote booleans as well * fix naming * fix review comments * fix condition according to comments --------- Co-authored-by: Lilian Kasem <[email protected]>
1 parent a061764 commit 2cc8779

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/Azure.Functions.Cli/Actions/KubernetesActions/KubernetesDeployAction.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class KubernetesDeployAction : BaseAction
5050
public string HashFilesPattern { get; set; } = "";
5151
public bool BuildImage { get; set; } = true;
5252

53+
public IDictionary<string, string> KeySecretAnnotations { get; private set; }
54+
5355
public KubernetesDeployAction(ISecretsManager secretsManager)
5456
{
5557
_secretsManager = secretsManager;
@@ -93,6 +95,7 @@ public override ICommandLineParserResult ParseArgs(string[] args)
9395
SetFlag<string>("config-file", "if --write-configs is true, write configs to this file (default: 'functions.yaml')", f => ConfigFile = f);
9496
SetFlag<string>("hash-files", "Files to hash to determine the image version", f => HashFilesPattern = f);
9597
SetFlag<bool>("image-build", "If false, skip the docker build", f => BuildImage = f);
98+
SetFlag<string>("key-secret-annotations", "The annotations to add to the keys secret e.g. key1=val1,key2=val2", a => KeySecretAnnotations = a.Split(',').Select(s => s.Split('=')).ToDictionary(k => k[0], v => v[1]));
9699

97100
return base.ParseArgs(args);
98101
}
@@ -145,7 +148,9 @@ public override async Task RunAsync()
145148
MaxReplicaCount,
146149
KeysSecretCollectionName,
147150
MountFuncKeysAsContainerVolume,
148-
KedaVersion);
151+
KedaVersion,
152+
KeySecretAnnotations
153+
);
149154

150155
if (DryRun)
151156
{

src/Azure.Functions.Cli/Kubernetes/KubernetesHelpers.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ internal static async Task CreateNamespace(string @namespace)
106106
int? maxReplicas = null,
107107
string keysSecretCollectionName = null,
108108
bool mountKeysAsContainerVolume = false,
109-
KedaVersion? kedaVersion = null)
109+
KedaVersion? kedaVersion = null,
110+
IDictionary<string, string> keySecretsAnnotations = null)
110111
{
111112
IKubernetesResource scaledObject = null;
112113
var result = new List<IKubernetesResource>();
@@ -224,7 +225,7 @@ internal static async Task CreateNamespace(string @namespace)
224225
resultantFunctionKeys = GetFunctionKeys(currentImageFuncKeys, await GetExistingFunctionKeys(keysSecretCollectionName, @namespace));
225226
if (resultantFunctionKeys.Any())
226227
{
227-
result.Insert(resourceIndex, GetSecret(keysSecretCollectionName, @namespace, resultantFunctionKeys));
228+
result.Insert(resourceIndex, GetSecret(keysSecretCollectionName, @namespace, resultantFunctionKeys, annotations: keySecretsAnnotations));
228229
resourceIndex++;
229230
}
230231

@@ -480,10 +481,13 @@ public QuoteNumbersEventEmitter(IEventEmitter nextEmitter)
480481

481482
public override void Emit(ScalarEventInfo eventInfo, IEmitter emitter)
482483
{
483-
if (eventInfo.Source.Type == typeof(string) && double.TryParse(eventInfo.Source.Value.ToString(), out _))
484+
if (eventInfo.Source.Type == typeof(string) &&
485+
(double.TryParse(eventInfo.Source.Value.ToString(), out _) ||
486+
bool.TryParse(eventInfo.Source.Value.ToString(), out _)))
484487
{
485488
eventInfo.Style = ScalarStyle.DoubleQuoted;
486489
}
490+
487491
base.Emit(eventInfo, emitter);
488492
}
489493
}
@@ -642,7 +646,7 @@ private static ServiceV1 GetService(string name, string @namespace, DeploymentV1
642646
};
643647
}
644648

645-
private static SecretsV1 GetSecret(string name, string @namespace, IDictionary<string, string> secrets)
649+
private static SecretsV1 GetSecret(string name, string @namespace, IDictionary<string, string> secrets, IDictionary<string, string> annotations = null)
646650
{
647651
return new SecretsV1
648652
{
@@ -651,7 +655,8 @@ private static SecretsV1 GetSecret(string name, string @namespace, IDictionary<s
651655
Metadata = new ObjectMetadataV1
652656
{
653657
Name = name,
654-
Namespace = @namespace
658+
Namespace = @namespace,
659+
Annotations = annotations
655660
},
656661
Data = secrets.ToDictionary(k => k.Key, v => Convert.ToBase64String(Encoding.UTF8.GetBytes(v.Value)))
657662
};

0 commit comments

Comments
 (0)