From 1e095661ade3d447169f0cca2f1ea57d685eeca8 Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Mon, 22 May 2017 14:40:28 -0700 Subject: [PATCH] matchbox: Remove pixiecore handler and support * Pixiecore was deprecated in v0.5.0 and can be removed --- CHANGES.md | 2 + Documentation/machine-lifecycle.md | 2 +- Documentation/matchbox.md | 2 +- matchbox/http/pixiecore.go | 57 -------------------- matchbox/http/pixiecore_test.go | 86 ------------------------------ matchbox/http/server.go | 4 -- 6 files changed, 4 insertions(+), 149 deletions(-) delete mode 100644 matchbox/http/pixiecore.go delete mode 100644 matchbox/http/pixiecore_test.go diff --git a/CHANGES.md b/CHANGES.md index aff728e4..65302ad2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,8 @@ Notable changes between releases. ## Latest +* Remove pixiecore support (deprecated in v0.5.0) + ### Examples * Upgrade self-hosted Kubernetes cluster examples to v1.6.4 diff --git a/Documentation/machine-lifecycle.md b/Documentation/machine-lifecycle.md index d2239892..7bee2e6e 100644 --- a/Documentation/machine-lifecycle.md +++ b/Documentation/machine-lifecycle.md @@ -4,7 +4,7 @@ Physical machines [network boot](network-booting.md) in an network boot environment with DHCP/TFTP/DNS services or with [coreos/dnsmasq](../contrib/dnsmasq). -`matchbox` serves iPXE, GRUB, or Pixiecore boot configs via HTTP to machines based on Group selectors (e.g. UUID, MAC, region, etc.) and machine Profiles. Kernel and initrd images are fetched and booted with Ignition to install CoreOS. The "first boot" Ignition config if fetched and CoreOS is installed. +`matchbox` serves iPXE or GRUB configs via HTTP to machines based on Group selectors (e.g. UUID, MAC, region, etc.) and machine Profiles. Kernel and initrd images are fetched and booted with Ignition to install CoreOS. The "first boot" Ignition config if fetched and CoreOS is installed. CoreOS boots ("first boot" from disk) and runs Ignition to provision its disk with systemd units, files, keys, and more to become a cluster node. Systemd units may fetch metadata from a remote source if needed. diff --git a/Documentation/matchbox.md b/Documentation/matchbox.md index e9945c3b..4e6651ce 100644 --- a/Documentation/matchbox.md +++ b/Documentation/matchbox.md @@ -75,7 +75,7 @@ Profiles reference an Ignition config, Cloud-Config, and/or generic config by na } ``` -The `"boot"` settings will be used to render configs to network boot programs such as iPXE, GRUB, or Pixiecore. You may reference remote kernel and initrd assets or [local assets](#assets). +The `"boot"` settings will be used to render configs to network boot programs such as iPXE or GRUB. You may reference remote kernel and initrd assets or [local assets](#assets). To use Ignition, set the `coreos.config.url` kernel option to reference the `matchbox` [Ignition endpoint](api.md#ignition-config), which will render the `ignition_id` file. Be sure to add the `coreos.first_boot` option as well. diff --git a/matchbox/http/pixiecore.go b/matchbox/http/pixiecore.go deleted file mode 100644 index 217fffec..00000000 --- a/matchbox/http/pixiecore.go +++ /dev/null @@ -1,57 +0,0 @@ -package http - -import ( - "net/http" - "path/filepath" - - "context" - "github.com/Sirupsen/logrus" - - "github.com/coreos/matchbox/matchbox/server" - pb "github.com/coreos/matchbox/matchbox/server/serverpb" -) - -// pixiecoreHandler returns a handler that renders the boot config JSON for -// the requester, to implement the Pixiecore API specification. -// DEPRECATED -func (s *Server) pixiecoreHandler(core server.Server) ContextHandler { - fn := func(ctx context.Context, w http.ResponseWriter, req *http.Request) { - // pixiecore only provides a MAC address label - macAddr, err := parseMAC(filepath.Base(req.URL.Path)) - if err != nil { - s.logger.Errorf("unparseable MAC address: %v", err) - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - attrs := map[string]string{"mac": macAddr.String()} - - group, err := core.SelectGroup(ctx, &pb.SelectGroupRequest{Labels: attrs}) - if err != nil { - s.logger.WithFields(logrus.Fields{ - "label": macAddr, - }).Infof("No matching group") - http.NotFound(w, req) - return - } - - profile, err := core.ProfileGet(ctx, &pb.ProfileGetRequest{Id: group.Profile}) - if err != nil { - s.logger.WithFields(logrus.Fields{ - "label": macAddr, - "group": group.Id, - }).Infof("No profile named: %s", group.Profile) - http.NotFound(w, req) - return - } - - // match was successful - s.logger.WithFields(logrus.Fields{ - "label": macAddr, - "group": group.Id, - "profile": profile.Id, - }).Debug("Matched a Pixiecore config") - - s.renderJSON(w, profile.Boot) - } - return ContextHandlerFunc(fn) -} diff --git a/matchbox/http/pixiecore_test.go b/matchbox/http/pixiecore_test.go deleted file mode 100644 index f5be8308..00000000 --- a/matchbox/http/pixiecore_test.go +++ /dev/null @@ -1,86 +0,0 @@ -package http - -import ( - "net/http" - "net/http/httptest" - "testing" - - "context" - logtest "github.com/Sirupsen/logrus/hooks/test" - "github.com/stretchr/testify/assert" - - "github.com/coreos/matchbox/matchbox/server" - "github.com/coreos/matchbox/matchbox/storage/storagepb" - fake "github.com/coreos/matchbox/matchbox/storage/testfakes" -) - -func TestPixiecoreHandler(t *testing.T) { - fakeProfile := &storagepb.Profile{ - Id: "g1h2i3j4", - Boot: &storagepb.NetBoot{ - Kernel: "/image/kernel", - Initrd: []string{"/image/initrd_a", "/image/initrd_b"}, - Cmdline: map[string]string{ - "a": "b", - "c": "", - }, - }, - CloudId: "cloud-config.tmpl", - IgnitionId: "ignition.tmpl", - GenericId: "generic.tmpl", - } - store := &fake.FixedStore{ - Groups: map[string]*storagepb.Group{testGroupWithMAC.Id: testGroupWithMAC}, - Profiles: map[string]*storagepb.Profile{testGroupWithMAC.Profile: fakeProfile}, - } - logger, _ := logtest.NewNullLogger() - srv := NewServer(&Config{Logger: logger}) - c := server.NewServer(&server.Config{Store: store}) - h := srv.pixiecoreHandler(c) - w := httptest.NewRecorder() - req, _ := http.NewRequest("GET", "/"+validMACStr, nil) - h.ServeHTTP(context.Background(), w, req) - // assert that: - // - MAC address parameter is used for Group matching - // - the Profile's NetBoot config is rendered as Pixiecore JSON - expectedJSON := `{"kernel":"/image/kernel","initrd":["/image/initrd_a","/image/initrd_b"],"cmdline":{"a":"b","c":""}}` - assert.Equal(t, http.StatusOK, w.Code) - assert.Equal(t, jsonContentType, w.HeaderMap.Get(contentType)) - assert.Equal(t, expectedJSON, w.Body.String()) -} - -func TestPixiecoreHandler_InvalidMACAddress(t *testing.T) { - logger, _ := logtest.NewNullLogger() - srv := NewServer(&Config{Logger: logger}) - c := server.NewServer(&server.Config{Store: &fake.EmptyStore{}}) - h := srv.pixiecoreHandler(c) - w := httptest.NewRecorder() - req, _ := http.NewRequest("GET", "/", nil) - h.ServeHTTP(context.Background(), w, req) - assert.Equal(t, http.StatusBadRequest, w.Code) -} - -func TestPixiecoreHandler_NoMatchingGroup(t *testing.T) { - logger, _ := logtest.NewNullLogger() - srv := NewServer(&Config{Logger: logger}) - c := server.NewServer(&server.Config{Store: &fake.EmptyStore{}}) - h := srv.pixiecoreHandler(c) - w := httptest.NewRecorder() - req, _ := http.NewRequest("GET", "/"+validMACStr, nil) - h.ServeHTTP(context.Background(), w, req) - assert.Equal(t, http.StatusNotFound, w.Code) -} - -func TestPixiecoreHandler_NoMatchingProfile(t *testing.T) { - store := &fake.FixedStore{ - Groups: map[string]*storagepb.Group{fake.Group.Id: fake.Group}, - } - logger, _ := logtest.NewNullLogger() - srv := NewServer(&Config{Logger: logger}) - c := server.NewServer(&server.Config{Store: store}) - h := srv.pixiecoreHandler(c) - w := httptest.NewRecorder() - req, _ := http.NewRequest("GET", "/"+validMACStr, nil) - h.ServeHTTP(context.Background(), w, req) - assert.Equal(t, http.StatusNotFound, w.Code) -} diff --git a/matchbox/http/server.go b/matchbox/http/server.go index d03d657c..e80c4bd8 100644 --- a/matchbox/http/server.go +++ b/matchbox/http/server.go @@ -55,8 +55,6 @@ func (s *Server) HTTPHandler() http.Handler { mux.Handle("/boot.ipxe", chain(ipxeInspect())) mux.Handle("/boot.ipxe.0", chain(ipxeInspect())) mux.Handle("/ipxe", chain(s.selectProfile(s.core, s.ipxeHandler()))) - // Boot via Pixiecore - mux.Handle("/pixiecore/v1/boot/", chain(s.pixiecoreHandler(s.core))) // Ignition Config mux.Handle("/ignition", chain(s.selectGroup(s.core, s.ignitionHandler(s.core)))) // Cloud-Config @@ -75,7 +73,6 @@ func (s *Server) HTTPHandler() http.Handler { mux.Handle("/boot.ipxe.sig", signerChain(ipxeInspect())) mux.Handle("/boot.ipxe.0.sig", signerChain(ipxeInspect())) mux.Handle("/ipxe.sig", signerChain(s.selectProfile(s.core, s.ipxeHandler()))) - mux.Handle("/pixiecore/v1/boot.sig/", signerChain(s.pixiecoreHandler(s.core))) mux.Handle("/ignition.sig", signerChain(s.selectGroup(s.core, s.ignitionHandler(s.core)))) mux.Handle("/cloud.sig", signerChain(s.selectGroup(s.core, s.cloudHandler(s.core)))) mux.Handle("/generic.sig", signerChain(s.selectGroup(s.core, s.genericHandler(s.core)))) @@ -89,7 +86,6 @@ func (s *Server) HTTPHandler() http.Handler { mux.Handle("/boot.ipxe.asc", signerChain(ipxeInspect())) mux.Handle("/boot.ipxe.0.asc", signerChain(ipxeInspect())) mux.Handle("/ipxe.asc", signerChain(s.selectProfile(s.core, s.ipxeHandler()))) - mux.Handle("/pixiecore/v1/boot.asc/", signerChain(s.pixiecoreHandler(s.core))) mux.Handle("/ignition.asc", signerChain(s.selectGroup(s.core, s.ignitionHandler(s.core)))) mux.Handle("/cloud.asc", signerChain(s.selectGroup(s.core, s.cloudHandler(s.core)))) mux.Handle("/generic.asc", signerChain(s.selectGroup(s.core, s.genericHandler(s.core))))