Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion cloud/scope/load_balancer_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions cloud/scope/machine_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,17 +861,17 @@ 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))
}
}
}
return nsgs
} 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
Expand Down
2 changes: 1 addition & 1 deletion cloud/scope/managed_control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cloud/scope/managed_machine_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
26 changes: 15 additions & 11 deletions cloud/scope/nsg_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ 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
}
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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
31 changes: 19 additions & 12 deletions cloud/scope/subnet_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions cloud/scope/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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
}
}
Expand All @@ -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)
}
}
Expand Down
12 changes: 6 additions & 6 deletions cloud/scope/virtual_machine_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand All @@ -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))
}
}
}
Expand Down