labInstance-operator

command module
v0.0.0-...-ace2c68 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

README

Laboratory Instance Operator (LabOperator)

Based on Kubebuilder 2.3, the operator implements the backend logic of Crownlabs

Basic Functioning

CRDs

The Laboratory Operator (LabOperator) implements the backend logic necessary to spawn new laboratories starting from a predefined template. LabOperator relies on two Kubernetes Custom Resource Definitions (CRDs) which implement the basic APIs:

  • Laboratory Template (LabTemplate) defines the size of the execution environment (e.g.; Virtual Machine), its base image and a description. This object is created by professors and read by students, while creating new instances.
  • Laboratory Instance (LabInstance) defines an instance of a certain template. The manipulation of those objects triggers the reconciliation logic in LabOperator, which creates/destroy associated resources (e.g.; Virtual Machines).

A LabInstance resource triggers the creation of the following components:

  • Kubevirt VirtualMachine Instance and the logic to access the noVNC instance inside the VM (Service, Ingress)
  • An instance of Oauth2 Proxy (Deployment, Service, Ingress) to regulate access to the VM.

All those resources are binded to the LabInstance life-cycle via the OwnerRef property

Both LabTemplates and LabInstances are namespaced.

Installation

Pre-requirements

The only LabOperator requirement is to have Kubevirt deployed. This can be done with the following commands, as reported by the official website:

# On other OS you might need to define it like
export KUBEVIRT_VERSION="v0.34.0"

# Deploy the KubeVirt operator
kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml
# Only if HW Virtualization is not available
kubectl create configmap kubevirt-config -n kubevirt --from-literal debug.useEmulation=true
# Deploy Kubevirt
kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml
Install the CRDs

Before the deploying the operator, we have to add the LabInstance and LabTemplate CRDs. This can be done via the Kubebuilder-provided Makefile:

make install
make install-lab-template

or directly via the commands:

kubectl kustomize config/crd | kubectl apply -f -
kubectl kustomize config/crd | kubectl delete -f -
Deployment

To deploy the LabOperator in your cluster, you have to do the following steps.

First, set the desired values in operators/labInstance-operator/k8s-manifest-example.env .

Then export the environment variables and generate the manifest from the template using:

export $(xargs < k8s-manifest-example.env)
envsubst < k8s-manifest.yaml.tmpl > k8s-manifest.yaml

After the manifest have been correctly generated. You can deploy the labOperator using:

kubectl apply -f k8s-manifest.yaml

Development

Build from source

LabOperator requires Golang 1.13 and make. To build the operator:

cd operators/labInstance-operator
go build
Testing

After having installed Kubevirt in your testing cluster, you have to deploy the Custom Resource Definitions (CRDs) on the target cluster:

make install
make install-lab-template

Then, you can launch locally your operator:

make run

N.B. So far, the readiness check for VirtualMachines is performed by assuming that the operator is running on the same cluster of the Virtual Machines. This prevents the possibility to have ready VMs when testing the operator outside the cluster.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api
v1alpha1
Package v1alpha1 contains API Schema definitions for the instance v1alpha1 API group +kubebuilder:object:generate=true +groupName=crownlabs.polito.it
Package v1alpha1 contains API Schema definitions for the instance v1alpha1 API group +kubebuilder:object:generate=true +groupName=crownlabs.polito.it
kubeVirt
api
api/v1
* This file is part of the KubeVirt project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
* This file is part of the KubeVirt project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
api/v1alpha1
Package v1alpha1 is the v1alpha1 version of the API.
Package v1alpha1 is the v1alpha1 version of the API.
labTemplate
api/v1alpha1
Package v1alpha1 contains API Schema definitions for the template v1alpha1 API group +kubebuilder:object:generate=true +groupName=crownlabs.polito.it
Package v1alpha1 contains API Schema definitions for the template v1alpha1 API group +kubebuilder:object:generate=true +groupName=crownlabs.polito.it
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL