diff --git a/cloud/scope/load_balancer_reconciler.go b/cloud/scope/load_balancer_reconciler.go index b26f850e..f8eab6ae 100644 --- a/cloud/scope/load_balancer_reconciler.go +++ b/cloud/scope/load_balancer_reconciler.go @@ -163,7 +163,7 @@ func (s *ClusterScope) CreateLB(ctx context.Context, lb infrastructurev1beta2.Lo var controlPlaneEndpointSubnets []string for _, subnet := range ptr.ToSubnetSlice(s.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets) { if subnet.ID != nil && subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole { - controlPlaneEndpointSubnets = append(controlPlaneEndpointSubnets, *subnet.ID) + controlPlaneEndpointSubnets = append(controlPlaneEndpointSubnets, ptr.ToString(subnet.ID)) } } if len(controlPlaneEndpointSubnets) < 1 { diff --git a/cloud/scope/machine_pool.go b/cloud/scope/machine_pool.go index 15b1a466..475e3955 100644 --- a/cloud/scope/machine_pool.go +++ b/cloud/scope/machine_pool.go @@ -861,8 +861,8 @@ func (m *MachinePoolScope) getWorkerMachineNSGs() []string { nsgs := make([]string, 0) for _, nsgName := range instanceVnicConfiguration.NsgNames { for _, nsg := range ptr.ToNSGSlice(m.OCIClusterAccesor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List) { - if nsg.ID != nil && nsg.Name == nsgName { - nsgs = append(nsgs, *nsg.ID) + if nsg.Name == nsgName { + nsgs = append(nsgs, ptr.ToString(nsg.ID)) } } } @@ -870,8 +870,8 @@ func (m *MachinePoolScope) getWorkerMachineNSGs() []string { } else { nsgs := make([]string, 0) for _, nsg := range ptr.ToNSGSlice(m.OCIClusterAccesor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List) { - if nsg.ID != nil && nsg.Role == infrastructurev1beta2.WorkerRole { - nsgs = append(nsgs, *nsg.ID) + if nsg.Role == infrastructurev1beta2.WorkerRole { + nsgs = append(nsgs, ptr.ToString(nsg.ID)) } } return nsgs diff --git a/cloud/scope/managed_control_plane.go b/cloud/scope/managed_control_plane.go index c51e9482..79a2ea92 100644 --- a/cloud/scope/managed_control_plane.go +++ b/cloud/scope/managed_control_plane.go @@ -389,7 +389,7 @@ func (s *ManagedControlPlaneScope) getServiceLbSubnets() []string { subnets := make([]string, 0) for _, subnet := range ptr.ToSubnetSlice(s.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets) { if subnet.Role == infrastructurev1beta2.ServiceLoadBalancerRole { - subnets = append(subnets, *subnet.ID) + subnets = append(subnets, ptr.ToString(subnet.ID)) } } return subnets diff --git a/cloud/scope/managed_machine_pool.go b/cloud/scope/managed_machine_pool.go index fec1c557..83893bf2 100644 --- a/cloud/scope/managed_machine_pool.go +++ b/cloud/scope/managed_machine_pool.go @@ -528,8 +528,8 @@ func (m *ManagedMachinePoolScope) getPodSubnets(subnets []string) []string { if len(subnets) > 0 { for _, subnetName := range subnets { for _, subnet := range ptr.ToSubnetSlice(m.OCIManagedCluster.Spec.NetworkSpec.Vcn.Subnets) { - if subnet.ID != nil && subnet.Name == subnetName { - subnetList = append(subnetList, *subnet.ID) + if subnet.Name == subnetName { + subnetList = append(subnetList, ptr.ToString(subnet.ID)) } } } diff --git a/cloud/scope/nsg_reconciler.go b/cloud/scope/nsg_reconciler.go index 40ef326f..a69c56e8 100644 --- a/cloud/scope/nsg_reconciler.go +++ b/cloud/scope/nsg_reconciler.go @@ -36,8 +36,8 @@ func (s *ClusterScope) ReconcileNSG(ctx context.Context) error { return nil } desiredNSGs := s.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup - for _, desiredNSG := range ptr.ToNSGSlice(desiredNSGs.List) { - nsg, err := s.GetNSG(ctx, desiredNSG) + for _, desiredNSG := range desiredNSGs.List { + nsg, err := s.GetNSG(ctx, *desiredNSG) if err != nil { s.Logger.Error(err, "error to get nsg") return err @@ -45,8 +45,8 @@ func (s *ClusterScope) ReconcileNSG(ctx context.Context) error { if nsg != nil { nsgOCID := nsg.Id desiredNSG.ID = nsgOCID - if !s.IsNSGEqual(nsg, desiredNSG) { - err = s.UpdateNSG(ctx, desiredNSG) + if !s.IsNSGEqual(nsg, *desiredNSG) { + err = s.UpdateNSG(ctx, *desiredNSG) if err != nil { return err } @@ -55,7 +55,7 @@ func (s *ClusterScope) ReconcileNSG(ctx context.Context) error { continue } s.Logger.Info("Creating the network security list") - nsgID, err := s.CreateNSG(ctx, desiredNSG) + nsgID, err := s.CreateNSG(ctx, *desiredNSG) if err != nil { return err } @@ -135,8 +135,8 @@ func (s *ClusterScope) DeleteNSGs(ctx context.Context) error { return nil } desiredNSGs := s.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup - for _, desiredNSG := range ptr.ToNSGSlice(desiredNSGs.List) { - nsg, err := s.GetNSG(ctx, desiredNSG) + for _, desiredNSG := range desiredNSGs.List { + nsg, err := s.GetNSG(ctx, *desiredNSG) if err != nil && !ociutil.IsNotFound(err) { return err } @@ -484,9 +484,10 @@ func getProtocolOptionsForSpec(icmp *core.IcmpOptions, tcp *core.TcpOptions, udp } func getNsgIdFromName(nsgName *string, list []*infrastructurev1beta2.NSG) *string { - for _, nsg := range ptr.ToNSGSlice(list) { - if nsg.Name == *nsgName { - return nsg.ID + nsgSlice := ptr.ToNSGSlice(list) + for i := range nsgSlice { + if nsgSlice[i].Name == *nsgName { + return nsgSlice[i].ID } } return nil @@ -496,7 +497,10 @@ func getNsgNameFromId(nsgId *string, list []*infrastructurev1beta2.NSG) *string if nsgId == nil { return nil } - for _, nsg := range ptr.ToNSGSlice(list) { + + nsgSlice := ptr.ToNSGSlice(list) + for i := range nsgSlice { + nsg := &nsgSlice[i] if nsg.ID != nil && reflect.DeepEqual(nsg.ID, nsgId) { return &nsg.Name } diff --git a/cloud/scope/subnet_reconciler.go b/cloud/scope/subnet_reconciler.go index 5e340629..857e9164 100644 --- a/cloud/scope/subnet_reconciler.go +++ b/cloud/scope/subnet_reconciler.go @@ -32,13 +32,13 @@ import ( ) func (s *ClusterScope) ReconcileSubnet(ctx context.Context) error { - desiredSubnets := ptr.ToSubnetSlice(s.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets) + desiredSubnets := s.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets for _, desiredSubnet := range desiredSubnets { if desiredSubnet.Skip { s.Logger.Info("Skipping Subnet reconciliation as per spec") continue } - subnet, err := s.GetSubnet(ctx, desiredSubnet) + subnet, err := s.GetSubnet(ctx, *desiredSubnet) if err != nil { return err } @@ -69,10 +69,10 @@ func (s *ClusterScope) ReconcileSubnet(ctx context.Context) error { } } } - if s.IsSubnetsEqual(subnet, desiredSubnet) { + if s.IsSubnetsEqual(subnet, *desiredSubnet) { s.Logger.Info("No Reconciliation Required for Subnet", "subnet", subnetOCID) } else { - err = s.UpdateSubnet(ctx, desiredSubnet) + err = s.UpdateSubnet(ctx, *desiredSubnet) if err != nil { return err } @@ -90,7 +90,7 @@ func (s *ClusterScope) ReconcileSubnet(ctx context.Context) error { s.Logger.Info("Created the security list", "ocid", seclistId) desiredSubnet.SecurityList.ID = seclistId } - subnetId, err := s.CreateSubnet(ctx, desiredSubnet) + subnetId, err := s.CreateSubnet(ctx, *desiredSubnet) if err != nil { return err } @@ -197,13 +197,13 @@ func (s *ClusterScope) UpdateSubnet(ctx context.Context, spec infrastructurev1be } func (s *ClusterScope) DeleteSubnets(ctx context.Context) error { - desiredSubnets := ptr.ToSubnetSlice(s.GetSubnetsSpec()) + desiredSubnets := s.GetSubnetsSpec() for _, desiredSubnet := range desiredSubnets { if desiredSubnet.Skip { s.Logger.Info("Skipping Subnet reconciliation as per spec") continue } - subnet, err := s.GetSubnet(ctx, desiredSubnet) + subnet, err := s.GetSubnet(ctx, *desiredSubnet) if err != nil && !ociutil.IsNotFound(err) { return err } @@ -325,7 +325,9 @@ func (s *ClusterScope) isControlPlaneEndpointSubnetPrivate() bool { } func (s *ClusterScope) GetControlPlaneEndpointSubnetCidr() string { - for _, subnet := range ptr.ToSubnetSlice(s.GetSubnetsSpec()) { + subnetSlice := ptr.ToSubnetSlice(s.GetSubnetsSpec()) + for i := range subnetSlice { + subnet := &subnetSlice[i] if subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole { if subnet.CIDR != "" { return subnet.CIDR @@ -336,7 +338,9 @@ func (s *ClusterScope) GetControlPlaneEndpointSubnetCidr() string { } func (s *ClusterScope) GetServiceLoadBalancerSubnetCidr() string { - for _, subnet := range ptr.ToSubnetSlice(s.GetSubnetsSpec()) { + subnetSlice := ptr.ToSubnetSlice(s.GetSubnetsSpec()) + for i := range subnetSlice { + subnet := &subnetSlice[i] if subnet.Role == infrastructurev1beta2.ServiceLoadBalancerRole { if subnet.CIDR != "" { return subnet.CIDR @@ -347,9 +351,10 @@ func (s *ClusterScope) GetServiceLoadBalancerSubnetCidr() string { } func (s *ClusterScope) NodeSubnetCidr() []string { - subnets := s.GetNodeSubnet() var nodeCIDR []string - for _, subnet := range ptr.ToSubnetSlice(subnets) { + subnetSlice := ptr.ToSubnetSlice(s.GetNodeSubnet()) + for i := range subnetSlice { + subnet := &subnetSlice[i] if subnet.CIDR != "" { nodeCIDR = append(nodeCIDR, subnet.CIDR) } @@ -372,7 +377,9 @@ func (s *ClusterScope) GetControlPlaneMachineSubnetCidr() string { // IsAllSubnetsPrivate determines if all the ClusterScope's subnets are private func (s *ClusterScope) IsAllSubnetsPrivate() bool { - for _, subnet := range ptr.ToSubnetSlice(s.GetSubnetsSpec()) { + subnetSlice := ptr.ToSubnetSlice(s.GetSubnetsSpec()) + for i := range subnetSlice { + subnet := &subnetSlice[i] if subnet.Type == infrastructurev1beta2.Public { return false } diff --git a/cloud/scope/util.go b/cloud/scope/util.go index 4221f017..15e12722 100644 --- a/cloud/scope/util.go +++ b/cloud/scope/util.go @@ -33,7 +33,7 @@ func GetNsgNamesFromId(ids []string, nsgs []*infrastructurev1beta2.NSG) []string names := make([]string, 0) for _, id := range ids { for _, nsg := range ptr.ToNSGSlice(nsgs) { - if nsg.ID != nil && id == *nsg.ID { + if id == ptr.ToString(nsg.ID) { names = append(names, nsg.Name) } } @@ -44,7 +44,7 @@ func GetNsgNamesFromId(ids []string, nsgs []*infrastructurev1beta2.NSG) []string // GetSubnetNameFromId returns the name of the Subnet with the provided ID func GetSubnetNameFromId(id *string, subnets []*infrastructurev1beta2.Subnet) string { for _, subnet := range ptr.ToSubnetSlice(subnets) { - if subnet.ID != nil && *id == *subnet.ID { + if ptr.ToString(id) == ptr.ToString(subnet.ID) { return subnet.Name } } @@ -56,7 +56,7 @@ func GetSubnetNamesFromId(ids []string, subnets []*infrastructurev1beta2.Subnet) names := make([]string, 0) for _, id := range ids { for _, subnet := range ptr.ToSubnetSlice(subnets) { - if subnet.ID != nil && id == *subnet.ID { + if id == ptr.ToString(subnet.ID) { names = append(names, subnet.Name) } } diff --git a/cloud/scope/virtual_machine_pool.go b/cloud/scope/virtual_machine_pool.go index 37063bca..50631293 100644 --- a/cloud/scope/virtual_machine_pool.go +++ b/cloud/scope/virtual_machine_pool.go @@ -393,15 +393,15 @@ func (m *VirtualMachinePoolScope) getWorkerMachineNSGs() []string { if len(specNsgNames) > 0 { for _, nsgName := range specNsgNames { for _, nsg := range ptr.ToNSGSlice(m.OCIManagedCluster.Spec.NetworkSpec.Vcn.NetworkSecurityGroup.List) { - if nsg.ID != nil && nsg.Name == nsgName { - nsgList = append(nsgList, *nsg.ID) + if nsg.Name == nsgName { + nsgList = append(nsgList, ptr.ToString(nsg.ID)) } } } } else { for _, nsg := range ptr.ToNSGSlice(m.OCIManagedCluster.Spec.NetworkSpec.Vcn.NetworkSecurityGroup.List) { - if nsg.ID != nil && nsg.Role == infrastructurev1beta2.WorkerRole { - nsgList = append(nsgList, *nsg.ID) + if nsg.Role == infrastructurev1beta2.WorkerRole { + nsgList = append(nsgList, ptr.ToString(nsg.ID)) } } } @@ -423,8 +423,8 @@ func (m *VirtualMachinePoolScope) getPodNSGs(nsgs []string) []string { if len(nsgs) > 0 { for _, nsgName := range nsgs { for _, nsg := range ptr.ToNSGSlice(m.OCIManagedCluster.Spec.NetworkSpec.Vcn.NetworkSecurityGroup.List) { - if nsg.ID != nil && nsg.Name == nsgName { - nsgList = append(nsgList, *nsg.ID) + if nsg.Name == nsgName { + nsgList = append(nsgList, ptr.ToString(nsg.ID)) } } }