Skip to content

Commit

Permalink
Merge pull request #111 from jasonmadigan/policy-topology-fixes
Browse files Browse the repository at this point in the history
Policy topology fixes, centralise CRD versioning refs
  • Loading branch information
openshift-merge-bot[bot] authored Oct 17, 2024
2 parents 8c398cd + 66cfa3b commit 5bc574d
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 68 deletions.
88 changes: 66 additions & 22 deletions console-extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@
"component": { "$codeRef": "KuadrantPoliciesPage" }
}
},
{
"type": "console.page/route",
"properties": {
"exact": true,
"path": "/kuadrant/policy-topology",
"component": { "$codeRef": "PolicyTopologyPage" }
}
},
{
"type": "console.page/route",
"properties": {
"exact": true,
"path": "/k8s/ns/:ns/tlspolicy/name/:name/edit",
"component": { "$codeRef": "KuadrantTLSCreatePage" }
}
},
{
"type": "console.page/route",
"properties": {
"exact": true,
"path": "/k8s/ns/:ns/dnspolicy/name/:name/edit",
"component": { "$codeRef": "KuadrantDNSPolicyCreatePage" }
}
},
{
"type": "console.resource/create",
"properties": {
Expand All @@ -32,6 +56,17 @@
"component": { "$codeRef": "KuadrantDNSPolicyCreatePage" }
}
},
{
"type": "console.resource/create",
"properties": {
"model": {
"group": "kuadrant.io",
"version": "v1",
"kind": "DNSPolicy"
},
"component": { "$codeRef": "KuadrantDNSPolicyCreatePage" }
}
},
{
"type": "console.resource/create",
"properties": {
Expand All @@ -44,11 +79,14 @@
}
},
{
"type": "console.page/route",
"type": "console.resource/create",
"properties": {
"exact": true,
"path": "/kuadrant/policy-topology",
"component": { "$codeRef": "PolicyTopologyPage" }
"model": {
"group": "kuadrant.io",
"version": "v1",
"kind": "RateLimitPolicy"
},
"component": { "$codeRef": "KuadrantRateLimitPolicyCreatePage" }
}
},
{
Expand All @@ -63,19 +101,36 @@
}
},
{
"type": "console.page/route",
"type": "console.resource/create",
"properties": {
"exact": true,
"path": "/k8s/ns/:ns/tlspolicy/name/:name/edit",
"model": {
"group": "kuadrant.io",
"version": "v1",
"kind": "TLSPolicy"
},
"component": { "$codeRef": "KuadrantTLSCreatePage" }
}
},
{
"type": "console.page/route",
"type": "console.resource/create",
"properties": {
"exact": true,
"path": "/k8s/ns/:ns/dnspolicy/name/:name/edit",
"component": { "$codeRef": "KuadrantDNSPolicyCreatePage" }
"model": {
"group": "kuadrant.io",
"version": "v1beta2",
"kind": "AuthPolicy"
},
"component": { "$codeRef": "KuadrantAuthPolicyCreatePage" }
}
},
{
"type": "console.resource/create",
"properties": {
"model": {
"group": "kuadrant.io",
"version": "v1",
"kind": "AuthPolicy"
},
"component": { "$codeRef": "KuadrantAuthPolicyCreatePage" }
}
},
{
Expand Down Expand Up @@ -155,16 +210,5 @@
"section": "kuadrant-section-dev",
"badge": "dev"
}
},
{
"type": "console.resource/create",
"properties": {
"model": {
"group": "kuadrant.io",
"version": "v1beta2",
"kind": "AuthPolicy"
},
"component": { "$codeRef": "KuadrantAuthPolicyCreatePage" }
}
}
]
2 changes: 1 addition & 1 deletion install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ spec:
type: ClusterIP
sessionAffinity: None
---
apiVersion: console.openshift.io/v1alpha1
apiVersion: console.openshift.io/v1
kind: ConsolePlugin
metadata:
name: kuadrant-console-plugin
Expand Down
5 changes: 3 additions & 2 deletions src/components/KuadrantAuthPolicyCreatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import Helmet from 'react-helmet';
import { Button, Modal, ModalBox, ModalBoxHeader, ModalBoxBody, ModalBoxFooter, ButtonVariant } from '@patternfly/react-core';
import { useTranslation } from 'react-i18next';
import { ResourceYAMLEditor, useActiveNamespace } from '@openshift-console/dynamic-plugin-sdk';
import resourceGVKMapping from '../utils/latest';

const KuadrantAuthPolicyCreatePage: React.FC = () => {
const { t } = useTranslation('plugin__kuadrant-console-plugin');
const [selectedNamespace] = useActiveNamespace();

const yamlResource = {
apiVersion: 'kuadrant.io/v1beta2',
kind: 'AuthPolicy',
apiVersion: resourceGVKMapping['AuthPolicy'].group + '/' + resourceGVKMapping['AuthPolicy'].version,
kind: resourceGVKMapping['AuthPolicy'].kind,
metadata: {
name: 'example-authpolicy',
namespace: selectedNamespace,
Expand Down
12 changes: 8 additions & 4 deletions src/components/KuadrantDNSPolicyCreatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import GatewaySelect from './gateway/GatewaySelect';
import yaml from 'js-yaml';
import KuadrantCreateUpdate from './KuadrantCreateUpdate'
import { handleCancel } from '../utils/cancel';
import resourceGVKMapping from '../utils/latest';


const KuadrantDNSPolicyCreatePage: React.FC = () => {
Expand All @@ -51,8 +52,8 @@ const KuadrantDNSPolicyCreatePage: React.FC = () => {
const createDNSPolicy = () => {
const hasHealthCheck = healthCheck.endpoint || healthCheck.failureThreshold || healthCheck.port || healthCheck.protocol;
return {
apiVersion: 'kuadrant.io/v1alpha1',
kind: 'DNSPolicy',
apiVersion: resourceGVKMapping['DNSPolicy'].group + '/' + resourceGVKMapping['DNSPolicy'].version,
kind: resourceGVKMapping['DNSPolicy'].kind,
metadata: {
name: policyName,
namespace: selectedNamespace,
Expand Down Expand Up @@ -86,8 +87,11 @@ const KuadrantDNSPolicyCreatePage: React.FC = () => {

const [yamlInput, setYamlInput] = React.useState(createDNSPolicy)
const dnsPolicy = createDNSPolicy();
const dnsPolicyGVK = getGroupVersionKindForResource({ apiVersion: 'kuadrant.io/v1alpha1', kind: 'DNSPolicy' });
const [dnsPolicyModel] = useK8sModel({ group: dnsPolicyGVK.group, version: dnsPolicyGVK.version, kind: dnsPolicyGVK.kind });
const dnsPolicyGVK = getGroupVersionKindForResource({
apiVersion: `${resourceGVKMapping['DNSPolicy'].group}/${resourceGVKMapping['DNSPolicy'].version}`,
kind: resourceGVKMapping['DNSPolicy'].kind,
});
const [dnsPolicyModel] = useK8sModel({ group: dnsPolicyGVK.group, version: dnsPolicyGVK.version, kind: dnsPolicyGVK.kind });

const history = useHistory();

Expand Down
13 changes: 7 additions & 6 deletions src/components/KuadrantOverviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import './kuadrant.css';
import ResourceList from './ResourceList';
import { sortable } from '@patternfly/react-table';
import { INTERNAL_LINKS, EXTERNAL_LINKS } from '../constants/links';
import resourceGVKMapping from '../utils/latest';

const KuadrantOverviewPage: React.FC = () => {
const { t } = useTranslation('plugin__kuadrant-console-plugin');
Expand Down Expand Up @@ -226,10 +227,10 @@ const KuadrantOverviewPage: React.FC = () => {
<CardBody className="pf-u-p-0">
<ResourceList
resources={[
{ group: 'kuadrant.io', version: 'v1beta2', kind: 'AuthPolicy' },
{ group: 'kuadrant.io', version: 'v1alpha1', kind: 'DNSPolicy' },
{ group: 'kuadrant.io', version: 'v1beta2', kind: 'RateLimitPolicy' },
{ group: 'kuadrant.io', version: 'v1alpha1', kind: 'TLSPolicy' }
resourceGVKMapping['AuthPolicy'],
resourceGVKMapping['DNSPolicy'],
resourceGVKMapping['RateLimitPolicy'],
resourceGVKMapping['TLSPolicy']
]}
columns={columns}
namespace='#ALL_NS#'
Expand All @@ -247,7 +248,7 @@ const KuadrantOverviewPage: React.FC = () => {
<CardBody className="pf-u-p-0">
<ResourceList
resources={[
{ group: 'gateway.networking.k8s.io', version: 'v1', kind: 'Gateway' },
resourceGVKMapping['Gateway']
]}
columns={columns}
namespace='#ALL_NS#'
Expand All @@ -261,7 +262,7 @@ const KuadrantOverviewPage: React.FC = () => {
<CardBody className="pf-u-p-0">
<ResourceList
resources={[
{ group: 'gateway.networking.k8s.io', version: 'v1', kind: 'HTTPRoute' },
resourceGVKMapping['HTTPRoute']
]}
columns={columns}
namespace='#ALL_NS#'
Expand Down
9 changes: 5 additions & 4 deletions src/components/KuadrantPoliciesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Title } from '@patternfly/react-core';
import { Alert, AlertGroup } from '@patternfly/react-core';
import ResourceList from './ResourceList';
import './kuadrant.css';
import resourceGVKMapping from '../utils/latest';

interface Resource {
name: string;
Expand All @@ -28,10 +29,10 @@ interface Resource {
}

export const resources: Resource[] = [
{ name: 'AuthPolicies', gvk: { group: 'kuadrant.io', version: 'v1beta2', kind: 'AuthPolicy' } },
{ name: 'DNSPolicies', gvk: { group: 'kuadrant.io', version: 'v1alpha1', kind: 'DNSPolicy' } },
{ name: 'RateLimitPolicies', gvk: { group: 'kuadrant.io', version: 'v1beta2', kind: 'RateLimitPolicy' } },
{ name: 'TLSPolicies', gvk: { group: 'kuadrant.io', version: 'v1alpha1', kind: 'TLSPolicy' } },
{ name: 'AuthPolicies', gvk: resourceGVKMapping['AuthPolicy'] },
{ name: 'DNSPolicies', gvk: resourceGVKMapping['DNSPolicy'] },
{ name: 'RateLimitPolicies', gvk: resourceGVKMapping['RateLimitPolicy'] },
{ name: 'TLSPolicies', gvk: resourceGVKMapping['TLSPolicy'] },
];

export const AllPoliciesListPage: React.FC<{
Expand Down
5 changes: 3 additions & 2 deletions src/components/KuadrantRateLimitPolicyCreatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { useTranslation } from 'react-i18next';
import './kuadrant.css';
import { ResourceYAMLEditor, useActiveNamespace } from '@openshift-console/dynamic-plugin-sdk';
import resourceGVKMapping from '../utils/latest';

const KuadrantRateLimitPolicyCreatePage: React.FC = () => {
const { t } = useTranslation('plugin__kuadrant-console-plugin');
Expand All @@ -17,8 +18,8 @@ const KuadrantRateLimitPolicyCreatePage: React.FC = () => {
const [errorModalMsg] = React.useState('');

const rateLimitPolicy = {
apiVersion: 'kuadrant.io/v1beta2',
kind: 'RateLimitPolicy',
apiVersion: resourceGVKMapping['RateLimitPolicy'].group + '/' + resourceGVKMapping['RateLimitPolicy'].version,
kind: resourceGVKMapping['RateLimitPolicy'].kind,
metadata: {
name: 'example-ratelimitpolicy',
namespace: selectedNamespace,
Expand Down
10 changes: 7 additions & 3 deletions src/components/KuadrantTLSCreatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { Gateway } from './gateway/types';
import GatewaySelect from './gateway/GatewaySelect';
import KuadrantCreateUpdate from './KuadrantCreateUpdate'
import { K8sResourceCommon } from '@openshift-console/dynamic-plugin-sdk';
import resourceGVKMapping from '../utils/latest';


const KuadrantTLSCreatePage: React.FC = () => {
Expand All @@ -59,8 +60,8 @@ const KuadrantTLSCreatePage: React.FC = () => {

// Creates TLS policy object to be used for form and yaml creation of the resource
const createTlsPolicy = () => ({
apiVersion: 'kuadrant.io/v1alpha1',
kind: 'TLSPolicy',
apiVersion: resourceGVKMapping['TLSPolicy'].group + '/' + resourceGVKMapping['TLSPolicy'].version,
kind: resourceGVKMapping['TLSPolicy'].kind,
metadata: {
name: policyName,
namespace: selectedNamespace,
Expand All @@ -87,7 +88,10 @@ const KuadrantTLSCreatePage: React.FC = () => {
})

const tlsPolicy = createTlsPolicy();
const tlsPolicyGVK = getGroupVersionKindForResource({ apiVersion: 'kuadrant.io/v1alpha1', kind: 'TLSPolicy' });
const tlsPolicyGVK = getGroupVersionKindForResource({
apiVersion: `${resourceGVKMapping['TLSPolicy'].group}/${resourceGVKMapping['TLSPolicy'].version}`,
kind: resourceGVKMapping['TLSPolicy'].kind,
});
const [tlsPolicyModel] = useK8sModel({ group: tlsPolicyGVK.group, version: tlsPolicyGVK.version, kind: tlsPolicyGVK.kind });

// K8sResourceCommon by default does not contain spec etc which is needed for updating resource forms
Expand Down
Loading

0 comments on commit 5bc574d

Please sign in to comment.