-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add support for podman quadlet
#26330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
flouthoc
wants to merge
1
commit into
containers:main
Choose a base branch
from
flouthoc:quadlet-work
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,199
−456
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package quadlet | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/containers/podman/v5/cmd/podman/common" | ||
"github.com/containers/podman/v5/cmd/podman/registry" | ||
"github.com/containers/podman/v5/cmd/podman/utils" | ||
"github.com/containers/podman/v5/pkg/domain/entities" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
quadletInstallDescription = `Install a quadlet file or quadlet application. Quadlets may be specified as local files, Web URLs, and OCI artifacts.` | ||
|
||
quadletInstallCmd = &cobra.Command{ | ||
Use: "install [options] QUADLET-PATH-OR-URL [FILES-PATH-OR-URL...]", | ||
Short: "Install a quadlet file or quadlet application", | ||
Long: quadletInstallDescription, | ||
RunE: install, | ||
Args: func(_ *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
return fmt.Errorf("must provide at least one argument") | ||
} | ||
return nil | ||
}, | ||
ValidArgsFunction: common.AutocompleteDefaultManyArg, | ||
Example: `podman quadlet install /path/to/myquadlet.container | ||
podman quadlet install https://github.com/containers/podman/blob/main/test/e2e/quadlet/basic.container | ||
podman quadlet install oci-artifact://my-artifact:latest`, | ||
} | ||
|
||
installOptions entities.QuadletInstallOptions | ||
) | ||
|
||
func installFlags(cmd *cobra.Command) { | ||
flags := cmd.Flags() | ||
flags.BoolVar(&installOptions.ReloadSystemd, "reload-systemd", true, "Reload systemd after installing Quadlets") | ||
} | ||
|
||
func init() { | ||
registry.Commands = append(registry.Commands, registry.CliCommand{ | ||
Command: quadletInstallCmd, | ||
Parent: quadletCmd, | ||
}) | ||
installFlags(quadletInstallCmd) | ||
} | ||
|
||
func install(cmd *cobra.Command, args []string) error { | ||
var errs utils.OutputErrors | ||
installReport, err := registry.ContainerEngine().QuadletInstall(registry.Context(), args, installOptions) | ||
if err != nil { | ||
return err | ||
} | ||
for pathOrURL, err := range installReport.QuadletErrors { | ||
errs = append(errs, fmt.Errorf("quadlet %q failed to install: %v", pathOrURL, err)) | ||
} | ||
for _, s := range installReport.InstalledQuadlets { | ||
fmt.Println(s) | ||
} | ||
|
||
if len(installReport.QuadletErrors) > 0 { | ||
errs = append(errs, errors.New("errors occurred installing some Quadlets")) | ||
} | ||
|
||
return errs.PrintErrors() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,103 @@ | ||||||||||||||||||||||||||
package quadlet | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||||||
"os" | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
"github.com/containers/common/pkg/completion" | ||||||||||||||||||||||||||
"github.com/containers/common/pkg/report" | ||||||||||||||||||||||||||
"github.com/containers/podman/v5/cmd/podman/common" | ||||||||||||||||||||||||||
"github.com/containers/podman/v5/cmd/podman/registry" | ||||||||||||||||||||||||||
"github.com/containers/podman/v5/cmd/podman/validate" | ||||||||||||||||||||||||||
"github.com/containers/podman/v5/pkg/domain/entities" | ||||||||||||||||||||||||||
"github.com/spf13/cobra" | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
var ( | ||||||||||||||||||||||||||
quadletListDescription = `List all Quadlets configured for the current user.` | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
quadletListCmd = &cobra.Command{ | ||||||||||||||||||||||||||
Use: "list [options]", | ||||||||||||||||||||||||||
Short: "List Quadlets", | ||||||||||||||||||||||||||
Long: quadletListDescription, | ||||||||||||||||||||||||||
RunE: list, | ||||||||||||||||||||||||||
Args: validate.NoArgs, | ||||||||||||||||||||||||||
ValidArgsFunction: completion.AutocompleteNone, | ||||||||||||||||||||||||||
Example: `podman quadlet list | ||||||||||||||||||||||||||
podman quadlet list --format '{{ .Unit }}' | ||||||||||||||||||||||||||
podman quadlet list --filter 'name=test*'`, | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
listOptions entities.QuadletListOptions | ||||||||||||||||||||||||||
format string | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func listFlags(cmd *cobra.Command) { | ||||||||||||||||||||||||||
formatFlagName := "format" | ||||||||||||||||||||||||||
filterFlagName := "filter" | ||||||||||||||||||||||||||
flags := cmd.Flags() | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
flags.StringArrayVarP(&listOptions.Filters, filterFlagName, "f", []string{}, "Filter output based on conditions given") | ||||||||||||||||||||||||||
flags.StringVar(&format, formatFlagName, "{{range .}}{{.Name}}\t{{.UnitName}}\t{{.Path}}\t{{.Status}}\t{{.App}}\n{{end -}}", "Pretty-print output to JSON or using a Go template") | ||||||||||||||||||||||||||
_ = quadletListCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&entities.ListQuadlet{})) | ||||||||||||||||||||||||||
_ = quadletListCmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteQuadletFilters) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func init() { | ||||||||||||||||||||||||||
registry.Commands = append(registry.Commands, registry.CliCommand{ | ||||||||||||||||||||||||||
Command: quadletListCmd, | ||||||||||||||||||||||||||
Parent: quadletCmd, | ||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||
listFlags(quadletListCmd) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func list(cmd *cobra.Command, args []string) error { | ||||||||||||||||||||||||||
quadlets, err := registry.ContainerEngine().QuadletList(registry.Context(), listOptions) | ||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if report.IsJSON(format) { | ||||||||||||||||||||||||||
return outputJSON(quadlets) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
return outputTemplate(cmd, quadlets) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func outputTemplate(cmd *cobra.Command, responses []*entities.ListQuadlet) error { | ||||||||||||||||||||||||||
headers := report.Headers(entities.ListQuadlet{}, map[string]string{ | ||||||||||||||||||||||||||
ygalblum marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||
"Name": "NAME", | ||||||||||||||||||||||||||
"UnitName": "UNIT NAME", | ||||||||||||||||||||||||||
"Path": "PATH ON DISK", | ||||||||||||||||||||||||||
"Status": "STATUS", | ||||||||||||||||||||||||||
"App": "APPLICATION", | ||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
rpt := report.New(os.Stdout, cmd.Name()) | ||||||||||||||||||||||||||
defer rpt.Flush() | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
var err error | ||||||||||||||||||||||||||
switch { | ||||||||||||||||||||||||||
case cmd.Flag("format").Changed: | ||||||||||||||||||||||||||
rpt, err = rpt.Parse(report.OriginUser, format) | ||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||
rpt, err = rpt.Parse(report.OriginPodman, format) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+78
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if err := rpt.Execute(headers); err != nil { | ||||||||||||||||||||||||||
return fmt.Errorf("writing column headers: %w", err) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return rpt.Execute(responses) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func outputJSON(vols []*entities.ListQuadlet) error { | ||||||||||||||||||||||||||
b, err := json.MarshalIndent(vols, "", " ") | ||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
fmt.Println(string(b)) | ||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package quadlet | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/containers/podman/v5/cmd/podman/common" | ||
"github.com/containers/podman/v5/cmd/podman/registry" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
quadletPrintDescription = `Print the contents of a Quadlet, displaying the file including all comments` | ||
|
||
quadletPrintCmd = &cobra.Command{ | ||
Use: "print QUADLET", | ||
Short: "Display the contents of a quadlet", | ||
Long: quadletPrintDescription, | ||
RunE: print, | ||
ValidArgsFunction: common.AutocompleteQuadlets, | ||
Args: cobra.ExactArgs(1), | ||
Example: `podman quadlet print myquadlet.container | ||
podman quadlet print mypod.pod | ||
podman quadlet print myimage.build`, | ||
} | ||
) | ||
|
||
func init() { | ||
registry.Commands = append(registry.Commands, registry.CliCommand{ | ||
Command: quadletPrintCmd, | ||
Parent: quadletCmd, | ||
}) | ||
} | ||
|
||
func print(cmd *cobra.Command, args []string) error { | ||
quadletContents, err := registry.ContainerEngine().QuadletPrint(registry.Context(), args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Print(quadletContents) | ||
|
||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package quadlet | ||
|
||
import ( | ||
"github.com/containers/podman/v5/cmd/podman/registry" | ||
"github.com/containers/podman/v5/cmd/podman/validate" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
// Pull in configured json library | ||
json = registry.JSONLibrary() | ||
|
||
// Command: podman _quadlet_ | ||
quadletCmd = &cobra.Command{ | ||
Use: "quadlet", | ||
Short: "Allows users to manage Quadlets", | ||
Long: "Allows users to manage Quadlets", | ||
RunE: validate.SubCommandExists, | ||
} | ||
) | ||
|
||
func init() { | ||
registry.Commands = append(registry.Commands, registry.CliCommand{ | ||
Command: quadletCmd, | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: what would be the recommend way of installing a kube quadlet? since the YAML would not be copied with this command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this is an even bigger questions. Many
.container
units come with a configuration file stored locally and mounted into the container. For example, see: https://github.com/containers/appstore/tree/main/quadlet/minio-prometheus.prometheus.yml
must be copied along withprometheus.container
.Furthermore, if you look at the examples, you can see that in many cases, more than one file is needed (units and others). Can the
install
command support installing a directory?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it supports multiplefile but I think we need to start consuming entire directory as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, having to list all the files does not make sense for the user. Plus, as I wrote not all of them will be Quadlet files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we copy resources, we may want to ensure they don't already exists, and have a
--force
flag, to allow overwriting existing filesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added patch to install from directory in new commit.
Will add
--force
in a follow up PR once this gets merged in order to keep review simpler and not to added too much to matt's original patch.