Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d78c229

Browse files
committedFeb 28, 2024·
Add DHCP server create configurations
1 parent 40efa1d commit d78c229

26 files changed

+1011
-639
lines changed
 

‎api/v1beta1/zz_generated.conversion.go

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/v1beta2/ibmpowervscluster_types.go

+92-10
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,22 @@ type IBMPowerVSClusterSpec struct {
3737
ServiceInstanceID string `json:"serviceInstanceID"`
3838

3939
// Network is the reference to the Network to use for this cluster.
40-
// when the field is omitted, A DHCP service will be created in the Power VS server workspace and its private network will be used.
40+
// when the field is omitted, A DHCP service will be created in the Power VS workspace and its private network will be used.
41+
// the DHCP service created network will have the following name format
42+
// 1. in the case of DHCPServer.Name is not set the name will be DHCPSERVER<CLUSTER_NAME>_Private.
43+
// 2. if DHCPServer.Name is set the name will be DHCPSERVER<DHCPServer.Name>_Private.
44+
// when Network.ID is set, its expected that there exist a network in PowerVS workspace with id or else system will give error.
45+
// when Network.Name is set, system will first check for network with Name in PowerVS workspace, if not exist network will be created by DHCP service.
46+
// Network.RegEx is not yet supported and system will ignore the value.
4147
Network IBMPowerVSResourceReference `json:"network"`
4248

49+
// dhcpServer is contains the configuration to be used while creating a new DHCP server in PowerVS workspace.
50+
// when the field is omitted, CLUSTER_NAME will be used as DHCPServer.Name and DHCP server will be created.
51+
// it will automatically create network with name DHCPSERVER<DHCPServer.Name>_Private in PowerVS workspace.
52+
// the default name
53+
// +optional
54+
DHCPServer *DHCPServer `json:"dhcpServer,omitempty"`
55+
4356
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
4457
// +optional
4558
ControlPlaneEndpoint capiv1beta1.APIEndpoint `json:"controlPlaneEndpoint"`
@@ -50,46 +63,108 @@ type IBMPowerVSClusterSpec struct {
5063
// supported serviceInstance identifier in PowerVSResource are Name and ID and that can be obtained from IBM Cloud UI or IBM Cloud cli.
5164
// More detail about Power VS service instance.
5265
// https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-creating-power-virtual-server
53-
// when omitted system will dynamically create the service instance
66+
// when omitted system will dynamically create the service instance with name CLUSTER_NAME-serviceInstance.
67+
// when ServiceInstance.ID is set, its expected that there exist a service instance in PowerVS workspace with id or else system will give error.
68+
// when ServiceInstance.Name is set, system will first check for service instance with Name in PowerVS workspace, if not exist system will create new instance.
69+
// ServiceInstance.Regex is not yet supported not yet supported and system will ignore the value.
5470
// +optional
5571
ServiceInstance *IBMPowerVSResourceReference `json:"serviceInstance,omitempty"`
5672

5773
// zone is the name of Power VS zone where the cluster will be created
5874
// possible values can be found here https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-creating-power-virtual-server.
75+
// when powervs.cluster.x-k8s.io/create-infra=true annotation is set on IBMPowerVSCluster resource,
76+
// 1. it is expected to set the zone, not setting will result in webhook error.
77+
// 2. the zone should have PER capabilities, or else system will give error.
5978
// +optional
6079
Zone *string `json:"zone,omitempty"`
6180

6281
// resourceGroup name under which the resources will be created.
63-
// when omitted default resource group of the account will be used.
82+
// when powervs.cluster.x-k8s.io/create-infra=true annotation is set on IBMPowerVSCluster resource,
83+
// 1. it is expected to set the ResourceGroup.Name, not setting will result in webhook error.
84+
// ServiceInstance.ID and ServiceInstance.Regex is not yet supported and system will ignore the value.
6485
// +optional
6586
ResourceGroup *IBMPowerVSResourceReference `json:"resourceGroup,omitempty"`
6687

6788
// vpc contains information about IBM Cloud VPC resources.
89+
// when omitted system will dynamically create the VPC with name CLUSTER_NAME-vpc.
90+
// when VPC.ID is set, its expected that there exist a VPC with ID or else system will give error.
91+
// when VPC.Name is set, system will first check for VPC with Name, if not exist system will create new VPC.
92+
// when powervs.cluster.x-k8s.io/create-infra=true annotation is set on IBMPowerVSCluster resource,
93+
// 1. it is expected to set the VPC.Region, not setting will result in webhook error.
6894
// +optional
6995
VPC *VPCResourceReference `json:"vpc,omitempty"`
7096

7197
// vpcSubnets contains information about IBM Cloud VPC Subnet resources.
98+
// when omitted system will create the subnets in all the zone corresponding to VPC.Region, with name CLUSTER_NAME-vpcsubnet-ZONE_NAME.
99+
// possible values can be found here https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-creating-power-virtual-server.
100+
// when VPCSubnets[].ID is set, its expected that there exist a subnet with ID or else system will give error.
101+
// when VPCSubnets[].Zone is not set, a random zone is picked from available zones of VPC.Region.
102+
// when VPCSubnets[].Name is not set, system will set name as CLUSTER_NAME-vpcsubnet-INDEX.
103+
// if subnet with name VPCSubnets[].Name not found, system will create new subnet in VPCSubnets[].Zone.
72104
// +optional
73105
VPCSubnets []Subnet `json:"vpcSubnets,omitempty"`
74106

75107
// transitGateway contains information about IBM Cloud TransitGateway
76108
// IBM Cloud TransitGateway helps in establishing network connectivity between IBM Cloud Power VS and VPC infrastructure
77109
// more information about TransitGateway can be found here https://www.ibm.com/products/transit-gateway.
110+
// when TransitGateway.ID is set, its expected that there exist a TransitGateway with ID or else system will give error.
111+
// when TransitGateway.Name is set, system will first check for TransitGateway with Name, if not exist system will create new TransitGateway.
78112
// +optional
79113
TransitGateway *TransitGateway `json:"transitGateway,omitempty"`
80114

81-
// loadBalancers is optional configuration for configuring loadbalancers to control plane or data plane nodes
115+
// loadBalancers is optional configuration for configuring loadbalancers to control plane or data plane nodes.
116+
// when omitted system will create a public loadbalancer with name CLUSTER_NAME-loadbalancer.
82117
// when specified a vpc loadbalancer will be created and controlPlaneEndpoint will be set with associated hostname of loadbalancer.
83-
// when omitted user is expected to set controlPlaneEndpoint.
118+
// ControlPlaneEndpoint will be set with associated hostname of public loadbalancer.
119+
// when LoadBalancers[].ID is set, its expected that there exist a loadbalancer with ID or else system will give error.
120+
// when LoadBalancers[].Name is set, system will first check for loadbalancer with Name, if not exist system will create new loadbalancer.
84121
// +optional
85122
LoadBalancers []VPCLoadBalancerSpec `json:"loadBalancers,omitempty"`
86123

87124
// cosInstance contains options to configure a supporting IBM Cloud COS bucket for this
88125
// cluster - currently used for nodes requiring Ignition
89126
// (https://coreos.github.io/ignition/) for bootstrapping (requires
90127
// BootstrapFormatIgnition feature flag to be enabled).
128+
// when powervs.cluster.x-k8s.io/create-infra=true annotation is set on IBMPowerVSCluster resource and Ignition is set, then
129+
// 1. CosInstance.Name should be set not setting will result in webhook error.
130+
// 2. CosInstance.BucketName should be set not setting will result in webhook error.
131+
// 3. CosInstance.BucketRegion should be set not setting will result in webhook error.
91132
// +optional
92133
CosInstance *CosInstance `json:"cosInstance,omitempty"`
134+
135+
// Ignition defined options related to the bootstrapping systems where Ignition is used.
136+
// +optional
137+
Ignition *Ignition `json:"ignition,omitempty"`
138+
}
139+
140+
// Ignition defines options related to the bootstrapping systems where Ignition is used.
141+
type Ignition struct {
142+
// Version defines which version of Ignition will be used to generate bootstrap data.
143+
//
144+
// +optional
145+
// +kubebuilder:default="2.3"
146+
// +kubebuilder:validation:Enum="2.3";"2.4";"3.0";"3.1";"3.2";"3.3";"3.4"
147+
Version string `json:"version,omitempty"`
148+
}
149+
150+
// DHCPServer contains the DHCP server configurations.
151+
type DHCPServer struct {
152+
// Optional cidr for DHCP private network
153+
Cidr *string `json:"cidr,omitempty"`
154+
155+
// Optional DNS Server for DHCP service
156+
// +kubebuilder:default="1.1.1.1"
157+
DNSServer *string `json:"dnsServer,omitempty"`
158+
159+
// Optional name of DHCP Service. Only alphanumeric characters and dashes are allowed.
160+
Name *string `json:"name,omitempty"`
161+
162+
// Optional id of the existing DHCPServer
163+
ID *string `json:"id,omitempty"`
164+
165+
// Optional indicates if SNAT will be enabled for DHCP service
166+
// +kubebuilder:default=true
167+
Snat *bool `json:"snat,omitempty"`
93168
}
94169

95170
// ResourceReference identifies a resource with id.
@@ -167,31 +242,38 @@ type IBMPowerVSClusterList struct {
167242

168243
// TransitGateway holds the TransitGateway information.
169244
type TransitGateway struct {
245+
// name of resource.
246+
// +optional
170247
Name *string `json:"name,omitempty"`
171-
ID *string `json:"id,omitempty"`
248+
// id of resource.
249+
// +optional
250+
ID *string `json:"id,omitempty"`
172251
}
173252

174253
// VPCResourceReference is a reference to a specific VPC resource by ID or Name
175254
// Only one of ID or Name may be specified. Specifying more than one will result in
176255
// a validation error.
177256
type VPCResourceReference struct {
178-
// ID of resource
257+
// id of resource.
179258
// +kubebuilder:validation:MinLength=1
180259
// +optional
181260
ID *string `json:"id,omitempty"`
182261

183-
// Name of resource
262+
// name of resource.
184263
// +kubebuilder:validation:MinLength=1
185264
// +optional
186265
Name *string `json:"name,omitempty"`
187266

188-
// IBM Cloud VPC region
267+
// region of IBM Cloud VPC.
268+
// when powervs.cluster.x-k8s.io/create-infra=true annotation is set on IBMPowerVSCluster resource,
269+
// it is expected to set the region, not setting will result in webhook error.
189270
Region *string `json:"region,omitempty"`
190271
}
191272

192273
// CosInstance represents IBM Cloud COS instance.
193274
type CosInstance struct {
194-
// Name defines name of IBM cloud COS instance to be created.
275+
// name defines name of IBM cloud COS instance to be created.
276+
// when IBMPowerVSCluster.Ignition is set
195277
// +kubebuilder:validation:MinLength:=3
196278
// +kubebuilder:validation:MaxLength:=63
197279
// +kubebuilder:validation:Pattern=`^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$`

‎api/v1beta2/ibmpowervscluster_webhook.go

+60
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
"strconv"
21+
2022
apierrors "k8s.io/apimachinery/pkg/api/errors"
2123
"k8s.io/apimachinery/pkg/runtime"
2224
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -74,6 +76,11 @@ func (r *IBMPowerVSCluster) validateIBMPowerVSCluster() (admission.Warnings, err
7476
if err := r.validateIBMPowerVSClusterNetwork(); err != nil {
7577
allErrs = append(allErrs, err)
7678
}
79+
80+
if err := r.validateIBMPowerVSClusterCreateInfraPrereq(); err != nil {
81+
allErrs = append(allErrs, err)
82+
}
83+
7784
if len(allErrs) == 0 {
7885
return nil, nil
7986
}
@@ -89,3 +96,56 @@ func (r *IBMPowerVSCluster) validateIBMPowerVSClusterNetwork() *field.Error {
8996
}
9097
return nil
9198
}
99+
100+
func (r *IBMPowerVSCluster) validateIBMPowerVSClusterCreateInfraPrereq() *field.Error {
101+
annotations := r.GetAnnotations()
102+
if len(annotations) == 0 {
103+
return nil
104+
}
105+
106+
value, found := annotations[CreateInfrastructureAnnotation]
107+
if !found {
108+
return nil
109+
}
110+
111+
createInfra, err := strconv.ParseBool(value)
112+
if err != nil {
113+
return field.Invalid(field.NewPath("annotations"), r.Annotations, "value of powervs.cluster.x-k8s.io/create-infra should be boolean")
114+
}
115+
116+
if !createInfra {
117+
return nil
118+
}
119+
120+
if r.Spec.Zone == nil {
121+
return field.Invalid(field.NewPath("spec.zone"), r.Spec.Zone, "value of zone is empty")
122+
}
123+
124+
if r.Spec.VPC.Region == nil {
125+
return field.Invalid(field.NewPath("spec.vpc.region"), r.Spec.VPC.Region, "value of VPC region is empty")
126+
}
127+
128+
if r.Spec.ResourceGroup == nil {
129+
return field.Invalid(field.NewPath("spec.resourceGroup"), r.Spec.ResourceGroup, "value of resource group is empty")
130+
}
131+
132+
if r.Spec.Ignition == nil {
133+
return nil
134+
}
135+
136+
// TODO(Phase 1): If ignition is set and these resources are not set, auto create them.
137+
// If ignition is set, make sure to check that CosInstanceName, BucketName and region is set
138+
if r.Spec.CosInstance == nil {
139+
return field.Invalid(field.NewPath("spec.cosInstance"), r.Spec.CosInstance, "ignition is set but value of cosInstance is empty")
140+
}
141+
if r.Spec.CosInstance.Name == "" {
142+
return field.Invalid(field.NewPath("spec.cosInstance.name"), r.Spec.CosInstance, "ignition is set but value of cosInstance name is empty")
143+
}
144+
if r.Spec.CosInstance.BucketName == "" {
145+
return field.Invalid(field.NewPath("spec.cosInstance.bucketName"), r.Spec.CosInstance, "ignition is set but value of bucketName is empty")
146+
}
147+
if r.Spec.CosInstance.BucketRegion == "" {
148+
return field.Invalid(field.NewPath("spec.cosInstance.bucketRegion"), r.Spec.CosInstance, "ignition is set but value of bucketRegion is empty")
149+
}
150+
return nil
151+
}

‎api/v1beta2/ibmpowervsmachine_types.go

-14
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,6 @@ type IBMPowerVSMachineSpec struct {
133133
// ProviderID is the unique identifier as specified by the cloud provider.
134134
// +optional
135135
ProviderID *string `json:"providerID,omitempty"`
136-
137-
// Ignition defined options related to the bootstrapping systems where Ignition is used.
138-
// +optional
139-
Ignition *Ignition `json:"ignition,omitempty"`
140-
}
141-
142-
// Ignition defines options related to the bootstrapping systems where Ignition is used.
143-
type Ignition struct {
144-
// Version defines which version of Ignition will be used to generate bootstrap data.
145-
//
146-
// +optional
147-
// +kubebuilder:default="2.3"
148-
// +kubebuilder:validation:Enum="2.3";"3.0";"3.1";"3.2";"3.3";"3.4"
149-
Version string `json:"version,omitempty"`
150136
}
151137

152138
// IBMPowerVSResourceReference is a reference to a specific PowerVS resource by ID, Name or RegEx

‎api/v1beta2/ibmvpccluster_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ type VPCLoadBalancerSpec struct {
6363
// +optional
6464
Name string `json:"name,omitempty"`
6565

66+
// id of the loadbalancer
67+
// +optional
68+
ID *string `json:"id,omitempty"`
69+
6670
// public indicates that load balancer is public or private
6771
// +kubebuilder:default=true
6872
// +optional

‎api/v1beta2/types.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ limitations under the License.
1616

1717
package v1beta2
1818

19-
// APIServerPort is API server port number.
20-
const APIServerPort int32 = 6443
19+
// DefaultAPIServerPort is defuault API server port number.
20+
const DefaultAPIServerPort int32 = 6443
2121

2222
// PowerVSInstanceState describes the state of an IBM Power VS instance.
2323
type PowerVSInstanceState string
@@ -71,10 +71,21 @@ var (
7171
type TransitGatewayState string
7272

7373
var (
74+
// TransitGatewayStateAvailable is the string representing a transit gateway in available state.
75+
TransitGatewayStateAvailable = TransitGatewayState("available")
76+
7477
// TransitGatewayStateDeletePending is the string representing a transit gateway in deleting state.
7578
TransitGatewayStateDeletePending = TransitGatewayState("deleting")
7679
)
7780

81+
// TransitGatewayConnectionState describes the state of an IBM Transit Gateway connection.
82+
type TransitGatewayConnectionState string
83+
84+
var (
85+
// TransitGatewayConnectionStateAttached is the string representing a transit gateway connection in attached state.
86+
TransitGatewayConnectionStateAttached = TransitGatewayConnectionState("attached")
87+
)
88+
7889
// VPCLoadBalancerState describes the state of the load balancer.
7990
type VPCLoadBalancerState string
8091

@@ -121,7 +132,7 @@ var (
121132
ResourceTypeTransitGateway = ResourceType("transitGateway")
122133
// ResourceTypeVPC is Power VS network resource.
123134
ResourceTypeVPC = ResourceType("vpc")
124-
// SResourceTypeubnet is VPC subnet resource.
135+
// ResourceTypeSubnet is VPC subnet resource.
125136
ResourceTypeSubnet = ResourceType("subnet")
126137
// ResourceTypeCOSInstance is IBM COS instance resource.
127138
ResourceTypeCOSInstance = ResourceType("cosInstance")

0 commit comments

Comments
 (0)
Please sign in to comment.