Fix issues found by linter

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas 2024-01-28 05:59:49 -05:00
parent 76ea142051
commit 4716bf8bd4
No known key found for this signature in database
GPG Key ID: 80D83A796103BF59
2 changed files with 20 additions and 21 deletions

View File

@ -80,15 +80,15 @@ func init() {
flag.Var(&nodeEnvs, "node-env", "An environment variable passed to instance as metadata, e.g. when '--node-env=PATH=/usr/bin' is specified, there will be an extra instance metadata 'PATH=/usr/bin'.")
}
const (
defaultGCEMachine = "e2-standard-2"
)
type GCERunner struct {
cfg remote.Config
gceImages *internalGCEImageConfig
}
const (
defaultGCEMachine = "e2-standard-2"
)
func NewGCERunner(cfg remote.Config) remote.Runner {
if cfg.InstanceNamePrefix == "" {
cfg.InstanceNamePrefix = "tmp-node-e2e-" + uuid.New().String()[:8]
@ -470,6 +470,9 @@ func (g *GCERunner) testGCEImage(suite remote.TestSuite, archivePath string, ima
// This is a temporary solution to collect serial node serial log. Only port 1 contains useful information.
// TODO(random-liu): Extract out and unify log collection logic with cluste e2e.
contents, err := g.getSerialOutput(host)
if err != nil {
klog.Errorf("Failed to get serial Output from node %q : %v", host, err)
}
logFilename := "serial-1.log"
err = remote.WriteLog(host, logFilename, contents)
if err != nil {
@ -482,7 +485,7 @@ func (g *GCERunner) testGCEImage(suite remote.TestSuite, archivePath string, ima
func (g *GCERunner) createGCEInstance(imageConfig *internalGCEImage) (string, error) {
data, err := runGCPCommand("compute", "project-info", "describe", "--format=json", "--project="+*project)
if err != nil {
return "", fmt.Errorf("failed to get project info for %q: %w", project, err)
return "", fmt.Errorf("failed to get project info for %q: %w", *project, err)
}
var p projectInfo
@ -506,7 +509,7 @@ func (g *GCERunner) createGCEInstance(imageConfig *internalGCEImage) (string, er
createArgs := []string{"compute", "instances", "create"}
createArgs = append(createArgs, name)
createArgs = append(createArgs, "--machine-type="+imageConfig.machine)
createArgs = append(createArgs, "--machine-type="+g.machineType(imageConfig.machine))
createArgs = append(createArgs, "--create-disk="+strings.Join(diskArgs, ","))
createArgs = append(createArgs, "--service-account="+serviceAccount)
if *preemptibleInstances {
@ -552,7 +555,7 @@ func (g *GCERunner) createGCEInstance(imageConfig *internalGCEImage) (string, er
_, err := runGCPCommandWithZone(createArgs...)
if err != nil {
fmt.Println(err)
return "", fmt.Errorf("failed to create instance in project %q: %w", project, err)
return "", fmt.Errorf("failed to create instance in project %q: %w", *project, err)
}
}
@ -568,7 +571,7 @@ func (g *GCERunner) createGCEInstance(imageConfig *internalGCEImage) (string, er
continue
}
if strings.ToUpper(instance.Status) != "RUNNING" {
err = fmt.Errorf("instance %s not in state RUNNING, was %s", name, instance.Status)
_ = fmt.Errorf("instance %s not in state RUNNING, was %s", name, instance.Status)
continue
}
externalIP := g.getExternalIP(instance)
@ -580,12 +583,12 @@ func (g *GCERunner) createGCEInstance(imageConfig *internalGCEImage) (string, er
output, err = remote.SSH(name, "sh", "-c",
"'systemctl list-units --type=service --state=running | grep -e containerd -e crio'")
if err != nil {
err = fmt.Errorf("instance %s not running containerd/crio daemon - Command failed: %s", name, output)
_ = fmt.Errorf("instance %s not running containerd/crio daemon - Command failed: %s", name, output)
continue
}
if !strings.Contains(output, "containerd.service") &&
!strings.Contains(output, "crio.service") {
err = fmt.Errorf("instance %s not running containerd/crio daemon: %s", name, output)
_ = fmt.Errorf("instance %s not running containerd/crio daemon: %s", name, output)
continue
}
instanceRunning = true
@ -634,10 +637,6 @@ func (g *GCERunner) isCloudInitUsed(metadata *gceMetadata) bool {
return false
}
func (g *GCERunner) sourceImage(image, imageProject string) string {
return fmt.Sprintf("projects/%s/global/images/%s", imageProject, image)
}
func (g *GCERunner) imageToInstanceName(imageConfig *internalGCEImage) string {
if imageConfig.machine == "" {
return g.cfg.InstanceNamePrefix + "-" + imageConfig.image
@ -723,7 +722,7 @@ func (g *GCERunner) machineType(machine string) string {
} else {
ret = defaultGCEMachine
}
return fmt.Sprintf("zones/%s/machineTypes/%s", *zone, ret)
return ret
}
func (g *GCERunner) rebootInstance(instance *gceInstance) error {

View File

@ -25,7 +25,7 @@ import (
type gceImage struct {
CreationTimestamp string `json:"creationTimestamp"`
Family string `json:"family"`
Id string `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
}
@ -54,7 +54,7 @@ type gceInstance struct {
CreationTimestamp string `json:"creationTimestamp"`
Description string `json:"description"`
Fingerprint string `json:"fingerprint"`
Id string `json:"id"`
ID string `json:"id"`
KeyRevocationActionType string `json:"keyRevocationActionType"`
Kind string `json:"kind"`
LabelFingerprint string `json:"labelFingerprint"`
@ -78,7 +78,7 @@ type projectInfo struct {
CreationTimestamp string `json:"creationTimestamp"`
DefaultNetworkTier string `json:"defaultNetworkTier"`
DefaultServiceAccount string `json:"defaultServiceAccount"`
Id string `json:"id"`
ID string `json:"id"`
}
func runGCPCommandWithZone(args ...string) ([]byte, error) {
@ -111,7 +111,7 @@ func runGCPCommandNoProject(args ...string) ([]byte, error) {
} else {
message = fmt.Sprintf("%v", err)
}
return nil, fmt.Errorf("Unable to run gcloud command\n %s \n %w", message, err)
return nil, fmt.Errorf("unable to run gcloud command\n %s \n %w", message, err)
}
return bytes, nil
}
@ -119,7 +119,7 @@ func runGCPCommandNoProject(args ...string) ([]byte, error) {
func getGCEInstance(host string) (*gceInstance, error) {
data, err := runGCPCommandWithZone("compute", "instances", "describe", host, "--format=json")
if err != nil {
return nil, fmt.Errorf("failed to describe instance in project %q: %w", project, err)
return nil, fmt.Errorf("failed to describe instance in project %q: %w", *project, err)
}
var gceHost gceInstance
@ -133,7 +133,7 @@ func getGCEInstance(host string) (*gceInstance, error) {
func (g *GCERunner) getSerialOutput(host string) (string, error) {
data, err := runGCPCommandWithZone("compute", "instances", "get-serial-port-output", "--port=1", host)
if err != nil {
return "", fmt.Errorf("failed to describe instance in project %q: %w", project, err)
return "", fmt.Errorf("failed to describe instance in project %q: %w", *project, err)
}
return string(data), nil
}