Skip to content

Commit

Permalink
Fix version output, fix Ubuntu packaging, fix systemd socket file
Browse files Browse the repository at this point in the history
  • Loading branch information
evol262 committed Sep 17, 2021
1 parent bd23391 commit ff32653
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 34 deletions.
16 changes: 15 additions & 1 deletion dockershim/remote/docker_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ package remote

import (
"fmt"
"net"
"os"
"strings"

"google.golang.org/grpc"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
Expand Down Expand Up @@ -51,6 +53,18 @@ func NewDockerServer(endpoint string, s dockershim.CRIService) *DockerServer {
}
}

func getListener(addr string) (net.Listener, error) {
addrSlice := strings.SplitN(addr, "://", 2)
proto := addrSlice[0]
listenAddr := addrSlice[1]
switch proto {
case "fd":
return listenFd(listenAddr)
default:
return util.CreateListener(addr)
}
}

// Start starts the dockershim grpc server.
func (s *DockerServer) Start() error {
// Start the internal service.
Expand All @@ -60,7 +74,7 @@ func (s *DockerServer) Start() error {
}

klog.V(2).InfoS("Start dockershim grpc server")
l, err := util.CreateListener(s.endpoint)
l, err := getListener(s.endpoint)
if err != nil {
return fmt.Errorf("failed to listen on %q: %v", s.endpoint, err)
}
Expand Down
33 changes: 33 additions & 0 deletions dockershim/remote/docker_server_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// +build !dockerless !windows

package remote

import (
"net"

"github.com/coreos/go-systemd/v22/activation"
"github.com/pkg/errors"
)

func listenFd(addr string) (net.Listener, error) {
var (
err error
listeners []net.Listener
)

listeners, err = activation.Listeners()
if err != nil {
return nil, err
}

if len(listeners) == 0 {
return nil, errors.New("no sockets found via socket activation: make sure the service was started by systemd")
}

if addr == "" {
return listeners[0], nil
}

//TODO: systemd fd selection (default is 3)
return nil, errors.New("not supported yet")
}
13 changes: 13 additions & 0 deletions dockershim/remote/docker_server_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build !dockerless windows

package server

import (
"net"

"github.com/pkg/errors"
)

func listenFd(addr string) (net.Listener, error) {
return nil, errors.New("listening on a file descriptor is not supported on Windows")
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.14
require (
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e
github.com/blang/semver v3.5.1+incompatible
github.com/coreos/go-systemd/v22 v22.1.0
github.com/docker/docker v17.12.0-ce-rc1.0.20200916142827-bd33bbf0497b+incompatible
github.com/docker/go-connections v0.4.0
github.com/imdario/mergo v0.3.7 // indirect
Expand Down
2 changes: 1 addition & 1 deletion packaging/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include common.mk

APP_DIR:=$(realpath $(CURDIR)/../app)
APP_DIR:=$(realpath $(CURDIR)/../)
STATIC_VERSION:=$(shell static/gen-static-ver $(VERSION))

# Taken from: https://www.cmcrossroads.com/article/printing-value-makefile-variable
Expand Down
4 changes: 2 additions & 2 deletions packaging/common.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ARCH=$(shell uname -m)
BUILDTIME=$(shell date -u -d "@$${SOURCE_DATE_EPOCH:-$$(date +%s)}" --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')
GO_VERSION:=1.13.11
PLATFORM=Docker Engine - Community
PLATFORM=cri-dockerd
SHELL:=/bin/bash
VERSION?=0.1.0
VERSION?=0.1.0-dev

export BUILDTIME
export PLATFORM
6 changes: 3 additions & 3 deletions packaging/deb/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
include ../common.mk

APP_DIR:=$(realpath $(CURDIR)/../../cli)
APP_DIR:=$(realpath $(CURDIR)/../../)
GITCOMMIT?=$(shell cd $(APP_DIR) && git rev-parse --short HEAD)
STATIC_VERSION:=$(shell ../static/gen-static-ver $(APP_DIR) $(VERSION))
GO_BASE_IMAGE=golang
GO_IMAGE=$(GO_BASE_IMAGE):$(GO_VERSION)-stretch
DEB_VERSION=$(shell ./gen-deb-ver $(APP_DIR) "$(VERSION)")
CHOWN:=docker run --rm -v $(CURDIR):/v -w /v alpine chown
EPOCH?=5
EPOCH?=0

ifdef BUILD_IMAGE
BUILD_IMAGE_FLAG=--build-arg BUILD_IMAGE=$(BUILD_IMAGE)
Expand All @@ -27,7 +27,7 @@ RUN=docker run --rm -i \
-e EPOCH='$(EPOCH)' \
-e DEB_VERSION=$(word 1, $(DEB_VERSION)) \
-e VERSION=$(word 2, $(DEB_VERSION)) \
-e GITCOMMIT=$(ITCOMMIT) \
-e GITCOMMIT=$(GITCOMMIT) \
-e PLATFORM \
-v $(CURDIR)/debbuild/$@:/build \
$(RUN_FLAGS) \
Expand Down
11 changes: 5 additions & 6 deletions packaging/deb/common/control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Source: cri-docker
Section: admin
Priority: optional
Maintainer: Docker <support@docker.com>
Maintainer: Mirantis <support@mirantis.com>
Build-Depends: bash,
bash-completion,
libbtrfs-dev | btrfs-tools,
Expand All @@ -21,9 +21,9 @@ Build-Depends: bash,
make,
pkg-config
Standards-Version: 3.9.6
Homepage: https://www.docker.com
Vcs-Browser: https://github.com/docker/docker
Vcs-Git: git://github.com/docker/docker.git
Homepage: https://www.mirantis.com
Vcs-Browser: https://github.com/Mirantis/cri-dockerd
Vcs-Git: git://github.com/Mirantis/cri-dockerd.git

Package: cri-docker
Architecture: linux-any
Expand All @@ -36,5 +36,4 @@ Recommends: aufs-tools [amd64],
xz-utils,
libltdl7,
${apparmor:Recommends}
Description: Docker: the open-source application container engine
cri-docker is a lightweight implementation of the CRI specification which talks to docker.
Description: cri-docker is a lightweight implementation of the CRI specification which talks to docker.
2 changes: 1 addition & 1 deletion packaging/deb/gen-deb-ver
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ if [[ "$VERSION" == *-dev ]]; then
gitUnix="$($GIT_COMMAND log -1 --pretty='%ct')"
gitDate="$($DATE_COMMAND --utc --date "@$gitUnix" +'%Y%m%d%H%M%S')"
gitCommit="$($GIT_COMMAND log -1 --pretty='%h')"
debVersion="0.0.0-${gitDate}-${gitCommit}"
debVersion="${VERSION/-dev/}-${gitDate}-${gitCommit}"
origVersion=$debVersion
fi

Expand Down
2 changes: 1 addition & 1 deletion packaging/rpm/gen-rpm-ver
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if [[ "$rpmVersion" == *-dev ]] || [ -n "$($GIT_COMMAND status --porcelain)" ];
gitDate="$($DATE_COMMAND --utc --date "@$gitUnix" +'%Y%m%d%H%M%S')"
gitCommit="$($GIT_COMMAND log -1 --pretty='%h')"
# rpmVersion is now something like '0.0.0-20180719213702-cd5e2db'
rpmVersion="0.0.0-${gitDate}-${gitCommit}"
rpmVersion="${VERSION/-dev/}-${gitDate}-${gitCommit}"
rpmRelease="0"
origVersion=$rpmVersion
fi
Expand Down
4 changes: 2 additions & 2 deletions packaging/static/gen-static-ver
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ APP_DIR=$1
VERSION=$2

if [ -z "$APP_DIR" ] || [ -z "$VERSION" ]; then
echo 'usage: ./gen-static-ver ${ENGINE_DIR} ${VERSION}'
echo 'usage: ./gen-static-ver ${APP_DIR} ${VERSION}'
exit 1
fi

Expand All @@ -29,7 +29,7 @@ if [[ "$VERSION" == *-dev ]]; then
gitDate="$($DATE_COMMAND --utc --date "@$gitUnix" +'%Y%m%d%H%M%S')"
gitCommit="$($GIT_COMMAND log -1 --pretty='%h')"
# staticVersion is now something like '0.0.0-20180719213702-cd5e2db'
staticVersion="0.0.0-${gitDate}-${gitCommit}"
staticVersion="${VERSION/-dev/}-${gitDate}-${gitCommit}"
fi

echo "$staticVersion"
2 changes: 1 addition & 1 deletion packaging/systemd/cri-docker.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Requires=cri-docker.socket

[Service]
Type=notify
ExecStart=/usr/bin/cri-dockerd --v=10 --networkplugin="" --logtostderr
ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd:// --v=10 --networkplugin="" --logtostderr
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Expand Down
2 changes: 1 addition & 1 deletion packaging/systemd/cri-docker.socket
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Description=CRI Docker Socket for the API
PartOf=cri-docker.service

[Socket]
ListenStream=/var/run/cri-docker.sock
ListenStream=$t/cri-docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
Expand Down
4 changes: 1 addition & 3 deletions pkg/app/options/globalflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ import (

// libs that provide registration functions
"k8s.io/component-base/logs"
"k8s.io/component-base/version/verflag"
)

// AddGlobalFlags explicitly registers flags that libraries (glog, verflag, etc.) register
// AddGlobalFlags explicitly registers flags that libraries (glog, etc.) register
// against the global flagsets from "flag" and "github.com/spf13/pflag".
// We do this in order to prevent unwanted flags from leaking into the cri-dockerd's flagset.
func AddGlobalFlags(fs *pflag.FlagSet) {
addGlogFlags(fs)
verflag.AddFlags(fs)
logs.AddFlags(fs)
}

Expand Down
29 changes: 17 additions & 12 deletions pkg/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ package app

import (
"fmt"
"net/url"
"github.com/Mirantis/cri-dockerd/dockershim"
dockerremote "github.com/Mirantis/cri-dockerd/dockershim/remote"
"github.com/Mirantis/cri-dockerd/pkg/app/options"
"github.com/Mirantis/cri-dockerd/version"
"k8s.io/component-base/cli/flag"
"k8s.io/component-base/version/verflag"
utilflag "k8s.io/component-base/cli/flag"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
"k8s.io/klog"
"github.com/Mirantis/cri-dockerd/dockershim"
dockerremote "github.com/Mirantis/cri-dockerd/dockershim/remote"
"k8s.io/kubernetes/pkg/kubelet/cri/streaming"
utilflag "k8s.io/component-base/cli/flag"
"net/url"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

const (
componentDockerCRI = "DockerCRI"
componentDockerCRI = "cri-dockerd"
)

// NewDockerCRICommand creates a *cobra.Command object with default parameters
Expand Down Expand Up @@ -75,8 +75,13 @@ func NewDockerCRICommand(stopCh <-chan struct{}) *cobra.Command {
return
}

verflag, _ := cleanFlagSet.GetBool("version")
if verflag {
fmt.Fprintf(cmd.OutOrStderr(), "%s %s\n", version.PlatformName, version.FullVersion())
return
}

// short-circuit on verflag
verflag.PrintAndExitIfRequested()
utilflag.PrintFlags(cleanFlagSet)

if err := RunDockershim(kubeletFlags, stopCh); err != nil {
Expand All @@ -89,6 +94,7 @@ func NewDockerCRICommand(stopCh <-chan struct{}) *cobra.Command {
kubeletFlags.AddFlags(cleanFlagSet)
options.AddGlobalFlags(cleanFlagSet)
cleanFlagSet.BoolP("help", "h", false, fmt.Sprintf("help for %s", cmd.Name()))
cleanFlagSet.Bool("version", false, "prints the version of cri-dockerd")

// ugly, but necessary, because Cobra's default UsageFunc and HelpFunc pollute the flagset with global flags
const usageFmt = "Usage:\n %s\n\nFlags:\n%s"
Expand All @@ -99,7 +105,6 @@ func NewDockerCRICommand(stopCh <-chan struct{}) *cobra.Command {
cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
fmt.Fprintf(cmd.OutOrStdout(), "%s\n\n"+usageFmt, cmd.Long, cmd.UseLine(), cleanFlagSet.FlagUsagesWrapped(2))
})

return cmd
}

Expand All @@ -116,13 +121,13 @@ func RunDockershim(f *options.DockerCRIFlags, stopCh <-chan struct{}) error {

// Initialize network plugin settings.
pluginSettings := dockershim.NetworkPluginSettings{
HairpinMode: "none",
HairpinMode: "none",
PluginName: f.NetworkPluginName,
PluginConfDir: f.CNIConfDir,
PluginBinDirString: f.CNIBinDir,
PluginCacheDir: f.CNICacheDir,
MTU: int(f.NetworkPluginMTU),
NonMasqueradeCIDR: f.NonMasqueradeCIDR,
NonMasqueradeCIDR: f.NonMasqueradeCIDR,
}

// Initialize streaming configuration. (Not using TLS now)
Expand All @@ -144,11 +149,11 @@ func RunDockershim(f *options.DockerCRIFlags, stopCh <-chan struct{}) error {

if _, err := ds.UpdateRuntimeConfig(nil, &runtimeapi.UpdateRuntimeConfigRequest{
RuntimeConfig: &runtimeapi.RuntimeConfig{
NetworkConfig: &runtimeapi.NetworkConfig {
NetworkConfig: &runtimeapi.NetworkConfig{
PodCidr: f.PodCIDR,
},
},
}) ; err != nil {
}); err != nil {
return err
}

Expand Down
33 changes: 33 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package version

var (
// Version of the product
Version = "0.1.0"
// PreRelease is set during the build
PreRelease = ""
// GitCommit is set during the build
GitCommit = "HEAD"
// BuildTime is set during the build
BuildTime = "<unknown>"
)

const (
// PlatformName of the product
PlatformName = "cri-dockerd"
)

// FullVersion returns the formatted "$Version[-$PreRelease] ($GitCommit)"
func FullVersion() string {
if PreRelease != "" {
return Version + "-" + PreRelease + " (" + GitCommit + ")"
}
return Version + " (" + GitCommit + ")"
}

// TagVersion returns "$Version[-$PreRelease]" without the git commit
func TagVersion() string {
if PreRelease != "" {
return Version + "-" + PreRelease
}
return Version
}

0 comments on commit ff32653

Please sign in to comment.