summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/api/handlers/libpod/networks.go66
-rw-r--r--pkg/api/server/register_networks.go2
-rw-r--r--pkg/bindings/images/build.go2
-rw-r--r--pkg/bindings/test/networks_test.go4
-rw-r--r--pkg/checkpoint/checkpoint_restore.go7
-rw-r--r--pkg/machine/fcos.go57
6 files changed, 118 insertions, 20 deletions
diff --git a/pkg/api/handlers/libpod/networks.go b/pkg/api/handlers/libpod/networks.go
index 71d46ce70..16f499d4c 100644
--- a/pkg/api/handlers/libpod/networks.go
+++ b/pkg/api/handlers/libpod/networks.go
@@ -17,22 +17,37 @@ import (
)
func CreateNetwork(w http.ResponseWriter, r *http.Request) {
+ if v, err := utils.SupportedVersion(r, ">=4.0.0"); err != nil {
+ utils.BadRequest(w, "version", v.String(), err)
+ return
+ }
+
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
network := types.Network{}
if err := json.NewDecoder(r.Body).Decode(&network); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "decode body"))
+ utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to decode request JSON payload"))
return
}
ic := abi.ContainerEngine{Libpod: runtime}
report, err := ic.NetworkCreate(r.Context(), network)
if err != nil {
- utils.InternalServerError(w, err)
+ if errors.Is(err, types.ErrNetworkExists) {
+ utils.Error(w, http.StatusConflict, err)
+ } else {
+ utils.InternalServerError(w, err)
+ }
return
}
utils.WriteResponse(w, http.StatusOK, report)
}
+
func ListNetworks(w http.ResponseWriter, r *http.Request) {
+ if v, err := utils.SupportedVersion(r, ">=4.0.0"); err != nil {
+ utils.BadRequest(w, "version", v.String(), err)
+ return
+ }
+
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
filterMap, err := util.PrepareFilters(r)
if err != nil {
@@ -54,6 +69,11 @@ func ListNetworks(w http.ResponseWriter, r *http.Request) {
}
func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
+ if v, err := utils.SupportedVersion(r, ">=4.0.0"); err != nil {
+ utils.BadRequest(w, "version", v.String(), err)
+ return
+ }
+
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
query := struct {
@@ -87,21 +107,18 @@ func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
utils.WriteResponse(w, http.StatusOK, reports)
}
+// InspectNetwork reports on given network's details
func InspectNetwork(w http.ResponseWriter, r *http.Request) {
- runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
- decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
- query := struct {
- }{
- // override any golang type defaults
- }
- if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusInternalServerError,
- errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ if v, err := utils.SupportedVersion(r, ">=4.0.0"); err != nil {
+ utils.BadRequest(w, "version", v.String(), err)
return
}
+
+ runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
+ ic := abi.ContainerEngine{Libpod: runtime}
+
name := utils.GetName(r)
options := entities.InspectOptions{}
- ic := abi.ContainerEngine{Libpod: runtime}
reports, errs, err := ic.NetworkInspect(r.Context(), []string{name}, options)
// If the network cannot be found, we return a 404.
if len(errs) > 0 {
@@ -117,14 +134,19 @@ func InspectNetwork(w http.ResponseWriter, r *http.Request) {
// Connect adds a container to a network
func Connect(w http.ResponseWriter, r *http.Request) {
- runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
+ if v, err := utils.SupportedVersion(r, ">=4.0.0"); err != nil {
+ utils.BadRequest(w, "version", v.String(), err)
+ return
+ }
+ runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
var netConnect entities.NetworkConnectOptions
if err := json.NewDecoder(r.Body).Decode(&netConnect); err != nil {
- utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
+ utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to decode request JSON payload"))
return
}
name := utils.GetName(r)
+
err := runtime.ConnectContainerToNetwork(netConnect.Container, name, netConnect.PerNetworkOptions)
if err != nil {
if errors.Cause(err) == define.ErrNoSuchCtr {
@@ -143,10 +165,15 @@ func Connect(w http.ResponseWriter, r *http.Request) {
// ExistsNetwork check if a network exists
func ExistsNetwork(w http.ResponseWriter, r *http.Request) {
- runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
- name := utils.GetName(r)
+ if v, err := utils.SupportedVersion(r, ">=4.0.0"); err != nil {
+ utils.BadRequest(w, "version", v.String(), err)
+ return
+ }
+ runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
ic := abi.ContainerEngine{Libpod: runtime}
+
+ name := utils.GetName(r)
report, err := ic.NetworkExists(r.Context(), name)
if err != nil {
utils.Error(w, http.StatusInternalServerError, err)
@@ -161,7 +188,13 @@ func ExistsNetwork(w http.ResponseWriter, r *http.Request) {
// Prune removes unused networks
func Prune(w http.ResponseWriter, r *http.Request) {
+ if v, err := utils.SupportedVersion(r, ">=4.0.0"); err != nil {
+ utils.BadRequest(w, "version", v.String(), err)
+ return
+ }
+
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
+ ic := abi.ContainerEngine{Libpod: runtime}
filterMap, err := util.PrepareFilters(r)
if err != nil {
@@ -172,7 +205,6 @@ func Prune(w http.ResponseWriter, r *http.Request) {
pruneOptions := entities.NetworkPruneOptions{
Filters: *filterMap,
}
- ic := abi.ContainerEngine{Libpod: runtime}
pruneReports, err := ic.NetworkPrune(r.Context(), pruneOptions)
if err != nil {
utils.Error(w, http.StatusInternalServerError, err)
diff --git a/pkg/api/server/register_networks.go b/pkg/api/server/register_networks.go
index baa1fe6fb..4466c938f 100644
--- a/pkg/api/server/register_networks.go
+++ b/pkg/api/server/register_networks.go
@@ -320,6 +320,8 @@ func (s *APIServer) registerNetworkHandlers(r *mux.Router) error {
// $ref: "#/responses/NetworkCreateReport"
// 400:
// $ref: "#/responses/BadParamError"
+ // 409:
+ // $ref: "#/responses/ConflictError"
// 500:
// $ref: "#/responses/InternalError"
r.HandleFunc(VersionedPath("/libpod/networks/create"), s.APIHandler(libpod.CreateNetwork)).Methods(http.MethodPost)
diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go
index a363f2c6e..c508cb767 100644
--- a/pkg/bindings/images/build.go
+++ b/pkg/bindings/images/build.go
@@ -352,11 +352,13 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
}
c = tmpFile.Name()
}
+ c = filepath.Clean(c)
cfDir := filepath.Dir(c)
if absDir, err := filepath.EvalSymlinks(cfDir); err == nil {
name := filepath.ToSlash(strings.TrimPrefix(c, cfDir+string(filepath.Separator)))
c = filepath.Join(absDir, name)
}
+
containerfile, err := filepath.Abs(c)
if err != nil {
logrus.Errorf("Cannot find absolute path of %v: %v", c, err)
diff --git a/pkg/bindings/test/networks_test.go b/pkg/bindings/test/networks_test.go
index ee2d6f472..137db71a3 100644
--- a/pkg/bindings/test/networks_test.go
+++ b/pkg/bindings/test/networks_test.go
@@ -80,7 +80,7 @@ var _ = Describe("Podman networks", func() {
// Valid filter params => network should be pruned now.
filters = map[string][]string{
- "until": {"5000000000"}, //June 11, 2128
+ "until": {"5000000000"}, // June 11, 2128
}
pruneResponse, err = network.Prune(connText, new(network.PruneOptions).WithFilters(filters))
Expect(err).To(BeNil())
@@ -105,7 +105,7 @@ var _ = Describe("Podman networks", func() {
_, err = network.Create(connText, &net)
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
- Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
+ Expect(code).To(BeNumerically("==", http.StatusConflict))
})
It("inspect network", func() {
diff --git a/pkg/checkpoint/checkpoint_restore.go b/pkg/checkpoint/checkpoint_restore.go
index 1ebd6a455..270b5b6c4 100644
--- a/pkg/checkpoint/checkpoint_restore.go
+++ b/pkg/checkpoint/checkpoint_restore.go
@@ -140,6 +140,13 @@ func CRImportCheckpoint(ctx context.Context, runtime *libpod.Runtime, restoreOpt
return nil, errors.Errorf("pod %s does not share the network namespace", ctrConfig.Pod)
}
ctrConfig.NetNsCtr = infraContainer.ID()
+ for net, opts := range ctrConfig.Networks {
+ opts.StaticIPs = nil
+ opts.StaticMAC = nil
+ ctrConfig.Networks[net] = opts
+ }
+ ctrConfig.StaticIP = nil
+ ctrConfig.StaticMAC = nil
}
if ctrConfig.PIDNsCtr != "" {
diff --git a/pkg/machine/fcos.go b/pkg/machine/fcos.go
index 60ab471ee..4d3e2edf4 100644
--- a/pkg/machine/fcos.go
+++ b/pkg/machine/fcos.go
@@ -14,6 +14,7 @@ import (
"strings"
"github.com/coreos/stream-metadata-go/fedoracoreos"
+ "github.com/coreos/stream-metadata-go/release"
"github.com/coreos/stream-metadata-go/stream"
"github.com/pkg/errors"
@@ -28,6 +29,14 @@ var (
Format string = "qcow2.xz"
)
+const (
+ // Used for testing the latest podman in fcos
+ // special builds
+ podmanTesting = "podman-testing"
+ PodmanTestingHost = "fedorapeople.org"
+ PodmanTestingURL = "groups/podman/testing"
+)
+
type FcosDownload struct {
Download
}
@@ -111,14 +120,39 @@ func getFcosArch() string {
return arch
}
+// getStreamURL is a wrapper for the fcos.GetStream URL
+// so that we can inject a special stream and url for
+// testing podman before it merges into fcos builds
+func getStreamURL(streamType string) url2.URL {
+ // For the podmanTesting stream type, we point to
+ // a custom url on fedorapeople.org
+ if streamType == podmanTesting {
+ return url2.URL{
+ Scheme: "https",
+ Host: PodmanTestingHost,
+ Path: fmt.Sprintf("%s/%s.json", PodmanTestingURL, "podman4"),
+ }
+ }
+ return fedoracoreos.GetStreamURL(streamType)
+}
+
// This should get Exported and stay put as it will apply to all fcos downloads
// getFCOS parses fedoraCoreOS's stream and returns the image download URL and the release version
func getFCOSDownload(imageStream string) (*fcosDownloadInfo, error) {
var (
fcosstable stream.Stream
+ altMeta release.Release
streamType string
)
+
+ // This is being hard set to testing. Once podman4 is in the
+ // fcos trees, we should remove it and re-release at least on
+ // macs.
+ imageStream = "podman-testing"
+
switch imageStream {
+ case "podman-testing":
+ streamType = "podman-testing"
case "testing", "":
streamType = fedoracoreos.StreamTesting
case "next":
@@ -128,7 +162,7 @@ func getFCOSDownload(imageStream string) (*fcosDownloadInfo, error) {
default:
return nil, errors.Errorf("invalid stream %s: valid streams are `testing` and `stable`", imageStream)
}
- streamurl := fedoracoreos.GetStreamURL(streamType)
+ streamurl := getStreamURL(streamType)
resp, err := http.Get(streamurl.String())
if err != nil {
return nil, err
@@ -142,6 +176,27 @@ func getFCOSDownload(imageStream string) (*fcosDownloadInfo, error) {
logrus.Error(err)
}
}()
+ if imageStream == podmanTesting {
+ if err := json.Unmarshal(body, &altMeta); err != nil {
+ return nil, err
+ }
+
+ arches, ok := altMeta.Architectures[getFcosArch()]
+ if !ok {
+ return nil, fmt.Errorf("unable to pull VM image: no targetArch in stream")
+ }
+ qcow2, ok := arches.Media.Qemu.Artifacts["qcow2.xz"]
+ if !ok {
+ return nil, fmt.Errorf("unable to pull VM image: no qcow2.xz format in stream")
+ }
+ disk := qcow2.Disk
+
+ return &fcosDownloadInfo{
+ Location: disk.Location,
+ Sha256Sum: disk.Sha256,
+ CompressionType: "xz",
+ }, nil
+ }
if err := json.Unmarshal(body, &fcosstable); err != nil {
return nil, err