mirror of https://github.com/containers/podman.git
Fix QF1003: could use tagged switch" staticcheck warning
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
0dddc5e3c0
commit
0105131b5c
|
@ -1182,9 +1182,10 @@ func (c *Container) cleanupRuntime(ctx context.Context) error {
|
||||||
// If we were Stopped, we are now Exited, as we've removed ourself
|
// If we were Stopped, we are now Exited, as we've removed ourself
|
||||||
// from the runtime.
|
// from the runtime.
|
||||||
// If we were Created, we are now Configured.
|
// If we were Created, we are now Configured.
|
||||||
if c.state.State == define.ContainerStateStopped {
|
switch c.state.State {
|
||||||
|
case define.ContainerStateStopped:
|
||||||
c.state.State = define.ContainerStateExited
|
c.state.State = define.ContainerStateExited
|
||||||
} else if c.state.State == define.ContainerStateCreated {
|
case define.ContainerStateCreated:
|
||||||
c.state.State = define.ContainerStateConfigured
|
c.state.State = define.ContainerStateConfigured
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1219,10 +1220,11 @@ func (c *Container) reinit(ctx context.Context, retainRetries bool) error {
|
||||||
// Performs all necessary steps to start a container that is not running
|
// Performs all necessary steps to start a container that is not running
|
||||||
// Does not lock or check validity, requires to run on the same thread that holds the lock for the container.
|
// Does not lock or check validity, requires to run on the same thread that holds the lock for the container.
|
||||||
func (c *Container) initAndStart(ctx context.Context) (retErr error) {
|
func (c *Container) initAndStart(ctx context.Context) (retErr error) {
|
||||||
// If we are ContainerStateUnknown, throw an error
|
// If we are ContainerState{Unknown,Removing}, throw an error.
|
||||||
if c.state.State == define.ContainerStateUnknown {
|
switch c.state.State {
|
||||||
|
case define.ContainerStateUnknown:
|
||||||
return fmt.Errorf("container %s is in an unknown state: %w", c.ID(), define.ErrCtrStateInvalid)
|
return fmt.Errorf("container %s is in an unknown state: %w", c.ID(), define.ErrCtrStateInvalid)
|
||||||
} else if c.state.State == define.ContainerStateRemoving {
|
case define.ContainerStateRemoving:
|
||||||
return fmt.Errorf("cannot start container %s as it is being removed: %w", c.ID(), define.ErrCtrStateInvalid)
|
return fmt.Errorf("cannot start container %s as it is being removed: %w", c.ID(), define.ErrCtrStateInvalid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1688,14 +1690,14 @@ func (c *Container) restartWithTimeout(ctx context.Context, timeout uint) (retEr
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.state.State == define.ContainerStateStopped {
|
switch c.state.State {
|
||||||
// Reinitialize the container if we need to
|
case define.ContainerStateStopped:
|
||||||
|
// Reinitialize the container if we need to.
|
||||||
if err := c.reinit(ctx, false); err != nil {
|
if err := c.reinit(ctx, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if c.state.State == define.ContainerStateConfigured ||
|
case define.ContainerStateConfigured, define.ContainerStateExited:
|
||||||
c.state.State == define.ContainerStateExited {
|
// Initialize the container.
|
||||||
// Initialize the container
|
|
||||||
if err := c.init(ctx, false); err != nil {
|
if err := c.init(ctx, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,26 +229,26 @@ func Attach(ctx context.Context, nameOrID string, stdin io.Reader, stdout io.Wri
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch fd {
|
||||||
case fd == 0:
|
case 0:
|
||||||
if isSet.stdout {
|
if isSet.stdout {
|
||||||
if _, err := stdout.Write(frame[0:l]); err != nil {
|
if _, err := stdout.Write(frame[0:l]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case fd == 1:
|
case 1:
|
||||||
if isSet.stdout {
|
if isSet.stdout {
|
||||||
if _, err := stdout.Write(frame[0:l]); err != nil {
|
if _, err := stdout.Write(frame[0:l]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case fd == 2:
|
case 2:
|
||||||
if isSet.stderr {
|
if isSet.stderr {
|
||||||
if _, err := stderr.Write(frame[0:l]); err != nil {
|
if _, err := stderr.Write(frame[0:l]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case fd == 3:
|
case 3:
|
||||||
return fmt.Errorf("from service from stream: %s", frame)
|
return fmt.Errorf("from service from stream: %s", frame)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unrecognized channel '%d' in header, 0-3 supported", fd)
|
return fmt.Errorf("unrecognized channel '%d' in header, 0-3 supported", fd)
|
||||||
|
@ -558,8 +558,8 @@ func ExecStartAndAttach(ctx context.Context, sessionID string, options *ExecStar
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch fd {
|
||||||
case fd == 0:
|
case 0:
|
||||||
if options.GetAttachInput() {
|
if options.GetAttachInput() {
|
||||||
// Write STDIN to STDOUT (echoing characters
|
// Write STDIN to STDOUT (echoing characters
|
||||||
// typed by another attach session)
|
// typed by another attach session)
|
||||||
|
@ -567,19 +567,19 @@ func ExecStartAndAttach(ctx context.Context, sessionID string, options *ExecStar
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case fd == 1:
|
case 1:
|
||||||
if options.GetAttachOutput() {
|
if options.GetAttachOutput() {
|
||||||
if _, err := options.GetOutputStream().Write(frame[0:l]); err != nil {
|
if _, err := options.GetOutputStream().Write(frame[0:l]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case fd == 2:
|
case 2:
|
||||||
if options.GetAttachError() {
|
if options.GetAttachError() {
|
||||||
if _, err := options.GetErrorStream().Write(frame[0:l]); err != nil {
|
if _, err := options.GetErrorStream().Write(frame[0:l]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case fd == 3:
|
case 3:
|
||||||
return fmt.Errorf("from service from stream: %s", frame)
|
return fmt.Errorf("from service from stream: %s", frame)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unrecognized channel '%d' in header, 0-3 supported", fd)
|
return fmt.Errorf("unrecognized channel '%d' in header, 0-3 supported", fd)
|
||||||
|
|
|
@ -73,9 +73,10 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
state := status.String()
|
state := status.String()
|
||||||
if status == define.ContainerStateConfigured {
|
switch status {
|
||||||
|
case define.ContainerStateConfigured:
|
||||||
state = "created"
|
state = "created"
|
||||||
} else if status == define.ContainerStateStopped {
|
case define.ContainerStateStopped:
|
||||||
state = "exited"
|
state = "exited"
|
||||||
}
|
}
|
||||||
for _, filterValue := range filterValues {
|
for _, filterValue := range filterValues {
|
||||||
|
|
|
@ -75,9 +75,10 @@ func GeneratePodFilterFunc(filter string, filterValues []string, r *libpod.Runti
|
||||||
}
|
}
|
||||||
for _, ctrStatus := range ctrStatuses {
|
for _, ctrStatus := range ctrStatuses {
|
||||||
state := ctrStatus.String()
|
state := ctrStatus.String()
|
||||||
if ctrStatus == define.ContainerStateConfigured {
|
switch ctrStatus {
|
||||||
|
case define.ContainerStateConfigured:
|
||||||
state = "created"
|
state = "created"
|
||||||
} else if ctrStatus == define.ContainerStateStopped {
|
case define.ContainerStateStopped:
|
||||||
state = "exited"
|
state = "exited"
|
||||||
}
|
}
|
||||||
for _, filterValue := range filterValues {
|
for _, filterValue := range filterValues {
|
||||||
|
|
|
@ -347,9 +347,10 @@ func ParseQuantity(str string) (Quantity, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// So that no one but us has to think about suffixes, remove it.
|
// So that no one but us has to think about suffixes, remove it.
|
||||||
if base == 10 {
|
switch base {
|
||||||
|
case 10:
|
||||||
amount.SetScale(amount.Scale() + Scale(exponent).infScale())
|
amount.SetScale(amount.Scale() + Scale(exponent).infScale())
|
||||||
} else if base == 2 {
|
case 2:
|
||||||
// numericSuffix = 2 ** exponent
|
// numericSuffix = 2 ** exponent
|
||||||
numericSuffix := big.NewInt(1).Lsh(bigOne, uint(exponent))
|
numericSuffix := big.NewInt(1).Lsh(bigOne, uint(exponent))
|
||||||
ub := amount.UnscaledBig()
|
ub := amount.UnscaledBig()
|
||||||
|
|
|
@ -288,11 +288,11 @@ func ParseCgroupNamespace(ns string) (Namespace, error) {
|
||||||
// form.
|
// form.
|
||||||
func ParseIPCNamespace(ns string) (Namespace, error) {
|
func ParseIPCNamespace(ns string) (Namespace, error) {
|
||||||
toReturn := Namespace{}
|
toReturn := Namespace{}
|
||||||
switch {
|
switch ns {
|
||||||
case ns == "shareable", ns == "":
|
case "shareable", "":
|
||||||
toReturn.NSMode = Shareable
|
toReturn.NSMode = Shareable
|
||||||
return toReturn, nil
|
return toReturn, nil
|
||||||
case ns == "none":
|
case "none":
|
||||||
toReturn.NSMode = None
|
toReturn.NSMode = None
|
||||||
return toReturn, nil
|
return toReturn, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,8 +238,8 @@ func setContainerNameForTemplate(startCommand []string, info *containerInfo) ([]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch {
|
switch nameIx {
|
||||||
case nameIx == -1:
|
case -1:
|
||||||
// if not found, add --name argument in the command slice before the "run" argument.
|
// if not found, add --name argument in the command slice before the "run" argument.
|
||||||
// it's assumed that the command slice contains this argument.
|
// it's assumed that the command slice contains this argument.
|
||||||
runIx := -1
|
runIx := -1
|
||||||
|
|
|
@ -704,11 +704,12 @@ var _ = Describe("Podman kube generate", func() {
|
||||||
// have anything for protocol under the ports as tcp is the default
|
// have anything for protocol under the ports as tcp is the default
|
||||||
// for k8s
|
// for k8s
|
||||||
Expect(port.Protocol).To(BeEmpty())
|
Expect(port.Protocol).To(BeEmpty())
|
||||||
if port.HostPort == 4008 {
|
switch port.HostPort {
|
||||||
|
case 4008:
|
||||||
foundPort400x++
|
foundPort400x++
|
||||||
} else if port.HostPort == 5008 {
|
case 5008:
|
||||||
foundPort500x++
|
foundPort500x++
|
||||||
} else {
|
default:
|
||||||
foundOtherPort++
|
foundOtherPort++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue