Skip to content

Commit

Permalink
VirtualMachine support
Browse files Browse the repository at this point in the history
Signed-off-by: vaspahomov <[email protected]>
  • Loading branch information
vaspahomov committed Jun 23, 2021
1 parent e6e9620 commit 6a4622a
Show file tree
Hide file tree
Showing 14 changed files with 1,680 additions and 0 deletions.
39 changes: 39 additions & 0 deletions apis/compute/v1alpha3/referencers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,42 @@ func (mg *AKSCluster) ResolveReferences(ctx context.Context, c client.Reader) er

return nil
}

// ResolveReferences of this VirtualMachine.
func (mg *VirtualMachine) ResolveReferences(ctx context.Context, c client.Reader) error {
r := reference.NewAPIResolver(c, mg)

// Resolve spec.resourceGroupName
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: mg.Spec.ResourceGroupName,
Reference: mg.Spec.ResourceGroupNameRef,
Selector: mg.Spec.ResourceGroupNameSelector,
To: reference.To{Managed: &v1alpha3.ResourceGroup{}, List: &v1alpha3.ResourceGroupList{}},
Extract: reference.ExternalName(),
})
if err != nil {
return errors.Wrap(err, "spec.resourceGroupName")
}
mg.Spec.ResourceGroupName = rsp.ResolvedValue
mg.Spec.ResourceGroupNameRef = rsp.ResolvedReference

if mg.Spec.VirtualMachineParameters != nil && mg.Spec.VirtualMachineParameters.NetworkProfile != nil {
netProf := mg.Spec.VirtualMachineParameters.NetworkProfile
for _, networkInterface := range netProf.NetworkInterfaces {
// Resolve spec.properties.networkProfile.networkInterfaces[].networkInterfaceID
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: networkInterface.NetworkInterfaceID,
Reference: networkInterface.NetworkInterfaceIDRef,
Selector: networkInterface.NetworkInterfaceIDSelector,
To: reference.To{Managed: &networkv1alpha3.NetworkInterface{}, List: &networkv1alpha3.NetworkInterfaceList{}},
Extract: networkv1alpha3.NetworkInterfaceID(),
})
if err != nil {
return errors.Wrap(err, "spec.properties.networkProfile.networkInterfaces[].networkInterfaceID")
}
networkInterface.NetworkInterfaceID = rsp.ResolvedValue
networkInterface.NetworkInterfaceIDRef = rsp.ResolvedReference
}
}
return nil
}
9 changes: 9 additions & 0 deletions apis/compute/v1alpha3/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ var (
AKSClusterGroupVersionKind = SchemeGroupVersion.WithKind(AKSClusterKind)
)

// VirtualMachine type metadata.
var (
VirtualMachineKind = reflect.TypeOf(VirtualMachine{}).Name()
VirtualMachineGroupKind = schema.GroupKind{Group: Group, Kind: VirtualMachineKind}.String()
VirtualMachineKindAPIVersion = VirtualMachineKind + "." + SchemeGroupVersion.String()
VirtualMachineGroupVersionKind = SchemeGroupVersion.WithKind(VirtualMachineKind)
)

func init() {
SchemeBuilder.Register(&AKSCluster{}, &AKSClusterList{})
SchemeBuilder.Register(&VirtualMachine{}, &VirtualMachineList{})
}
181 changes: 181 additions & 0 deletions apis/compute/v1alpha3/types.go

Large diffs are not rendered by default.

Loading

0 comments on commit 6a4622a

Please sign in to comment.