-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: restructure HW information in
Server
resources (v1alpha2)
This is basically subset of PR #735 with only CRD changes without actual code changes to use new CRDs. As storage version is v1alpha2, every access goes twice via conversion webhooks (for better test coverage). Other parts of #735 will be incorporated in a follow-up PR, I decided to split things up for easier review. Example: ```bash $ kubectl get servers.v1alpha1.metal.sidero.dev 49fd7c2d-1ba4-4157-8cc0-3f7212f119f0 -o yaml ... cpu: manufacturer: QEMU version: pc-q35-6.0 hostname: pxe-3 managementApi: endpoint: 172.25.0.1:39565 system: family: Unknown manufacturer: QEMU productName: Standard PC (Q35 + ICH9, 2009) serialNumber: Unknown skuNumber: Unknown version: pc-q35-6.0 $ kubectl get servers.v1alpha2.metal.sidero.dev 49fd7c2d-1ba4-4157-8cc0-3f7212f119f0 -o yaml ... hardware: compute: processors: - manufacturer: QEMU productName: pc-q35-6.0 system: family: Unknown manufacturer: QEMU productName: Standard PC (Q35 + ICH9, 2009) serialNumber: Unknown skuNumber: Unknown version: pc-q35-6.0 ``` We can make more changes to v1alpha2 resources in follow-up PRs. Co-authored-by: Gerard de Leeuw <gdeleeuw@leeuwit.nl> Signed-off-by: Gerard de Leeuw <gdeleeuw@leeuwit.nl> Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
- Loading branch information
Showing
37 changed files
with
4,310 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,5 @@ spec: | |
caBundle: Cg== | ||
service: | ||
namespace: system | ||
name: webhook-service | ||
name: caps-webhook-service | ||
path: /convert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,5 @@ spec: | |
caBundle: Cg== | ||
service: | ||
namespace: system | ||
name: webhook-service | ||
name: caps-webhook-service | ||
path: /convert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,5 @@ spec: | |
caBundle: Cg== | ||
service: | ||
namespace: system | ||
name: webhook-service | ||
name: caps-webhook-service | ||
path: /convert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,5 @@ spec: | |
caBundle: Cg== | ||
service: | ||
namespace: system | ||
name: webhook-service | ||
name: caps-webhook-service | ||
path: /convert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package v1alpha1 | ||
|
||
// +k8s:conversion-gen=github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha2 |
56 changes: 56 additions & 0 deletions
56
app/sidero-controller-manager/api/v1alpha1/environment_conversion.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
//nolint:golint,stylecheck | ||
package v1alpha1 | ||
|
||
import ( | ||
utilconversion "sigs.k8s.io/cluster-api/util/conversion" | ||
"sigs.k8s.io/controller-runtime/pkg/conversion" | ||
|
||
metalv1alpha2 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha2" | ||
) | ||
|
||
// ConvertTo converts this Environment to the Hub version (v1alpha2). | ||
func (src *Environment) ConvertTo(dstRaw conversion.Hub) error { | ||
dst := dstRaw.(*metalv1alpha2.Environment) | ||
if err := Convert_v1alpha1_Environment_To_v1alpha2_Environment(src, dst, nil); err != nil { | ||
return err | ||
} | ||
|
||
// Manually restore data from annotations | ||
restored := &metalv1alpha2.Environment{} | ||
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ConvertFrom converts from the Hub version (v1alpha3) to this version. | ||
func (dst *Environment) ConvertFrom(srcRaw conversion.Hub) error { | ||
src := srcRaw.(*metalv1alpha2.Environment) | ||
if err := Convert_v1alpha2_Environment_To_v1alpha1_Environment(src, dst, nil); err != nil { | ||
return err | ||
} | ||
|
||
// Preserve Hub data on down-conversion. | ||
if err := utilconversion.MarshalData(src, dst); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ConvertTo converts this MetalMachineTemplateList to the Hub version (v1alpha3). | ||
func (src *EnvironmentList) ConvertTo(dstRaw conversion.Hub) error { | ||
dst := dstRaw.(*metalv1alpha2.EnvironmentList) | ||
return Convert_v1alpha1_EnvironmentList_To_v1alpha2_EnvironmentList(src, dst, nil) | ||
} | ||
|
||
// ConvertFrom converts from the Hub version (v1alpha3) to this version. | ||
func (dst *EnvironmentList) ConvertFrom(srcRaw conversion.Hub) error { | ||
src := srcRaw.(*metalv1alpha2.EnvironmentList) | ||
return Convert_v1alpha2_EnvironmentList_To_v1alpha1_EnvironmentList(src, dst, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
app/sidero-controller-manager/api/v1alpha1/server_conversion.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
//nolint:golint,stylecheck | ||
package v1alpha1 | ||
|
||
import ( | ||
apiconversion "k8s.io/apimachinery/pkg/conversion" | ||
utilconversion "sigs.k8s.io/cluster-api/util/conversion" | ||
"sigs.k8s.io/controller-runtime/pkg/conversion" | ||
|
||
metalv1alpha2 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha2" | ||
) | ||
|
||
// ConvertTo converts this Server to the Hub version (v1alpha2). | ||
func (src *Server) ConvertTo(dstRaw conversion.Hub) error { | ||
dst := dstRaw.(*metalv1alpha2.Server) | ||
if err := Convert_v1alpha1_Server_To_v1alpha2_Server(src, dst, nil); err != nil { | ||
return err | ||
} | ||
|
||
// Manually restore data from annotations | ||
restored := &metalv1alpha2.Server{} | ||
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ConvertFrom converts from the Hub version (v1alpha3) to this version. | ||
func (dst *Server) ConvertFrom(srcRaw conversion.Hub) error { | ||
src := srcRaw.(*metalv1alpha2.Server) | ||
if err := Convert_v1alpha2_Server_To_v1alpha1_Server(src, dst, nil); err != nil { | ||
return err | ||
} | ||
|
||
// Preserve Hub data on down-conversion. | ||
if err := utilconversion.MarshalData(src, dst); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ConvertTo converts this MetalMachineTemplateList to the Hub version (v1alpha3). | ||
func (src *ServerList) ConvertTo(dstRaw conversion.Hub) error { | ||
dst := dstRaw.(*metalv1alpha2.ServerList) | ||
return Convert_v1alpha1_ServerList_To_v1alpha2_ServerList(src, dst, nil) | ||
} | ||
|
||
// ConvertFrom converts from the Hub version (v1alpha3) to this version. | ||
func (dst *ServerList) ConvertFrom(srcRaw conversion.Hub) error { | ||
src := srcRaw.(*metalv1alpha2.ServerList) | ||
return Convert_v1alpha2_ServerList_To_v1alpha1_ServerList(src, dst, nil) | ||
} | ||
|
||
// Convert_v1alpha1_ServerSpec_To_v1alpha2_ServerSpec converts to the Hub version (v1alpha2). | ||
func Convert_v1alpha1_ServerSpec_To_v1alpha2_ServerSpec(in *ServerSpec, out *metalv1alpha2.ServerSpec, s apiconversion.Scope) error { | ||
if err := autoConvert_v1alpha1_ServerSpec_To_v1alpha2_ServerSpec(in, out, s); err != nil { | ||
return err | ||
} | ||
|
||
// Manually convert SystemInformation to Hardware. | ||
if in.SystemInformation != nil { | ||
if out.Hardware == nil { | ||
out.Hardware = &metalv1alpha2.HardwareInformation{} | ||
} | ||
out.Hardware.System = &metalv1alpha2.SystemInformation{ | ||
Manufacturer: in.SystemInformation.Manufacturer, | ||
ProductName: in.SystemInformation.ProductName, | ||
Version: in.SystemInformation.Version, | ||
SerialNumber: in.SystemInformation.SerialNumber, | ||
SKUNumber: in.SystemInformation.SKUNumber, | ||
Family: in.SystemInformation.Family, | ||
} | ||
} | ||
|
||
// Manually convert CPU to Hardware. | ||
if in.CPU != nil { | ||
if out.Hardware == nil { | ||
out.Hardware = &metalv1alpha2.HardwareInformation{} | ||
} | ||
out.Hardware.Compute = &metalv1alpha2.ComputeInformation{ | ||
Processors: []*metalv1alpha2.Processor{ | ||
{ | ||
Manufacturer: in.CPU.Manufacturer, | ||
ProductName: in.CPU.Version, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Convert_v1alpha2_ServerSpec_To_v1alpha1_ServerSpec converts from the Hub version (v1alpha2). | ||
func Convert_v1alpha2_ServerSpec_To_v1alpha1_ServerSpec(in *metalv1alpha2.ServerSpec, out *ServerSpec, s apiconversion.Scope) error { | ||
if err := autoConvert_v1alpha2_ServerSpec_To_v1alpha1_ServerSpec(in, out, s); err != nil { | ||
return err | ||
} | ||
|
||
// Manually convert Hardware to SystemInformation. | ||
if in.Hardware != nil && in.Hardware.System != nil { | ||
out.SystemInformation = &SystemInformation{ | ||
Manufacturer: in.Hardware.System.Manufacturer, | ||
ProductName: in.Hardware.System.ProductName, | ||
Version: in.Hardware.System.Version, | ||
SerialNumber: in.Hardware.System.SerialNumber, | ||
SKUNumber: in.Hardware.System.SKUNumber, | ||
Family: in.Hardware.System.Family, | ||
} | ||
} | ||
|
||
// Manually convert Hardware to CPU. | ||
if in.Hardware != nil && in.Hardware.Compute != nil && len(in.Hardware.Compute.Processors) > 0 { | ||
cpu := in.Hardware.Compute.Processors[0] | ||
out.CPU = &CPUInformation{ | ||
Manufacturer: cpu.Manufacturer, | ||
Version: cpu.ProductName, | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func Convert_v1alpha2_SystemInformation_To_v1alpha1_SystemInformation(in *metalv1alpha2.SystemInformation, out *SystemInformation, s apiconversion.Scope) error { | ||
return autoConvert_v1alpha2_SystemInformation_To_v1alpha1_SystemInformation(in, out, s) | ||
} |
124 changes: 124 additions & 0 deletions
124
app/sidero-controller-manager/api/v1alpha1/serverclass_conversion.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
//nolint:golint,stylecheck | ||
package v1alpha1 | ||
|
||
import ( | ||
apiconversion "k8s.io/apimachinery/pkg/conversion" | ||
utilconversion "sigs.k8s.io/cluster-api/util/conversion" | ||
"sigs.k8s.io/controller-runtime/pkg/conversion" | ||
|
||
metalv1alpha2 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha2" | ||
) | ||
|
||
// ConvertTo converts this ServerClass to the Hub version (v1alpha2). | ||
func (src *ServerClass) ConvertTo(dstRaw conversion.Hub) error { | ||
dst := dstRaw.(*metalv1alpha2.ServerClass) | ||
if err := Convert_v1alpha1_ServerClass_To_v1alpha2_ServerClass(src, dst, nil); err != nil { | ||
return err | ||
} | ||
|
||
// Manually restore data from annotations | ||
restored := &metalv1alpha2.ServerClass{} | ||
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ConvertFrom converts from the Hub version (v1alpha3) to this version. | ||
func (dst *ServerClass) ConvertFrom(srcRaw conversion.Hub) error { | ||
src := srcRaw.(*metalv1alpha2.ServerClass) | ||
if err := Convert_v1alpha2_ServerClass_To_v1alpha1_ServerClass(src, dst, nil); err != nil { | ||
return err | ||
} | ||
|
||
// Preserve Hub data on down-conversion. | ||
if err := utilconversion.MarshalData(src, dst); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ConvertTo converts this MetalMachineTemplateList to the Hub version (v1alpha3). | ||
func (src *ServerClassList) ConvertTo(dstRaw conversion.Hub) error { | ||
dst := dstRaw.(*metalv1alpha2.ServerClassList) | ||
return Convert_v1alpha1_ServerClassList_To_v1alpha2_ServerClassList(src, dst, nil) | ||
} | ||
|
||
// ConvertFrom converts from the Hub version (v1alpha3) to this version. | ||
func (dst *ServerClassList) ConvertFrom(srcRaw conversion.Hub) error { | ||
src := srcRaw.(*metalv1alpha2.ServerClassList) | ||
return Convert_v1alpha2_ServerClassList_To_v1alpha1_ServerClassList(src, dst, nil) | ||
} | ||
|
||
// Convert_v1alpha1_Qualifiers_To_v1alpha2_Qualifiers converts to the Hub version (v1alpha2). | ||
func Convert_v1alpha1_Qualifiers_To_v1alpha2_Qualifiers(in *Qualifiers, out *metalv1alpha2.Qualifiers, s apiconversion.Scope) error { | ||
if err := autoConvert_v1alpha1_Qualifiers_To_v1alpha2_Qualifiers(in, out, s); err != nil { | ||
return err | ||
} | ||
|
||
// Manually convert SystemInformation to Hardware. | ||
for _, v := range in.SystemInformation { | ||
out.Hardware = append(out.Hardware, metalv1alpha2.HardwareInformation{ | ||
System: &metalv1alpha2.SystemInformation{ | ||
Manufacturer: v.Manufacturer, | ||
ProductName: v.ProductName, | ||
Version: v.Version, | ||
SerialNumber: v.SerialNumber, | ||
SKUNumber: v.SKUNumber, | ||
Family: v.Family, | ||
}, | ||
}) | ||
} | ||
|
||
// Manually convert CPU to Hardware. | ||
for _, v := range in.CPU { | ||
out.Hardware = append(out.Hardware, metalv1alpha2.HardwareInformation{ | ||
Compute: &metalv1alpha2.ComputeInformation{ | ||
Processors: []*metalv1alpha2.Processor{ | ||
{ | ||
Manufacturer: v.Manufacturer, | ||
ProductName: v.Version, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Convert_v1alpha2_Qualifiers_To_v1alpha1_Qualifiers converts from the Hub version (v1alpha2). | ||
func Convert_v1alpha2_Qualifiers_To_v1alpha1_Qualifiers(in *metalv1alpha2.Qualifiers, out *Qualifiers, s apiconversion.Scope) error { | ||
if err := autoConvert_v1alpha2_Qualifiers_To_v1alpha1_Qualifiers(in, out, s); err != nil { | ||
return err | ||
} | ||
|
||
// Manually convert Hardware to SystemInformation or CPU. | ||
for _, v := range in.Hardware { | ||
if v.System != nil { | ||
out.SystemInformation = append(out.SystemInformation, SystemInformation{ | ||
Manufacturer: v.System.Manufacturer, | ||
ProductName: v.System.ProductName, | ||
Version: v.System.Version, | ||
SerialNumber: v.System.SerialNumber, | ||
SKUNumber: v.System.SKUNumber, | ||
Family: v.System.Family, | ||
}) | ||
} | ||
if v.Compute != nil && len(v.Compute.Processors) > 0 { | ||
cpu := v.Compute.Processors[0] | ||
out.CPU = append(out.CPU, CPUInformation{ | ||
Manufacturer: cpu.Manufacturer, | ||
Version: cpu.ProductName, | ||
}) | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.