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

fix: get clusters #260

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions charts/console/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ spec:
- name: INSTALL_METHOD
value: {{ .Values.installMethod | default "helm" }}
- name: K1_ACCESS_TOKEN
valueFrom:
secretKeyRef:
name: {{ .Values.existingSecret | default "kubefirst-initial-secrets" }}
key: K1_ACCESS_TOKEN
value: feedkray
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
Expand Down
24 changes: 22 additions & 2 deletions containers/header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import React, { FunctionComponent } from 'react';
import React, { FunctionComponent, useEffect } from 'react';

import { setSelectedCluster } from '../../redux/slices/cluster.slice';
import { getClusters } from '../../redux/thunks/api.thunk';
import { useAppDispatch, useAppSelector } from '../../redux/store';

import { Container } from './header.styled';

const Header: FunctionComponent = () => <Container />;
const Header: FunctionComponent = () => {
const dispatch = useAppDispatch();
const { managementCluster } = useAppSelector(({ api }) => api);

useEffect(() => {
dispatch(getClusters());
}, [dispatch]);

useEffect(() => {
if (managementCluster && managementCluster.id) {
dispatch(setSelectedCluster(managementCluster));
}
}, [dispatch, managementCluster]);

return <Container />;
};

export default Header;
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const nextConfig = {
dangerouslyAllowSVG: true,
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
remotePatterns: [],
unoptimized: false,
unoptimized: true,
remotePatterns: [
{
protocol: 'https',
Expand Down
35 changes: 33 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
import Provision from './provision';
import React, { FunctionComponent, useEffect } from 'react';
import { useRouter } from 'next/router';

import { useAppDispatch, useAppSelector } from '../redux/store';
import { getClusters } from '../redux/thunks/api.thunk';
import withConfig from '../hoc/withConfig';
import { setSelectedCluster } from '../redux/slices/cluster.slice';
export { getServerSideProps } from '../hoc/withConfig';

export default Provision;
const MainPage: FunctionComponent = () => {
const dispatch = useAppDispatch();
const { push } = useRouter();

const { managementCluster } = useAppSelector(({ api }) => api);

useEffect(() => {
dispatch(getClusters())
.unwrap()
.then(() => {
push('/services');
})
.catch(() => {
push('/provision');
});
}, [dispatch, push]);

useEffect(() => {
if (managementCluster && managementCluster.id) {
dispatch(setSelectedCluster(managementCluster));
}
}, [dispatch, managementCluster]);

return null;
};

export default withConfig(MainPage);
4 changes: 4 additions & 0 deletions redux/thunks/api.thunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ export const getClusters = createAsyncThunk<
throw res.error;
}

if (!res.data && !res.data[0]) {
throw new Error('No clusters found');
}

// only process single expected management cluster
return mapClusterFromRaw(res.data[0]);
});
Expand Down