Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
clean-polish-and-remove-cloudconfig (#117)
Browse files Browse the repository at this point in the history
* clean-polish-and-remove-cloudconfig

* fixes

* gofmt

* fix alpine version

* update Docker file

* updaye dns tmpl

* text changes

* move set-enviroment to files

* rename yochu

* restart always on finish installation

* remove restart from oneshot
  • Loading branch information
calvix committed Nov 29, 2017
1 parent 4b62ead commit 20f9bcb
Show file tree
Hide file tree
Showing 52 changed files with 757 additions and 2,178 deletions.
4 changes: 0 additions & 4 deletions .dockerignore.dist

This file was deleted.

16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

6 changes: 1 addition & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ RUN apk add --no-cache git ca-certificates dnsmasq
RUN mkdir -p /etc/mayu /var/lib/mayu /usr/lib/mayu
COPY mayu /mayu
COPY tftproot /usr/lib/mayu/tftproot
COPY static_html /usr/lib/mayu/static_html
COPY template_snippets /usr/lib/mayu/template_snippets
COPY files /usr/lib/mayu/files
COPY templates /usr/lib/mayu/templates
COPY config.yaml* /etc/mayu/

# enable if you want to add a post hook to github to store your cluster config
#RUN ssh-keyscan -H github.com > /etc/ssh/ssh_known_hosts

WORKDIR /usr/lib/mayu

RUN if [ ! -f /etc/mayu/config.yaml ]; then cp /etc/mayu/config.yaml.dist /etc/mayu/config.yaml; fi
Expand Down
21 changes: 5 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
[![CircleCI](https://circleci.com/gh/giantswarm/mayu.svg?&style=shield)](https://circleci.com/gh/giantswarm/mayu)
[![](https://godoc.org/github.com/giantswarm/mayu?status.svg)](http://godoc.org/github.com/giantswarm/mayu) [![](https://img.shields.io/docker/pulls/giantswarm/mayu.svg)](http://hub.docker.com/giantswarm/mayu)
[![Go Report Card](https://goreportcard.com/badge/github.com/giantswarm/mayu)](https://goreportcard.com/report/github.com/giantswarm/mayu)
![Docker Repository on Quay](https://quay.io/repository/giantswarm/mayu/status "Docker Repository on Quay")](https://quay.io/repository/giantswarm/mayu)
[![Docker Repository on Quay](https://quay.io/repository/giantswarm/mayu/status "Docker Repository on Quay")](https://quay.io/repository/giantswarm/mayu)

# Mayu
Mayu provides a set of mechanisms to bootstrap PXE-enabled bare metal nodes
that must follow a specific configuration with Container Linux. It sets up fleet
meta-data, and patched versions of fleet, etcd, and docker when using
[Yochu](https://github.com/giantswarm/yochu).
that must follow a specific configuration with Container Linux.

## Prerequisites

Expand All @@ -19,20 +17,11 @@ be configured to boot via ethernet by default and share a network segment with
the management node, so they get the PXE boot data from the management node on
DHCP request.

You need `dnsmasq` (>= 2.75) installed. Make sure dnsmasq is not running via an
init script or systemd after you installed it, as mayu starts its own
dnsmasq. In case you don't want to care about this, you maybe want to use the
docker image, where the dependency is built in. This eases the setup.

Further, mayu will keep track of all changes to the cluster by making git
commits. This is a feature for production systems and requires `git` (> 1.7.4)
installed. Use the `-no-git` flag when starting mayu to turn this feature off.

Developing Mayu requires the following tools to be installed.

* `wget`
* `go-bindata`
* `cpio`
* `wget
* `go-bindata
* `cpio`

## Getting Mayu

Expand Down
88 changes: 0 additions & 88 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ import (
"io/ioutil"
"net"
"net/http"
"strconv"
"strings"

mayuerror "github.com/giantswarm/mayu/error"
"github.com/giantswarm/mayu/hostmgr"
"github.com/giantswarm/mayu/httputil"
"github.com/giantswarm/mayu/pxemgr"
"gopkg.in/yaml.v2"
)

const contentType = "application/json"
Expand Down Expand Up @@ -59,28 +55,6 @@ func (c *Client) BootComplete(serial string, host hostmgr.Host) error {
return nil
}

// SetMetadata sets fleet metadata given by value for a node given by serial.
func (c *Client) SetMetadata(serial, value string) error {
data, err := json.Marshal(hostmgr.Host{
FleetMetadata: strings.Split(value, ","),
})
if err != nil {
return mayuerror.MaskAny(err)
}

resp, err := httputil.Put(fmt.Sprintf("%s://%s:%d/admin/host/%s/set_metadata", c.Scheme, c.Host, c.Port, serial), contentType, bytes.NewBuffer(data))
if err != nil {
return mayuerror.MaskAny(err)
}
defer resp.Body.Close()

if resp.StatusCode > 399 {
return mayuerror.MaskAny(fmt.Errorf("invalid status code '%d'", resp.StatusCode))
}

return nil
}

// SetProviderId sets the provider ID given by value for a node given by serial.
func (c *Client) SetProviderId(serial, value string) error {
data, err := json.Marshal(hostmgr.Host{
Expand Down Expand Up @@ -174,33 +148,6 @@ func (c *Client) SetState(serial, value string) error {
return nil
}

// SetCabinet sets the cabinet given by value for a node given by serial.
func (c *Client) SetCabinet(serial, value string) error {
cabinet, err := strconv.ParseUint(value, 10, 0)
if err != nil {
return mayuerror.MaskAny(err)
}

data, err := json.Marshal(hostmgr.Host{
Cabinet: uint(cabinet),
})
if err != nil {
return mayuerror.MaskAny(err)
}

resp, err := httputil.Put(fmt.Sprintf("%s://%s:%d/admin/host/%s/set_cabinet", c.Scheme, c.Host, c.Port, serial), contentType, bytes.NewBuffer(data))
if err != nil {
return mayuerror.MaskAny(err)
}
defer resp.Body.Close()

if resp.StatusCode > 399 {
return mayuerror.MaskAny(fmt.Errorf("invalid status code '%d'", resp.StatusCode))
}

return nil
}

// Override overrides a template properties such as docker_version, yochu_version, etc
func (c *Client) Override(serial, property, value string) error {
data, err := json.Marshal(hostmgr.Host{
Expand Down Expand Up @@ -281,38 +228,3 @@ func (c *Client) Status(serial string) (hostmgr.Host, error) {

return host, fmt.Errorf("host %s not found.", serial)
}

func (c *Client) GetConfig() (string, error) {
resp, err := http.Get(fmt.Sprintf("%s://%s:%d/admin/mayu_config", c.Scheme, c.Host, c.Port))
if err != nil {
return "", mayuerror.MaskAny(err)
}
defer resp.Body.Close()

if resp.StatusCode > 399 {
return "", mayuerror.MaskAny(fmt.Errorf("invalid status code '%d'", resp.StatusCode))
}

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", mayuerror.MaskAny(err)
}

return string(body), nil
}

func (c *Client) SetConfig(conf pxemgr.Configuration) error {
data, err := yaml.Marshal(conf)
if err != nil {
return mayuerror.MaskAny(err)
}
resp, err := httputil.Put(fmt.Sprintf("%s://%s:%d/admin/mayu_config", c.Scheme, c.Host, c.Port), "text/plain", bytes.NewBuffer(data))
if err != nil {
return mayuerror.MaskAny(err)
}
if resp.StatusCode > 399 {
return mayuerror.MaskAny(fmt.Errorf("invalid status code '%d'", resp.StatusCode))
}

return nil
}
160 changes: 0 additions & 160 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,86 +53,6 @@ func newClientAndServer(t *testing.T, handler http.Handler) (*client.Client, *ht
return client, ts
}

//
// Client.SetMetadata
//

// Test_Client_001 checks for Client.SetMetadata to provide proper information
// to the server as expected.
func Test_Client_001(t *testing.T) {
var response testResponse

newClient, ts := newClientAndServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
r.Body.Close()
if err != nil {
t.Fatal(err)
}

response = testResponse{
Body: body,
Header: r.Header,
Method: r.Method,
Path: r.URL.Path,
}

w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
}))
defer ts.Close()

err := newClient.SetMetadata("serial", "key1=value1,key2=value2")
if err != nil {
t.Fatalf("Client.SetMetadata returned error: %#v", err)
}

data, err := json.Marshal(hostmgr.Host{
FleetMetadata: []string{"key1=value1", "key2=value2"},
})
if err != nil {
t.Fatalf("json.Marshal returned error: %#v", err)
}
if string(response.Body) != string(data) {
t.Fatalf("expected response body to be '%s', got '%s'", string(response.Body), string(data))
}

assertHeader(t, response, "content-type", []string{"application/json"})
assertMethod(t, response, "PUT")
assertPath(t, response, fmt.Sprintf("/admin/host/%s/set_metadata", "serial"))
}

// Test_Client_002 checks for Client.SetMetadata to provide proper error
// information to the client as expected, when there are errors returned from
// the server.
func Test_Client_002(t *testing.T) {
newClient, ts := newClientAndServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("internal server error"))
}))
defer ts.Close()

err := newClient.SetMetadata("serial", "key1=value1,key2=value2")
if err == nil {
t.Fatalf("Client.SetMetadata NOT returned error")
}
}

// Test_Client_003 checks for Client.SetMetadata to provide proper error
// information to the client as expected, when there is no server running.
func Test_Client_003(t *testing.T) {
newClient, ts := newClientAndServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("internal server error"))
}))
// Immediatelly close the server.
ts.Close()

err := newClient.SetMetadata("serial", "key1=value1,key2=value2")
if err == nil {
t.Fatalf("Client.SetMetadata NOT returned error")
}
}

//
// Client.SetProviderId
//
Expand Down Expand Up @@ -293,86 +213,6 @@ func Test_Client_009(t *testing.T) {
}
}

//
// Client.SetCabinet
//

// Test_Client_010 checks for Client.SetCabinet to provide proper information
// to the server as expected.
func Test_Client_010(t *testing.T) {
var response testResponse

newClient, ts := newClientAndServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
r.Body.Close()
if err != nil {
t.Fatal(err)
}

response = testResponse{
Body: body,
Header: r.Header,
Method: r.Method,
Path: r.URL.Path,
}

w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
}))
defer ts.Close()

err := newClient.SetCabinet("serial", "101")
if err != nil {
t.Fatalf("Client.SetCabinet returned error: %#v", err)
}

data, err := json.Marshal(hostmgr.Host{
Cabinet: uint(101),
})
if err != nil {
t.Fatalf("json.Marshal returned error: %#v", err)
}
if string(response.Body) != string(data) {
t.Fatalf("expected response body to be '%s', got '%s'", string(response.Body), string(data))
}

assertHeader(t, response, "content-type", []string{"application/json"})
assertMethod(t, response, "PUT")
assertPath(t, response, fmt.Sprintf("/admin/host/%s/set_cabinet", "serial"))
}

// Test_Client_011 checks for Client.SetCabinet to provide proper error
// information to the client as expected, when there are errors returned from
// the server.
func Test_Client_011(t *testing.T) {
newClient, ts := newClientAndServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("internal server error"))
}))
defer ts.Close()

err := newClient.SetCabinet("serial", "101")
if err == nil {
t.Fatalf("Client.SetCabinet NOT returned error")
}
}

// Test_Client_012 checks for Client.SetCabinet to provide proper error
// information to the client as expected, when there is no server running.
func Test_Client_012(t *testing.T) {
newClient, ts := newClientAndServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("internal server error"))
}))
// Immediatelly close the server.
ts.Close()

err := newClient.SetCabinet("serial", "101")
if err == nil {
t.Fatalf("Client.SetCabinet NOT returned error")
}
}

//
// Client.List
//
Expand Down
Loading

0 comments on commit 20f9bcb

Please sign in to comment.