forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
operator-hub-page.tsx
438 lines (411 loc) · 16.6 KB
/
operator-hub-page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
import * as React from 'react';
import * as _ from 'lodash';
import { Helmet } from 'react-helmet';
import { Trans, useTranslation } from 'react-i18next';
import { match } from 'react-router';
import { Link } from 'react-router-dom';
import { OPERATOR_BACKED_SERVICE_CATALOG_TYPE_ID } from '@console/dev-console/src/const';
import {
DOC_URL_RED_HAT_MARKETPLACE,
ExternalLink,
Firehose,
MsgBox,
PageHeading,
skeletonCatalog,
StatusBox,
} from '@console/internal/components/utils';
import {
referenceForModel,
CloudCredentialKind,
InfrastructureKind,
AuthenticationKind,
} from '@console/internal/module/k8s';
import { fromRequirements } from '@console/internal/module/k8s/selector';
import { isCatalogTypeEnabled, useIsDeveloperCatalogEnabled } from '@console/shared';
import { ErrorBoundaryFallbackPage, withFallback } from '@console/shared/src/components/error';
import { parseJSONAnnotation } from '@console/shared/src/utils/annotations';
import { iconFor } from '..';
import {
CloudCredentialModel,
AuthenticationModel,
InfrastructureModel,
} from '../../../../../public/models';
import { OPERATOR_TYPE_ANNOTATION, NON_STANDALONE_ANNOTATION_VALUE } from '../../const';
import {
ClusterServiceVersionModel,
PackageManifestModel,
OperatorGroupModel,
SubscriptionModel,
} from '../../models';
import {
ClusterServiceVersionKind,
PackageManifestKind,
OperatorGroupKind,
SubscriptionKind,
} from '../../types';
import { subscriptionFor } from '../operator-group';
import { OperatorHubTileView } from './operator-hub-items';
import {
getCatalogSourceDisplayName,
shortLivedTokenAuth,
isAWSSTSCluster,
} from './operator-hub-utils';
import {
OperatorHubItem,
OperatorHubCSVAnnotations,
InstalledState,
OperatorHubCSVAnnotationKey,
InfraFeatures,
ValidSubscriptionValue,
} from './index';
const ANNOTATIONS_WITH_JSON = [
OperatorHubCSVAnnotationKey.infrastructureFeatures,
OperatorHubCSVAnnotationKey.validSubscription,
];
const clusterServiceVersionFor = (
clusterServiceVersions: ClusterServiceVersionKind[],
csvName: string,
): ClusterServiceVersionKind => {
return clusterServiceVersions?.find((csv) => csv.metadata.name === csvName);
};
const isOpenShiftValidSubscriptionValue = (validSubscriptionValue) =>
[
ValidSubscriptionValue.OpenShiftKubernetesEngine,
ValidSubscriptionValue.OpenShiftContainerPlatform,
ValidSubscriptionValue.OpenShiftPlatformPlus,
].includes(validSubscriptionValue);
export const OperatorHubList: React.FC<OperatorHubListProps> = ({
loaded,
loadError,
marketplacePackageManifests,
namespace,
operatorGroups,
packageManifests,
subscriptions,
clusterServiceVersions,
cloudCredentials,
authentication,
infrastructure,
}) => {
const { t } = useTranslation();
const items: OperatorHubItem[] = React.useMemo(() => {
return [...(marketplacePackageManifests?.data ?? []), ...(packageManifests?.data ?? [])]
.filter((pkg) => {
const { channels, defaultChannel } = pkg.status ?? {};
// if a package does not have status.defaultChannel, exclude it so the app doesn't fail
if (!defaultChannel) {
// eslint-disable-next-line no-console
console.warn(
`PackageManifest ${pkg.metadata.name} has no status.defaultChannel and has been excluded`,
);
return false;
}
const { currentCSVDesc } = channels.find((ch) => ch.name === defaultChannel);
// if CSV contains annotation for a non-standalone operator, filter it out
return !(
currentCSVDesc.annotations?.[OPERATOR_TYPE_ANNOTATION] === NON_STANDALONE_ANNOTATION_VALUE
);
})
.map(
(pkg): OperatorHubItem => {
const { channels, defaultChannel } = pkg.status ?? {};
const { currentCSVDesc } = (channels || []).find(({ name }) => name === defaultChannel);
const currentCSVAnnotations: OperatorHubCSVAnnotations =
currentCSVDesc?.annotations ?? {};
const [parsedInfraFeatures, validSubscription] = ANNOTATIONS_WITH_JSON.map(
(annotationKey) =>
parseJSONAnnotation(currentCSVAnnotations, annotationKey, () =>
// eslint-disable-next-line no-console
console.warn(`Error parsing annotation in PackageManifest ${pkg.metadata.name}`),
) ?? [],
);
const validSubscriptionFilters = validSubscription.reduce(
(previousValidSubscriptionValues, currentValidSubscriptionValue) => {
// The three openshift valid subscriptions values should be appended as-is so that
// they show up as filter options on operator hub
if (isOpenShiftValidSubscriptionValue(currentValidSubscriptionValue)) {
return [...previousValidSubscriptionValues, currentValidSubscriptionValue];
}
// Any value other than the openshift valid subscription values above should be
// aggregated into a single "Requires separate subscription" filter option
if (
!previousValidSubscriptionValues.includes(
ValidSubscriptionValue.RequiresSeparateSubscription,
)
) {
return [
...previousValidSubscriptionValues,
ValidSubscriptionValue.RequiresSeparateSubscription,
];
}
return previousValidSubscriptionValues;
},
[],
);
const {
certifiedLevel,
healthIndex,
repository,
containerImage,
createdAt,
support,
capabilities: capabilityLevel,
[OperatorHubCSVAnnotationKey.disconnected]: disconnected,
[OperatorHubCSVAnnotationKey.fipsCompliant]: fipsCompliant,
[OperatorHubCSVAnnotationKey.proxyAware]: proxyAware,
[OperatorHubCSVAnnotationKey.cnf]: cnf,
[OperatorHubCSVAnnotationKey.cni]: cni,
[OperatorHubCSVAnnotationKey.csi]: csi,
// tlsProfiles requires addtional changes
// [OperatorHubCSVAnnotationKey.tlsProfiles]: tlsProfiles,
[OperatorHubCSVAnnotationKey.tokenAuthAWS]: tokenAuthAWS,
// tokenAuthAzure and tokenAuthGCP require additional changes
// [OperatorHubCSVAnnotationKey.tokenAuthAzure]: tokenAuthAzure,
// [OperatorHubCSVAnnotationKey.tokenAuthGCP]: tokenAuthGCP,
[OperatorHubCSVAnnotationKey.actionText]: marketplaceActionText,
[OperatorHubCSVAnnotationKey.remoteWorkflow]: marketplaceRemoteWorkflow,
[OperatorHubCSVAnnotationKey.supportWorkflow]: marketplaceSupportWorkflow,
} = currentCSVAnnotations;
const subscription =
loaded && subscriptionFor(subscriptions?.data)(operatorGroups?.data)(pkg)(namespace);
const cloudCredential = loaded && cloudCredentials?.data;
const infra = loaded && infrastructure?.data;
const auth = loaded && authentication?.data;
let infrastructureFeatures: InfraFeatures[] = parsedInfraFeatures.map(
(key) => InfraFeatures[key],
);
const featuresAnnotationsObjects = [
{ key: InfraFeatures.Disconnected, value: disconnected },
{ key: InfraFeatures.FipsMode, value: fipsCompliant },
{ key: InfraFeatures.Proxy, value: proxyAware },
{ key: InfraFeatures.cnf, value: cnf },
{ key: InfraFeatures.cni, value: cni },
{ key: InfraFeatures.csi, value: csi },
];
featuresAnnotationsObjects.forEach(({ key, value }) => {
if (value === 'false') {
// override existing operators.openshift.io/infrastructure-features annotation value
infrastructureFeatures = infrastructureFeatures.filter((feature) => feature !== key);
} else if (value === 'true') {
infrastructureFeatures.push(key);
}
});
if (tokenAuthAWS === 'true' && isAWSSTSCluster(cloudCredential, infra, auth)) {
infrastructureFeatures.push(InfraFeatures[shortLivedTokenAuth]);
}
const infraFeatures = _.uniq(_.compact(infrastructureFeatures));
const clusterServiceVersion =
loaded &&
clusterServiceVersionFor(
clusterServiceVersions?.data,
subscription?.status?.installedCSV,
);
const installed = loaded && clusterServiceVersion?.status?.phase === 'Succeeded';
return {
obj: pkg,
kind: PackageManifestModel.kind,
name: currentCSVDesc?.displayName ?? pkg.metadata.name,
uid: `${pkg.metadata.name}-${pkg.status.catalogSource}-${pkg.status.catalogSourceNamespace}`,
installed,
isInstalling:
loaded &&
!_.isNil(subscription) &&
!_.isNil(clusterServiceVersion?.status?.phase) &&
clusterServiceVersion?.status?.phase !== 'Succeeded',
subscription,
installState: installed ? InstalledState.Installed : InstalledState.NotInstalled,
imgUrl: iconFor(pkg),
description: currentCSVAnnotations.description || currentCSVDesc.description,
longDescription: currentCSVDesc.description || currentCSVAnnotations.description,
provider: pkg.status.provider?.name ?? pkg.metadata.labels?.provider,
tags: [],
version: currentCSVDesc?.version,
categories: (currentCSVAnnotations?.categories ?? '')
.split(',')
.map((category) => category.trim()),
catalogSource: pkg.status.catalogSource,
catalogSourceDisplayName: getCatalogSourceDisplayName(pkg),
catalogSourceNamespace: pkg.status.catalogSourceNamespace,
certifiedLevel,
healthIndex,
repository,
containerImage,
createdAt,
support,
capabilityLevel,
marketplaceActionText,
marketplaceRemoteWorkflow,
marketplaceSupportWorkflow,
validSubscription,
validSubscriptionFilters,
infraFeatures,
keywords: currentCSVDesc?.keywords ?? [],
cloudCredentials: cloudCredential,
infrastructure: infra,
authentication: auth,
};
},
);
}, [
clusterServiceVersions,
loaded,
marketplacePackageManifests,
namespace,
operatorGroups,
packageManifests,
subscriptions,
cloudCredentials,
infrastructure,
authentication,
]);
const uniqueItems = _.uniqBy(items, 'uid');
if (uniqueItems.length !== items.length) {
// eslint-disable-next-line no-console
console.warn(`${items.length - uniqueItems.length} duplicate PackageManifests.`);
}
return (
<StatusBox
skeleton={skeletonCatalog}
data={items}
loaded={loaded}
loadError={loadError}
label={t('olm~Resources')}
EmptyMsg={() => (
<MsgBox
title={t('olm~No OperatorHub items found')}
detail={
<span>
<Trans ns="olm">
Please check that the OperatorHub is running and that you have created a valid
CatalogSource. For more information about OperatorHub, please click{' '}
<ExternalLink
href="https://github.com/operator-framework/operator-marketplace"
text={t('olm~here')}
/>
.
</Trans>
</span>
}
/>
)}
>
<OperatorHubTileView items={uniqueItems} namespace={namespace} />
</StatusBox>
);
};
export const OperatorHubPage = withFallback((props: OperatorHubPageProps) => {
const isDevCatalogEnabled = useIsDeveloperCatalogEnabled();
const isOperatorBackedServiceEnabled = isCatalogTypeEnabled(
OPERATOR_BACKED_SERVICE_CATALOG_TYPE_ID,
);
return (
<>
<Helmet>
<title>OperatorHub</title>
</Helmet>
<div className="co-m-page__body">
<div className="co-catalog">
<PageHeading title="OperatorHub" />
<p className="co-catalog-page__description">
{isDevCatalogEnabled && isOperatorBackedServiceEnabled ? (
<Trans ns="olm">
Discover Operators from the Kubernetes community and Red Hat partners, curated by
Red Hat. You can purchase commercial software through{' '}
<ExternalLink href={DOC_URL_RED_HAT_MARKETPLACE}>Red Hat Marketplace</ExternalLink>.
You can install Operators on your clusters to provide optional add-ons and shared
services to your developers. After installation, the Operator capabilities will
appear in the <Link to="/catalog">Developer Catalog</Link> providing a self-service
experience.
</Trans>
) : (
<Trans ns="olm">
Discover Operators from the Kubernetes community and Red Hat partners, curated by
Red Hat. You can purchase commercial software through{' '}
<ExternalLink href={DOC_URL_RED_HAT_MARKETPLACE}>Red Hat Marketplace</ExternalLink>.
You can install Operators on your clusters to provide optional add-ons and shared
services to your developers. The Operator Backed Developer Catalog is currently
disabled, thus Operator capabilities will not be exposed to developers.
</Trans>
)}
</p>
<div className="co-catalog__body">
<Firehose
resources={[
{
isList: true,
kind: referenceForModel(OperatorGroupModel),
prop: 'operatorGroups',
},
{
isList: true,
kind: referenceForModel(PackageManifestModel),
namespace: props.match.params.ns,
selector: { 'openshift-marketplace': 'true' },
prop: 'marketplacePackageManifests',
},
{
isList: true,
kind: referenceForModel(PackageManifestModel),
namespace: props.match.params.ns,
selector: fromRequirements([
{ key: 'opsrc-owner-name', operator: 'DoesNotExist' },
{ key: 'csc-owner-name', operator: 'DoesNotExist' },
]),
prop: 'packageManifests',
},
{
isList: true,
kind: referenceForModel(SubscriptionModel),
prop: 'subscriptions',
},
{
kind: referenceForModel(ClusterServiceVersionModel),
namespaced: true,
isList: true,
namespace: props.match.params.ns,
prop: 'clusterServiceVersions',
},
{
kind: referenceForModel(CloudCredentialModel),
prop: 'cloudCredentials',
name: 'cluster',
},
{
kind: referenceForModel(InfrastructureModel),
prop: 'infrastructure',
name: 'cluster',
},
{
kind: referenceForModel(AuthenticationModel),
prop: 'authentication',
name: 'cluster',
},
]}
>
{/* FIXME(alecmerdler): Hack because `Firehose` injects props without TypeScript knowing about it */}
<OperatorHubList {...(props as any)} namespace={props.match.params.ns} />
</Firehose>
</div>
</div>
</div>
</>
);
}, ErrorBoundaryFallbackPage);
export type OperatorHubPageProps = {
match: match<{ ns?: string }>;
};
export type OperatorHubListProps = {
namespace?: string;
operatorGroups: { loaded: boolean; data?: OperatorGroupKind[] };
packageManifests: { loaded: boolean; data?: PackageManifestKind[] };
marketplacePackageManifests: { loaded: boolean; data?: PackageManifestKind[] };
subscriptions: { loaded: boolean; data?: SubscriptionKind[] };
cloudCredentials: { loaded: boolean; data?: CloudCredentialKind };
infrastructure: { loaded: boolean; data?: InfrastructureKind };
authentication: { loaded: boolean; data?: AuthenticationKind };
loaded: boolean;
loadError?: string;
clusterServiceVersions: { loaded: boolean; data?: ClusterServiceVersionKind[] };
};
OperatorHubList.displayName = 'OperatorHubList';
OperatorHubPage.displayName = 'OperatorHubPage';