Skip to content

Commit cafb6b8

Browse files
authored
📖 Improved code comments in host.go (#1712)
1 parent 5885311 commit cafb6b8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/services/baremetal/host/host.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ func rebootTypesFromStringList(rebootTypeStringList []string) ([]infrav1.RebootT
316316
return rebootTypes, nil
317317
}
318318

319+
// ensureSSHKey ensures that the given ssh key is known to the Robot-API.
320+
// s.scope.RobotClient.SetSSHKey() gets used to upload the public-key, if it is not there yet.
319321
func (s *Service) ensureSSHKey(sshSecretRef infrav1.SSHSecretRef, sshSecret *corev1.Secret) (infrav1.SSHKey, actionResult) {
320322
if sshSecret == nil {
321323
return infrav1.SSHKey{}, actionError{err: errNilSSHSecret}
@@ -324,7 +326,7 @@ func (s *Service) ensureSSHKey(sshSecretRef infrav1.SSHSecretRef, sshSecret *cor
324326
if err != nil {
325327
s.handleRobotRateLimitExceeded(err, "ListSSHKeys")
326328
if !models.IsError(err, models.ErrorCodeNotFound) {
327-
return infrav1.SSHKey{}, actionError{err: fmt.Errorf("failed to list ssh heys: %w", err)}
329+
return infrav1.SSHKey{}, actionError{err: fmt.Errorf("failed to list ssh keys: %w", err)}
328330
}
329331
}
330332

@@ -345,6 +347,9 @@ func (s *Service) ensureSSHKey(sshSecretRef infrav1.SSHSecretRef, sshSecret *cor
345347
if err != nil {
346348
s.handleRobotRateLimitExceeded(err, "SetSSHKey")
347349
if models.IsError(err, models.ErrorCodeKeyAlreadyExists) {
350+
// Robot SSH-keys API is a bit strange: the public key value must be unique; you
351+
// can’t add the same key twice. Uniqueness is checked by key value, not by the
352+
// key’s name.
348353
msg := fmt.Sprintf("cannot upload ssh key %q (from secret %q) - exists already under a different name: %s",
349354
string(sshSecret.Data[sshSecretRef.Key.Name]), sshSecretRef.Name, err.Error())
350355
conditions.MarkFalse(
@@ -2149,7 +2154,7 @@ func (s *Service) actionProvisioned(ctx context.Context) actionResult {
21492154
}
21502155
err = fmt.Errorf("failed to handle incomplete boot - actionProvisioned: %w", err)
21512156
conditions.MarkFalse(host, infrav1.RebootSucceededCondition,
2152-
"FailureFailGettingHostnameViaSSH",
2157+
"FailureGettingHostnameViaSSH",
21532158
clusterv1.ConditionSeverityWarning, "%s",
21542159
err.Error())
21552160
return actionError{err: err}

0 commit comments

Comments
 (0)