mirror of
https://github.com/rancher/os.git
synced 2025-09-12 13:17:17 +00:00
Fix environment variables set for system services
This commit is contained in:
@@ -32,7 +32,7 @@ func CreateService(cfg *config.CloudConfig, name string, serviceConfig *project.
|
||||
}
|
||||
|
||||
func CreateServiceSet(name string, cfg *config.CloudConfig, configs map[string]*project.ServiceConfig) (*project.Project, error) {
|
||||
p, err := newProject(name, cfg)
|
||||
p, err := newProject(name, cfg, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -55,12 +55,16 @@ func GetProject(cfg *config.CloudConfig, networkingAvailable bool) (*project.Pro
|
||||
return newCoreServiceProject(cfg, networkingAvailable)
|
||||
}
|
||||
|
||||
func newProject(name string, cfg *config.CloudConfig) (*project.Project, error) {
|
||||
func newProject(name string, cfg *config.CloudConfig, environmentLookup project.EnvironmentLookup) (*project.Project, error) {
|
||||
clientFactory, err := rosDocker.NewClientFactory(docker.ClientOpts{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if environmentLookup == nil {
|
||||
environmentLookup = rosDocker.NewConfigEnvironment(cfg)
|
||||
}
|
||||
|
||||
serviceFactory := &rosDocker.ServiceFactory{
|
||||
Deps: map[string][]string{},
|
||||
}
|
||||
@@ -69,7 +73,7 @@ func newProject(name string, cfg *config.CloudConfig) (*project.Project, error)
|
||||
Context: project.Context{
|
||||
ProjectName: name,
|
||||
NoRecreate: true, // for libcompose to not recreate on project reload, looping up the boot :)
|
||||
EnvironmentLookup: rosDocker.NewConfigEnvironment(cfg),
|
||||
EnvironmentLookup: environmentLookup,
|
||||
ServiceFactory: serviceFactory,
|
||||
Log: cfg.Rancher.Log,
|
||||
LoggerFactory: logger.NewColorLoggerFactory(),
|
||||
@@ -121,7 +125,9 @@ func newCoreServiceProject(cfg *config.CloudConfig, network bool) (*project.Proj
|
||||
projectEvents := make(chan project.Event)
|
||||
enabled := map[interface{}]interface{}{}
|
||||
|
||||
p, err := newProject("os", cfg)
|
||||
environmentLookup := rosDocker.NewConfigEnvironment(cfg)
|
||||
|
||||
p, err := newProject("os", cfg, environmentLookup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -136,6 +142,8 @@ func newCoreServiceProject(cfg *config.CloudConfig, network bool) (*project.Proj
|
||||
return err
|
||||
}
|
||||
|
||||
environmentLookup.SetConfig(cfg)
|
||||
|
||||
enabled = addServices(p, enabled, cfg.Rancher.Services)
|
||||
|
||||
for service, serviceEnabled := range cfg.Rancher.ServicesInclude {
|
||||
@@ -193,7 +201,7 @@ func newCoreServiceProject(cfg *config.CloudConfig, network bool) (*project.Proj
|
||||
}
|
||||
|
||||
func StageServices(cfg *config.CloudConfig, services ...string) error {
|
||||
p, err := newProject("stage-services", cfg)
|
||||
p, err := newProject("stage-services", cfg, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -49,6 +49,10 @@ func lookupKeys(cfg *config.CloudConfig, keys ...string) []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func (c *ConfigEnvironment) SetConfig(cfg *config.CloudConfig) {
|
||||
c.cfg = cfg
|
||||
}
|
||||
|
||||
func (c *ConfigEnvironment) Lookup(key, serviceName string, serviceConfig *project.ServiceConfig) []string {
|
||||
fullKey := fmt.Sprintf("%s/%s", serviceName, key)
|
||||
return lookupKeys(c.cfg, fullKey, key)
|
||||
|
18
tests/integration/assets/test_11/cloud-config.yml
Normal file
18
tests/integration/assets/test_11/cloud-config.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
#cloud-config
|
||||
rancher:
|
||||
environment:
|
||||
A: A
|
||||
BB: BB
|
||||
BC: BC
|
||||
services:
|
||||
env:
|
||||
image: busybox
|
||||
command: env
|
||||
labels:
|
||||
io.rancher.os.scope: system
|
||||
io.rancher.os.before: console
|
||||
environment:
|
||||
- A
|
||||
- B*
|
||||
ssh_authorized_keys:
|
||||
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt
|
22
tests/integration/rostest/test_11_environment.py
Normal file
22
tests/integration/rostest/test_11_environment.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import pytest
|
||||
import rostest.util as u
|
||||
from rostest.util import SSH
|
||||
|
||||
ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key']
|
||||
cloud_config_path = './tests/integration/assets/test_11/cloud-config.yml'
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def qemu(request):
|
||||
q = u.run_qemu(request, ['--cloud-config', cloud_config_path])
|
||||
u.flush_out(q.stdout)
|
||||
return q
|
||||
|
||||
|
||||
@pytest.mark.timeout(40)
|
||||
def test_rancher_environment_in_system_service(qemu):
|
||||
SSH(qemu, ssh_command).check_call('''
|
||||
sudo system-docker logs env | grep A=A
|
||||
sudo system-docker logs env | grep BB=BB
|
||||
sudo system-docker logs env | grep BC=BC
|
||||
''')
|
Reference in New Issue
Block a user