Skip to content

Commit d8b98bc

Browse files
committed
make pipelines editable
1 parent 9d755cd commit d8b98bc

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

client/src/components/pipelines/new.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ export default {
194194
},
195195
data: () => ({
196196
newPipeline: true,
197+
resourceVersion: undefined,
197198
repotab: 'github', //selected tab
198199
buildpack: undefined,
199200
buildpackList: [],
@@ -437,6 +438,8 @@ export default {
437438
.then(response => {
438439
this.newPipeline = false;
439440
const p = response.data;
441+
442+
this.resourceVersion = p.resourceVersion;
440443
this.pipelineName = p.name;
441444
this.domain = p.domain;
442445
this.gitrepo = p.git.repository.ssh_url;
@@ -490,6 +493,7 @@ export default {
490493
},
491494
updatePipeline() {
492495
axios.put(`/api/pipelines/${this.pipeline}`, {
496+
resourceVersion: this.resourceVersion,
493497
pipelineName: this.pipelineName,
494498
domain: this.domain,
495499
gitrepo: this.gitrepo,

src/kubero.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class Kubero {
128128

129129
// creates a new pipeline in the same namespace as the kubero app
130130
public async newPipeline(pipeline: IPipeline) {
131-
debug.debug('create newPipeline: '+pipeline.name);
131+
debug.debug('create Pipeline: '+pipeline.name);
132132

133133
// Create the Pipeline CRD
134134
await this.kubectl.createPipeline(pipeline);
@@ -140,6 +140,21 @@ export class Kubero {
140140
this._io.emit('updatedPipelines', "created");
141141
}
142142

143+
// updates a new pipeline in the same namespace as the kubero app
144+
public async updatePipeline(pipeline: IPipeline, resourceVersion: string) {
145+
debug.debug('update Pipeline: '+pipeline.name);
146+
147+
// Create the Pipeline CRD
148+
await this.kubectl.updatePipeline(pipeline, resourceVersion);
149+
this.updateState();
150+
151+
this.kubectl.createEvent('Normal', 'Updated', 'pipeline.updated', 'updated pipeline: '+pipeline.name);
152+
153+
// update agents
154+
this._io.emit('updatedPipelines', "updated");
155+
}
156+
157+
143158
public async listPipelines(): Promise<IPipelineList> {
144159
debug.debug('listPipelines');
145160
let pipelines = await this.kubectl.getPipelinesList();
@@ -162,6 +177,7 @@ export class Kubero {
162177
});
163178

164179
if (pipeline) {
180+
pipeline.spec.resourceVersion = pipeline.metadata.resourceVersion;
165181
return pipeline.spec;
166182
}
167183
}

src/modules/kubectl.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ export class Kubectl {
103103
return pipelines.body as IKubectlPipelineList;
104104
}
105105

106-
107106
public async createPipeline(pl: IPipeline) {
108107
debug.log("create pipeline: " + pl.name);
109108
let pipeline = new KubectlPipeline(pl);
@@ -120,6 +119,24 @@ export class Kubectl {
120119
});
121120
}
122121

122+
public async updatePipeline(pl: IPipeline, resourceVersion: string ) {
123+
debug.log("update pipeline: " + pl.name);
124+
let pipeline = new KubectlPipeline(pl);
125+
pipeline.metadata.resourceVersion = resourceVersion;
126+
127+
this.kc.setCurrentContext(process.env.KUBERO_CONTEXT || 'default');
128+
await this.customObjectsApi.replaceNamespacedCustomObject(
129+
"application.kubero.dev",
130+
"v1alpha1",
131+
process.env.KUBERO_NAMESPACE || 'kubero',
132+
"kuberopipelines",
133+
pl.name,
134+
pipeline
135+
).catch(error => {
136+
debug.log(error);
137+
});
138+
}
139+
123140
public async deletePipeline(pipelineName: string) {
124141
debug.log("delete pipeline: " + pipelineName);
125142
this.kc.setCurrentContext(process.env.KUBERO_CONTEXT || 'default');

src/routes/pipelines.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ Router.post('/pipelines',authMiddleware, async function (req: Request, res: Resp
6767
res.send("new");
6868
});
6969

70+
71+
Router.put('/pipelines/:pipeline',authMiddleware, async function (req: Request, res: Response) {
72+
// #swagger.tags = ['UI']
73+
// #swagger.summary = 'Edit a pipeline'
74+
// #swagger.parameters['body'] = { in: 'body', description: 'Pipeline object', required: true, type: 'object' }
75+
let pipeline: IPipeline = {
76+
name: req.body.pipelineName,
77+
domain: req.body.domain,
78+
phases: req.body.phases,
79+
buildpack: req.body.buildpack,
80+
reviewapps: req.body.reviewapps,
81+
git: req.body.git,
82+
dockerimage: req.body.dockerimage,
83+
deploymentstrategy: req.body.deploymentstrategy,
84+
};
85+
req.app.locals.kubero.updatePipeline(pipeline, req.body.resourceVersion);
86+
res.send("new");
87+
});
88+
7089
Router.get('/cli/pipelines', bearerMiddleware, async function (req: Request, res: Response) {
7190
// #swagger.tags = ['Pipeline']
7291
// #swagger.summary = 'Get a list of available pipelines'

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export interface IPipeline {
145145
};
146146
dockerimage: string;
147147
deploymentstrategy: 'git' | 'docker',
148+
resourceVersion?: string; // required to update resource, not part of spec
148149
}
149150

150151
export interface IPipelineList {

0 commit comments

Comments
 (0)