Skip to content

Commit

Permalink
Merge pull request #3887 from benjaminapetersen/JIRA/console-2004/olm…
Browse files Browse the repository at this point in the history
…/filter-by-architecture

Bug 1796078: Filter OLM operators by architecture
  • Loading branch information
openshift-merge-robot committed Mar 4, 2020
2 parents e64970f + e9adf08 commit de3233c
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 5 deletions.
7 changes: 7 additions & 0 deletions cmd/bridge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/x509"
"flag"
"fmt"
"runtime"

"io/ioutil"
"net/http"
Expand Down Expand Up @@ -192,6 +193,12 @@ func main() {
LoadTestFactor: *fLoadTestFactor,
}

// if !in-cluster (dev) we should not pass these values to the frontend
if *fK8sMode == "in-cluster" {
srv.GOARCH = runtime.GOARCH
srv.GOOS = runtime.GOOS
}

if (*fKubectlClientID == "") != (*fKubectlClientSecret == "" && *fKubectlClientSecretFile == "") {
fmt.Fprintln(os.Stderr, "Must provide both --kubectl-client-id and --kubectl-client-secret or --kubectrl-client-secret-file")
os.Exit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import * as _ from 'lodash';
import LazyLoad from 'react-lazyload';
import { CatalogItemHeader, CatalogTile } from '@patternfly/react-catalog-view-extension';
import * as classNames from 'classnames';
import { Button, Modal } from '@patternfly/react-core';
import { ExternalLinkAltIcon } from '@patternfly/react-icons';
import { ExternalLink } from '@console/internal/components/utils';

import {
Button,
EmptyState,
EmptyStateBody,
EmptyStateVariant,
Modal,
Title,
} from '@patternfly/react-core';
import {
COMMUNITY_PROVIDERS_WARNING_LOCAL_STORAGE_KEY,
GreenCheckCircleIcon,
Expand All @@ -20,6 +26,54 @@ import { OperatorHubItemDetails } from './operator-hub-item-details';
import { communityOperatorWarningModal } from './operator-hub-community-provider-modal';
import { OperatorHubItem, InstalledState, ProviderType, CapabilityLevel } from './index';

const osBaseLabel = 'operatorframework.io/os.';
const targetGOOSLabel = window.SERVER_FLAGS.GOOS ? `${osBaseLabel}${window.SERVER_FLAGS.GOOS}` : '';
const archBaseLabel = 'operatorframework.io/arch.';
const targetGOARCHLabel = window.SERVER_FLAGS.GOARCH
? `${archBaseLabel}${window.SERVER_FLAGS.GOARCH}`
: '';
// if no label present, these are the assumed defaults
const archDefaultAMD64Label = 'operatorframework.io/arch.amd64';
const osDefaultLinuxLabel = 'operatorframework.io/os.linux';
const filterByArchAndOS = (items: OperatorHubItem[]): OperatorHubItem[] => {
if (!window.SERVER_FLAGS.GOARCH || !window.SERVER_FLAGS.GOOS) {
return items;
}
return items.filter((item: OperatorHubItem) => {
// - if the operator has no flags, treat it with the defaults
// - if it has any flags, it must list all flags (no defaults applied)
const relevantLabels = _.reduce(
item?.obj?.metadata?.labels,
(result, value: string, label: string): { arch: string[]; os: string[] } => {
if (label.includes(archBaseLabel) && value === 'supported') {
result.arch.push(label);
}
if (label.includes(osBaseLabel) && value === 'supported') {
result.os.push(label);
}
return result;
},
{
arch: [],
os: [],
},
);

if (_.isEmpty(relevantLabels.os)) {
relevantLabels.os.push(osDefaultLinuxLabel);
}

if (_.isEmpty(relevantLabels.os)) {
relevantLabels.arch.push(archDefaultAMD64Label);
}

return (
_.includes(relevantLabels.os, targetGOOSLabel) &&
_.includes(relevantLabels.arch, targetGOARCHLabel)
);
});
};

const badge = (text: string) => (
<span key="1" className="pf-c-badge pf-m-read">
{text}
Expand Down Expand Up @@ -233,12 +287,14 @@ export const OperatorHubTileView: React.FC<OperatorHubTileViewProps> = (props) =
const [detailsItem, setDetailsItem] = React.useState(null);
const [showDetails, setShowDetails] = React.useState(false);

const filteredItems = filterByArchAndOS(props.items);

React.useEffect(() => {
const detailsItemID = new URLSearchParams(window.location.search).get('details-item');
const currentItem = _.find(props.items, { uid: detailsItemID });
const currentItem = _.find(filteredItems, { uid: detailsItemID });
setDetailsItem(currentItem);
setShowDetails(!_.isNil(currentItem));
}, [props.items]);
}, [filteredItems]);

const showCommunityOperator = (item: OperatorHubItem) => (ignoreWarning = false) => {
const params = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -332,10 +388,28 @@ export const OperatorHubTileView: React.FC<OperatorHubTileViewProps> = (props) =
detailsItem &&
`/k8s/ns/${detailsItem.subscription.metadata.namespace}/${SubscriptionModel.plural}/${detailsItem.subscription.metadata.name}?showDelete=true`;

if (_.isEmpty(filteredItems)) {
return (
<>
<EmptyState variant={EmptyStateVariant.full} className="co-status-card__alerts-msg">
<Title headingLevel="h5" size="lg">
No operators available
</Title>
{window.SERVER_FLAGS.GOOS && window.SERVER_FLAGS.GOARCH && (
<EmptyStateBody>
There are no operators that match operating system {window.SERVER_FLAGS.GOOS} and
architecture {window.SERVER_FLAGS.GOARCH}.
</EmptyStateBody>
)}
</EmptyState>
</>
);
}

return (
<>
<TileViewPage
items={props.items}
items={filteredItems}
itemsSorter={(itemsToSort) => _.sortBy(itemsToSort, ({ name }) => name.toLowerCase())}
getAvailableCategories={determineCategories}
getAvailableFilters={determineAvailableFilters}
Expand Down
2 changes: 2 additions & 0 deletions frontend/public/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ declare interface Window {
prometheusTenancyBaseURL: string;
requestTokenURL: string;
statuspageID: string;
GOARCH: string;
GOOS: string;
};
windowError?: boolean;
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: Function;
Expand Down
6 changes: 6 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type jsGlobals struct {
StatuspageID string `json:"statuspageID"`
DocumentationBaseURL string `json:"documentationBaseURL"`
LoadTestFactor int `json:"loadTestFactor"`
GOARCH string `json:"GOARCH"`
GOOS string `json:"GOOS"`
}

type Server struct {
Expand Down Expand Up @@ -94,6 +96,8 @@ type Server struct {
// A lister for resource listing of a particular kind
MonitoringDashboardConfigMapLister *ResourceLister
HelmChartRepoProxyConfig *proxy.Config
GOARCH string
GOOS string
}

func (s *Server) authDisabled() bool {
Expand Down Expand Up @@ -351,6 +355,8 @@ func (s *Server) indexHandler(w http.ResponseWriter, r *http.Request) {
StatuspageID: s.StatuspageID,
DocumentationBaseURL: s.DocumentationBaseURL.String(),
LoadTestFactor: s.LoadTestFactor,
GOARCH: s.GOARCH,
GOOS: s.GOOS,
}

if !s.authDisabled() {
Expand Down

0 comments on commit de3233c

Please sign in to comment.