filestore: Parse Profiles found in /etc/bootcfg/profiles

* FileStore should manage resources found in type named directories
since this is similar to a traditional table-DB layout and to how
an EtcdStore would work
This commit is contained in:
Dalton Hubble
2016-03-25 11:52:29 -07:00
parent d72c136590
commit 4e563bbce3
22 changed files with 26 additions and 29 deletions

View File

@@ -8,10 +8,10 @@
#### Changes
* Rename `Spec` to `Profile`.
- Rename top-level config groups field `spec` to `profile`
- Keep Profiles in a `profiles` data directory
* Change default `-config` path to `/etc/bootcfg.conf`
* Rename `Spec` to `Profile`.
- Rename groups field `spec` to `profile`
- Keep profiles in JSON files under `/etc/bootcfg/profiles`
* Change default `-data-path` to `/etc/bootcfg`
* Change default `-assets-path` to `/var/bootcfg`
* Remove HTTP `/spec/id` JSON endpoint

View File

@@ -35,10 +35,8 @@ Prepare `/etc/bootcfg` or a custom `-data-path` with `profile`, `ignition`, and
│   └── etcd.yaml
│   └── simple_networking.yaml
└── profiles
└── etcd
└── profile.json
└── worker
└── profile.json
└── etcd.json
└── worker.json
Ignition templates can be JSON or YAML files. Cloud-Config templates can be a script or YAML file. Both may contain may contain [Go template](https://golang.org/pkg/text/template/) elements which will be executed machine group [metadata](#groups-and-metadata). For details and examples:
@@ -50,7 +48,8 @@ Ignition templates can be JSON or YAML files. Cloud-Config templates can be a sc
Profiles specify the Ignition config, Cloud-Config, and network boot config to be used by machine(s).
{
"id": "etcd_profile",
"id": "etcd",
"name": "CoreOS with etcd2"
"cloud_id": "",
"ignition_id": "etcd.yaml",
"boot": {
@@ -104,13 +103,13 @@ Here is an example `/etc/bootcfg.conf` YAML file:
ssh_authorized_keys:
- "ssh-rsa pub-key-goes-here"
- name: etcd Proxy
profile: etcd_proxy
profile: etcd-proxy
require:
mac: 52:54:00:89:d8:10
metadata:
etcd_initial_cluster: "node1=http://172.15.0.21:2380"
For example, a request to `/cloud?mac=52:54:00:89:d8:10` would render the Cloud-Config template in the "etcd_proxy" `Profile`, with the machine group's metadata. A request to `/cloud` would match the default group (which has no selectors) and render the Cloud-Config in the "discovery" Profile. Avoid defining multiple default groups as resolution will not be deterministic.
For example, a request to `/cloud?mac=52:54:00:89:d8:10` would render the Cloud-Config template in the "etcd-proxy" `Profile`, with the machine group's metadata. A request to `/cloud` would match the default group (which has no selectors) and render the Cloud-Config in the "discovery" Profile. Avoid defining multiple default groups as resolution will not be deterministic.
### Reserved Attributes

View File

@@ -10,7 +10,7 @@ Ignition template files can be added in the `/etc/bootcfg/ignition` directory or
├── ignition
│   └── simple.json
│   └── etcd.yaml
│   └── etcd_proxy.yaml
│   └── etcd-proxy.yaml
│   └── networking.yaml
└── profiles

View File

@@ -3,6 +3,7 @@ package storage
import (
"encoding/json"
"path/filepath"
"strings"
"github.com/coreos/coreos-baremetal/bootcfg/storage/storagepb"
)
@@ -54,7 +55,7 @@ func (s *fileStore) GroupList() ([]*storagepb.Group, error) {
// ProfileGet gets a profile by id.
func (s *fileStore) ProfileGet(id string) (*storagepb.Profile, error) {
data, err := Dir(s.root).readFile(filepath.Join("profiles", id, "profile.json"))
data, err := Dir(s.root).readFile(filepath.Join("profiles", id+".json"))
if err != nil {
return nil, err
}
@@ -77,7 +78,8 @@ func (s *fileStore) ProfileList() ([]*storagepb.Profile, error) {
}
profiles := make([]*storagepb.Profile, 0, len(files))
for _, finfo := range files {
profile, err := s.ProfileGet(finfo.Name())
name := strings.TrimSuffix(finfo.Name(), filepath.Ext(finfo.Name()))
profile, err := s.ProfileGet(name)
if err == nil {
profiles = append(profiles, profile)
}

View File

@@ -99,16 +99,12 @@ func setup(fixedStore *fixedStore) (root string, err error) {
profileDir := filepath.Join(root, "profiles")
ignitionDir := filepath.Join(root, "ignition")
cloudDir := filepath.Join(root, "cloud")
dirs := []string{profileDir, ignitionDir, cloudDir}
for _, profile := range fixedStore.Profiles {
dirs = append(dirs, filepath.Join(root, "profiles", profile.Id))
}
if err := mkdirs(dirs...); err != nil {
if err := mkdirs(profileDir, ignitionDir, cloudDir); err != nil {
return root, err
}
// files
for _, profile := range fixedStore.Profiles {
profileFile := filepath.Join(profileDir, profile.Id, "profile.json")
profileFile := filepath.Join(profileDir, profile.Id+".json")
data, err := json.MarshalIndent(profile, "", "\t")
if err != nil {
return root, err

View File

@@ -2,7 +2,7 @@
api_version: v1alpha1
groups:
- name: CoreOS Install
profile: coreos-install
profile: install-reboot
metadata:
coreos_channel: alpha
coreos_version: 962.0.0
@@ -55,7 +55,7 @@ groups:
etcd_initial_cluster: "node1=http://172.15.0.21:2380,node2=http://172.15.0.22:2380,node3=http://172.15.0.23:2380"
- name: etcd Proxy
profile: etcd_proxy
profile: etcd-proxy
require:
os: installed
metadata:

View File

@@ -44,7 +44,7 @@ groups:
etcd_initial_cluster: "node1=http://172.17.0.21:2380,node2=http://172.17.0.22:2380,node3=http://172.17.0.23:2380"
- name: default
profile: etcd_proxy
profile: etcd-proxy
metadata:
networkd_name: ens3
networkd_gateway: 172.17.0.1

View File

@@ -44,7 +44,7 @@ groups:
etcd_initial_cluster: "node1=http://172.15.0.21:2380,node2=http://172.15.0.22:2380,node3=http://172.15.0.23:2380"
- name: default
profile: etcd_proxy
profile: etcd-proxy
metadata:
networkd_name: ens3
networkd_gateway: 172.15.0.1

0
examples/groups/.gitkeep Normal file
View File

View File

@@ -2,7 +2,7 @@
api_version: v1alpha1
groups:
- name: CoreOS Install
profile: coreos-install
profile: install-reboot
metadata:
coreos_channel: alpha
coreos_version: 983.0.0

View File

@@ -1,6 +1,6 @@
{
"id": "etcd_proxy",
"name": "etcd_proxy",
"id": "etcd-proxy",
"name": "etcd-proxy",
"boot": {
"kernel": "/assets/coreos/983.0.0/coreos_production_pxe.vmlinuz",
"initrd": ["/assets/coreos/983.0.0/coreos_production_pxe_image.cpio.gz"],
@@ -11,5 +11,5 @@
}
},
"cloud_id": "",
"ignition_id": "etcd_proxy.yaml"
"ignition_id": "etcd-proxy.yaml"
}

View File

@@ -1,6 +1,6 @@
{
"id": "coreos-install",
"name": "Install CoreOS",
"id": "install-reboot",
"name": "Install CoreOS and Reboot",
"boot": {
"kernel": "/assets/coreos/983.0.0/coreos_production_pxe.vmlinuz",
"initrd": ["/assets/coreos/983.0.0/coreos_production_pxe_image.cpio.gz"],