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

introduce CRD to manage MAC addresses used for OVNStaticBridgeMacMappings #381

Merged
merged 6 commits into from
Sep 14, 2021
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
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ resources:
webhooks:
defaulting: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: openstack.org
group: osp-director
kind: OpenStackMACAddress
path: github.com/openstack-k8s-operators/osp-director-operator/api/v1beta1
version: v1beta1
version: "3"
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ Create a base RHEL data volume prior to deploying OpenStack. This will be used
openStackClientStorageClass: host-nfs-storageclass
passwordSecret: userpassword
gitSecret: git-secret
# optional: specify all phys networks with optional MAC address prefix, used to create static OVN Bridge MAC address mappings.
# Unique OVN bridge mac address per node is dynamically allocated by creating OpenStackMACAddress resource and create a MAC per
# physnet per node.
physNetworks:
- name: datacentre
macPrefix: fa:16:3a
- name: datacentre2
macPrefix: fa:16:3b
virtualMachineRoles:
controller:
roleName: Controller
Expand Down
8 changes: 8 additions & 0 deletions api/v1beta1/openstackcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ type OpenStackControlPlaneSpec struct {
// +kubebuilder:default={ctlplane,external}
// OpenStackClientNetworks the name(s) of the OpenStackClientNetworks used to attach the openstackclient to
OpenStackClientNetworks []string `json:"openStackClientNetworks"`

// +kubebuilder:validation:Optional
// PhysNetworks - physical networks list with optional MAC address prefix, used to create static OVN Bridge MAC address mappings.
// Unique OVN bridge mac address is dynamically allocated by creating OpenStackMACAddress resource and create a MAC per physnet per OpenStack node.
// This information is used to create the OVNStaticBridgeMacMappings.
// If PhysNetworks is not provided, the tripleo default physnet datacentre gets created
// If the macPrefix is not specified for a physnet, the default macPrefix "fa:16:3a" is used.
PhysNetworks []Physnet `json:"physNetworks"`
}

// OpenStackVirtualMachineRoleSpec - defines the desired state of VMs
Expand Down
110 changes: 110 additions & 0 deletions api/v1beta1/openstackmacaddress_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*


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 v1beta1

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

// Physnet - name and prefix to be used for the physnet
type Physnet struct {
// +kubebuilder:default="datacentre"
// Name - the name of the physnet
Name string `json:"name"`

// +kubebuilder:validation:Optional
// +kubebuilder:default="fa:16:3a"
// MACPrefix - the MAC address prefix to use
// Locally administered addresses are distinguished from universally administered addresses by setting
// (assigning the value of 1 to) the second-least-significant bit of the first octet of the address.
// https://en.wikipedia.org/wiki/MAC_address#Universal_vs._local_(U/L_bit)
MACPrefix string `json:"macPrefix"`
}

// OpenStackMACAddressSpec defines the desired state of OpenStackMACAddress
type OpenStackMACAddressSpec struct {
// +kubebuilder:validation:MinItems=1
// PhysNetworks - physical networks list to create MAC addresses per physnet per node to create OVNStaticBridgeMacMappings
PhysNetworks []Physnet `json:"physNetworks"`
}

// OpenStackMACNodeStatus defines the observed state of the MAC addresses per PhysNetworks
type OpenStackMACNodeStatus struct {
// Reservations MAC reservations per PhysNetwork
Reservations map[string]string `json:"reservations"`

// node and therefore MAC reservation are flagged as deleted
Deleted bool `json:"deleted"`
}

// MACState - the state of this openstack mac reservation
type MACState string

const (
// MACWaiting - the mac creation is blocked by prerequisite objects
MACWaiting MACState = "Waiting"
// MACCreating - we are waiting for mac addresses to be created
MACCreating MACState = "Creating"
// MACConfigured - the MAC addresses have been created
MACConfigured MACState = "Created"
// MACError - the mac creation hit a error
MACError MACState = "Error"
)

// OpenStackMACAddressStatus defines the observed state of OpenStackMACAddress
type OpenStackMACAddressStatus struct {
// Reservations MAC address reservations per node
MACReservations map[string]OpenStackMACNodeStatus `json:"macReservations"`

// ReservedMACCount - the count of all MAC addresses reserved
ReservedMACCount int `json:"reservedMACCount"`

// CurrentState - the overall state of the OSMAC cr
CurrentState MACState `json:"currentState"`

// Conditions - conditions to display in the OpenShift GUI, which reflect CurrentState
Conditions ConditionList `json:"conditions,omitempty" optional:"true"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=osmacaddress;osmacaddresses;osmacaddr;osmacaddrs
// +operator-sdk:csv:customresourcedefinitions:displayName="OpenStack MACAddress"
// +kubebuilder:printcolumn:name="Reserved MACs",type="integer",JSONPath=".status.reservedMACCount"
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.currentState`,description="Status"

// OpenStackMACAddress is the Schema for the openstackmacaddresses API
type OpenStackMACAddress struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec OpenStackMACAddressSpec `json:"spec,omitempty"`
Status OpenStackMACAddressStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&OpenStackMACAddress{}, &OpenStackMACAddressList{})
}
150 changes: 150 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,34 @@ spec:
passwordSecret:
description: PasswordSecret used to e.g specify root pwd
type: string
physNetworks:
description: PhysNetworks - physical networks list with optional MAC
address prefix, used to create static OVN Bridge MAC address mappings.
Unique OVN bridge mac address is dynamically allocated by creating
OpenStackMACAddress resource and create a MAC per physnet per OpenStack
node. This information is used to create the OVNStaticBridgeMacMappings.
If PhysNetworks is not provided, the tripleo default physnet datacentre
gets created If the macPrefix is not specified for a physnet, the
default macPrefix "fa:16:3a" is used.
items:
description: Physnet - name and prefix to be used for the physnet
properties:
macPrefix:
default: fa:16:3a
description: MACPrefix - the MAC address prefix to use Locally
administered addresses are distinguished from universally
administered addresses by setting (assigning the value of
1 to) the second-least-significant bit of the first octet
of the address. https://en.wikipedia.org/wiki/MAC_address#Universal_vs._local_(U/L_bit)
type: string
name:
default: datacentre
description: Name - the name of the physnet
type: string
required:
- name
type: object
type: array
virtualMachineRoles:
additionalProperties:
description: OpenStackVirtualMachineRoleSpec - defines the desired
Expand Down
Loading