Skip to content

Commit

Permalink
chore: update naming to conform kubevirt.io style
Browse files Browse the repository at this point in the history
Signed-off-by: Zespre Schmidt <starbops@zespre.com>
  • Loading branch information
starbops committed Jul 30, 2024
1 parent 81d4cfb commit 7d6abc7
Show file tree
Hide file tree
Showing 52 changed files with 309 additions and 455 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
matrix:
include:
- dockerfile: ./Dockerfile
image: starbops/kubebmc-controller
- dockerfile: ./Dockerfile.kbmc
image: starbops/kbmc
image: starbops/virtbmc-controller
- dockerfile: ./Dockerfile.virtbmc
image: starbops/virtbmc
steps:
- name: Check out repository code
uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
matrix:
include:
- dockerfile: ./Dockerfile
image: starbops/kubebmc-controller
- dockerfile: ./Dockerfile.kbmc
image: starbops/kbmc
image: starbops/virtbmc-controller
- dockerfile: ./Dockerfile.virtbmc
image: starbops/virtbmc
steps:
- name: Check out repository code
uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
matrix:
include:
- dockerfile: ./Dockerfile
image: starbops/kubebmc-controller
- dockerfile: ./Dockerfile.kbmc
image: starbops/kbmc
image: starbops/virtbmc-controller
- dockerfile: ./Dockerfile.virtbmc
image: starbops/virtbmc
steps:
- name: Check out repository code
uses: actions/checkout@v4
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile.kbmc → Dockerfile.virtbmc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Build the virt-bmc binary
# Build the virtbmc 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/virt-bmc/main.go cmd/virt-bmc/main.go
COPY cmd/virtbmc/main.go cmd/virtbmc/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 virt-bmc cmd/virt-bmc/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o virtbmc cmd/virtbmc/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/virt-bmc .
COPY --from=builder /workspace/virtbmc .
USER 65532:65532

ENTRYPOINT ["/virt-bmc"]
ENTRYPOINT ["/virtbmc"]
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/virt-bmc cmd/virt-bmc/main.go
go build -o bin/virtbmc cmd/virtbmc/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-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-build-virtbmc
docker-build-virtbmc: ## Builder docker image with the virtbmc binary.
$(CONTAINER_TOOL) build -t ${IMG} --build-arg TARGETARCH=amd64 -f Dockerfile.virtbmc .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
Expand Down
8 changes: 4 additions & 4 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: kubevirt.org
domain: kubevirt.io
layout:
- go.kubebuilder.io/v4
projectName: kubevirtbmc
repo: kubevirt.org/kubevirtbmc
repo: kubevirt.io/kubevirtbmc
resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: kubevirt.org
domain: kubevirt.io
group: virtualmachine
kind: VirtualMachineBMC
path: kubevirt.org/kubevirtbmc/api/v1
path: kubevirt.io/kubevirtbmc/api/v1
version: v1
webhooks:
defaulting: true
Expand Down
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ flowchart LR

KubeVirtBMC consists of two components:

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

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

```mermaid
flowchart LR
controller["virt-bmc-controller"]
controller["virtbmc-controller"]
cr["virtualmachinebmc CR"]
virt-bmc-pod["virt-bmc Pod"]
virt-bmc-svc["virt-bmc Service"]
virtbmc-pod["virtbmc Pod"]
virtbmc-svc["virtbmc Service"]
controller-.->|watches|cr
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
cr-.->|owns|virtbmc-svc
cr-.->|owns|virtbmc-pod
client--->|IPMI|virtbmc-svc
virtbmc-svc-->virtbmc-pod
virtbmc-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>/virt-bmc-controller:<tag>
make docker-build-virt-bmc docker-push IMG=<some-registry>/virt-bmc:<tag>
make docker-build docker-push IMG=<some-registry>/virtbmc-controller:<tag>
make docker-build-virtbmc docker-push IMG=<some-registry>/virtbmc:<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>/virt-bmc-controller:<tag>
make deploy IMG=<some-registry>/virtbmc-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 `*-virt-bmc` 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 `*-virtbmc` Pod and Service object.

```sh
$ kubectl -n kubevirtbmc-system get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default-test-vm-virt-bmc ClusterIP 10.53.106.65 <none> 623/UDP 3h13m
default-test-vm-virtbmc 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-virt-bmc.kubevirtbmc-system.svc.cluster.local power status
$ ipmitool -I lan -U admin -P password -H default-test-vm-virtbmc.kubevirtbmc-system.svc.cluster.local power status
Chassis Power is off
$ ipmitool -I lan -U admin -P password -H default-test-vm-virt-bmc.kubevirtbmc-system.svc.cluster.local power on
$ ipmitool -I lan -U admin -P password -H default-test-vm-virtbmc.kubevirtbmc-system.svc.cluster.local power on
Chassis Power Control: Up/On
$ ipmitool -I lan -U admin -P password -H default-test-vm-virt-bmc.kubevirtbmc-system.svc.cluster.local power status
$ ipmitool -I lan -U admin -P password -H default-test-vm-virtbmc.kubevirtbmc-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.kubevirt.org
// +groupName=virtualmachine.kubevirt.io
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.kubevirt.org", Version: "v1"}
GroupVersion = schema.GroupVersion{Group: "virtualmachine.kubevirt.io", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down
4 changes: 2 additions & 2 deletions api/v1/virtualmachinebmc_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (r *VirtualMachineBMC) SetupWebhookWithManager(mgr ctrl.Manager) error {

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

//+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
//+kubebuilder:webhook:path=/mutate-virtualmachine-kubevirt-io-v1-virtualmachinebmc,mutating=true,failurePolicy=fail,sideEffects=None,groups=virtualmachine.kubevirt.io,resources=virtualmachinebmcs,verbs=create;update,versions=v1,name=mvirtualmachinebmc.kb.io,admissionReviewVersions=v1

var _ webhook.Defaulter = &VirtualMachineBMC{}

Expand All @@ -57,7 +57,7 @@ func (r *VirtualMachineBMC) Default() {
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+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
//+kubebuilder:webhook:path=/validate-virtualmachine-kubevirt-io-v1-virtualmachinebmc,mutating=false,failurePolicy=fail,sideEffects=None,groups=virtualmachine.kubevirt.io,resources=virtualmachinebmcs,verbs=create;update,versions=v1,name=vvirtualmachinebmc.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &VirtualMachineBMC{}

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

virtualmachinev1 "kubevirt.org/kubevirtbmc/api/v1"
"kubevirt.org/kubevirtbmc/internal/controller/service"
"kubevirt.org/kubevirtbmc/internal/controller/virtualmachine"
"kubevirt.org/kubevirtbmc/internal/controller/virtualmachinebmc"
virtualmachinev1 "kubevirt.io/kubevirtbmc/api/v1"
ctlservice "kubevirt.io/kubevirtbmc/internal/controller/service"
ctlvirtualmachine "kubevirt.io/kubevirtbmc/internal/controller/virtualmachine"
ctlvirtualmachinebmc "kubevirt.io/kubevirtbmc/internal/controller/virtualmachinebmc"

// clischeme "kubevirt.org/kubevirtbmc/pkg/generated/clientset/versioned/scheme"
kubevirtv1 "kubevirt.io/api/core/v1"
//+kubebuilder:scaffold:imports
)
Expand Down Expand Up @@ -76,7 +75,7 @@ func main() {
Metrics: metricsserver.Options{BindAddress: metricsAddr},
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "5e66b2cf.kubevirt.org",
LeaderElectionID: "5e66b2cf.kubevirt.io",
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
Expand All @@ -94,21 +93,21 @@ func main() {
os.Exit(1)
}

if err = (&virtualmachinebmc.VirtualMachineBMCReconciler{
if err = (&ctlvirtualmachinebmc.VirtualMachineBMCReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "VirtualMachineBMC")
os.Exit(1)
}
if err = (&service.ServiceReconciler{
if err = (&ctlservice.ServiceReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Service")
os.Exit(1)
}
if err = (&virtualmachine.VirtualMachineReconciler{
if err = (&ctlvirtualmachine.VirtualMachineReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
Expand Down
18 changes: 9 additions & 9 deletions cmd/kbmc/main.go → cmd/virtbmc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (

"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"kubevirt.org/virtualmachinebmc/pkg/virt-bmc"
"kubevirt.org/kubevirtbmc/pkg/kbmc"
"kubevirt.io/kubevirtbmc/pkg/virtbmc"
)

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

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

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

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

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

return virt-bmc.Run()
return virtBMC.Run()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
name: virtualmachinebmcs.virtualmachine.kubevirt.org
name: virtualmachinebmcs.virtualmachine.kubevirt.io
spec:
group: virtualmachine.kubevirt.org
group: virtualmachine.kubevirt.io
names:
kind: VirtualMachineBMC
listKind: VirtualMachineBMCList
Expand Down
Loading

0 comments on commit 7d6abc7

Please sign in to comment.