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

✨ IPAM provider for floating ips #1763

Merged
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ generate-go: $(MOCKGEN)
paths=./api/... \
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt
$(CONVERSION_GEN) \
--input-dirs=./api/v1alpha1 \
--input-dirs=./api/v1alpha5 \
--input-dirs=./api/v1alpha6 \
--input-dirs=./api/v1alpha7 \
Expand Down
27 changes: 17 additions & 10 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
version: "2"
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: cluster.x-k8s.io
repo: sigs.k8s.io/cluster-api-provider-openstack
resources:
- group: infrastructure
version: v1alpha5
kind: OpenStackCluster
- group: infrastructure
version: v1alpha5
kind: OpenStackMachine
- group: infrastructure
kind: OpenStackMachine
version: v1alpha5
- group: infrastructure
kind: OpenStackMachineTemplate
version: v1alpha5
- group: infrastructure
kind: OpenStackClusterTemplate
version: v1alpha5
- group: infrastructure
version: v1alpha6
kind: OpenStackCluster
- group: infrastructure
version: v1alpha6
kind: OpenStackMachine
- group: infrastructure
kind: OpenStackMachine
version: v1alpha6
- group: infrastructure
kind: OpenStackMachineTemplate
version: v1alpha6
- group: infrastructure
kind: OpenStackClusterTemplate
version: v1alpha6
- group: infrastructure
version: v1alpha7
kind: OpenStackCluster
- group: infrastructure
version: v1alpha7
kind: OpenStackMachine
- group: infrastructure
kind: OpenStackMachine
version: v1alpha7
- group: infrastructure
kind: OpenStackMachineTemplate
version: v1alpha7
- group: infrastructure
kind: OpenStackClusterTemplate
version: v1alpha7
Expand All @@ -50,3 +53,7 @@ resources:
- group: infrastructure
kind: OpenStackClusterTemplate
version: v1alpha8
- group: infrastructure
kind: OpenStackFloatingIPPool
version: v1alpha1
version: "2"
22 changes: 22 additions & 0 deletions api/v1alpha1/conditions_consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2023 The Kubernetes 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

const (
// OpenstackFloatingIPPoolReadyCondition reports on the current status of the floating ip pool. Ready indicates that the pool is ready to be used.
OpenstackFloatingIPPoolReadyCondition = "OpenstackFloatingIPPoolReadyCondition"
)
17 changes: 17 additions & 0 deletions api/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright 2023 The Kubernetes 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
36 changes: 36 additions & 0 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2023 The Kubernetes 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 contains API Schema definitions for the infrastructure v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=infrastructure.cluster.x-k8s.io
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "infrastructure.cluster.x-k8s.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
136 changes: 136 additions & 0 deletions api/v1alpha1/openstackfloatingippool_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
Copyright 2019 The Kubernetes 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 (
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

// We use v1alpha7 here rather than anything newer because as of writing
// it is the newest API version we should no longer be making breaking
// changes to. If we bump this we need to look carefully for resulting
// CRD changes in v1alpha1 to ensure they are compatible.
infrav1alpha7 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7"
)

const (
// OpenStackFloatingIPPoolFinalizer allows ReconcileOpenStackFloatingIPPool to clean up resources associated with OpenStackFloatingIPPool before
// removing it from the apiserver.
OpenStackFloatingIPPoolFinalizer = "openstackfloatingippool.infrastructure.cluster.x-k8s.io"

OpenStackFloatingIPPoolNameIndex = "spec.poolRef.name"

// OpenStackFloatingIPPoolIP.
DeleteFloatingIPFinalizer = "openstackfloatingippool.infrastructure.cluster.x-k8s.io/delete-floating-ip"
)

// ReclaimPolicy is a string type alias to represent reclaim policies for floating ips.
type ReclaimPolicy string

const (
// ReclaimDelete is the reclaim policy for floating ips.
ReclaimDelete ReclaimPolicy = "Delete"
// ReclaimRetain is the reclaim policy for floating ips.
ReclaimRetain ReclaimPolicy = "Retain"
)

// OpenStackFloatingIPPoolSpec defines the desired state of OpenStackFloatingIPPool.
type OpenStackFloatingIPPoolSpec struct {
// PreAllocatedFloatingIPs is a list of floating IPs precreated in OpenStack that should be used by this pool.
// These are used before allocating new ones and are not deleted from OpenStack when the pool is deleted.
PreAllocatedFloatingIPs []string `json:"preAllocatedFloatingIPs,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a doc string for this as well? I know it is fairly self explanatory, but it is still nice to have descriptions for all fields.

Copy link
Contributor

@dulek dulek Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little formatting fixes, plus I think this should have +optional:

	// PreAllocatedFloatingIPs is a list of floating IPs precreated in OpenStack that should be used by this pool.
	// These are used before allocating new ones and are not deleted from OpenStack when the pool is deleted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dulek FYI I've been recommending against +optionals because they're already the default. I don't have a strong position on it, though. Is there specific guidance somewhere I'm ignoring?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so just the formatting fixes! :)


// IdentityRef is a reference to a identity to be used when reconciling this pool.
// +optional
IdentityRef *infrav1alpha7.OpenStackIdentityReference `json:"identityRef,omitempty"`

// FloatingIPNetwork is the external network to use for floating ips, if there's only one external network it will be used by default
// +optional
FloatingIPNetwork infrav1alpha7.NetworkFilter `json:"floatingIPNetwork"`

// The name of the cloud to use from the clouds secret
// +optional
CloudName string `json:"cloudName"`

// The stratergy to use for reclaiming floating ips when they are released from a machine
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Enum=Retain;Delete
ReclaimPolicy ReclaimPolicy `json:"reclaimPolicy"`
}

// OpenStackFloatingIPPoolStatus defines the observed state of OpenStackFloatingIPPool.
type OpenStackFloatingIPPoolStatus struct {
// +kubebuilder:default={}
// +optional
ClaimedIPs []string `json:"claimedIPs"`

// +kubebuilder:default={}
// +optional
AvailableIPs []string `json:"availableIPs"`

// FailedIPs contains a list of floating ips that failed to be allocated
// +optional
FailedIPs []string `json:"failedIPs,omitempty"`

// floatingIPNetwork contains information about the network used for floating ips
// +optional
FloatingIPNetwork *infrav1alpha7.NetworkStatus `json:"floatingIPNetwork,omitempty"`

Conditions clusterv1.Conditions `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:storageversion
//+kubebuilder:subresource:status

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

Spec OpenStackFloatingIPPoolSpec `json:"spec,omitempty"`
Status OpenStackFloatingIPPoolStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

// GetConditions returns the observations of the operational state of the OpenStackFloatingIPPool resource.
func (r *OpenStackFloatingIPPool) GetConditions() clusterv1.Conditions {
return r.Status.Conditions
}

// SetConditions sets the underlying service state of the OpenStackFloatingIPPool to the predescribed clusterv1.Conditions.
func (r *OpenStackFloatingIPPool) SetConditions(conditions clusterv1.Conditions) {
r.Status.Conditions = conditions
}

func (r *OpenStackFloatingIPPool) GetFloatingIPTag() string {
return fmt.Sprintf("cluster-api-provider-openstack-fip-pool-%s", r.Name)
}

func init() {
SchemeBuilder.Register(&OpenStackFloatingIPPool{}, &OpenStackFloatingIPPoolList{})
}
Loading