-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(topology): remove usage of k8s plugin from topology & tekton plu…
…gins (#1869) feat(topology): remove k8s plugin dependency from topology & tekton
- Loading branch information
Showing
31 changed files
with
522 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { useDebounceCallback } from './debounce'; | ||
export { useDeepCompareMemoize } from './useDeepCompareMemoize'; | ||
export { useKubernetesObjects } from './useKubernetesObjects'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// This file is a replica of useKubernetesObjects.ts & auth.ts from the Backstage upstream, created to address the issue https://issues.redhat.com/browse/RHIDP-3126 | ||
|
||
import { useCallback } from 'react'; | ||
import useAsyncRetry from 'react-use/esm/useAsyncRetry'; | ||
import useInterval from 'react-use/esm/useInterval'; | ||
|
||
import { Entity } from '@backstage/catalog-model'; | ||
import { ApiRef, useApi } from '@backstage/core-plugin-api'; | ||
import { | ||
KubernetesRequestBody, | ||
ObjectsByEntityResponse, | ||
} from '@backstage/plugin-kubernetes-common'; | ||
import { | ||
KubernetesApi, | ||
KubernetesAuthProvidersApi, | ||
} from '@backstage/plugin-kubernetes-react'; | ||
|
||
/** | ||
* | ||
* @public | ||
*/ | ||
export interface KubernetesObjects { | ||
kubernetesObjects?: ObjectsByEntityResponse; | ||
loading: boolean; | ||
error?: string; | ||
} | ||
|
||
const generateAuth = async ( | ||
entity: Entity, | ||
kubernetesApi: KubernetesApi, | ||
kubernetesAuthProvidersApi: KubernetesAuthProvidersApi, | ||
) => { | ||
const clusters = await kubernetesApi.getClusters(); | ||
|
||
const authProviders: string[] = [ | ||
...new Set( | ||
clusters.map( | ||
c => | ||
`${c.authProvider}${ | ||
c.oidcTokenProvider ? `.${c.oidcTokenProvider}` : '' | ||
}`, | ||
), | ||
), | ||
]; | ||
|
||
let requestBody: KubernetesRequestBody = { | ||
entity, | ||
}; | ||
for (const authProviderStr of authProviders) { | ||
requestBody = await kubernetesAuthProvidersApi.decorateRequestBodyForAuth( | ||
authProviderStr, | ||
requestBody, | ||
); | ||
} | ||
return requestBody.auth ?? {}; | ||
}; | ||
|
||
/** | ||
* | ||
* @public | ||
*/ | ||
export const useKubernetesObjects = ( | ||
entity: Entity, | ||
kubernetesApiRef: ApiRef<KubernetesApi>, | ||
kubernetesAuthProvidersApiRef: ApiRef<KubernetesAuthProvidersApi>, | ||
intervalMs: number = 10000, | ||
): KubernetesObjects => { | ||
const kubernetesApi = useApi(kubernetesApiRef); | ||
const kubernetesAuthProvidersApi = useApi(kubernetesAuthProvidersApiRef); | ||
const getObjects = useCallback(async (): Promise<ObjectsByEntityResponse> => { | ||
const auth = await generateAuth( | ||
entity, | ||
kubernetesApi, | ||
kubernetesAuthProvidersApi, | ||
); | ||
return await kubernetesApi.getObjectsByEntity({ | ||
auth, | ||
entity, | ||
}); | ||
}, [kubernetesApi, entity, kubernetesAuthProvidersApi]); | ||
|
||
const { value, loading, error, retry } = useAsyncRetry( | ||
() => getObjects(), | ||
[getObjects], | ||
); | ||
|
||
useInterval(() => retry(), intervalMs); | ||
|
||
return { | ||
kubernetesObjects: value, | ||
loading, | ||
error: error?.message, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.