Skip to content

Commit 0711c74

Browse files
mhmxsRichard Kovacsavestukeljohnson92
authored
Introduce VPC controller (#62)
* Introduce VPC controller * Requeue non empty vpc deletion * Filter out not found in vpc controller patch * Update controller/linodemachine_controller.go Co-authored-by: Alex Vest <[email protected]> * Update controller/linodemachine_controller_helpers.go Co-authored-by: Alex Vest <[email protected]> * update CRD creation for VPC and setup VPC Controller in main.go * Remove vpc list copy before sort --------- Co-authored-by: Richard Kovacs <[email protected]> Co-authored-by: Alex Vest <[email protected]> Co-authored-by: Evan Johnson <[email protected]>
1 parent 29c1229 commit 0711c74

25 files changed

+1329
-97
lines changed

api/v1alpha1/linodecluster_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
corev1 "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2223
"sigs.k8s.io/cluster-api/errors"
@@ -35,6 +36,10 @@ type LinodeClusterSpec struct {
3536
// NetworkSpec encapsulates all things related to Linode network.
3637
// +optional
3738
Network NetworkSpec `json:"network"`
39+
40+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
41+
// +optional
42+
VPCRef *corev1.ObjectReference `json:"vpcRef,omitempty"`
3843
}
3944

4045
// LinodeClusterStatus defines the observed state of LinodeCluster

api/v1alpha1/linodemachine_types.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ type LinodeMachineSpec struct {
4141
// +kubebuilder:validation:Required
4242
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
4343
Type string `json:"type"`
44+
// +kubebuilder:validation:MinLength=3
45+
// +kubebuilder:validation:MaxLength=63
4446
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
47+
// +optional
4548
Label string `json:"label,omitempty"`
4649
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
4750
Group string `json:"group,omitempty"`
@@ -82,10 +85,13 @@ type InstanceMetadataOptions struct {
8285

8386
// InstanceConfigInterfaceCreateOptions defines network interface config
8487
type InstanceConfigInterfaceCreateOptions struct {
85-
IPAMAddress string `json:"ipamAddress,omitempty"`
86-
Label string `json:"label,omitempty"`
87-
Purpose linodego.ConfigInterfacePurpose `json:"purpose,omitempty"`
88-
Primary bool `json:"primary,omitempty"`
88+
IPAMAddress string `json:"ipamAddress,omitempty"`
89+
// +kubebuilder:validation:MinLength=3
90+
// +kubebuilder:validation:MaxLength=63
91+
// +optional
92+
Label string `json:"label,omitempty"`
93+
Purpose linodego.ConfigInterfacePurpose `json:"purpose,omitempty"`
94+
Primary bool `json:"primary,omitempty"`
8995
// +optional
9096
SubnetID *int `json:"subnetId,omitempty"`
9197
// +optional
@@ -103,6 +109,7 @@ type VPCIPv4 struct {
103109
type LinodeMachineStatus struct {
104110
// Ready is true when the provider resource is ready.
105111
// +optional
112+
// +kubebuilder:default=false
106113
Ready bool `json:"ready"`
107114

108115
// Addresses contains the Linode instance associated addresses.

api/v1alpha1/linodevpc_types.go

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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

Comments
 (0)