diff --git a/pkg/infradriver/ssh_infradriver.go b/pkg/infradriver/ssh_infradriver.go index 1995d0ef4b4..f63cb43832f 100644 --- a/pkg/infradriver/ssh_infradriver.go +++ b/pkg/infradriver/ssh_infradriver.go @@ -26,6 +26,7 @@ import ( v2 "github.com/sealerio/sealer/types/api/v2" "github.com/sealerio/sealer/utils/shellcommand" "github.com/sealerio/sealer/utils/ssh" + "golang.org/x/sync/errgroup" ) @@ -34,7 +35,7 @@ type SSHInfraDriver struct { hosts []net.IP roleHostsMap map[string][]net.IP hostEnvMap map[string]map[string]interface{} - clusterRenderData map[string]interface{} + clusterEnv map[string]interface{} clusterName string clusterImageName string clusterLaunchCmds []string @@ -90,7 +91,7 @@ func NewInfraDriver(cluster *v2.Cluster) (InfraDriver, error) { roleHostsMap: map[string][]net.IP{}, // todo need to separate env into app render data and sys render data hostEnvMap: map[string]map[string]interface{}{}, - clusterRenderData: ConvertEnv(cluster.Spec.Env), + clusterEnv: ConvertEnv(cluster.Spec.Env), clusterHostAliases: cluster.Spec.HostAliases, } @@ -125,7 +126,7 @@ func NewInfraDriver(cluster *v2.Cluster) (InfraDriver, error) { // merge the host ENV and global env, the host env will overwrite cluster.Spec.Env for _, host := range cluster.Spec.Hosts { for _, ip := range host.IPS { - ret.hostEnvMap[ip.String()] = mergeList(ConvertEnv(host.Env), ret.clusterRenderData) + ret.hostEnvMap[ip.String()] = mergeList(ConvertEnv(host.Env), ret.clusterEnv) } } @@ -141,11 +142,23 @@ func (d *SSHInfraDriver) GetHostIPListByRole(role string) []net.IP { } func (d *SSHInfraDriver) GetHostEnv(host net.IP) map[string]interface{} { - return d.hostEnvMap[host.String()] + hostEnv := d.hostEnvMap[host.String()] + if hostEnv["HostIP"] == nil { + hostEnv["HostIP"] = host.String() + } + + return hostEnv } func (d *SSHInfraDriver) GetClusterEnv() map[string]interface{} { - return d.clusterRenderData + if d.clusterEnv["RegistryDomain"] == nil { + d.clusterEnv["RegistryDomain"] = "sea.hub" + } + if d.clusterEnv["RegistryPort"] == nil { + d.clusterEnv["RegistryPort"] = "5000" + } + + return d.clusterEnv } func (d *SSHInfraDriver) Copy(host net.IP, localFilePath, remoteFilePath string) error { diff --git a/pkg/infradriver/ssh_infradriver_test.go b/pkg/infradriver/ssh_infradriver_test.go index f46269f7153..b5882d9a6a0 100644 --- a/pkg/infradriver/ssh_infradriver_test.go +++ b/pkg/infradriver/ssh_infradriver_test.go @@ -117,17 +117,20 @@ func TestSSHInfraDriver_GetClusterInfo(t *testing.T) { }) assert.Equal(t, driver.GetClusterEnv(), map[string]interface{}{ - "key1": "value1", - "key2": []string{"value2", "value3"}, + "HostIP": []string{"192.168.0.2", "192.168.0.3"}, + "key1": "value1", + "key2": []string{"value2", "value3"}, }) assert.Equal(t, driver.GetHostEnv(net.IPv4(192, 168, 0, 2)), map[string]interface{}{ + "HostIP": []string{"192.168.0.2", "192.168.0.3"}, "key1": "value1", "key2": []string{"value2", "value3"}, "etcd-dir": "/data/etcd", }) assert.Equal(t, driver.GetHostEnv(net.IPv4(192, 168, 0, 3)), map[string]interface{}{ + "HostIP": []string{"192.168.0.2", "192.168.0.3"}, "key1": "value1", "key2": []string{"value2", "value3"}, "test_node_env_key": "test_node_env_value",