Skip to content

Commit 84cc4a9

Browse files
committed
fix(management): K8SNS management jobs now provide useful error if alias is invalid.
1 parent 71fecc2 commit 84cc4a9

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

kubernetes-orchestrator-extension/Jobs/Management.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ private V1Secret HandlePkcs12Secret(ManagementJobConfiguration config, bool remo
281281
{
282282
if (config.OperationType == CertStoreOperationType.Remove)
283283
{
284-
Logger.LogWarning("Secret {Name} not found in Kubernetes so nothing to remove...", KubeSecretName);
284+
Logger.LogWarning("Secret {Name} not found in Kubernetes, nothing to remove...", KubeSecretName);
285285
return null;
286286
}
287-
Logger.LogWarning("Secret {Name} not found in Kubernetes so creating new secret...", KubeSecretName);
287+
Logger.LogWarning("Secret {Name} not found in Kubernetes, creating new secret...", KubeSecretName);
288288
}
289289
}
290290

@@ -548,6 +548,13 @@ private JobResult HandleCreateOrUpdate(string secretType, ManagementJobConfigura
548548
jobCertObj.Alias = config.JobCertificate.Alias;
549549
// Split alias by / and get second to last element KubeSecretType
550550
var splitAlias = jobCertObj.Alias.Split("/");
551+
if (splitAlias.Length < 2)
552+
{
553+
var invalidAliasErrMsg = "Invalid alias format for K8SNS store type. Alias pattern: `<secret_type>/<secret_name>` where `secret_type` is one of 'opaque' or 'tls' and `secret_name` is the name of the secret.";
554+
Logger.LogError(invalidAliasErrMsg);
555+
Logger.LogInformation("End MANAGEMENT job " + config.JobId + " " + invalidAliasErrMsg + " Failed!");
556+
return FailJob(invalidAliasErrMsg, config.JobHistoryId);
557+
}
551558
KubeSecretType = splitAlias[^2];
552559
KubeSecretName = splitAlias[^1];
553560
Logger.LogDebug("Handling managment add job for K8SNS secret type '" + KubeSecretType + "(" + jobCertObj.Alias + ")'...");

0 commit comments

Comments
 (0)