Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

machine: adjust return consistency #832

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
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
32 changes: 25 additions & 7 deletions pkg/machine/machineset.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewSetBuilderFromCopy(
" params: namespace: %s, instanceType: %s, workerLabel: %s, and replicas: %v", nsName, instanceType,
workerLabel, replicas)

builder := SetBuilder{
builder := &SetBuilder{
apiClient: apiClient,
}

Expand All @@ -63,7 +63,7 @@ func NewSetBuilderFromCopy(

builder.errorMsg = fmt.Sprintf("Error initializing MachineSet from copy: %s", err.Error())

return &builder
return builder
}

builder.Definition = newSetBuilder.Definition
Expand All @@ -72,6 +72,8 @@ func NewSetBuilderFromCopy(

if err != nil {
builder.errorMsg = fmt.Sprintf("error getting the public cloud kind: %v", err.Error())

return builder
}

glog.V(100).Infof("Updating copied MachineSet provider instanceType to: %s", instanceType)
Expand All @@ -80,46 +82,58 @@ func NewSetBuilderFromCopy(

if err != nil {
builder.errorMsg = fmt.Sprintf("error changing the instanceType: %v", err.Error())

return builder
}

if nsName == "" {
glog.V(100).Infof("The Namespace of the MachineSet is empty")

builder.errorMsg = "MachineSet 'nsName' cannot be empty"

return builder
}

if instanceType == "" {
glog.V(100).Infof("The instanceType of the MachineSet is empty")

builder.errorMsg = "MachineSet 'instanceType' cannot be empty"

return builder
}

if replicas == 0 {
glog.V(100).Infof("The replicas of the MachineSet is zero")

builder.errorMsg = "MachineSet 'replicas' cannot be zero"

return builder
}

if workerLabel == "" {
glog.V(100).Infof("The workerLabel of the MachineSet is empty")

builder.errorMsg = "MachineSet 'workerLabel' cannot be empty"

return builder
}

if builder.Definition == nil {
glog.V(100).Infof("The MachineSet object definition is nil")

builder.errorMsg = "MachineSet 'Object.Definition' is nil"

return builder
}

return &builder
return builder
}

// PullSet loads an existing MachineSet into Builder struct.
func PullSet(apiClient *clients.Settings, name, namespace string) (*SetBuilder, error) {
glog.V(100).Infof("Pulling existing machineSet name %s in namespace %s", name, namespace)

builder := SetBuilder{
builder := &SetBuilder{
apiClient: apiClient,
Definition: &machinev1beta1.MachineSet{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -131,10 +145,14 @@ func PullSet(apiClient *clients.Settings, name, namespace string) (*SetBuilder,

if name == "" {
builder.errorMsg = "MachineSet 'name' cannot be empty"

return nil, fmt.Errorf("machineSet 'name' cannot be empty")
}

if namespace == "" {
builder.errorMsg = "MachineSet 'namespace' cannot be empty"

return nil, fmt.Errorf("machineSet 'namespace' cannot be empty")
}

if !builder.Exists() {
Expand All @@ -143,7 +161,7 @@ func PullSet(apiClient *clients.Settings, name, namespace string) (*SetBuilder,

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Exists checks whether the given MachineSet exists.
Expand Down Expand Up @@ -569,13 +587,13 @@ func (builder *SetBuilder) validate() (bool, error) {
if builder.Definition == nil {
glog.V(100).Infof("The %s is undefined", resourceCRD)

builder.errorMsg = msg.UndefinedCrdObjectErrString(resourceCRD)
return false, fmt.Errorf(msg.UndefinedCrdObjectErrString(resourceCRD))
}

if builder.apiClient == nil {
glog.V(100).Infof("The %s builder apiClient is nil", resourceCRD)

builder.errorMsg = fmt.Sprintf("%s builder cannot have nil apiClient", resourceCRD)
return false, fmt.Errorf("%s builder cannot have nil apiClient", resourceCRD)
}

if builder.errorMsg != "" {
Expand Down
Loading