|
| 1 | +/* |
| 2 | +Copyright 2023 Akamai Technologies, Inc. |
| 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 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 22 | +) |
| 23 | + |
| 24 | +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! |
| 25 | +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. |
| 26 | + |
| 27 | +// LinodeVPCSpec defines the desired state of LinodeVPC |
| 28 | +type LinodeVPCSpec struct { |
| 29 | + // +optional |
| 30 | + VPCID *int `json:"vpcID,omitempty"` |
| 31 | + |
| 32 | + // +kubebuilder:validation:MinLength=3 |
| 33 | + // +kubebuilder:validation:MaxLength=63 |
| 34 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable" |
| 35 | + // +optional |
| 36 | + Label string `json:"label,omitempty"` |
| 37 | + // +optional |
| 38 | + Description string `json:"description,omitempty"` |
| 39 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable" |
| 40 | + Region string `json:"region"` |
| 41 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable" |
| 42 | + // +optional |
| 43 | + Subnets []VPCSubnetCreateOptions `json:"subnets,omitempty"` |
| 44 | +} |
| 45 | + |
| 46 | +// VPCSubnetCreateOptions defines subnet options |
| 47 | +type VPCSubnetCreateOptions struct { |
| 48 | + // +kubebuilder:validation:MinLength=3 |
| 49 | + // +kubebuilder:validation:MaxLength=63 |
| 50 | + // +optional |
| 51 | + Label string `json:"label,omitempty"` |
| 52 | + // +optional |
| 53 | + IPv4 string `json:"ipv4,omitempty"` |
| 54 | +} |
| 55 | + |
| 56 | +// LinodeVPCStatus defines the observed state of LinodeVPC |
| 57 | +type LinodeVPCStatus struct { |
| 58 | + // Ready is true when the provider resource is ready. |
| 59 | + // +optional |
| 60 | + // +kubebuilder:default=false |
| 61 | + Ready bool `json:"ready"` |
| 62 | + |
| 63 | + // FailureReason will be set in the event that there is a terminal problem |
| 64 | + // reconciling the VPC and will contain a succinct value suitable |
| 65 | + // for machine interpretation. |
| 66 | + // |
| 67 | + // This field should not be set for transitive errors that a controller |
| 68 | + // faces that are expected to be fixed automatically over |
| 69 | + // time (like service outages), but instead indicate that something is |
| 70 | + // fundamentally wrong with the VPC's spec or the configuration of |
| 71 | + // the controller, and that manual intervention is required. Examples |
| 72 | + // of terminal errors would be invalid combinations of settings in the |
| 73 | + // spec, values that are unsupported by the controller, or the |
| 74 | + // responsible controller itself being critically misconfigured. |
| 75 | + // |
| 76 | + // Any transient errors that occur during the reconciliation of VPCs |
| 77 | + // can be added as events to the VPC object and/or logged in the |
| 78 | + // controller's output. |
| 79 | + // +optional |
| 80 | + FailureReason *VPCStatusError `json:"failureReason,omitempty"` |
| 81 | + |
| 82 | + // FailureMessage will be set in the event that there is a terminal problem |
| 83 | + // reconciling the VPC and will contain a more verbose string suitable |
| 84 | + // for logging and human consumption. |
| 85 | + // |
| 86 | + // This field should not be set for transitive errors that a controller |
| 87 | + // faces that are expected to be fixed automatically over |
| 88 | + // time (like service outages), but instead indicate that something is |
| 89 | + // fundamentally wrong with the VPC's spec or the configuration of |
| 90 | + // the controller, and that manual intervention is required. Examples |
| 91 | + // of terminal errors would be invalid combinations of settings in the |
| 92 | + // spec, values that are unsupported by the controller, or the |
| 93 | + // responsible controller itself being critically misconfigured. |
| 94 | + // |
| 95 | + // Any transient errors that occur during the reconciliation of VPCs |
| 96 | + // can be added as events to the VPC object and/or logged in the |
| 97 | + // controller's output. |
| 98 | + // +optional |
| 99 | + FailureMessage *string `json:"failureMessage,omitempty"` |
| 100 | + |
| 101 | + // Conditions defines current service state of the LinodeVPC. |
| 102 | + // +optional |
| 103 | + Conditions clusterv1.Conditions `json:"conditions,omitempty"` |
| 104 | +} |
| 105 | + |
| 106 | +//+kubebuilder:object:root=true |
| 107 | +//+kubebuilder:subresource:status |
| 108 | + |
| 109 | +// LinodeVPC is the Schema for the linodemachines API |
| 110 | +type LinodeVPC struct { |
| 111 | + metav1.TypeMeta `json:",inline"` |
| 112 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 113 | + |
| 114 | + Spec LinodeVPCSpec `json:"spec,omitempty"` |
| 115 | + Status LinodeVPCStatus `json:"status,omitempty"` |
| 116 | +} |
| 117 | + |
| 118 | +func (lm *LinodeVPC) GetConditions() clusterv1.Conditions { |
| 119 | + return lm.Status.Conditions |
| 120 | +} |
| 121 | + |
| 122 | +func (lm *LinodeVPC) SetConditions(conditions clusterv1.Conditions) { |
| 123 | + lm.Status.Conditions = conditions |
| 124 | +} |
| 125 | + |
| 126 | +//+kubebuilder:object:root=true |
| 127 | + |
| 128 | +// LinodeVPCList contains a list of LinodeVPC |
| 129 | +type LinodeVPCList struct { |
| 130 | + metav1.TypeMeta `json:",inline"` |
| 131 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 132 | + Items []LinodeVPC `json:"items"` |
| 133 | +} |
| 134 | + |
| 135 | +func init() { |
| 136 | + SchemeBuilder.Register(&LinodeVPC{}, &LinodeVPCList{}) |
| 137 | +} |
| 138 | + |
| 139 | +// VPCStatusError defines errors states for VPC objects. |
| 140 | +type VPCStatusError string |
| 141 | + |
| 142 | +const ( |
| 143 | + // CreateVPCError indicates that an error was encountered |
| 144 | + // when trying to create the VPC. |
| 145 | + CreateVPCError VPCStatusError = "CreateError" |
| 146 | + |
| 147 | + // UpdateVPCError indicates that an error was encountered |
| 148 | + // when trying to update the VPC. |
| 149 | + UpdateVPCError VPCStatusError = "UpdateError" |
| 150 | + |
| 151 | + // DeleteVPCError indicates that an error was encountered |
| 152 | + // when trying to delete the VPC. |
| 153 | + DeleteVPCError VPCStatusError = "DeleteError" |
| 154 | +) |
0 commit comments