Merge pull request #18038 from vrothberg/quadlet-version

add `quadlet -version` flag
This commit is contained in:
OpenShift Merge Robot
2023-04-04 09:01:00 -04:00
committed by GitHub
5 changed files with 46 additions and 17 deletions

View File

@ -164,7 +164,7 @@ spelled with complete minutiae.
`git checkout -b bump_vX.Y.Z`.
1. Look up the *COMMIT ID* of the last release,
`git log -1 $(git tag | sort -V | tail -1)`.
1. Edit `version/version.go` and bump the `Version` value to the new
1. Edit `version/rawversion/version.go` and bump the `Version` value to the new
release version. If there were API changes, also bump `APIVersion` value.
Make sure to also bump the version in the swagger.yaml `pkg/api/server/docs.go`
and to add a new entry in `docs/source/Reference.rst` for major and minor releases.
@ -181,7 +181,7 @@ spelled with complete minutiae.
1. Tag the `Bump to vX.Y.Z` commit as a release by running
`git tag -s -m 'vX.Y.Z' vX.Y.Z $HASH` where `$HASH` is specified explicitly
and carefully, to avoid (basically) unfixable accidents (if they are pushed).
1. Change `version/version.go` again. This time, bump the **patch** version and
1. Change `version/rawversion/version.go` again. This time, bump the **patch** version and
re-add the `-dev` suffix to indicate this is a non-released version of Podman.
1. Change `contrib/spec/podman.spec.in`, bumping **patch** number of `Version`.
1. Commit these changes with the message `Bump to X.Y.Z-dev`.

View File

@ -12,6 +12,7 @@ import (
"github.com/containers/podman/v4/pkg/systemd/parser"
"github.com/containers/podman/v4/pkg/systemd/quadlet"
"github.com/containers/podman/v4/version/rawversion"
)
// This commandline app is the systemd generator (system and user,
@ -25,8 +26,9 @@ import (
var (
verboseFlag bool // True if -v passed
noKmsgFlag bool
isUser bool // True if run as quadlet-user-generator executable
dryRun bool // True if -dryrun is used
isUserFlag bool // True if run as quadlet-user-generator executable
dryRunFlag bool // True if -dryrun is used
versionFlag bool // True if -version is used
)
var (
@ -294,32 +296,37 @@ func warnIfAmbiguousName(container *parser.UnitFile) {
func main() {
exitCode := 0
prgname := path.Base(os.Args[0])
isUser = strings.Contains(prgname, "user")
isUserFlag = strings.Contains(prgname, "user")
flag.Parse()
if verboseFlag || dryRun {
if versionFlag {
fmt.Printf("%s\n", rawversion.RawVersion)
return
}
if verboseFlag || dryRunFlag {
enableDebug()
}
if noKmsgFlag || dryRun {
if noKmsgFlag || dryRunFlag {
noKmsg = true
}
if !dryRun && flag.NArg() < 1 {
if !dryRunFlag && flag.NArg() < 1 {
Logf("Missing output directory argument")
os.Exit(1)
}
var outputPath string
if !dryRun {
if !dryRunFlag {
outputPath = flag.Arg(0)
Debugf("Starting quadlet-generator, output to: %s", outputPath)
}
sourcePaths := getUnitDirs(isUser)
sourcePaths := getUnitDirs(isUserFlag)
units := make(map[string]*parser.UnitFile)
for _, d := range sourcePaths {
@ -333,7 +340,7 @@ func main() {
os.Exit(0)
}
if !dryRun {
if !dryRunFlag {
err := os.MkdirAll(outputPath, os.ModePerm)
if err != nil {
Logf("Can't create dir %s: %s", outputPath, err)
@ -348,11 +355,11 @@ func main() {
switch {
case strings.HasSuffix(name, ".container"):
warnIfAmbiguousName(unit)
service, err = quadlet.ConvertContainer(unit, isUser)
service, err = quadlet.ConvertContainer(unit, isUserFlag)
case strings.HasSuffix(name, ".volume"):
service, err = quadlet.ConvertVolume(unit, name)
case strings.HasSuffix(name, ".kube"):
service, err = quadlet.ConvertKube(unit, isUser)
service, err = quadlet.ConvertKube(unit, isUserFlag)
case strings.HasSuffix(name, ".network"):
service, err = quadlet.ConvertNetwork(unit, name)
default:
@ -365,7 +372,7 @@ func main() {
} else {
service.Path = path.Join(outputPath, service.Filename)
if dryRun {
if dryRunFlag {
data, err := service.ToString()
if err != nil {
Debugf("Error parsing %s\n---\n", service.Path)
@ -388,6 +395,7 @@ func main() {
func init() {
flag.BoolVar(&verboseFlag, "v", false, "Print debug information")
flag.BoolVar(&noKmsgFlag, "no-kmsg-log", false, "Don't log to kmsg")
flag.BoolVar(&isUser, "user", false, "Run as systemd user")
flag.BoolVar(&dryRun, "dryrun", false, "run in dryrun mode printing debug information")
flag.BoolVar(&isUserFlag, "user", false, "Run as systemd user")
flag.BoolVar(&dryRunFlag, "dryrun", false, "Run in dryrun mode printing debug information")
flag.BoolVar(&versionFlag, "version", false, "Print version information and exit")
}

View File

@ -9,6 +9,7 @@ import (
"strings"
"github.com/containers/podman/v4/pkg/systemd/parser"
"github.com/containers/podman/v4/version"
"github.com/mattn/go-shellwords"
. "github.com/containers/podman/v4/test/utils"
@ -426,6 +427,15 @@ var _ = Describe("quadlet system generator", func() {
})
Describe("quadlet -version", func() {
It("Should print correct version", func() {
session := podmanTest.Quadlet([]string{"-version"}, "/something")
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(Equal(version.Version.String()))
})
})
Describe("Running quadlet dryrun tests", func() {
It("Should exit with an error because of no files are found to parse", func() {
fileName := "basic.kube"

View File

@ -0,0 +1,10 @@
package rawversion
// RawVersion is the raw version string.
//
// This indirection is needed to prevent semver packages from bloating
// Quadlet's binary size.
//
// NOTE: remember to bump the version at the top of the top-level README.md
// file when this is bumped.
const RawVersion = "4.5.0-dev"

View File

@ -2,6 +2,7 @@ package version
import (
"github.com/blang/semver/v4"
"github.com/containers/podman/v4/version/rawversion"
)
type (
@ -27,7 +28,7 @@ const (
// NOTE: remember to bump the version at the top
// of the top-level README.md file when this is
// bumped.
var Version = semver.MustParse("4.5.0-dev")
var Version = semver.MustParse(rawversion.RawVersion)
// See https://docs.docker.com/engine/api/v1.40/
// libpod compat handlers are expected to honor docker API versions