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

Commit

Permalink
Merge branch 'master' into cache-invalidation
Browse files Browse the repository at this point in the history
# Conflicts:
#	pkg/gitops/gitops.go
#	pkg/storage/cache.go
#	pkg/storage/manifest/rawstorage.go
#	pkg/storage/storage.go
  • Loading branch information
twelho committed Jul 22, 2019
2 parents c107e6e + 4ade869 commit 9c57e26
Show file tree
Hide file tree
Showing 66 changed files with 24,569 additions and 1,552 deletions.
54 changes: 38 additions & 16 deletions cmd/ignite-spawn/ignite-spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package main

import (
"fmt"
"net"
"os"
"path"

log "github.com/sirupsen/logrus"
api "github.com/weaveworks/ignite/pkg/apis/ignite"
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"github.com/weaveworks/ignite/pkg/constants"
"github.com/weaveworks/ignite/pkg/container"
"github.com/weaveworks/ignite/pkg/container/prometheus"
"github.com/weaveworks/ignite/pkg/dmlegacy"
"github.com/weaveworks/ignite/pkg/logs"
"github.com/weaveworks/ignite/pkg/providers"
patchutil "github.com/weaveworks/ignite/pkg/util/patch"
)

func main() {
Expand Down Expand Up @@ -51,28 +54,30 @@ func StartVM(co *options) error {
if err != nil {
return fmt.Errorf("network setup failed: %v", err)
}

// Serve DHCP requests for those interfaces
if err := container.StartDHCPServers(co.vm, dhcpIfaces); err != nil {
// This function returns the available IP addresses that are being
// served over DHCP now
ipAddrs, err := container.StartDHCPServers(co.vm, dhcpIfaces)
if err != nil {
return err
}

// Serve metrics over an unix socket in the VM's own directory
metricsSocket := path.Join(co.vm.ObjectPath(), constants.PROMETHEUS_SOCKET)
go prometheus.ServeMetrics(metricsSocket)

// VM state handling
// TODO: Use a .Patch here instead
if err := setState(co.vm, api.VMStateRunning); err != nil {
return fmt.Errorf("failed to update VM state: %v", err)
// Update the VM status and IP address information
if err := patchRunning(co.vm, ipAddrs); err != nil {
return fmt.Errorf("failed to patch VM state: %v", err)
}
defer setState(co.vm, api.VMStateStopped) // Performs a save, all other metadata-modifying defers need to be after this

// Patches the VM object to set state to stopped, and clear IP addresses
defer patchStopped(co.vm)

// Remove the snapshot overlay post-run, which also removes the detached backing loop devices
defer dmlegacy.DeactivateSnapshot(co.vm)

// Remove the IP addresses post-run
defer clearIPAddresses(co.vm)

// Remove the Prometheus socket post-run
defer os.Remove(metricsSocket)

Expand All @@ -84,13 +89,30 @@ func StartVM(co *options) error {
return nil
}

func setState(vm *api.VM, s api.VMState) error {
vm.Status.State = s

return providers.Client.VMs().Set(vm)
func patchRunning(vm *api.VM, ipAddrs []net.IP) error {
patch, err := patchutil.Create(vm, func(obj meta.Object) error {
patchVM := obj.(*api.VM)
patchVM.Status.State = api.VMStateRunning
patchVM.Status.IPAddresses = ipAddrs
return nil
})
if err != nil {
return err
}
// Perform the patch
return providers.Client.VMs().Patch(vm.GetUID(), patch)
}

func clearIPAddresses(vm *api.VM) {
vm.Status.IPAddresses = nil
// TODO: This currently relies on the ordering of a set of defers. Make this more robust in the future.
func patchStopped(vm *api.VM) error {
patch, err := patchutil.Create(vm, func(obj meta.Object) error {
patchVM := obj.(*api.VM)
patchVM.Status.State = api.VMStateStopped
patchVM.Status.IPAddresses = nil
return nil
})
if err != nil {
return err
}
// Perform the patch
return providers.Client.VMs().Patch(vm.GetUID(), patch)
}
2,840 changes: 1,420 additions & 1,420 deletions docs/dependencies.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.2.0 h1:l6N3VoaVzTncYYW+9yOz2LJJammFZGBO13sqgEhpy9g=
github.com/googleapis/gnostic v0.2.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e h1:XmA6L9IPRdUr28a+SK/oMchGgQy159wvzXA5tJ7l+40=
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e/go.mod h1:AFIo+02s+12CEg8Gzz9kzhCbmbq6JcKNrhHffCGA9z4=
Expand Down
4 changes: 3 additions & 1 deletion hack/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
)

func main() {
providers.Populate()
if err := providers.Populate(); err != nil {
log.Fatal(err)
}
ignite := cmd.NewIgniteCommand(os.Stdin, os.Stdout, os.Stderr)
if err := doc.GenMarkdownTree(ignite, "./docs/cli"); err != nil {
log.Fatal(err)
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/ignite/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

api "github.com/weaveworks/ignite/pkg/apis/ignite"
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"

"k8s.io/apimachinery/pkg/util/validation/field"
)

Expand Down
10 changes: 9 additions & 1 deletion pkg/client/client_dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"github.com/weaveworks/ignite/pkg/storage"
"github.com/weaveworks/ignite/pkg/storage/filterer"

"k8s.io/apimachinery/pkg/runtime/schema"
)

Expand All @@ -18,6 +17,9 @@ type DynamicClient interface {
Get(meta.UID) (meta.Object, error)
// Set saves an Object into the persistent storage
Set(meta.Object) error
// Patch performs a strategic merge patch on the object with
// the given UID, using the byte-encoded patch given
Patch(meta.UID, []byte) error
// Find returns an Object based on the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Find(filter filterer.BaseFilter) (meta.Object, error)
Expand Down Expand Up @@ -78,6 +80,12 @@ func (c *dynamicClient) Set(resource meta.Object) error {
return c.storage.Set(c.gvk, resource)
}

// Patch performs a strategic merge patch on the object with
// the given UID, using the byte-encoded patch given
func (c *dynamicClient) Patch(uid meta.UID, patch []byte) error {
return c.storage.Patch(c.gvk, uid, patch)
}

// Find returns an Object based on a given Filter
func (c *dynamicClient) Find(filter filterer.BaseFilter) (meta.Object, error) {
return c.filterer.Find(c.gvk, filter)
Expand Down
10 changes: 9 additions & 1 deletion pkg/client/client_resource_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"github.com/weaveworks/ignite/pkg/storage"
"github.com/weaveworks/ignite/pkg/storage/filterer"

"k8s.io/apimachinery/pkg/runtime/schema"
)

Expand All @@ -28,6 +27,9 @@ type ResourceClient interface {
Get(meta.UID) (*api.Resource, error)
// Set saves the given Resource into persistent storage
Set(*api.Resource) error
// Patch performs a strategic merge patch on the object with
// the given UID, using the byte-encoded patch given
Patch(meta.UID, []byte) error
// Find returns the Resource matching the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Find(filter filterer.BaseFilter) (*api.Resource, error)
Expand Down Expand Up @@ -120,6 +122,12 @@ func (c *resourceClient) Set(resource *api.Resource) error {
return c.storage.Set(c.gvk, resource)
}

// Patch performs a strategic merge patch on the object with
// the given UID, using the byte-encoded patch given
func (c *resourceClient) Patch(uid meta.UID, patch []byte) error {
return c.storage.Patch(c.gvk, uid, patch)
}

// Delete deletes the Resource from the storage
func (c *resourceClient) Delete(uid meta.UID) error {
log.Tracef("Client.Delete; UID: %q, GVK: %v", uid, c.gvk)
Expand Down
11 changes: 9 additions & 2 deletions pkg/client/zz_generated.client_image.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
Note: This file is autogenerated! Do not edit it manually!
Edit client_image_template.go instead, and run
Expand All @@ -15,7 +14,6 @@ import (
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"github.com/weaveworks/ignite/pkg/storage"
"github.com/weaveworks/ignite/pkg/storage/filterer"

"k8s.io/apimachinery/pkg/runtime/schema"
)

Expand All @@ -27,6 +25,9 @@ type ImageClient interface {
Get(meta.UID) (*api.Image, error)
// Set saves the given Image into persistent storage
Set(*api.Image) error
// Patch performs a strategic merge patch on the object with
// the given UID, using the byte-encoded patch given
Patch(meta.UID, []byte) error
// Find returns the Image matching the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Find(filter filterer.BaseFilter) (*api.Image, error)
Expand Down Expand Up @@ -119,6 +120,12 @@ func (c *imageClient) Set(image *api.Image) error {
return c.storage.Set(c.gvk, image)
}

// Patch performs a strategic merge patch on the object with
// the given UID, using the byte-encoded patch given
func (c *imageClient) Patch(uid meta.UID, patch []byte) error {
return c.storage.Patch(c.gvk, uid, patch)
}

// Delete deletes the Image from the storage
func (c *imageClient) Delete(uid meta.UID) error {
log.Tracef("Client.Delete; UID: %q, GVK: %v", uid, c.gvk)
Expand Down
11 changes: 9 additions & 2 deletions pkg/client/zz_generated.client_kernel.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
Note: This file is autogenerated! Do not edit it manually!
Edit client_kernel_template.go instead, and run
Expand All @@ -15,7 +14,6 @@ import (
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"github.com/weaveworks/ignite/pkg/storage"
"github.com/weaveworks/ignite/pkg/storage/filterer"

"k8s.io/apimachinery/pkg/runtime/schema"
)

Expand All @@ -27,6 +25,9 @@ type KernelClient interface {
Get(meta.UID) (*api.Kernel, error)
// Set saves the given Kernel into persistent storage
Set(*api.Kernel) error
// Patch performs a strategic merge patch on the object with
// the given UID, using the byte-encoded patch given
Patch(meta.UID, []byte) error
// Find returns the Kernel matching the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Find(filter filterer.BaseFilter) (*api.Kernel, error)
Expand Down Expand Up @@ -119,6 +120,12 @@ func (c *kernelClient) Set(kernel *api.Kernel) error {
return c.storage.Set(c.gvk, kernel)
}

// Patch performs a strategic merge patch on the object with
// the given UID, using the byte-encoded patch given
func (c *kernelClient) Patch(uid meta.UID, patch []byte) error {
return c.storage.Patch(c.gvk, uid, patch)
}

// Delete deletes the Kernel from the storage
func (c *kernelClient) Delete(uid meta.UID) error {
log.Tracef("Client.Delete; UID: %q, GVK: %v", uid, c.gvk)
Expand Down
11 changes: 9 additions & 2 deletions pkg/client/zz_generated.client_vm.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
Note: This file is autogenerated! Do not edit it manually!
Edit client_vm_template.go instead, and run
Expand All @@ -15,7 +14,6 @@ import (
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"github.com/weaveworks/ignite/pkg/storage"
"github.com/weaveworks/ignite/pkg/storage/filterer"

"k8s.io/apimachinery/pkg/runtime/schema"
)

Expand All @@ -27,6 +25,9 @@ type VMClient interface {
Get(meta.UID) (*api.VM, error)
// Set saves the given VM into persistent storage
Set(*api.VM) error
// Patch performs a strategic merge patch on the object with
// the given UID, using the byte-encoded patch given
Patch(meta.UID, []byte) error
// Find returns the VM matching the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Find(filter filterer.BaseFilter) (*api.VM, error)
Expand Down Expand Up @@ -119,6 +120,12 @@ func (c *vmClient) Set(vm *api.VM) error {
return c.storage.Set(c.gvk, vm)
}

// Patch performs a strategic merge patch on the object with
// the given UID, using the byte-encoded patch given
func (c *vmClient) Patch(uid meta.UID, patch []byte) error {
return c.storage.Patch(c.gvk, uid, patch)
}

// Delete deletes the VM from the storage
func (c *vmClient) Delete(uid meta.UID) error {
log.Tracef("Client.Delete; UID: %q, GVK: %v", uid, c.gvk)
Expand Down
12 changes: 7 additions & 5 deletions pkg/container/dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ import (
var leaseDuration, _ = time.ParseDuration(constants.DHCP_INFINITE_LEASE) // Infinite lease time

// StartDHCPServers starts multiple DHCP servers for the VM, one per interface
func StartDHCPServers(vm *api.VM, dhcpIfaces []DHCPInterface) error {
// It returns the IP addresses that the API object may post in .status, and a potential error
func StartDHCPServers(vm *api.VM, dhcpIfaces []DHCPInterface) ([]net.IP, error) {
// Generate the MAC addresses for the VM's adapters
macAddresses := make([]string, 0, len(dhcpIfaces))
if err := util.NewMAC(&macAddresses); err != nil {
return fmt.Errorf("failed to generate MAC addresses: %v", err)
return nil, fmt.Errorf("failed to generate MAC addresses: %v", err)
}

// Fetch the DNS servers given to the container
clientConfig, err := dns.ClientConfigFromFile("/etc/resolv.conf")
if err != nil {
return fmt.Errorf("failed to get DNS configuration: %v", err)
return nil, fmt.Errorf("failed to get DNS configuration: %v", err)
}

var ipAddrs []net.IP
for i := range dhcpIfaces {
dhcpIface := &dhcpIfaces[i]
// Set the VM hostname to the VM ID
Expand All @@ -43,7 +45,7 @@ func StartDHCPServers(vm *api.VM, dhcpIfaces []DHCPInterface) error {
dhcpIface.SetDNSServers(clientConfig.Servers)

// Register what IP address this VM has in the API object
vm.Status.IPAddresses = append(vm.Status.IPAddresses, dhcpIface.VMIPNet.IP)
ipAddrs = append(ipAddrs, dhcpIface.VMIPNet.IP)

go func() {
log.Infof("Starting DHCP server for interface %s (%s)\n", dhcpIface.Bridge, dhcpIface.VMIPNet.IP)
Expand All @@ -53,7 +55,7 @@ func StartDHCPServers(vm *api.VM, dhcpIfaces []DHCPInterface) error {
}()
}

return nil
return ipAddrs, nil
}

type DHCPInterface struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gitops
package gitdir

import (
"context"
Expand Down
Loading

0 comments on commit 9c57e26

Please sign in to comment.