Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
90a80ea
bare metal
cwize1 Mar 31, 2021
8dec1f7
Added aksiot.md.
gmileka Apr 1, 2021
25b7e25
Bug fixes
cwize1 Apr 7, 2021
ec872cd
Merge branch 'BareMetal2' of ssh://github.com/cwize1/cluster-api-prov…
romoh Apr 15, 2021
b8a836c
Fix merge conflicts and integrate with latest moc bm entity
romoh Apr 15, 2021
dd3d46c
Merge branch 'ecf' into master
jiria Apr 15, 2021
e0db96e
Loadbalancer workaround
romoh Apr 15, 2021
def897d
remove missed CloudResourceName
romoh Apr 19, 2021
61a0882
cleanup
romoh Apr 20, 2021
dcf48ba
Merge pull request #117 from romoh/master
romoh Apr 20, 2021
a733541
Update Makefile to match master branch (#119)
cwize1 Apr 20, 2021
c6b2b37
Add missing files (#120)
cwize1 Apr 20, 2021
828f54b
Fix retrieval logic for existing bare-metal machines. (#121)
cwize1 Apr 23, 2021
77bc616
Use new moc package's providerid functions. (#123)
cwize1 Apr 28, 2021
57553bc
Merge tag 'v0.3.7' into ecf
cwize1 May 11, 2021
545d8eb
Update go.mod
cwize1 May 11, 2021
559338a
Remove load balancer workaround for bare metal.
cwize1 May 13, 2021
ad73f8e
Merge pull request #127 from cwize1/user/chrisgun/RemoveLBWorkaround
cwize1 May 18, 2021
b162428
Pre-upstream cleanup
cwize1 Jun 3, 2021
c3e337d
Merge pull request #135 from cwize1/user/chrisgun/PreUpstreamCleanup
cwize1 Jun 4, 2021
4ac0b52
Add support for custom suffix for container image tags. (#133)
cwize1 Jun 5, 2021
7f14c0b
Merge branch 'ecf' into integrate-bm
jiria Aug 5, 2021
8b59042
Merge remote-tracking branch 'upstream/master' into integrate-bm
jiria Nov 1, 2021
fa77a7f
Merge fixes
jiria Nov 1, 2021
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
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ KUBECTL_VER := v1.21.4
KUBECTL_BIN := kubectl
KUBECTL := $(TOOLS_BIN_DIR)/$(KUBECTL_BIN)-$(KUBECTL_VER)

TAGSUFFIX_APPEND :=
ifdef TAGSUFFIX
TAGSUFFIX_APPEND := -${TAGSUFFIX}
endif

# Version
MAJOR_VER ?= 0
MINOR_VER ?= 4
Expand All @@ -99,7 +104,7 @@ STAGING_REGISTRY := mocimages.azurecr.io
PROD_REGISTRY := mocimages.azurecr.io
IMAGE_NAME ?= caphcontroller
CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)
TAG := $(MAJOR_VER).$(MINOR_VER).$(PATCH_VER)
TAG := $(MAJOR_VER).$(MINOR_VER).$(PATCH_VER)${TAGSUFFIX_APPEND}
ARCH := amd64
ALL_ARCH = amd64 arm arm64 ppc64le s390x

Expand Down
6 changes: 5 additions & 1 deletion api/v1alpha3/azurestackhciloadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ const (
type AzureStackHCILoadBalancerSpec struct {
SSHPublicKey string `json:"sshPublicKey"`
Image Image `json:"image"`
VMSize string `json:"vmSize"`

// +optional
HostType HostType `json:"hostType,omitempty"`

VMSize string `json:"vmSize"`

// Number of desired loadbalancer machines. Defaults to 1.
// This is a pointer to distinguish between explicit zero and not specified.
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha3/azurestackhcimachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type AzureStackHCIMachineSpec struct {
// +optional
ProviderID *string `json:"providerID,omitempty"`

// +optional
HostType HostType `json:"hostType,omitempty"`

VMSize string `json:"vmSize"`

AvailabilityZone AvailabilityZone `json:"availabilityZone,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha3/azurestackhcivirtualmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const (

// AzureStackHCIVirtualMachineSpec defines the desired state of AzureStackHCIVirtualMachine
type AzureStackHCIVirtualMachineSpec struct {
// +optional
HostType HostType `json:"hostType,omitempty"`

VMSize string `json:"vmSize"`
AvailabilityZone AvailabilityZone `json:"availabilityZone,omitempty"`
Image Image `json:"image"`
Expand Down
12 changes: 12 additions & 0 deletions api/v1alpha3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,15 @@ const (
ValueReady = "true"
AnnotationControlPlaneReady = "azurestackhci.cluster.sigs.k8s.io/control-plane-ready"
)

// HostType specifies what type of machine a node should be deployed on.
type HostType string

const (
// HostTypeVM specifies that the node should be deployed on a virtual machine.
// Default value.
HostTypeVM = HostType("vm")

// HostTypeBareMetal specifies that the node should be deployed on a bare metal machine.
HostTypeBareMetal = HostType("baremetal")
)
6 changes: 6 additions & 0 deletions api/v1alpha3/zz_generated.conversion.go

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

3 changes: 3 additions & 0 deletions api/v1alpha4/azurestackhciloadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type AzureStackHCILoadBalancerSpec struct {
// +optional
// +kubebuilder:default=1
Replicas *int32 `json:"replicas,omitempty"`

// +optional
HostType HostType `json:"hostType,omitempty"`
}

type AzureStackHCILoadBalancerStatus struct {
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha4/azurestackhcimachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type AzureStackHCIMachineSpec struct {
// +optional
ProviderID *string `json:"providerID,omitempty"`

// +optional
HostType HostType `json:"hostType,omitempty"`

VMSize string `json:"vmSize"`

AvailabilityZone AvailabilityZone `json:"availabilityZone,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha4/azurestackhcivirtualmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const (

// AzureStackHCIVirtualMachineSpec defines the desired state of AzureStackHCIVirtualMachine
type AzureStackHCIVirtualMachineSpec struct {
// +optional
HostType HostType `json:"hostType,omitempty"`

VMSize string `json:"vmSize"`
AvailabilityZone AvailabilityZone `json:"availabilityZone,omitempty"`
Image Image `json:"image"`
Expand Down
12 changes: 12 additions & 0 deletions api/v1alpha4/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,15 @@ const (
ValueReady = "true"
AnnotationControlPlaneReady = "azurestackhci.cluster.sigs.k8s.io/control-plane-ready"
)

// HostType specifies what type of machine a node should be deployed on.
type HostType string

const (
// HostTypeVM specifies that the node should be deployed on a virtual machine.
// Default value.
HostTypeVM = HostType("vm")

// HostTypeBareMetal specifies that the node should be deployed on a bare metal machine.
HostTypeBareMetal = HostType("baremetal")
)
14 changes: 12 additions & 2 deletions cloud/converters/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@ import (
"github.com/microsoft/moc-sdk-for-go/services/compute"
)

// SDKToVM converts an SDK VirtualMachine to the provider VM type.
func SDKToVM(v compute.VirtualMachine) (*infrav1.VM, error) {
// VMConvertToCAPH converts an SDK VirtualMachine to the provider VM type.
func VMConvertToCAPH(v compute.VirtualMachine) (*infrav1.VM, error) {
vm := &infrav1.VM{
ID: to.String(v.ID),
Name: to.String(v.Name),
State: infrav1.VMStateSucceeded, // Hard-coded for now until we expose provisioning state
}
return vm, nil
}

// BareMetalMachineConvertToCAPH converts an SDK BareMetalMachine to the provider VM type.
func BareMetalMachineConvertToCAPH(v compute.BareMetalMachine) (*infrav1.VM, error) {
vm := &infrav1.VM{
ID: to.String(v.ID),
Name: to.String(v.Name),
Expand Down
18 changes: 13 additions & 5 deletions cloud/services/virtualmachines/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ package virtualmachines
import (
azurestackhci "github.com/microsoft/cluster-api-provider-azurestackhci/cloud"
"github.com/microsoft/cluster-api-provider-azurestackhci/cloud/scope"
"github.com/microsoft/moc/pkg/auth"
"github.com/microsoft/moc-sdk-for-go/services/compute/baremetalmachine"
"github.com/microsoft/moc-sdk-for-go/services/compute/virtualmachine"
"github.com/microsoft/moc/pkg/auth"
)

var _ azurestackhci.Service = (*Service)(nil)

// Service provides operations on virtual machines.
type Service struct {
Client virtualmachine.VirtualMachineClient
Scope scope.ScopeInterface
VMClient virtualmachine.VirtualMachineClient
BareMetalClient baremetalmachine.BareMetalMachineClient
Scope scope.ScopeInterface
}

// getVirtualMachinesClient creates a new virtual machines client.
Expand All @@ -38,10 +40,16 @@ func getVirtualMachinesClient(cloudAgentFqdn string, authorizer auth.Authorizer)
return *vmClient
}

func getBareMetalMachinesClient(cloudAgentFqdn string, authorizer auth.Authorizer) baremetalmachine.BareMetalMachineClient {
bareMetalClient, _ := baremetalmachine.NewBareMetalMachineClient(cloudAgentFqdn, authorizer)
return *bareMetalClient
}

// NewService creates a new virtual machines service.
func NewService(scope scope.ScopeInterface) *Service {
return &Service{
Client: getVirtualMachinesClient(scope.GetCloudAgentFqdn(), scope.GetAuthorizer()),
Scope: scope,
VMClient: getVirtualMachinesClient(scope.GetCloudAgentFqdn(), scope.GetAuthorizer()),
BareMetalClient: getBareMetalMachinesClient(scope.GetCloudAgentFqdn(), scope.GetAuthorizer()),
Scope: scope,
}
}
116 changes: 95 additions & 21 deletions cloud/services/virtualmachines/virtualmachines.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,43 @@ type Spec struct {
OSDisk infrav1.OSDisk
CustomData string
VMType compute.VMType
HostType infrav1.HostType
}

// Get provides information about a virtual machine.
func (s *Service) Get(ctx context.Context, spec interface{}) (interface{}, error) {
var err error
vmSpec, ok := spec.(*Spec)
if !ok {
return compute.VirtualMachine{}, errors.New("invalid vm specification")
return nil, errors.New("invalid vm specification")
}

vm, err := s.Client.Get(ctx, s.Scope.GetResourceGroup(), vmSpec.Name)
if err != nil {
return nil, err
}
if vm == nil || len(*vm) == 0 {
return nil, errors.Wrapf(err, "vm %s not found", vmSpec.Name)
}
switch vmSpec.HostType {
case infrav1.HostTypeBareMetal:
var baremetalmachine *[]compute.BareMetalMachine

baremetalmachine, err = s.BareMetalClient.Get(ctx, s.Scope.GetResourceGroup(), vmSpec.Name)
if err != nil {
return nil, err
}

if baremetalmachine == nil || len(*baremetalmachine) == 0 {
return nil, errors.Errorf("bare-metal machine %s not found", vmSpec.Name)
}

return converters.BareMetalMachineConvertToCAPH((*baremetalmachine)[0])

return converters.SDKToVM((*vm)[0])
default:
vm, err := s.VMClient.Get(ctx, s.Scope.GetResourceGroup(), vmSpec.Name)
if err != nil {
return nil, err
}
if vm == nil || len(*vm) == 0 {
return nil, errors.Errorf("vm %s not found", vmSpec.Name)
}

return converters.VMConvertToCAPH((*vm)[0])
}
}

// Reconcile gets/creates/updates a virtual machine.
Expand Down Expand Up @@ -173,36 +192,91 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
}
}

_, err = s.Client.CreateOrUpdate(
ctx,
s.Scope.GetResourceGroup(),
vmSpec.Name,
&virtualMachine)
if err != nil {
return errors.Wrapf(err, "cannot create vm")
}
switch vmSpec.HostType {
case infrav1.HostTypeBareMetal:
_, err := s.createOrUpdateBareMetal(
ctx,
&virtualMachine)
if err != nil {
return errors.Wrapf(err, "cannot create bare-metal machine")
}

default:
_, err = s.VMClient.CreateOrUpdate(
ctx,
s.Scope.GetResourceGroup(),
vmSpec.Name,
&virtualMachine)
if err != nil {
return errors.Wrapf(err, "cannot create vm")
}
}
klog.V(2).Infof("successfully created vm %s ", vmSpec.Name)
return err
}

func (s *Service) createOrUpdateBareMetal(ctx context.Context, virtualMachine *compute.VirtualMachine) (*compute.BareMetalMachine, error) {
// Create a new baremetal machine
bareMetalMachine := &compute.BareMetalMachine{
Name: virtualMachine.Name,
}

bareMetalMachine.BareMetalMachineProperties = &compute.BareMetalMachineProperties{
StorageProfile: &compute.BareMetalMachineStorageProfile{
ImageReference: &compute.BareMetalMachineImageReference{
ID: virtualMachine.VirtualMachineProperties.StorageProfile.ImageReference.ID,
Name: virtualMachine.VirtualMachineProperties.StorageProfile.ImageReference.Name,
},
},
OsProfile: &compute.BareMetalMachineOSProfile{
ComputerName: virtualMachine.VirtualMachineProperties.OsProfile.ComputerName,
AdminUsername: virtualMachine.VirtualMachineProperties.OsProfile.AdminUsername,
AdminPassword: virtualMachine.VirtualMachineProperties.OsProfile.AdminPassword,
CustomData: virtualMachine.VirtualMachineProperties.OsProfile.CustomData,
LinuxConfiguration: virtualMachine.VirtualMachineProperties.OsProfile.LinuxConfiguration,
},
SecurityProfile: virtualMachine.VirtualMachineProperties.SecurityProfile,
ProvisioningState: virtualMachine.VirtualMachineProperties.ProvisioningState,
Statuses: virtualMachine.VirtualMachineProperties.Statuses,
}

// Try to apply the update.
_, err := s.BareMetalClient.CreateOrUpdate(ctx, s.Scope.GetResourceGroup(), *bareMetalMachine.Name, bareMetalMachine)

if err != nil {
return nil, errors.Wrap(err, "Failed to create baremetal machine.")
}

klog.V(2).Infof("Successfully created baremetal machine %s ", bareMetalMachine.Name)
return bareMetalMachine, nil
}

// Delete deletes the virtual machine with the provided name.
func (s *Service) Delete(ctx context.Context, spec interface{}) error {
vmSpec, ok := spec.(*Spec)
if !ok {
return errors.New("invalid vm Specification")
}
klog.V(2).Infof("deleting vm %s ", vmSpec.Name)
err := s.Client.Delete(ctx, s.Scope.GetResourceGroup(), vmSpec.Name)

var err error
switch vmSpec.HostType {
case infrav1.HostTypeBareMetal:
klog.V(2).Infof("deleting bare-metal machine %s ", vmSpec.Name)
err = s.BareMetalClient.Delete(ctx, s.Scope.GetResourceGroup(), vmSpec.Name)
default:
klog.V(2).Infof("deleting vm %s ", vmSpec.Name)
err = s.VMClient.Delete(ctx, s.Scope.GetResourceGroup(), vmSpec.Name)
}

if err != nil && azurestackhci.ResourceNotFound(err) {
// already deleted
return nil
}
if err != nil {
return errors.Wrapf(err, "failed to delete vm %s in resource group %s", vmSpec.Name, s.Scope.GetResourceGroup())
return errors.Wrapf(err, "failed to delete %s %s in resource group %s", vmSpec.HostType, vmSpec.Name, s.Scope.GetResourceGroup())
}

klog.V(2).Infof("successfully deleted vm %s ", vmSpec.Name)
klog.V(2).Infof("successfully deleted %s %s ", vmSpec.HostType, vmSpec.Name)
return err
}

Expand Down
Loading