Skip to content

Commit

Permalink
Add BMC subscription CRD and reconciler
Browse files Browse the repository at this point in the history
This patch implements the fast eventing API:

metal3-io/metal3-docs#167

We introduce a new CRD, and a new reconciler.  We use the Ironic API to
communicate with the BMC to manage node subscriptions.
  • Loading branch information
honza authored and jzding committed Nov 5, 2021
1 parent c38de6a commit e89fc2d
Show file tree
Hide file tree
Showing 19 changed files with 859 additions and 14 deletions.
92 changes: 92 additions & 0 deletions apis/metal3.io/v1alpha1/bmceventsubscription_types.go
@@ -0,0 +1,92 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (

// BMCEventSubscriptionFinalizer is the name of the finalizer added to
// subscriptions to block delete operations until the subscription is removed
// from the BMC.
BMCEventSubscriptionFinalizer string = "bmceventsubscription.metal3.io"
)

type BMCEventSubscriptionSpec struct {
Taints []corev1.Taint `json:"taints,omitempty"`

// A reference to a BareMetalHost
HostRef string `json:"hostRef,omitempty"`

// A webhook URL to send events to
Destination string `json:"destination,omitempty"`

// Arbitrary user-provided context for the event
Context string `json:"context,omitempty"`

// Messages of which type we should pass along; defaults to ["Alert"]
EventTypes []string `json:"eventTypes,omitempty"`

// The BMC protocol to use; defaults to "Redfish"
Protocol string `json:"protocol,omitempty"`

// A secret containing HTTP headers which should be passed along to the Destination
// when making a request
HTTPHeadersRef *corev1.SecretReference `json:"httpHeadersRef,omitempty"`
}

type BMCEventSubscriptionStatus struct {
SubscriptionID string `json:"subscriptionID,omitempty"`
ErrorMessage string `json:"errorMessage"`
// ErrorCount records how many times the host has encoutered an error since the last successful operation
// +kubebuilder:default:=0
ErrorCount int `json:"errorCount"`
// LastUpdated identifies when this status was last observed.
// +optional
LastUpdated *metav1.Time `json:"lastUpdated,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
//
// BMCEventSubscription is the Schema for the ...
// +k8s:openapi-gen=true
// +kubebuilder:resource:shortName=bes;bmcevent
// +kubebuilder:subresource:status
// +kubebuilder:object:root=true
type BMCEventSubscription struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BMCEventSubscriptionSpec `json:"spec,omitempty"`
Status BMCEventSubscriptionStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// BareMetalHostList contains a list of BareMetalHost
type BMCEventSubscriptionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []BMCEventSubscription `json:"items"`
}

func init() {
SchemeBuilder.Register(&BMCEventSubscription{}, &BMCEventSubscriptionList{})
}
110 changes: 110 additions & 0 deletions apis/metal3.io/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 128 additions & 0 deletions config/crd/bases/metal3.io_bmceventsubscriptions.yaml
@@ -0,0 +1,128 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: bmceventsubscriptions.metal3.io
spec:
group: metal3.io
names:
kind: BMCEventSubscription
listKind: BMCEventSubscriptionList
plural: bmceventsubscriptions
shortNames:
- bes
- bmcevent
singular: bmceventsubscription
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: BMCEventSubscription is the Schema for the ...
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
properties:
context:
description: Arbitrary user-provided context for the event
type: string
destination:
description: A webhook URL to send events to
type: string
eventTypes:
description: Messages of which type we should pass along; defaults
to ["Alert"]
items:
type: string
type: array
hostRef:
description: A reference to a BareMetalHost
type: string
httpHeadersRef:
description: A secret containing HTTP headers which should be passed
along to the Destination when making a request
properties:
name:
description: Name is unique within a namespace to reference a
secret resource.
type: string
namespace:
description: Namespace defines the space within which the secret
name must be unique.
type: string
type: object
protocol:
description: The BMC protocol to use; defaults to "Redfish"
type: string
taints:
items:
description: The node this Taint is attached to has the "effect"
on any pod that does not tolerate the Taint.
properties:
effect:
description: Required. The effect of the taint on pods that
do not tolerate the taint. Valid effects are NoSchedule, PreferNoSchedule
and NoExecute.
type: string
key:
description: Required. The taint key to be applied to a node.
type: string
timeAdded:
description: TimeAdded represents the time at which the taint
was added. It is only written for NoExecute taints.
format: date-time
type: string
value:
description: The taint value corresponding to the taint key.
type: string
required:
- effect
- key
type: object
type: array
type: object
status:
properties:
errorCount:
default: 0
description: ErrorCount records how many times the host has encoutered
an error since the last successful operation
type: integer
errorMessage:
type: string
lastUpdated:
description: LastUpdated identifies when this status was last observed.
format: date-time
type: string
subscriptionID:
type: string
required:
- errorCount
- errorMessage
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
1 change: 1 addition & 0 deletions config/crd/kustomization.yaml
Expand Up @@ -6,6 +6,7 @@ resources:
- bases/metal3.io_hostfirmwaresettings.yaml
- bases/metal3.io_firmwareschemas.yaml
- bases/metal3.io_preprovisioningimages.yaml
- bases/metal3.io_bmceventsubscriptions.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand Down

0 comments on commit e89fc2d

Please sign in to comment.