From 4e563bbce3e0130c466feee322ac1d4e29ddb294 Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Fri, 25 Mar 2016 11:52:29 -0700 Subject: [PATCH] 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 --- CHANGES.md | 6 +++--- Documentation/bootcfg.md | 13 ++++++------- Documentation/ignition.md | 2 +- bootcfg/storage/filestore.go | 6 ++++-- bootcfg/storage/filestore_test.go | 8 ++------ examples/coreos-install.yaml | 4 ++-- examples/etcd-docker.yaml | 2 +- examples/etcd-rkt.yaml | 2 +- examples/groups/.gitkeep | 0 .../ignition/{etcd_proxy.yaml => etcd-proxy.yaml} | 0 examples/k8s-install.yaml | 2 +- .../{etcd_proxy/profile.json => etcd-proxy.json} | 6 +++--- examples/profiles/{etcd/profile.json => etcd.json} | 0 examples/profiles/{grub/profile.json => grub.json} | 0 .../profile.json => install-reboot.json} | 4 ++-- .../profile.json => install-shutdown.json} | 0 .../profile.json => k8s-master-install.json} | 0 .../{k8s-master/profile.json => k8s-master.json} | 0 .../profile.json => k8s-worker-install.json} | 0 .../{k8s-worker/profile.json => k8s-worker.json} | 0 .../{pxe-disk/profile.json => pxe-disk.json} | 0 examples/profiles/{pxe/profile.json => pxe.json} | 0 22 files changed, 26 insertions(+), 29 deletions(-) create mode 100644 examples/groups/.gitkeep rename examples/ignition/{etcd_proxy.yaml => etcd-proxy.yaml} (100%) rename examples/profiles/{etcd_proxy/profile.json => etcd-proxy.json} (81%) rename examples/profiles/{etcd/profile.json => etcd.json} (100%) rename examples/profiles/{grub/profile.json => grub.json} (100%) rename examples/profiles/{coreos-install/profile.json => install-reboot.json} (86%) rename examples/profiles/{install-shutdown/profile.json => install-shutdown.json} (100%) rename examples/profiles/{k8s-master-install/profile.json => k8s-master-install.json} (100%) rename examples/profiles/{k8s-master/profile.json => k8s-master.json} (100%) rename examples/profiles/{k8s-worker-install/profile.json => k8s-worker-install.json} (100%) rename examples/profiles/{k8s-worker/profile.json => k8s-worker.json} (100%) rename examples/profiles/{pxe-disk/profile.json => pxe-disk.json} (100%) rename examples/profiles/{pxe/profile.json => pxe.json} (100%) diff --git a/CHANGES.md b/CHANGES.md index c991640a..43107a34 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/Documentation/bootcfg.md b/Documentation/bootcfg.md index e298461a..00680071 100644 --- a/Documentation/bootcfg.md +++ b/Documentation/bootcfg.md @@ -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 diff --git a/Documentation/ignition.md b/Documentation/ignition.md index f1c48df1..d6d1909a 100644 --- a/Documentation/ignition.md +++ b/Documentation/ignition.md @@ -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 diff --git a/bootcfg/storage/filestore.go b/bootcfg/storage/filestore.go index f092c3bd..2316872e 100644 --- a/bootcfg/storage/filestore.go +++ b/bootcfg/storage/filestore.go @@ -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) } diff --git a/bootcfg/storage/filestore_test.go b/bootcfg/storage/filestore_test.go index a3b617be..35e88997 100644 --- a/bootcfg/storage/filestore_test.go +++ b/bootcfg/storage/filestore_test.go @@ -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 diff --git a/examples/coreos-install.yaml b/examples/coreos-install.yaml index f468b015..53f5924f 100644 --- a/examples/coreos-install.yaml +++ b/examples/coreos-install.yaml @@ -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: diff --git a/examples/etcd-docker.yaml b/examples/etcd-docker.yaml index d043b5f9..a96ab6c7 100644 --- a/examples/etcd-docker.yaml +++ b/examples/etcd-docker.yaml @@ -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 diff --git a/examples/etcd-rkt.yaml b/examples/etcd-rkt.yaml index 92c3e8d7..84198990 100644 --- a/examples/etcd-rkt.yaml +++ b/examples/etcd-rkt.yaml @@ -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 diff --git a/examples/groups/.gitkeep b/examples/groups/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/examples/ignition/etcd_proxy.yaml b/examples/ignition/etcd-proxy.yaml similarity index 100% rename from examples/ignition/etcd_proxy.yaml rename to examples/ignition/etcd-proxy.yaml diff --git a/examples/k8s-install.yaml b/examples/k8s-install.yaml index 5b3c2398..ae02a243 100644 --- a/examples/k8s-install.yaml +++ b/examples/k8s-install.yaml @@ -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 diff --git a/examples/profiles/etcd_proxy/profile.json b/examples/profiles/etcd-proxy.json similarity index 81% rename from examples/profiles/etcd_proxy/profile.json rename to examples/profiles/etcd-proxy.json index 6b99bad2..ad520ddb 100644 --- a/examples/profiles/etcd_proxy/profile.json +++ b/examples/profiles/etcd-proxy.json @@ -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" } \ No newline at end of file diff --git a/examples/profiles/etcd/profile.json b/examples/profiles/etcd.json similarity index 100% rename from examples/profiles/etcd/profile.json rename to examples/profiles/etcd.json diff --git a/examples/profiles/grub/profile.json b/examples/profiles/grub.json similarity index 100% rename from examples/profiles/grub/profile.json rename to examples/profiles/grub.json diff --git a/examples/profiles/coreos-install/profile.json b/examples/profiles/install-reboot.json similarity index 86% rename from examples/profiles/coreos-install/profile.json rename to examples/profiles/install-reboot.json index 58c2959c..16266655 100644 --- a/examples/profiles/coreos-install/profile.json +++ b/examples/profiles/install-reboot.json @@ -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"], diff --git a/examples/profiles/install-shutdown/profile.json b/examples/profiles/install-shutdown.json similarity index 100% rename from examples/profiles/install-shutdown/profile.json rename to examples/profiles/install-shutdown.json diff --git a/examples/profiles/k8s-master-install/profile.json b/examples/profiles/k8s-master-install.json similarity index 100% rename from examples/profiles/k8s-master-install/profile.json rename to examples/profiles/k8s-master-install.json diff --git a/examples/profiles/k8s-master/profile.json b/examples/profiles/k8s-master.json similarity index 100% rename from examples/profiles/k8s-master/profile.json rename to examples/profiles/k8s-master.json diff --git a/examples/profiles/k8s-worker-install/profile.json b/examples/profiles/k8s-worker-install.json similarity index 100% rename from examples/profiles/k8s-worker-install/profile.json rename to examples/profiles/k8s-worker-install.json diff --git a/examples/profiles/k8s-worker/profile.json b/examples/profiles/k8s-worker.json similarity index 100% rename from examples/profiles/k8s-worker/profile.json rename to examples/profiles/k8s-worker.json diff --git a/examples/profiles/pxe-disk/profile.json b/examples/profiles/pxe-disk.json similarity index 100% rename from examples/profiles/pxe-disk/profile.json rename to examples/profiles/pxe-disk.json diff --git a/examples/profiles/pxe/profile.json b/examples/profiles/pxe.json similarity index 100% rename from examples/profiles/pxe/profile.json rename to examples/profiles/pxe.json