Skip to content

Commit

Permalink
feat: add extended hardware information to Server and ServerClass CRDs
Browse files Browse the repository at this point in the history
This change adds detailed hardware information to the Server CRD.
Hardware info is extracted by the agent from SMBIOS.
The ServerClass CRD is also updated so more precise qualifiers can be used.

Signed-off-by: Gerard de Leeuw <gdeleeuw@leeuwit.nl>
  • Loading branch information
lion7 committed Mar 26, 2022
1 parent 5fb30a9 commit bf99ecc
Show file tree
Hide file tree
Showing 106 changed files with 6,263 additions and 832 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ RUN protoc -I/src/app/sidero-controller-manager/internal/api \
api.proto
RUN --mount=type=cache,target=/.cache controller-gen object:headerFile="./hack/boilerplate.go.txt" paths="./..."
RUN --mount=type=cache,target=/.cache conversion-gen --input-dirs="./app/caps-controller-manager/api/v1alpha2" --output-base ./ --output-file-base="zz_generated.conversion" --go-header-file="./hack/boilerplate.go.txt"
RUN --mount=type=cache,target=/.cache conversion-gen --input-dirs="./app/sidero-controller-manager/api/v1alpha1" --output-base ./ --output-file-base="zz_generated.conversion" --go-header-file="./hack/boilerplate.go.txt"
ARG MODULE
RUN --mount=type=cache,target=/.cache gofumports -w -local ${MODULE} .

Expand Down
14 changes: 7 additions & 7 deletions app/caps-controller-manager/config/certmanager/certificate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: selfsigned-issuer
name: caps-selfsigned-issuer
namespace: system
spec:
selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
name: caps-serving-cert # this name should match the one appeared in kustomizeconfig.yaml
namespace: system
spec:
# $(SERVICE_NAME) and $(SERVICE_NAMESPACE) will be substituted by kustomize
# $(CAPS_WEBHOOK_SERVICE_NAME) and $(CAPS_WEBHOOK_SERVICE_NAMESPACE) will be substituted by kustomize
dnsNames:
- $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc
- $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc.cluster.local
- $(CAPS_WEBHOOK_SERVICE_NAME).$(CAPS_WEBHOOK_SERVICE_NAMESPACE).svc
- $(CAPS_WEBHOOK_SERVICE_NAME).$(CAPS_WEBHOOK_SERVICE_NAMESPACE).svc.cluster.local
issuerRef:
kind: Issuer
name: selfsigned-issuer
secretName: $(SERVICE_NAME)-cert
name: caps-selfsigned-issuer
secretName: $(CAPS_WEBHOOK_SERVICE_NAME)-cert
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
cert-manager.io/inject-ca-from: $(CAPS_CERTIFICATE_NAMESPACE)/$(CAPS_CERTIFICATE_NAME)
name: metalclusters.infrastructure.cluster.x-k8s.io
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
cert-manager.io/inject-ca-from: $(CAPS_CERTIFICATE_NAMESPACE)/$(CAPS_CERTIFICATE_NAME)
name: metalmachines.infrastructure.cluster.x-k8s.io
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
cert-manager.io/inject-ca-from: $(CAPS_CERTIFICATE_NAMESPACE)/$(CAPS_CERTIFICATE_NAME)
name: metalmachinetemplates.infrastructure.cluster.x-k8s.io
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
cert-manager.io/inject-ca-from: $(CAPS_CERTIFICATE_NAMESPACE)/$(CAPS_CERTIFICATE_NAME)
name: serverbindings.infrastructure.cluster.x-k8s.io
16 changes: 8 additions & 8 deletions app/caps-controller-manager/config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ patchesStrategicMerge:
# - webhookcainjection_patch.yaml

vars:
- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
- name: CAPS_CERTIFICATE_NAMESPACE # namespace of the certificate CR
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: serving-cert # this name should match the one in certificate.yaml
name: caps-serving-cert # this name should match the one in certificate.yaml
fieldref:
fieldpath: metadata.namespace
- name: CERTIFICATE_NAME
- name: CAPS_CERTIFICATE_NAME
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: serving-cert # this name should match the one in certificate.yaml
- name: SERVICE_NAMESPACE # namespace of the service
name: caps-serving-cert # this name should match the one in certificate.yaml
- name: CAPS_WEBHOOK_SERVICE_NAMESPACE # namespace of the service
objref:
kind: Service
version: v1
name: webhook-service
name: caps-webhook-service
fieldref:
fieldpath: metadata.namespace
- name: SERVICE_NAME
- name: CAPS_WEBHOOK_SERVICE_NAME
objref:
kind: Service
version: v1
name: webhook-service
name: caps-webhook-service

configurations:
- kustomizeconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ spec:
- name: cert
secret:
defaultMode: 420
secretName: $(SERVICE_NAME)-cert
secretName: $(CAPS_WEBHOOK_SERVICE_NAME)-cert
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# This patch add annotation to admission webhook config and
# the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize.
# the variables $(CAPS_CERTIFICATE_NAMESPACE) and $(CAPS_CERTIFICATE_NAME) will be substituted by kustomize.
apiVersion: admissionregistration.k8s.io/v1beta1
kind: MutatingWebhookConfiguration
metadata:
name: mutating-webhook-configuration
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
cert-manager.io/inject-ca-from: $(CAPS_CERTIFICATE_NAMESPACE)/$(CAPS_CERTIFICATE_NAME)
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
metadata:
name: validating-webhook-configuration
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
cert-manager.io/inject-ca-from: $(CAPS_CERTIFICATE_NAMESPACE)/$(CAPS_CERTIFICATE_NAME)
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ resources:
- service.yaml

configurations:
- kustomizeconfig.yaml
- kustomizeconfig.yaml
3 changes: 1 addition & 2 deletions app/caps-controller-manager/config/webhook/service.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

apiVersion: v1
kind: Service
metadata:
name: webhook-service
name: caps-webhook-service
namespace: system
spec:
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

infrav1 "github.com/talos-systems/sidero/app/caps-controller-manager/api/v1alpha3"
"github.com/talos-systems/sidero/app/caps-controller-manager/pkg/constants"
metalv1alpha1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
metalv1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha2"
)

var ErrNoServersInServerClass = errors.New("no servers available in serverclass")
Expand Down Expand Up @@ -265,7 +265,7 @@ func (r *MetalMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.
Complete(r)
}

func (r *MetalMachineReconciler) fetchServerFromClass(ctx context.Context, logger logr.Logger, classRef *corev1.ObjectReference, metalMachine *infrav1.MetalMachine) (*metalv1alpha1.Server, error) {
func (r *MetalMachineReconciler) fetchServerFromClass(ctx context.Context, logger logr.Logger, classRef *corev1.ObjectReference, metalMachine *infrav1.MetalMachine) (*metalv1.Server, error) {
// First, check if there is already existing serverBinding for this metalmachine
var serverBindingList infrav1.ServerBindingList

Expand All @@ -276,7 +276,7 @@ func (r *MetalMachineReconciler) fetchServerFromClass(ctx context.Context, logge
for _, serverBinding := range serverBindingList.Items {
if serverBinding.Spec.MetalMachineRef.Namespace == metalMachine.Namespace && serverBinding.Spec.MetalMachineRef.Name == metalMachine.Name {
// found existing serverBinding for this metalMachine
var server metalv1alpha1.Server
var server metalv1.Server

if err := r.Get(ctx, types.NamespacedName{Namespace: serverBinding.Namespace, Name: serverBinding.Name}, &server); err != nil {
return nil, err
Expand All @@ -302,7 +302,7 @@ func (r *MetalMachineReconciler) fetchServerFromClass(ctx context.Context, logge
// NB: we added this loop to double check that an available server isn't "in use" because
// we saw raciness between server selection and it being removed from the ServersAvailable list.
for _, availServer := range serverClassResource.Status.ServersAvailable {
serverObj := &metalv1alpha1.Server{}
serverObj := &metalv1.Server{}

namespacedName := types.NamespacedName{
Namespace: "",
Expand Down Expand Up @@ -408,7 +408,7 @@ func (r *MetalMachineReconciler) patchProviderID(ctx context.Context, cluster *c
}

// createServerBinding updates a server to mark it as "in use" via ServerBinding resource.
func (r *MetalMachineReconciler) createServerBinding(ctx context.Context, serverClass *metalv1alpha1.ServerClass, serverObj *metalv1alpha1.Server, metalMachine *infrav1.MetalMachine) error {
func (r *MetalMachineReconciler) createServerBinding(ctx context.Context, serverClass *metalv1.ServerClass, serverObj *metalv1.Server, metalMachine *infrav1.MetalMachine) error {
serverRef, err := reference.GetReference(r.Scheme, serverObj)
if err != nil {
return err
Expand Down Expand Up @@ -445,8 +445,8 @@ func (r *MetalMachineReconciler) createServerBinding(ctx context.Context, server
return err
}

func (r *MetalMachineReconciler) fetchServerClass(ctx context.Context, classRef *corev1.ObjectReference) (*metalv1alpha1.ServerClass, error) {
serverClassResource := &metalv1alpha1.ServerClass{}
func (r *MetalMachineReconciler) fetchServerClass(ctx context.Context, classRef *corev1.ObjectReference) (*metalv1.ServerClass, error) {
serverClassResource := &metalv1.ServerClass{}

namespacedName := types.NamespacedName{
Namespace: classRef.Namespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"

infrav1 "github.com/talos-systems/sidero/app/caps-controller-manager/api/v1alpha3"
metalv1alpha1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
metalv1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha2"
)

// ServerBindingReconciler reconciles a ServerBinding object.
Expand Down Expand Up @@ -75,7 +75,7 @@ func (r *ServerBindingReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}
}()

var server metalv1alpha1.Server
var server metalv1.Server

err = r.Get(ctx, req.NamespacedName, &server)
if err != nil {
Expand Down Expand Up @@ -190,7 +190,7 @@ func (r *ServerBindingReconciler) reconcileTransition(ctx context.Context, logge
return ctrl.Result{}, nil
}

var server metalv1alpha1.Server
var server metalv1.Server

if err = r.Get(ctx, req.NamespacedName, &server); err != nil {
if apierrors.IsNotFound(err) {
Expand Down
2 changes: 2 additions & 0 deletions app/caps-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
infrav1alpha3 "github.com/talos-systems/sidero/app/caps-controller-manager/api/v1alpha3"
"github.com/talos-systems/sidero/app/caps-controller-manager/controllers"
metalv1alpha1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
metalv1alpha2 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha2"
// +kubebuilder:scaffold:imports
)

Expand All @@ -45,6 +46,7 @@ func init() {
_ = infrav1alpha2.AddToScheme(scheme)
_ = infrav1alpha3.AddToScheme(scheme)
_ = metalv1alpha1.AddToScheme(scheme)
_ = metalv1alpha2.AddToScheme(scheme)
// +kubebuilder:scaffold:scheme
}

Expand Down
9 changes: 9 additions & 0 deletions app/sidero-controller-manager/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ resources:
- group: metal
kind: ServerClass
version: v1alpha1
- group: metal
kind: Environment
version: v1alpha2
- group: metal
kind: Server
version: v1alpha2
- group: metal
kind: ServerClass
version: v1alpha2
version: "2"
7 changes: 7 additions & 0 deletions app/sidero-controller-manager/api/v1alpha1/doc.go
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
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ var (

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme

// localSchemeBuilder is used for type conversions.
localSchemeBuilder = SchemeBuilder.SchemeBuilder
)
Loading

0 comments on commit bf99ecc

Please sign in to comment.