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

✨ HostFirmwareComponents CRD and Controller & Tests #1559

Merged
merged 1 commit into from
Apr 5, 2024
Merged
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
3 changes: 2 additions & 1 deletion PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: metal3.io
group: metal3.io
kind: HostFirmwareComponents
path: github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha
path: github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
Expand Down
9 changes: 3 additions & 6 deletions apis/metal3.io/v1alpha1/hostfirmwarecomponents_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// FirmwareUpdate defines a firmware update specification.
type FirmwareUpdate struct {
Component string `json:"component"`
Expand All @@ -34,9 +32,9 @@ type FirmwareUpdate struct {
type FirmwareComponentStatus struct {
Component string `json:"component"`
InitialVersion string `json:"initialVersion"`
CurrentVersion string `json:"currentVersion"`
LastVersionFlashed string `json:"lastVersionFlashed"`
UpdatedAt metav1.Time `json:"updatedAt"`
CurrentVersion string `json:"currentVersion,omitempty"`
LastVersionFlashed string `json:"lastVersionFlashed,omitempty"`
UpdatedAt metav1.Time `json:"updatedAt,omitempty"`
}

type UpdatesConditionType string
Expand Down Expand Up @@ -77,7 +75,6 @@ type HostFirmwareComponentsStatus struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:shortName=hfc
//+kubebuilder:subresource:status

// HostFirmwareComponents is the Schema for the hostfirmwarecomponents API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func TestValidateHostFirmwareComponents(t *testing.T) {
Component: "bios",
InitialVersion: "1.0",
CurrentVersion: "1.0",
UpdatedAt: metav1.NewTime(time.Now()),
},
{
Component: "bmc",
Expand Down
5 changes: 0 additions & 5 deletions config/base/crds/bases/metal3.io_hostfirmwarecomponents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ spec:
kind: HostFirmwareComponents
listKind: HostFirmwareComponentsList
plural: hostfirmwarecomponents
shortNames:
- hfc
singular: hostfirmwarecomponents
scope: Namespaced
versions:
Expand Down Expand Up @@ -77,10 +75,7 @@ spec:
type: string
required:
- component
- currentVersion
- initialVersion
- lastVersionFlashed
- updatedAt
type: object
type: array
conditions:
Expand Down
3 changes: 3 additions & 0 deletions config/base/crds/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# It should be run by config/default
resources:
- bases/metal3.io_baremetalhosts.yaml
- bases/metal3.io_hostfirmwarecomponents.yaml
- bases/metal3.io_hostfirmwaresettings.yaml
- bases/metal3.io_firmwareschemas.yaml
- bases/metal3.io_preprovisioningimages.yaml
Expand All @@ -15,6 +16,7 @@ patches:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_baremetalhosts.yaml
#- patches/webhook_in_hostfirmwarecomponents.yaml
#- patches/webhook_in_hostfirmwaresettings.yaml
#- patches/webhook_in_firmwareschemas.yaml
#- patches/webhook_in_preprovisioningimages.yaml
Expand All @@ -26,6 +28,7 @@ patches:
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
- path: patches/cainjection_in_baremetalhosts.yaml
#- patches/cainjection_in_hostfirmwarecomponents.yaml
#- patches/cainjection_in_hostfirmwaresettings.yaml
#- patches/cainjection_in_firmwareschemas.yaml
#- patches/cainjection_in_preprovisioningimages.yaml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: hostfirmwarecomponents.metal3.io
16 changes: 16 additions & 0 deletions config/base/crds/patches/webhook_in_hostfirmwarecomponents.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: hostfirmwarecomponents.metal3.io
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
17 changes: 12 additions & 5 deletions config/base/rbac/hostfirmwarecomponents_editor_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: clusterrole
app.kubernetes.io/instance: hostfirmwarecomponents-editor-role
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: baremetal-operator
app.kubernetes.io/part-of: baremetal-operator
app.kubernetes.io/managed-by: kustomize
name: hostfirmwarecomponents-editor-role
rules:
- apiGroups:
- metal3.io
resources:
- hostfirmwarecomponents
verbs:
- create
- delete
- get
- list
- watch
- create
- update
- patch
- delete
- update
- watch
- apiGroups:
- metal3.io
resources:
- hostfirmwarecomponents/status
verbs:
- get
- get
11 changes: 9 additions & 2 deletions config/base/rbac/hostfirmwarecomponents_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# permissions for end users to edit hostfirmwarecomponents.
# permissions for end users to view hostfirmwarecomponents.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: clusterrole
app.kubernetes.io/instance: hostfirmwarecomponents-viewer-role
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: baremetal-operator
app.kubernetes.io/part-of: baremetal-operator
app.kubernetes.io/managed-by: kustomize
name: hostfirmwarecomponents-viewer-role
rules:
- apiGroups:
Expand All @@ -17,4 +24,4 @@ rules:
resources:
- hostfirmwarecomponents/status
verbs:
- get
- get
26 changes: 26 additions & 0 deletions config/base/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,32 @@ rules:
- patch
- update
- watch
- apiGroups:
- metal3.io
resources:
- hostfirmwarecomponents
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- metal3.io
resources:
- hostfirmwarecomponents/finalizers
verbs:
- update
- apiGroups:
- metal3.io
resources:
- hostfirmwarecomponents/status
verbs:
- get
- patch
- update
- apiGroups:
- metal3.io
resources:
Expand Down
Loading