mirror of
https://github.com/containers/podman.git
synced 2026-07-10 15:25:00 -04:00
Merge pull request #28909 from Honny1/fix-lint
Replace deprecated `strings.Title` and fix staticcheck warnings
This commit is contained in:
@@ -103,9 +103,6 @@ func noop(_ *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("setting up grpc client for podman service: %w", err)
|
||||
}
|
||||
noopClient := grpcpb.NewNoopClient(grpcClient)
|
||||
if noopClient == nil {
|
||||
return fmt.Errorf("setting up client for noop grpc service: %w", err)
|
||||
}
|
||||
var request grpcpb.NoopRequest
|
||||
if encoded := strings.Join(args, ""); len(encoded) > 0 {
|
||||
if err := json.Unmarshal([]byte(encoded), &request); err != nil {
|
||||
|
||||
@@ -120,7 +120,7 @@ func PrepareSigning(pushOpts *entities.ImagePushOptions, cliOpts *SigningCLIOnly
|
||||
if passphrase != "" {
|
||||
opts = append(opts, simplesequoia.WithPassphrase(passphrase))
|
||||
}
|
||||
signer, err := simplesequoia.NewSigner(opts...)
|
||||
signer, err := simplesequoia.NewSigner(opts...) //nolint:staticcheck,nolintlint // SA4023 false positive: stub always errors, real build does not
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error using --sign-by-sq-fingerprint: %w", err)
|
||||
}
|
||||
|
||||
@@ -382,12 +382,9 @@ func (l psReporter) Status() string {
|
||||
state = fmt.Sprintf("Exited (%d) %s ago", l.ExitCode, t)
|
||||
default:
|
||||
// Need to capitalize the first letter to match Docker.
|
||||
|
||||
// strings.Title is deprecated since go 1.18
|
||||
// However for our use case it is still fine. The recommended replacement
|
||||
// is adding about 400kb binary size so let's keep using this for now.
|
||||
//nolint:staticcheck
|
||||
state = strings.Title(l.ListContainer.State)
|
||||
if s := l.ListContainer.State; len(s) > 0 {
|
||||
state = strings.ToUpper(s[:1]) + s[1:]
|
||||
}
|
||||
}
|
||||
hc := l.ListContainer.Status
|
||||
if hc != "" {
|
||||
|
||||
@@ -328,7 +328,7 @@ func (s *BoltState) getVolumeFromDB(name []byte, volume *Volume, volBkt *bolt.Bu
|
||||
// ocicniPortsToNetTypesPorts convert the old port format to the new one
|
||||
// while deduplicating ports into ranges
|
||||
//
|
||||
//nolint:staticcheck
|
||||
//nolint:staticcheck // OCICNIPortMapping is deprecated; kept for backwards-compatible DB migration
|
||||
func ocicniPortsToNetTypesPorts(ports []types.OCICNIPortMapping) []types.PortMapping {
|
||||
if len(ports) == 0 {
|
||||
return nil
|
||||
@@ -377,7 +377,7 @@ func ocicniPortsToNetTypesPorts(ports []types.OCICNIPortMapping) []types.PortMap
|
||||
// 3) hostPort
|
||||
// 4) container port
|
||||
//
|
||||
//nolint:staticcheck
|
||||
//nolint:staticcheck // OCICNIPortMapping is deprecated; kept for backwards-compatible DB migration
|
||||
func compareOCICNIPorts(i, j types.OCICNIPortMapping) bool {
|
||||
if i.HostIP != j.HostIP {
|
||||
return i.HostIP < j.HostIP
|
||||
|
||||
@@ -258,7 +258,7 @@ type ContainerNetworkConfig struct {
|
||||
// namespace. As of podman 4.0 this field is deprecated, use PortMappings
|
||||
// instead. The db will convert the old ports to the new structure for you.
|
||||
// These are not used unless CreateNetNS is true
|
||||
OldPortMappings []types.OCICNIPortMapping `json:"portMappings,omitempty"` //nolint:staticcheck
|
||||
OldPortMappings []types.OCICNIPortMapping `json:"portMappings,omitempty"` //nolint:staticcheck // OCICNIPortMapping is deprecated but kept for backwards-compatible DB migration
|
||||
// ExposedPorts are the ports which are exposed but not forwarded
|
||||
// into the container.
|
||||
// The map key is the port and the string slice contains the protocols,
|
||||
|
||||
@@ -289,7 +289,7 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) {
|
||||
utils.WaitContainerDocker(w, r)
|
||||
}
|
||||
|
||||
//nolint:staticcheck
|
||||
//nolint:staticcheck // LegacyNetworkSettings is deprecated but kept for Docker API compat < v1.52
|
||||
func convertSecondaryIPPrefixLen(input *define.InspectNetworkSettings, output *handlers.LegacyNetworkSettings) {
|
||||
for index, ip := range input.SecondaryIPAddresses {
|
||||
output.SecondaryIPAddresses[index].PrefixLen = ip.PrefixLength
|
||||
@@ -485,7 +485,7 @@ func LibpodToContainer(l *libpod.Container, sz bool, includeHealth bool) (*handl
|
||||
}, nil
|
||||
}
|
||||
|
||||
//nolint:staticcheck
|
||||
//nolint:staticcheck // LegacyImageInspect is deprecated but kept for Docker API compat < v1.52
|
||||
func LibpodToContainerJSON(l *libpod.Container, sz bool) (*handlers.LegacyImageInspect, error) {
|
||||
imageID, imageName := l.Image()
|
||||
inspect, err := l.Inspect(sz)
|
||||
@@ -588,7 +588,7 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*handlers.LegacyImageI
|
||||
Data: inspect.GraphDriver.Data,
|
||||
}
|
||||
|
||||
cb := handlers.LegacyImageInspect{ //nolint:staticcheck
|
||||
cb := handlers.LegacyImageInspect{ //nolint:staticcheck // LegacyImageInspect is deprecated but kept for Docker API compat < v1.52
|
||||
InspectResponse: container.InspectResponse{
|
||||
ID: l.ID(),
|
||||
Created: l.CreatedTime().UTC().Format(time.RFC3339Nano), // Docker uses UTC
|
||||
@@ -702,7 +702,7 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*handlers.LegacyImageI
|
||||
return nil, err
|
||||
}
|
||||
|
||||
networkSettings := handlers.LegacyNetworkSettings{} //nolint:staticcheck
|
||||
networkSettings := handlers.LegacyNetworkSettings{} //nolint:staticcheck // LegacyNetworkSettings is deprecated but kept for Docker API compat < v1.52
|
||||
if err := json.Unmarshal(n, &networkSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -98,24 +98,20 @@ func GetEvents(w http.ResponseWriter, r *http.Request) {
|
||||
// Handle these differences for Docker-compat.
|
||||
if !utils.IsLibpodRequest(r) && e.Type == "image" && e.Action == "remove" {
|
||||
// Status is deprecated, but we still like to set it for consumers that might use it.
|
||||
//nolint:staticcheck,nolintlint // we run the linter several times and sometimes it
|
||||
// complains about this and sometimes it doesn't thus the nolintlint
|
||||
e.Status = "delete"
|
||||
e.Status = "delete" //nolint:staticcheck // deprecated field
|
||||
e.Action = "delete"
|
||||
}
|
||||
if !utils.IsLibpodRequest(r) && e.Action == "died" {
|
||||
//nolint:staticcheck,nolintlint // we run the linter several times and sometimes it
|
||||
// complains about this and sometimes it doesn't thus the nolintlint
|
||||
e.Status = "die"
|
||||
e.Status = "die" //nolint:staticcheck // deprecated field
|
||||
e.Action = "die"
|
||||
e.Actor.Attributes["exitCode"] = e.Actor.Attributes["containerExitCode"]
|
||||
}
|
||||
|
||||
// Remove fields which are not set in 1.52 and newer.
|
||||
if _, err := apiutil.SupportedVersion(r, ">=1.52.0"); err == nil && !apiutil.IsLibpodRequest(r) {
|
||||
e.Status = "" //nolint:staticcheck
|
||||
e.ID = "" //nolint:staticcheck
|
||||
e.From = "" //nolint:staticcheck
|
||||
e.Status = "" //nolint:staticcheck // deprecated field, cleared for API >= 1.52
|
||||
e.ID = "" //nolint:staticcheck // deprecated field, cleared for API >= 1.52
|
||||
e.From = "" //nolint:staticcheck // deprecated field, cleared for API >= 1.52
|
||||
}
|
||||
|
||||
if err := coder.Encode(e); err != nil {
|
||||
|
||||
@@ -152,7 +152,7 @@ func PushImage(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
loop: // break out of for/select infinite loop
|
||||
for {
|
||||
var report handlers.LegacyJSONMessage //nolint:staticcheck
|
||||
var report handlers.LegacyJSONMessage //nolint:staticcheck // LegacyJSONMessage is deprecated but kept for Docker API compat < v1.52
|
||||
|
||||
select {
|
||||
case e := <-options.Progress:
|
||||
@@ -204,9 +204,8 @@ loop: // break out of for/select infinite loop
|
||||
report.Error = &jsonstream.Error{
|
||||
Message: msg,
|
||||
}
|
||||
//nolint:staticcheck // Deprecated field, but because consumers might still read it keep it.
|
||||
if _, err := apiutil.SupportedVersion(r, "<1.52.0"); err == nil {
|
||||
report.ErrorMessage = msg
|
||||
report.ErrorMessage = msg //nolint:staticcheck // deprecated field
|
||||
}
|
||||
if err := enc.Encode(report); err != nil {
|
||||
logrus.Warnf("Failed to json encode error %q", err.Error())
|
||||
|
||||
@@ -105,7 +105,7 @@ func GetDiskUsage(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
utils.WriteResponse(w, http.StatusOK, handlers.LegacyDiskUsage{ //nolint:staticcheck
|
||||
utils.WriteResponse(w, http.StatusOK, handlers.LegacyDiskUsage{ //nolint:staticcheck // LegacyDiskUsage is deprecated but kept for Docker API compat < v1.52
|
||||
LayersSize: df.ImagesSize,
|
||||
Images: legacy,
|
||||
Containers: ctnrs,
|
||||
|
||||
@@ -216,7 +216,7 @@ func CompatPull(r *http.Request, w http.ResponseWriter, runtime *libpod.Runtime,
|
||||
|
||||
loop: // break out of for/select infinite loop
|
||||
for {
|
||||
report := handlers.LegacyJSONMessage{} //nolint:staticcheck
|
||||
report := handlers.LegacyJSONMessage{} //nolint:staticcheck // LegacyJSONMessage is deprecated but kept for Docker API compat < v1.52
|
||||
report.Progress = &jsonstream.Progress{}
|
||||
select {
|
||||
case e := <-progress:
|
||||
@@ -251,9 +251,8 @@ loop: // break out of for/select infinite loop
|
||||
report.Error = &jsonstream.Error{
|
||||
Message: msg,
|
||||
}
|
||||
//nolint:staticcheck // Deprecated field, but because consumers might still read it keep it.
|
||||
if _, err := apiutil.SupportedVersion(r, "<1.52.0"); err == nil {
|
||||
report.ErrorMessage = msg
|
||||
report.ErrorMessage = msg //nolint:staticcheck // deprecated field
|
||||
}
|
||||
} else {
|
||||
pulledImages := pullRes.images
|
||||
@@ -266,9 +265,8 @@ loop: // break out of for/select infinite loop
|
||||
report.Error = &jsonstream.Error{
|
||||
Message: msg,
|
||||
}
|
||||
//nolint:staticcheck // Deprecated field, but because consumers might still read it keep it.
|
||||
if _, err := apiutil.SupportedVersion(r, "<1.52.0"); err == nil {
|
||||
report.ErrorMessage = msg
|
||||
report.ErrorMessage = msg //nolint:staticcheck // deprecated field
|
||||
}
|
||||
writeStatusCode(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -1185,11 +1185,11 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
|
||||
// If name is absolute path, then it has to be containerfile outside of build context.
|
||||
// If not, we should check it for being excluded via pattern matcher.
|
||||
if !filepath.IsAbs(name) {
|
||||
excluded, err := pm.Matches(name) //nolint:staticcheck
|
||||
res, err := pm.MatchesResult(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("checking if %q is excluded: %w", name, err)
|
||||
}
|
||||
if excluded {
|
||||
if res.IsMatched() {
|
||||
// Note: filepath.SkipDir is not possible to use given .dockerignore semantics.
|
||||
// An exception to exclusions may include an excluded directory, therefore we
|
||||
// are required to visit all files. :(
|
||||
|
||||
@@ -236,10 +236,11 @@ func parseApplyInput(arg string) (string, string, error) {
|
||||
}
|
||||
|
||||
imagePath := imgRef.StringWithinTransport()
|
||||
if transportName == ociTransport { //nolint:staticcheck
|
||||
switch transportName {
|
||||
case ociTransport:
|
||||
// oci:/tmp/oci-image
|
||||
imagePath, _, _ = strings.Cut(imagePath, ":")
|
||||
} else if transportName == ociArchiveTransport {
|
||||
case ociArchiveTransport:
|
||||
// oci-archive:/tmp/myimage.tar
|
||||
imagePath = strings.TrimSuffix(imagePath, ":")
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func InitializeSeccompPaths(annotations map[string]string, profileRoot string) (
|
||||
// check if it is prefaced with container.seccomp.security.alpha.kubernetes.io/
|
||||
prefixAndCtr := strings.Split(annKeyValue, "/")
|
||||
// FIXME: Rework for deprecation removal https://github.com/containers/podman/issues/27501
|
||||
//nolint:staticcheck
|
||||
//nolint:staticcheck // deprecated k8s annotation constant
|
||||
if prefixAndCtr[0]+"/" != v1.SeccompContainerAnnotationKeyPrefix {
|
||||
continue
|
||||
} else if len(prefixAndCtr) != 2 {
|
||||
@@ -55,7 +55,7 @@ func InitializeSeccompPaths(annotations map[string]string, profileRoot string) (
|
||||
seccompPaths.containerPaths[prefixAndCtr[1]] = path
|
||||
}
|
||||
// FIXME: Rework for deprecation removal https://github.com/containers/podman/issues/27501
|
||||
//nolint:staticcheck
|
||||
//nolint:staticcheck // deprecated k8s annotation constant
|
||||
podSeccomp, ok := annotations[v1.SeccompPodAnnotationKey]
|
||||
if ok {
|
||||
seccompPaths.podPath, err = verifySeccompPath(podSeccomp, profileRoot)
|
||||
@@ -74,11 +74,11 @@ func InitializeSeccompPaths(annotations map[string]string, profileRoot string) (
|
||||
func verifySeccompPath(path string, profileRoot string) (string, error) {
|
||||
switch path {
|
||||
// FIXME: Rework for deprecation removal https://github.com/containers/podman/issues/27501
|
||||
//nolint:staticcheck
|
||||
//nolint:staticcheck // deprecated k8s seccomp constant
|
||||
case v1.DeprecatedSeccompProfileDockerDefault:
|
||||
fallthrough
|
||||
// FIXME: Rework for deprecation removal https://github.com/containers/podman/issues/27501
|
||||
//nolint:staticcheck
|
||||
//nolint:staticcheck // deprecated k8s seccomp constant
|
||||
case v1.SeccompProfileRuntimeDefault:
|
||||
return libpod.DefaultSeccompPath()
|
||||
case "unconfined":
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2" //nolint:staticcheck
|
||||
. "github.com/onsi/gomega" //nolint:staticcheck
|
||||
. "github.com/onsi/ginkgo/v2" //nolint:staticcheck // ST1001: should not use dot imports
|
||||
. "github.com/onsi/gomega" //nolint:staticcheck // ST1001: should not use dot imports
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user