Skip to content

Commit 8d854f9

Browse files
Rename VPC security group types (#1783)
Remove VPC and resource group field from VPC security group since it is causing confusion by providing an option to pass a different resource than the one used in cluster
1 parent 2c2b640 commit 8d854f9

File tree

2 files changed

+233
-251
lines changed

2 files changed

+233
-251
lines changed

api/v1beta2/types.go

Lines changed: 74 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -190,62 +190,62 @@ var (
190190
ResourceTypeResourceGroup = ResourceType("resourceGroup")
191191
)
192192

193-
// SecurityGroupRuleAction represents the actions for a Security Group Rule.
193+
// VPCSecurityGroupRuleAction represents the actions for a Security Group Rule.
194194
// +kubebuilder:validation:Enum=allow;deny
195-
type SecurityGroupRuleAction string
195+
type VPCSecurityGroupRuleAction string
196196

197197
const (
198-
// SecurityGroupRuleActionAllow defines that the Rule should allow traffic.
199-
SecurityGroupRuleActionAllow SecurityGroupRuleAction = vpcv1.NetworkACLRuleActionAllowConst
200-
// SecurityGroupRuleActionDeny defines that the Rule should deny traffic.
201-
SecurityGroupRuleActionDeny SecurityGroupRuleAction = vpcv1.NetworkACLRuleActionDenyConst
198+
// VPCSecurityGroupRuleActionAllow defines that the Rule should allow traffic.
199+
VPCSecurityGroupRuleActionAllow VPCSecurityGroupRuleAction = vpcv1.NetworkACLRuleActionAllowConst
200+
// VPCSecurityGroupRuleActionDeny defines that the Rule should deny traffic.
201+
VPCSecurityGroupRuleActionDeny VPCSecurityGroupRuleAction = vpcv1.NetworkACLRuleActionDenyConst
202202
)
203203

204-
// SecurityGroupRuleDirection represents the directions for a Security Group Rule.
204+
// VPCSecurityGroupRuleDirection represents the directions for a Security Group Rule.
205205
// +kubebuilder:validation:Enum=inbound;outbound
206-
type SecurityGroupRuleDirection string
206+
type VPCSecurityGroupRuleDirection string
207207

208208
const (
209-
// SecurityGroupRuleDirectionInbound defines the Rule is for inbound traffic.
210-
SecurityGroupRuleDirectionInbound SecurityGroupRuleDirection = vpcv1.NetworkACLRuleDirectionInboundConst
211-
// SecurityGroupRuleDirectionOutbound defines the Rule is for outbound traffic.
212-
SecurityGroupRuleDirectionOutbound SecurityGroupRuleDirection = vpcv1.NetworkACLRuleDirectionOutboundConst
209+
// VPCSecurityGroupRuleDirectionInbound defines the Rule is for inbound traffic.
210+
VPCSecurityGroupRuleDirectionInbound VPCSecurityGroupRuleDirection = vpcv1.NetworkACLRuleDirectionInboundConst
211+
// VPCSecurityGroupRuleDirectionOutbound defines the Rule is for outbound traffic.
212+
VPCSecurityGroupRuleDirectionOutbound VPCSecurityGroupRuleDirection = vpcv1.NetworkACLRuleDirectionOutboundConst
213213
)
214214

215-
// SecurityGroupRuleProtocol represents the protocols for a Security Group Rule.
215+
// VPCSecurityGroupRuleProtocol represents the protocols for a Security Group Rule.
216216
// +kubebuilder:validation:Enum=all;icmp;tcp;udp
217-
type SecurityGroupRuleProtocol string
217+
type VPCSecurityGroupRuleProtocol string
218218

219219
const (
220-
// SecurityGroupRuleProtocolAll defines the Rule is for all network protocols.
221-
SecurityGroupRuleProtocolAll SecurityGroupRuleProtocol = vpcv1.NetworkACLRuleProtocolAllConst
222-
// SecurityGroupRuleProtocolIcmp defiens the Rule is for ICMP network protocol.
223-
SecurityGroupRuleProtocolIcmp SecurityGroupRuleProtocol = vpcv1.NetworkACLRuleProtocolIcmpConst
224-
// SecurityGroupRuleProtocolTCP defines the Rule is for TCP network protocol.
225-
SecurityGroupRuleProtocolTCP SecurityGroupRuleProtocol = vpcv1.NetworkACLRuleProtocolTCPConst
226-
// SecurityGroupRuleProtocolUDP defines the Rule is for UDP network protocol.
227-
SecurityGroupRuleProtocolUDP SecurityGroupRuleProtocol = vpcv1.NetworkACLRuleProtocolUDPConst
220+
// VPCSecurityGroupRuleProtocolAll defines the Rule is for all network protocols.
221+
VPCSecurityGroupRuleProtocolAll VPCSecurityGroupRuleProtocol = vpcv1.NetworkACLRuleProtocolAllConst
222+
// VPCSecurityGroupRuleProtocolIcmp defiens the Rule is for ICMP network protocol.
223+
VPCSecurityGroupRuleProtocolIcmp VPCSecurityGroupRuleProtocol = vpcv1.NetworkACLRuleProtocolIcmpConst
224+
// VPCSecurityGroupRuleProtocolTCP defines the Rule is for TCP network protocol.
225+
VPCSecurityGroupRuleProtocolTCP VPCSecurityGroupRuleProtocol = vpcv1.NetworkACLRuleProtocolTCPConst
226+
// VPCSecurityGroupRuleProtocolUDP defines the Rule is for UDP network protocol.
227+
VPCSecurityGroupRuleProtocolUDP VPCSecurityGroupRuleProtocol = vpcv1.NetworkACLRuleProtocolUDPConst
228228
)
229229

230-
// SecurityGroupRuleRemoteType represents the type of Security Group Rule's destination or source is
231-
// intended. This is intended to define the SecurityGroupRulePrototype subtype.
230+
// VPCSecurityGroupRuleRemoteType represents the type of Security Group Rule's destination or source is
231+
// intended. This is intended to define the VPCSecurityGroupRulePrototype subtype.
232232
// For example:
233233
// - any - Any source or destination (0.0.0.0/0)
234234
// - cidr - A CIDR representing a set of IP's (10.0.0.0/28)
235235
// - ip - A specific IP address (192.168.0.1)
236236
// - sg - A Security Group.
237237
// +kubebuilder:validation:Enum=any;cidr;ip;sg
238-
type SecurityGroupRuleRemoteType string
238+
type VPCSecurityGroupRuleRemoteType string
239239

240240
const (
241-
// SecurityGroupRuleRemoteTypeAny defines the destination or source for the Rule is anything/anywhere.
242-
SecurityGroupRuleRemoteTypeAny SecurityGroupRuleRemoteType = SecurityGroupRuleRemoteType("any")
243-
// SecurityGroupRuleRemoteTypeCIDR defines the destination or source for the Rule is a CIDR block.
244-
SecurityGroupRuleRemoteTypeCIDR SecurityGroupRuleRemoteType = SecurityGroupRuleRemoteType("cidr")
245-
// SecurityGroupRuleRemoteTypeIP defines the destination or source for the Rule is an IP address.
246-
SecurityGroupRuleRemoteTypeIP SecurityGroupRuleRemoteType = SecurityGroupRuleRemoteType("ip")
247-
// SecurityGroupRuleRemoteTypeSG defines the destination or source for the Rule is a VPC Security Group.
248-
SecurityGroupRuleRemoteTypeSG SecurityGroupRuleRemoteType = SecurityGroupRuleRemoteType("sg")
241+
// VPCSecurityGroupRuleRemoteTypeAny defines the destination or source for the Rule is anything/anywhere.
242+
VPCSecurityGroupRuleRemoteTypeAny VPCSecurityGroupRuleRemoteType = VPCSecurityGroupRuleRemoteType("any")
243+
// VPCSecurityGroupRuleRemoteTypeCIDR defines the destination or source for the Rule is a CIDR block.
244+
VPCSecurityGroupRuleRemoteTypeCIDR VPCSecurityGroupRuleRemoteType = VPCSecurityGroupRuleRemoteType("cidr")
245+
// VPCSecurityGroupRuleRemoteTypeIP defines the destination or source for the Rule is an IP address.
246+
VPCSecurityGroupRuleRemoteTypeIP VPCSecurityGroupRuleRemoteType = VPCSecurityGroupRuleRemoteType("ip")
247+
// VPCSecurityGroupRuleRemoteTypeSG defines the destination or source for the Rule is a VPC Security Group.
248+
VPCSecurityGroupRuleRemoteTypeSG VPCSecurityGroupRuleRemoteType = VPCSecurityGroupRuleRemoteType("sg")
249249
)
250250

251251
// NetworkInterface holds the network interface information like subnet id.
@@ -254,9 +254,9 @@ type NetworkInterface struct {
254254
Subnet string `json:"subnet,omitempty"`
255255
}
256256

257-
// PortRange represents a range of ports, minimum to maximum.
257+
// VPCSecurityGroupPortRange represents a range of ports, minimum to maximum.
258258
// +kubebuilder:validation:XValidation:rule="self.maximumPort >= self.minimumPort",message="maximum port must be greater than or equal to minimum port"
259-
type PortRange struct {
259+
type VPCSecurityGroupPortRange struct {
260260
// maximumPort is the inclusive upper range of ports.
261261
// +kubebuilder:validation:Minimum=1
262262
// +kubebuilder:validation:Maximum=65535
@@ -268,9 +268,9 @@ type PortRange struct {
268268
MinimumPort int64 `json:"minimumPort,omitempty"`
269269
}
270270

271-
// SecurityGroup defines a VPC Security Group that should exist or be created within the specified VPC, with the specified Security Group Rules.
271+
// VPCSecurityGroup defines a VPC Security Group that should exist or be created within the specified VPC, with the specified Security Group Rules.
272272
// +kubebuilder:validation:XValidation:rule="has(self.id) || has(self.name)",message="either an id or name must be specified"
273-
type SecurityGroup struct {
273+
type VPCSecurityGroup struct {
274274
// id of the Security Group.
275275
// +optional
276276
ID *string `json:"id,omitempty"`
@@ -279,107 +279,99 @@ type SecurityGroup struct {
279279
// +optional
280280
Name *string `json:"name,omitempty"`
281281

282-
// resourceGroup of the Security Group.
283-
// +optional
284-
ResourceGroup *string `json:"resourceGroup,omitempty"`
285-
286282
// rules are the Security Group Rules for the Security Group.
287283
// +optional
288-
Rules []*SecurityGroupRule `json:"rules,omitempty"`
284+
Rules []*VPCSecurityGroupRule `json:"rules,omitempty"`
289285

290286
// tags are tags to add to the Security Group.
291287
// +optional
292288
Tags []*string `json:"tags,omitempty"`
293-
294-
// vpc is the IBM Cloud VPC for the Security Group.
295-
// +optional
296-
VPC *VPCResourceReference `json:"vpc,omitempty"`
297289
}
298290

299-
// SecurityGroupRule defines a VPC Security Group Rule for a specified Security Group.
291+
// VPCSecurityGroupRule defines a VPC Security Group Rule for a specified Security Group.
300292
// +kubebuilder:validation:XValidation:rule="(has(self.destination) && !has(self.source)) || (!has(self.destination) && has(self.source))",message="both destination and source cannot be provided"
301-
// +kubebuilder:validation:XValidation:rule="self.direction == 'inbound' ? has(self.source) : true",message="source must be set for SecurityGroupRuleDirectionInbound direction"
302-
// +kubebuilder:validation:XValidation:rule="self.direction == 'inbound' ? !has(self.destination) : true",message="destination is not valid for SecurityGroupRuleDirectionInbound direction"
303-
// +kubebuilder:validation:XValidation:rule="self.direction == 'outbound' ? has(self.destination) : true",message="destination must be set for SecurityGroupRuleDirectionOutbound direction"
304-
// +kubebuilder:validation:XValidation:rule="self.direction == 'outbound' ? !has(self.source) : true",message="source is not valid for SecurityGroupRuleDirectionOutbound direction"
305-
type SecurityGroupRule struct {
293+
// +kubebuilder:validation:XValidation:rule="self.direction == 'inbound' ? has(self.source) : true",message="source must be set for VPCSecurityGroupRuleDirectionInbound direction"
294+
// +kubebuilder:validation:XValidation:rule="self.direction == 'inbound' ? !has(self.destination) : true",message="destination is not valid for VPCSecurityGroupRuleDirectionInbound direction"
295+
// +kubebuilder:validation:XValidation:rule="self.direction == 'outbound' ? has(self.destination) : true",message="destination must be set for VPCSecurityGroupRuleDirectionOutbound direction"
296+
// +kubebuilder:validation:XValidation:rule="self.direction == 'outbound' ? !has(self.source) : true",message="source is not valid for VPCSecurityGroupRuleDirectionOutbound direction"
297+
type VPCSecurityGroupRule struct {
306298
// action defines whether to allow or deny traffic defined by the Security Group Rule.
307299
// +required
308-
Action SecurityGroupRuleAction `json:"action"`
300+
Action VPCSecurityGroupRuleAction `json:"action"`
309301

310-
// destination is a SecurityGroupRulePrototype which defines the destination of outbound traffic for the Security Group Rule.
311-
// Only used when direction is SecurityGroupRuleDirectionOutbound.
302+
// destination is a VPCSecurityGroupRulePrototype which defines the destination of outbound traffic for the Security Group Rule.
303+
// Only used when direction is VPCSecurityGroupRuleDirectionOutbound.
312304
// +optional
313-
Destination *SecurityGroupRulePrototype `json:"destination,omitempty"`
305+
Destination *VPCSecurityGroupRulePrototype `json:"destination,omitempty"`
314306

315307
// direction defines whether the traffic is inbound or outbound for the Security Group Rule.
316308
// +required
317-
Direction SecurityGroupRuleDirection `json:"direction"`
309+
Direction VPCSecurityGroupRuleDirection `json:"direction"`
318310

319311
// securityGroupID is the ID of the Security Group for the Security Group Rule.
320312
// +optional
321313
SecurityGroupID *string `json:"securityGroupID,omitempty"`
322314

323-
// source is a SecurityGroupRulePrototype which defines the source of inbound traffic for the Security Group Rule.
324-
// Only used when direction is SecurityGroupRuleDirectionInbound.
315+
// source is a VPCSecurityGroupRulePrototype which defines the source of inbound traffic for the Security Group Rule.
316+
// Only used when direction is VPCSecurityGroupRuleDirectionInbound.
325317
// +optional
326-
Source *SecurityGroupRulePrototype `json:"source,omitempty"`
318+
Source *VPCSecurityGroupRulePrototype `json:"source,omitempty"`
327319
}
328320

329-
// SecurityGroupRuleRemote defines a VPC Security Group Rule's remote details.
321+
// VPCSecurityGroupRuleRemote defines a VPC Security Group Rule's remote details.
330322
// The type of remote defines the additional remote details where are used for defining the remote.
331-
// +kubebuilder:validation:XValidation:rule="self.remoteType == 'any' ? (!has(self.cidrSubnetName) && !has(self.ip) && !has(self.securityGroupName)) : true",message="cidrSubnetName, ip, and securityGroupName are not valid for SecurityGroupRuleRemoteTypeAny remoteType"
332-
// +kubebuilder:validation:XValidation:rule="self.remoteType == 'cidr' ? (has(self.cidrSubnetName) && !has(self.ip) && !has(self.securityGroupName)) : true",message="only cidrSubnetName is valid for SecurityGroupRuleRemoteTypeCIDR remoteType"
333-
// +kubebuilder:validation:XValidation:rule="self.remoteType == 'ip' ? (has(self.ip) && !has(self.cidrSubnetName) && !has(self.securityGroupName)) : true",message="only ip is valid for SecurityGroupRuleRemoteTypeIP remoteType"
334-
// +kubebuilder:validation:XValidation:rule="self.remoteType == 'sg' ? (has(self.securityGroupName) && !has(self.cidrSubnetName) && !has(self.ip)) : true",message="only securityGroupName is valid for SecurityGroupRuleRemoteTypeSG remoteType"
335-
type SecurityGroupRuleRemote struct {
323+
// +kubebuilder:validation:XValidation:rule="self.remoteType == 'any' ? (!has(self.cidrSubnetName) && !has(self.ip) && !has(self.securityGroupName)) : true",message="cidrSubnetName, ip, and securityGroupName are not valid for VPCSecurityGroupRuleRemoteTypeAny remoteType"
324+
// +kubebuilder:validation:XValidation:rule="self.remoteType == 'cidr' ? (has(self.cidrSubnetName) && !has(self.ip) && !has(self.securityGroupName)) : true",message="only cidrSubnetName is valid for VPCSecurityGroupRuleRemoteTypeCIDR remoteType"
325+
// +kubebuilder:validation:XValidation:rule="self.remoteType == 'ip' ? (has(self.ip) && !has(self.cidrSubnetName) && !has(self.securityGroupName)) : true",message="only ip is valid for VPCSecurityGroupRuleRemoteTypeIP remoteType"
326+
// +kubebuilder:validation:XValidation:rule="self.remoteType == 'sg' ? (has(self.securityGroupName) && !has(self.cidrSubnetName) && !has(self.ip)) : true",message="only securityGroupName is valid for VPCSecurityGroupRuleRemoteTypeSG remoteType"
327+
type VPCSecurityGroupRuleRemote struct {
336328
// cidrSubnetName is the name of the VPC Subnet to retrieve the CIDR from, to use for the remote's destination/source.
337-
// Only used when remoteType is SecurityGroupRuleRemoteTypeCIDR.
329+
// Only used when remoteType is VPCSecurityGroupRuleRemoteTypeCIDR.
338330
// +optional
339331
CIDRSubnetName *string `json:"cidrSubnetName,omitempty"`
340332

341333
// ip is the IP to use for the remote's destination/source.
342-
// Only used when remoteType is SecurityGroupRuleRemoteTypeIP.
334+
// Only used when remoteType is VPCSecurityGroupRuleRemoteTypeIP.
343335
// +optional
344336
IP *string `json:"ip,omitempty"`
345337

346338
// remoteType defines the type of filter to define for the remote's destination/source.
347339
// +required
348-
RemoteType SecurityGroupRuleRemoteType `json:"remoteType"`
340+
RemoteType VPCSecurityGroupRuleRemoteType `json:"remoteType"`
349341

350342
// securityGroupName is the name of the VPC Security Group to use for the remote's destination/source.
351-
// Only used when remoteType is SecurityGroupRuleRemoteTypeSG
343+
// Only used when remoteType is VPCSecurityGroupRuleRemoteTypeSG
352344
// +optional
353345
SecurityGroupName *string `json:"securityGroupName,omitempty"`
354346
}
355347

356-
// SecurityGroupRulePrototype defines a VPC Security Group Rule's traffic specifics for a series of remotes (destinations or sources).
357-
// +kubebuilder:validation:XValidation:rule="self.protocol != 'icmp' ? (!has(self.icmpCode) && !has(self.icmpType)) : true",message="icmpCode and icmpType are only supported for SecurityGroupRuleProtocolIcmp protocol"
358-
// +kubebuilder:validation:XValidation:rule="self.protocol == 'all' ? !has(self.portRange) : true",message="portRange is not valid for SecurityGroupRuleProtocolAll protocol"
359-
// +kubebuilder:validation:XValidation:rule="self.protocol == 'icmp' ? !has(self.portRange) : true",message="portRange is not valid for SecurityGroupRuleProtocolIcmp protocol"
360-
type SecurityGroupRulePrototype struct {
348+
// VPCSecurityGroupRulePrototype defines a VPC Security Group Rule's traffic specifics for a series of remotes (destinations or sources).
349+
// +kubebuilder:validation:XValidation:rule="self.protocol != 'icmp' ? (!has(self.icmpCode) && !has(self.icmpType)) : true",message="icmpCode and icmpType are only supported for VPCSecurityGroupRuleProtocolIcmp protocol"
350+
// +kubebuilder:validation:XValidation:rule="self.protocol == 'all' ? !has(self.portRange) : true",message="portRange is not valid for VPCSecurityGroupRuleProtocolAll protocol"
351+
// +kubebuilder:validation:XValidation:rule="self.protocol == 'icmp' ? !has(self.portRange) : true",message="portRange is not valid for VPCSecurityGroupRuleProtocolIcmp protocol"
352+
type VPCSecurityGroupRulePrototype struct {
361353
// icmpCode is the ICMP code for the Rule.
362-
// Only used when Protocol is SecurityGroupProtocolICMP.
354+
// Only used when Protocol is VPCSecurityGroupRuleProtocolIcmp.
363355
// +optional
364356
ICMPCode *int64 `json:"icmpCode,omitempty"`
365357

366358
// icmpType is the ICMP type for the Rule.
367-
// Only used when Protocol is SecurityGroupProtocolICMP.
359+
// Only used when Protocol is VPCSecurityGroupRuleProtocolIcmp.
368360
// +optional
369361
ICMPType *int64 `json:"icmpType,omitempty"`
370362

371363
// portRange is a range of ports allowed for the Rule's remote.
372364
// +optional
373-
PortRange *PortRange `json:"portRange,omitempty"`
365+
PortRange *VPCSecurityGroupPortRange `json:"portRange,omitempty"`
374366

375367
// protocol defines the traffic protocol used for the Security Group Rule.
376368
// +required
377-
Protocol SecurityGroupRuleProtocol `json:"protocol"`
369+
Protocol VPCSecurityGroupRuleProtocol `json:"protocol"`
378370

379-
// remotes is a set of SecurityGroupRuleRemote's that define the traffic allowed by the Rule's remote.
380-
// Specifying multiple SecurityGroupRuleRemote's creates a unique Security Group Rule with the shared Protocol, PortRange, etc.
371+
// remotes is a set of VPCSecurityGroupRuleRemote's that define the traffic allowed by the Rule's remote.
372+
// Specifying multiple VPCSecurityGroupRuleRemote's creates a unique Security Group Rule with the shared Protocol, PortRange, etc.
381373
// This allows for easier management of Security Group Rule's for sets of CIDR's, IP's, etc.
382-
Remotes []SecurityGroupRuleRemote `json:"remotes"`
374+
Remotes []VPCSecurityGroupRuleRemote `json:"remotes"`
383375
}
384376

385377
// Subnet describes a subnet.

0 commit comments

Comments
 (0)