Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #5 from Luap99/cmdDel
Browse files Browse the repository at this point in the history
Do not error on del command and output version information
  • Loading branch information
rhatdan authored Sep 8, 2021
2 parents 4ae55f6 + fd05f77 commit e67f238
Show file tree
Hide file tree
Showing 366 changed files with 32 additions and 177,052 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ ifeq ($(GOBIN),)
GOBIN := $(FIRST_GOPATH)/bin
endif

COMMIT_NO ?= $(shell git rev-parse HEAD 2> /dev/null || true)
GIT_COMMIT ?= $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO})

LDFLAGS_MACHINE ?= -X main.gitCommit=$(GIT_COMMIT)

all: binaries

validate: install.tools gofmt .gitvalidation lint
Expand All @@ -34,7 +39,7 @@ gofmt:


binaries:
$(GO_BUILD) -o bin/podman-machine github.com/containers/podman-machine-cni/plugins/meta/podman-machine
$(GO_BUILD) -ldflags '$(LDFLAGS_MACHINE)' -o bin/podman-machine github.com/containers/podman-machine-cni/plugins/meta/podman-machine

.PHONY: .gitvalidation
.gitvalidation:
Expand Down
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ go 1.16

require (
github.com/containernetworking/cni v0.8.1
github.com/containernetworking/plugins v0.9.1
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
)
21 changes: 12 additions & 9 deletions plugins/meta/podman-machine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"os"
"strconv"

"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/cni/pkg/types"
"github.com/containernetworking/cni/pkg/version"
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
"github.com/pkg/errors"
)

func cmdAdd(args *skel.CmdArgs) error {
// Get the port information from the chained plugin
portMaps, err := parseConfig(args.StdinData, args.Args)
if err != nil {
return errors.Wrap(err, "failed to parse config")
return fmt.Errorf("failed to parse config: %w", err)
}

hostAddr, err := getPrimaryIP()
Expand Down Expand Up @@ -69,7 +69,8 @@ func cmdAdd(args *skel.CmdArgs) error {
func cmdDel(args *skel.CmdArgs) error {
portMaps, err := parseConfig(args.StdinData, args.Args)
if err != nil {
return errors.Wrap(err, "failed to parse config")
fmt.Fprintf(os.Stderr, "failed to parse config: %v", err)
return nil
}
// No portmappings, do nothing
if len(portMaps.RuntimeConfig.PortMaps) < 1 {
Expand All @@ -79,18 +80,20 @@ func cmdDel(args *skel.CmdArgs) error {
hostPort := strconv.Itoa(pm.HostPort)
u, err := url.Parse(fmt.Sprintf("http://%s:%s/services/forwarder/unexpose", apiEndpoint, apiEndpointPort))
if err != nil {
return err
fmt.Fprintf(os.Stderr, "failed to parse url: %v", err)
return nil
}
unexpose := Unexpose{Local: fmt.Sprintf("0.0.0.0:%s", hostPort)}
if err := postRequest(context.Background(), u, unexpose); err != nil {
return err
fmt.Fprint(os.Stderr, err)
return nil
}
}
return nil
}

func main() {
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("machine"))
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, getVersion())
}

func cmdCheck(args *skel.CmdArgs) error {
Expand All @@ -117,12 +120,12 @@ func cmdCheck(args *skel.CmdArgs) error {
func parseConfig(stdin []byte, args string) (*PortMapConf, error) {
conf := PortMapConf{}
if err := json.Unmarshal(stdin, &conf); err != nil {
return nil, fmt.Errorf("failed to parse network configuration: %v", err)
return nil, fmt.Errorf("failed to parse network configuration: %w", err)
}
// Parse previous result.
if conf.RawPrevResult != nil {
if err := version.ParsePrevResult(&conf.NetConf); err != nil {
return nil, errors.Wrap(err, "could not parse prevResult")
return nil, fmt.Errorf("could not parse prevResult: %w", err)
}
}
return &conf, nil
Expand Down
14 changes: 14 additions & 0 deletions plugins/meta/podman-machine/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import "fmt"

// overwritten at build time
var gitCommit = "unknown"

const machineVersion = "0.1.0-dev"

func getVersion() string {
return fmt.Sprintf(`CNI podman-machine plugin
version: %s
commit: %s`, machineVersion, gitCommit)
}
201 changes: 0 additions & 201 deletions vendor/github.com/containernetworking/plugins/LICENSE

This file was deleted.

This file was deleted.

24 changes: 0 additions & 24 deletions vendor/github.com/pkg/errors/.gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions vendor/github.com/pkg/errors/.travis.yml

This file was deleted.

Loading

0 comments on commit e67f238

Please sign in to comment.