Skip to content

Commit

Permalink
Merge pull request #10 from alperencelik/containers
Browse files Browse the repository at this point in the history
Add container support
  • Loading branch information
alperencelik committed Nov 16, 2023
2 parents 418e7de + afe2c2f commit 0f181af
Show file tree
Hide file tree
Showing 22 changed files with 1,185 additions and 190 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ resources:
kind: VirtualMachineSnapshotPolicy
path: github.com/alperencelik/kubemox/api/proxmox/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: alperen.cloud
group: proxmox
kind: Container
path: github.com/alperencelik/kubemox/api/proxmox/v1alpha1
version: v1alpha1
version: "3"
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ helm install kubemox ./ -f values.yaml -n $NAMESPACE

Currently Kubemox brings five different CRDs for only VirtualMachines in Proxmox. These are `VirtualMachine`, `VirtualMachineSet`, `ManagedVirtualMachine`, `VirtualMachineSnapshot` and `VirtualMachineSnapshotPolicy`. You can use these CRDs to create and manage VirtualMachine(s) in Proxmox.

### VirtualMachine

`VirtualMachine` is a way to create new VirtualMachines in Proxmox via operator. You can create `VirtualMachine` resource and Kubemox will create it for you in Proxmox. `VirtualMachine` is also reconciled by the operator which means every change on `VirtualMachine` resource will be reflected to Proxmox as well.

`VirtualMachineSet` is a way to create multiple VirtualMachines in Proxmox. The relationship between `VirtualMachineSet` and `VirtualMachine` is similar to the relationship between `Deployment` and `Pod`. `VirtualMachineSet` creates multiple `VirtualMachine` resources and Kubemox will create them for you in Proxmox. You can only use `VirtualMachineSet` with templates. Creating multiple VirtualMachines from scratch is not supported yet.
Expand All @@ -40,6 +42,11 @@ Currently Kubemox brings five different CRDs for only VirtualMachines in Proxmox
`VirtualMachineSnapshot` is helping to create snapshots for `VirtualMachine` object. This object mostly considered for the milestone snapshots. This will create only one snapshot for the `VirtualMachine` object. Also deleting the `VirtualMachineSnapshot` object won't be deleting the snapshot from Proxmox since the current proxmox client the project uses doesn't have an implementation for deleting snapshots.

`VirtualMachineSnapshotPolicy` is helping to create snapshots for `VirtualMachine` object periodically. This object mostly considered for the scheduled snapshots. The schedule and the selectors that you specify matches with the `VirtualMachine` objects and according to the schedule it will create snapshots for those `VirtualMachine` objects. `VirtualMachineSnapshotPolicy` will be spawning `VirtualMachineSnapshot` objects for each `VirtualMachine` object that matches with the selectors. Also deleting the `VirtualMachineSnapshotPolicy` object also won't be deleting the snapshots from Proxmox but it will stop creating new `VirtualMachineSnapshot` objects for the `VirtualMachine` objects that matches with the selectors.

### Containers

`Container` is a way to create new Linux containers (LXC) in Proxmox via operator. You can create `Container` resource and Kubemox will create it for you in Proxmox. `Container` is also reconciled by the operator which means every change on `Container` resource will be reflected to Proxmox as well. `Container` object should be generated by other container template objects. This is a requirement that comes from Proxmox itself.

### Create a VirtualMachine

To create a VirtualMachine you can use the following `VirtualMachine` resource:
Expand Down Expand Up @@ -123,7 +130,33 @@ spec:
my-label: my-virtualmachine
```

To learn more about `VirtualMachine`, `VirtualMachineSet` and `VirtualMachineSnapshot` resources you can check `charts/kubemox/samples/`
### Create a Container

To create a Container you can use the following `Container` resource:

```yaml
apiVersion: proxmox.alperen.cloud/v1alpha1
kind: Container
metadata:
name: container-new
spec:
name: container-new
nodeName: lowtower
template:
# This template should be generated by other container template object
name: test-container
cores: 2
memory: 4096 # As MB
disk:
- storage: nvme
size: 50 # As GB
type: scsi
network:
- model: virtio
bridge: vmbr0
```

To learn more about `VirtualMachine`, `VirtualMachineSet`, `Container` and `VirtualMachineSnapshot` resources you can check `charts/kubemox/samples/`


## Developing
Expand Down
103 changes: 103 additions & 0 deletions api/proxmox/v1alpha1/container_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
Copyright 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

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

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// ContainerSpec defines the desired state of Container
type ContainerSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Name is the name of the Container
Name string `json:"name"`
// NodeName is the name of the target node of Proxmox
NodeName string `json:"nodeName"`
// TemplateSpec of the source Container
Template ContainerTemplate `json:"template,omitempty"`
// This field should be modified further
}

type ContainerTemplate struct {
// Name of the template
Name string `json:"name,omitempty"`
// Cores is the number of CPU cores
Cores int `json:"cores,omitempty"`
// Memory is the amount of memory in MB
Memory int `json:"memory,omitempty"`
// Disks is the list of disks
Disk []ContainerTemplateDisk `json:"disk,omitempty"`
// Networks is the list of networks
Network []ContainerTemplateNetwork `json:"network,omitempty"`
}

type ContainerTemplateDisk struct {
// Storage is the name of the storage
Storage string `json:"storage,omitempty"`
// Size is the size of the disk
Size int `json:"size,omitempty"`
// Type is the type of the disk
Type string `json:"type,omitempty"`
}

type ContainerTemplateNetwork struct {
// Name is the name of the network
Model string `json:"model,omitempty"`
// Bridge is the name of the bridge
Bridge string `json:"bridge,omitempty"`
}

// ContainerStatus defines the observed state of Container
type ContainerStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
State string `json:"state,omitempty"`
Node string `json:"node,omitempty"`
Name string `json:"name,omitempty"`
ID int `json:"id,omitempty"`
Uptime string `json:"uptime,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Container is the Schema for the containers API
type Container struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ContainerSpec `json:"spec,omitempty"`
Status ContainerStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// ContainerList contains a list of Container
type ContainerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Container `json:"items"`
}

func init() {
SchemeBuilder.Register(&Container{}, &ContainerList{})
}
145 changes: 145 additions & 0 deletions api/proxmox/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions charts/kubemox/samples/container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: proxmox.alperen.cloud/v1alpha1
kind: Container
metadata:
name: container-new
spec:
name: container-new
nodeName: lowtower
template:
# Name of the template to be cloned
name: test-container
cores: 2
memory: 4096 # As MB
disk:
- storage: nvme
size: 50 # As GB
type: scsi
network:
- model: virtio
bridge: vmbr0
34 changes: 34 additions & 0 deletions charts/kubemox/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,38 @@ rules:
verbs:
- get
- patch
- update
- apiGroups:
- proxmox.alperen.cloud
resources:
- containers/status
verbs:
- get
- patch
- update
- apiGroups:
- proxmox.alperen.cloud
resources:
- containers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- proxmox.alperen.cloud
resources:
- containers/finalizers
verbs:
- update
- apiGroups:
- proxmox.alperen.cloud
resources:
- containers/status
verbs:
- get
- patch
- update
Loading

0 comments on commit 0f181af

Please sign in to comment.