Merge pull request #935 from spotify/freben/namespace

Make namespace schema stricter (according to k8s)
This commit is contained in:
Fredrik Adelöw
2020-05-20 11:07:27 +02:00
committed by GitHub
5 changed files with 26 additions and 1 deletions
@@ -72,7 +72,7 @@ export class DescriptorEnvelopeParser {
.test(
'metadata.namespace',
'The namespace is malformed',
value => value === undefined || validators.isValidEntityName(value),
value => value === undefined || validators.isValidNamespace(value),
);
const labelsSchema = yup
@@ -83,6 +83,25 @@ describe('KubernetesValidatorFunctions', () => {
expect(KubernetesValidatorFunctions.isValidObjectName(value)).toBe(matches);
});
it.each([
[7, false],
[null, false],
['', false],
['a', true],
['AZ09', false],
['a'.repeat(63), true],
['a'.repeat(64), false],
['a/b', false],
['a-b', true],
['-a-b', false],
['a-b-', false],
['a--b', false],
['a_b', false],
['a.b', false],
])('isValidNamespace', (value, matches) => {
expect(KubernetesValidatorFunctions.isValidNamespace(value)).toBe(matches);
});
it.each([
[7, false],
[null, false],
@@ -52,6 +52,10 @@ export class KubernetesValidatorFunctions {
);
}
static isValidNamespace(value: any): boolean {
return CommonValidatorFunctions.isValidDnsLabel(value);
}
static isValidLabelKey(value: any): boolean {
return CommonValidatorFunctions.isValidPrefixAndOrSuffix(
value,
@@ -22,6 +22,7 @@ const defaultValidators: Validators = {
isValidApiVersion: KubernetesValidatorFunctions.isValidApiVersion,
isValidKind: KubernetesValidatorFunctions.isValidKind,
isValidEntityName: KubernetesValidatorFunctions.isValidObjectName,
isValidNamespace: KubernetesValidatorFunctions.isValidNamespace,
normalizeEntityName: CommonValidatorFunctions.normalizeToLowercaseAlphanum,
isValidLabelKey: KubernetesValidatorFunctions.isValidLabelKey,
isValidLabelValue: KubernetesValidatorFunctions.isValidLabelValue,
@@ -18,6 +18,7 @@ export type Validators = {
isValidApiVersion(value: any): boolean;
isValidKind(value: any): boolean;
isValidEntityName(value: any): boolean;
isValidNamespace(value: any): boolean;
normalizeEntityName(value: string): string;
isValidLabelKey(value: any): boolean;
isValidLabelValue(value: any): boolean;