Skip to content

Code Refine: Update latest VPC info in VPCNetworkConfiguration.Status #968

@wenyingd

Description

@wenyingd
  1. Use vpcInfo.path instead for vpcInfo.name as the key when iterating the VPCs in VPCNetworkConfiguration CR.
  2. Reload the latest valid VPC's info rather than re-use the old info to update the CR status.

The related code is about function updateVPCNetworkConfigurationStatusWithAliveVPCs in networkinfo_utils.go,

func updateVPCNetworkConfigurationStatusWithAliveVPCs(ctx context.Context, client client.Client, ncName string, getAliveVPCsFn func(ncName string) []*model.Vpc) {
	// read v1alpha1.VPCNetworkConfiguration by ncName
	nc := &v1alpha1.VPCNetworkConfiguration{}
	err := client.Get(ctx, apitypes.NamespacedName{Name: ncName}, nc)
	if err != nil {
		log.Error(err, "Failed to get VPCNetworkConfiguration", "Name", ncName)
		return
	}

	if getAliveVPCsFn != nil {
		aliveVPCs := sets.New[string]()
		for _, vpc := range getAliveVPCsFn(ncName) {
			aliveVPCs.Insert(*vpc.DisplayName)
		}
		var newVPCInfos []v1alpha1.VPCInfo
		for _, vpcInfo := range nc.Status.VPCs {
			if aliveVPCs.Has(vpcInfo.Name) {
				newVPCInfos = append(newVPCInfos, vpcInfo)
			}
		}
		nc.Status.VPCs = newVPCInfos
		if err := client.Status().Update(ctx, nc); err != nil {
			log.Error(err, "Failed to update VPCNetworkConfiguration status", "Name", ncName, "nc.Status.VPCs", nc.Status.VPCs)
			return
		}
		log.Info("Updated VPCNetworkConfiguration status", "Name", ncName, "nc.Status.VPCs", nc.Status.VPCs)
	}
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions