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

ssh: List pending nodes #368

Merged
merged 7 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
support pending machines
  • Loading branch information
petersutter committed Jan 16, 2024
commit 0cd9fc56c2429fe631964c8f15ee7c8e2082a691
17 changes: 15 additions & 2 deletions pkg/cmd/ssh/connect_information.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,17 @@ func NewConnectInformation(
sshPrivateKeyFile PrivateKeyFile,
nodePrivateKeyFiles []PrivateKeyFile,
nodes []corev1.Node,
pendingNodeNames []string,
user string,
) (*ConnectInformation, error) {
var nodeList []Node
nodeSet := make(map[string]Node)
petersutter marked this conversation as resolved.
Show resolved Hide resolved

for _, pendingNodeName := range pendingNodeNames {
nodeSet[pendingNodeName] = Node{
Name: pendingNodeName,
Status: "Unknown",
}
}

for _, node := range nodes {
n := Node{
Expand Down Expand Up @@ -125,7 +133,12 @@ func NewConnectInformation(
}
}

nodeList = append(nodeList, n)
nodeSet[n.Name] = n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea here, very smart.

}

nodeList := make([]Node, 0, len(nodeSet))
for _, node := range nodeSet {
nodeList = append(nodeList, node)
}

return &ConnectInformation{
Expand Down
13 changes: 13 additions & 0 deletions pkg/cmd/ssh/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,23 @@ func (o *SSHOptions) Run(f util.Factory) error {

if !o.Interactive {
var nodes []corev1.Node

var pendingNodeNames []string

if nodeHostname == "" {
nodes, err = getNodes(ctx, shootClient)
if err != nil {
return fmt.Errorf("failed to list shoot cluster nodes: %w", err)
}

// We also want to determine if there are nodes that have not yet joined the cluster.
// This is an optional step, as only Gardener operators have access to the Seeds.
// Regular users will receive a 'Forbidden' error when trying to fetch the Machines.
// However, we do not want to log an error message in this case.
pendingNodeNames, err = getNodeNamesFromMachines(ctx, manager, currentTarget)
if err != nil && !apierrors.IsForbidden(err) {
logger.Info("failed to get shoot cluster node names from machines", "err", err)
}
}

connectInformation, err := NewConnectInformation(
Expand All @@ -664,6 +676,7 @@ func (o *SSHOptions) Run(f util.Factory) error {
o.SSHPrivateKeyFile,
nodePrivateKeyFiles,
nodes,
pendingNodeNames,
o.User,
)
if err != nil {
Expand Down