github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/pkg/infradriver/infradriver.go (about) 1 // Copyright © 2022 Alibaba Group Holding Ltd. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package infradriver 16 17 import ( 18 "net" 19 20 k8sv1 "k8s.io/api/core/v1" 21 22 v1 "github.com/sealerio/sealer/types/api/v1" 23 v2 "github.com/sealerio/sealer/types/api/v2" 24 ) 25 26 // InfraDriver treat the entire cluster as an operating system kernel, 27 // interface function here is the target system call. 28 type InfraDriver interface { 29 // GetHostTaints GetHostTaint return host taint 30 GetHostTaints(host net.IP) []k8sv1.Taint 31 32 GetHostIPList() []net.IP 33 34 GetHostIPListByRole(role string) []net.IP 35 36 GetRoleListByHostIP(ip string) []string 37 38 GetHostsPlatform(hosts []net.IP) (map[v1.Platform][]net.IP, error) 39 40 //GetHostEnv return merged env with host env and cluster env. 41 GetHostEnv(host net.IP) map[string]string 42 43 //GetHostLabels return host labels. 44 GetHostLabels(host net.IP) map[string]string 45 46 //GetClusterEnv return cluster.spec.env as map[string]interface{} 47 GetClusterEnv() map[string]string 48 49 AddClusterEnv(envs []string) 50 51 //GetClusterName ${clusterName} 52 GetClusterName() string 53 54 //GetClusterImageName ${cluster image Name} 55 GetClusterImageName() string 56 57 //GetClusterLaunchCmds ${user-defined launch command} 58 GetClusterLaunchCmds() []string 59 60 //GetClusterLaunchApps ${user-defined launch apps} 61 GetClusterLaunchApps() []string 62 63 //GetClusterRootfsPath /var/lib/sealer/data/${clusterName}/rootfs 64 GetClusterRootfsPath() string 65 66 // GetClusterBasePath /var/lib/sealer/data/${clusterName} 67 GetClusterBasePath() string 68 69 // Execute use eg.Go to execute shell cmd concurrently 70 Execute(hosts []net.IP, f func(host net.IP) error) error 71 72 // Copy local files to remote host 73 // scp -r /tmp root@192.168.0.2:/root/tmp => Copy("192.168.0.2","tmp","/root/tmp") 74 // need check md5sum 75 Copy(host net.IP, localFilePath, remoteFilePath string) error 76 // CopyR copy remote host files to localhost 77 CopyR(host net.IP, remoteFilePath, localFilePath string) error 78 // CmdAsync exec command on remote host, and asynchronous return logs 79 CmdAsync(host net.IP, env map[string]string, cmd ...string) error 80 // Cmd exec command on remote host, and return combined standard output and standard error 81 Cmd(host net.IP, env map[string]string, cmd string) ([]byte, error) 82 // CmdToString exec command on remote host, and return spilt standard output and standard error 83 CmdToString(host net.IP, env map[string]string, cmd, spilt string) (string, error) 84 85 // IsFileExist check remote file exist or not 86 IsFileExist(host net.IP, remoteFilePath string) (bool, error) 87 // IsDirExist Remote file existence returns true, nil 88 IsDirExist(host net.IP, remoteDirPath string) (bool, error) 89 90 // GetPlatform Get remote platform 91 GetPlatform(host net.IP) (v1.Platform, error) 92 93 GetHostName(host net.IP) (string, error) 94 // Ping Ping remote host 95 Ping(host net.IP) error 96 // SetHostName add or update host name on host 97 SetHostName(host net.IP, hostName string) error 98 99 //SetClusterHostAliases set additional HostAliases 100 SetClusterHostAliases(hosts []net.IP) error 101 102 //DeleteClusterHostAliases delete additional HostAliases 103 DeleteClusterHostAliases(hosts []net.IP) error 104 105 GetClusterRegistry() v2.Registry 106 // SetLvsRule add or update host name on host 107 //SetLvsRule(host net.IP, hostName string) error 108 }