Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kashif Khan <kashif.khan@est.tech>
  • Loading branch information
kashifest authored and starbops committed Jul 30, 2024
1 parent 896ac47 commit 81d4cfb
Show file tree
Hide file tree
Showing 39 changed files with 144 additions and 157 deletions.
10 changes: 5 additions & 5 deletions Dockerfile.kbmc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Build the kbmc binary
# Build the virt-bmc binary
FROM golang:1.20 as builder
ARG TARGETOS
ARG TARGETARCH
Expand All @@ -12,21 +12,21 @@ COPY go.sum go.sum
RUN go mod download

# Copy the go source
COPY cmd/kbmc/main.go cmd/kbmc/main.go
COPY cmd/virt-bmc/main.go cmd/virt-bmc/main.go
COPY pkg/ pkg/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o kbmc cmd/kbmc/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o virt-bmc cmd/virt-bmc/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/kbmc .
COPY --from=builder /workspace/virt-bmc .
USER 65532:65532

ENTRYPOINT ["/kbmc"]
ENTRYPOINT ["/virt-bmc"]
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/controller/main.go
go build -o bin/kbmc cmd/kbmc/main.go
go build -o bin/virt-bmc cmd/virt-bmc/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
Expand All @@ -110,9 +110,9 @@ run: manifests generate fmt vet ## Run a controller from your host.
docker-build: ## Build docker image with the manager.
$(CONTAINER_TOOL) build -t ${IMG} .

.PHONY: docker-build-kbmc
docker-build-kbmc: ## Builder docker image with the kbmc binary.
$(CONTAINER_TOOL) build -t ${IMG} --build-arg TARGETARCH=amd64 -f Dockerfile.kbmc .
.PHONY: docker-build-virt-bmc
docker-build-virt-bmc: ## Builder docker image with the virt-bmc binary.
$(CONTAINER_TOOL) build -t ${IMG} --build-arg TARGETARCH=amd64 -f Dockerfile.virt-bmc .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
Expand Down
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# VirtualMachineBMC
# KubeVirtBMC

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.
KubeVirtBMC 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

VirtualMachineBMC was inspired by [VirtualBMC](https://opendev.org/openstack/virtualbmc). The difference between them could be illustrated below:
KubeVirtBMC 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 VirtualMachineBMC
subgraph KubeVirtBMC
direction LR
client2-->|IPMI|kBMC-->|K8s API|VM
client2-->|IPMI|virtBMC-->|K8s API|VM
end
subgraph VirtualBMC
direction LR
Expand All @@ -34,25 +34,25 @@ flowchart LR
- Providing BMC functionalities for bare-metal machines
- Providing BMC accessibility outside of the cluster via LoadBalancer or NodePort type of Services

VirtualMachineBMC consists of two components:
KubeVirtBMC consists of two components:

- **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
- **virt-bmc-controller**: A typical Kubernetes controller built with kubebuilder that reconciles on the VirtualMachineBMC, VirtualMachine, and Service objects
- **virt-bmc**: A BMC simulator for serving IPMI and translating the requests to native Kubernetes API requests

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

```mermaid
flowchart LR
controller["virtualmachinebmc-controller"]
controller["virt-bmc-controller"]
cr["virtualmachinebmc CR"]
kbmc-pod["kbmc Pod"]
kbmc-svc["kbmc Service"]
virt-bmc-pod["virt-bmc Pod"]
virt-bmc-svc["virt-bmc Service"]
controller-.->|watches|cr
cr-.->|owns|kbmc-svc
cr-.->|owns|kbmc-pod
client--->|IPMI|kbmc-svc
kbmc-svc-->kbmc-pod
kbmc-pod-->|HTTP|apiserver
cr-.->|owns|virt-bmc-svc
cr-.->|owns|virt-bmc-pod
client--->|IPMI|virt-bmc-svc
virt-bmc-svc-->virt-bmc-pod
virt-bmc-pod-->|HTTP|apiserver
apiserver-->|modifies|vm
vm-->|creates|vmi
```
Expand Down Expand Up @@ -100,8 +100,8 @@ type VirtualMachineBMCStatus struct {
**Build and push the images to the location specified by `IMG`:**

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

> **NOTE:** These images ought to be published in the personal registry you specified. And it is required to have access to pull the images from the working environment. Make sure you have the proper permission to the registry if the above commands don’t work.
Expand Down Expand Up @@ -130,7 +130,7 @@ 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>/virtualmachinebmc-controller:<tag>
make deploy IMG=<some-registry>/virt-bmc-controller:<tag>
```

> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin privileges or be logged in as admin.
Expand All @@ -143,12 +143,12 @@ Create the VirtualMachineBMC object in the cluster:
kubectl apply -f config/samples/virtualmachine_v1_virtualmachinebmc.yaml
```

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.
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 `*-virt-bmc` Pod and Service object.

```sh
$ kubectl -n virtualmachinebmc-system get svc
$ kubectl -n kubevirtbmc-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
default-test-vm-virt-bmc ClusterIP 10.53.106.65 <none> 623/UDP 3h13m
```

To access the VM's BMC, you need to be in the cluster network. Run a Pod that comes with `ipmitool` built in:
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.virtualmachinebmc-system.svc.cluster.local power status
$ ipmitool -I lan -U admin -P password -H default-test-vm-virt-bmc.kubevirtbmc-system.svc.cluster.local power status
Chassis Power is off
$ ipmitool -I lan -U admin -P password -H default-test-vm-kbmc.virtualmachinebmc-system.svc.cluster.local power on
$ ipmitool -I lan -U admin -P password -H default-test-vm-virt-bmc.kubevirtbmc-system.svc.cluster.local power on
Chassis Power Control: Up/On
$ ipmitool -I lan -U admin -P password -H default-test-vm-kbmc.virtualmachinebmc-system.svc.cluster.local power status
$ ipmitool -I lan -U admin -P password -H default-test-vm-virt-bmc.kubevirtbmc-system.svc.cluster.local power status
Chassis Power is on
```

Expand Down
10 changes: 5 additions & 5 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

virtualmachinev1 "kubevirt.org/virtualmachinebmc/api/v1"
"kubevirt.org/virtualmachinebmc/internal/controller/service"
"kubevirt.org/virtualmachinebmc/internal/controller/virtualmachine"
"kubevirt.org/virtualmachinebmc/internal/controller/virtualmachinebmc"
virtualmachinev1 "kubevirt.org/kubevirtbmc/api/v1"
"kubevirt.org/kubevirtbmc/internal/controller/service"
"kubevirt.org/kubevirtbmc/internal/controller/virtualmachine"
"kubevirt.org/kubevirtbmc/internal/controller/virtualmachinebmc"

// clischeme "kubevirt.org/virtualmachinebmc/pkg/generated/clientset/versioned/scheme"
// clischeme "kubevirt.org/kubevirtbmc/pkg/generated/clientset/versioned/scheme"
kubevirtv1 "kubevirt.io/api/core/v1"
//+kubebuilder:scaffold:imports
)
Expand Down
19 changes: 9 additions & 10 deletions cmd/kbmc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (

"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"

"kubevirt.org/virtualmachinebmc/pkg/kbmc"
)
"kubevirt.org/virtualmachinebmc/pkg/virt-bmc"
"kubevirt.org/kubevirtbmc/pkg/kbmc"

func main() {
var options kbmc.Options
var options virt-bmc.Options

app := &cli.App{
Name: "kbmc",
Name: "virt-bmc",
Usage: "receive ipmi requests and traslate them into native k8s api calls",
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down Expand Up @@ -53,8 +52,8 @@ func main() {
}
}

func run(ctx context.Context, options kbmc.Options) error {
logrus.Info("Starting kBMC")
func run(ctx context.Context, options virt-bmc.Options) error {
logrus.Info("Starting virt-bmc")

// TODO: check kubeconfig flag instead
// check whether we're in a cluster or not
Expand All @@ -78,10 +77,10 @@ func run(ctx context.Context, options kbmc.Options) error {
os.Exit(2)
}()

kbmc, err := kbmc.NewKBMC(ctx, options, ok)
virt-bmc, err := virt-bmc.Newvirt-bmc(ctx, options, ok)
if err != nil {
return fmt.Errorf("failed to create kbmc server: %v", err)
return fmt.Errorf("failed to create virt-bmc server: %v", err)
}

return kbmc.Run()
return virt-bmc.Run()
}
8 changes: 4 additions & 4 deletions config/certmanager/certificate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ metadata:
app.kubernetes.io/name: certificate
app.kubernetes.io/instance: serving-cert
app.kubernetes.io/component: certificate
app.kubernetes.io/created-by: virtualmachinebmc
app.kubernetes.io/part-of: virtualmachinebmc
app.kubernetes.io/created-by: kubevirtbmc
app.kubernetes.io/part-of: kubevirtbmc
app.kubernetes.io/managed-by: kustomize
name: selfsigned-issuer
namespace: system
Expand All @@ -23,8 +23,8 @@ metadata:
app.kubernetes.io/name: certificate
app.kubernetes.io/instance: serving-cert
app.kubernetes.io/component: certificate
app.kubernetes.io/created-by: virtualmachinebmc
app.kubernetes.io/part-of: virtualmachinebmc
app.kubernetes.io/created-by: kubevirtbmc
app.kubernetes.io/part-of: kubevirtbmc
app.kubernetes.io/managed-by: kustomize
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
namespace: system
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Adds namespace to all resources.
namespace: virtualmachinebmc-system
namespace: kubevirtbmc-system

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# "wordpress" becomes "alices-wordpress".
# Note that it should also match with the prefix (text before '-') of the namespace
# field above.
namePrefix: virtualmachinebmc-
namePrefix: kubevirtbmc-

# Labels to add to all resources and selectors.
#labels:
Expand All @@ -18,7 +18,7 @@ resources:
- ../crd
- ../rbac
- ../manager
- ../kbmc
- ../virt-bmc
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
- ../webhook
Expand Down
8 changes: 4 additions & 4 deletions config/default/webhookcainjection_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ metadata:
app.kubernetes.io/name: mutatingwebhookconfiguration
app.kubernetes.io/instance: mutating-webhook-configuration
app.kubernetes.io/component: webhook
app.kubernetes.io/created-by: virtualmachinebmc
app.kubernetes.io/part-of: virtualmachinebmc
app.kubernetes.io/created-by: kubevirtbmc
app.kubernetes.io/part-of: kubevirtbmc
app.kubernetes.io/managed-by: kustomize
name: mutating-webhook-configuration
annotations:
Expand All @@ -21,8 +21,8 @@ metadata:
app.kubernetes.io/name: validatingwebhookconfiguration
app.kubernetes.io/instance: validating-webhook-configuration
app.kubernetes.io/component: webhook
app.kubernetes.io/created-by: virtualmachinebmc
app.kubernetes.io/part-of: virtualmachinebmc
app.kubernetes.io/created-by: kubevirtbmc
app.kubernetes.io/part-of: kubevirtbmc
app.kubernetes.io/managed-by: kustomize
name: validating-webhook-configuration
annotations:
Expand Down
12 changes: 0 additions & 12 deletions config/kbmc/service_account.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: starbops/virtualmachinebmc-controller
newName: starbops/virt-bmc-controller
newTag: dev
8 changes: 4 additions & 4 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ metadata:
app.kubernetes.io/name: namespace
app.kubernetes.io/instance: system
app.kubernetes.io/component: manager
app.kubernetes.io/created-by: virtualmachinebmc
app.kubernetes.io/part-of: virtualmachinebmc
app.kubernetes.io/created-by: kubevirtbmc
app.kubernetes.io/part-of: kubevirtbmc
app.kubernetes.io/managed-by: kustomize
name: system
---
Expand All @@ -21,8 +21,8 @@ metadata:
app.kubernetes.io/name: deployment
app.kubernetes.io/instance: controller-manager
app.kubernetes.io/component: manager
app.kubernetes.io/created-by: virtualmachinebmc
app.kubernetes.io/part-of: virtualmachinebmc
app.kubernetes.io/created-by: kubevirtbmc
app.kubernetes.io/part-of: kubevirtbmc
app.kubernetes.io/managed-by: kustomize
spec:
selector:
Expand Down
4 changes: 2 additions & 2 deletions config/prometheus/monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ metadata:
app.kubernetes.io/name: servicemonitor
app.kubernetes.io/instance: controller-manager-metrics-monitor
app.kubernetes.io/component: metrics
app.kubernetes.io/created-by: virtualmachinebmc
app.kubernetes.io/part-of: virtualmachinebmc
app.kubernetes.io/created-by: kubevirtbmc
app.kubernetes.io/part-of: kubevirtbmc
app.kubernetes.io/managed-by: kustomize
name: controller-manager-metrics-monitor
namespace: system
Expand Down
4 changes: 2 additions & 2 deletions config/rbac/auth_proxy_client_clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ metadata:
app.kubernetes.io/name: clusterrole
app.kubernetes.io/instance: metrics-reader
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/created-by: virtualmachinebmc
app.kubernetes.io/part-of: virtualmachinebmc
app.kubernetes.io/created-by: kubevirtbmc
app.kubernetes.io/part-of: kubevirtbmc
app.kubernetes.io/managed-by: kustomize
name: metrics-reader
rules:
Expand Down
4 changes: 2 additions & 2 deletions config/rbac/auth_proxy_role_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ metadata:
app.kubernetes.io/name: clusterrolebinding
app.kubernetes.io/instance: proxy-rolebinding
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/created-by: virtualmachinebmc
app.kubernetes.io/part-of: virtualmachinebmc
app.kubernetes.io/created-by: kubevirtbmc
app.kubernetes.io/part-of: kubevirtbmc
app.kubernetes.io/managed-by: kustomize
name: proxy-rolebinding
roleRef:
Expand Down
4 changes: 2 additions & 2 deletions config/rbac/auth_proxy_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ metadata:
app.kubernetes.io/name: service
app.kubernetes.io/instance: controller-manager-metrics-service
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/created-by: virtualmachinebmc
app.kubernetes.io/part-of: virtualmachinebmc
app.kubernetes.io/created-by: kubevirtbmc
app.kubernetes.io/part-of: kubevirtbmc
app.kubernetes.io/managed-by: kustomize
name: controller-manager-metrics-service
namespace: system
Expand Down
4 changes: 2 additions & 2 deletions config/rbac/kubebmc_editor_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ metadata:
app.kubernetes.io/name: clusterrole
app.kubernetes.io/instance: virtualmachinebmc-editor-role
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: virtualmachinebmc
app.kubernetes.io/part-of: virtualmachinebmc
app.kubernetes.io/created-by: kubevirtbmc
app.kubernetes.io/part-of: kubevirtbmc
app.kubernetes.io/managed-by: kustomize
name: virtualmachinebmc-editor-role
rules:
Expand Down
Loading

0 comments on commit 81d4cfb

Please sign in to comment.