-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Move EKS Discover joinToken generation to the ManualHelm dialog. #37730
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
Changes from all commits
c05349b
52f6cf7
55f8214
5fafad1
0d9a158
e67ad98
8faf471
2f7a401
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ | |
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| import React, { useState } from 'react'; | ||
| import React, { useState, useCallback } from 'react'; | ||
| import { Box, ButtonSecondary, ButtonText, Text, Toggle } from 'design'; | ||
| import styled from 'styled-components'; | ||
| import { FetchStatus } from 'design/DataTable/types'; | ||
|
|
@@ -39,14 +39,15 @@ import { isIamPermError } from 'teleport/Discover/Shared/Aws/error'; | |
| import { AgentStepProps } from 'teleport/Discover/types'; | ||
| import useTeleport from 'teleport/useTeleport'; | ||
|
|
||
| import { useJoinTokenSuspender } from 'teleport/Discover/Shared/useJoinTokenSuspender'; | ||
| import { generateCmd } from 'teleport/Discover/Kubernetes/HelmChart/HelmChart'; | ||
| import { Kube } from 'teleport/services/kube'; | ||
|
|
||
| import { Header, ResourceKind } from '../../Shared'; | ||
| import { JoinToken } from 'teleport/services/joinToken'; | ||
|
|
||
| import { Header } from '../../Shared'; | ||
|
|
||
| import { ClustersList } from './EksClustersList'; | ||
| import { ManualHelmDialog } from './ManualHelmDialog'; | ||
| import ManualHelmDialog from './ManualHelmDialog'; | ||
| import { EnrollmentDialog } from './EnrollmentDialog'; | ||
| import { AgentWaitingDialog } from './AgentWaitingDialog'; | ||
|
|
||
|
|
@@ -97,14 +98,11 @@ export function EnrollEksCluster(props: AgentStepProps) { | |
| useState(false); | ||
| const [isManualHelmDialogShown, setIsManualHelmDialogShown] = useState(false); | ||
| const [waitingResourceId, setWaitingResourceId] = useState(''); | ||
| // join token will be set only if user opens ManualHelmDialog, | ||
| // we delay it to avoid premature admin action MFA confirmation request. | ||
| const [joinToken, setJoinToken] = useState<JoinToken>(null); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's document the fact that we need a separate state for the join token because while the join token is used mostly by code in If I saw this code without any context, my inclination would be to move
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added comment 👍 55f8214 |
||
| const ctx = useTeleport(); | ||
|
|
||
| const { joinToken } = useJoinTokenSuspender([ | ||
| ResourceKind.Kubernetes, | ||
| ResourceKind.Application, | ||
| ResourceKind.Discovery, | ||
| ]); | ||
|
|
||
| function fetchClustersWithNewRegion(region: Regions) { | ||
| setSelectedRegion(region); | ||
| // Clear table when fetching with new region. | ||
|
|
@@ -205,8 +203,6 @@ export function EnrollEksCluster(props: AgentStepProps) { | |
| { | ||
| region: selectedRegion, | ||
| enableAppDiscovery: isAppDiscoveryEnabled, | ||
| joinToken: joinToken.id, | ||
| resourceId: joinToken.internalResourceId, | ||
|
Comment on lines
-208
to
-209
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did we remove it?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not used anymore by the backend - we now create our own token in the backend enrollment code and return resourceId that frontend should look for while pinging resource. |
||
| clusterNames: [selectedCluster.name], | ||
| } | ||
| ); | ||
|
|
@@ -262,23 +258,34 @@ export function EnrollEksCluster(props: AgentStepProps) { | |
| !selectedCluster || | ||
| enrollmentState.status !== 'notStarted'; | ||
|
|
||
| let command = ''; | ||
| if (selectedCluster) { | ||
| command = generateCmd({ | ||
| namespace: 'teleport-agent', | ||
| clusterName: selectedCluster.name, | ||
| proxyAddr: ctx.storeUser.state.cluster.publicURL, | ||
| tokenId: joinToken.id, | ||
| clusterVersion: ctx.storeUser.state.cluster.authVersion, | ||
| resourceId: joinToken.internalResourceId, | ||
| isEnterprise: ctx.isEnterprise, | ||
| isCloud: ctx.isCloud, | ||
| automaticUpgradesEnabled: ctx.automaticUpgradesEnabled, | ||
| automaticUpgradesTargetVersion: ctx.automaticUpgradesTargetVersion, | ||
| joinLabels: [...selectedCluster.labels, ...selectedCluster.joinLabels], | ||
| disableAppDiscovery: !isAppDiscoveryEnabled, | ||
| }); | ||
| } | ||
| const setJoinTokenAndGetCommand = useCallback( | ||
| (token: JoinToken) => { | ||
| setJoinToken(token); | ||
| return generateCmd({ | ||
| namespace: 'teleport-agent', | ||
| clusterName: selectedCluster.name, | ||
| proxyAddr: ctx.storeUser.state.cluster.publicURL, | ||
| clusterVersion: ctx.storeUser.state.cluster.authVersion, | ||
| tokenId: token.id, | ||
| resourceId: token.internalResourceId, | ||
| isEnterprise: ctx.isEnterprise, | ||
| isCloud: ctx.isCloud, | ||
| automaticUpgradesEnabled: ctx.automaticUpgradesEnabled, | ||
| automaticUpgradesTargetVersion: ctx.automaticUpgradesTargetVersion, | ||
| joinLabels: [...selectedCluster.labels, ...selectedCluster.joinLabels], | ||
| disableAppDiscovery: !isAppDiscoveryEnabled, | ||
| }); | ||
| }, | ||
| [ | ||
| ctx.automaticUpgradesEnabled, | ||
| ctx.automaticUpgradesTargetVersion, | ||
| ctx.isCloud, | ||
| ctx.isEnterprise, | ||
| ctx.storeUser.state.cluster, | ||
| isAppDiscoveryEnabled, | ||
| selectedCluster, | ||
| ] | ||
| ); | ||
|
|
||
| return ( | ||
| <Box maxWidth="1000px"> | ||
|
|
@@ -366,7 +373,7 @@ export function EnrollEksCluster(props: AgentStepProps) { | |
| )} | ||
| {isManualHelmDialogShown && ( | ||
| <ManualHelmDialog | ||
| command={command} | ||
| setJoinTokenAndGetCommand={setJoinTokenAndGetCommand} | ||
| cancel={() => setIsManualHelmDialogShown(false)} | ||
| confirmedCommands={() => { | ||
| setEnrollmentState({ status: 'awaitingAgent' }); | ||
|
|
@@ -377,7 +384,7 @@ export function EnrollEksCluster(props: AgentStepProps) { | |
| )} | ||
| {isAgentWaitingDialogShown && ( | ||
| <AgentWaitingDialog | ||
| joinResourceId={waitingResourceId || joinToken.internalResourceId} | ||
| joinResourceId={waitingResourceId || joinToken?.internalResourceId} | ||
| status={enrollmentState.status} | ||
| clusterName={selectedCluster.name} | ||
| updateWaitingResult={(result: Kube) => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I open the story for
EnrollEksClusterand try to openManualHelmDialog, I get "A component suspended while responding to synchronous input. This will cause the UI to be replaced with a loading indicator. To fix, updates that suspend should be wrapped with startTransition."I wanted to use the story to see how
setJoinTokeninManualHelmDialoginteracts with re-renderingEnrollEksClustersince I don't have a cluster with an AWS account set up to test this in a real UI.storybook-error.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added container to the dialog 52f6cf7