func()

in internal/ssm/config.go [18:56]


func (s *ssm) registerMachine(cfg *api.NodeConfig) error {
	registration := NewSSMRegistration()
	registered, err := registration.isRegistered()
	if err != nil {
		return err
	}

	if registered {
		s.logger.Info("SSM agent already registered, skipping registration")
	} else {
		agentPath, err := agentBinaryPath()
		if err != nil {
			return fmt.Errorf("can't register without ssm agent installed: %w", err)
		}

		s.logger.Info("Registering machine with SSM agent")
		registerCmd := exec.Command(agentPath,
			"-register", "-y",
			"-region", cfg.Spec.Cluster.Region,
			"-code", cfg.Spec.Hybrid.SSM.ActivationCode,
			"-id", cfg.Spec.Hybrid.SSM.ActivationID,
		)

		out, err := registerCmd.CombinedOutput()
		if err != nil {
			return fmt.Errorf("running register machine command: %s, error: %v", out, err)
		}
	}

	// Set the nodename on nodeconfig post registration
	registeredNodeName, err := registration.GetManagedHybridInstanceId()
	if err != nil {
		return err
	}

	s.logger.Info("Machine registered with SSM, assigning instance ID as node name", zap.String("instanceID", registeredNodeName))
	s.nodeConfig.Status.Hybrid.NodeName = registeredNodeName
	return nil
}