Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lowercase regex validation for vpc, vpcsubnet and loadbalancer names #1715

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/v1beta2/ibmpowervscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ type DHCPServer struct {
DNSServer *string `json:"dnsServer,omitempty"`

// Optional name of DHCP Service. Only alphanumeric characters and dashes are allowed.
// +kubebuilder:validation:MaxLength:=63
// +kubebuilder:validation:Pattern=`^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$`
Name *string `json:"name,omitempty"`

// Optional id of the existing DHCPServer
Expand Down Expand Up @@ -243,6 +245,8 @@ type IBMPowerVSClusterList struct {
// TransitGateway holds the TransitGateway information.
type TransitGateway struct {
// name of resource.
// +kubebuilder:validation:MaxLength:=63
// +kubebuilder:validation:Pattern=`^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you manually verified from UI this before adding the check?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the reference https://cloud.ibm.com/apidocs/transit-gateway#create-transit-gateway, It does support capital letters

// +optional
Name *string `json:"name,omitempty"`
// id of resource.
Expand All @@ -261,6 +265,8 @@ type VPCResourceReference struct {

// name of resource.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength:=63
// +kubebuilder:validation:Pattern=`^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$`
// +optional
Name *string `json:"name,omitempty"`

Expand Down
2 changes: 2 additions & 0 deletions api/v1beta2/ibmpowervsmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ type IBMPowerVSResourceReference struct {

// Name of resource
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength:=63
Copy link
Contributor

@Amulyam24 Amulyam24 Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shilpa-Gokul, can you share why pattern validation was added to IBMPowerVSResourceReference? ResourceGroup is of type IBMPowerVSResourceReference and I see that is supports camel case and capital letters in case user specifies it.
Would it maybe be possible to add to the specific resource than adding it here?

// +kubebuilder:validation:Pattern=`^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$`
// +optional
Name *string `json:"name,omitempty"`

Expand Down
1 change: 1 addition & 0 deletions api/v1beta2/ibmvpccluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type IBMVPCClusterSpec struct {
type VPCLoadBalancerSpec struct {
// Name sets the name of the VPC load balancer.
// +kubebuilder:validation:MaxLength:=63
// +kubebuilder:validation:Pattern=`^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$`
// +optional
Name string `json:"name,omitempty"`

Expand Down
8 changes: 5 additions & 3 deletions api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,11 @@ type SecurityGroupRulePrototype struct {
// Subnet describes a subnet.
type Subnet struct {
Ipv4CidrBlock *string `json:"cidr,omitempty"`
Name *string `json:"name,omitempty"`
ID *string `json:"id,omitempty"`
Zone *string `json:"zone,omitempty"`
// +kubebuilder:validation:MaxLength:=63
// +kubebuilder:validation:Pattern=`^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$`
Name *string `json:"name,omitempty"`
ID *string `json:"id,omitempty"`
Zone *string `json:"zone,omitempty"`
}

// VPCEndpoint describes a VPCEndpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ spec:
name:
description: Optional name of DHCP Service. Only alphanumeric
characters and dashes are allowed.
maxLength: 63
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
snat:
default: true
Expand Down Expand Up @@ -294,6 +296,7 @@ spec:
name:
description: Name sets the name of the VPC load balancer.
maxLength: 63
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
public:
default: true
Expand All @@ -319,7 +322,9 @@ spec:
type: string
name:
description: Name of resource
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
regex:
description: |-
Expand All @@ -341,7 +346,9 @@ spec:
type: string
name:
description: Name of resource
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
regex:
description: |-
Expand Down Expand Up @@ -369,7 +376,9 @@ spec:
type: string
name:
description: Name of resource
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
regex:
description: |-
Expand All @@ -396,6 +405,8 @@ spec:
type: string
name:
description: name of resource.
maxLength: 63
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
type: object
vpc:
Expand All @@ -413,7 +424,9 @@ spec:
type: string
name:
description: name of resource.
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
region:
description: |-
Expand All @@ -439,6 +452,8 @@ spec:
id:
type: string
name:
maxLength: 63
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
zone:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ spec:
name:
description: Optional name of DHCP Service. Only alphanumeric
characters and dashes are allowed.
maxLength: 63
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
snat:
default: true
Expand Down Expand Up @@ -325,6 +327,7 @@ spec:
name:
description: Name sets the name of the VPC load balancer.
maxLength: 63
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
public:
default: true
Expand All @@ -350,7 +353,9 @@ spec:
type: string
name:
description: Name of resource
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
regex:
description: |-
Expand All @@ -372,7 +377,9 @@ spec:
type: string
name:
description: Name of resource
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
regex:
description: |-
Expand Down Expand Up @@ -400,7 +407,9 @@ spec:
type: string
name:
description: Name of resource
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
regex:
description: |-
Expand All @@ -427,6 +436,8 @@ spec:
type: string
name:
description: name of resource.
maxLength: 63
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
type: object
vpc:
Expand All @@ -444,7 +455,9 @@ spec:
type: string
name:
description: name of resource.
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
region:
description: |-
Expand All @@ -470,6 +483,8 @@ spec:
id:
type: string
name:
maxLength: 63
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
zone:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ spec:
type: string
name:
description: Name of resource
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
regex:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ spec:
type: string
name:
description: Name of resource
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
regex:
description: |-
Expand Down Expand Up @@ -407,7 +409,9 @@ spec:
type: string
name:
description: Name of resource
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
regex:
description: |-
Expand Down Expand Up @@ -470,7 +474,9 @@ spec:
type: string
name:
description: Name of resource
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
regex:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ spec:
type: string
name:
description: Name of resource
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
regex:
description: |-
Expand Down Expand Up @@ -250,7 +252,9 @@ spec:
type: string
name:
description: Name of resource
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
regex:
description: |-
Expand Down Expand Up @@ -313,7 +317,9 @@ spec:
type: string
name:
description: Name of resource
maxLength: 63
minLength: 1
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
regex:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ spec:
name:
description: Name sets the name of the VPC load balancer.
maxLength: 63
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
public:
default: true
Expand Down Expand Up @@ -366,6 +367,8 @@ spec:
id:
type: string
name:
maxLength: 63
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
zone:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ spec:
name:
description: Name sets the name of the VPC load balancer.
maxLength: 63
pattern: ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$
type: string
public:
default: true
Expand Down