|
| 1 | +/* |
| 2 | +Copyright 2019 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + |
| 22 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 23 | + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 24 | + |
| 25 | + // We use v1alpha7 here rather than anything newer because as of writing |
| 26 | + // it is the newest API version we should no longer be making breaking |
| 27 | + // changes to. If we bump this we need to look carefully for resulting |
| 28 | + // CRD changes in v1alpha1 to ensure they are compatible. |
| 29 | + infrav1alpha7 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7" |
| 30 | +) |
| 31 | + |
| 32 | +const ( |
| 33 | + // OpenStackFloatingIPPoolFinalizer allows ReconcileOpenStackFloatingIPPool to clean up resources associated with OpenStackFloatingIPPool before |
| 34 | + // removing it from the apiserver. |
| 35 | + OpenStackFloatingIPPoolFinalizer = "openstackfloatingippool.infrastructure.cluster.x-k8s.io" |
| 36 | + |
| 37 | + OpenStackFloatingIPPoolNameIndex = "spec.poolRef.name" |
| 38 | + |
| 39 | + // OpenStackFloatingIPPoolIP. |
| 40 | + DeleteFloatingIPFinalizer = "openstackfloatingippool.infrastructure.cluster.x-k8s.io/delete-floating-ip" |
| 41 | +) |
| 42 | + |
| 43 | +// ReclaimPolicy is a string type alias to represent reclaim policies for floating ips. |
| 44 | +type ReclaimPolicy string |
| 45 | + |
| 46 | +const ( |
| 47 | + // ReclaimDelete is the reclaim policy for floating ips. |
| 48 | + ReclaimDelete ReclaimPolicy = "Delete" |
| 49 | + // ReclaimRetain is the reclaim policy for floating ips. |
| 50 | + ReclaimRetain ReclaimPolicy = "Retain" |
| 51 | +) |
| 52 | + |
| 53 | +// OpenStackFloatingIPPoolSpec defines the desired state of OpenStackFloatingIPPool. |
| 54 | +type OpenStackFloatingIPPoolSpec struct { |
| 55 | + // PreAllocatedFloatingIPs is a list of floating IPs precreated in OpenStack that should be used by this pool. |
| 56 | + // These are used before allocating new ones and are not deleted from OpenStack when the pool is deleted. |
| 57 | + PreAllocatedFloatingIPs []string `json:"preAllocatedFloatingIPs,omitempty"` |
| 58 | + |
| 59 | + // IdentityRef is a reference to a identity to be used when reconciling this pool. |
| 60 | + // +optional |
| 61 | + IdentityRef *infrav1alpha7.OpenStackIdentityReference `json:"identityRef,omitempty"` |
| 62 | + |
| 63 | + // FloatingIPNetwork is the external network to use for floating ips, if there's only one external network it will be used by default |
| 64 | + // +optional |
| 65 | + FloatingIPNetwork infrav1alpha7.NetworkFilter `json:"floatingIPNetwork"` |
| 66 | + |
| 67 | + // The name of the cloud to use from the clouds secret |
| 68 | + // +optional |
| 69 | + CloudName string `json:"cloudName"` |
| 70 | + |
| 71 | + // The stratergy to use for reclaiming floating ips when they are released from a machine |
| 72 | + // +kubebuilder:validation:Optional |
| 73 | + // +kubebuilder:validation:Enum=Retain;Delete |
| 74 | + ReclaimPolicy ReclaimPolicy `json:"reclaimPolicy"` |
| 75 | +} |
| 76 | + |
| 77 | +// OpenStackFloatingIPPoolStatus defines the observed state of OpenStackFloatingIPPool. |
| 78 | +type OpenStackFloatingIPPoolStatus struct { |
| 79 | + // +kubebuilder:default={} |
| 80 | + // +optional |
| 81 | + ClaimedIPs []string `json:"claimedIPs"` |
| 82 | + |
| 83 | + // +kubebuilder:default={} |
| 84 | + // +optional |
| 85 | + AvailableIPs []string `json:"availableIPs"` |
| 86 | + |
| 87 | + // FailedIPs contains a list of floating ips that failed to be allocated |
| 88 | + // +optional |
| 89 | + FailedIPs []string `json:"failedIPs,omitempty"` |
| 90 | + |
| 91 | + // floatingIPNetwork contains information about the network used for floating ips |
| 92 | + // +optional |
| 93 | + FloatingIPNetwork *infrav1alpha7.NetworkStatus `json:"floatingIPNetwork,omitempty"` |
| 94 | + |
| 95 | + Conditions clusterv1.Conditions `json:"conditions,omitempty"` |
| 96 | +} |
| 97 | + |
| 98 | +//+kubebuilder:object:root=true |
| 99 | +// +kubebuilder:storageversion |
| 100 | +//+kubebuilder:subresource:status |
| 101 | + |
| 102 | +// OpenStackFloatingIPPool is the Schema for the openstackfloatingippools API. |
| 103 | +type OpenStackFloatingIPPool struct { |
| 104 | + metav1.TypeMeta `json:",inline"` |
| 105 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 106 | + |
| 107 | + Spec OpenStackFloatingIPPoolSpec `json:"spec,omitempty"` |
| 108 | + Status OpenStackFloatingIPPoolStatus `json:"status,omitempty"` |
| 109 | +} |
| 110 | + |
| 111 | +//+kubebuilder:object:root=true |
| 112 | + |
| 113 | +// OpenStackFloatingIPPoolList contains a list of OpenStackFloatingIPPool. |
| 114 | +type OpenStackFloatingIPPoolList struct { |
| 115 | + metav1.TypeMeta `json:",inline"` |
| 116 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 117 | + Items []OpenStackFloatingIPPool `json:"items"` |
| 118 | +} |
| 119 | + |
| 120 | +// GetConditions returns the observations of the operational state of the OpenStackFloatingIPPool resource. |
| 121 | +func (r *OpenStackFloatingIPPool) GetConditions() clusterv1.Conditions { |
| 122 | + return r.Status.Conditions |
| 123 | +} |
| 124 | + |
| 125 | +// SetConditions sets the underlying service state of the OpenStackFloatingIPPool to the predescribed clusterv1.Conditions. |
| 126 | +func (r *OpenStackFloatingIPPool) SetConditions(conditions clusterv1.Conditions) { |
| 127 | + r.Status.Conditions = conditions |
| 128 | +} |
| 129 | + |
| 130 | +func (r *OpenStackFloatingIPPool) GetFloatingIPTag() string { |
| 131 | + return fmt.Sprintf("cluster-api-provider-openstack-fip-pool-%s", r.Name) |
| 132 | +} |
| 133 | + |
| 134 | +func init() { |
| 135 | + SchemeBuilder.Register(&OpenStackFloatingIPPool{}, &OpenStackFloatingIPPoolList{}) |
| 136 | +} |
0 commit comments