Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
reword agent-bind-ip to ssh-address
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed Dec 13, 2021
1 parent 109b00d commit 24bb748
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ jobs:
set -ex
for target_host in ${TRENTO_AGENT_HOSTS//,/ }
do
ssh "$TRENTO_USER@$target_host" "TRENTO_REPO_OWNER=$TRENTO_REPO_OWNER sudo --preserve-env=PATH,TRENTO_REPO_OWNER bash -s" -- < ./install-agent.sh "--rolling" "--use-tgz" "--agent-bind-ip" "$target_host" "--server-ip" "$TRENTO_SERVER_HOST"
ssh "$TRENTO_USER@$target_host" "TRENTO_REPO_OWNER=$TRENTO_REPO_OWNER sudo --preserve-env=PATH,TRENTO_REPO_OWNER bash -s" -- < ./install-agent.sh "--rolling" "--use-tgz" "--ssh-address" "$target_host" "--server-ip" "$TRENTO_SERVER_HOST"
ssh "$TRENTO_USER@$target_host" "sudo systemctl enable --now trento-agent.service"
done
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,18 @@ sudo ./install-agent.sh

The script will ask you for two IP addresses.

- `agent bind IP`: the private address to which the trento-agent should be bound for internal communications.
This is an IP address that should be reachable by the other hosts, including the trento server.
Note for the Pacemaker users: this IP address _should not be_ a floating IP.
- `ssh address`: the address to which the trento-agent should be reachable for ssh connection by the runner for check execution.

- `trento server IP`: the address where Trento server can be reached.

You can pass these arguments as flags or env variables too:

```
curl -sfL https://raw.githubusercontent.com/trento-project/trento/main/install-agent.sh | sudo bash -s - --agent-bind-ip=192.168.33.10 --server-ip=192.168.33.1
curl -sfL https://raw.githubusercontent.com/trento-project/trento/main/install-agent.sh | sudo bash -s - --ssh-address=192.168.33.10 --server-ip=192.168.33.1
```

```
AGENT_BIND_IP=192.168.33.10 SERVER_IP=192.168.33.1 sudo ./install-agent.sh
SSH_ADDRESS=192.168.33.10 SERVER_IP=192.168.33.1 sudo ./install-agent.sh
```

#### Starting Trento Agent service
Expand Down
4 changes: 2 additions & 2 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Agent struct {

type Config struct {
InstanceName string
BindIP string
SSHAddress string
ConsulConfigDir string
DiscoveryPeriod time.Duration
CollectorConfig *collector.Config
Expand Down Expand Up @@ -69,7 +69,7 @@ func NewAgent(config *Config) (*Agent, error) {
discovery.NewSAPSystemsDiscovery(consulClient, collectorClient),
discovery.NewCloudDiscovery(consulClient, collectorClient),
discovery.NewSubscriptionDiscovery(collectorClient),
discovery.NewHostDiscovery(config.BindIP, consulClient, collectorClient),
discovery.NewHostDiscovery(config.SSHAddress, consulClient, collectorClient),
},
templateRunner: templateRunner,
}
Expand Down
12 changes: 6 additions & 6 deletions agent/discovery/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import (
const HostDiscoveryId string = "host_discovery"

type HostDiscovery struct {
id string
agentBindIP string
discovery BaseDiscovery
id string
sshAddress string
discovery BaseDiscovery
}

func NewHostDiscovery(agentBindIP string, consulClient consul.Client, collectorClient collector.Client) HostDiscovery {
func NewHostDiscovery(sshAddress string, consulClient consul.Client, collectorClient collector.Client) HostDiscovery {
d := HostDiscovery{}
d.id = HostDiscoveryId
d.agentBindIP = agentBindIP
d.sshAddress = sshAddress
d.discovery = NewDiscovery(consulClient, collectorClient)
return d
}
Expand All @@ -52,7 +52,7 @@ func (h HostDiscovery) Discover() (string, error) {
}

host := hosts.DiscoveredHost{
AgentBindIP: h.agentBindIP,
SSHAddress: h.sshAddress,
OSVersion: getOSVersion(),
HostIpAddresses: ipAddresses,
HostName: h.discovery.host,
Expand Down
2 changes: 1 addition & 1 deletion agent/discovery/mocks/discovered_host_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "github.com/trento-project/trento/internal/hosts"

func NewDiscoveredHostMock() hosts.DiscoveredHost {
return hosts.DiscoveredHost{
AgentBindIP: "10.2.2.22",
SSHAddress: "10.2.2.22",
OSVersion: "15-SP2",
HostIpAddresses: []string{"10.1.1.4", "10.1.1.5", "10.1.1.6"},
HostName: "thehostnamewherethediscoveryhappened",
Expand Down
6 changes: 3 additions & 3 deletions cmd/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func NewAgentCmd() *cobra.Command {
var bindIP string
var sshAddress string
var consulConfigDir string
var discoveryPeriod int

Expand All @@ -42,8 +42,8 @@ func NewAgentCmd() *cobra.Command {
},
}

startCmd.Flags().StringVar(&bindIP, "bind-ip", "", "Private address to which the trento-agent should be bound for internal communications. Reachable by the other hosts, including the trento server.")
startCmd.MarkFlagRequired("bind-ip")
startCmd.Flags().StringVar(&sshAddress, "ssh-address", "", "The address to which the trento-agent should be reachable for ssh connection by the runner for check execution.")
startCmd.MarkFlagRequired("ssh-address")

startCmd.Flags().StringVarP(&consulConfigDir, "consul-config-dir", "", "consul.d", "Consul configuration directory used to store node meta-data")
startCmd.Flags().IntVarP(&discoveryPeriod, "discovery-period", "", 2, "Discovery mechanism loop period on minutes")
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func LoadConfig() (*agent.Config, error) {
},
ConsulConfigDir: viper.GetString("consul-config-dir"),
InstanceName: hostname,
BindIP: viper.GetString("bind-ip"),
SSHAddress: viper.GetString("ssh-address"),
DiscoveryPeriod: time.Duration(viper.GetInt("discovery-period")) * time.Minute,
}, nil
}
21 changes: 10 additions & 11 deletions install-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ that can help you deploy, provision and operate infrastructure for SAP Applicati
Usage:
sudo ./install-agent.sh --agent-bind-ip <192.168.122.10> --server-ip <192.168.122.5>
sudo ./install-agent.sh --ssh-address <192.168.122.10> --server-ip <192.168.122.5>
Arguments:
--agent-bind-ip The private address to which the trento-agent should be bound for internal communications.
This is an IP address that should be reachable by the other hosts, including the trento server.
--ssh-address The address to which the trento-agent should be reachable for ssh connection by the runner for check execution.
--server-ip The trento server ip.
--rolling Use the factory/rolling-release version instead of the stable one.
--use-tgz Use the trento tar.gz file from GH releases rather than the RPM
Expand All @@ -35,7 +34,7 @@ case "$1" in
esac

ARGUMENT_LIST=(
"agent-bind-ip:"
"ssh-address:"
"server-ip:"
"rolling"
"use-tgz"
Expand All @@ -55,8 +54,8 @@ eval set "--$opts"

while [[ $# -gt 0 ]]; do
case "$1" in
--agent-bind-ip)
AGENT_BIND_IP=$2
--ssh-address)
SSH_ADDRESS=$2
shift 2
;;

Expand Down Expand Up @@ -117,7 +116,7 @@ AGENT_CONFIG_PATH="/etc/trento"
AGENT_CONFIG_FILE="$AGENT_CONFIG_PATH/agent.yaml"
AGENT_CONFIG_TEMPLATE='
consul-config-dir: @CONFIG_PATH@
bind-ip: @BIND_IP@
ssh-address: @SSH_ADDRESS@
collector-host: @COLLECTOR_HOST@
'

Expand All @@ -141,8 +140,8 @@ function check_installer_deps() {
}

function configure_installation() {
if [[ -z "$AGENT_BIND_IP" ]]; then
read -rp "Please provide a bind IP for the agent: " AGENT_BIND_IP </dev/tty
if [[ -z "$SSH_ADDRESS" ]]; then
read -rp "Please provide an ssh address for the agent: " SSH_ADDRESS </dev/tty
fi
if [[ -z "$SERVER_IP" ]]; then
read -rp "Please provide the server IP: " SERVER_IP </dev/tty
Expand All @@ -161,7 +160,7 @@ function install_consul() {
function setup_consul() {
echo "$CONSUL_HCL_TEMPLATE" |
sed "s|@JOIN_ADDR@|${SERVER_IP}|g" |
sed "s|@BIND_ADDR@|${AGENT_BIND_IP}|g" \
sed "s|@BIND_ADDR@|${SSH_ADDRESS}|g" \
>${CONFIG_PATH}/consul.hcl

if [[ -f "/usr/lib/systemd/system/$CONSUL_SERVICE_NAME" ]]; then
Expand Down Expand Up @@ -242,7 +241,7 @@ function setup_trento() {
echo "$AGENT_CONFIG_TEMPLATE" |
sed "s|@CONFIG_PATH@|${CONFIG_PATH}|g" |
sed "s|@COLLECTOR_HOST@|${SERVER_IP}|g" |
sed "s|@BIND_IP@|${AGENT_BIND_IP}|g" \
sed "s|@SSH_ADDRESS@|${SSH_ADDRESS}|g" \
> ${AGENT_CONFIG_FILE}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/hosts/discovered_host.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hosts

type DiscoveredHost struct {
AgentBindIP string `json:"agent_bind_ip"`
SSHAddress string `json:"ssh_address"`
OSVersion string `json:"os_version"`
HostIpAddresses []string `json:"ip_addresses"`
HostName string `json:"hostname"`
Expand Down
7 changes: 7 additions & 0 deletions packaging/config/agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@

###############################################################################

## The address to which the trento-agent should be reachable for ssh connection by the runner for check execution.
## Required.

# ssh-address: 0.0.0.0

###############################################################################

## Discovery period configures the tick interval for the discovery loops.
## Time unit is minutes
## Defaults to 2.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"agent_id": "779cdd70-e9e2-58ca-b18a-bf3eb3f71244",
"discovery_type": "host_discovery",
"payload": {
"agent_bind_ip": "10.2.2.22",
"ssh_address": "10.2.2.22",
"os_version": "15-SP2",
"ip_addresses": [
"10.1.1.4",
Expand Down
4 changes: 2 additions & 2 deletions web/datapipeline/hosts_projector.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func hostsProjector_HostDiscoveryHandler(dataCollectedEvent *DataCollectedEvent,

host := entities.Host{
AgentID: dataCollectedEvent.AgentID,
AgentBindIP: discoveredHost.AgentBindIP,
SSHAddress: discoveredHost.SSHAddress,
Name: discoveredHost.HostName,
IPAddresses: filterIPAddresses(discoveredHost.HostIpAddresses),
AgentVersion: discoveredHost.AgentVersion,
Expand All @@ -46,7 +46,7 @@ func hostsProjector_HostDiscoveryHandler(dataCollectedEvent *DataCollectedEvent,
"name",
"ip_addresses",
"agent_version",
"agent_bind_ip",
"ssh_address",
)
}

Expand Down
2 changes: 1 addition & 1 deletion web/entities/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

type Host struct {
AgentID string `gorm:"primaryKey"`
AgentBindIP string
SSHAddress string
Name string
IPAddresses pq.StringArray `gorm:"type:text[]"`
CloudProvider string
Expand Down
2 changes: 1 addition & 1 deletion web/services/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (s *clustersService) GetAllClustersSettings() (models.ClustersSettings, err

hosts = append(hosts, &models.HostConnection{
Name: host.Name,
Address: host.AgentBindIP,
Address: host.SSHAddress,
User: username,
})
}
Expand Down
4 changes: 2 additions & 2 deletions web/services/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func loadClustersFixtures(db *gorm.DB) {
Hosts: []*entities.Host{
{
AgentID: "1",
AgentBindIP: "10.74.2.10",
SSHAddress: "10.74.2.10",
ClusterID: "1",
Name: "host1",
IPAddresses: []string{"10.74.1.10"},
Expand Down Expand Up @@ -102,7 +102,7 @@ func loadClustersFixtures(db *gorm.DB) {
Hosts: []*entities.Host{
{
AgentID: "2",
AgentBindIP: "10.74.2.11",
SSHAddress: "10.74.2.11",
ClusterID: "2",
Name: "host2",
IPAddresses: pq.StringArray{"10.74.1.11"},
Expand Down

0 comments on commit 24bb748

Please sign in to comment.