Skip to content

Commit 0547905

Browse files
Update API response to include status.lastAppliedRevision fields (#1643)
* Update API response to include status.lastAppliedRevision fields * add test cover * revert application snap
1 parent d12ba2b commit 0547905

File tree

9 files changed

+259
-115
lines changed

9 files changed

+259
-115
lines changed

api/pipelines/pipelines.swagger.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@
263263
},
264264
"version": {
265265
"type": "string"
266+
},
267+
"lastAppliedRevision": {
268+
"type": "string"
266269
}
267270
}
268271
}

api/pipelines/types.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ message WorkloadStatus {
3737
string kind = 1;
3838
string name = 2;
3939
string version = 3;
40+
string lastAppliedRevision = 4;
4041
}
4142

4243
message PipelineTargetStatus {

pkg/api/pipelines/types.pb.go

Lines changed: 72 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/pipelines/server/get.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func getWorkloadStatus(obj *unstructured.Unstructured) (*pb.WorkloadStatus, erro
108108
ws.Kind = hr.Kind
109109
ws.Name = hr.Name
110110
ws.Version = hr.Spec.Chart.Spec.Version
111+
ws.LastAppliedRevision = hr.Status.LastAppliedRevision
111112
}
112113

113114
return ws, nil

pkg/pipelines/server/get_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func TestGetPipeline(t *testing.T) {
4040

4141
assert.Equal(t, p.Name, res.Pipeline.Name)
4242
assert.Equal(t, res.Pipeline.Status.Environments[envName].TargetsStatuses[0].Workloads[0].Version, hr.Spec.Chart.Spec.Version)
43+
assert.Equal(t, res.Pipeline.Status.Environments[envName].TargetsStatuses[0].Workloads[0].LastAppliedRevision, hr.Status.LastAppliedRevision)
4344
assert.Equal(t, res.Pipeline.Status.Environments[envName].TargetsStatuses[0].Namespace, targetNamespace.Name)
4445
})
4546

@@ -109,6 +110,9 @@ func createHelmRelease(ctx context.Context, t *testing.T, k client.Client, name
109110
},
110111
},
111112
},
113+
Status: helm.HelmReleaseStatus{
114+
LastAppliedRevision: "0.1.2",
115+
},
112116
}
113117

114118
require.NoError(t, k.Create(ctx, hr))

ui-cra/src/api/pipelines/types.pb.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export type WorkloadStatus = {
3535
kind?: string
3636
name?: string
3737
version?: string
38+
lastAppliedRevision?: string
3839
}
3940

4041
export type PipelineTargetStatus = {

ui-cra/src/components/Pipelines/PipelineDetails/__tests__/PipelineDetails.test.tsx

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable testing-library/no-node-access */
12
import { act, render, RenderResult, screen } from '@testing-library/react';
23
import { formatURL } from '@weaveworks/weave-gitops';
34
import PipelineDetails from '..';
@@ -81,6 +82,7 @@ const res: GetPipelineResponse = {
8182
kind: 'HelmRelease',
8283
name: 'podinfo',
8384
version: '6.2.0',
85+
lastAppliedRevision: '6.2.0',
8486
},
8587
],
8688
},
@@ -141,6 +143,16 @@ const res: GetPipelineResponse = {
141143
},
142144
};
143145

146+
interface MappedWorkload {
147+
kind?: string | undefined;
148+
name?: string | undefined;
149+
namespace?: string | undefined;
150+
version?: string | undefined;
151+
lastAppliedVersion?: string | undefined;
152+
mappedClusterName?: string | undefined;
153+
clusterName?: string | undefined;
154+
}
155+
144156
describe('PipelineDetails', () => {
145157
let wrap: (el: JSX.Element) => JSX.Element;
146158
let api: PipelinesClientMock;
@@ -178,23 +190,14 @@ describe('PipelineDetails', () => {
178190
);
179191
expect(targets.length).toEqual(env.targets?.length);
180192

181-
let workloads: {
182-
target: string | undefined;
183-
kind?: string | undefined;
184-
name?: string | undefined;
185-
namespace?: string | undefined;
186-
version?: string | undefined;
187-
clusterName?: string | undefined;
188-
}[] = [];
193+
let workloads: MappedWorkload[] = [];
189194

190195
targetsStatuses[env.name!].targetsStatuses?.forEach(ts => {
191196
if (ts.workloads) {
192197
const wrks = ts.workloads.map(wrk => ({
193198
...wrk,
194-
target: ts.clusterRef?.name
195-
? `${ts.clusterRef?.name}/${ts.namespace}`
196-
: ts.namespace,
197-
clusterName: ts.clusterRef?.namespace
199+
clusterName: ts.clusterRef?.name,
200+
mappedClusterName: ts.clusterRef?.namespace
198201
? `${ts.clusterRef?.namespace}/${ts.clusterRef.name}`
199202
: '',
200203
namespace: ts.namespace,
@@ -205,28 +208,55 @@ describe('PipelineDetails', () => {
205208

206209
// Targets
207210
targets.forEach((target, index) => {
208-
// Target
209-
const workloadTarget =
210-
target.querySelector('.workloadTarget')?.textContent;
211-
expect(workloadTarget).toEqual(workloads![index].target);
211+
const workloadTarget = target.querySelector('.workloadTarget');
212+
213+
// Cluster Name
214+
const clusterNameEle = workloadTarget?.querySelector('.cluster-name');
215+
if (workloads![index].clusterName) {
216+
checkTextContentToEqual(
217+
clusterNameEle,
218+
workloads![index].clusterName || '',
219+
);
220+
} else {
221+
elementToBeNull(clusterNameEle);
222+
}
223+
224+
// Workload Namespace
225+
const workloadNamespace = workloadTarget?.querySelector(
226+
'.workload-namespace',
227+
);
228+
expect(workloadNamespace?.textContent).toEqual(
229+
workloads![index].namespace,
230+
);
212231

213232
//Target as a link
214233
const linkToAutomation = target.querySelector('.workloadName > a');
215-
216-
if (workloads![index].clusterName) {
234+
if (workloads![index].mappedClusterName) {
217235
const href = formatURL('/helm_release/details', {
218236
name: workloads![index].name,
219237
namespace: workloads![index].namespace,
220-
clusterName: workloads![index].clusterName,
238+
clusterName: workloads![index].mappedClusterName,
221239
});
222240
linkToExists(linkToAutomation, href);
223241
} else {
224-
linkToBeNull(linkToAutomation);
242+
elementToBeNull(linkToAutomation);
243+
checkTextContentToEqual(
244+
target.querySelector('.workload-name'),
245+
workloads![index].name || '',
246+
);
247+
}
248+
// Workload Last Applied Version
249+
const lastAppliedRevision = target.querySelector(
250+
'workloadName > .last-applied-version',
251+
);
252+
if (workloads![index].lastAppliedVersion) {
253+
checkTextContentToEqual(
254+
lastAppliedRevision,
255+
workloads![index].lastAppliedVersion || '',
256+
);
257+
} else {
258+
elementToBeNull(lastAppliedRevision);
225259
}
226-
227-
// Workload Name
228-
const workloadName = target.querySelector('.workloadName')?.textContent;
229-
expect(workloadName).toEqual(workloads![index].name);
230260

231261
// Workload Version
232262
const workloadVersion = target.querySelector('.version')?.textContent;
@@ -254,9 +284,16 @@ describe('PipelineDetails', () => {
254284
});
255285
});
256286

257-
const linkToExists = (element: Element | null, href: String) => {
258-
return expect(element).toHaveAttribute('href', href);
287+
const linkToExists = (element: Element | null, href: string) => {
288+
expect(element).toHaveAttribute('href', href);
259289
};
260-
const linkToBeNull = (element: Element | null) => {
261-
return expect(element).toBeNull();
290+
const elementToBeNull = (element: Element | null | undefined) => {
291+
expect(element).toBeNull();
292+
};
293+
294+
const checkTextContentToEqual = (
295+
element: Element | null | undefined,
296+
clusterName: string,
297+
) => {
298+
expect(element?.textContent).toEqual(clusterName);
262299
};

0 commit comments

Comments
 (0)