Skip to content

Commit ba6c445

Browse files
authored
[KubernetesV1] Using default configtype instead of failing (#9506)
* [KubernetesV1] Using default configtype instead of failing * Fixing test * Making the default false
1 parent e297274 commit ba6c445

File tree

5 files changed

+81
-71
lines changed

5 files changed

+81
-71
lines changed

Tasks/KubernetesV1/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@
9292
"loc.messages.ConfigurationFileNotFound": "No configuration file matching %s was found.",
9393
"loc.messages.KubernetesServiceConnectionNotFound": "Kubernetes service connection details not found.",
9494
"loc.messages.OutputVariableDataSizeExceeded": "Output variable not set as kubectl command output exceeded the maximum supported length. Output length: %s, Maximum supported length: %s",
95-
"loc.messages.InvalidConfiguration": "Can not set configuration with both file: %s and inline configuration: %s."
95+
"loc.messages.InvalidConfiguration": "No Kubernetes configuration found, supply either inline configuration or configuration file path"
9696
}

Tasks/KubernetesV1/Tests/L0.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -575,19 +575,21 @@ describe('Kubernetes Suite', function() {
575575
done();
576576
});
577577

578-
it('Run fails when both configurations are provided through yaml', (done:MochaDone) => {
578+
it('Run defaults to filepath when both configurations are provided through yaml', (done:MochaDone) => {
579579
let tp = path.join(__dirname, 'TestSetup.js');
580580
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
581581
process.env[shared.TestEnvVars.command] = shared.Commands.apply;
582582
process.env[shared.TestEnvVars.useConfigurationFile] = "true";
583583
process.env[shared.TestEnvVars.configurationType] = ''; //does not matter during a yaml definition
584-
process.env[shared.TestEnvVars.configuration] = 'someFile.yaml'; //dummy value to trigger not default configuration condition
584+
process.env[shared.TestEnvVars.configuration] = shared.formatPath("dir/deployment.yaml"); //dummy value to trigger not default configuration condition
585585
process.env[shared.TestEnvVars.inline] = 'sometextforinline';
586586
tr.run();
587587

588-
assert(tr.failed, 'task should have failed');
589-
assert(tr.invokedToolCount == 0, 'should not have invoked the tool. actual: ' + tr.invokedToolCount);
590-
assert(tr.stderr.length > 0 || tr.errorIssues.length, 'should have written an error message');
588+
assert(tr.succeeded, 'task should have succeeded');
589+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
590+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
591+
assert(tr.succeeded, 'task should have succeeded');
592+
assert(tr.stdout.indexOf(`[command]kubectl apply -f ${shared.formatPath("dir/deployment.yaml")} -o json`) != -1, "kubectl apply should run");
591593
console.log(tr.stderr);
592594
done();
593595
});

Tasks/KubernetesV1/src/kubernetescommand.ts

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,40 @@ function getCommandOutputFormat(kubecommand: string) : string[] {
4545
function getCommandConfigurationFile(): string[] {
4646
var args: string[] = [];
4747
var useConfigurationFile: boolean = tl.getBoolInput("useConfigurationFile", false);
48-
let configurationPath = tl.getPathInput("configuration", false);
49-
var inlineConfiguration = tl.getInput("inline", false);
50-
51-
if (!tl.filePathSupplied("configuration")) {
52-
configurationPath = null;
53-
}
54-
if (configurationPath != null && inlineConfiguration != null) {
55-
throw new Error(tl.loc('InvalidConfiguration', configurationPath, inlineConfiguration));
56-
}
57-
else if (configurationPath) {
58-
//apply incoming configuration irrespective of useConfigurationFile flag. Simplifies yaml definition for pipelines
59-
if (tl.exist(configurationPath)) {
60-
args[0] = "-f";
61-
args[1] = configurationPath;
48+
if (useConfigurationFile) {
49+
let configurationPath = tl.getPathInput("configuration", false);
50+
var inlineConfiguration = tl.getInput("inline", false);
51+
52+
if (!tl.filePathSupplied("configuration")) {
53+
configurationPath = null;
6254
}
63-
else {
64-
throw new Error(tl.loc('ConfigurationFileNotFound', configurationPath));
55+
56+
if (configurationPath != null && inlineConfiguration != null) {
57+
let type = tl.getInput("configurationType", false);
58+
if (type == "inline") configurationPath = null;
59+
else inlineConfiguration = null;
6560
}
66-
}
67-
else if (inlineConfiguration) {
68-
var tempInlineFile = utils.writeInlineConfigInTempPath(inlineConfiguration);
69-
if (tl.exist(tempInlineFile)) {
70-
args[0] = "-f";
71-
args[1] = tempInlineFile;
72-
} else {
73-
throw new Error(tl.loc('ConfigurationFileNotFound', tempInlineFile));
61+
62+
if (configurationPath == null && inlineConfiguration == null) {
63+
throw new Error(tl.loc('InvalidConfiguration'));
64+
}
65+
else if (configurationPath) {
66+
if (tl.exist(configurationPath)) {
67+
args[0] = "-f";
68+
args[1] = configurationPath;
69+
}
70+
else {
71+
throw new Error(tl.loc('ConfigurationFileNotFound', configurationPath));
72+
}
73+
}
74+
else if (inlineConfiguration) {
75+
var tempInlineFile = utils.writeInlineConfigInTempPath(inlineConfiguration);
76+
if (tl.exist(tempInlineFile)) {
77+
args[0] = "-f";
78+
args[1] = tempInlineFile;
79+
} else {
80+
throw new Error(tl.loc('ConfigurationFileNotFound', tempInlineFile));
81+
}
7482
}
7583
}
7684

Tasks/KubernetesV1/task.json

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 1,
1616
"Minor": 1,
17-
"Patch": 21
17+
"Patch": 22
1818
},
1919
"demands": [],
2020
"releaseNotes": "What's new in Version 1.0:<br/>&nbsp;Added new service connection type input for easy selection of Azure AKS cluster.<br/>&nbsp;Replaced output variable input with output variables section that we had added in all tasks.",
@@ -160,42 +160,42 @@
160160
"visibleRule": "command != login && command != logout"
161161
},
162162
{
163-
"name": "configurationType",
164-
"type": "radio",
165-
"label": "Configuration type",
166-
"defaultValue": "configuration",
167-
"groupName": "commands",
168-
"helpMarkDown": "Type of Kubernetes configuration for kubectl command. It can be a file path or an inline script.",
169-
"options": {
170-
"configuration": "File path",
171-
"inline": "Inline configuration"
172-
},
173-
"visibleRule": "useConfigurationFile = true"
174-
},
175-
{
176-
"name": "configuration",
177-
"type": "filePath",
178-
"label": "File path",
179-
"defaultValue": "",
180-
"required": true,
181-
"helpMarkDown": "Filename, directory, or URL to kubernetes configuration files that will be used with the commands.",
182-
"visibleRule": "configurationType = configuration",
183-
"groupName": "commands"
184-
},
185-
{
186-
"name": "inline",
187-
"type": "multiLine",
188-
"properties": {
189-
"resizable": "true",
190-
"rows": "10",
191-
"maxLength": "5000"
192-
},
193-
"required": true,
194-
"defaultValue": "",
195-
"label": "Inline configuration",
196-
"helpMarkDown": "Inline deployment configuration for kubectl command",
197-
"groupName": "commands",
198-
"visibleRule": "configurationType = inline"
163+
"name": "configurationType",
164+
"type": "radio",
165+
"label": "Configuration type",
166+
"defaultValue": "configuration",
167+
"groupName": "commands",
168+
"helpMarkDown": "Type of Kubernetes configuration for kubectl command. It can be a file path or an inline script.",
169+
"options": {
170+
"configuration": "File path",
171+
"inline": "Inline configuration"
172+
},
173+
"visibleRule": "useConfigurationFile = true"
174+
},
175+
{
176+
"name": "configuration",
177+
"type": "filePath",
178+
"label": "File path",
179+
"defaultValue": "",
180+
"required": true,
181+
"helpMarkDown": "Filename, directory, or URL to kubernetes configuration files that will be used with the commands.",
182+
"visibleRule": "configurationType = configuration",
183+
"groupName": "commands"
184+
},
185+
{
186+
"name": "inline",
187+
"type": "multiLine",
188+
"properties": {
189+
"resizable": "true",
190+
"rows": "10",
191+
"maxLength": "5000"
192+
},
193+
"required": true,
194+
"defaultValue": "",
195+
"label": "Inline configuration",
196+
"helpMarkDown": "Inline deployment configuration for kubectl command",
197+
"groupName": "commands",
198+
"visibleRule": "configurationType = inline"
199199
},
200200
{
201201
"name": "arguments",
@@ -358,7 +358,7 @@
358358
"name": "versionSpec",
359359
"type": "string",
360360
"label": "Version spec",
361-
"defaultValue": "1.7.0",
361+
"defaultValue": "1.13.2",
362362
"helpMarkDown": "Version Spec of version to get. Examples: 1.7.0, 1.x.0, 4.x.0, 6.10.0, >=6.10.0",
363363
"groupName": "advanced",
364364
"visibleRule": "versionOrLocation = version"
@@ -466,6 +466,6 @@
466466
"ConfigurationFileNotFound": "No configuration file matching %s was found.",
467467
"KubernetesServiceConnectionNotFound": "Kubernetes service connection details not found.",
468468
"OutputVariableDataSizeExceeded": "Output variable not set as kubectl command output exceeded the maximum supported length. Output length: %s, Maximum supported length: %s",
469-
"InvalidConfiguration": "Can not set configuration with both file: %s and inline configuration: %s."
469+
"InvalidConfiguration": "No Kubernetes configuration found, supply either inline configuration or configuration file path"
470470
}
471471
}

Tasks/KubernetesV1/task.loc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 1,
1515
"Minor": 1,
16-
"Patch": 21
16+
"Patch": 22
1717
},
1818
"demands": [],
1919
"releaseNotes": "ms-resource:loc.releaseNotes",
@@ -357,7 +357,7 @@
357357
"name": "versionSpec",
358358
"type": "string",
359359
"label": "ms-resource:loc.input.label.versionSpec",
360-
"defaultValue": "1.7.0",
360+
"defaultValue": "1.13.2",
361361
"helpMarkDown": "ms-resource:loc.input.help.versionSpec",
362362
"groupName": "advanced",
363363
"visibleRule": "versionOrLocation = version"

0 commit comments

Comments
 (0)