Skip to content

Commit

Permalink
cmd/create, cmd/run: Style fixes
Browse files Browse the repository at this point in the history
It's better not to use the global flag variables beyond the top-level
RunE functions, because sometimes the lower-level functions are re-used
from other files within the 'cmd' package.  In this case,
createContainer(), and hence pullImage(), is also used in src/cmd/run.go
to implement the 'run' command.  However, the 'run' command doesn't have
a --authflags option.

Since the default value of the flag is the zero value of the type, which
is a NOP in the code, it's likely that the code was still correct, but
it will be better to maintain some discipline here to highlight the
inputs needed by the lower-level functions.  Otherwise, things can get
tangled up.

Fallout from ecd1ced

#1240
  • Loading branch information
debarshiray committed Feb 16, 2023
1 parent 48c07b8 commit 8af015e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/cmd/create.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2019 – 2022 Red Hat Inc.
* Copyright © 2019 – 2023 Red Hat Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -176,14 +176,14 @@ func create(cmd *cobra.Command, args []string) error {
return err
}

if err := createContainer(container, image, release, true); err != nil {
if err := createContainer(container, image, release, createFlags.authFile, true); err != nil {
return err
}

return nil
}

func createContainer(container, image, release string, showCommandToEnter bool) error {
func createContainer(container, image, release, authFile string, showCommandToEnter bool) error {
if container == "" {
panic("container not specified")
}
Expand All @@ -210,7 +210,7 @@ func createContainer(container, image, release string, showCommandToEnter bool)
return errors.New(errMsg)
}

pulled, err := pullImage(image, release)
pulled, err := pullImage(image, release, authFile)
if err != nil {
return err
}
Expand Down Expand Up @@ -646,7 +646,7 @@ func getServiceSocket(serviceName string, unitName string) (string, error) {
return "", fmt.Errorf("failed to find a SOCK_STREAM socket for %s", unitName)
}

func pullImage(image, release string) (bool, error) {
func pullImage(image, release, authFile string) (bool, error) {
if ok := utils.ImageReferenceCanBeID(image); ok {
logrus.Debugf("Looking for image %s", image)

Expand Down Expand Up @@ -721,7 +721,7 @@ func pullImage(image, release string) (bool, error) {
defer s.Stop()
}

if err := podman.Pull(imageFull, createFlags.authFile); err != nil {
if err := podman.Pull(imageFull, authFile); err != nil {
var builder strings.Builder
fmt.Fprintf(&builder, "failed to pull image %s\n", imageFull)
fmt.Fprintf(&builder, "If it was a private image, log in with: podman login %s\n", domain)
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2019 – 2022 Red Hat Inc.
* Copyright © 2019 – 2023 Red Hat Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -215,7 +215,7 @@ func runCommand(container string,
return nil
}

if err := createContainer(container, image, release, false); err != nil {
if err := createContainer(container, image, release, "", false); err != nil {
return err
}
} else if containersCount == 1 && defaultContainer {
Expand Down

0 comments on commit 8af015e

Please sign in to comment.