-
Notifications
You must be signed in to change notification settings - Fork 64
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
podman http api client #51
Conversation
Have you considered using the Golang API bindings in the Podman repo here? |
@mheon , yes, we discussed about it in #37 and created also a podman issue at containers/podman#6866 We would like, of course, to reuse some of your work but hesitate to do it. Our concerns are:
Thank you for reaching out , it would be nice if you can clarify the intentions about your podman binding package. |
Start http api service unit
Improved container startup and stats Disabled oom test because of podman problems
Enable filesystem isolation mode, solved weird Env[] problems Expose more podman systeminfo details to nomad Removed custom cgroupv2 detector, rely on podman instead
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.
@towe75 this is amazing work! I have many stylistic nitpicks and only a few questions. Really awesome job getting this together. Let me know if you have any questions.
apiclient/apiclient.go
Outdated
logger hclog.Logger | ||
} | ||
|
||
func NewClient(logger hclog.Logger) *APIClient { |
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.
GuessSocketPath
sounds like we are guessing :) Thoughts on passing in a an Config struct, that contains a logger and socket path? when we initialize the config we can use a renamed version of GuessSocketPath as DefaultSocketPath is one isn't provided
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.
Method is now renamed to DefaultSocketPath().
Not sure how to approach the config struct. What about moving api initialization from NewPodmanDriver() to SetConfig()? This way we could simply share the drivers config with api or derive a separate struct from driverconfig.
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.
IMO something like this would be nice, if SetConfig
is the entry point it could be built up there, We can provide a DefaultConfig()
method in the api package if we are initializing the client first, then calling setconfig but that seems like something to think about for future improvements to only call once
type ClientConfig struct{
SocketPath string
}
func NewClient(cfg ClientConfig, logger hclog.Logger) *APIClient {
apiclient/apiclient.go
Outdated
func (c *APIClient) SetSocketPath(baseUrl string) { | ||
c.logger.Debug("http baseurl", "url", baseUrl) | ||
c.httpClient = &http.Client{ | ||
Timeout: 60 * time.Second, |
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.
Timeout seems like another good candidate to make configurable
driver.go
Outdated
} else if driverConfig.NetworkMode == "slirp4netns" { | ||
createOpts.ContainerNetworkConfig.NetNS.NSMode = apiclient.Slirp | ||
} else { | ||
// FIXME: needs more work, parsing etc. |
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.
can we track this with a github issue
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.
This "else" part is a typical place to handle not-yet-known requirements. I would not know what to write into the issue except "implement all possible podman network modes and switches". We can remove the FIXME because it's not a bug per se.
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.
APL2 headers should be removed, repo is under MPL, no file specific headers necessary
renamed apiclient package to api improved httpclient context usage improved driver struct, renamed field podmanClient2 to podman
Renamed GuessSocketPath to DefaultSocketPath Removed api-version constant Cleaned up api-endpoints, do not use "compat" api, always send api version Worked around flaky tests by adding sleeps to avoid very shortliving containers
Improved comments Simplified TestPodmanDriver_SignalTask
Moved all podman structs to new file structs.go
Moved api.NewClient to driver.SetConfig()
@drewbailey PTAL. Everything should be resolved now. |
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.
Looking really good, just a few outstanding comments and questions left and then should be good to go!
api/container_create.go
Outdated
if err != nil { | ||
return response, err | ||
} | ||
// fmt.Println(string(jsonString)) |
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.
// fmt.Println(string(jsonString)) |
} | ||
|
||
// wait max 10 seconds for running state | ||
timeout, cancel := context.WithTimeout(ctx, time.Second*10) |
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.
timeout, cancel := context.WithTimeout(ctx, time.Second*10) | |
// TODO make timeout configurable | |
timeout, cancel := context.WithTimeout(ctx, time.Second*10) |
api/system_info.go
Outdated
|
||
var infoData Info | ||
|
||
// the libpod/info endpoint seems to have some trouble |
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.
// the libpod/info endpoint seems to have some trouble | |
// The libpod/info endpoint seems to have some trouble |
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.
Will remove this stale comment, we're not using the compat endpoint anymore.
driver.go
Outdated
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ |
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.
This Source Code Form is subject to the terms of the Mozilla Public | |
License, v. 2.0. If a copy of the MPL was not distributed with this | |
file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
*/ |
driver.go
Outdated
@@ -341,6 +335,8 @@ func BuildContainerName(cfg *drivers.TaskConfig) string { | |||
|
|||
// StartTask creates and starts a new Container based on the given TaskConfig. | |||
func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drivers.DriverNetwork, error) { | |||
// d.logger.Warn("Env1", "env1", cfg.Env) |
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.
re-bumping this :)
cgroupv2 := false | ||
for _, l := range procFilesystems { | ||
cgroupv2 = cgroupv2 || strings.HasSuffix(l, "cgroup2") | ||
if cfg.Resources.NomadResources.Memory.MemoryMB > 0 { |
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.
what is this limit? MemoryMB * 1024 * 1024 seems high, unless memoryMB its bytes?
handle.go
Outdated
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ |
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.
This Source Code Form is subject to the terms of the Mozilla Public | |
License, v. 2.0. If a copy of the MPL was not distributed with this | |
file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
*/ |
main.go
Outdated
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ |
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.
This Source Code Form is subject to the terms of the Mozilla Public | |
License, v. 2.0. If a copy of the MPL was not distributed with this | |
file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
*/ |
state.go
Outdated
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ |
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.
This Source Code Form is subject to the terms of the Mozilla Public | |
License, v. 2.0. If a copy of the MPL was not distributed with this | |
file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
*/ |
See also #37
Goal
Goal of this PR is to replace the deprecated podman varlink api client with a http/rest based implementation.
It will not be a generic podman client, structs and methods will only implement the minimum needed attributes/features.
Todo
Client implementation
Endpoints
Port currently implemented varlink endpoints:
Buildsystem
Port features
Improvements