Skip to content

Commit

Permalink
Fix lint issue
Browse files Browse the repository at this point in the history
  • Loading branch information
schnell18 committed Jun 15, 2023
1 parent 426ebcb commit aa1aa87
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions builder/ucloud/uhost/step_check_source_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ package uhost
import (
"context"
"fmt"
"github.com/ucloud/ucloud-sdk-go/services/uhost"

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/ucloud/ucloud-sdk-go/services/uhost"

ucloudcommon "github.com/ucloud/packer-plugin-ucloud/builder/ucloud/common"
)

type stepCheckSourceImageId struct {
SourceUHostImageId string
}

func (s *stepCheckSourceImageId) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
func (s *stepCheckSourceImageId) Run(
ctx context.Context,
state multistep.StateBag,
) multistep.StepAction {
ui := state.Get("ui").(packersdk.Ui)
client := state.Get("client").(*ucloudcommon.UCloudClient)

Expand All @@ -25,10 +29,21 @@ func (s *stepCheckSourceImageId) Run(ctx context.Context, state multistep.StateB
if ucloudcommon.IsNotFoundError(err) {
uk8sNodeImage, uk8sErr := client.DescribeUK8sNodeImageById(s.SourceUHostImageId)
if ucloudcommon.IsNotFoundError(uk8sErr) {
return ucloudcommon.Halt(state, fmt.Errorf("fail to find source_image_id %q", s.SourceUHostImageId), "")
return ucloudcommon.Halt(
state,
fmt.Errorf("fail to find source_image_id %q", s.SourceUHostImageId),
"",
)
}
if uk8sErr != nil {
return ucloudcommon.Halt(state, uk8sErr, fmt.Sprintf("Error on querying specified source_image_id %q", s.SourceUHostImageId))
return ucloudcommon.Halt(
state,
uk8sErr,
fmt.Sprintf(
"Error on querying specified source_image_id %q",
s.SourceUHostImageId,
),
)
}
imageSet = &uhost.UHostImageSet{}
imageSet.ImageName = uk8sNodeImage.ImageName
Expand All @@ -41,14 +56,29 @@ func (s *stepCheckSourceImageId) Run(ctx context.Context, state multistep.StateB
}

if imageSet.OsType == ucloudcommon.OsTypeWindows {
return ucloudcommon.Halt(state, err, "The ucloud-uhost builder does not support Windows images yet")
return ucloudcommon.Halt(
state,
err,
"The ucloud-uhost builder does not support Windows images yet",
)
}

_, uOK := state.GetOk("user_data")
_, fOK := state.GetOk("user_data_file")
if uOK || fOK {
if !ucloudcommon.IsStringIn("CloudInit", imageSet.Features) {
return ucloudcommon.Halt(state, err, fmt.Sprintf("The image %s must have %q feature when set the %q or %q, got %#v", imageSet.ImageId, "CloudInit", "user_data", "user_data_file", imageSet.Features))
return ucloudcommon.Halt(
state,
err,
fmt.Sprintf(
"The image %s must have %q feature when set the %q or %q, got %#v",
imageSet.ImageId,
"CloudInit",
"user_data",
"user_data_file",
imageSet.Features,
),
)
}
}

Expand Down

0 comments on commit aa1aa87

Please sign in to comment.