1
0
mirror of https://github.com/rancher/os.git synced 2025-06-01 11:25:51 +00:00
os/config/types.go

249 lines
11 KiB
Go
Raw Normal View History

2015-03-15 04:27:04 +00:00
package config
import (
"fmt"
2016-05-24 00:21:28 +00:00
"runtime"
"github.com/rancher/os/config/cloudinit/config"
2016-11-07 19:36:37 +00:00
"github.com/rancher/os/config/yaml"
2018-09-16 04:55:26 +00:00
"github.com/rancher/os/pkg/netconf"
"github.com/docker/engine-api/types"
composeConfig "github.com/docker/libcompose/config"
)
2015-03-15 04:27:04 +00:00
const (
OemDir = "/usr/share/ros/oem"
BootDir = "/boot"
StateDir = "/state"
2016-11-28 08:06:00 +00:00
RosBin = "/usr/bin/ros"
SysInitBin = "/usr/bin/ros-sysinit"
SystemDockerHost = "unix:///var/run/system-docker.sock"
DockerHost = "unix:///var/run/docker.sock"
ImagesPath = "/usr/share/ros"
InitImages = "images-init.tar"
SystemImages = "images-system.tar"
2019-05-16 06:11:17 +00:00
UserImages = "images-user.tar"
2016-11-28 08:06:00 +00:00
Debug = false
SystemDockerBin = "/usr/bin/system-dockerd"
DefaultDind = "rancher/os-dind:17.12.1"
2016-11-28 08:06:00 +00:00
2018-06-27 04:08:32 +00:00
DetachLabel = "io.rancher.os.detach"
CreateOnlyLabel = "io.rancher.os.createonly"
ReloadConfigLabel = "io.rancher.os.reloadconfig"
ConsoleLabel = "io.rancher.os.console"
ScopeLabel = "io.rancher.os.scope"
RebuildLabel = "io.docker.compose.rebuild"
UserDockerLabel = "io.rancher.user_docker.name"
UserDockerNetLabel = "io.rancher.user_docker.net"
UserDockerFIPLabel = "io.rancher.user_docker.fix_ip"
System = "system"
OsConfigFile = "/usr/share/ros/os-config.yml"
VarRancherDir = "/var/lib/rancher"
CloudConfigDir = "/var/lib/rancher/conf/cloud-config.d"
CloudConfigInitFile = "/var/lib/rancher/conf/cloud-config.d/init.yml"
CloudConfigBootFile = "/var/lib/rancher/conf/cloud-config.d/boot.yml"
2015-12-20 05:37:57 +00:00
CloudConfigNetworkFile = "/var/lib/rancher/conf/cloud-config.d/network.yml"
CloudConfigScriptFile = "/var/lib/rancher/conf/cloud-config-script"
MetaDataFile = "/var/lib/rancher/conf/metadata"
CloudConfigFile = "/var/lib/rancher/conf/cloud-config.yml"
EtcResolvConfFile = "/etc/resolv.conf"
2018-11-07 09:04:45 +00:00
WPAConfigFile = "/etc/wpa_supplicant-%s.conf"
WPATemplateFile = "/etc/wpa_supplicant.conf.tpl"
DHCPCDConfigFile = "/etc/dhcpcd.conf"
DHCPCDTemplateFile = "/etc/dhcpcd.conf.tpl"
2018-06-27 04:08:32 +00:00
MultiDockerConfFile = "/var/lib/rancher/conf.d/m-user-docker.yml"
MultiDockerDataDir = "/var/lib/m-user-docker"
2018-11-29 08:41:52 +00:00
UdevRulesDir = "/etc/udev/rules.d"
UdevRulesExtrasDir = "/lib/udev/rules-extras.d"
2015-03-15 04:27:04 +00:00
)
var (
OemConfigFile = OemDir + "/oem-config.yml"
2016-11-28 08:06:00 +00:00
Version string
BuildDate string
2016-11-28 08:06:00 +00:00
Arch string
Suffix string
OsRepo string
OsBase string
2016-05-31 21:34:04 +00:00
PrivateKeys = []string{
"rancher.ssh",
"rancher.docker.ca_key",
"rancher.docker.ca_cert",
"rancher.docker.server_key",
"rancher.docker.server_cert",
}
Additional = []string{
"rancher.password",
"rancher.autologin",
"EXTRA_CMDLINE",
}
SupportedDinds = []string{
"rancher/os-dind:17.12.1",
"rancher/os-dind:18.03.1",
}
2015-03-15 04:27:04 +00:00
)
func init() {
2016-11-28 08:06:00 +00:00
if Version == "" {
Version = "v0.0.0-dev"
}
2016-11-28 08:06:00 +00:00
if Arch == "" {
Arch = runtime.GOARCH
}
2016-11-28 08:06:00 +00:00
if Suffix == "" && Arch != "amd64" {
Suffix = "_" + Arch
}
2016-11-28 08:06:00 +00:00
if OsBase == "" {
OsBase = fmt.Sprintf("%s/os-base:%s%s", OsRepo, Version, Suffix)
}
}
2015-04-16 05:57:59 +00:00
type Repository struct {
2016-11-28 08:06:00 +00:00
URL string `yaml:"url,omitempty"`
2015-04-16 05:57:59 +00:00
}
type Repositories map[string]Repository
type CloudConfig struct {
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys,omitempty"`
WriteFiles []File `yaml:"write_files,omitempty"`
Hostname string `yaml:"hostname,omitempty"`
2016-11-07 19:36:37 +00:00
Mounts [][]string `yaml:"mounts,omitempty"`
Rancher RancherConfig `yaml:"rancher,omitempty"`
Runcmd []yaml.StringandSlice `yaml:"runcmd,omitempty"`
Bootcmd []yaml.StringandSlice `yaml:"bootcmd,omitempty"`
}
type File struct {
config.File
Container string `yaml:"container,omitempty"`
}
type RancherConfig struct {
2016-06-06 22:13:15 +00:00
Console string `yaml:"console,omitempty"`
2016-05-24 00:21:28 +00:00
Environment map[string]string `yaml:"environment,omitempty"`
Services map[string]*composeConfig.ServiceConfigV1 `yaml:"services,omitempty"`
BootstrapContainers map[string]*composeConfig.ServiceConfigV1 `yaml:"bootstrap,omitempty"`
2016-11-09 19:08:30 +00:00
CloudInitServices map[string]*composeConfig.ServiceConfigV1 `yaml:"cloud_init_services,omitempty"`
2016-05-24 00:21:28 +00:00
BootstrapDocker DockerConfig `yaml:"bootstrap_docker,omitempty"`
CloudInit CloudInit `yaml:"cloud_init,omitempty"`
Debug bool `yaml:"debug,omitempty"`
RmUsr bool `yaml:"rm_usr,omitempty"`
NoSharedRoot bool `yaml:"no_sharedroot,omitempty"`
2016-05-24 00:21:28 +00:00
Log bool `yaml:"log,omitempty"`
ForceConsoleRebuild bool `yaml:"force_console_rebuild,omitempty"`
2016-11-30 01:06:23 +00:00
Recovery bool `yaml:"recovery,omitempty"`
2016-05-24 00:21:28 +00:00
Disable []string `yaml:"disable,omitempty"`
ServicesInclude map[string]bool `yaml:"services_include,omitempty"`
Modules []string `yaml:"modules,omitempty"`
Network netconf.NetworkConfig `yaml:"network,omitempty"`
2016-05-24 00:21:28 +00:00
Repositories Repositories `yaml:"repositories,omitempty"`
2016-11-28 08:06:00 +00:00
SSH SSHConfig `yaml:"ssh,omitempty"`
2016-05-24 00:21:28 +00:00
State StateConfig `yaml:"state,omitempty"`
SystemDocker DockerConfig `yaml:"system_docker,omitempty"`
Upgrade UpgradeConfig `yaml:"upgrade,omitempty"`
Docker DockerConfig `yaml:"docker,omitempty"`
RegistryAuths map[string]types.AuthConfig `yaml:"registry_auths,omitempty"`
Defaults Defaults `yaml:"defaults,omitempty"`
ResizeDevice string `yaml:"resize_device,omitempty"`
2016-06-18 06:05:45 +00:00
Sysctl map[string]string `yaml:"sysctl,omitempty"`
RestartServices []string `yaml:"restart_services,omitempty"`
HypervisorService bool `yaml:"hypervisor_service,omitempty"`
ShutdownTimeout int `yaml:"shutdown_timeout,omitempty"`
HTTPLoadRetries int `yaml:"http_load_retries,omitempty"`
2018-04-02 04:56:47 +00:00
PreloadWait bool `yaml:"preload_wait,omitempty"`
2015-03-15 05:21:22 +00:00
}
2015-03-15 04:27:04 +00:00
type UpgradeConfig struct {
2016-11-28 08:06:00 +00:00
URL string `yaml:"url,omitempty"`
2015-03-19 21:57:53 +00:00
Image string `yaml:"image,omitempty"`
Rollback string `yaml:"rollback,omitempty"`
2019-01-30 05:32:08 +00:00
Policy string `yaml:"policy,omitempty"`
2015-03-15 04:27:04 +00:00
}
type EngineOpts struct {
Bridge string `yaml:"bridge,omitempty" opt:"bridge"`
BIP string `yaml:"bip,omitempty" opt:"bip"`
ConfigFile string `yaml:"config_file,omitempty" opt:"config-file"`
Containerd string `yaml:"containerd,omitempty" opt:"containerd"`
Debug *bool `yaml:"debug,omitempty" opt:"debug"`
ExecRoot string `yaml:"exec_root,omitempty" opt:"exec-root"`
Group string `yaml:"group,omitempty" opt:"group"`
Graph string `yaml:"graph,omitempty" opt:"graph"`
Host []string `yaml:"host,omitempty" opt:"host"`
InsecureRegistry []string `yaml:"insecure_registry" opt:"insecure-registry"`
LiveRestore *bool `yaml:"live_restore,omitempty" opt:"live-restore"`
LogDriver string `yaml:"log_driver,omitempty" opt:"log-driver"`
LogOpts map[string]string `yaml:"log_opts,omitempty" opt:"log-opt"`
PidFile string `yaml:"pid_file,omitempty" opt:"pidfile"`
RegistryMirror string `yaml:"registry_mirror,omitempty" opt:"registry-mirror"`
Restart *bool `yaml:"restart,omitempty" opt:"restart"`
SelinuxEnabled *bool `yaml:"selinux_enabled,omitempty" opt:"selinux-enabled"`
StorageDriver string `yaml:"storage_driver,omitempty" opt:"storage-driver"`
UserlandProxy *bool `yaml:"userland_proxy,omitempty" opt:"userland-proxy"`
}
2015-03-18 13:23:27 +00:00
type DockerConfig struct {
EngineOpts
Engine string `yaml:"engine,omitempty"`
TLS bool `yaml:"tls,omitempty"`
TLSArgs []string `yaml:"tls_args,flow,omitempty"`
ExtraArgs []string `yaml:"extra_args,flow,omitempty"`
ServerCert string `yaml:"server_cert,omitempty"`
ServerKey string `yaml:"server_key,omitempty"`
CACert string `yaml:"ca_cert,omitempty"`
CAKey string `yaml:"ca_key,omitempty"`
Environment []string `yaml:"environment,omitempty"`
StorageContext string `yaml:"storage_context,omitempty"`
Exec bool `yaml:"exec,omitempty"`
2015-03-15 04:27:04 +00:00
}
2016-11-28 08:06:00 +00:00
type SSHConfig struct {
Keys map[string]string `yaml:"keys,omitempty"`
Daemon bool `yaml:"daemon,omitempty"`
Port int `yaml:"port,omitempty"`
ListenAddress string `yaml:"listen_address,omitempty"`
}
2015-03-18 13:23:27 +00:00
type StateConfig struct {
Directory string `yaml:"directory,omitempty"`
2015-03-18 13:23:27 +00:00
FsType string `yaml:"fstype,omitempty"`
Dev string `yaml:"dev,omitempty"`
2016-07-28 06:25:08 +00:00
Wait bool `yaml:"wait,omitempty"`
2015-03-18 13:23:27 +00:00
Required bool `yaml:"required,omitempty"`
Autoformat []string `yaml:"autoformat,omitempty"`
2015-12-21 06:26:34 +00:00
MdadmScan bool `yaml:"mdadm_scan,omitempty"`
2018-10-31 13:36:59 +00:00
LvmScan bool `yaml:"lvm_scan,omitempty"`
Cryptsetup bool `yaml:"cryptsetup,omitempty"`
2018-09-14 08:34:09 +00:00
Rngd bool `yaml:"rngd,omitempty"`
2015-12-21 06:26:34 +00:00
Script string `yaml:"script,omitempty"`
OemFsType string `yaml:"oem_fstype,omitempty"`
OemDev string `yaml:"oem_dev,omitempty"`
BootFsType string `yaml:"boot_fstype,omitempty"`
BootDev string `yaml:"boot_dev,omitempty"`
2015-03-15 04:27:04 +00:00
}
type CloudInit struct {
Datasources []string `yaml:"datasources,omitempty"`
}
2015-03-20 18:35:21 +00:00
type Defaults struct {
Hostname string `yaml:"hostname,omitempty"`
Docker DockerConfig `yaml:"docker,omitempty"`
Network netconf.NetworkConfig `yaml:"network,omitempty"`
SystemDockerLogs string `yaml:"system_docker_logs,omitempty"`
}
func (r Repositories) ToArray() []string {
result := make([]string, 0, len(r))
for _, repo := range r {
2016-11-28 08:06:00 +00:00
if repo.URL != "" {
result = append(result, repo.URL)
}
2015-03-20 18:35:21 +00:00
}
return result
2015-03-20 18:35:21 +00:00
}