mirror of
https://github.com/rancher/os.git
synced 2025-09-01 14:48:55 +00:00
Reshuffle cloud-config
Read files cloud-config.d in alphanumeric order, then cloud-config.yml `ros config` writes to cloud-config.yml (and cloud-config.d/private.yml - only private keys) Add (c *CloudConfig) Save() method, use it to save the changed config Read and apply metadata as part of LoadConfig() Simplify ros config export logic
This commit is contained in:
100
config/metadata_test.go
Normal file
100
config/metadata_test.go
Normal file
@@ -0,0 +1,100 @@
|
||||
// Copyright 2015 CoreOS, Inc.
|
||||
// Copyright 2015 Rancher Labs, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/coreos/coreos-cloudinit/datasource"
|
||||
)
|
||||
|
||||
func TestSubstituteUserDataVars(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
metadata datasource.Metadata
|
||||
input string
|
||||
out string
|
||||
}{
|
||||
{
|
||||
// Userdata with docker-compose syntax
|
||||
datasource.Metadata{
|
||||
PublicIPv4: net.ParseIP("192.0.2.3"),
|
||||
PrivateIPv4: net.ParseIP("192.0.2.203"),
|
||||
PublicIPv6: net.ParseIP("fe00:1234::"),
|
||||
PrivateIPv6: net.ParseIP("fe00:5678::"),
|
||||
},
|
||||
`servicexyz:
|
||||
image: rancher/servicexyz:v0.3.1
|
||||
ports:
|
||||
- "$public_ipv4:8001:8001"
|
||||
- "$public_ipv6:8001:8001"
|
||||
- "$private_ipv4:8001:8001"
|
||||
- "$private_ipv6:8001:8001"`,
|
||||
`servicexyz:
|
||||
image: rancher/servicexyz:v0.3.1
|
||||
ports:
|
||||
- "192.0.2.3:8001:8001"
|
||||
- "fe00:1234:::8001:8001"
|
||||
- "192.0.2.203:8001:8001"
|
||||
- "fe00:5678:::8001:8001"`,
|
||||
},
|
||||
{
|
||||
// Userdata with cloud-config/rancher syntax
|
||||
datasource.Metadata{
|
||||
PublicIPv4: net.ParseIP("192.0.2.3"),
|
||||
PrivateIPv4: net.ParseIP("192.0.2.203"),
|
||||
PublicIPv6: net.ParseIP("fe00:1234::"),
|
||||
PrivateIPv6: net.ParseIP("fe00:5678::"),
|
||||
},
|
||||
`write_files:
|
||||
- path: /etc/environment
|
||||
content: |
|
||||
PRIVATE_IPV6=$private_ipv6
|
||||
PUBLIC_IPV6=$public_ipv6
|
||||
rancher:
|
||||
network:
|
||||
interfaces:
|
||||
eth1:
|
||||
address: $private_ipv4/16
|
||||
docker:
|
||||
tls_args: ['-H=$public_ipv4:2376']`,
|
||||
`write_files:
|
||||
- path: /etc/environment
|
||||
content: |
|
||||
PRIVATE_IPV6=fe00:5678::
|
||||
PUBLIC_IPV6=fe00:1234::
|
||||
rancher:
|
||||
network:
|
||||
interfaces:
|
||||
eth1:
|
||||
address: 192.0.2.203/16
|
||||
docker:
|
||||
tls_args: ['-H=192.0.2.3:2376']`,
|
||||
},
|
||||
{
|
||||
// no metadata
|
||||
datasource.Metadata{},
|
||||
"address: $private_ipv4",
|
||||
"address: ",
|
||||
},
|
||||
} {
|
||||
|
||||
got := substituteVars([]byte(tt.input), tt.metadata)
|
||||
if string(got) != tt.out {
|
||||
t.Fatalf("Userdata substitution incorrectly applied.\ngot:\n%s\nwant:\n%s", got, tt.out)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user