Skip to content

Commit 8d20070

Browse files
committed
Remove security group rules from status
1 parent 67fa7b7 commit 8d20070

File tree

10 files changed

+310
-838
lines changed

10 files changed

+310
-838
lines changed

api/v1alpha5/conversion.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -687,55 +687,12 @@ func Convert_v1alpha5_Bastion_To_v1beta1_Bastion(in *Bastion, out *infrav1.Basti
687687
func Convert_v1beta1_SecurityGroupStatus_To_v1alpha5_SecurityGroup(in *infrav1.SecurityGroupStatus, out *SecurityGroup, s conversion.Scope) error { //nolint:revive
688688
out.ID = in.ID
689689
out.Name = in.Name
690-
out.Rules = make([]SecurityGroupRule, len(in.Rules))
691-
for i, rule := range in.Rules {
692-
out.Rules[i] = SecurityGroupRule{
693-
ID: rule.ID,
694-
Direction: rule.Direction,
695-
}
696-
if rule.Description != nil {
697-
out.Rules[i].Description = *rule.Description
698-
}
699-
if rule.EtherType != nil {
700-
out.Rules[i].EtherType = *rule.EtherType
701-
}
702-
if rule.PortRangeMin != nil {
703-
out.Rules[i].PortRangeMin = *rule.PortRangeMin
704-
}
705-
if rule.PortRangeMax != nil {
706-
out.Rules[i].PortRangeMax = *rule.PortRangeMax
707-
}
708-
if rule.Protocol != nil {
709-
out.Rules[i].Protocol = *rule.Protocol
710-
}
711-
if rule.RemoteGroupID != nil {
712-
out.Rules[i].RemoteGroupID = *rule.RemoteGroupID
713-
}
714-
if rule.RemoteIPPrefix != nil {
715-
out.Rules[i].RemoteIPPrefix = *rule.RemoteIPPrefix
716-
}
717-
}
718690
return nil
719691
}
720692

721693
func Convert_v1alpha5_SecurityGroup_To_v1beta1_SecurityGroupStatus(in *SecurityGroup, out *infrav1.SecurityGroupStatus, s conversion.Scope) error { //nolint:revive
722694
out.ID = in.ID
723695
out.Name = in.Name
724-
out.Rules = make([]infrav1.SecurityGroupRuleStatus, len(in.Rules))
725-
for i, rule := range in.Rules {
726-
out.Rules[i] = infrav1.SecurityGroupRuleStatus{
727-
ID: rule.ID,
728-
Description: pointer.String(rule.Description),
729-
Direction: rule.Direction,
730-
EtherType: pointer.String(rule.EtherType),
731-
PortRangeMin: pointer.Int(rule.PortRangeMin),
732-
PortRangeMax: pointer.Int(rule.PortRangeMax),
733-
Protocol: pointer.String(rule.Protocol),
734-
RemoteGroupID: pointer.String(rule.RemoteGroupID),
735-
RemoteIPPrefix: pointer.String(rule.RemoteIPPrefix),
736-
}
737-
}
738-
739696
return nil
740697
}
741698

api/v1alpha6/types_conversion.go

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -364,63 +364,18 @@ func restorev1alpha6SecurityGroup(previous *SecurityGroup, dst *SecurityGroup) {
364364
return
365365
}
366366

367-
for i, rule := range previous.Rules {
368-
dst.Rules[i].SecurityGroupID = rule.SecurityGroupID
369-
}
367+
dst.Rules = previous.Rules
370368
}
371369

372370
func Convert_v1beta1_SecurityGroupStatus_To_v1alpha6_SecurityGroup(in *infrav1.SecurityGroupStatus, out *SecurityGroup, _ apiconversion.Scope) error {
373371
out.ID = in.ID
374372
out.Name = in.Name
375-
out.Rules = make([]SecurityGroupRule, len(in.Rules))
376-
for i, rule := range in.Rules {
377-
out.Rules[i] = SecurityGroupRule{
378-
ID: rule.ID,
379-
Direction: rule.Direction,
380-
}
381-
if rule.Description != nil {
382-
out.Rules[i].Description = *rule.Description
383-
}
384-
if rule.EtherType != nil {
385-
out.Rules[i].EtherType = *rule.EtherType
386-
}
387-
if rule.PortRangeMin != nil {
388-
out.Rules[i].PortRangeMin = *rule.PortRangeMin
389-
}
390-
if rule.PortRangeMax != nil {
391-
out.Rules[i].PortRangeMax = *rule.PortRangeMax
392-
}
393-
if rule.Protocol != nil {
394-
out.Rules[i].Protocol = *rule.Protocol
395-
}
396-
if rule.RemoteGroupID != nil {
397-
out.Rules[i].RemoteGroupID = *rule.RemoteGroupID
398-
}
399-
if rule.RemoteIPPrefix != nil {
400-
out.Rules[i].RemoteIPPrefix = *rule.RemoteIPPrefix
401-
}
402-
}
403373
return nil
404374
}
405375

406376
func Convert_v1alpha6_SecurityGroup_To_v1beta1_SecurityGroupStatus(in *SecurityGroup, out *infrav1.SecurityGroupStatus, _ apiconversion.Scope) error {
407377
out.ID = in.ID
408378
out.Name = in.Name
409-
out.Rules = make([]infrav1.SecurityGroupRuleStatus, len(in.Rules))
410-
for i, rule := range in.Rules {
411-
out.Rules[i] = infrav1.SecurityGroupRuleStatus{
412-
ID: rule.ID,
413-
Description: pointer.String(rule.Description),
414-
Direction: rule.Direction,
415-
EtherType: pointer.String(rule.EtherType),
416-
PortRangeMin: pointer.Int(rule.PortRangeMin),
417-
PortRangeMax: pointer.Int(rule.PortRangeMax),
418-
Protocol: pointer.String(rule.Protocol),
419-
RemoteGroupID: pointer.String(rule.RemoteGroupID),
420-
RemoteIPPrefix: pointer.String(rule.RemoteIPPrefix),
421-
}
422-
}
423-
424379
return nil
425380
}
426381

api/v1alpha7/openstackcluster_conversion.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,6 @@ func restorev1alpha7ClusterStatus(previous *OpenStackClusterStatus, dst *OpenSta
346346
}
347347

348348
func restorev1beta1ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst *infrav1.OpenStackClusterStatus) {
349-
restorev1beta1SecurityGroupStatus(previous.ControlPlaneSecurityGroup, dst.ControlPlaneSecurityGroup)
350-
restorev1beta1SecurityGroupStatus(previous.WorkerSecurityGroup, dst.WorkerSecurityGroup)
351-
restorev1beta1SecurityGroupStatus(previous.BastionSecurityGroup, dst.BastionSecurityGroup)
352-
353349
// ReferencedResources have no equivalent in v1alpha7
354350
if previous.Bastion != nil {
355351
dst.Bastion.ReferencedResources = previous.Bastion.ReferencedResources

api/v1alpha7/types_conversion.go

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package v1alpha7
1818

1919
import (
2020
apiconversion "k8s.io/apimachinery/pkg/conversion"
21-
"k8s.io/utils/pointer"
2221

2322
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
2423
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
@@ -40,9 +39,7 @@ func restorev1alpha7SecurityGroup(previous *SecurityGroup, dst *SecurityGroup) {
4039
return
4140
}
4241

43-
for i, rule := range previous.Rules {
44-
dst.Rules[i].SecurityGroupID = rule.SecurityGroupID
45-
}
42+
dst.Rules = previous.Rules
4643
}
4744

4845
func Convert_v1alpha7_SecurityGroupFilter_To_v1beta1_SecurityGroupFilter(in *SecurityGroupFilter, out *infrav1.SecurityGroupFilter, s apiconversion.Scope) error {
@@ -142,39 +139,6 @@ func Convert_v1beta1_RouterFilter_To_v1alpha7_RouterFilter(in *infrav1.RouterFil
142139
return nil
143140
}
144141

145-
func restorev1beta1SecurityGroupStatus(previous *infrav1.SecurityGroupStatus, dst *infrav1.SecurityGroupStatus) {
146-
if previous == nil || dst == nil {
147-
return
148-
}
149-
150-
for i := range dst.Rules {
151-
dstRule := &dst.Rules[i]
152-
153-
// Conversion from scalar to *scalar is lossy for zero values. We need to restore only nil values.
154-
if dstRule.Description != nil && *dstRule.Description == "" {
155-
dstRule.Description = previous.Rules[i].Description
156-
}
157-
if dstRule.EtherType != nil && *dstRule.EtherType == "" {
158-
dstRule.EtherType = previous.Rules[i].EtherType
159-
}
160-
if dstRule.PortRangeMin != nil && *dstRule.PortRangeMin == 0 {
161-
dstRule.PortRangeMin = previous.Rules[i].PortRangeMin
162-
}
163-
if dstRule.PortRangeMax != nil && *dstRule.PortRangeMax == 0 {
164-
dstRule.PortRangeMax = previous.Rules[i].PortRangeMax
165-
}
166-
if dstRule.Protocol != nil && *dstRule.Protocol == "" {
167-
dstRule.Protocol = previous.Rules[i].Protocol
168-
}
169-
if dstRule.RemoteGroupID != nil && *dstRule.RemoteGroupID == "" {
170-
dstRule.RemoteGroupID = previous.Rules[i].RemoteGroupID
171-
}
172-
if dstRule.RemoteIPPrefix != nil && *dstRule.RemoteIPPrefix == "" {
173-
dstRule.RemoteIPPrefix = previous.Rules[i].RemoteIPPrefix
174-
}
175-
}
176-
}
177-
178142
/* PortOpts */
179143

180144
func restorev1alpha7Port(previous *PortOpts, dst *PortOpts) {
@@ -300,55 +264,13 @@ func Convert_v1beta1_PortOpts_To_v1alpha7_PortOpts(in *infrav1.PortOpts, out *Po
300264
func Convert_v1alpha7_SecurityGroup_To_v1beta1_SecurityGroupStatus(in *SecurityGroup, out *infrav1.SecurityGroupStatus, _ apiconversion.Scope) error {
301265
out.ID = in.ID
302266
out.Name = in.Name
303-
out.Rules = make([]infrav1.SecurityGroupRuleStatus, len(in.Rules))
304-
for i, rule := range in.Rules {
305-
out.Rules[i] = infrav1.SecurityGroupRuleStatus{
306-
ID: rule.ID,
307-
Description: pointer.String(rule.Description),
308-
Direction: rule.Direction,
309-
EtherType: pointer.String(rule.EtherType),
310-
PortRangeMin: pointer.Int(rule.PortRangeMin),
311-
PortRangeMax: pointer.Int(rule.PortRangeMax),
312-
Protocol: pointer.String(rule.Protocol),
313-
RemoteGroupID: pointer.String(rule.RemoteGroupID),
314-
RemoteIPPrefix: pointer.String(rule.RemoteIPPrefix),
315-
}
316-
}
317267

318268
return nil
319269
}
320270

321271
func Convert_v1beta1_SecurityGroupStatus_To_v1alpha7_SecurityGroup(in *infrav1.SecurityGroupStatus, out *SecurityGroup, _ apiconversion.Scope) error {
322272
out.ID = in.ID
323273
out.Name = in.Name
324-
out.Rules = make([]SecurityGroupRule, len(in.Rules))
325-
for i, rule := range in.Rules {
326-
out.Rules[i] = SecurityGroupRule{
327-
ID: rule.ID,
328-
Direction: rule.Direction,
329-
}
330-
if rule.Description != nil {
331-
out.Rules[i].Description = *rule.Description
332-
}
333-
if rule.EtherType != nil {
334-
out.Rules[i].EtherType = *rule.EtherType
335-
}
336-
if rule.PortRangeMin != nil {
337-
out.Rules[i].PortRangeMin = *rule.PortRangeMin
338-
}
339-
if rule.PortRangeMax != nil {
340-
out.Rules[i].PortRangeMax = *rule.PortRangeMax
341-
}
342-
if rule.Protocol != nil {
343-
out.Rules[i].Protocol = *rule.Protocol
344-
}
345-
if rule.RemoteGroupID != nil {
346-
out.Rules[i].RemoteGroupID = *rule.RemoteGroupID
347-
}
348-
if rule.RemoteIPPrefix != nil {
349-
out.Rules[i].RemoteIPPrefix = *rule.RemoteIPPrefix
350-
}
351-
}
352274
return nil
353275
}
354276

api/v1beta1/types.go

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,6 @@ type SecurityGroupStatus struct {
448448
// id of the security group
449449
// +kubebuilder:validation:Required
450450
ID string `json:"id"`
451-
452-
// list of security group rules
453-
// +optional
454-
Rules []SecurityGroupRuleStatus `json:"rules,omitempty"`
455451
}
456452

457453
// SecurityGroupRuleSpec represent the basic information of the associated OpenStack
@@ -514,55 +510,6 @@ type SecurityGroupRuleSpec struct {
514510
RemoteManagedGroups []ManagedSecurityGroupName `json:"remoteManagedGroups,omitempty"`
515511
}
516512

517-
type SecurityGroupRuleStatus struct {
518-
// id of the security group rule
519-
// +kubebuilder:validation:Required
520-
ID string `json:"id"`
521-
522-
// description of the security group rule.
523-
// +optional
524-
Description *string `json:"description,omitempty"`
525-
526-
// direction in which the security group rule is applied. The only values
527-
// allowed are "ingress" or "egress". For a compute instance, an ingress
528-
// security group rule is applied to incoming (ingress) traffic for that
529-
// instance. An egress rule is applied to traffic leaving the instance.
530-
// +kubebuilder:validation:Required
531-
// +kubebuilder:validation:enum=ingress;egress
532-
Direction string `json:"direction"`
533-
534-
// etherType must be IPv4 or IPv6, and addresses represented in CIDR must match the
535-
// ingress or egress rules.
536-
// +kubebuilder:validation:enum=IPv4;IPv6
537-
// +optional
538-
EtherType *string `json:"etherType,omitempty"`
539-
540-
// portRangeMin is a number in the range that is matched by the security group
541-
// rule. If the protocol is TCP or UDP, this value must be less than or equal
542-
// to the value of the portRangeMax attribute.
543-
// +optional
544-
PortRangeMin *int `json:"portRangeMin,omitempty"`
545-
546-
// portRangeMax is a number in the range that is matched by the security group
547-
// rule. The portRangeMin attribute constrains the portRangeMax attribute.
548-
// +optional
549-
PortRangeMax *int `json:"portRangeMax,omitempty"`
550-
551-
// protocol is the protocol that is matched by the security group rule.
552-
// +optional
553-
Protocol *string `json:"protocol,omitempty"`
554-
555-
// remoteGroupID is the remote group ID to be associated with this security group rule.
556-
// You can specify either remoteGroupID or remoteIPPrefix or remoteManagedGroups.
557-
// +optional
558-
RemoteGroupID *string `json:"remoteGroupID,omitempty"`
559-
560-
// remoteIPPrefix is the remote IP prefix to be associated with this security group rule.
561-
// You can specify either remoteGroupID or remoteIPPrefix or remoteManagedGroups.
562-
// +optional
563-
RemoteIPPrefix *string `json:"remoteIPPrefix,omitempty"`
564-
}
565-
566513
// +kubebuilder:validation:Enum=bastion;controlplane;worker
567514
type ManagedSecurityGroupName string
568515

0 commit comments

Comments
 (0)