Skip to content

Commit

Permalink
Merge pull request #6550 from debsmita1/revert-helm-filtering
Browse files Browse the repository at this point in the history
Bug 1876741: undo filtering of incompatible helm charts
  • Loading branch information
openshift-merge-robot committed Sep 10, 2020
2 parents f09fd48 + 015a69f commit 84e7fc1
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 120 deletions.
1 change: 0 additions & 1 deletion frontend/__mocks__/catalogItemsMocks.ts
@@ -1,6 +1,5 @@
export const catalogListPageProps = {
namespace: 'default',
kubernetesVersion: 'v1.18.0+ui896hui',
helmCharts: {
data: [
{
Expand Down
Expand Up @@ -138,15 +138,13 @@ export const mockHelmChartData: HelmChartMetaData[] = [
version: '1.0.3',
},
{
appVersion: '3.12',
apiVersion: 'v1',
description: 'abc',
name: 'hazelcast-enterprise',
urls: [
'https://raw.githubusercontent.com/IBM/charts/master/repo/community/hazelcast-enterprise-1.0.2.tgz',
],
version: '1.0.2',
kubeVersion: '>=1.10.0',
},
{
appVersion: '3.10.5',
Expand All @@ -157,27 +155,6 @@ export const mockHelmChartData: HelmChartMetaData[] = [
'https://raw.githubusercontent.com/IBM/charts/master/repo/community/hazelcast-enterprise-1.0.1.tgz',
],
version: '1.0.1',
kubeVersion: '>=1.11.0',
},
];

export const mockHelmChartData2: HelmChartMetaData[] = [
{
appVersion: '3.12',
apiVersion: 'v1',
name: 'hazelcast-enterprise',
urls: [
'https://raw.githubusercontent.com/IBM/charts/master/repo/community/hazelcast-enterprise-1.0.3.tgz',
],
version: '1.0.3',
},
{
apiVersion: 'v1',
name: 'hazelcast-enterprise',
urls: [
'https://raw.githubusercontent.com/IBM/charts/master/repo/community/hazelcast-enterprise-1.0.2.tgz',
],
version: '1.0.2',
},
];

Expand Down
@@ -1,4 +1,3 @@
import * as _ from 'lodash';
import {
OtherReleaseStatuses,
releaseStatusReducer,
Expand All @@ -13,7 +12,6 @@ import { HelmReleaseStatus } from '../helm-types';
import {
mockHelmReleases,
mockHelmChartData,
mockHelmChartData2,
mockReleaseResources,
flattenedMockReleaseResources,
} from './helm-release-mock-data';
Expand Down Expand Up @@ -58,17 +56,9 @@ describe('Helm Releases Utils', () => {
});

it('should return the chart versions, concatenated with the App Version, available for the helm chart', () => {
const chartVersions = getChartVersions(mockHelmChartData, 'v1.18.2+ui678hjj');
const chartVersions = getChartVersions(mockHelmChartData);
expect(chartVersions).toEqual({
'1.0.1': '1.0.1 / App Version 3.10.5',
'1.0.2': '1.0.2 / App Version 3.12',
'1.0.3': '1.0.3 / App Version 3.12',
});
});

it('should concatenate App Version with the Chart Version only when it is available', () => {
const chartVersions = getChartVersions(mockHelmChartData2, 'v1.18.2');
expect(chartVersions).toEqual({
'1.0.2': '1.0.2',
'1.0.3': '1.0.3 / App Version 3.12',
});
Expand All @@ -78,48 +68,6 @@ describe('Helm Releases Utils', () => {
expect(flattenReleaseResources(mockReleaseResources)).toEqual(flattenedMockReleaseResources);
});

it('should filter the chart versions which are incompatible with the kubernetes version', () => {
let kubernetesVersion = 'v1.18.0';
mockHelmChartData[2].kubeVersion = '>=1.25.0';
let chartVersions = getChartVersions(mockHelmChartData, kubernetesVersion);
const expectedChartVersions = {
'1.0.1': '1.0.1 / App Version 3.10.5',
'1.0.2': '1.0.2 / App Version 3.12',
'1.0.3': '1.0.3 / App Version 3.12',
};
expect(chartVersions).toEqual(_.omit(expectedChartVersions, '1.0.1'));

kubernetesVersion = '-';
chartVersions = getChartVersions(mockHelmChartData, kubernetesVersion);
expect(chartVersions).toEqual(expectedChartVersions);

kubernetesVersion = 'unknown';
chartVersions = getChartVersions(mockHelmChartData, kubernetesVersion);
expect(chartVersions).toEqual(expectedChartVersions);

kubernetesVersion = 'v1.18.3+e1ba7b6';
chartVersions = getChartVersions(mockHelmChartData, kubernetesVersion);
expect(chartVersions).toEqual(_.omit(expectedChartVersions, '1.0.1'));

kubernetesVersion = 'v1.20.3-alpha.1';
mockHelmChartData[2].kubeVersion = '>=1.20.3-0';
chartVersions = getChartVersions(mockHelmChartData, kubernetesVersion);
expect(chartVersions).toEqual(_.omit(expectedChartVersions, '1.0.2'));

kubernetesVersion = 'v1.20.3-alpha.1';
mockHelmChartData[2].kubeVersion = '>=1.19.3-0';
chartVersions = getChartVersions(mockHelmChartData, kubernetesVersion);
expect(chartVersions).toEqual({
'1.0.3': '1.0.3 / App Version 3.12',
});

kubernetesVersion = 'v1.18.3+8uinj';
mockHelmChartData[0].kubeVersion = '>1.14.1';
mockHelmChartData[2].kubeVersion = '>= 1.13.0 < 1.14.0 || >= 1.14.1 < 1.15.0';
chartVersions = getChartVersions(mockHelmChartData, kubernetesVersion);
expect(chartVersions).toEqual(_.omit(expectedChartVersions, '1.0.1'));
});

it('should return the readme for the chart provided', () => {
expect(getChartReadme(mockHelmReleases[0].chart)).toEqual('example readme content');
});
Expand Down
Expand Up @@ -7,8 +7,6 @@ import { InfoCircleIcon } from '@patternfly/react-icons';
import { coFetchJSON, coFetch } from '@console/internal/co-fetch';
import { DropdownField } from '@console/shared';
import { confirmModal } from '@console/internal/components/modals/confirm-modal';
import { k8sVersion } from '@console/internal/module/status';
import { getK8sGitVersion } from '@console/internal/module/k8s';
import { EditorType } from '@console/shared/src/components/synced-editor/editor-toggle';
import { HelmChartMetaData, HelmChart, HelmActionType, HelmChartEntries } from '../helm-types';
import {
Expand Down Expand Up @@ -40,7 +38,6 @@ const HelmChartVersionDropdown: React.FunctionComponent<HelmChartVersionDropdown
} = useFormikContext<FormikValues>();
const [helmChartVersions, setHelmChartVersions] = React.useState({});
const [helmChartEntries, setHelmChartEntries] = React.useState<HelmChartMetaData[]>([]);
const [kubernetesVersion, setKubernetesVersion] = React.useState<string>();
const [initialYamlData, setInitialYamlData] = React.useState<string>('');
const [initialFormData, setInitialFormData] = React.useState<object>();

Expand Down Expand Up @@ -77,12 +74,6 @@ const HelmChartVersionDropdown: React.FunctionComponent<HelmChartVersionDropdown
});
};

React.useEffect(() => {
k8sVersion()
.then((response) => setKubernetesVersion(getK8sGitVersion(response) || '-'))
.catch(() => setKubernetesVersion('unknown'));
}, []);

React.useEffect(() => {
setInitialYamlData(yamlData);
setInitialFormData(formData);
Expand All @@ -104,13 +95,13 @@ const HelmChartVersionDropdown: React.FunctionComponent<HelmChartVersionDropdown
}
if (ignore) return;
setHelmChartEntries(json?.entries?.[chartName]);
setHelmChartVersions(getChartVersions(json?.entries?.[chartName], kubernetesVersion));
setHelmChartVersions(getChartVersions(json?.entries?.[chartName]));
};
fetchChartVersions();
return () => {
ignore = true;
};
}, [chartName, kubernetesVersion]);
}, [chartName]);

const onChartVersionChange = (value: string) => {
const chartURL = getChartURL(helmChartEntries, value);
Expand Down
10 changes: 1 addition & 9 deletions frontend/packages/dev-console/src/components/helm/helm-utils.ts
@@ -1,7 +1,6 @@
import * as fuzzy from 'fuzzysearch';
import * as _ from 'lodash';
import { safeDump } from 'js-yaml';
import * as semver from 'semver';
import { coFetchJSON } from '@console/internal/co-fetch';
import { K8sResourceKind } from '@console/internal/module/k8s';
import {
Expand Down Expand Up @@ -87,17 +86,10 @@ export const concatVersions = (chartVersion: string, appVersion: string): string
return appVersion ? `${chartVersion} / App Version ${appVersion}` : chartVersion;
};

export const getChartVersions = (chartEntries: HelmChartMetaData[], kubernetesVersion: string) => {
export const getChartVersions = (chartEntries: HelmChartMetaData[]) => {
const chartVersions = _.reduce(
chartEntries,
(obj, chart) => {
if (
chart?.kubeVersion &&
semver.valid(kubernetesVersion) &&
!semver.satisfies(kubernetesVersion, chart?.kubeVersion)
) {
return obj;
}
obj[chart.version] = concatVersions(chart.version, chart.appVersion);
return obj;
},
Expand Down
25 changes: 2 additions & 23 deletions frontend/public/components/catalog/catalog-page.tsx
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react';
import * as _ from 'lodash-es';
import { Helmet } from 'react-helmet';
import { safeLoad } from 'js-yaml';
import * as semver from 'semver';
import { PropertyItem } from '@patternfly/react-catalog-view-extension';
import { ANNOTATIONS, FLAGS, APIError } from '@console/shared';
import {
Expand All @@ -22,8 +21,6 @@ import {
PartialObjectMetadata,
TemplateKind,
} from '../../module/k8s';
import { k8sVersion } from '../../module/status';
import { getK8sGitVersion } from '../../module/k8s/cluster-settings';
import { withStartGuide } from '../start-guide';
import { connectToFlags, flagPending, FlagsObject } from '../../reducers/features';
import {
Expand Down Expand Up @@ -67,7 +64,6 @@ export const CatalogListPage = withExtensions<CatalogListPageExtensionProps>({
helmCharts,
namespace,
loaded,
kubernetesVersion,
} = this.props;
if (
(!prevProps.loaded && loaded) ||
Expand All @@ -76,8 +72,7 @@ export const CatalogListPage = withExtensions<CatalogListPageExtensionProps>({
!_.isEqual(templateMetadata, prevProps.templateMetadata) ||
!_.isEqual(projectTemplateMetadata, prevProps.projectTemplateMetadata) ||
!_.isEqual(imageStreams, prevProps.imageStreams) ||
!_.isEqual(helmCharts, prevProps.helmCharts) ||
!_.isEqual(kubernetesVersion, prevProps.kubernetesVersion)
!_.isEqual(helmCharts, prevProps.helmCharts)
) {
const items = this.getItems();
this.setState({ items });
Expand Down Expand Up @@ -216,20 +211,13 @@ export const CatalogListPage = withExtensions<CatalogListPageExtensionProps>({
}

normalizeHelmCharts(chartEntries: HelmChartEntries): Item[] {
const { namespace: currentNamespace = '', kubernetesVersion } = this.props;
const { namespace: currentNamespace = '' } = this.props;
const notAvailable = <span className="properties-side-panel-pf-property-label">N/A</span>;

return _.reduce(
chartEntries,
(normalizedCharts, charts) => {
charts.forEach((chart: HelmChart) => {
if (
chart?.kubeVersion &&
semver.valid(kubernetesVersion) &&
!semver.satisfies(kubernetesVersion, chart?.kubeVersion)
) {
return;
}
const tags = chart.keywords;
const chartName = chart.name;
const chartVersion = chart.version;
Expand Down Expand Up @@ -403,7 +391,6 @@ export const Catalog = connectToFlags<CatalogProps>(
);
const [projectTemplateError, setProjectTemplateError] = React.useState<APIError>();
const [helmCharts, setHelmCharts] = React.useState<HelmChartEntries>();
const [kubernetesVersion, setKubernetesVersion] = React.useState<string>();

const loadTemplates = openshiftFlag && !mock;

Expand Down Expand Up @@ -449,12 +436,6 @@ export const Catalog = connectToFlags<CatalogProps>(
});
}, []);

React.useEffect(() => {
k8sVersion()
.then((response) => setKubernetesVersion(getK8sGitVersion(response) || '-'))
.catch(() => setKubernetesVersion('unknown'));
}, []);

const error = templateError || projectTemplateError;
if (error) {
return (
Expand Down Expand Up @@ -502,7 +483,6 @@ export const Catalog = connectToFlags<CatalogProps>(
templateMetadata={templateMetadata}
projectTemplateMetadata={projectTemplateMetadata}
helmCharts={helmCharts}
kubernetesVersion={kubernetesVersion}
{...(props as any)}
/>
</Firehose>
Expand Down Expand Up @@ -551,7 +531,6 @@ export type CatalogListPageProps = CatalogListPageExtensionProps & {
loaded: boolean;
loadError?: string;
namespace?: string;
kubernetesVersion?: string;
};

export type CatalogListPageState = {
Expand Down

0 comments on commit 84e7fc1

Please sign in to comment.