Skip to content

Commit

Permalink
Implement InfraMachine for Huaweicloud
Browse files Browse the repository at this point in the history
include creating and removing ECS instances

Signed-off-by: ekko <tuuwtu1@gmail.com>
  • Loading branch information
0ekk committed Jan 20, 2025
1 parent 5b0ee71 commit 3538055
Show file tree
Hide file tree
Showing 30 changed files with 2,366 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ issues:
linters:
- dupl
- lll
- linters:
- staticcheck
text: "SA1019: \"sigs.k8s.io/cluster-api/errors\" is deprecated:"
linters:
disable-all: true
enable:
Expand Down
30 changes: 30 additions & 0 deletions api/v1alpha1/conditions_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,36 @@ package v1alpha1

import clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

const (
// InstanceReadyCondition reports on current status of the ECS instance. Ready indicates the instance is in a Running state.
InstanceReadyCondition clusterv1.ConditionType = "InstanceReady"

// InstanceNotFoundReason used when the instance couldn't be retrieved.
InstanceNotFoundReason = "InstanceNotFound"
// InstanceTerminatedReason instance is in a terminated state.
InstanceTerminatedReason = "InstanceTerminated"
// InstanceStoppedReason instance is in a stopped state.
InstanceStoppedReason = "InstanceStopped"
// InstanceNotReadyReason used when the instance is in a pending state.
InstanceNotReadyReason = "InstanceNotReady"
// InstanceProvisionStartedReason set when the provisioning of an instance started.
InstanceProvisionStartedReason = "InstanceProvisionStarted"
// InstanceProvisionFailedReason used for failures during instance provisioning.
InstanceProvisionFailedReason = "InstanceProvisionFailed"
// WaitingForClusterInfrastructureReason used when machine is waiting for cluster infrastructure to be ready before proceeding.
WaitingForClusterInfrastructureReason = "WaitingForClusterInfrastructure"
// WaitingForBootstrapDataReason used when machine is waiting for bootstrap data to be ready before proceeding.
WaitingForBootstrapDataReason = "WaitingForBootstrapData"
)

const (
// SecurityGroupsReadyCondition indicates the security groups are up to date on the HuaweiCloudMachine.
SecurityGroupsReadyCondition clusterv1.ConditionType = "SecurityGroupsReady"

// SecurityGroupsFailedReason used when the security groups could not be synced.
SecurityGroupsFailedReason = "SecurityGroupsSyncFailed"
)

const (
// VpcReadyCondition reports on the successful reconciliation of a VPC.
VpcReadyCondition clusterv1.ConditionType = "VpcReady"
Expand Down
52 changes: 48 additions & 4 deletions api/v1alpha1/huaweicloudmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
capierrors "sigs.k8s.io/cluster-api/errors"
)

const (
// MachineFinalizer allows HuaweiCloudMachineReconciler to clean up HuaweiCloud resources associated with HuaweiCloudMachine before
// removing it from the apiserver.
MachineFinalizer = "huaweicloudmachine.infrastructure.cluster.x-k8s.io"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand All @@ -29,7 +36,6 @@ type HuaweiCloudMachineSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// 弹性云服务器uuid。
// ProviderID is the unique identifier as specified by the cloud provider.
ProviderID *string `json:"providerID,omitempty"`

Expand All @@ -46,18 +52,41 @@ type HuaweiCloudMachineSpec struct {
// +kubebuilder:validation:MinLength:=2
FlavorRef string `json:"flavorRef"`

// TODO, need to define the type of Volume struct in the future
// SSHKeyName is the name of the ssh key to attach to the instance. Valid values are empty string (do not use SSH keys), a valid SSH key name, or omitted (use the default SSH key name)
// +optional
SSHKeyName *string `json:"sshKeyName,omitempty"`

// RootVolume encapsulates the configuration options for the root volume
// +optional
// RootVolume *model.RootVolume `json:"rootVolume,omitempty"`
RootVolume *Volume `json:"rootVolume,omitempty"`

// TODO
// Configuration options for the data storage volumes.
// +optional
// DataVolumes *[]model.DataVolumes `json:"dataVolumes,omitempty"`

// PublicIP specifies whether the instance should get a public IP.
// Precedence for this setting is as follows:
// 1. This field if set
// 2. Cluster/flavor setting
// 3. Subnet default
// +optional
PublicIP *bool `json:"publicIP,omitempty"`

// ElasticIPPool is the configuration to allocate Public IPv4 address (Elastic IP/EIP) from user-defined pool.
//
// +optional
ElasticIPPool *ElasticIPPool `json:"elasticIpPool,omitempty"`

// TODO, more fields need to be defined in the future
// AdminPass *string `json:"admin_pass,omitempty"`
// NetConfig *NetConfig `json:"net_config"`
// Bandwidth *BandwidthConfig `json:"bandwidth,omitempty"`

// Subnet is a reference to the subnet to use for this instance. If not specified,
// the cluster subnet will be used.
// +optional
Subnet *HuaweiCloudResourceReference `json:"subnet,omitempty"`
}

// HuaweiCloudMachineStatus defines the observed state of HuaweiCloudMachine.
Expand All @@ -78,7 +107,12 @@ type HuaweiCloudMachineStatus struct {
// +optional
FailureMessage *string `json:"failureMessage,omitempty"`

// TODO add conditions and more fields in the future
// +optional
FailureReason *capierrors.MachineStatusError `json:"failureReason,omitempty"`

// Conditions defines current service state of the HuaweiCloudMachine.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
Expand All @@ -93,6 +127,16 @@ type HuaweiCloudMachine struct {
Status HuaweiCloudMachineStatus `json:"status,omitempty"`
}

// GetConditions returns the observations of the operational state of the HuaweiCloudMachine resource.
func (r *HuaweiCloudMachine) GetConditions() clusterv1.Conditions {
return r.Status.Conditions
}

// SetConditions sets the underlying service state of the HuaweiMachine to the predescribed clusterv1.Conditions.
func (r *HuaweiCloudMachine) SetConditions(conditions clusterv1.Conditions) {
r.Status.Conditions = conditions
}

// +kubebuilder:object:root=true

// HuaweiCloudMachineList contains a list of HuaweiCloudMachine.
Expand Down
15 changes: 13 additions & 2 deletions api/v1alpha1/huaweicloudmachinetemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand All @@ -28,8 +29,7 @@ type HuaweiCloudMachineTemplateSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of HuaweiCloudMachineTemplate. Edit huaweicloudmachinetemplate_types.go to remove/update
Foo string `json:"foo,omitempty"`
Template HuaweiCloudMachineTemplateResource `json:"template"`
}

// HuaweiCloudMachineTemplateStatus defines the observed state of HuaweiCloudMachineTemplate.
Expand Down Expand Up @@ -59,6 +59,17 @@ type HuaweiCloudMachineTemplateList struct {
Items []HuaweiCloudMachineTemplate `json:"items"`
}

// HuaweiCloudMachineTemplateResource describes the data needed to create am HuaweiCloudMachine from a template.
type HuaweiCloudMachineTemplateResource struct {
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty"`

// Spec is the specification of the desired behavior of the machine.
Spec HuaweiCloudMachineSpec `json:"spec"`
}

func init() {
SchemeBuilder.Register(&HuaweiCloudMachineTemplate{}, &HuaweiCloudMachineTemplateList{})
}
Loading

0 comments on commit 3538055

Please sign in to comment.