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 committed Nov 17, 2021
1 parent 75ceaad commit c1a1186
Show file tree
Hide file tree
Showing 19 changed files with 756 additions and 14 deletions.
83 changes: 83 additions & 0 deletions apis/metal3.io/v1alpha1/bmceventsubscription_types.go
@@ -0,0 +1,83 @@
/*
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 {
// 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"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
//
// BMCEventSubscription is the Schema for the fast eventing API
// +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

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

func init() {
SchemeBuilder.Register(&BMCEventSubscription{}, &BMCEventSubscriptionList{})
}
99 changes: 99 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.

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

---
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 fast eventing API
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
type: object
status:
properties:
subscriptionID:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
2 changes: 2 additions & 0 deletions config/crd/kustomization.yaml
Expand Up @@ -6,7 +6,9 @@ resources:
- bases/metal3.io_hostfirmwaresettings.yaml
- bases/metal3.io_firmwareschemas.yaml
- bases/metal3.io_preprovisioningimages.yaml
- bases/metal3.io_bmceventsubscriptions.yaml
#+kubebuilder:scaffold:crdkustomizeresource
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
Expand Down
87 changes: 87 additions & 0 deletions config/render/capm3.yaml
Expand Up @@ -1100,6 +1100,93 @@ status:
---
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 fast eventing API
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
type: object
status:
properties:
subscriptionID:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.2
Expand Down

0 comments on commit c1a1186

Please sign in to comment.