Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Davanum Srinivas <[email protected]>
  • Loading branch information
dims committed May 12, 2020
0 parents commit 3290752
Show file tree
Hide file tree
Showing 8 changed files with 1,399 additions and 0 deletions.
46 changes: 46 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module github.com/dims/cri-dockerd

go 1.14

require (
github.com/evanphx/json-patch v4.5.0+incompatible // indirect
github.com/googleapis/gnostic v0.3.1 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/onsi/ginkgo v1.12.0 // indirect
github.com/onsi/gomega v1.8.1 // indirect
github.com/opencontainers/runc v1.0.0-rc9 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.4.0 // indirect
github.com/spf13/cobra v0.0.6
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.5.1 // indirect
k8s.io/apimachinery v0.18.2
k8s.io/apiserver v0.18.2
k8s.io/component-base v0.18.2
k8s.io/klog v1.0.0
k8s.io/kubernetes v1.18.2
)

replace (
k8s.io/api => k8s.io/api v0.18.2
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.18.2
k8s.io/apimachinery => k8s.io/apimachinery v0.18.2
k8s.io/apiserver => k8s.io/apiserver v0.18.2
k8s.io/cli-runtime => k8s.io/cli-runtime v0.18.2
k8s.io/client-go => k8s.io/client-go v0.18.2
k8s.io/cloud-provider => k8s.io/cloud-provider v0.18.2
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.18.2
k8s.io/code-generator => k8s.io/code-generator v0.18.2
k8s.io/component-base => k8s.io/component-base v0.18.2
k8s.io/cri-api => k8s.io/cri-api v0.18.2
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.18.2
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.18.2
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.18.2
k8s.io/kube-proxy => k8s.io/kube-proxy v0.18.2
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.18.2
k8s.io/kubectl => k8s.io/kubectl v0.18.2
k8s.io/kubelet => k8s.io/kubelet v0.18.2
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.18.2
k8s.io/metrics => k8s.io/metrics v0.18.2
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.18.2
)
889 changes: 889 additions & 0 deletions go.sum

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2014 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"fmt"
"math/rand"
"os"
"time"

"github.com/dims/cri-dockerd/pkg/app"
"k8s.io/apiserver/pkg/server"
"k8s.io/component-base/logs"
)

func main() {
rand.Seed(time.Now().UnixNano())

command := app.NewDockerCRICommand(server.SetupSignalHandler())
logs.InitLogs()
defer logs.FlushLogs()

if err := command.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
68 changes: 68 additions & 0 deletions pkg/app/config/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package config

import (
"fmt"

"github.com/spf13/pflag"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ContainerRuntimeOptions contains runtime options
type ContainerRuntimeOptions struct {
// General options.

//// driver that the kubelet uses to manipulate cgroups on the host (cgroupfs or systemd)
CgroupDriver string
// RuntimeCgroups that container runtime is expected to be isolated in.
RuntimeCgroups string

// Docker-specific options.

// DockershimRootDirectory is the path to the dockershim root directory. Defaults to
// /var/lib/dockershim if unset. Exposed for integration testing (e.g. in OpenShift).
DockershimRootDirectory string
// PodSandboxImage is the image whose network/ipc namespaces
// containers in each pod will use.
PodSandboxImage string
// DockerEndpoint is the path to the docker endpoint to communicate with.
DockerEndpoint string
// If no pulling progress is made before the deadline imagePullProgressDeadline,
// the image pulling will be cancelled. Defaults to 1m0s.
// +optional
ImagePullProgressDeadline metav1.Duration
// runtimeRequestTimeout is the timeout for all runtime requests except long running
// requests - pull, logs, exec and attach.
RuntimeRequestTimeout metav1.Duration
// streamingConnectionIdleTimeout is the maximum time a streaming connection
// can be idle before the connection is automatically closed.
StreamingConnectionIdleTimeout metav1.Duration
}

// AddFlags has the set of flags needed by cri-dockerd
func (s *ContainerRuntimeOptions) AddFlags(fs *pflag.FlagSet) {
// General settings.
fs.StringVar(&s.RuntimeCgroups, "runtime-cgroups", s.RuntimeCgroups, "Optional absolute name of cgroups to create and run the runtime in.")

// Docker-specific settings.
fs.StringVar(&s.DockershimRootDirectory, "dockershim-root-directory", s.DockershimRootDirectory, "Path to the dockershim root directory.")
fs.StringVar(&s.PodSandboxImage, "pod-infra-container-image", s.PodSandboxImage, fmt.Sprintf("The image whose network/ipc namespaces containers in each pod will use"))
fs.StringVar(&s.DockerEndpoint, "docker-endpoint", s.DockerEndpoint, fmt.Sprintf("Use this for the docker endpoint to communicate with."))
fs.DurationVar(&s.ImagePullProgressDeadline.Duration, "image-pull-progress-deadline", s.ImagePullProgressDeadline.Duration, fmt.Sprintf("If no pulling progress is made before this deadline, the image pulling will be cancelled."))
}
53 changes: 53 additions & 0 deletions pkg/app/options/container_runtime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package options

import (
"runtime"
"time"

"github.com/dims/cri-dockerd/pkg/app/config"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// When these values are updated, also update test/e2e/framework/util.go
defaultPodSandboxImageName = "k8s.gcr.io/pause"
defaultPodSandboxImageVersion = "3.1"
)

var (
dockerContainerRuntime = "docker"
defaultPodSandboxImage = defaultPodSandboxImageName +
":" + defaultPodSandboxImageVersion
)

// NewContainerRuntimeOptions will create a new ContainerRuntimeOptions with
// default values.
func NewContainerRuntimeOptions() *config.ContainerRuntimeOptions {
dockerEndpoint := ""
if runtime.GOOS != "windows" {
dockerEndpoint = "unix:///var/run/docker.sock"
}

return &config.ContainerRuntimeOptions{
DockerEndpoint: dockerEndpoint,
DockershimRootDirectory: "/var/lib/dockershim",
PodSandboxImage: defaultPodSandboxImage,
ImagePullProgressDeadline: metav1.Duration{Duration: 1 * time.Minute},
}
}
74 changes: 74 additions & 0 deletions pkg/app/options/globalflags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package options

import (
"flag"
"fmt"
"os"
"strings"

"github.com/spf13/pflag"

// 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
// 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)
}

// normalize replaces underscores with hyphens
// we should always use hyphens instead of underscores when registering cri-dockerd flags
func normalize(s string) string {
return strings.Replace(s, "_", "-", -1)
}

// register adds a flag to local that targets the Value associated with the Flag named globalName in global
func register(global *flag.FlagSet, local *pflag.FlagSet, globalName string) {
if f := global.Lookup(globalName); f != nil {
pflagFlag := pflag.PFlagFromGoFlag(f)
pflagFlag.Name = normalize(pflagFlag.Name)
local.AddFlag(pflagFlag)
} else {
panic(fmt.Sprintf("failed to find flag in global flagset (flag): %s", globalName))
}
}

// addGlogFlags adds flags from k8s.io/klog
func addGlogFlags(fs *pflag.FlagSet) {
// lookup flags in global flag set and re-register the values with our flagset
global := flag.CommandLine
local := pflag.NewFlagSet(os.Args[0], pflag.ExitOnError)

register(global, local, "logtostderr")
register(global, local, "alsologtostderr")
register(global, local, "v")
register(global, local, "stderrthreshold")
register(global, local, "vmodule")
register(global, local, "log_backtrace_at")
register(global, local, "log_dir")
register(global, local, "log_file")

fs.AddFlagSet(local)
}
82 changes: 82 additions & 0 deletions pkg/app/options/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Copyright 2015 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package options contains all of the primary arguments for cri-dockerd.
package options

import (
"runtime"

"github.com/dims/cri-dockerd/pkg/app/config"

"github.com/spf13/pflag"
)

// DockerCRIFlags contains configuration flags for the cri-dockerd.
type DockerCRIFlags struct {
// Container-runtime-specific options.
config.ContainerRuntimeOptions
// remoteRuntimeEndpoint is the endpoint of remote runtime service
RemoteRuntimeEndpoint string
// nonMasqueradeCIDR configures masquerading: traffic to IPs outside this range will use IP masquerade.
NonMasqueradeCIDR string
}

// NewDockerCRIFlags will create a new DockerCRIFlags with default values
func NewDockerCRIFlags() *DockerCRIFlags {
remoteRuntimeEndpoint := ""
if runtime.GOOS == "linux" {
remoteRuntimeEndpoint = "unix:///var/run/dockershim.sock"
} else if runtime.GOOS == "windows" {
remoteRuntimeEndpoint = "npipe:////./pipe/dockershim"
}

return &DockerCRIFlags{
ContainerRuntimeOptions: *NewContainerRuntimeOptions(),
NonMasqueradeCIDR: "10.0.0.0/8",
RemoteRuntimeEndpoint: remoteRuntimeEndpoint,
}
}

// DockerCRIServer encapsulates all of the parameters necessary for starting up
// a kubelet. These can either be set via command line or directly.
type DockerCRIServer struct {
DockerCRIFlags
}

// AddFlags adds flags for a specific DockerCRIServer to the specified FlagSet
func (s *DockerCRIServer) AddFlags(fs *pflag.FlagSet) {
s.DockerCRIFlags.AddFlags(fs)
}

// AddFlags adds flags for a specific DockerCRIFlags to the specified FlagSet
func (f *DockerCRIFlags) AddFlags(mainfs *pflag.FlagSet) {
fs := pflag.NewFlagSet("", pflag.ExitOnError)
defer func() {
// Unhide deprecated flags. We want deprecated flags to show in cri-dockerd's help.
// We have some hidden flags, but we might as well unhide these when they are deprecated,
// as silently deprecating and removing (even hidden) things is unkind to people who use them.
fs.VisitAll(func(f *pflag.Flag) {
if len(f.Deprecated) > 0 {
f.Hidden = false
}
})
mainfs.AddFlagSet(fs)
}()

f.ContainerRuntimeOptions.AddFlags(fs)
fs.StringVar(&f.RemoteRuntimeEndpoint, "container-runtime-endpoint", f.RemoteRuntimeEndpoint, "The endpoint of remote runtime service. Currently unix socket and tcp endpoints are supported on Linux, while npipe and tcp endpoints are supported on windows. Examples:'unix:///var/run/dockershim.sock', 'npipe:////./pipe/dockershim'")
}
Loading

0 comments on commit 3290752

Please sign in to comment.