Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add extended hardware information to Server and ServerClass CRDs #735

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ RUN --mount=type=cache,target=/.cache controller-gen \
FROM scratch AS manifests
COPY --from=manifests-build /src/app/caps-controller-manager/config ./app/caps-controller-manager/config
COPY --from=manifests-build /src/app/sidero-controller-manager/config ./app/sidero-controller-manager/config
COPY --from=manifests-build /src/app/webhook-server/config ./app/webhook-server/config

FROM base AS generate-build
COPY ./app/sidero-controller-manager/internal/api/api.proto \
Expand All @@ -79,6 +80,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 All @@ -94,12 +96,15 @@ COPY ./config ./config
COPY ./templates ./templates
COPY ./app/caps-controller-manager/config ./app/caps-controller-manager/config
COPY ./app/sidero-controller-manager/config ./app/sidero-controller-manager/config
COPY ./app/webhook-server/config ./app/webhook-server/config
ARG REGISTRY_AND_USERNAME
ARG TAG
RUN cd ./app/caps-controller-manager/config/manager \
&& kustomize edit set image controller=${REGISTRY_AND_USERNAME}/caps-controller-manager:${TAG}
RUN cd ./app/sidero-controller-manager/config/manager \
&& kustomize edit set image controller=${REGISTRY_AND_USERNAME}/sidero-controller-manager:${TAG}
RUN cd ./app/webhook-server/config/webhook-server \
&& kustomize edit set image controller=${REGISTRY_AND_USERNAME}/webhook-server:${TAG}
RUN kustomize build config > /infrastructure-components.yaml \
&& cp ./config/metadata/metadata.yaml /metadata.yaml \
&& cp ./templates/cluster-template.yaml /cluster-template.yaml
Expand Down Expand Up @@ -217,6 +222,23 @@ FROM sidero-controller-manager-image AS sidero-controller-manager
LABEL org.opencontainers.image.source https://github.com/siderolabs/sidero
ENTRYPOINT [ "/manager" ]

FROM base AS build-webhook-server
ARG TALOS_RELEASE
ARG TARGETARCH
ARG GO_BUILDFLAGS
ARG GO_LDFLAGS
RUN --mount=type=cache,target=/.cache GOOS=linux GOARCH=${TARGETARCH} go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS} -X main.TalosRelease=${TALOS_RELEASE}" -o /webhook-server ./app/webhook-server
RUN chmod +x /webhook-server

FROM scratch AS webhook-server
COPY --from=pkg-ca-certificates / /
COPY --from=pkg-fhs / /
COPY --from=pkg-musl / /
COPY --from=pkg-libressl / /
COPY --from=build-webhook-server /webhook-server /webhook-server
LABEL org.opencontainers.image.source https://github.com/talos-systems/sidero
ENTRYPOINT [ "/webhook-server" ]

FROM base AS unit-tests-runner
ARG TEST_PKGS
RUN --mount=type=cache,target=/.cache --mount=type=cache,id=testspace,target=/tmp --mount=type=cache,target=/root/.cache/go-build go test -v -covermode=atomic -coverprofile=coverage.txt -count 1 ${TEST_PKGS}
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ COMMON_ARGS += --build-arg=CGO_ENABLED=$(CGO_ENABLED)
COMMON_ARGS += --build-arg=GO_BUILDFLAGS="$(GO_BUILDFLAGS)"
COMMON_ARGS += --build-arg=GO_LDFLAGS="$(GO_LDFLAGS)"

all: manifests generate caps-controller-manager sidero-controller-manager sfyra
all: manifests generate caps-controller-manager sidero-controller-manager webhook-server sfyra


# Help Menu
Expand Down Expand Up @@ -139,6 +139,10 @@ caps-controller-manager: ## Build the CAPI provider container image.
sidero-controller-manager: ## Build the CAPI provider container image.
@$(MAKE) docker-$@ TARGET_ARGS="--push=$(PUSH)" NAME="$@"

.PHONY: webhook-server
webhook-server: ## Build the webhook server container image.
@$(MAKE) docker-$@ TARGET_ARGS="--push=$(PUSH)" NAME="$@"

.PHONY: release-notes
release-notes:
@mkdir -p $(ARTIFACTS)
Expand Down
20 changes: 7 additions & 13 deletions app/caps-controller-manager/config/crd/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# This file is for teaching kustomize how to substitute name and namespace reference in CRD
nameReference:
- kind: Service
version: v1
fieldSpecs:
- kind: CustomResourceDefinition
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/name

namespace:
- kind: CustomResourceDefinition
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/namespace
create: false
- kind: Service
version: v1
fieldSpecs:
- kind: CustomResourceDefinition
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/name

varReference:
- path: metadata/annotations
- path: metadata/annotations
39 changes: 1 addition & 38 deletions app/caps-controller-manager/config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,7 @@ namePrefix: caps-
commonLabels:
cluster.x-k8s.io/provider: "control-plane-talos"

bases:
resources:
- ../crd
- ../certmanager
- ../webhook
- ../rbac
- ../manager

patchesStrategicMerge:
- manager_webhook_patch.yaml
# - webhookcainjection_patch.yaml

vars:
- name: 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
fieldref:
fieldpath: metadata.namespace
- name: 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
objref:
kind: Service
version: v1
name: webhook-service
fieldref:
fieldpath: metadata.namespace
- name: SERVICE_NAME
objref:
kind: Service
version: v1
name: webhook-service

configurations:
- kustomizeconfig.yaml

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions app/caps-controller-manager/config/webhook/kustomization.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions app/caps-controller-manager/config/webhook/service.yaml

This file was deleted.

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"
metalv1 "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
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"
metalv1 "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
35 changes: 8 additions & 27 deletions app/caps-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"flag"
"os"
"sigs.k8s.io/controller-runtime/pkg/healthz"

debug "github.com/talos-systems/go-debug"
corev1 "k8s.io/api/core/v1"
Expand All @@ -16,7 +17,7 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
cgrecord "k8s.io/client-go/tools/record"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
Expand All @@ -25,6 +26,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 @@ -41,10 +43,11 @@ var (
//nolint:wsl
func init() {
_ = clientgoscheme.AddToScheme(scheme)
_ = capiv1.AddToScheme(scheme)
_ = capiv1beta1.AddToScheme(scheme)
_ = infrav1alpha2.AddToScheme(scheme)
_ = infrav1alpha3.AddToScheme(scheme)
_ = metalv1alpha1.AddToScheme(scheme)
_ = metalv1alpha2.AddToScheme(scheme)
// +kubebuilder:scaffold:scheme
}

Expand All @@ -53,14 +56,12 @@ func main() {
metricsAddr string
healthAddr string
enableLeaderElection bool
webhookPort int
)

flag.StringVar(&metricsAddr, "metrics-bind-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&healthAddr, "health-addr", ":9440", "The address the health endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", true,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
flag.IntVar(&webhookPort, "webhook-port", 9443, "Webhook Server port, disabled by default. When enabled, the manager will only work as webhook server, no reconcilers are installed.")
flag.Parse()

ctrl.SetLogger(zap.New(func(o *zap.Options) {
Expand Down Expand Up @@ -88,7 +89,7 @@ func main() {
MetricsBindAddress: metricsAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "controller-leader-election-capm",
Port: webhookPort,
Port: 9443,
EventBroadcaster: broadcaster,
HealthProbeBindAddress: healthAddr,
})
Expand Down Expand Up @@ -143,26 +144,6 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "ServerBinding")
os.Exit(1)
}

if err = (&infrav1alpha3.MetalCluster{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "MetalCluster")
os.Exit(1)
}

if err = (&infrav1alpha3.MetalMachine{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "MetalMachine")
os.Exit(1)
}

if err = (&infrav1alpha3.MetalMachineTemplate{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "MetalMachineTemplate")
os.Exit(1)
}

if err = (&infrav1alpha3.ServerBinding{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "ServerBinding")
os.Exit(1)
}
// +kubebuilder:scaffold:builder

setupChecks(mgr)
Expand All @@ -176,12 +157,12 @@ func main() {
}

func setupChecks(mgr ctrl.Manager) {
if err := mgr.AddReadyzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
if err := mgr.AddReadyzCheck("ping", healthz.Ping); err != nil {
setupLog.Error(err, "unable to create ready check")
os.Exit(1)
}

if err := mgr.AddHealthzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
if err := mgr.AddHealthzCheck("ping", healthz.Ping); err != nil {
setupLog.Error(err, "unable to create health check")
os.Exit(1)
}
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)
}
Loading