Skip to content

Commit

Permalink
Merge pull request #12743 from sg00dwin/select-operator-install-version
Browse files Browse the repository at this point in the history
CONSOLE-3372, OCPBUGS-13648, OCPBUGS-13833: Console supports installing non-latest Operator versions
  • Loading branch information
openshift-merge-robot committed Jun 20, 2023
2 parents 0742e71 + 4af7787 commit 8217b1f
Show file tree
Hide file tree
Showing 11 changed files with 339 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export const operator = {
cy.log('go to operator overview panel');
cy.byTestID(operatorHubCardTestID).click();
cy.log('go to the install form');
cy.log('verify the channel selection is displayed');
cy.get('.co-operator-channel__select').should('exist');
cy.log('verify the version selection is displayed');
cy.get('.co-operator-version__select').should('exist');
cy.byLegacyTestID('operator-install-btn').click({ force: true });
/* Installation mode
* () All namespaces // default: 'openshift-operators'
Expand Down
10 changes: 7 additions & 3 deletions frontend/packages/operator-lifecycle-manager/locales/en/olm.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@
"The Operator Lifecycle Manager will not watch this Namespace because it is not configured with an OperatorGroup.": "The Operator Lifecycle Manager will not watch this Namespace because it is not configured with an OperatorGroup.",
"Create one here.": "Create one here.",
"Select OperatorGroup": "Select OperatorGroup",
"Select a channel": "Select a channel",
"Select a version": "Select a version",
"Show community Operator": "Show community Operator",
"Community Operators are Operators which have not been vetted or verified by Red Hat. Community Operators should be used with caution because their stability is unknown. Red Hat provides no support for community Operators.": "Community Operators are Operators which have not been vetted or verified by Red Hat. Community Operators should be used with caution because their stability is unknown. Red Hat provides no support for community Operators.",
"Learn more about Red Hat’s third party software support policy": "Learn more about Red Hat’s third party software support policy",
Expand All @@ -246,9 +248,10 @@
"Auto Pilot": "Auto Pilot",
"Checked": "Checked",
"Installed Operator": "Installed Operator",
"Version <1>{{installedVersion}}</1> of this Operator has been installed on the cluster.": "Version <1>{{installedVersion}}</1> of this Operator has been installed on the cluster.",
"This Operator has been installed on the cluster.": "This Operator has been installed on the cluster.",
"View it here.": "View it here.",
"Installed Channel": "Installed Channel",
"Installed Version": "Installed Version",
"Installing Operator": "Installing Operator",
"This Operator is being installed on the cluster.": "This Operator is being installed on the cluster.",
"Community Operator": "Community Operator",
Expand All @@ -257,7 +260,8 @@
"This Operator is purchased through Red Hat Marketplace. After completing the purchase process, you can install the Operator on this or other OpenShift clusters. Visit Red Hat Marketplace for more details and to track your usage of this application.": "This Operator is purchased through Red Hat Marketplace. After completing the purchase process, you can install the Operator on this or other OpenShift clusters. Visit Red Hat Marketplace for more details and to track your usage of this application.",
"Learn more about the Red Hat Marketplace": "Learn more about the Red Hat Marketplace",
"N/A": "N/A",
"Latest version": "Latest version",
"Channel": "Channel",
"Version": "Version",
"Capability level": "Capability level",
"Source": "Source",
"Infrastructure features": "Infrastructure features",
Expand Down Expand Up @@ -319,7 +323,7 @@
"The strategy to determine either manual or automatic updates.": "The strategy to determine either manual or automatic updates.",
"Will function as manual approval strategy": "Will function as manual approval strategy",
"Manual approval applies to all operators in a namespace": "Manual approval applies to all operators in a namespace",
"Installing an operator with manual approval causes all operators installed in namespace <1>{{selectedTargetNamespace}}</1> to function as manual approval strategy. To allow automatic approval, all operators installed in the namespace must use automatic approval strategy.": "Installing an operator with manual approval causes all operators installed in namespace <1>{{selectedTargetNamespace}}</1> to function as manual approval strategy. To allow automatic approval, all operators installed in the namespace must use automatic approval strategy.",
"Installing an operator with manual approval causes all operators installed in namespace <1>{{selectedTargetNamespace}}</1> to function as manual approval strategy and will be updated altogether. Install operators into separate namespaces for handling their updates independently. To allow automatic approval, all operators installed in the namespace must use automatic approval strategy.": "Installing an operator with manual approval causes all operators installed in namespace <1>{{selectedTargetNamespace}}</1> to function as manual approval strategy and will be updated altogether. Install operators into separate namespaces for handling their updates independently. To allow automatic approval, all operators installed in the namespace must use automatic approval strategy.",
"No Kubernetes APIs are provided by this Operator.": "No Kubernetes APIs are provided by this Operator.",
"View installed Operators in Namespace {{namespace}}": "View installed Operators in Namespace {{namespace}}",
"View installed Operators in all Namespaces": "View installed Operators in all Namespaces",
Expand Down
4 changes: 4 additions & 0 deletions frontend/packages/operator-lifecycle-manager/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,10 @@ export const mockProviderStrings = [
export const operatorHubDetailsProps = {
item: operatorHubTileViewPageProps.items[0],
closeOverlay: null,
channel: 'foo',
version: '1.0.0-Beta',
setUpdateChannel: () => {},
setUpdateVersion: () => {},
};

export const itemWithLongDescription = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import * as React from 'react';
import { Select, SelectOption } from '@patternfly/react-core';
import { useTranslation } from 'react-i18next';
import { setQueryArgument } from '@console/internal/components/utils';
import { alphanumericCompare } from '@console/shared';
import { PackageManifestKind } from '../../types';

export const OperatorChannelSelect: React.FC<OperatorChannelSelectProps> = ({
packageManifest,
selectedUpdateChannel,
setUpdateChannel,
setUpdateVersion,
}) => {
const { t } = useTranslation();
const { channels = [] } = packageManifest.status;
const [isChannelSelectOpen, setIsChannelSelectOpen] = React.useState(false);
const onToggleChannel = () => setIsChannelSelectOpen(!isChannelSelectOpen);

channels.sort((a, b) => -alphanumericCompare(a.name, b.name));

const channelSelectOptions = channels.map((ch) => (
<SelectOption key={ch.name} id={ch.name} value={ch.name}>
{ch.name}
</SelectOption>
));

React.useEffect(() => {
setQueryArgument('channel', selectedUpdateChannel);
}, [selectedUpdateChannel]);

const handleChannelSelection = (ch, newSelected: string) => {
setUpdateChannel(newSelected);
setIsChannelSelectOpen(false);
setUpdateVersion('');
};

return (
<>
<Select
className="co-operator-channel__select"
aria-label={t('olm~Select a channel')}
onToggle={onToggleChannel}
isOpen={isChannelSelectOpen}
selections={selectedUpdateChannel}
onSelect={handleChannelSelection}
>
{channelSelectOptions}
</Select>
</>
);
};

type OperatorChannelSelectProps = {
packageManifest: PackageManifestKind;
selectedUpdateChannel: string;
setUpdateChannel: (updateChannel: string) => void;
setUpdateVersion: (updateVersion: string) => void;
};

export const OperatorVersionSelect: React.FC<OperatorVersionSelectProps> = ({
packageManifest,
selectedUpdateChannel,
updateVersion,
setUpdateVersion,
}) => {
const { t } = useTranslation();
const [isVersionSelectOpen, setIsVersionSelectOpen] = React.useState(false);
const [defaultVersionForChannel, setDefaultVersionForChannel] = React.useState('');
const { channels = [] } = packageManifest.status;

React.useEffect(() => {
setDefaultVersionForChannel(
channels.find((ch) => ch.name === selectedUpdateChannel).currentCSVDesc.version,
);
}, [channels, selectedUpdateChannel]);

const onToggleVersion = () => setIsVersionSelectOpen(!isVersionSelectOpen);

const selectedUpdateVersion = updateVersion || defaultVersionForChannel;

// Return all versions associated with selectedUpdateChannel
const selectedChannelVersions = channels.find((ch) => ch.name === selectedUpdateChannel).entries;

const handleVersionSelection = (versions, newSelection) => {
setUpdateVersion(newSelection);
setIsVersionSelectOpen(false);
};
const versionSelectOptions = selectedChannelVersions.map((v) => (
<SelectOption key={v.version} id={v.version} value={v.version}>
{v.version}
</SelectOption>
));

React.useEffect(() => {
setQueryArgument('version', selectedUpdateVersion);
}, [selectedUpdateVersion]);

return (
<>
<Select
className="co-operator-version__select"
aria-label={t('olm~Select a version')}
onToggle={onToggleVersion}
isOpen={isVersionSelectOpen}
selections={selectedUpdateVersion}
onSelect={handleVersionSelection}
>
{versionSelectOptions}
</Select>
</>
);
};

type OperatorVersionSelectProps = {
packageManifest: PackageManifestKind;
selectedUpdateChannel: string;
updateVersion: string;
setUpdateVersion: (updateVersion: string) => void;
};
Loading

0 comments on commit 8217b1f

Please sign in to comment.