From 7d6abc7d9f8e1b111d7ae810adf624fe2562e478 Mon Sep 17 00:00:00 2001 From: Zespre Schmidt Date: Tue, 30 Jul 2024 12:34:51 +0800 Subject: [PATCH] chore: update naming to conform kubevirt.io style Signed-off-by: Zespre Schmidt --- .github/workflows/main.yml | 6 +- .github/workflows/pull-request.yaml | 6 +- .github/workflows/tag.yml | 6 +- Dockerfile.kbmc => Dockerfile.virtbmc | 10 +-- Makefile | 8 +- PROJECT | 8 +- README.md | 36 ++++----- api/v1/groupversion_info.go | 4 +- api/v1/virtualmachinebmc_webhook.go | 4 +- cmd/controller/main.go | 17 ++--- cmd/{kbmc => virtbmc}/main.go | 18 ++--- ...chine.kubevirt.io_virtualmachinebmcs.yaml} | 4 +- .../virtualmachine.kubevirt.org_kubebmcs.yaml | 74 ------------------- .../virtualmachine.zespre.com_kubebmcs.yaml | 74 ------------------- config/crd/kustomization.yaml | 2 +- .../cainjection_in_virtualmachinebmcs.yaml | 2 +- .../webhook_in_virtualmachinebmcs.yaml | 2 +- config/default/kustomization.yaml | 2 +- config/manager/kustomization.yaml | 2 +- config/rbac/role.yaml | 16 +++- ...aml => virtualmachinebmc_editor_role.yaml} | 4 +- .../rbac/virtualmachinebmc_viewer_role.yaml | 4 +- .../virtualmachine_v1_virtualmachinebmc.yaml | 2 +- .../{virt-bmc => virtbmc}/kustomization.yaml | 0 config/{virt-bmc => virtbmc}/role.yaml | 6 +- .../{virt-bmc => virtbmc}/role_binding.yaml | 10 +-- .../service_account.yaml | 6 +- config/webhook/manifests.yaml | 8 +- go.mod | 2 +- internal/controller/service/controller.go | 27 ++++--- .../controller/service/controller_test.go | 56 +++++++------- internal/controller/service/suite_test.go | 2 +- .../controller/virtualmachine/controller.go | 57 +++++++------- .../virtualmachine/controller_test.go | 26 +++---- .../controller/virtualmachine/suite_test.go | 2 +- .../controller/virtualmachinebmc/constant.go | 23 +++--- .../virtualmachinebmc/controller.go | 65 ++++++++-------- .../virtualmachinebmc/controller_test.go | 42 +++++------ .../virtualmachinebmc/suite_test.go | 11 ++- .../clientset/versioned/clientset.go | 2 +- .../versioned/fake/clientset_generated.go | 6 +- .../versioned/typed/core/v1/core_client.go | 2 +- .../typed/core/v1/fake/fake_core_client.go | 2 +- .../versioned/typed/core/v1/kubevirt.go | 2 +- .../versioned/typed/core/v1/virtualmachine.go | 2 +- .../typed/core/v1/virtualmachineinstance.go | 2 +- .../v1/virtualmachineinstancemigration.go | 2 +- .../core/v1/virtualmachineinstancepreset.go | 2 +- .../v1/virtualmachineinstancereplicaset.go | 2 +- pkg/{bmc => virtbmc}/ipmi.go | 18 ++--- pkg/{bmc => virtbmc}/k8s.go | 38 +++++----- pkg/{bmc/kbmc.go => virtbmc/virtbmc.go} | 30 ++++---- 52 files changed, 309 insertions(+), 455 deletions(-) rename Dockerfile.kbmc => Dockerfile.virtbmc (85%) rename cmd/{kbmc => virtbmc}/main.go (80%) rename config/crd/bases/{virtualmachine.kubevirt.org_virtualmachinebmcs.yaml => virtualmachine.kubevirt.io_virtualmachinebmcs.yaml} (96%) delete mode 100644 config/crd/bases/virtualmachine.kubevirt.org_kubebmcs.yaml delete mode 100644 config/crd/bases/virtualmachine.zespre.com_kubebmcs.yaml rename config/rbac/{kubebmc_editor_role.yaml => virtualmachinebmc_editor_role.yaml} (91%) rename config/{virt-bmc => virtbmc}/kustomization.yaml (100%) rename config/{virt-bmc => virtbmc}/role.yaml (81%) rename config/{virt-bmc => virtbmc}/role_binding.yaml (69%) rename config/{virt-bmc => virtbmc}/service_account.yaml (70%) rename pkg/{bmc => virtbmc}/ipmi.go (79%) rename pkg/{bmc => virtbmc}/k8s.go (65%) rename pkg/{bmc/kbmc.go => virtbmc/virtbmc.go} (54%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ecb2fe1..a89b224 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index c0e8ab9..3743325 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -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 diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 2229c77..6e9d337 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -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 diff --git a/Dockerfile.kbmc b/Dockerfile.virtbmc similarity index 85% rename from Dockerfile.kbmc rename to Dockerfile.virtbmc index 114f535..7b28fb0 100644 --- a/Dockerfile.kbmc +++ b/Dockerfile.virtbmc @@ -1,4 +1,4 @@ -# Build the virt-bmc binary +# Build the virtbmc binary FROM golang:1.20 as builder ARG TARGETOS ARG TARGETARCH @@ -12,7 +12,7 @@ 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 @@ -20,13 +20,13 @@ COPY pkg/ pkg/ # 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"] diff --git a/Makefile b/Makefile index 2d0f5e8..bded728 100644 --- a/Makefile +++ b/Makefile @@ -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. @@ -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. diff --git a/PROJECT b/PROJECT index b4328e5..a0237b5 100644 --- a/PROJECT +++ b/PROJECT @@ -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 diff --git a/README.md b/README.md index 7fa0e0c..7f904c2 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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=/virt-bmc-controller: -make docker-build-virt-bmc docker-push IMG=/virt-bmc: +make docker-build docker-push IMG=/virtbmc-controller: +make docker-build-virtbmc docker-push IMG=/virtbmc: ``` > **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. @@ -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=/virt-bmc-controller: +make deploy IMG=/virtbmc-controller: ``` > **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin privileges or be logged in as admin. @@ -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 623/UDP 3h13m +default-test-vm-virtbmc ClusterIP 10.53.106.65 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: @@ -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 ``` diff --git a/api/v1/groupversion_info.go b/api/v1/groupversion_info.go index 84b9f07..2703891 100644 --- a/api/v1/groupversion_info.go +++ b/api/v1/groupversion_info.go @@ -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 ( @@ -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} diff --git a/api/v1/virtualmachinebmc_webhook.go b/api/v1/virtualmachinebmc_webhook.go index 9876638..91464ef 100644 --- a/api/v1/virtualmachinebmc_webhook.go +++ b/api/v1/virtualmachinebmc_webhook.go @@ -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{} @@ -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{} diff --git a/cmd/controller/main.go b/cmd/controller/main.go index c50c247..00e4d8f 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -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 ) @@ -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 @@ -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 { diff --git a/cmd/kbmc/main.go b/cmd/virtbmc/main.go similarity index 80% rename from cmd/kbmc/main.go rename to cmd/virtbmc/main.go index 9a89bc7..3f0cd23 100644 --- a/cmd/kbmc/main.go +++ b/cmd/virtbmc/main.go @@ -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{ @@ -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 @@ -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() } diff --git a/config/crd/bases/virtualmachine.kubevirt.org_virtualmachinebmcs.yaml b/config/crd/bases/virtualmachine.kubevirt.io_virtualmachinebmcs.yaml similarity index 96% rename from config/crd/bases/virtualmachine.kubevirt.org_virtualmachinebmcs.yaml rename to config/crd/bases/virtualmachine.kubevirt.io_virtualmachinebmcs.yaml index ef3bf69..06bc61e 100644 --- a/config/crd/bases/virtualmachine.kubevirt.org_virtualmachinebmcs.yaml +++ b/config/crd/bases/virtualmachine.kubevirt.io_virtualmachinebmcs.yaml @@ -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 diff --git a/config/crd/bases/virtualmachine.kubevirt.org_kubebmcs.yaml b/config/crd/bases/virtualmachine.kubevirt.org_kubebmcs.yaml deleted file mode 100644 index f16da49..0000000 --- a/config/crd/bases/virtualmachine.kubevirt.org_kubebmcs.yaml +++ /dev/null @@ -1,74 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.15.0 - name: virtualmachinebmcs.virtualmachine.kubevirt.org -spec: - group: virtualmachine.kubevirt.org - names: - kind: VirtualMachineBMC - listKind: VirtualMachineBMCList - plural: virtualmachinebmcs - singular: virtualmachinebmc - scope: Namespaced - versions: - - name: v1 - schema: - openAPIV3Schema: - description: VirtualMachineBMC is the Schema for the virtualmachinebmcs API - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - description: VirtualMachineBMCSpec defines the desired state of VirtualMachineBMC - properties: - password: - description: The credential part of the IPMI service - type: string - username: - description: To authenticate who the user is. - type: string - vmName: - description: The actual virtual machine that this BMC controls - type: string - vmNamespace: - description: The namespace where the virtual machine is in - type: string - required: - - vmName - - vmNamespace - type: object - status: - description: VirtualMachineBMCStatus defines the observed state of VirtualMachineBMC - properties: - ready: - description: The indicator that shows the readiness of the IPMI service for the virtual machine - type: boolean - serviceIP: - description: The listen IP address for the IPMI service. - type: string - required: - - ready - - serviceIP - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/config/crd/bases/virtualmachine.zespre.com_kubebmcs.yaml b/config/crd/bases/virtualmachine.zespre.com_kubebmcs.yaml deleted file mode 100644 index f16da49..0000000 --- a/config/crd/bases/virtualmachine.zespre.com_kubebmcs.yaml +++ /dev/null @@ -1,74 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.15.0 - name: virtualmachinebmcs.virtualmachine.kubevirt.org -spec: - group: virtualmachine.kubevirt.org - names: - kind: VirtualMachineBMC - listKind: VirtualMachineBMCList - plural: virtualmachinebmcs - singular: virtualmachinebmc - scope: Namespaced - versions: - - name: v1 - schema: - openAPIV3Schema: - description: VirtualMachineBMC is the Schema for the virtualmachinebmcs API - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - description: VirtualMachineBMCSpec defines the desired state of VirtualMachineBMC - properties: - password: - description: The credential part of the IPMI service - type: string - username: - description: To authenticate who the user is. - type: string - vmName: - description: The actual virtual machine that this BMC controls - type: string - vmNamespace: - description: The namespace where the virtual machine is in - type: string - required: - - vmName - - vmNamespace - type: object - status: - description: VirtualMachineBMCStatus defines the observed state of VirtualMachineBMC - properties: - ready: - description: The indicator that shows the readiness of the IPMI service for the virtual machine - type: boolean - serviceIP: - description: The listen IP address for the IPMI service. - type: string - required: - - ready - - serviceIP - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 982303d..c5e31db 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -2,7 +2,7 @@ # since it depends on service name and namespace that are out of this kustomize package. # It should be run by config/default resources: -- bases/virtualmachine.kubevirt.org_virtualmachinebmcs.yaml +- bases/virtualmachine.kubevirt.io_virtualmachinebmcs.yaml #+kubebuilder:scaffold:crdkustomizeresource patches: diff --git a/config/crd/patches/cainjection_in_virtualmachinebmcs.yaml b/config/crd/patches/cainjection_in_virtualmachinebmcs.yaml index a101f4c..7850281 100644 --- a/config/crd/patches/cainjection_in_virtualmachinebmcs.yaml +++ b/config/crd/patches/cainjection_in_virtualmachinebmcs.yaml @@ -4,4 +4,4 @@ kind: CustomResourceDefinition metadata: annotations: cert-manager.io/inject-ca-from: CERTIFICATE_NAMESPACE/CERTIFICATE_NAME - name: virtualmachinebmcs.virtualmachine.kubevirt.org + name: virtualmachinebmcs.virtualmachine.kubevirt.io diff --git a/config/crd/patches/webhook_in_virtualmachinebmcs.yaml b/config/crd/patches/webhook_in_virtualmachinebmcs.yaml index 1c509be..952d964 100644 --- a/config/crd/patches/webhook_in_virtualmachinebmcs.yaml +++ b/config/crd/patches/webhook_in_virtualmachinebmcs.yaml @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: virtualmachinebmcs.virtualmachine.kubevirt.org + name: virtualmachinebmcs.virtualmachine.kubevirt.io spec: conversion: strategy: Webhook diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index cab6306..9457e80 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -18,7 +18,7 @@ resources: - ../crd - ../rbac - ../manager -- ../virt-bmc +- ../virtbmc # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml - ../webhook diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index bb4a4ec..25254da 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization images: - name: controller - newName: starbops/virt-bmc-controller + newName: starbops/virtbmc-controller newTag: dev diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index e7884b8..902e624 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -29,7 +29,17 @@ rules: - update - watch - apiGroups: - - virtualmachine.kubevirt.org + - kubevirt.io + resources: + - virtualmachines + verbs: + - get + - list + - patch + - update + - watch +- apiGroups: + - virtualmachine.kubevirt.io resources: - virtualmachinebmcs verbs: @@ -41,13 +51,13 @@ rules: - update - watch - apiGroups: - - virtualmachine.kubevirt.org + - virtualmachine.kubevirt.io resources: - virtualmachinebmcs/finalizers verbs: - update - apiGroups: - - virtualmachine.kubevirt.org + - virtualmachine.kubevirt.io resources: - virtualmachinebmcs/status verbs: diff --git a/config/rbac/kubebmc_editor_role.yaml b/config/rbac/virtualmachinebmc_editor_role.yaml similarity index 91% rename from config/rbac/kubebmc_editor_role.yaml rename to config/rbac/virtualmachinebmc_editor_role.yaml index 4ddfa38..2cba11f 100644 --- a/config/rbac/kubebmc_editor_role.yaml +++ b/config/rbac/virtualmachinebmc_editor_role.yaml @@ -12,7 +12,7 @@ metadata: name: virtualmachinebmc-editor-role rules: - apiGroups: - - virtualmachine.kubevirt.org + - virtualmachine.kubevirt.io resources: - virtualmachinebmcs verbs: @@ -24,7 +24,7 @@ rules: - update - watch - apiGroups: - - virtualmachine.kubevirt.org + - virtualmachine.kubevirt.io resources: - virtualmachinebmcs/status verbs: diff --git a/config/rbac/virtualmachinebmc_viewer_role.yaml b/config/rbac/virtualmachinebmc_viewer_role.yaml index 3eb4b5e..73292cf 100644 --- a/config/rbac/virtualmachinebmc_viewer_role.yaml +++ b/config/rbac/virtualmachinebmc_viewer_role.yaml @@ -12,7 +12,7 @@ metadata: name: virtualmachinebmc-viewer-role rules: - apiGroups: - - virtualmachine.kubevirt.org + - virtualmachine.kubevirt.io resources: - virtualmachinebmcs verbs: @@ -20,7 +20,7 @@ rules: - list - watch - apiGroups: - - virtualmachine.kubevirt.org + - virtualmachine.kubevirt.io resources: - virtualmachinebmcs/status verbs: diff --git a/config/samples/virtualmachine_v1_virtualmachinebmc.yaml b/config/samples/virtualmachine_v1_virtualmachinebmc.yaml index d2fdf51..1f826c0 100644 --- a/config/samples/virtualmachine_v1_virtualmachinebmc.yaml +++ b/config/samples/virtualmachine_v1_virtualmachinebmc.yaml @@ -1,4 +1,4 @@ -apiVersion: virtualmachine.kubevirt.org/v1 +apiVersion: virtualmachine.kubevirt.io/v1 kind: VirtualMachineBMC metadata: labels: diff --git a/config/virt-bmc/kustomization.yaml b/config/virtbmc/kustomization.yaml similarity index 100% rename from config/virt-bmc/kustomization.yaml rename to config/virtbmc/kustomization.yaml diff --git a/config/virt-bmc/role.yaml b/config/virtbmc/role.yaml similarity index 81% rename from config/virt-bmc/role.yaml rename to config/virtbmc/role.yaml index 90d0473..f214218 100644 --- a/config/virt-bmc/role.yaml +++ b/config/virtbmc/role.yaml @@ -3,12 +3,12 @@ kind: ClusterRole metadata: labels: app.kubernetes.io/name: clusterrole - app.kubernetes.io/instance: virt-bmc-role - app.kubernetes.io/component: virt-bmc-rbac + app.kubernetes.io/instance: virtbmc-role + app.kubernetes.io/component: virtbmc-rbac app.kubernetes.io/created-by: kubevirtbmc app.kubernetes.io/part-of: kubevirtbmc app.kubernetes.io/managed-by: kustomize - name: virt-bmc-role + name: virtbmc-role rules: - apiGroups: - kubevirt.io diff --git a/config/virt-bmc/role_binding.yaml b/config/virtbmc/role_binding.yaml similarity index 69% rename from config/virt-bmc/role_binding.yaml rename to config/virtbmc/role_binding.yaml index e88fc1f..3a3fd81 100644 --- a/config/virt-bmc/role_binding.yaml +++ b/config/virtbmc/role_binding.yaml @@ -3,17 +3,17 @@ kind: ClusterRoleBinding metadata: labels: app.kubernetes.io/name: clusterrolebinding - app.kubernetes.io/instance: virt-bmc-rolebinding - app.kubernetes.io/component: virt-bmc-rbac + app.kubernetes.io/instance: virtbmc-rolebinding + app.kubernetes.io/component: virtbmc-rbac app.kubernetes.io/created-by: kubevirtbmc app.kubernetes.io/part-of: kubevirtbmc app.kubernetes.io/managed-by: kustomize - name: virt-bmc-rolebinding + name: virtbmc-rolebinding roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: virt-bmc-role + name: virtbmc-role subjects: - kind: ServiceAccount - name: virt-bmc + name: virtbmc namespace: system diff --git a/config/virt-bmc/service_account.yaml b/config/virtbmc/service_account.yaml similarity index 70% rename from config/virt-bmc/service_account.yaml rename to config/virtbmc/service_account.yaml index fce40bd..6b2b5de 100644 --- a/config/virt-bmc/service_account.yaml +++ b/config/virtbmc/service_account.yaml @@ -3,10 +3,10 @@ kind: ServiceAccount metadata: labels: app.kubernetes.io/name: serviceaccount - app.kubernetes.io/instance: virt-bmc-sa - app.kubernetes.io/component: virt-bmc-rbac + app.kubernetes.io/instance: virtbmc-sa + app.kubernetes.io/component: virtbmc-rbac app.kubernetes.io/created-by: kubevirtbmc app.kubernetes.io/part-of: kubevirtbmc app.kubernetes.io/managed-by: kustomize - name: virt-bmc + name: virtbmc namespace: system diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index 2e0153b..bc46107 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -10,12 +10,12 @@ webhooks: service: name: webhook-service namespace: system - path: /mutate-virtualmachine-kubevirt-org-v1-virtualmachinebmc + path: /mutate-virtualmachine-kubevirt-io-v1-virtualmachinebmc failurePolicy: Fail name: mvirtualmachinebmc.kb.io rules: - apiGroups: - - virtualmachine.kubevirt.org + - virtualmachine.kubevirt.io apiVersions: - v1 operations: @@ -36,12 +36,12 @@ webhooks: service: name: webhook-service namespace: system - path: /validate-virtualmachine-kubevirt-org-v1-virtualmachinebmc + path: /validate-virtualmachine-kubevirt-io-v1-virtualmachinebmc failurePolicy: Fail name: vvirtualmachinebmc.kb.io rules: - apiGroups: - - virtualmachine.kubevirt.org + - virtualmachine.kubevirt.io apiVersions: - v1 operations: diff --git a/go.mod b/go.mod index ec07970..e14fb63 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module kubevirt.org/kubevirtbmc +module kubevirt.io/kubevirtbmc go 1.20 diff --git a/internal/controller/service/controller.go b/internal/controller/service/controller.go index f4d61a1..8eeec8f 100644 --- a/internal/controller/service/controller.go +++ b/internal/controller/service/controller.go @@ -25,9 +25,12 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" - virtualmachinev1 "kubevirt.org/kubevirtbmc/api/v1" + ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" + + virtualmachinev1 "kubevirt.io/kubevirtbmc/api/v1" + ctlvirtualmachinebmc "kubevirt.io/kubevirtbmc/internal/controller/virtualmachinebmc" ) // ServiceReconciler reconciles a Service object @@ -37,8 +40,8 @@ type ServiceReconciler struct { } //+kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch -//+kubebuilder:rbac:groups=virtualmachine.kubevirt.org,resources=virtualmachinebmcs,verbs=get;list;watch -//+kubebuilder:rbac:groups=virtualmachine.kubevirt.org,resources=virtualmachinebmcs/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=virtualmachine.kubevirt.io,resources=virtualmachinebmcs,verbs=get;list;watch +//+kubebuilder:rbac:groups=virtualmachine.kubevirt.io,resources=virtualmachinebmcs/status,verbs=get;update;patch func (s *ServiceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { log := log.FromContext(ctx) @@ -55,17 +58,17 @@ func (s *ServiceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct if svc.Labels == nil { return ctrl.Result{}, nil } - virt - bmcName, ok := svc.Labels[ctlvirtualmachinebmc.virt-bmcNameLabel] + virtualMachineBMCName, ok := svc.Labels[ctlvirtualmachinebmc.VirtualMachineBMCNameLabel] if !ok { return ctrl.Result{}, nil } - knn := types.NamespacedName{ + virtualMachineBMCNamespacedName := types.NamespacedName{ Namespace: req.Namespace, - Name: virt - bmcName, + Name: virtualMachineBMCName, } - var kubeBMC virtualmachinev1.VirtualMachineBMC - if err := s.Get(ctx, knn, &kubeBMC); err != nil { + var virtualMachineBMC virtualmachinev1.VirtualMachineBMC + if err := s.Get(ctx, virtualMachineBMCNamespacedName, &virtualMachineBMC); err != nil { log.Error(err, "unable to fetch VirtualMachineBMC") return ctrl.Result{}, client.IgnoreNotFound(err) } @@ -74,14 +77,14 @@ func (s *ServiceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct if svc.Spec.ClusterIP == "" { return ctrl.Result{RequeueAfter: time.Duration(time.Second * 10)}, fmt.Errorf("clusterIP is not ready yet") } - kubeBMC.Status.Ready = true - kubeBMC.Status.ServiceIP = svc.Spec.ClusterIP - if err := s.Status().Update(ctx, &kubeBMC); err != nil { + virtualMachineBMC.Status.Ready = true + virtualMachineBMC.Status.ServiceIP = svc.Spec.ClusterIP + if err := s.Status().Update(ctx, &virtualMachineBMC); err != nil { log.Error(err, "unable to update VirtualMachineBMC status") return ctrl.Result{}, err } - log.V(1).Info("updated VirtualMachineBMC status for Service", "kubeBMC", kubeBMC) + log.V(1).Info("updated VirtualMachineBMC status for Service", "virtualMachineBMC", virtualMachineBMC) return ctrl.Result{}, nil } diff --git a/internal/controller/service/controller_test.go b/internal/controller/service/controller_test.go index 9fe7fbe..d2f5f8d 100644 --- a/internal/controller/service/controller_test.go +++ b/internal/controller/service/controller_test.go @@ -26,19 +26,19 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - virtualmachinev1 "zespre.com/kubebmc/api/v1" - ctlkubebmc "zespre.com/kubebmc/internal/controller/kubebmc" + virtualmachinev1 "kubevirt.io/kubevirtbmc/api/v1" + ctlvirtualmachinebmc "kubevirt.io/kubevirtbmc/internal/controller/virtualmachinebmc" ) var _ = Describe("Service Controller", func() { const ( - testKubeBMCName = "default-test-vm" - testKubeBMCNamespace = "kubebmc-system" - testUsername = "test-username" - testPassword = "test-password" - testVMName = "test-vm" - testVMNamespace = "default" - testClusterIP = "10.0.0.100" + testVirtualMachineBMCName = "default-test-vm" + testVirtualMachineBMCNamespace = "kubevirtbmc-system" + testUsername = "test-username" + testPassword = "test-password" + testVMName = "test-vm" + testVMNamespace = "default" + testClusterIP = "10.0.0.100" timeout = time.Second * 10 duration = time.Second * 10 @@ -46,42 +46,42 @@ var _ = Describe("Service Controller", func() { ) Context("When clusterIP for the Service is ready", func() { - It("Should update the KubeBMC status", func() { + It("Should update the VirtualMachineBMC status", func() { ctx := context.Background() // we need to create the namespace in the cluster first ns := &corev1.Namespace{ - ObjectMeta: metav1.ObjectMeta{Name: testKubeBMCNamespace}, + ObjectMeta: metav1.ObjectMeta{Name: testVirtualMachineBMCNamespace}, } Expect(k8sClient.Create(ctx, ns)).Should(Succeed()) - By("Creating a new KubeBMC") - kubeBMC := &virtualmachinev1.KubeBMC{ + By("Creating a new VirtualMachineBMC") + virtualMachineBMC := &virtualmachinev1.VirtualMachineBMC{ ObjectMeta: metav1.ObjectMeta{ - Name: testKubeBMCName, - Namespace: testKubeBMCNamespace, + Name: testVirtualMachineBMCName, + Namespace: testVirtualMachineBMCNamespace, }, TypeMeta: metav1.TypeMeta{ - APIVersion: "zespre.com/v1", - Kind: "KubeBMC", + APIVersion: "virtualmachine.kubevirt.io/v1", + Kind: "VirtualMachineBMC", }, - Spec: virtualmachinev1.KubeBMCSpec{ + Spec: virtualmachinev1.VirtualMachineBMCSpec{ Username: testUsername, Password: testPassword, VirtualMachineNamespace: testVMNamespace, VirtualMachineName: testVMName, }, } - Expect(k8sClient.Create(ctx, kubeBMC)).To(Succeed()) + Expect(k8sClient.Create(ctx, virtualMachineBMC)).To(Succeed()) By("Creating a new Service") svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - ctlkubebmc.KBMCNameLabel: testKubeBMCName, + ctlvirtualmachinebmc.VirtualMachineBMCNameLabel: testVirtualMachineBMCName, }, - Name: testKubeBMCName, - Namespace: testKubeBMCNamespace, + Name: testVirtualMachineBMCName, + Namespace: testVirtualMachineBMCNamespace, }, TypeMeta: metav1.TypeMeta{ APIVersion: "v1", @@ -91,22 +91,22 @@ var _ = Describe("Service Controller", func() { ClusterIP: testClusterIP, Ports: []corev1.ServicePort{ { - Port: ctlkubebmc.IPMISvcPort, + Port: ctlvirtualmachinebmc.IPMISvcPort, }, }, }, } Expect(k8sClient.Create(ctx, svc)).To(Succeed()) - By("Checking that the KubeBMC has ServiceIP reflected") - kubeBMCLookupKey := types.NamespacedName{Name: kubeBMC.Name, Namespace: kubeBMC.Namespace} - updatedKubeBMC := &virtualmachinev1.KubeBMC{} + By("Checking that the VirtualMachineBMC has ServiceIP reflected") + virtualMachineBMCLookupKey := types.NamespacedName{Name: virtualMachineBMC.Name, Namespace: virtualMachineBMC.Namespace} + updatedVirtualMachineBMC := &virtualmachinev1.VirtualMachineBMC{} Eventually(func() bool { - if err := k8sClient.Get(ctx, kubeBMCLookupKey, updatedKubeBMC); err != nil { + if err := k8sClient.Get(ctx, virtualMachineBMCLookupKey, updatedVirtualMachineBMC); err != nil { return false } - return updatedKubeBMC.Status.ServiceIP == testClusterIP + return updatedVirtualMachineBMC.Status.ServiceIP == testClusterIP }, timeout, interval).Should(BeTrue()) }) }) diff --git a/internal/controller/service/suite_test.go b/internal/controller/service/suite_test.go index b1dbeb7..46b53e1 100644 --- a/internal/controller/service/suite_test.go +++ b/internal/controller/service/suite_test.go @@ -35,7 +35,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/controller-runtime/pkg/metrics/server" - virtualmachinev1 "zespre.com/kubebmc/api/v1" + virtualmachinev1 "kubevirt.io/kubevirtbmc/api/v1" //+kubebuilder:scaffold:imports ) diff --git a/internal/controller/virtualmachine/controller.go b/internal/controller/virtualmachine/controller.go index db51e42..4bfa958 100644 --- a/internal/controller/virtualmachine/controller.go +++ b/internal/controller/virtualmachine/controller.go @@ -25,16 +25,17 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" kubevirtv1 "kubevirt.io/api/core/v1" - virtualmachinev1 "kubevirt.org/kubevirtbmc/api/v1" - ctlvirtualmachinebmc "kubevirt.org/kubevirtbmc/internal/controller/virtualmachinebmc" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/log" + + virtualmachinev1 "kubevirt.io/kubevirtbmc/api/v1" + ctlvirtualmachinebmc "kubevirt.io/kubevirtbmc/internal/controller/virtualmachinebmc" ) const ( - finalizerName = "virtualmachinebmc-virtualmachine-controller" + finalizerName = "kubevirtbmc-virtualmachine-controller" ) // VirtualMachineReconciler reconciles a VirtualMachine object @@ -66,14 +67,10 @@ func (v *VirtualMachineReconciler) handleFinalizer(ctx context.Context, vm *kube func (v *VirtualMachineReconciler) constructVirtualMachineBMCForVirtualMachine(vm *kubevirtv1.VirtualMachine) (*virtualmachinev1.VirtualMachineBMC, error) { name := fmt.Sprintf("%s-%s", vm.Namespace, vm.Name) - kubeBMC := &virtualmachinev1.VirtualMachineBMC{ + virtualMachineBMC := &virtualmachinev1.VirtualMachineBMC{ ObjectMeta: metav1.ObjectMeta{ - Annotations: make(map[string]string), - Labels: map[string]string{ - ctlvirtualmachinebmc.ManagedByLabel: "virt-bmc-controller", - }, Name: name, - Namespace: ctlvirtualmachinebmc.KBMCNamespace, + Namespace: ctlvirtualmachinebmc.VirtualMachineBMCNamespace, }, Spec: virtualmachinev1.VirtualMachineBMCSpec{ Username: ctlvirtualmachinebmc.DefaultUsername, @@ -83,13 +80,13 @@ func (v *VirtualMachineReconciler) constructVirtualMachineBMCForVirtualMachine(v }, } - return kubeBMC, nil + return virtualMachineBMC, nil } //+kubebuilder:rbac:groups=kubevirt.io,resources=virtualmachines,verbs=get;list;watch;update;patch -//+kubebuilder:rbac:groups=virtualmachine.kubevirt.org,resources=virtualmachinebmcs,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=virtualmachine.kubevirt.org,resources=virtualmachinebmcs/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=virtualmachine.kubevirt.org,resources=virtualmachinebmcs/finalizers,verbs=update +//+kubebuilder:rbac:groups=virtualmachine.kubevirt.io,resources=virtualmachinebmcs,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=virtualmachine.kubevirt.io,resources=virtualmachinebmcs/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=virtualmachine.kubevirt.io,resources=virtualmachinebmcs/finalizers,verbs=update func (v *VirtualMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { log := log.FromContext(ctx) @@ -109,36 +106,36 @@ func (v *VirtualMachineReconciler) Reconcile(ctx context.Context, req ctrl.Reque } // Prepare the VirtualMachineBMC - kubeBMC, err := v.constructVirtualMachineBMCForVirtualMachine(&vm) + virtualMachineBMC, err := v.constructVirtualMachineBMCForVirtualMachine(&vm) if err != nil { log.Error(err, "unable to construct virtualmachinebmc from template") return ctrl.Result{}, err } // Create the VirtualMachineBMC on the cluster - if err := v.Create(ctx, kubeBMC); err != nil && !apierrors.IsAlreadyExists(err) { - log.Error(err, "unable to create VirtualMachineBMC for VirtualMachine", "kubeBMC", kubeBMC) + if err := v.Create(ctx, virtualMachineBMC); err != nil && !apierrors.IsAlreadyExists(err) { + log.Error(err, "unable to create VirtualMachineBMC for VirtualMachine", "virtualMachineBMC", virtualMachineBMC) return ctrl.Result{}, err } - log.V(1).Info("created VirtualMachineBMC for VirtualMachine", "kubeBMC", kubeBMC) - - knn := types.NamespacedName{ - Namespace: ctlvirtualmachinebmc.KBMCNamespace, - Name: fmt.Sprintf("%s-%s", vm.Namespace, vm.Name), - } - var virt-bmc virtualmachinev1.VirtualMachineBMC - if err := v.Get(ctx, knn, &virt-bmc); err != nil { - log.Error(err, "unable to fetch VirtualMachineBMC") - return ctrl.Result{}, err - } + log.V(1).Info("created VirtualMachineBMC for VirtualMachine", "virtualMachineBMC", virtualMachineBMC) if !vm.ObjectMeta.DeletionTimestamp.IsZero() { - if err := v.Delete(ctx, &virt-bmc); err != nil { - log.Error(err, "unable to delete VirtualMachineBMC for VirtualMachine", "virt-bmc", virt-bmc) + virtualMachineBMCNamespacedName := types.NamespacedName{ + Namespace: ctlvirtualmachinebmc.VirtualMachineBMCNamespace, + Name: fmt.Sprintf("%s-%s", vm.Namespace, vm.Name), + } + var virtualMachineBMC virtualmachinev1.VirtualMachineBMC + if err := v.Get(ctx, virtualMachineBMCNamespacedName, &virtualMachineBMC); err != nil { + log.Error(err, "unable to fetch VirtualMachineBMC") + return ctrl.Result{}, err + } + + if err := v.Delete(ctx, &virtualMachineBMC); err != nil { + log.Error(err, "unable to delete VirtualMachineBMC for VirtualMachine", "virtualMachineBMC", virtualMachineBMC) return ctrl.Result{}, err } - log.V(1).Info("removed VirtualMachineBMC for VirtualMachine", "virt-bmc", virt-bmc) + log.V(1).Info("removed VirtualMachineBMC for VirtualMachine", "virtualMachineBMC", virtualMachineBMC) } return ctrl.Result{}, nil diff --git a/internal/controller/virtualmachine/controller_test.go b/internal/controller/virtualmachine/controller_test.go index a648f24..056b163 100644 --- a/internal/controller/virtualmachine/controller_test.go +++ b/internal/controller/virtualmachine/controller_test.go @@ -27,17 +27,17 @@ import ( "k8s.io/apimachinery/pkg/types" kubevirtv1 "kubevirt.io/api/core/v1" - virtualmachinev1 "zespre.com/kubebmc/api/v1" + virtualmachinev1 "kubevirt.io/kubevirtbmc/api/v1" ) var _ = Describe("VirtualMachine Controller", func() { const ( - testVMName = "test-vm" - testVMNamespace = "default" - testKubeBMCName = "default-test-vm" - testKubeBMCNamespace = "kubebmc-system" - testUsername = "test-username" - testPassword = "test-password" + testVMName = "test-vm" + testVMNamespace = "default" + testVirtualMachineBMCName = "default-test-vm" + testVirtualMachineBMCNamespace = "kubevirtbmc-system" + testUsername = "test-username" + testPassword = "test-password" timeout = time.Second * 10 duration = time.Second * 10 @@ -45,12 +45,12 @@ var _ = Describe("VirtualMachine Controller", func() { ) Context("When creating a VirtualMachine", func() { - It("Should create a KubeBMC", func() { + It("Should create a VirtualMachineBMC", func() { ctx := context.Background() // we need to create the namespace in the cluster first ns := corev1.Namespace{ - ObjectMeta: metav1.ObjectMeta{Name: testKubeBMCNamespace}, + ObjectMeta: metav1.ObjectMeta{Name: testVirtualMachineBMCNamespace}, } Expect(k8sClient.Create(ctx, &ns)).Should(Succeed()) @@ -70,12 +70,12 @@ var _ = Describe("VirtualMachine Controller", func() { } Expect(k8sClient.Create(ctx, vm)).To(Succeed()) - By("Checking that the KubeBMC is created") - kubeBMCLookupKey := types.NamespacedName{Name: testKubeBMCName, Namespace: testKubeBMCNamespace} - createdKubeBMC := &virtualmachinev1.KubeBMC{} + By("Checking that the VirtualMachineBMC is created") + virtualMachineBMCLookupKey := types.NamespacedName{Name: testVirtualMachineBMCName, Namespace: testVirtualMachineBMCNamespace} + createdVirtualMachineBMC := &virtualmachinev1.VirtualMachineBMC{} Eventually(func() bool { - err := k8sClient.Get(ctx, kubeBMCLookupKey, createdKubeBMC) + err := k8sClient.Get(ctx, virtualMachineBMCLookupKey, createdVirtualMachineBMC) return err == nil }, timeout, interval).Should(BeTrue()) }) diff --git a/internal/controller/virtualmachine/suite_test.go b/internal/controller/virtualmachine/suite_test.go index 623f9d2..32fc3af 100644 --- a/internal/controller/virtualmachine/suite_test.go +++ b/internal/controller/virtualmachine/suite_test.go @@ -36,7 +36,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/controller-runtime/pkg/metrics/server" - virtualmachinev1 "zespre.com/kubebmc/api/v1" + virtualmachinev1 "kubevirt.io/kubevirtbmc/api/v1" //+kubebuilder:scaffold:imports ) diff --git a/internal/controller/virtualmachinebmc/constant.go b/internal/controller/virtualmachinebmc/constant.go index 8c5b7f5..bfac5f8 100644 --- a/internal/controller/virtualmachinebmc/constant.go +++ b/internal/controller/virtualmachinebmc/constant.go @@ -1,16 +1,15 @@ package virtualmachinebmc const ( - DefaultUsername = "admin" - DefaultPassword = "password" - kbmcContainerName = "virt-bmc" - kbmcImageName = "starbops/virt-bmc" - kbmcImageTag = "dev" - ipmiPort = 623 - IPMISvcPort = 623 - ipmiPortName = "ipmi" - ManagedByLabel = "app.kubernetes.io/managed-by" - KBMCNameLabel = "kubevirt.org/virtualmachinebmc-name" - VMNameLabel = "kubevirt.org/vm-name" - KBMCNamespace = "kubevirtbmc-system" + DefaultUsername = "admin" + DefaultPassword = "password" + virtBMCContainerName = "virtbmc" + virtBMCImageName = "starbops/virtbmc" + virtBMCImageTag = "dev" + ipmiPort = 623 + IPMISvcPort = 623 + ipmiPortName = "ipmi" + VirtualMachineBMCNameLabel = "kubevirt.io/virtualmachinebmc-name" + VMNameLabel = "kubevirt.io/vm-name" + VirtualMachineBMCNamespace = "kubevirtbmc-system" ) diff --git a/internal/controller/virtualmachinebmc/controller.go b/internal/controller/virtualmachinebmc/controller.go index 2c8c800..d74b0d9 100644 --- a/internal/controller/virtualmachinebmc/controller.go +++ b/internal/controller/virtualmachinebmc/controller.go @@ -29,7 +29,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - virtualmachinev1 "kubevirt.org/kubevirtbmc/api/v1" + virtualmachinev1 "kubevirt.io/kubevirtbmc/api/v1" ) // VirtualMachineBMCReconciler reconciles a VirtualMachineBMC object @@ -43,32 +43,30 @@ var ( apiGVStr = virtualmachinev1.GroupVersion.String() ) -func (r *VirtualMachineBMCReconciler) constructPodForVirtualMachineBMC(kubeBMC *virtualmachinev1.VirtualMachineBMC) (*corev1.Pod, error) { - name := fmt.Sprintf("%s-virt-bmc", kubeBMC.Name) +func (r *VirtualMachineBMCReconciler) constructPodForVirtualMachineBMC(virtualMachineBMC *virtualmachinev1.VirtualMachineBMC) (*corev1.Pod, error) { + name := fmt.Sprintf("%s-virtbmc", virtualMachineBMC.Name) pod := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ - Annotations: make(map[string]string), Labels: map[string]string{ - ManagedByLabel: "virt-bmc", - KBMCNameLabel: kubeBMC.Name, - VMNameLabel: kubeBMC.Spec.VirtualMachineName, + VirtualMachineBMCNameLabel: virtualMachineBMC.Name, + VMNameLabel: virtualMachineBMC.Spec.VirtualMachineName, }, Name: name, - Namespace: KBMCNamespace, + Namespace: VirtualMachineBMCNamespace, }, Spec: corev1.PodSpec{ Containers: []corev1.Container{ { - Name: kbmcContainerName, - Image: fmt.Sprintf("%s:%s", kbmcImageName, kbmcImageTag), + Name: virtBMCContainerName, + Image: fmt.Sprintf("%s:%s", virtBMCImageName, virtBMCImageTag), Args: []string{ "--address", "0.0.0.0", "--port", "623", - kubeBMC.Spec.VirtualMachineNamespace, - kubeBMC.Spec.VirtualMachineName, + virtualMachineBMC.Spec.VirtualMachineNamespace, + virtualMachineBMC.Spec.VirtualMachineName, }, Ports: []corev1.ContainerPort{ { @@ -79,31 +77,28 @@ func (r *VirtualMachineBMCReconciler) constructPodForVirtualMachineBMC(kubeBMC * }, }, }, - ServiceAccountName: "kubevirtbmc-virt-bmc", + ServiceAccountName: "kubevirtbmc-virtbmc", }, } return pod, nil } -func (r *VirtualMachineBMCReconciler) constructServiceForVirtualMachineBMC(kubeBMC *virtualmachinev1.VirtualMachineBMC) (*corev1.Service, error) { - name := fmt.Sprintf("%s-virt-bmc", kubeBMC.Name) +func (r *VirtualMachineBMCReconciler) constructServiceForVirtualMachineBMC(virtualMachineBMC *virtualmachinev1.VirtualMachineBMC) (*corev1.Service, error) { + name := fmt.Sprintf("%s-virtbmc", virtualMachineBMC.Name) svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ - Annotations: make(map[string]string), Labels: map[string]string{ - ManagedByLabel: "virt-bmc", - KBMCNameLabel: kubeBMC.Name, - VMNameLabel: kubeBMC.Spec.VirtualMachineName, + VirtualMachineBMCNameLabel: virtualMachineBMC.Name, + VMNameLabel: virtualMachineBMC.Spec.VirtualMachineName, }, Name: name, - Namespace: KBMCNamespace, + Namespace: VirtualMachineBMCNamespace, }, Spec: corev1.ServiceSpec{ Selector: map[string]string{ - ManagedByLabel: "virt-bmc", - KBMCNameLabel: kubeBMC.Name, + VirtualMachineBMCNameLabel: virtualMachineBMC.Name, }, Ports: []corev1.ServicePort{ { @@ -119,9 +114,9 @@ func (r *VirtualMachineBMCReconciler) constructServiceForVirtualMachineBMC(kubeB return svc, nil } -//+kubebuilder:rbac:groups=virtualmachine.kubevirt.org,resources=virtualmachinebmcs,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=virtualmachine.kubevirt.org,resources=virtualmachinebmcs/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=virtualmachine.kubevirt.org,resources=virtualmachinebmcs/finalizers,verbs=update +//+kubebuilder:rbac:groups=virtualmachine.kubevirt.io,resources=virtualmachinebmcs,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=virtualmachine.kubevirt.io,resources=virtualmachinebmcs/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=virtualmachine.kubevirt.io,resources=virtualmachinebmcs/finalizers,verbs=update //+kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch;create;update;patch;delete @@ -137,8 +132,8 @@ func (r *VirtualMachineBMCReconciler) constructServiceForVirtualMachineBMC(kubeB func (r *VirtualMachineBMCReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { log := log.FromContext(ctx) - var kubeBMC virtualmachinev1.VirtualMachineBMC - if err := r.Get(ctx, req.NamespacedName, &kubeBMC); err != nil { + var virtualMachineBMC virtualmachinev1.VirtualMachineBMC + if err := r.Get(ctx, req.NamespacedName, &virtualMachineBMC); err != nil { if apierrors.IsNotFound(err) { return ctrl.Result{}, nil } @@ -146,17 +141,17 @@ func (r *VirtualMachineBMCReconciler) Reconcile(ctx context.Context, req ctrl.Re return ctrl.Result{}, client.IgnoreNotFound(err) } - // Prepare the virt-bmc Pod - pod, err := r.constructPodForVirtualMachineBMC(&kubeBMC) + // Prepare the virtBMC Pod + pod, err := r.constructPodForVirtualMachineBMC(&virtualMachineBMC) if err != nil { log.Error(err, "unable to construct pod from template") return ctrl.Result{}, err } - if err := ctrl.SetControllerReference(&kubeBMC, pod, r.Scheme); err != nil { + if err := ctrl.SetControllerReference(&virtualMachineBMC, pod, r.Scheme); err != nil { return ctrl.Result{}, err } - // Create the virt-bmc Pod on the cluster + // Create the virtBMC Pod on the cluster if err := r.Create(ctx, pod); err != nil && !apierrors.IsAlreadyExists(err) { log.Error(err, "unable to create Pod for VirtualMachineBMC", "pod", pod) return ctrl.Result{}, err @@ -164,17 +159,17 @@ func (r *VirtualMachineBMCReconciler) Reconcile(ctx context.Context, req ctrl.Re log.V(1).Info("created Pod for VirtualMachineBMC", "pod", pod) - // Prepare the virt-bmc Service - svc, err := r.constructServiceForVirtualMachineBMC(&kubeBMC) + // Prepare the virtBMC Service + svc, err := r.constructServiceForVirtualMachineBMC(&virtualMachineBMC) if err != nil { log.Error(err, "unable to construct svc from template") return ctrl.Result{}, err } - if err := ctrl.SetControllerReference(&kubeBMC, svc, r.Scheme); err != nil { + if err := ctrl.SetControllerReference(&virtualMachineBMC, svc, r.Scheme); err != nil { return ctrl.Result{}, err } - // Create the virt-bmc Service on the cluster + // Create the virtBMC Service on the cluster if err := r.Create(ctx, svc); err != nil && !apierrors.IsAlreadyExists(err) { log.Error(err, "unable to create Service for VirtualMachineBMC", "svc", svc) return ctrl.Result{}, err diff --git a/internal/controller/virtualmachinebmc/controller_test.go b/internal/controller/virtualmachinebmc/controller_test.go index 9c63298..80c3c62 100644 --- a/internal/controller/virtualmachinebmc/controller_test.go +++ b/internal/controller/virtualmachinebmc/controller_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package kubebmc +package virtualmachinebmc import ( "context" @@ -26,54 +26,54 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - virtualmachinev1 "zespre.com/kubebmc/api/v1" + virtualmachinev1 "kubevirt.io/kubevirtbmc/api/v1" ) -var _ = Describe("KubeBMC Controller", func() { +var _ = Describe("VirtualMachineBMC Controller", func() { const ( - testKubeBMCName = "default-test-vm" - testKubeBMCNamespace = "kubebmc-system" - testUsername = "test-username" - testPassword = "test-password" - testVMName = "test-vm" - testVMNamespace = "default" + testVirtualMachineBMCName = "default-test-vm" + testVirtualMachineBMCNamespace = "kubevirtbmc-system" + testUsername = "test-username" + testPassword = "test-password" + testVMName = "test-vm" + testVMNamespace = "default" timeout = time.Second * 10 duration = time.Second * 10 interval = time.Millisecond * 250 ) - Context("When creating an KubeBMC", func() { + Context("When creating an VirtualMachineBMC", func() { It("Should create a Pod and a Service", func() { ctx := context.Background() // we need to create the namespace in the cluster first ns := &corev1.Namespace{ - ObjectMeta: metav1.ObjectMeta{Name: testKubeBMCNamespace}, + ObjectMeta: metav1.ObjectMeta{Name: testVirtualMachineBMCNamespace}, } Expect(k8sClient.Create(ctx, ns)).Should(Succeed()) - By("Creating a new KubeBMC") - kubeBMC := &virtualmachinev1.KubeBMC{ + By("Creating a new VirtualMachineBMC") + virtualMachineBMC := &virtualmachinev1.VirtualMachineBMC{ ObjectMeta: metav1.ObjectMeta{ - Name: testKubeBMCName, - Namespace: testKubeBMCNamespace, + Name: testVirtualMachineBMCName, + Namespace: testVirtualMachineBMCNamespace, }, TypeMeta: metav1.TypeMeta{ - APIVersion: "zespre.com/v1", - Kind: "KubeBMC", + APIVersion: "virtualmachine.kubevirt.io/v1", + Kind: "VirtualMachineBMC", }, - Spec: virtualmachinev1.KubeBMCSpec{ + Spec: virtualmachinev1.VirtualMachineBMCSpec{ Username: testUsername, Password: testPassword, VirtualMachineNamespace: testVMNamespace, VirtualMachineName: testVMName, }, } - Expect(k8sClient.Create(ctx, kubeBMC)).To(Succeed()) + Expect(k8sClient.Create(ctx, virtualMachineBMC)).To(Succeed()) By("Checking that the Pod is created") - podLookupKey := types.NamespacedName{Name: kubeBMC.Name + "-kbmc", Namespace: kubeBMC.Namespace} + podLookupKey := types.NamespacedName{Name: virtualMachineBMC.Name + "-virtbmc", Namespace: virtualMachineBMC.Namespace} createdPod := &corev1.Pod{} Eventually(func() bool { @@ -82,7 +82,7 @@ var _ = Describe("KubeBMC Controller", func() { }, timeout, interval).Should(BeTrue()) By("Checking that the Service is created") - svcLookupKey := types.NamespacedName{Name: kubeBMC.Name + "-kbmc", Namespace: kubeBMC.Namespace} + svcLookupKey := types.NamespacedName{Name: virtualMachineBMC.Name + "-virtbmc", Namespace: virtualMachineBMC.Namespace} createdSvc := &corev1.Service{} Eventually(func() bool { diff --git a/internal/controller/virtualmachinebmc/suite_test.go b/internal/controller/virtualmachinebmc/suite_test.go index 27adb51..281c571 100644 --- a/internal/controller/virtualmachinebmc/suite_test.go +++ b/internal/controller/virtualmachinebmc/suite_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package kubebmc +package virtualmachinebmc import ( "context" @@ -35,8 +35,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/controller-runtime/pkg/metrics/server" - virtualmachinev1 "kubevirt.org/kubevirtbmc/api/v1" - "kubevirt.org/kubevirtbmc/internal/controller/virtualmachinebmc" + virtualmachinev1 "kubevirt.io/kubevirtbmc/api/v1" //+kubebuilder:scaffold:imports ) @@ -51,10 +50,10 @@ var ( cancel context.CancelFunc ) -func TestKubeBMCControllers(t *testing.T) { +func TestVirtualMachineBMCControllers(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "KubeBMC Controller Suite") + RunSpecs(t, "VirtualMachineBMC Controller Suite") } var _ = BeforeSuite(func() { @@ -98,7 +97,7 @@ var _ = BeforeSuite(func() { }) Expect(err).ToNot(HaveOccurred()) - err = (&virtualmachinebmc.VirtualMachineBMCReconciler{ + err = (&VirtualMachineBMCReconciler{ Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), }).SetupWithManager(k8sManager) diff --git a/pkg/generated/clientset/versioned/clientset.go b/pkg/generated/clientset/versioned/clientset.go index 27e62b2..f3a765a 100644 --- a/pkg/generated/clientset/versioned/clientset.go +++ b/pkg/generated/clientset/versioned/clientset.go @@ -19,7 +19,7 @@ package versioned import ( "fmt" - kubevirtv1 "kubevirt.org/virtualmachinebmc/pkg/generated/clientset/versioned/typed/core/v1" + kubevirtv1 "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned/typed/core/v1" "net/http" discovery "k8s.io/client-go/discovery" diff --git a/pkg/generated/clientset/versioned/fake/clientset_generated.go b/pkg/generated/clientset/versioned/fake/clientset_generated.go index 789822e..e26546b 100644 --- a/pkg/generated/clientset/versioned/fake/clientset_generated.go +++ b/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -18,9 +18,9 @@ limitations under the License. package fake import ( - clientset "kubevirt.org/virtualmachinebmc/pkg/generated/clientset/versioned" - kubevirtv1 "kubevirt.org/virtualmachinebmc/pkg/generated/clientset/versioned/typed/core/v1" - fakekubevirtv1 "kubevirt.org/virtualmachinebmc/pkg/generated/clientset/versioned/typed/core/v1/fake" + clientset "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned" + kubevirtv1 "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned/typed/core/v1" + fakekubevirtv1 "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned/typed/core/v1/fake" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" diff --git a/pkg/generated/clientset/versioned/typed/core/v1/core_client.go b/pkg/generated/clientset/versioned/typed/core/v1/core_client.go index dd73908..bf8687b 100644 --- a/pkg/generated/clientset/versioned/typed/core/v1/core_client.go +++ b/pkg/generated/clientset/versioned/typed/core/v1/core_client.go @@ -18,7 +18,7 @@ limitations under the License. package v1 import ( - "kubevirt.org/virtualmachinebmc/pkg/generated/clientset/versioned/scheme" + "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned/scheme" "net/http" rest "k8s.io/client-go/rest" diff --git a/pkg/generated/clientset/versioned/typed/core/v1/fake/fake_core_client.go b/pkg/generated/clientset/versioned/typed/core/v1/fake/fake_core_client.go index 9339bde..32acac6 100644 --- a/pkg/generated/clientset/versioned/typed/core/v1/fake/fake_core_client.go +++ b/pkg/generated/clientset/versioned/typed/core/v1/fake/fake_core_client.go @@ -18,7 +18,7 @@ limitations under the License. package fake import ( - v1 "kubevirt.org/virtualmachinebmc/pkg/generated/clientset/versioned/typed/core/v1" + v1 "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned/typed/core/v1" rest "k8s.io/client-go/rest" testing "k8s.io/client-go/testing" diff --git a/pkg/generated/clientset/versioned/typed/core/v1/kubevirt.go b/pkg/generated/clientset/versioned/typed/core/v1/kubevirt.go index 8913085..e9b863e 100644 --- a/pkg/generated/clientset/versioned/typed/core/v1/kubevirt.go +++ b/pkg/generated/clientset/versioned/typed/core/v1/kubevirt.go @@ -19,7 +19,7 @@ package v1 import ( "context" - scheme "kubevirt.org/virtualmachinebmc/pkg/generated/clientset/versioned/scheme" + scheme "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned/scheme" "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/generated/clientset/versioned/typed/core/v1/virtualmachine.go b/pkg/generated/clientset/versioned/typed/core/v1/virtualmachine.go index 32f2a7e..b1f2bc8 100644 --- a/pkg/generated/clientset/versioned/typed/core/v1/virtualmachine.go +++ b/pkg/generated/clientset/versioned/typed/core/v1/virtualmachine.go @@ -19,7 +19,7 @@ package v1 import ( "context" - scheme "kubevirt.org/virtualmachinebmc/pkg/generated/clientset/versioned/scheme" + scheme "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned/scheme" "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstance.go b/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstance.go index 0ccfaa7..e4af566 100644 --- a/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstance.go +++ b/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstance.go @@ -19,7 +19,7 @@ package v1 import ( "context" - scheme "kubevirt.org/virtualmachinebmc/pkg/generated/clientset/versioned/scheme" + scheme "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned/scheme" "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstancemigration.go b/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstancemigration.go index 4a607c8..d9c7e51 100644 --- a/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstancemigration.go +++ b/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstancemigration.go @@ -19,7 +19,7 @@ package v1 import ( "context" - scheme "kubevirt.org/virtualmachinebmc/pkg/generated/clientset/versioned/scheme" + scheme "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned/scheme" "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstancepreset.go b/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstancepreset.go index f27a001..9e02610 100644 --- a/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstancepreset.go +++ b/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstancepreset.go @@ -19,7 +19,7 @@ package v1 import ( "context" - scheme "kubevirt.org/virtualmachinebmc/pkg/generated/clientset/versioned/scheme" + scheme "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned/scheme" "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstancereplicaset.go b/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstancereplicaset.go index 62e6c49..d9faa5d 100644 --- a/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstancereplicaset.go +++ b/pkg/generated/clientset/versioned/typed/core/v1/virtualmachineinstancereplicaset.go @@ -19,7 +19,7 @@ package v1 import ( "context" - scheme "kubevirt.org/virtualmachinebmc/pkg/generated/clientset/versioned/scheme" + scheme "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned/scheme" "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/bmc/ipmi.go b/pkg/virtbmc/ipmi.go similarity index 79% rename from pkg/bmc/ipmi.go rename to pkg/virtbmc/ipmi.go index 31bc10c..252d7fe 100644 --- a/pkg/bmc/ipmi.go +++ b/pkg/virtbmc/ipmi.go @@ -1,11 +1,11 @@ -package kbmc +package virtbmc import ( "github.com/sirupsen/logrus" ipmi "github.com/vmware/goipmi" ) -func (k *KBMC) chassisControlHandler(m *ipmi.Message) ipmi.Response { +func (b *VirtBMC) chassisControlHandler(m *ipmi.Message) ipmi.Response { r := &ipmi.ChassisControlRequest{} if err := m.Request(r); err != nil { return err @@ -16,13 +16,13 @@ func (k *KBMC) chassisControlHandler(m *ipmi.Message) ipmi.Response { switch r.ChassisControl { case ipmi.ControlPowerDown, ipmi.ControlPowerAcpiSoft: logrus.Info("power off") - err = k.stopVirtualMachine() + err = b.stopVirtualMachine() case ipmi.ControlPowerUp: logrus.Info("power on") - err = k.startVirtualMachine() + err = b.startVirtualMachine() case ipmi.ControlPowerCycle, ipmi.ControlPowerHardReset: logrus.Info("power cycle") - err = k.rebootVirtualMachine() + err = b.rebootVirtualMachine() } if err != nil { @@ -36,10 +36,10 @@ func (k *KBMC) chassisControlHandler(m *ipmi.Message) ipmi.Response { } } -func (k *KBMC) chassisStatusHandler(*ipmi.Message) ipmi.Response { +func (b *VirtBMC) chassisStatusHandler(*ipmi.Message) ipmi.Response { logrus.Info("power status") - isUp, err := k.getVirtualMachinePowerStatus() + isUp, err := b.getVirtualMachinePowerStatus() if err != nil { return &ipmi.ChassisStatusResponse{ CompletionCode: ipmi.ErrInvalidState, @@ -57,7 +57,7 @@ func (k *KBMC) chassisStatusHandler(*ipmi.Message) ipmi.Response { } } -func (k *KBMC) setSystemBootOptionsHandler(m *ipmi.Message) ipmi.Response { +func (b *VirtBMC) setSystemBootOptionsHandler(m *ipmi.Message) ipmi.Response { logrus.Info("set boot device") r := &ipmi.SetSystemBootOptionsRequest{} @@ -81,7 +81,7 @@ func (k *KBMC) setSystemBootOptionsHandler(m *ipmi.Message) ipmi.Response { device = Disk } - err := k.setVirtualMachineBootDevice(device) + err := b.setVirtualMachineBootDevice(device) if err != nil { return &ipmi.SetSystemBootOptionsResponse{ CompletionCode: ipmi.ErrUnspecified, diff --git a/pkg/bmc/k8s.go b/pkg/virtbmc/k8s.go similarity index 65% rename from pkg/bmc/k8s.go rename to pkg/virtbmc/k8s.go index 24190dd..938b1bd 100644 --- a/pkg/bmc/k8s.go +++ b/pkg/virtbmc/k8s.go @@ -1,4 +1,4 @@ -package kbmc +package virtbmc import ( "github.com/sirupsen/logrus" @@ -7,7 +7,7 @@ import ( "k8s.io/client-go/tools/clientcmd" kubevirtv1 "kubevirt.io/api/core/v1" - kubevirtv1type "kubevirt.org/kubevirtbmc/pkg/generated/clientset/versioned/typed/core/v1" + kubevirtv1type "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned/typed/core/v1" ) type BootDevice string @@ -50,24 +50,24 @@ genClientset: return clientset } -func (k *KBMC) getVirtualMachine(namespace, name string) (*kubevirtv1.VirtualMachine, error) { - vm, err := k.kvClient.VirtualMachines(namespace).Get(k.context, name, v1.GetOptions{}) +func (b *VirtBMC) getVirtualMachine(namespace, name string) (*kubevirtv1.VirtualMachine, error) { + vm, err := b.kvClient.VirtualMachines(namespace).Get(b.context, name, v1.GetOptions{}) if err != nil { return nil, err } return vm, nil } -func (k *KBMC) getVirtualMachineInstance(namespace, name string) (*kubevirtv1.VirtualMachineInstance, error) { - vmi, err := k.kvClient.VirtualMachineInstances(namespace).Get(k.context, name, v1.GetOptions{}) +func (b *VirtBMC) getVirtualMachineInstance(namespace, name string) (*kubevirtv1.VirtualMachineInstance, error) { + vmi, err := b.kvClient.VirtualMachineInstances(namespace).Get(b.context, name, v1.GetOptions{}) if err != nil { return nil, err } return vmi, nil } -func (k *KBMC) getVirtualMachinePowerStatus() (bool, error) { - vm, err := k.kvClient.VirtualMachines(k.vmNamespace).Get(k.context, k.vmName, v1.GetOptions{}) +func (b *VirtBMC) getVirtualMachinePowerStatus() (bool, error) { + vm, err := b.kvClient.VirtualMachines(b.vmNamespace).Get(b.context, b.vmName, v1.GetOptions{}) if err != nil { return false, err } @@ -77,42 +77,42 @@ func (k *KBMC) getVirtualMachinePowerStatus() (bool, error) { return true, nil } -func (k *KBMC) stopVirtualMachine() error { - vm, err := k.kvClient.VirtualMachines(k.vmNamespace).Get(k.context, k.vmName, v1.GetOptions{}) +func (b *VirtBMC) stopVirtualMachine() error { + vm, err := b.kvClient.VirtualMachines(b.vmNamespace).Get(b.context, b.vmName, v1.GetOptions{}) if err != nil { return err } runStrategy := kubevirtv1.RunStrategyHalted vm.Spec.RunStrategy = &runStrategy - if _, err := k.kvClient.VirtualMachines(k.vmNamespace).Update(k.context, vm, v1.UpdateOptions{}); err != nil { + if _, err := b.kvClient.VirtualMachines(b.vmNamespace).Update(b.context, vm, v1.UpdateOptions{}); err != nil { return err } return nil } -func (k *KBMC) startVirtualMachine() error { - vm, err := k.kvClient.VirtualMachines(k.vmNamespace).Get(k.context, k.vmName, v1.GetOptions{}) +func (b *VirtBMC) startVirtualMachine() error { + vm, err := b.kvClient.VirtualMachines(b.vmNamespace).Get(b.context, b.vmName, v1.GetOptions{}) if err != nil { return err } runStrategy := kubevirtv1.RunStrategyRerunOnFailure vm.Spec.RunStrategy = &runStrategy - if _, err := k.kvClient.VirtualMachines(k.vmNamespace).Update(k.context, vm, v1.UpdateOptions{}); err != nil { + if _, err := b.kvClient.VirtualMachines(b.vmNamespace).Update(b.context, vm, v1.UpdateOptions{}); err != nil { return err } return nil } -func (k *KBMC) rebootVirtualMachine() error { - if err := k.kvClient.VirtualMachineInstances(k.vmNamespace).Delete(k.context, k.vmName, v1.DeleteOptions{}); err != nil { +func (b *VirtBMC) rebootVirtualMachine() error { + if err := b.kvClient.VirtualMachineInstances(b.vmNamespace).Delete(b.context, b.vmName, v1.DeleteOptions{}); err != nil { return err } return nil } -func (k *KBMC) setVirtualMachineBootDevice(bd BootDevice) error { +func (b *VirtBMC) setVirtualMachineBootDevice(bd BootDevice) error { logrus.Info("setVirtualMachineBootDevice") - vm, err := k.kvClient.VirtualMachines(k.vmNamespace).Get(k.context, k.vmName, v1.GetOptions{}) + vm, err := b.kvClient.VirtualMachines(b.vmNamespace).Get(b.context, b.vmName, v1.GetOptions{}) if err != nil { return err } @@ -144,7 +144,7 @@ func (k *KBMC) setVirtualMachineBootDevice(bd BootDevice) error { logrus.Infof("To be updated vm: %+v", vm.Spec.Template.Spec.Domain.Devices.Disks[0]) } - if _, err := k.kvClient.VirtualMachines(k.vmNamespace).Update(k.context, vm, v1.UpdateOptions{}); err != nil { + if _, err := b.kvClient.VirtualMachines(b.vmNamespace).Update(b.context, vm, v1.UpdateOptions{}); err != nil { logrus.Errorf("update vm error: %v", err) return err } diff --git a/pkg/bmc/kbmc.go b/pkg/virtbmc/virtbmc.go similarity index 54% rename from pkg/bmc/kbmc.go rename to pkg/virtbmc/virtbmc.go index 24ae7d9..7309a69 100644 --- a/pkg/bmc/kbmc.go +++ b/pkg/virtbmc/virtbmc.go @@ -1,4 +1,4 @@ -package kbmc +package virtbmc import ( "context" @@ -7,7 +7,7 @@ import ( "github.com/sirupsen/logrus" ipmi "github.com/vmware/goipmi" - kubevirtv1 "kubevirt.org/kubevirtbmc/pkg/generated/clientset/versioned/typed/core/v1" + kubevirtv1 "kubevirt.io/kubevirtbmc/pkg/generated/clientset/versioned/typed/core/v1" ) type Options struct { @@ -16,7 +16,7 @@ type Options struct { Port int } -type KBMC struct { +type VirtBMC struct { context context.Context address string port int @@ -26,8 +26,8 @@ type KBMC struct { sim *ipmi.Simulator } -func NewKBMC(ctx context.Context, options Options, inCluster bool) (*KBMC, error) { - return &KBMC{ +func NewVirtBMC(ctx context.Context, options Options, inCluster bool) (*VirtBMC, error) { + return &VirtBMC{ context: ctx, address: options.Address, port: options.Port, @@ -41,24 +41,24 @@ func NewKBMC(ctx context.Context, options Options, inCluster bool) (*KBMC, error }, nil } -func (k *KBMC) register() { - k.sim.SetHandler(ipmi.NetworkFunctionChassis, ipmi.CommandChassisControl, k.chassisControlHandler) - k.sim.SetHandler(ipmi.NetworkFunctionChassis, ipmi.CommandChassisStatus, k.chassisStatusHandler) - k.sim.SetHandler(ipmi.NetworkFunctionChassis, ipmi.CommandSetSystemBootOptions, k.setSystemBootOptionsHandler) +func (b *VirtBMC) register() { + b.sim.SetHandler(ipmi.NetworkFunctionChassis, ipmi.CommandChassisControl, b.chassisControlHandler) + b.sim.SetHandler(ipmi.NetworkFunctionChassis, ipmi.CommandChassisStatus, b.chassisStatusHandler) + b.sim.SetHandler(ipmi.NetworkFunctionChassis, ipmi.CommandSetSystemBootOptions, b.setSystemBootOptionsHandler) } -func (k *KBMC) Run() error { +func (b *VirtBMC) Run() error { logrus.Info("Initializing the simulator...") - k.register() + b.register() - if err := k.sim.Run(); err != nil { + if err := b.sim.Run(); err != nil { return fmt.Errorf("unable to run the ipmi simulator") } - logrus.Infof("Listen on %s:%d", k.address, k.port) + logrus.Infof("Listen on %s:%d", b.address, b.port) - <-k.context.Done() + <-b.context.Done() logrus.Info("Gracefully shutting down IPMIService") - k.sim.Stop() + b.sim.Stop() return nil }