Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network policy forms: hide unavailable features for admin users #9628

Merged
merged 14 commits into from
Sep 29, 2021
Merged

Network policy forms: hide unavailable features for admin users #9628

merged 14 commits into from
Sep 29, 2021

Conversation

mariomac
Copy link
Contributor

Related JIRA issue: https://issues.redhat.com/browse/NETOBSERV-27

For a user with sufficient permissions (e.g. admin) using ovn-k8s network type,
all network policy features are available and no special information is
displayed about it.

For a user with sufficient permissions (e.g. admin) using openshift-sdn network
type, egress section and IP block exceptions are hidden, and no special
information is displayed about it.

For a user with insufficient permissions to get the network type, all network
policy features are visible but an informative message is displayed about
potential unavailable features.

@openshift-ci openshift-ci bot requested review from jcaianirh and spadgett July 26, 2021 13:24
@openshift-ci openshift-ci bot added the component/core Related to console core functionality label Jul 26, 2021
label: 'Network',
labelPlural: 'Networks',
apiVersion: 'v1',
apiGroup: 'operator.openshift.io',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly there's also Network in "config.openshift.io" api group that can be used (it also contains CNI type info), do you know if one is more relevant than another?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found multiple ways to fetch/guess the network type, but I used this because it's the only method I saw properly documented: https://docs.openshift.com/container-platform/4.7/networking/cluster-network-operator.html#nw-operator-cr_cluster-network-operator

So I decided to use the above documentation as a source of truth. But I might have missed the config.openshift.io api group. Does it provide any benefit with respect to operatior.openshift.io?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's documented as well: https://docs.openshift.com/container-platform/4.7/rest_api/config_apis/network-config-openshift-io-v1.html
We might need to ask the SDN team to know more about the difference

*/
export const useClusterNetworkFeatures = (): [ClusterNetworkFeatures, boolean] => {
const [features, setFeatures] = React.useState<ClusterNetworkFeatures>();
const [featuresLoaded, setFeaturesLoaded] = React.useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we want to distinguish the "not yet loaded" state versus "unknown" state, or we could say it's the same thing. We could argue that features are unknown until they are loaded, and hence remove this featuresLoaded state. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid that sometimes this could cause some kind of annoying warning message that is initially shown and immediately hidden after the page is loaded.

The other way, the unsupported fields are initially hidden and immediately shown after the page is loaded. This would give a more "natural" feeling of a page being progressively loaded.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I've tried locally, it generates some blinking effect that isn't very nice indeed. Ok to keep as you did

const [network, networkLoaded] = useK8sGet<K8sResourceKind>(clusterNetworkModel, networkName);
React.useEffect(() => {
const cniType = ClusterNetworkType[network?.spec?.defaultNetwork?.type];
setFeatures(featuresDocument[cniType ? cniType : ClusterNetworkType.Unknown]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: if I'm correct, cniType ? cniType : ClusterNetworkType.Unknown can be written cniType ?? ClusterNetworkType.Unknown as well (nullish coalescing) ( I'm being a smart ass but just learned this this week :-) )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaah yeah, I actually was looking for something like that but didn't find it. As a non-native TS coder, I was looking for the "elvis operator ?:" but didn't find anything by this term. Thank you!

@openshift-ci openshift-ci bot added the kind/i18n Indicates issue or PR relates to internationalization or has content that needs to be translated label Jul 27, 2021
</li>
</ul>
<p>
{t('public~More information:')}&nbsp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add another sentence to help the user understand what he has to do with this message, something like: "Refer to your cluster administrator to know which network provider is used".

Copy link
Contributor

@jotak jotak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion on the info alert, apart from that LGTM

Copy link
Contributor

@jotak jotak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mariomac
Copy link
Contributor Author

mariomac commented Aug 2, 2021

/assign @rohitkrai03

Mario Macias added 7 commits August 6, 2021 15:32
Related JIRA issue: https://issues.redhat.com/browse/NETOBSERV-27

For a user with sufficient permissions (e.g. admin) using ovn-k network type,
all network policy feature are available and no special information is
displayed about it.

For a user with sufficient permissions (e.g. admin) using openshift-sdn network
type, egress section and IP block exceptions are hidden, and no special
information is displayed about it.

For a user with insufficient permissions to get the network type, all network
policy features are visible but an informative message is displayed about
potential unavailable features.
The following parts have been hidden for OpenShiftSDN CNI type:

- "Exceptions" label in network policy peer IP blocks.
- The whole "Egress" section in the new policy form.
Previously, we used operator.openshift.io, but we moved to config
because this way we could detect other network types (e.g. Calico).
Kept the alert title as a single-line message, and move the rest of
the message into the alert body.
@memodi
Copy link
Contributor

memodi commented Aug 12, 2021

/label qe-approved

@openshift-ci openshift-ci bot added the qe-approved Signifies that QE has signed off on this PR label Aug 12, 2021
@nathan-weinberg
Copy link

/retest

@nathan-weinberg
Copy link

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 20, 2021
@mariomac
Copy link
Contributor Author

Pinging @rohitkrai03 for a review, as indicated by the openshift-ci bot.

@rohitkrai03
Copy link
Contributor

Hi @mariomac, sorry I missed this one. I am not that aware about this area of the console. @spadgett can you take a look at this?

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 29, 2021
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 30, 2021
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 30, 2021
Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, thanks

import { useK8sGet } from '@console/internal/components/utils/k8s-get-hook';
import { NetworkPolicyForm } from '../../components/network-policies/network-policy-form';

jest.mock('react-i18next', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a global mock for this now that you should be able use: https://github.com/openshift/console/blob/master/frontend/__mocks__/react-i18next.ts

import { NetworkPolicyPeerIPBlock } from '../../components/network-policies/network-policy-peer-ipblock';

const i18nNS = 'public';
jest.mock('react-i18next', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sam comment here. You should be able to use the global mock.

const namespace = getActiveNamespace();

const namespaceProps = {
namespace: getActiveNamespace(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer useActiveNamespace hook.

return (
<div className="co-m-pane__body co-m-pane__form">
<h1 className="co-m-pane__heading co-m-pane__heading--baseline">
<div className="co-m-pane__name">{t('public~Create NetworkPolicy')}</div>
<div className="co-m-pane__heading-link">
<Link
to={`/k8s/ns/${namespace}/networkpolicies/~new`}
to={`/k8s/ns/${namespaceProps.namespace}/networkpolicies/~new`}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would build the base URL with resourcePathFromModel then append /~new. (Eventually we'll add a cluster path section, so better to use the utility.)

@@ -8,15 +8,16 @@ import './_create-network-policy.scss';

export const CreateNetworkPolicy: React.FunctionComponent<{}> = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Other parts of the console use the shorthand React.FC. Not important to change for this PR, but it would be good to stay consistent.

networkFeatures?.PolicyPeerIPBlockExceptions === undefined && (
<Alert
variant="info"
title={<p>{t('public~When using the OpenShift SDN cluster network provider:')}</p>}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the alert title gets a heading element, in which case you wouldn't want to use p. Does this change the padding for the layout?

@@ -332,3 +369,5 @@ export const NetworkPolicyForm: React.FunctionComponent<NetworkPolicyFormProps>
</Form>
);
};

export const NetworkPolicyForm = connectToFlags(FLAGS.OPENSHIFT)(NetworkPolicyFormComponent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer useFlag

apiVersion: 'v1',
apiGroup: 'config.openshift.io',
plural: 'networks',
abbr: '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to define an abbr that is used in the badge to the left of links. Even if you don't have a details page for this resource, the badge can still show up (e.g. in the search page).

@mariomac
Copy link
Contributor Author

/test e2e-gcp-console

@mariomac
Copy link
Contributor Author

/cc @spadgett

@openshift-ci openshift-ci bot requested a review from spadgett September 15, 2021 15:34
Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

👍

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 24, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 24, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jotak, mariomac, nathan-weinberg, spadgett

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 24, 2021
@nalhadef
Copy link

nalhadef commented Sep 27, 2021

/docs-approved

@sferich888
Copy link

/label px-approved

@openshift-ci openshift-ci bot added the px-approved Signifies that Product Support has signed off on this PR label Sep 28, 2021
@spadgett
Copy link
Member

/docs-approved

/label docs-approved

@openshift-ci openshift-ci bot added the docs-approved Signifies that Docs has signed off on this PR label Sep 28, 2021
@openshift-merge-robot openshift-merge-robot merged commit cdc08ea into openshift:master Sep 29, 2021
@mariomac mariomac deleted the fetch-network-type branch September 29, 2021 07:08
@spadgett spadgett added this to the v4.10 milestone Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/core Related to console core functionality docs-approved Signifies that Docs has signed off on this PR kind/i18n Indicates issue or PR relates to internationalization or has content that needs to be translated lgtm Indicates that a PR is ready to be merged. px-approved Signifies that Product Support has signed off on this PR qe-approved Signifies that QE has signed off on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants