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

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

Open
wenyingd opened this issue Dec 13, 2024 · 0 comments
Open

Comments

@wenyingd
Copy link
Contributor

  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)
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant