Skip to content

Commit 269ef05

Browse files
authored
fix: Prevent infinite loop after connecting incorrect kubeconfig (kyma-project#4197)
* fix: Prevent infinite loop after connecting incorrect kubeconfig * fix: infinite loading * test: adjust hpa test * fix: adjust test
1 parent 25435c0 commit 269ef05

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/components/App/resourceSchemas/useResourceSchemas.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,18 @@ export const useResourceSchemas = () => {
4343
notification.notifyError({
4444
content: t('clusters.messages.connection-failed'),
4545
});
46+
4647
navigate('/clusters');
4748
}
49+
// eslint-disable-next-line react-hooks/exhaustive-deps
4850
}, [
4951
activeClusterName,
5052
cluster?.contextName,
5153
authData,
52-
openApi,
54+
openApi.state,
5355
isClusterList,
5456
navigate,
5557
t,
56-
notification,
5758
]);
5859

5960
useEffect(() => {

src/state/authDataAtom.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { parseOIDCparams } from 'components/Clusters/components/oidc-params';
22
import { User, UserManager } from 'oidc-client-ts';
3-
import { useEffect, useState } from 'react';
3+
import { useEffect, useRef, useState } from 'react';
44
import { useNavigate } from 'react-router';
55
import { atom, useAtomValue, useSetAtom } from 'jotai';
66
import { KubeconfigNonOIDCAuth, KubeconfigOIDCAuth } from 'types';
77
import { clusterAtom } from './clusterAtom';
88
import { getPreviousPath } from './useAfterInitHook';
99
import { openapiLastFetchedAtom } from 'state/openapi/openapiLastFetchedAtom';
10+
import { isEqual } from 'lodash';
1011

1112
export const hasNonOidcAuth = (
1213
user?: KubeconfigNonOIDCAuth | KubeconfigOIDCAuth,
@@ -138,27 +139,24 @@ export function useAuthHandler() {
138139
const navigate = useNavigate();
139140
const setLastFetched = useSetAtom(openapiLastFetchedAtom);
140141
const [isLoading, setIsLoading] = useState(true);
142+
const prevClusterRef = useRef<typeof cluster>(null);
141143

142144
useEffect(() => {
143-
console.log(
144-
'currentCluster reference changed, TODO make sure to deeply compare',
145-
);
146-
147145
if (!cluster) {
148146
setAuth(null);
149147
setIsLoading(false);
150148
} else {
151-
// don't do the auth flow on cluster list (e.g. after refresh, while the OIDC cluster is still connected)
152-
if (window.location.pathname === '/clusters') {
153-
setIsLoading(false);
154-
return;
155-
}
149+
if (isEqual(prevClusterRef.current, cluster)) return; // Skip if unchanged
150+
156151
const userCredentials = cluster.currentContext?.user?.user;
152+
157153
if (hasNonOidcAuth(userCredentials)) {
158154
setAuth(userCredentials as KubeconfigNonOIDCAuth);
159155
setIsLoading(false);
160156
} else {
161157
const onAfterLogin = () => {
158+
setIsLoading(false);
159+
162160
if (!getPreviousPath() || getPreviousPath() === '/clusters') {
163161
if (cluster.currentContext.namespace) {
164162
navigate(
@@ -170,8 +168,8 @@ export function useAuthHandler() {
170168
navigate('/cluster/' + encodeURIComponent(cluster.name));
171169
}
172170
}
173-
setIsLoading(false);
174171
};
172+
175173
const onError = () => {
176174
navigate('/clusters');
177175
setIsLoading(false);

tests/integration/tests/kyma-namespace/test-hpa.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ context('Test HPA', () => {
9090

9191
it('Check HPA subcomponent', () => {
9292
cy.clickGenericListLink(HPA_NAME);
93-
cy.wait(500);
93+
cy.wait(1000);
9494
cy.contains('ui5-link', DEPLOYEMENT_NAME).click();
9595
cy.wait(500);
9696
cy.url().should('match', /deployments/);
@@ -101,7 +101,7 @@ context('Test HPA', () => {
101101

102102
cy.wait(500).inspectTab('Edit');
103103

104-
cy.wait(2000);
104+
cy.wait(3000);
105105

106106
cy.getMidColumn()
107107
.get('[data-testid="spec.minReplicas"]:visible')

0 commit comments

Comments
 (0)