Skip to content

Commit

Permalink
Fix providerID format
Browse files Browse the repository at this point in the history
Signed-off-by: ekko <lihai.tu@daocloud.io>
  • Loading branch information
0ekk committed Feb 21, 2025
1 parent 0933be9 commit a404296
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/controller/huaweicloudmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (r *HuaweiCloudMachineReconciler) reconcileNormal(_ context.Context, machin
}

// Make sure Spec.ProviderID and Spec.InstanceID are always set.
machineScope.SetProviderID(instance.ID, instance.AvailabilityZone)
machineScope.SetProviderID(instance.ID)
machineScope.SetInstanceID(instance.ID)

existingInstanceState := machineScope.GetInstanceState()
Expand Down
4 changes: 2 additions & 2 deletions pkg/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func (m *MachineScope) GetProviderID() string {
}

// SetProviderID sets the HuaweiCloudMachine providerID in spec.
func (m *MachineScope) SetProviderID(instanceID, availabilityZone string) {
providerID := GenerateProviderID(availabilityZone, instanceID)
func (m *MachineScope) SetProviderID(instanceID string) {
providerID := GenerateProviderID(instanceID)
m.HCMachine.Spec.ProviderID = ptr.To[string](providerID)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/scope/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ const ProviderIDPrefix = "huaweicloud://"
//
// By default, the last id provided is used as identifier (last part).
func GenerateProviderID(ids ...string) string {
return fmt.Sprintf("%s/%s", ProviderIDPrefix, strings.Join(ids, "/"))
return fmt.Sprintf("%s%s", ProviderIDPrefix, strings.Join(ids, "/"))
}
3 changes: 1 addition & 2 deletions pkg/services/ecs/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte,
}

// Set the providerID and instanceID as soon as we create an instance so that we keep it in case of errors afterward
scope.SetProviderID(out.ID, out.AvailabilityZone)
scope.SetProviderID(out.ID)
scope.SetInstanceID(out.ID)

return out, nil
Expand All @@ -195,7 +195,6 @@ func (s *Service) runInstance(i *infrav1.Instance) (*infrav1.Instance, error) {
XClientToken: ptr.To(string(uuid.NewUUID())),
Body: &ecsModel.CreateServersRequestBody{
Server: &ecsModel.PrePaidServer{
AdminPass: ptr.To("dangerous@2025"),
Name: generateInstanceName("caphw-ecs"),
ImageRef: i.ImageID,
FlavorRef: i.Type,
Expand Down

0 comments on commit a404296

Please sign in to comment.