Skip to content

Commit a5cfcd7

Browse files
authored
Merge pull request kubernetes-sigs#2067 from shiftstack/OpenStackServer
✨ New CRD + controller for OpenStackServer (v1alpha1)
2 parents 82d7acf + fb3779c commit a5cfcd7

40 files changed

+6005
-1649
lines changed

PROJECT

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ resources:
4444
- group: infrastructure
4545
kind: OpenStackFloatingIPPool
4646
version: v1alpha1
47+
- group: infrastructure
48+
kind: OpenStackServer
49+
version: v1alpha1
4750
version: "2"

api/v1alpha1/conditions_consts.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ limitations under the License.
1616

1717
package v1alpha1
1818

19+
type ServerStatusError string
20+
1921
const (
2022
// OpenstackFloatingIPPoolReadyCondition reports on the current status of the floating ip pool. Ready indicates that the pool is ready to be used.
2123
OpenstackFloatingIPPoolReadyCondition = "OpenstackFloatingIPPoolReadyCondition"
@@ -25,4 +27,6 @@ const (
2527

2628
// UnableToFindFloatingIPNetworkReason is used when the floating ip network is not found.
2729
UnableToFindNetwork = "UnableToFindNetwork"
30+
31+
CreateServerError ServerStatusError = "CreateError"
2832
)
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/*
2+
Copyright 2024 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+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
23+
24+
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
25+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
26+
)
27+
28+
const (
29+
// OpenStackServerFinalizer allows ReconcileOpenStackServer to clean up resources associated with OpenStackServer before
30+
// removing it from the apiserver.
31+
OpenStackServerFinalizer = "openstackserver.infrastructure.cluster.x-k8s.io"
32+
)
33+
34+
// OpenStackServerSpec defines the desired state of OpenStackServer.
35+
type OpenStackServerSpec struct {
36+
// AdditionalBlockDevices is a list of specifications for additional block devices to attach to the server instance.
37+
// +listType=map
38+
// +listMapKey=name
39+
// +optional
40+
AdditionalBlockDevices []infrav1.AdditionalBlockDevice `json:"additionalBlockDevices,omitempty"`
41+
42+
// AvailabilityZone is the availability zone in which to create the server instance.
43+
//+optional
44+
AvailabilityZone optional.String `json:"availabilityZone,omitempty"`
45+
46+
// ConfigDrive is a flag to enable config drive for the server instance.
47+
// +optional
48+
ConfigDrive optional.Bool `json:"configDrive,omitempty"`
49+
50+
// The flavor reference for the flavor for the server instance.
51+
// +required
52+
Flavor string `json:"flavor"`
53+
54+
// FloatingIPPoolRef is a reference to a FloatingIPPool to allocate a floating IP from.
55+
// +optional
56+
FloatingIPPoolRef *corev1.TypedLocalObjectReference `json:"floatingIPPoolRef,omitempty"`
57+
58+
// IdentityRef is a reference to a secret holding OpenStack credentials.
59+
// +required
60+
IdentityRef infrav1.OpenStackIdentityReference `json:"identityRef"`
61+
62+
// The image to use for the server instance.
63+
// +required
64+
Image infrav1.ImageParam `json:"image"`
65+
66+
// Ports to be attached to the server instance.
67+
// +required
68+
Ports []infrav1.PortOpts `json:"ports"`
69+
70+
// RootVolume is the specification for the root volume of the server instance.
71+
// +optional
72+
RootVolume *infrav1.RootVolume `json:"rootVolume,omitempty"`
73+
74+
// SSHKeyName is the name of the SSH key to inject in the instance.
75+
// +required
76+
SSHKeyName string `json:"sshKeyName"`
77+
78+
// SecurityGroups is a list of security groups names to assign to the instance.
79+
// +optional
80+
SecurityGroups []infrav1.SecurityGroupParam `json:"securityGroups,omitempty"`
81+
82+
// ServerGroup is the server group to which the server instance belongs.
83+
// +optional
84+
ServerGroup *infrav1.ServerGroupParam `json:"serverGroup,omitempty"`
85+
86+
// ServerMetadata is a map of key value pairs to add to the server instance.
87+
// +listType=map
88+
// +listMapKey=key
89+
// +optional
90+
ServerMetadata []infrav1.ServerMetadata `json:"serverMetadata,omitempty"`
91+
92+
// Tags which will be added to the machine and all dependent resources
93+
// which support them. These are in addition to Tags defined on the
94+
// cluster.
95+
// Requires Nova api 2.52 minimum!
96+
// +listType=set
97+
Tags []string `json:"tags,omitempty"`
98+
99+
// Trunk is a flag to indicate if the server instance is created on a trunk port or not.
100+
// +optional
101+
Trunk optional.Bool `json:"trunk,omitempty"`
102+
103+
// UserDataRef is a reference to a secret containing the user data to
104+
// be injected into the server instance.
105+
// +optional
106+
UserDataRef *corev1.LocalObjectReference `json:"userDataRef,omitempty"`
107+
}
108+
109+
// OpenStackServerStatus defines the observed state of OpenStackServer.
110+
type OpenStackServerStatus struct {
111+
// Ready is true when the OpenStack server is ready.
112+
// +kubebuilder:default=false
113+
Ready bool `json:"ready"`
114+
115+
// InstanceID is the ID of the server instance.
116+
// +optional
117+
InstanceID optional.String `json:"instanceID,omitempty"`
118+
119+
// InstanceState is the state of the server instance.
120+
// +optional
121+
InstanceState *infrav1.InstanceState `json:"instanceState,omitempty"`
122+
123+
// Addresses is the list of addresses of the server instance.
124+
// +optional
125+
Addresses []corev1.NodeAddress `json:"addresses,omitempty"`
126+
127+
// Resolved contains parts of the machine spec with all external
128+
// references fully resolved.
129+
// +optional
130+
Resolved *ResolvedServerSpec `json:"resolved,omitempty"`
131+
132+
// Resources contains references to OpenStack resources created for the machine.
133+
// +optional
134+
Resources *ServerResources `json:"resources,omitempty"`
135+
136+
// Conditions defines current service state of the OpenStackServer.
137+
// +optional
138+
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
139+
}
140+
141+
// +genclient
142+
// +kubebuilder:object:root=true
143+
// +kubebuilder:storageversion
144+
// +kubebuilder:resource:path=openstackservers,scope=Namespaced,categories=cluster-api,shortName=oss
145+
// +kubebuilder:subresource:status
146+
// +kubebuilder:printcolumn:name="InstanceState",type="string",JSONPath=".status.instanceState",description="OpenStack instance state"
147+
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="OpenStack instance ready status"
148+
// +kubebuilder:printcolumn:name="InstanceID",type="string",JSONPath=".status.instanceID",description="OpenStack instance ID"
149+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of OpenStack instance"
150+
151+
// OpenStackServer is the Schema for the openstackservers API.
152+
type OpenStackServer struct {
153+
metav1.TypeMeta `json:",inline"`
154+
metav1.ObjectMeta `json:"metadata,omitempty"`
155+
156+
Spec OpenStackServerSpec `json:"spec,omitempty"`
157+
Status OpenStackServerStatus `json:"status,omitempty"`
158+
}
159+
160+
// +kubebuilder:object:root=true
161+
162+
// OpenStackServerList contains a list of OpenStackServer.
163+
type OpenStackServerList struct {
164+
metav1.TypeMeta `json:",inline"`
165+
metav1.ListMeta `json:"metadata,omitempty"`
166+
Items []OpenStackServer `json:"items"`
167+
}
168+
169+
// GetConditions returns the observations of the operational state of the OpenStackServer resource.
170+
func (r *OpenStackServer) GetConditions() clusterv1.Conditions {
171+
return r.Status.Conditions
172+
}
173+
174+
// SetConditions sets the underlying service state of the OpenStackServer to the predescribed clusterv1.Conditions.
175+
func (r *OpenStackServer) SetConditions(conditions clusterv1.Conditions) {
176+
r.Status.Conditions = conditions
177+
}
178+
179+
var _ infrav1.IdentityRefProvider = &OpenStackFloatingIPPool{}
180+
181+
// GetIdentifyRef returns the Server's namespace and IdentityRef.
182+
func (r *OpenStackServer) GetIdentityRef() (*string, *infrav1.OpenStackIdentityReference) {
183+
return &r.Namespace, &r.Spec.IdentityRef
184+
}
185+
186+
func init() {
187+
SchemeBuilder.Register(&OpenStackServer{}, &OpenStackServerList{})
188+
}

api/v1alpha1/types.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2024 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+
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
21+
)
22+
23+
// ResolvedServerSpec contains resolved references to resources required by the server.
24+
type ResolvedServerSpec struct {
25+
// ServerGroupID is the ID of the server group the server should be added to and is calculated based on ServerGroupFilter.
26+
// +optional
27+
ServerGroupID string `json:"serverGroupID,omitempty"`
28+
29+
// ImageID is the ID of the image to use for the server and is calculated based on ImageFilter.
30+
// +optional
31+
ImageID string `json:"imageID,omitempty"`
32+
33+
// Ports is the fully resolved list of ports to create for the server.
34+
// +optional
35+
Ports []infrav1.ResolvedPortSpec `json:"ports,omitempty"`
36+
}
37+
38+
// ServerResources contains references to OpenStack resources created for the server.
39+
type ServerResources struct {
40+
// Ports is the status of the ports created for the server.
41+
// +optional
42+
Ports []infrav1.PortStatus `json:"ports,omitempty"`
43+
}

0 commit comments

Comments
 (0)