Skip to content

Commit

Permalink
[VCDA-3532] Add RDEId into VApp metadata (vmware#103)
Browse files Browse the repository at this point in the history
* add metadata into VApp

Signed-off-by: ymo24 <[email protected]>

* reduce duplicated patchVCDCluster, avoid potential mix

Signed-off-by: ymo24 <[email protected]>

* Status field vAppMetadataUpdated should be optional

Signed-off-by: ymo24 <[email protected]>
  • Loading branch information
ymo24 authored Apr 20, 2022
1 parent d177449 commit 6f041a9
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 24 deletions.
4 changes: 4 additions & 0 deletions api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ func Convert_v1alpha4_VCDMachineSpec_To_v1beta1_VCDMachineSpec(in *VCDMachineSpe
func Convert_v1beta1_VCDMachineSpec_To_v1alpha4_VCDMachineSpec(in *v1beta1.VCDMachineSpec, out *VCDMachineSpec, s conversion.Scope) error {
return autoConvert_v1beta1_VCDMachineSpec_To_v1alpha4_VCDMachineSpec(in, out, s)
}
func Convert_v1beta1_VCDClusterStatus_To_v1alpha4_VCDClusterStatus(in *v1beta1.VCDClusterStatus, out *VCDClusterStatus, s conversion.Scope) error {
// Todo: check if VCDClusterStatus.vAppMetadata_Updated needs to be updated (VCDA-3532)
return autoConvert_v1beta1_VCDClusterStatus_To_v1alpha4_VCDClusterStatus(in, out, s)
}
85 changes: 61 additions & 24 deletions api/v1alpha4/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions api/v1beta1/vcdcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ type VCDClusterStatus struct {
// Ready denotes that the vcd cluster (infrastructure) is ready.
Ready bool `json:"ready"`

// MetadataUpdated denotes that the metadata of Vapp is updated.
// +optional
VAppMetadataUpdated bool `json:"vappmetadataUpdated,omitempty"`

// Conditions defines current service state of the VCDCluster.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ spec:
type: array
infraId:
type: string
VAppMetadataUpdated:
description: MetadataUpdated denotes that the metadata of Vapp is
updated.
type: boolean
ready:
description: Ready denotes that the vcd cluster (infrastructure) is
ready.
Expand Down
14 changes: 14 additions & 0 deletions controllers/vcdcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (

ClusterApiStatusPhaseReady = "Ready"
ClusterApiStatusPhaseNotReady = "Not Ready"
CapvcdInfraId = "CapvcdInfraId"

NoRdePrefix = `NO_RDE_`
)
Expand Down Expand Up @@ -613,11 +614,24 @@ func (r *VCDClusterReconciler) reconcileNormal(ctx context.Context, cluster *clu
Client: workloadVCDClient,
Vdc: workloadVCDClient.Vdc,
}

metadataMap := map[string]string{
CapvcdInfraId: vcdCluster.Status.InfraId,
}
//Todo duplicate check

_, err = vdcManager.GetOrCreateVApp(vcdCluster.Name, workloadVCDClient.NetworkName)
if err != nil {
return ctrl.Result{}, errors.Wrapf(err, "Error creating Infra vApp for the cluster [%s]: [%v]", vcdCluster.Name, err)
}

if metadataMap != nil && len(metadataMap) > 0 && !vcdCluster.Status.VAppMetadataUpdated {
if err := vdcManager.AddMetadataToVApp(vcdCluster.Name, metadataMap); err != nil {
return ctrl.Result{}, fmt.Errorf("unable to add metadata [%s] to vApp [%s]: [%v]", metadataMap, vcdCluster.Name, err)
}
vcdCluster.Status.VAppMetadataUpdated = true
}

// Update the vcdCluster resource with updated information
// TODO Check if updating ovdcNetwork, Org and Ovdc should be done somewhere earlier in the code.
vcdCluster.ClusterName = vcdCluster.Name
Expand Down
22 changes: 22 additions & 0 deletions pkg/vcdclient/vapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,28 @@ func (vdc *VdcManager) addOvdcNetworkToVApp(vApp *govcd.VApp, ovdcNetworkName st
return nil
}

func (vdc *VdcManager) AddMetadataToVApp(vAppName string, paramMap map[string]string) error {
vApp, err := vdc.Vdc.GetVAppByName(vAppName, true)
if err != nil {
if err == govcd.ErrorEntityNotFound {
return fmt.Errorf("cannot get the vApp [%s] from Vdc [%s]: [%v]", vAppName, vdc.VdcName, err)
}
return fmt.Errorf("error while getting vApp [%s] from Vdc [%s]: [%v]",
vAppName, vdc.VdcName, err)
}
if vApp == nil || vApp.VApp == nil {
return fmt.Errorf("cannot add metadata to a nil vApp")
}
for key, value := range paramMap {
_, err := vApp.AddMetadata(key, value)
if err != nil {
return fmt.Errorf("unable to add metadata [%s]: [%s] to vApp [%s]: [%v]",
key, value, vApp.VApp.Name, err)
}
}
return nil
}

func (vdc *VdcManager) isVappNetworkPresentInVapp(vApp *govcd.VApp, ovdcNetworkName string) bool {
if vApp == nil || vApp.VApp == nil {
klog.Error("found nil value for vApp")
Expand Down

0 comments on commit 6f041a9

Please sign in to comment.