Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added microvm spec & repository #34

Merged
merged 2 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ linters:
- wsl
- tagliatelle
- exhaustivestruct
- godox # remove in the future
- godox # remove in the future
- gci
48 changes: 44 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
UNAME := $(shell uname -s)

# versions
# Versions
BUF_VERSION := v0.43.2

# Directories
REPO_ROOT := $(shell git rev-parse --show-toplevel)
BIN_DIR := bin
REIGNITED_CMD := cmd/reignited
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
TOOLS_SHARE_DIR := $(TOOLS_DIR)/share
Expand All @@ -22,19 +25,47 @@ $(TOOLS_BIN_DIR):
$(TOOLS_SHARE_DIR):
mkdir -p $@


$(BIN_DIR):
mkdir -p $@

# Binaries
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
GINKGO := $(TOOLS_BIN_DIR)/ginkgo
BUF := $(TOOLS_BIN_DIR)/buf
MOCKGEN:= $(TOOLS_BIN_DIR)/mockgen
CONVERSION_GEN := $(TOOLS_BIN_DIR)/conversion-gen
DEFAULTER_GEN := $(TOOLS_BIN_DIR)/defaulter-gen
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen

# Set --output-base for conversion-gen if we are not within GOPATH
ifneq ($(abspath $(REPO_ROOT)),$(shell go env GOPATH)/src/github/weaveworks/reignited)
GEN_OUTPUT_BASE := --output-base=$(REPO_ROOT)
else
export GOPATH := $(shell go env GOPATH)
endif

.DEFAULT_GOAL := help

##@ Generate

.PHONY: generate
generate: $(BUF) $(MOCKGEN) ## Generate code
generate: ## Generate code
$(MAKE) generate-go
## $(MAKE) generate-proto

.PHONY: generate-go
generate-go: $(MOCKGEN) $(CONVERSION_GEN) $(DEFAULTER_GEN) $(CONTROLLER_GEN) ## Generate Go Code
go generate ./...
go generate ./...
$(CONTROLLER_GEN) \
paths=./api/reignite/... \
object:headerFile=./hack/boilerplate.generatego.txt

.PHONY: generate-proto ## Generate protobuf/grpc code
generate-proto: $(BUF)
$(BUF) generate

##@ Linting

Expand All @@ -58,15 +89,24 @@ compile-e2e: # Test e2e compilation

##@ Tools binaries

$(GOLANGCI_LINT): hack/tools/go.mod # Get and build golangci-lint
$(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod # Get and build golangci-lint
cd $(TOOLS_DIR); go build -tags=tools -o $(subst hack/tools/,,$@) github.com/golangci/golangci-lint/cmd/golangci-lint

$(GINKGO): hack/tools/go.mod # Get and build gginkgo
$(GINKGO): $(TOOLS_DIR)/go.mod # Get and build gginkgo
cd $(TOOLS_DIR); go build -tags=tools -o $(subst hack/tools/,,$@) github.com/onsi/ginkgo/ginkgo

$(MOCKGEN): hack/tools/go.mod # Get and build mockgen
$(MOCKGEN): $(TOOLS_DIR)/go.mod # Get and build mockgen
cd $(TOOLS_DIR); go build -tags=tools -o $(subst hack/tools/,,$@) github.com/golang/mock/mockgen

$(CONVERSION_GEN): $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR); go build -tags=tools -o $(subst hack/tools/,,$@) k8s.io/code-generator/cmd/conversion-gen

$(DEFAULTER_GEN): $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR); go build -tags=tools -o $(subst hack/tools/,,$@) k8s.io/code-generator/cmd/defaulter-gen

$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(subst hack/tools/,,$@) sigs.k8s.io/controller-tools/cmd/controller-gen

BUF_TARGET := buf-Linux-x86_64.tar.gz

ifeq ($(OS), darwin)
Expand Down
20 changes: 20 additions & 0 deletions api/reignite/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Package v1alpha1 contains the API schema definitions for the v1alpha1 reginite API definitions.
//+kubebuilder:object:generate=true
//+groupName=reignite.weave.works
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "reignite.weave.works", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
44 changes: 44 additions & 0 deletions api/reignite/v1alpha1/microvm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// MicroVMSpec represents the specification of a microvm machine.
type MicroVMSpec struct {
// Provider is the name of the microvm provider. Defaults to firecracker.
Provider string `json:"provider,omitempty"`
// Kernel specifies the kernel and its argments to use.
Kernel Kernel `json:"kernel" validate:"required"`
// InitrdImage is an optional initial ramdisk to use.
InitrdImage ContainerImage `json:"initrd_image,omitempty"`
// VCPU specifies how many vcpu the machine will be allocated.
VCPU int64 `json:"vcpu" validate:"required,gt=0"`
// MemoryInMb is the amount of memory in megabytes that the machine will be allocated.
MemoryInMb int64 `json:"memory_inmb" validate:"required,gt=0"`
// NetworkInterfaces specifies the network interfaces attached to the machine.
NetworkInterfaces []NetworkInterface `json:"network_interfaces" validate:"required"`
richardcase marked this conversation as resolved.
Show resolved Hide resolved
// Volumes specifies the volumes to be attached to the the machine.
Volumes []Volume `json:"volumes" validate:"required"`
}

// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// MicroVM represents a microvm machine that is created via a provider.
type MicroVM struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// MachineSpec is the spec of the machine.
Spec MicroVMSpec `json:"spec,omitempty"`
}

// +kubebuilder:object:root=true

// MicroVMList represents a list on microvms.
type MicroVMList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []MicroVM `json:"items"`
}
86 changes: 86 additions & 0 deletions api/reignite/v1alpha1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package v1alpha1

// Kernel is the specification of the kernel and its arguments.
type Kernel struct {
// Image is the container image to use for the kernel.
Image ContainerImage `json:"image" validate:"required"`
// Filename is the name of the kernel filename in the container.
Filename string
// CmdLine are the args to use for the kernel cmdline.
CmdLine string `json:"cmdline,omitempty"`
}

// ContainerImage represents the address of a OCI image.
type ContainerImage string

// NetworkInterface represents a network interface for the microvm.
type NetworkInterface struct {
// AllowMetadataRequests indicates that this interface can be used for metadata requests.
// TODO: we may hide this within the firecracker plugin.
AllowMetadataRequests bool `json:"allow_mmds,omitempty"`
// GuestMAC allows the specifying of a specifi MAC address to use for the interface. If
// not supplied a autogenerated MAC address will be used.
GuestMAC string `json:"guest_mac,omitempty"`
// HostDeviceName is the name of the network interface to use from the host. This will be
// a tuntap or macvtap interface.
HostDeviceName string `json:"host_device_name" validate:"required"`
// GuestDeviceName is the name of the network interface to create in the microvm. If this
// is not supplied than a device name will be assigned automatically.
GuestDeviceName string `json:"guest_device_name,omitempty"`
// TODO: add rate limiting.
// TODO: add CNI.
}

// Volume represents a volume to be attached to a microvm machine.
type Volume struct {
// ID is the uinique identifier of the volume.
ID string `json:"id" validate:"required"`
// IsRoot specifies that the volume is to be used as the root volume. A machine
// must have a root volume.
IsRoot bool `json:"is_root" validate:"required"`
// IsReadOnly specifies that the volume is to be mounted readonly.
IsReadOnly bool `json:"is_read_only,omitempty"`
// MountPoint is the mount point for the volume in the microvm.
MountPoint string `json:"mount_point" validate:"required"`
// Source is where the volume will be sourced from.
Source VolumeSource `json:"source" validate:"required"`
// PartitionID is the uuid of the boot partition.
PartitionID string `json:"partition_id,omitempty"`
// Size is the size to resize this volume to.
Size VolumeSize `json:"size,omitempty"`
// TODO: add rate limiting.
}

// VolumeSource is the source of a volume. Based loosely on the volumes in Kubernetes Pod specs.
type VolumeSource struct {
// Container is used to specify a source of a volume as a OCI container.
Container *ContainerVolumeSource `json:"container,omitempty"`
// HostPath is used to specify a source of a volume as a file/device on the host.
HostPath *HostPathVolumeSource `json:"host_path,omitempty"`
// TODO: add CSI.
}

// ContainerDriveSource represents the details of a volume coming from a OCI image.
type ContainerVolumeSource struct {
// Image is the OCI image to use.
Image ContainerImage `json:"image" validate:"required"`
}

// HostPathVolumeSource represents the details of a volume coming from a file/device on the host.
type HostPathVolumeSource struct {
// Path on the host of the file/device to use as a source for a volume.
Path string
// Type is the type of file/device on the host.
Type HostPathType
}

// HostPathType is a type representing the different type of files/devices.
type HostPathType string

const (
// HostPathRawFile represents a file on the host to use as a source for a volume. It should be a raw fs.
HostPathRawFile HostPathType = "RawFile"
)

// DriVolumeSizeveSize is a type used to represent the size of a volume.
type VolumeSize uint64
Loading