Skip to content

Commit cc2870b

Browse files
author
Richard Kovacs
committed
Introduce VPC controller
1 parent ec04676 commit cc2870b

20 files changed

+1230
-80
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: 23 additions & 6 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"`
@@ -77,32 +80,46 @@ type LinodeMachineSpec struct {
7780
// InstanceMetadataOptions defines metadata of instance
7881
type InstanceMetadataOptions struct {
7982
// UserData expects a Base64-encoded string
83+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
8084
UserData string `json:"userData,omitempty"`
8185
}
8286

8387
// InstanceConfigInterfaceCreateOptions defines network interface config
8488
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"`
89+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
90+
IPAMAddress string `json:"ipamAddress,omitempty"`
91+
// +kubebuilder:validation:MinLength=3
92+
// +kubebuilder:validation:MaxLength=63
93+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
94+
// +optional
95+
Label string `json:"label,omitempty"`
96+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
97+
Purpose linodego.ConfigInterfacePurpose `json:"purpose,omitempty"`
98+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
99+
Primary bool `json:"primary,omitempty"`
100+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
89101
// +optional
90102
SubnetID *int `json:"subnetId,omitempty"`
103+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
91104
// +optional
92-
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
105+
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
106+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
93107
IPRanges []string `json:"ipRanges,omitempty"`
94108
}
95109

96110
// VPCIPv4 defines VPC IPV4 settings
97111
type VPCIPv4 struct {
98-
VPC string `json:"vpc,omitempty"`
112+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
113+
VPC string `json:"vpc,omitempty"`
114+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
99115
NAT1To1 string `json:"nat1to1,omitempty"`
100116
}
101117

102118
// LinodeMachineStatus defines the observed state of LinodeMachine
103119
type LinodeMachineStatus struct {
104120
// Ready is true when the provider resource is ready.
105121
// +optional
122+
// +kubebuilder:default=false
106123
Ready bool `json:"ready"`
107124

108125
// Addresses contains the Linode instance associated addresses.

api/v1alpha1/linodevpc_types.go

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
51+
// +optional
52+
Label string `json:"label,omitempty"`
53+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
54+
// +optional
55+
IPv4 string `json:"ipv4,omitempty"`
56+
}
57+
58+
// LinodeVPCStatus defines the observed state of LinodeVPC
59+
type LinodeVPCStatus struct {
60+
// Ready is true when the provider resource is ready.
61+
// +optional
62+
// +kubebuilder:default=false
63+
Ready bool `json:"ready"`
64+
65+
// FailureReason will be set in the event that there is a terminal problem
66+
// reconciling the VPC and will contain a succinct value suitable
67+
// for machine interpretation.
68+
//
69+
// This field should not be set for transitive errors that a controller
70+
// faces that are expected to be fixed automatically over
71+
// time (like service outages), but instead indicate that something is
72+
// fundamentally wrong with the VPC's spec or the configuration of
73+
// the controller, and that manual intervention is required. Examples
74+
// of terminal errors would be invalid combinations of settings in the
75+
// spec, values that are unsupported by the controller, or the
76+
// responsible controller itself being critically misconfigured.
77+
//
78+
// Any transient errors that occur during the reconciliation of VPCs
79+
// can be added as events to the VPC object and/or logged in the
80+
// controller's output.
81+
// +optional
82+
FailureReason *VPCStatusError `json:"failureReason,omitempty"`
83+
84+
// FailureMessage will be set in the event that there is a terminal problem
85+
// reconciling the VPC and will contain a more verbose string suitable
86+
// for logging and human consumption.
87+
//
88+
// This field should not be set for transitive errors that a controller
89+
// faces that are expected to be fixed automatically over
90+
// time (like service outages), but instead indicate that something is
91+
// fundamentally wrong with the VPC's spec or the configuration of
92+
// the controller, and that manual intervention is required. Examples
93+
// of terminal errors would be invalid combinations of settings in the
94+
// spec, values that are unsupported by the controller, or the
95+
// responsible controller itself being critically misconfigured.
96+
//
97+
// Any transient errors that occur during the reconciliation of VPCs
98+
// can be added as events to the VPC object and/or logged in the
99+
// controller's output.
100+
// +optional
101+
FailureMessage *string `json:"failureMessage,omitempty"`
102+
103+
// Conditions defines current service state of the LinodeVPC.
104+
// +optional
105+
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
106+
}
107+
108+
//+kubebuilder:object:root=true
109+
//+kubebuilder:subresource:status
110+
111+
// LinodeVPC is the Schema for the linodemachines API
112+
type LinodeVPC struct {
113+
metav1.TypeMeta `json:",inline"`
114+
metav1.ObjectMeta `json:"metadata,omitempty"`
115+
116+
Spec LinodeVPCSpec `json:"spec,omitempty"`
117+
Status LinodeVPCStatus `json:"status,omitempty"`
118+
}
119+
120+
func (lm *LinodeVPC) GetConditions() clusterv1.Conditions {
121+
return lm.Status.Conditions
122+
}
123+
124+
func (lm *LinodeVPC) SetConditions(conditions clusterv1.Conditions) {
125+
lm.Status.Conditions = conditions
126+
}
127+
128+
//+kubebuilder:object:root=true
129+
130+
// LinodeVPCList contains a list of LinodeVPC
131+
type LinodeVPCList struct {
132+
metav1.TypeMeta `json:",inline"`
133+
metav1.ListMeta `json:"metadata,omitempty"`
134+
Items []LinodeVPC `json:"items"`
135+
}
136+
137+
func init() {
138+
SchemeBuilder.Register(&LinodeVPC{}, &LinodeVPCList{})
139+
}
140+
141+
// VPCStatusError defines errors states for VPC objects.
142+
type VPCStatusError string
143+
144+
const (
145+
// CreateVPCError indicates that an error was encountered
146+
// when trying to create the VPC.
147+
CreateVPCError VPCStatusError = "CreateError"
148+
149+
// UpdateVPCError indicates that an error was encountered
150+
// when trying to update the VPC.
151+
UpdateVPCError VPCStatusError = "UpdateError"
152+
153+
// DeleteVPCError indicates that an error was encountered
154+
// when trying to delete the VPC.
155+
DeleteVPCError VPCStatusError = "DeleteError"
156+
)

0 commit comments

Comments
 (0)