Skip to content

Commit 6a08f95

Browse files
authored
Merge pull request #125 from headlamp-k8s/flux-suspend-resume-fix
Flux suspend,resume fix
2 parents e7f3b64 + d4d4cb3 commit 6a08f95

File tree

7 files changed

+102
-65
lines changed

7 files changed

+102
-65
lines changed

flux/src/actions/index.tsx

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,14 @@ function SuspendAction(props) {
5757
const { resource } = props;
5858
const [open, setOpen] = React.useState<boolean>(false);
5959

60+
if(resource?.jsonData?.spec?.suspend) {
61+
return null;
62+
}
6063
return (
6164
<>
6265
<ActionButton
6366
description="Suspend"
6467
icon={'mdi:pause'}
65-
iconButtonProps={{
66-
style: {
67-
display: resource?.jsonData.spec.hasOwnProperty('suspend')
68-
? resource.jsonData.spec.suspend
69-
? 'none'
70-
: 'inline-flex'
71-
: 'inline-flex',
72-
},
73-
}}
7468
onClick={() => {
7569
setOpen(true);
7670
}}
@@ -81,7 +75,6 @@ function SuspendAction(props) {
8175
handleClose={() => setOpen(false)}
8276
onConfirm={() => {
8377
setOpen(false);
84-
resource.jsonData.spec['suspend'] = true;
8578
const patch = resource.constructor.apiEndpoint.patch;
8679
patch(
8780
{
@@ -121,17 +114,11 @@ function SuspendAction(props) {
121114
function ResumeAction(props) {
122115
const { resource } = props;
123116
const { enqueueSnackbar } = useSnackbar();
117+
if(!resource.jsonData.spec.suspend) {
118+
return null;
119+
}
124120
return (
125121
<ActionButton
126-
iconButtonProps={{
127-
style: {
128-
display: resource?.jsonData.spec.hasOwnProperty('suspend')
129-
? resource.jsonData.spec.suspend
130-
? 'inline-flex'
131-
: 'none'
132-
: 'none',
133-
},
134-
}}
135122
description="Resume"
136123
icon={'mdi:play'}
137124
onClick={() => {

flux/src/checkflux/index.tsx

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,19 @@
11
import { K8s } from '@kinvolk/headlamp-plugin/lib';
2-
import { Loader } from '@kinvolk/headlamp-plugin/lib/components/common';
32
import { Box, Link } from '@mui/material';
43
import { useTheme } from '@mui/material';
54

6-
export default function CheckIfFluxInstalled() {
5+
export default function Flux404() {
76
const theme = useTheme();
8-
const [deployments] = K8s.ResourceClasses.Deployment.useList({
9-
labelSelector: 'app.kubernetes.io/part-of=flux',
10-
});
117

12-
if (deployments === null) {
13-
return <Loader />;
14-
}
15-
if (
16-
deployments?.find(
17-
deployment =>
18-
deployment.jsonData.metadata?.labels['app.kubernetes.io/component'] === 'source-controller'
19-
)
20-
) {
21-
return null;
22-
} else {
238
// return a box with a message that flux is not installed and a link to the flux installation guide
249
return (
2510
<Box
2611
// center this box and also wrap it in a white background with some box shadow
27-
style={{
12+
sx={{
2813
padding: '1rem',
2914
alignItems: 'center',
3015
margin: '2rem auto',
31-
height: '20vh',
32-
width: '50%',
33-
backgroundColor: theme.palette.background.paper,
16+
maxWidth: '600px',
3417
}}
3518
>
3619
<h1>Flux is not installed</h1>
@@ -43,7 +26,14 @@ export default function CheckIfFluxInstalled() {
4326
</p>
4427
</Box>
4528
);
46-
}
29+
}
30+
31+
export function useFluxInstallCheck() {
32+
const [deployments] = K8s.ResourceClasses.Deployment.useList({
33+
labelSelector: 'app.kubernetes.io/part-of=flux,app.kubernetes.io/component=source-controller',
34+
});
35+
36+
return deployments;
4737
}
4838

4939
export function useFluxControllerAvailableCheck(props: { name: string }) {
@@ -56,15 +46,6 @@ export function useFluxControllerAvailableCheck(props: { name: string }) {
5646
return null;
5747
}
5848

59-
const isFluxAvailable = deployments?.find(
60-
deployment =>
61-
deployment.jsonData.metadata?.labels['app.kubernetes.io/component'] === 'source-controller'
62-
);
63-
64-
if (!isFluxAvailable) {
65-
return true;
66-
}
67-
6849
return deployments?.find(
6950
deployment => deployment.jsonData.metadata?.labels['app.kubernetes.io/component'] === name
7051
);

flux/src/helm-releases/HelmReleaseList.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import {
77
import { useFilterFunc } from '@kinvolk/headlamp-plugin/lib/Utils';
88
import { Link as MuiLink } from '@mui/material';
99
import React from 'react';
10-
import CheckIfFluxInstalled, { useFluxControllerAvailableCheck } from '../checkflux';
10+
import { useTheme } from '@mui/material/styles';
11+
import { useFluxControllerAvailableCheck, useFluxInstallCheck } from '../checkflux';
1112
import Table from '../common/Table';
13+
import Flux404 from '../checkflux';
1214

1315
export function HelmReleases() {
1416
const isHelmReleasesControllerAvailable = useFluxControllerAvailableCheck({
@@ -21,7 +23,12 @@ export function HelmReleases() {
2123

2224
if (!isHelmReleasesControllerAvailable) {
2325
return (
24-
<SectionBox>
26+
<SectionBox sx={{
27+
padding: '1rem',
28+
alignItems: 'center',
29+
margin: '2rem auto',
30+
maxWidth: '600px',
31+
}}>
2532
<h1>Helm Controller is not installed</h1>
2633
<p>
2734
Follow the{' '}
@@ -45,9 +52,18 @@ function HelmReleasesListWrapper() {
4552
return helmReleases?.makeCRClass();
4653
}, [helmReleases]);
4754

55+
const isFluxInstalled = useFluxInstallCheck();
56+
57+
if(isFluxInstalled === null) {
58+
return <Loader />;
59+
}
60+
61+
if(!isFluxInstalled) {
62+
return <Flux404 />;
63+
}
64+
4865
return (
4966
<div>
50-
<CheckIfFluxInstalled />
5167
{helmReleaseResourceClass && <HelmReleasesList resourceClass={helmReleaseResourceClass} />}
5268
</div>
5369
);

flux/src/image-automation/ImageAutomationList.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ import { KubeObject } from '@kinvolk/headlamp-plugin/lib/lib/k8s/cluster';
1111
import { useFilterFunc } from '@kinvolk/headlamp-plugin/lib/Utils';
1212
import { Link as MuiLink } from '@mui/material';
1313
import React from 'react';
14-
import CheckIfFluxInstalled, { useFluxControllerAvailableCheck } from '../checkflux';
14+
import { useTheme } from '@mui/material/styles';
15+
import { useFluxControllerAvailableCheck, useFluxInstallCheck } from '../checkflux';
1516
import SourceLink from '../common/Link';
1617
import Table from '../common/Table';
18+
import Flux404 from '../checkflux';
1719

1820
const IMAGE_AUTOMATION_BETA_VERSION = 'v1beta2';
1921

2022
function ImageAutomation() {
2123
const CRD = K8s.ResourceClasses.CustomResourceDefinition;
24+
const isFluxInstalled = useFluxInstallCheck();
2225
const isVersionAvailable = CRD.apiEndpoint.apiInfo.find(
2326
apiInfo => apiInfo.version === IMAGE_AUTOMATION_BETA_VERSION
2427
);
@@ -50,9 +53,16 @@ function ImageAutomation() {
5053
return imageUpdateAutomation?.makeCRClass();
5154
}, [imageUpdateAutomation]);
5255

56+
if(isFluxInstalled === null){
57+
return <Loader />;
58+
}
59+
60+
if(!isFluxInstalled){
61+
return <Flux404 />;
62+
}
63+
5364
return (
5465
<>
55-
<CheckIfFluxInstalled />
5666
{imageRepository && <ImageRepositoryList resourceClass={imageRepositoryClass} />}
5767
{imagePolicy && <ImagePolicyList resourceClass={imagePolicyClass} />}
5868
{imageUpdateAutomation && (
@@ -73,7 +83,12 @@ export default function ImageAutomationWrapper() {
7383

7484
if (!isImageAutomationControllerAvailable) {
7585
return (
76-
<SectionBox>
86+
<SectionBox sx={{
87+
padding: '1rem',
88+
alignItems: 'center',
89+
margin: '2rem auto',
90+
maxWidth: '600px',
91+
}}>
7792
<h1>Image Automation Controller is not installed</h1>
7893
<p>
7994
Follow the{' '}

flux/src/kustomizations/KustomizationList.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,27 @@ import {
77
import { useFilterFunc } from '@kinvolk/headlamp-plugin/lib/Utils';
88
import MuiLink from '@mui/material/Link';
99
import React from 'react';
10-
import CheckIfFluxInstalled, { useFluxControllerAvailableCheck } from '../checkflux';
10+
import { useTheme } from '@mui/material/styles';
11+
import { useFluxControllerAvailableCheck, useFluxInstallCheck } from '../checkflux';
1112
import Table from '../common/Table';
13+
import Flux404 from '../checkflux';
1214

1315
export function Kustomizations() {
1416
const isKustomizationControllerAvailable = useFluxControllerAvailableCheck({
1517
name: 'kustomize-controller',
1618
});
17-
1819
if (isKustomizationControllerAvailable === null) {
1920
return <Loader />;
2021
}
2122

2223
if (!isKustomizationControllerAvailable) {
2324
return (
24-
<SectionBox>
25+
<SectionBox sx={{
26+
padding: '1rem',
27+
alignItems: 'center',
28+
margin: '2rem auto',
29+
maxWidth: '600px',
30+
}}>
2531
<h1>Kustomize Controller is not installed</h1>
2632
<p>
2733
Follow the{' '}
@@ -38,6 +44,7 @@ export function Kustomizations() {
3844
}
3945

4046
export function KustomizationListWrapper() {
47+
const isFluxInstalled = useFluxInstallCheck();
4148
const [kustomizations] = K8s.ResourceClasses.CustomResourceDefinition.useGet(
4249
'kustomizations.kustomize.toolkit.fluxcd.io'
4350
);
@@ -46,9 +53,16 @@ export function KustomizationListWrapper() {
4653
return kustomizations?.makeCRClass();
4754
}, [kustomizations]);
4855

56+
if(isFluxInstalled === null) {
57+
return <Loader />;
58+
}
59+
60+
if(!isFluxInstalled) {
61+
return <Flux404 />;
62+
}
63+
4964
return (
5065
<div>
51-
<CheckIfFluxInstalled />
5266
{kustomizationResourceClass && (
5367
<KustomizationList resourceClass={kustomizationResourceClass} />
5468
)}

flux/src/notifications/NotificationList.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import {
88
import { useFilterFunc } from '@kinvolk/headlamp-plugin/lib/Utils';
99
import { Box, Link as MuiLink } from '@mui/material';
1010
import React from 'react';
11-
import CheckIfFluxInstalled, { useFluxControllerAvailableCheck } from '../checkflux';
11+
import { useTheme } from '@mui/material/styles';
12+
import { useFluxControllerAvailableCheck, useFluxInstallCheck } from '../checkflux';
1213
import Table from '../common/Table';
14+
import Flux404 from '../checkflux';
1315

1416
export default function NotificationsWrapper() {
1517
const isNotifcationControllerAvailable = useFluxControllerAvailableCheck({
@@ -22,7 +24,12 @@ export default function NotificationsWrapper() {
2224

2325
if (!isNotifcationControllerAvailable) {
2426
return (
25-
<SectionBox>
27+
<SectionBox sx={{
28+
padding: '1rem',
29+
alignItems: 'center',
30+
margin: '2rem auto',
31+
maxWidth: '600px',
32+
}}>
2633
<h1>Notification Controller is not installed</h1>
2734
<p>
2835
Follow the{' '}
@@ -38,6 +45,7 @@ export default function NotificationsWrapper() {
3845
}
3946

4047
export function Notifications() {
48+
const isFluxInstalled = useFluxInstallCheck()
4149
const [alerts] = K8s.ResourceClasses.CustomResourceDefinition.useGet(
4250
'alerts.notification.toolkit.fluxcd.io'
4351
);
@@ -62,9 +70,16 @@ export function Notifications() {
6270
return receivers?.makeCRClass();
6371
}, [receivers]);
6472

73+
if(isFluxInstalled === null) {
74+
return <Loader />;
75+
}
76+
77+
if(!isFluxInstalled) {
78+
return <Flux404 />;
79+
}
80+
6581
return (
6682
<>
67-
<CheckIfFluxInstalled />
6883
{alerts && <Alerts resourceClass={alertsClass} />}
6984
{providers && <Providers resourceClass={providersClass} />}
7085
{receivers && <Receivers resourceClass={receiversClass} />}

flux/src/sources/SourceList.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { K8s } from '@kinvolk/headlamp-plugin/lib';
2-
import { SectionFilterHeader } from '@kinvolk/headlamp-plugin/lib/components/common';
3-
import CheckIfFluxInstalled from '../checkflux';
2+
import { Loader, SectionFilterHeader } from '@kinvolk/headlamp-plugin/lib/components/common';
3+
import { useFluxInstallCheck } from '../checkflux';
44
import FluxSourceCustomResource from './SourceCustomResourceSingle';
5+
import Flux404 from '../checkflux';
56

67
export default function FluxSources() {
8+
const isFluxInstalled = useFluxInstallCheck();
79
const [gitRepoCRD] = K8s.ResourceClasses.CustomResourceDefinition.useGet(
810
'gitrepositories.source.toolkit.fluxcd.io'
911
);
@@ -43,9 +45,16 @@ export default function FluxSources() {
4345
},
4446
];
4547

48+
if(isFluxInstalled === null) {
49+
return <Loader />;
50+
}
51+
52+
if(!isFluxInstalled) {
53+
return <Flux404 />
54+
}
55+
4656
return (
4757
<div>
48-
<CheckIfFluxInstalled />
4958
{sourceTables.map(
5059
({ title, crd }) => crd && <FluxSourceCustomResource crd={crd} title={title} />
5160
)}

0 commit comments

Comments
 (0)