Skip to content

Commit

Permalink
Merge pull request #1262 from SanjalKatiyar/rook_external_script
Browse files Browse the repository at this point in the history
Fetch external RHCS script from Rook CSV
  • Loading branch information
openshift-merge-bot[bot] authored Mar 25, 2024
2 parents 241a027 + d97d8cb commit 0409def
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 27 deletions.
1 change: 0 additions & 1 deletion packages/ocs/constants/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const PVC_PROVISIONER_ANNOTATION =
'volume.beta.kubernetes.io/storage-provisioner';
export const OCS_OPERATOR = 'ocs-operator';
export const COMPRESSION_ON = 'aggressive';

export enum POOL_STATE {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { useODFNamespaceSelector } from '@odf/core/redux';
import { useODFSystemFlagsSelector } from '@odf/core/redux';
import { secretResource } from '@odf/core/resources';
import { OCS_OPERATOR } from '@odf/shared/constants';
import { BreakdownCardBody } from '@odf/shared/dashboards/breakdown-card/breakdown-body';
import { LabelPadding } from '@odf/shared/dashboards/breakdown-card/breakdown-chart';
import { getGroupedSelectOptions } from '@odf/shared/dashboards/breakdown-card/breakdown-dropdown';
Expand All @@ -28,11 +29,7 @@ import {
import * as _ from 'lodash-es';
import { useParams } from 'react-router-dom-v5-compat';
import { Card, CardBody, CardHeader, CardTitle } from '@patternfly/react-core';
import {
OCS_OPERATOR,
ServiceType,
CapacityBreakdown,
} from '../../../constants';
import { ServiceType, CapacityBreakdown } from '../../../constants';
import { breakdownQueryMapMCG } from '../../../queries';
import { ODFSystemParams } from '../../../types';
import { decodeRGWPrefix, getStackChartStats } from '../../../utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { useSafeK8sWatchResource } from '@odf/core/hooks';
import { useODFSystemFlagsSelector } from '@odf/core/redux';
import { K8sResourceObj } from '@odf/core/types';
import {
OCS_OPERATOR,
Breakdown,
DataConsumption,
Metrics,
ServiceType,
} from '@odf/ocs/constants';
import { DATA_CONSUMPTION_QUERIES } from '@odf/ocs/queries';
import { getRangeVectorStats } from '@odf/shared/charts';
import { OCS_OPERATOR } from '@odf/shared/constants';
import { FieldLevelHelp } from '@odf/shared/generic/FieldLevelHelp';
import {
useCustomPrometheusPoll,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as React from 'react';
import { OCS_OPERATOR } from '@odf/core/constants';
import { ODF_MODEL_FLAG } from '@odf/core/features';
import { useODFNamespaceSelector } from '@odf/core/redux';
import { useODFSystemFlagsSelector } from '@odf/core/redux';
import { ODF_OPERATOR } from '@odf/shared/constants';
import { ODF_OPERATOR, OCS_OPERATOR } from '@odf/shared/constants';
import {
useCustomPrometheusPoll,
usePrometheusBasePath,
Expand Down
4 changes: 2 additions & 2 deletions packages/ocs/dashboards/persistent-external/details-card.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import { CEPH_BRAND_NAME, OCS_OPERATOR } from '@odf/core/constants';
import { CEPH_BRAND_NAME } from '@odf/core/constants';
import { ODF_MODEL_FLAG } from '@odf/core/features';
import { useODFNamespaceSelector } from '@odf/core/redux';
import { getStorageClusterInNs } from '@odf/core/utils';
import { ODF_OPERATOR } from '@odf/shared/constants';
import { ODF_OPERATOR, OCS_OPERATOR } from '@odf/shared/constants';
import { useFetchCsv } from '@odf/shared/hooks/use-fetch-csv';
import { SecretModel } from '@odf/shared/models';
import { getName } from '@odf/shared/selectors';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { useODFSystemFlagsSelector } from '@odf/core/redux';
import { getStorageClusterInNs } from '@odf/core/utils';
import { OCS_OPERATOR } from '@odf/shared/constants';
import {
useCustomPrometheusPoll,
usePrometheusBasePath,
Expand Down Expand Up @@ -30,7 +31,7 @@ import { EventKind } from '@openshift-console/dynamic-plugin-sdk/lib/api/interna
import * as _ from 'lodash-es';
import { useParams } from 'react-router-dom-v5-compat';
import { Card, CardHeader, CardTitle, CardBody } from '@patternfly/react-core';
import { OCS_OPERATOR, PVC_PROVISIONER_ANNOTATION } from '../../../constants';
import { PVC_PROVISIONER_ANNOTATION } from '../../../constants';
import { StorageClusterModel } from '../../../models';
import {
DATA_RESILIENCY_QUERY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
StorageClassComponentProps as ExternalComponentProps,
StorageClassWizardStepExtensionProps as ExternalStorage,
} from '@odf/odf-plugin-sdk/extensions';
import { ROOK_CEPH_OPERATOR, OCS_OPERATOR } from '@odf/shared/constants';
import { useK8sGet } from '@odf/shared/hooks/k8s-get-hook';
import { useFetchCsv } from '@odf/shared/hooks/use-fetch-csv';
import {
Expand All @@ -41,8 +42,6 @@ import {
} from '@patternfly/react-core';
import './system-connection-details.scss';

const OCS_OPERATOR = 'ocs-operator';

const SCRIPT_NAME = 'ceph-external-cluster-details-exporter.py';

export const getValidationKeys = (
Expand All @@ -65,18 +64,27 @@ export const ConnectionDetails: React.FC<ExternalComponentProps<RHCSState>> = ({

const [pods, podsLoaded, podsLoadError] =
useK8sGet<ListKind<PodKind>>(PodModel);
const [csv, csvLoaded, csvLoadError] = useFetchCsv({

// From 4.16 onwards Rook will have separate CSV & Subscription.
const [rookCSV, rookCSVLoaded, rookCSVError] = useFetchCsv({
specName: ROOK_CEPH_OPERATOR,
namespace: odfNamespace,
startPollingInstantly: isNsSafe,
});

const [ocsCSV, ocsCSVLoaded, ocsCSVError] = useFetchCsv({
specName: OCS_OPERATOR,
namespace: odfNamespace,
startPollingInstantly: isNsSafe,
});

const { fileName, fileData, errorMessage, isLoading } = formState;

const annotations = getAnnotations(csv);
const rookAnnotations = getAnnotations(rookCSV, {});
const ocsAnnotations = getAnnotations(ocsCSV, {});

const downloadFile = createDownloadFile(
annotations?.['external.features.ocs.openshift.io/export-script']
rookAnnotations?.['externalClusterScript']
);

const handleDataChange: FileUploadProps['onDataChange'] = (
Expand All @@ -85,7 +93,7 @@ export const ConnectionDetails: React.FC<ExternalComponentProps<RHCSState>> = ({
) => {
if (isValidJSON(fData)) {
const { plainKeys, secretKeys } = getValidationKeys(
annotations?.['external.features.ocs.openshift.io/validation']
ocsAnnotations?.['external.features.ocs.openshift.io/validation']
);
const ipAddress: string = pods.items?.[0]?.status?.podIP;
const ipFamily: IP_FAMILY = ipAddress
Expand All @@ -103,7 +111,7 @@ export const ConnectionDetails: React.FC<ExternalComponentProps<RHCSState>> = ({
};

const handleFileChange: FileUploadProps['onFileInputChange'] = (
event,
_event,
file: File
) => {
const fName = file.name;
Expand All @@ -112,8 +120,8 @@ export const ConnectionDetails: React.FC<ExternalComponentProps<RHCSState>> = ({

return (
<ErrorHandler
error={podsLoadError || csvLoadError}
loaded={podsLoaded && csvLoaded}
error={podsLoadError || rookCSVError || ocsCSVError}
loaded={podsLoaded && rookCSVLoaded && ocsCSVLoaded}
>
<Form>
<FormGroup
Expand All @@ -130,7 +138,7 @@ export const ConnectionDetails: React.FC<ExternalComponentProps<RHCSState>> = ({
the RHCS cluster, then upload the results (JSON) in the
External storage system metadata field.
</Trans>{' '}
{downloadFile && (
{!!downloadFile && (
<a
id="downloadAnchorElem"
href={downloadFile}
Expand Down
10 changes: 6 additions & 4 deletions packages/odf/components/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,12 @@ export const checkError = (
return '';
};

export const createDownloadFile = (data: string = ''): string =>
`data:application/octet-stream;charset=utf-8,${encodeURIComponent(
Base64.decode(data)
)}`;
export const createDownloadFile = (data: string): string =>
!!data
? `data:application/octet-stream;charset=utf-8,${encodeURIComponent(
Base64.decode(data)
)}`
: '';

export const isValidJSON = (fData: string): boolean => {
try {
Expand Down
1 change: 0 additions & 1 deletion packages/odf/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const LABEL_OPERATOR = 'In';
export const OCS_SUPPORT_ANNOTATION = 'features.ocs.openshift.io/enabled';
export const OCS_DISABLED_ANNOTATION = 'features.ocs.openshift.io/disabled';
export const ODF_VENDOR_ANNOTATION = 'vendors.odf.openshift.io/kind';
export const OCS_OPERATOR = 'ocs-operator';
export const OCS_DEVICE_SET_FLEXIBLE_REPLICA = 1;
export const OCS_DEVICE_SET_MINIMUM_REPLICAS = 3;
export const MINIMUM_NODES = 3;
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export const DASH = '-';
export const AVAILABLE = 'Available';
export const CEPH_STORAGE_NAMESPACE = 'openshift-storage';
export const ODF_OPERATOR = 'odf-operator';
export const OCS_OPERATOR = 'ocs-operator';
export const ROOK_CEPH_OPERATOR = 'rook-ceph-operator';
export const ONE_SECOND = 1000;
export const ONE_MINUTE = 60 * ONE_SECOND;
export const ONE_HOUR = 60 * ONE_MINUTE;
Expand Down

0 comments on commit 0409def

Please sign in to comment.