Skip to content

Commit

Permalink
Migrate names to conform KubeVirt conventions
Browse files Browse the repository at this point in the history
Fixes #5

Signed-off-by: Kashif Khan <kashif.khan@est.tech>
  • Loading branch information
kashifest authored and starbops committed Jul 30, 2024
1 parent 7103c2d commit 896ac47
Show file tree
Hide file tree
Showing 58 changed files with 523 additions and 374 deletions.
12 changes: 6 additions & 6 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: zespre.com
domain: kubevirt.org
layout:
- go.kubebuilder.io/v4
projectName: kubebmc
repo: zespre.com/kubebmc
projectName: kubevirtbmc
repo: kubevirt.org/kubevirtbmc
resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: zespre.com
domain: kubevirt.org
group: virtualmachine
kind: KubeBMC
path: zespre.com/kubebmc/api/v1
kind: VirtualMachineBMC
path: kubevirt.org/kubevirtbmc/api/v1
version: v1
webhooks:
defaulting: true
Expand Down
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# KubeBMC
# VirtualMachineBMC

KubeBMC unleashes the power management for virtual machines on Kubernetes in a traditional way, i.e., [IPMI](https://www.intel.com.tw/content/www/tw/zh/products/docs/servers/ipmi/ipmi-second-gen-interface-spec-v2-rev1-1.html). This allows users to power on/off/reset and set the boot device for the VM. It was initially designed for [Tinkerbell](https://github.com/tinkerbell/tink)/[Seeder](https://github.com/harvester/seeder) to provision [KubeVirt](https://github.com/kubevirt/kubevirt) VMs, just like we did in the good old days.
VirtualMachineBMC unleashes the power management for virtual machines on Kubernetes in a traditional way, i.e., [IPMI](https://www.intel.com.tw/content/www/tw/zh/products/docs/servers/ipmi/ipmi-second-gen-interface-spec-v2-rev1-1.html). This allows users to power on/off/reset and set the boot device for the VM. It was initially designed for [Tinkerbell](https://github.com/tinkerbell/tink)/[Seeder](https://github.com/harvester/seeder) to provision [KubeVirt](https://github.com/kubevirt/kubevirt) VMs, just like we did in the good old days.

The project was born in [SUSE Hack Week 23](https://hackweek.opensuse.org/).

## Description

KubeBMC was inspired by [VirtualBMC](https://opendev.org/openstack/virtualbmc). The difference between them could be illustrated below:
VirtualMachineBMC was inspired by [VirtualBMC](https://opendev.org/openstack/virtualbmc). The difference between them could be illustrated below:

```mermaid
flowchart LR
client1[Client]
client2[Client]
BMC1[BMC]
VM[VM]
subgraph KubeBMC
subgraph VirtualMachineBMC
direction LR
client2-->|IPMI|kBMC-->|K8s API|VM
end
Expand All @@ -34,17 +34,17 @@ flowchart LR
- Providing BMC functionalities for bare-metal machines
- Providing BMC accessibility outside of the cluster via LoadBalancer or NodePort type of Services

KubeBMC consists of two components:
VirtualMachineBMC consists of two components:

- **kubebmc-controller**: A typical Kubernetes controller built with kubebuilder that reconciles on the KubeBMC, VirtualMachine, and Service objects
- **virtualmachinebmc-controller**: A typical Kubernetes controller built with kubebuilder that reconciles on the VirtualMachineBMC, VirtualMachine, and Service objects
- **kbmc**: A BMC simulator for serving IPMI and translating the requests to native Kubernetes API requests

Below is the workflow of KubeBMC when a VirtualMachine was created and booted up:
Below is the workflow of VirtualMachineBMC when a VirtualMachine was created and booted up:

```mermaid
flowchart LR
controller["kubebmc-controller"]
cr["kubebmc CR"]
controller["virtualmachinebmc-controller"]
cr["virtualmachinebmc CR"]
kbmc-pod["kbmc Pod"]
kbmc-svc["kbmc Service"]
controller-.->|watches|cr
Expand All @@ -57,10 +57,10 @@ flowchart LR
vm-->|creates|vmi
```

The KubeBMC CR (CustomResource):
The VirtualMachineBMC CR (CustomResource):

```go
type KubeBMCSpec struct {
type VirtualMachineBMCSpec struct {
// To authenticate who the user is.
// +optional
Username string `json:"username,omitempty"`
Expand All @@ -76,8 +76,8 @@ type KubeBMCSpec struct {
VirtualMachineName string `json:"vmName"`
}

// KubeBMCStatus defines the observed state of KubeBMC
type KubeBMCStatus struct {
// VirtualMachineBMCStatus defines the observed state of VirtualMachineBMC
type VirtualMachineBMCStatus struct {
// The listen IP address for the IPMI service.
ServiceIP string `json:"serviceIP"`

Expand All @@ -100,7 +100,7 @@ type KubeBMCStatus struct {
**Build and push the images to the location specified by `IMG`:**

```sh
make docker-build docker-push IMG=<some-registry>/kubebmc-controller:<tag>
make docker-build docker-push IMG=<some-registry>/virtualmachinebmc-controller:<tag>
make docker-build-kbmc docker-push IMG=<some-registry>/kbmc:<tag>
```

Expand Down Expand Up @@ -130,23 +130,23 @@ kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/
**Deploy the Manager to the cluster with the image specified by `IMG`:**

```sh
make deploy IMG=<some-registry>/kubebmc-controller:<tag>
make deploy IMG=<some-registry>/virtualmachinebmc-controller:<tag>
```

> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin privileges or be logged in as admin.
### To Start Using The KubeBMC
### To Start Using The VirtualMachineBMC

Create the KubeBMC object in the cluster:
Create the VirtualMachineBMC object in the cluster:

```sh
kubectl apply -f config/samples/virtualmachine_v1_kubebmc.yaml
kubectl apply -f config/samples/virtualmachine_v1_virtualmachinebmc.yaml
```

Though you can create the KubeBMC object manually, the corresponding KubeBMC object should be created automatically when the VirtualMachine object exists. It will then scaffold the `*-kbmc` Pod and Service object.
Though you can create the VirtualMachineBMC object manually, the corresponding VirtualMachineBMC object should be created automatically when the VirtualMachine object exists. It will then scaffold the `*-kbmc` Pod and Service object.

```sh
$ kubectl -n kubebmc-system get svc
$ kubectl -n virtualmachinebmc-system get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default-test-vm-kbmc ClusterIP 10.53.106.65 <none> 623/UDP 3h13m
```
Expand All @@ -160,11 +160,11 @@ $ kubectl run -it --rm ipmitool --image=mikeynap/ipmitool --command -- /bin/sh
Inside the Pod, you can for example turn on the VM via `ipmitool`:

```sh
$ ipmitool -I lan -U admin -P password -H default-test-vm-kbmc.kubebmc-system.svc.cluster.local power status
$ ipmitool -I lan -U admin -P password -H default-test-vm-kbmc.virtualmachinebmc-system.svc.cluster.local power status
Chassis Power is off
$ ipmitool -I lan -U admin -P password -H default-test-vm-kbmc.kubebmc-system.svc.cluster.local power on
$ ipmitool -I lan -U admin -P password -H default-test-vm-kbmc.virtualmachinebmc-system.svc.cluster.local power on
Chassis Power Control: Up/On
$ ipmitool -I lan -U admin -P password -H default-test-vm-kbmc.kubebmc-system.svc.cluster.local power status
$ ipmitool -I lan -U admin -P password -H default-test-vm-kbmc.virtualmachinebmc-system.svc.cluster.local power status
Chassis Power is on
```

Expand Down
4 changes: 2 additions & 2 deletions api/v1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

// Package v1 contains API Schema definitions for the virtualmachine v1 API group
// +kubebuilder:object:generate=true
// +groupName=virtualmachine.zespre.com
// +groupName=virtualmachine.kubevirt.org
package v1

import (
Expand All @@ -26,7 +26,7 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "virtualmachine.zespre.com", Version: "v1"}
GroupVersion = schema.GroupVersion{Group: "virtualmachine.kubevirt.org", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down
24 changes: 12 additions & 12 deletions api/v1/kubebmc_types.go → api/v1/virtualmachinebmc_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
// 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.

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

Expand All @@ -43,8 +43,8 @@ type KubeBMCSpec struct {
VirtualMachineName string `json:"vmName"`
}

// KubeBMCStatus defines the observed state of KubeBMC
type KubeBMCStatus struct {
// VirtualMachineBMCStatus defines the observed state of VirtualMachineBMC
type VirtualMachineBMCStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

Expand All @@ -58,24 +58,24 @@ type KubeBMCStatus struct {
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// KubeBMC is the Schema for the kubebmcs API
type KubeBMC struct {
// VirtualMachineBMC is the Schema for the virtualmachinebmcs API
type VirtualMachineBMC struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec KubeBMCSpec `json:"spec,omitempty"`
Status KubeBMCStatus `json:"status,omitempty"`
Spec VirtualMachineBMCSpec `json:"spec,omitempty"`
Status VirtualMachineBMCStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&KubeBMC{}, &KubeBMCList{})
SchemeBuilder.Register(&VirtualMachineBMC{}, &VirtualMachineBMCList{})
}
28 changes: 14 additions & 14 deletions api/v1/kubebmc_webhook.go → api/v1/virtualmachinebmc_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ import (
)

// log is for logging in this package.
var kubebmclog = logf.Log.WithName("kubebmc-resource")
var virtualmachinebmclog = logf.Log.WithName("virtualmachinebmc-resource")

// SetupWebhookWithManager will setup the manager to manage the webhooks
func (r *KubeBMC) SetupWebhookWithManager(mgr ctrl.Manager) error {
func (r *VirtualMachineBMC) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Complete()
}

// TODO(user): EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!

//+kubebuilder:webhook:path=/mutate-virtualmachine-zespre-com-v1-kubebmc,mutating=true,failurePolicy=fail,sideEffects=None,groups=virtualmachine.zespre.com,resources=kubebmcs,verbs=create;update,versions=v1,name=mkubebmc.kb.io,admissionReviewVersions=v1
//+kubebuilder:webhook:path=/mutate-virtualmachine-kubevirt-org-v1-virtualmachinebmc,mutating=true,failurePolicy=fail,sideEffects=None,groups=virtualmachine.kubevirt.org,resources=virtualmachinebmcs,verbs=create;update,versions=v1,name=mvirtualmachinebmc.kb.io,admissionReviewVersions=v1

var _ webhook.Defaulter = &KubeBMC{}
var _ webhook.Defaulter = &VirtualMachineBMC{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (r *KubeBMC) Default() {
kubebmclog.Info("default", "name", r.Name)
func (r *VirtualMachineBMC) Default() {
virtualmachinebmclog.Info("default", "name", r.Name)

// TODO(user): fill in your defaulting logic.
if r.Spec.Username == "" {
Expand All @@ -57,29 +57,29 @@ func (r *KubeBMC) Default() {
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:webhook:path=/validate-virtualmachine-zespre-com-v1-kubebmc,mutating=false,failurePolicy=fail,sideEffects=None,groups=virtualmachine.zespre.com,resources=kubebmcs,verbs=create;update,versions=v1,name=vkubebmc.kb.io,admissionReviewVersions=v1
//+kubebuilder:webhook:path=/validate-virtualmachine-kubevirt-org-v1-virtualmachinebmc,mutating=false,failurePolicy=fail,sideEffects=None,groups=virtualmachine.kubevirt.org,resources=virtualmachinebmcs,verbs=create;update,versions=v1,name=vvirtualmachinebmc.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &KubeBMC{}
var _ webhook.Validator = &VirtualMachineBMC{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *KubeBMC) ValidateCreate() (admission.Warnings, error) {
kubebmclog.Info("validate create", "name", r.Name)
func (r *VirtualMachineBMC) ValidateCreate() (admission.Warnings, error) {
virtualmachinebmclog.Info("validate create", "name", r.Name)

// TODO(user): fill in your validation logic upon object creation.
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *KubeBMC) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
kubebmclog.Info("validate update", "name", r.Name)
func (r *VirtualMachineBMC) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
virtualmachinebmclog.Info("validate update", "name", r.Name)

// TODO(user): fill in your validation logic upon object update.
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *KubeBMC) ValidateDelete() (admission.Warnings, error) {
kubebmclog.Info("validate delete", "name", r.Name)
func (r *VirtualMachineBMC) ValidateDelete() (admission.Warnings, error) {
virtualmachinebmclog.Info("validate delete", "name", r.Name)

// TODO(user): fill in your validation logic upon object deletion.
return nil, nil
Expand Down
2 changes: 1 addition & 1 deletion api/v1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var _ = BeforeSuite(func() {
})
Expect(err).NotTo(HaveOccurred())

err = (&KubeBMC{}).SetupWebhookWithManager(mgr)
err = (&VirtualMachineBMC{}).SetupWebhookWithManager(mgr)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:webhook
Expand Down
Loading

0 comments on commit 896ac47

Please sign in to comment.