Skip to content

Commit 426601d

Browse files
committed
Embedd hypervisor-crd, inital switch to hypervisor-crd based controllers
1 parent b05f27c commit 426601d

20 files changed

Lines changed: 1117 additions & 259 deletions

api/v1/hypervisor_types.go

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/*
2+
SPDX-FileCopyrightText: Copyright 2024 SAP SE or an SAP affiliate company and cobaltcore-dev contributors
3+
SPDX-License-Identifier: Apache-2.0
4+
5+
Licensed under the Apache License, LibVirtVersion 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package v1
19+
20+
import (
21+
"k8s.io/apimachinery/pkg/api/resource"
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/apimachinery/pkg/types"
24+
)
25+
26+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
27+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
28+
// Important: Run "make" to regenerate code after modifying this file
29+
30+
const (
31+
// ConditionTypeReady is the type of condition for ready status of a hypervisor
32+
ConditionTypeReady = "Ready"
33+
)
34+
35+
// HypervisorSpec defines the desired state of Hypervisor
36+
type HypervisorSpec struct {
37+
// +kubebuilder:validation:Optional
38+
// OperatingSystemVersion represents the desired operating system version.
39+
OperatingSystemVersion string `json:"version,omitempty"`
40+
41+
// +kubebuilder:default:=false
42+
// Reboot request an reboot after successful installation of an upgrade.
43+
Reboot bool `json:"reboot"`
44+
45+
// +kubebuilder:default:=true
46+
// EvacuateOnReboot request an evacuation of all instances before reboot.
47+
EvacuateOnReboot bool `json:"evacuateOnReboot"`
48+
49+
// +kubebuilder:default:=true
50+
// LifecycleEnabled enables the lifecycle management of the hypervisor via hypervisor-operator.
51+
LifecycleEnabled bool `json:"lifecycleEnabled"`
52+
53+
// +kubebuilder:default:=false
54+
// SkipTests skips the tests during the onboarding process.
55+
SkipTests bool `json:"skipTests"`
56+
57+
// +kubebuilder:default:={}
58+
// CustomTraits are used to apply custom traits to the hypervisor.
59+
CustomTraits []string `json:"customTraits"`
60+
61+
// +kubebuilder:default:=true
62+
// HighAvailability is used to enable the high availability handling of the hypervisor.
63+
HighAvailability bool `json:"highAvailability"`
64+
65+
// +kubebuilder:default:=false
66+
// Require to issue a certificate from cert-manager for the hypervisor, to be used for
67+
// secure communication with the libvirt API.
68+
CreateCertManagerCertificate bool `json:"createCertManagerCertificate"`
69+
70+
// +kubebuilder:default:=true
71+
// InstallCertificate is used to enable the installations of the certificates via kvm-node-agent.
72+
InstallCertificate bool `json:"installCertificate"`
73+
}
74+
75+
type Instance struct {
76+
// Represents the instance ID (uuidv4).
77+
ID string `json:"id"`
78+
79+
// Represents the instance name.
80+
Name string `json:"name"`
81+
82+
// Represents the instance state.
83+
Active bool `json:"active"`
84+
}
85+
86+
type HyperVisorUpdateStatus struct {
87+
// +kubebuilder:default:=false
88+
// Represents a running Operating System update.
89+
InProgress bool `json:"inProgress"`
90+
91+
// +kubebuilder:default:=unknown
92+
// Represents the Operating System installed update version.
93+
Installed string `json:"installed,omitempty"`
94+
95+
// +kubebuilder:default:=3
96+
// Represents the number of retries.
97+
Retry int `json:"retry"`
98+
}
99+
100+
type OperatingSystemStatus struct {
101+
// Represents the Operating System version.
102+
Version string `json:"version,omitempty"`
103+
104+
// PrettyVersion
105+
PrettyVersion string `json:"prettyVersion,omitempty"`
106+
107+
// KernelName
108+
KernelName string `json:"kernelName,omitempty"`
109+
110+
// KernelRelease
111+
KernelRelease string `json:"kernelRelease,omitempty"`
112+
113+
// KernelVersion
114+
KernelVersion string `json:"kernelVersion,omitempty"`
115+
116+
// HardwareVendor
117+
HardwareVendor string `json:"hardwareVendor,omitempty"`
118+
119+
// HardwareModel
120+
HardwareModel string `json:"hardwareModel,omitempty"`
121+
122+
// HardwareSerial
123+
HardwareSerial string `json:"hardwareSerial,omitempty"`
124+
125+
// FirmwareVersion
126+
FirmwareVersion string `json:"firmwareVersion,omitempty"`
127+
128+
// FirmwareVendor
129+
FirmwareVendor string `json:"firmwareVendor,omitempty"`
130+
131+
// FirmwareDate
132+
FirmwareDate metav1.Time `json:"firmwareDate,omitempty"`
133+
}
134+
135+
// Current capabilities reported by libvirt.
136+
type CapabilitiesStatus struct {
137+
// +kubebuilder:default:=unknown
138+
// The hosts CPU architecture (not the guests).
139+
HostCpuArch string `json:"cpuArch,omitempty"`
140+
// Total host memory available as a sum of memory over all numa cells.
141+
HostMemory resource.Quantity `json:"memory,omitempty"`
142+
// Total host cpus available as a sum of cpus over all numa cells.
143+
HostCpus resource.Quantity `json:"cpus,omitempty"`
144+
}
145+
146+
// HypervisorStatus defines the observed state of Hypervisor
147+
type HypervisorStatus struct {
148+
// +kubebuilder:default:=unknown
149+
// Represents the LibVirt version.
150+
LibVirtVersion string `json:"libVirtVersion"`
151+
152+
// Represents the Operating System status.
153+
OperatingSystem OperatingSystemStatus `json:"operatingSystem,omitempty"`
154+
155+
// Represents the Hypervisor update status.
156+
Update HyperVisorUpdateStatus `json:"updateStatus"`
157+
158+
// Represents the Hypervisor node name.
159+
Node types.NodeName `json:"node"`
160+
161+
// Represents the Hypervisor hosted Virtual Machines
162+
Instances []Instance `json:"instances,omitempty"`
163+
164+
// The capabilities of the hypervisors as reported by libvirt.
165+
Capabilities CapabilitiesStatus `json:"capabilities,omitempty"`
166+
167+
// +kubebuilder:default:=0
168+
// Represent the num of instances
169+
NumInstances int `json:"numInstances"`
170+
171+
// HypervisorID is the unique identifier of the hypervisor in OpenStack.
172+
HypervisorID string `json:"hypervisorId,omitempty"`
173+
174+
// ServiceID is the unique identifier of the compute service in OpenStack.
175+
ServiceID string `json:"serviceId,omitempty"`
176+
177+
// Represents the Hypervisor node conditions.
178+
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
179+
180+
SpecHash string `json:"specHash,omitempty"`
181+
}
182+
183+
// +kubebuilder:object:root=true
184+
// +kubebuilder:subresource:status
185+
// +kubebuilder:resource:scope=Cluster,shortName=hv
186+
// +kubebuilder:printcolumn:JSONPath=".status.conditions[?(@.type==\"Ready\")].reason",name="State",type="string"
187+
// +kubebuilder:printcolumn:JSONPath=".spec.lifecycleEnabled",name="Lifecycle",type="boolean"
188+
// +kubebuilder:printcolumn:JSONPath=".spec.highAvailability",name="High Availability",type="boolean"
189+
// +kubebuilder:printcolumn:JSONPath=".status.operatingSystem.prettyVersion",name="Version",type="string"
190+
// +kubebuilder:printcolumn:JSONPath=".status.numInstances",name="Instances",type="integer"
191+
// +kubebuilder:printcolumn:JSONPath=".status.operatingSystem.hardwareModel",name="Hardware",type="string",priority=2
192+
// +kubebuilder:printcolumn:JSONPath=".status.operatingSystem.kernelRelease",name="Kernel",type="string",priority=2
193+
// +kubebuilder:printcolumn:JSONPath=".status.conditions[?(@.type==\"Onboarding\")].reason",name="Onboarding",type="string",priority=3
194+
// +kubebuilder:printcolumn:JSONPath=".status.serviceId",name="Service ID",type="string",priority=3
195+
// +kubebuilder:printcolumn:JSONPath=".status.hypervisorId",name="Hypervisor ID",type="string",priority=3
196+
// +kubebuilder:printcolumn:JSONPath=".metadata.creationTimestamp",name="Age",type="date"
197+
198+
// Hypervisor is the Schema for the hypervisors API
199+
type Hypervisor struct {
200+
metav1.TypeMeta `json:",inline"`
201+
metav1.ObjectMeta `json:"metadata,omitempty"`
202+
203+
Spec HypervisorSpec `json:"spec,omitempty"`
204+
Status HypervisorStatus `json:"status,omitempty"`
205+
}
206+
207+
// +kubebuilder:object:root=true
208+
209+
// HypervisorList contains a list of Hypervisor
210+
type HypervisorList struct {
211+
metav1.TypeMeta `json:",inline"`
212+
metav1.ListMeta `json:"metadata,omitempty"`
213+
Items []Hypervisor `json:"items"`
214+
}
215+
216+
func init() {
217+
SchemeBuilder.Register(&Hypervisor{}, &HypervisorList{})
218+
}

0 commit comments

Comments
 (0)