-
Notifications
You must be signed in to change notification settings - Fork 308
✨ Add BareMetalSwitch CRD and controller for switch config generation #3046
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
Open
alegacy
wants to merge
1
commit into
metal3-io:main
Choose a base branch
from
alegacy:feature/switch-management
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| /* | ||
| Copyright 2025 The Metal3 Authors. | ||
|
|
||
| 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 ( | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // SwitchCredentialType defines the type of credential used for switch authentication. | ||
| type SwitchCredentialType string | ||
|
|
||
| const ( | ||
| // SwitchCredentialTypePassword indicates password-based authentication. | ||
| SwitchCredentialTypePassword SwitchCredentialType = "password" | ||
| // SwitchCredentialTypePublicKey indicates SSH public key-based authentication. | ||
| SwitchCredentialTypePublicKey SwitchCredentialType = "publickey" | ||
| ) | ||
|
|
||
| // SwitchCredentials defines the credentials used to access the switch. | ||
| type SwitchCredentials struct { | ||
| // Type is the type of switch credentials. | ||
| // This is currently limited to "password", but will be expanded to others. | ||
| // +kubebuilder:validation:Enum=password;publickey | ||
| // +kubebuilder:default=password | ||
| Type SwitchCredentialType `json:"type"` | ||
|
|
||
| // The name of the secret containing the switch credentials. | ||
| // For password authentication, requires keys "username" and "password" | ||
| // For SSH key authentication, requires keys "username" and "ssh-privatekey". | ||
| // In both cases, an optional "enable-secret" key can be provided if needed | ||
| // to enable privileged mode. | ||
| // +kubebuilder:validation:MinLength=1 | ||
| SecretName string `json:"secretName"` | ||
| } | ||
|
|
||
| // BareMetalSwitchSpec defines the desired state of BareMetalSwitch. | ||
| type BareMetalSwitchSpec struct { | ||
| // Address is the network address of the switch (IP address or hostname). | ||
| // +kubebuilder:validation:Required | ||
| Address string `json:"address"` | ||
|
|
||
| // MACAddress is the MAC address of the switch management interface. | ||
| // Used to correlate LLDP information from nodes to identify which switch they're connected to. | ||
| // +kubebuilder:validation:Pattern=`^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$` | ||
| // +kubebuilder:validation:Required | ||
| MACAddress string `json:"macAddress"` | ||
|
|
||
| // Driver specifies the driver to use. Currently only "generic-switch" is supported. | ||
| // +kubebuilder:validation:Enum=generic-switch | ||
| // +kubebuilder:default=generic-switch | ||
| // +optional | ||
| Driver string `json:"driver,omitempty"` | ||
|
|
||
| // DeviceType specifies the device type for the generic-switch driver. | ||
| // Must be one of the device types supported by networking-generic-switch. | ||
| // Examples: netmiko_cisco_ios, netmiko_dell_force10, netmiko_dell_os10, | ||
| // netmiko_juniper_junos, netmiko_arista_eos | ||
| // See https://github.com/openstack/networking-generic-switch/blob/master/setup.cfg | ||
| // +kubebuilder:validation:Required | ||
| DeviceType string `json:"deviceType"` | ||
|
|
||
| // Credentials references the secret containing switch authentication credentials. | ||
| // +kubebuilder:validation:Required | ||
| Credentials SwitchCredentials `json:"credentials"` | ||
|
|
||
| // Port specifies the management port to connect to (e.g., SSH port 22, HTTPS port 443). | ||
| // If not specified, the driver will use its default port based on the device type. | ||
| // +kubebuilder:validation:Minimum=1 | ||
| // +kubebuilder:validation:Maximum=65535 | ||
| // +optional | ||
| Port *int32 `json:"port,omitempty"` | ||
|
|
||
| // DisableCertificateVerification disables TLS certificate verification when using | ||
| // HTTPS to connect to the switch. This is required for self-signed certificates, | ||
| // but is insecure as it allows man-in-the-middle attacks. | ||
| // +optional | ||
| DisableCertificateVerification *bool `json:"disableCertificateVerification,omitempty"` | ||
| } | ||
|
|
||
| // SwitchConditionType defines the condition types for BareMetalSwitch. | ||
| type SwitchConditionType string | ||
|
|
||
| const ( | ||
| // SwitchConditionReconciled indicates whether the switch has been | ||
| // successfully reconciled into the switch config secret. | ||
| SwitchConditionReconciled SwitchConditionType = "Reconciled" | ||
| ) | ||
|
|
||
| // BareMetalSwitchStatus defines the observed state of BareMetalSwitch. | ||
| type BareMetalSwitchStatus struct { | ||
| // Conditions describes the state of the BareMetalSwitch resource. | ||
| // +patchMergeKey=type | ||
| // +patchStrategy=merge | ||
| // +listType=map | ||
| // +listMapKey=type | ||
| // +optional | ||
| Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
| // +kubebuilder:resource:scope=Namespaced,shortName=bms | ||
| // +kubebuilder:subresource:status | ||
| // +kubebuilder:printcolumn:name="Driver",type="string",JSONPath=".spec.driver",description="Switch driver type" | ||
| // +kubebuilder:printcolumn:name="Device Type",type="string",JSONPath=".spec.deviceType",description="Switch device type" | ||
| // +kubebuilder:printcolumn:name="Address",type="string",JSONPath=".spec.address",description="Switch address" | ||
| // +kubebuilder:printcolumn:name="Reconciled",type="string",JSONPath=".status.conditions[?(@.type==\"Reconciled\")].status",description="Reconciled status" | ||
|
|
||
| // BareMetalSwitch represents a Top-of-Rack switch managed by Ironic Networking. | ||
| type BareMetalSwitch struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
|
||
| Spec BareMetalSwitchSpec `json:"spec,omitempty"` | ||
| Status BareMetalSwitchStatus `json:"status,omitempty"` | ||
| } | ||
|
|
||
| // GetConditions returns the set of conditions for this object. | ||
| func (s *BareMetalSwitch) GetConditions() []metav1.Condition { | ||
| return s.Status.Conditions | ||
| } | ||
|
|
||
| // SetConditions sets conditions for this object. | ||
| func (s *BareMetalSwitch) SetConditions(conditions []metav1.Condition) { | ||
| s.Status.Conditions = conditions | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
|
|
||
| // BareMetalSwitchList contains a list of BareMetalSwitch. | ||
| type BareMetalSwitchList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata,omitempty"` | ||
| Items []BareMetalSwitch `json:"items"` | ||
| } | ||
|
|
||
| func init() { | ||
| SchemeBuilder.Register(&BareMetalSwitch{}, &BareMetalSwitchList{}) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.