Build and install from GOPATH
* Rename 'vendor/src' -> 'vendor' * Ignore vendor/ instead of vendor/src/ for lint * Rename 'cmd/client' -> 'cmd/ocic' to make it 'go install'able * Rename 'cmd/server' -> 'cmd/ocid' to make it 'go install'able * Update Makefile to build and install from GOPATH * Update tests to locate ocid/ocic in GOPATH/bin * Search for binaries in GOPATH/bin instead of PATH * Install tools using `go get -u`, so they are updated on each run Signed-off-by: Jonathan Yu <jawnsy@redhat.com>
This commit is contained in:
parent
9da2882d49
commit
6c9628cdb1
1111 changed files with 70 additions and 61 deletions
44
vendor/k8s.io/kubernetes/pkg/fields/BUILD
generated
vendored
Normal file
44
vendor/k8s.io/kubernetes/pkg/fields/BUILD
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"fields.go",
|
||||
"requirements.go",
|
||||
"selector.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
deps = ["//vendor:k8s.io/apimachinery/pkg/selection"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"fields_test.go",
|
||||
"selector_test.go",
|
||||
],
|
||||
library = ":go_default_library",
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
19
vendor/k8s.io/kubernetes/pkg/fields/doc.go
generated
vendored
Normal file
19
vendor/k8s.io/kubernetes/pkg/fields/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
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 fields implements a simple field system, parsing and matching
|
||||
// selectors with sets of fields.
|
||||
package fields // import "k8s.io/kubernetes/pkg/fields"
|
62
vendor/k8s.io/kubernetes/pkg/fields/fields.go
generated
vendored
Normal file
62
vendor/k8s.io/kubernetes/pkg/fields/fields.go
generated
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
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 fields
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Fields allows you to present fields independently from their storage.
|
||||
type Fields interface {
|
||||
// Has returns whether the provided field exists.
|
||||
Has(field string) (exists bool)
|
||||
|
||||
// Get returns the value for the provided field.
|
||||
Get(field string) (value string)
|
||||
}
|
||||
|
||||
// Set is a map of field:value. It implements Fields.
|
||||
type Set map[string]string
|
||||
|
||||
// String returns all fields listed as a human readable string.
|
||||
// Conveniently, exactly the format that ParseSelector takes.
|
||||
func (ls Set) String() string {
|
||||
selector := make([]string, 0, len(ls))
|
||||
for key, value := range ls {
|
||||
selector = append(selector, key+"="+value)
|
||||
}
|
||||
// Sort for determinism.
|
||||
sort.StringSlice(selector).Sort()
|
||||
return strings.Join(selector, ",")
|
||||
}
|
||||
|
||||
// Has returns whether the provided field exists in the map.
|
||||
func (ls Set) Has(field string) bool {
|
||||
_, exists := ls[field]
|
||||
return exists
|
||||
}
|
||||
|
||||
// Get returns the value in the map for the provided field.
|
||||
func (ls Set) Get(field string) string {
|
||||
return ls[field]
|
||||
}
|
||||
|
||||
// AsSelector converts fields into a selectors.
|
||||
func (ls Set) AsSelector() Selector {
|
||||
return SelectorFromSet(ls)
|
||||
}
|
30
vendor/k8s.io/kubernetes/pkg/fields/requirements.go
generated
vendored
Normal file
30
vendor/k8s.io/kubernetes/pkg/fields/requirements.go
generated
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Copyright 2016 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 fields
|
||||
|
||||
import "k8s.io/apimachinery/pkg/selection"
|
||||
|
||||
// Requirements is AND of all requirements.
|
||||
type Requirements []Requirement
|
||||
|
||||
// Requirement contains a field, a value, and an operator that relates the field and value.
|
||||
// This is currently for reading internal selection information of field selector.
|
||||
type Requirement struct {
|
||||
Operator selection.Operator
|
||||
Field string
|
||||
Value string
|
||||
}
|
278
vendor/k8s.io/kubernetes/pkg/fields/selector.go
generated
vendored
Normal file
278
vendor/k8s.io/kubernetes/pkg/fields/selector.go
generated
vendored
Normal file
|
@ -0,0 +1,278 @@
|
|||
/*
|
||||
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 fields
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/selection"
|
||||
)
|
||||
|
||||
// Selector represents a field selector.
|
||||
type Selector interface {
|
||||
// Matches returns true if this selector matches the given set of fields.
|
||||
Matches(Fields) bool
|
||||
|
||||
// Empty returns true if this selector does not restrict the selection space.
|
||||
Empty() bool
|
||||
|
||||
// RequiresExactMatch allows a caller to introspect whether a given selector
|
||||
// requires a single specific field to be set, and if so returns the value it
|
||||
// requires.
|
||||
RequiresExactMatch(field string) (value string, found bool)
|
||||
|
||||
// Transform returns a new copy of the selector after TransformFunc has been
|
||||
// applied to the entire selector, or an error if fn returns an error.
|
||||
Transform(fn TransformFunc) (Selector, error)
|
||||
|
||||
// Requirements converts this interface to Requirements to expose
|
||||
// more detailed selection information.
|
||||
Requirements() Requirements
|
||||
|
||||
// String returns a human readable string that represents this selector.
|
||||
String() string
|
||||
}
|
||||
|
||||
// Everything returns a selector that matches all fields.
|
||||
func Everything() Selector {
|
||||
return andTerm{}
|
||||
}
|
||||
|
||||
type hasTerm struct {
|
||||
field, value string
|
||||
}
|
||||
|
||||
func (t *hasTerm) Matches(ls Fields) bool {
|
||||
return ls.Get(t.field) == t.value
|
||||
}
|
||||
|
||||
func (t *hasTerm) Empty() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *hasTerm) RequiresExactMatch(field string) (value string, found bool) {
|
||||
if t.field == field {
|
||||
return t.value, true
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func (t *hasTerm) Transform(fn TransformFunc) (Selector, error) {
|
||||
field, value, err := fn(t.field, t.value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &hasTerm{field, value}, nil
|
||||
}
|
||||
|
||||
func (t *hasTerm) Requirements() Requirements {
|
||||
return []Requirement{{
|
||||
Field: t.field,
|
||||
Operator: selection.Equals,
|
||||
Value: t.value,
|
||||
}}
|
||||
}
|
||||
|
||||
func (t *hasTerm) String() string {
|
||||
return fmt.Sprintf("%v=%v", t.field, t.value)
|
||||
}
|
||||
|
||||
type notHasTerm struct {
|
||||
field, value string
|
||||
}
|
||||
|
||||
func (t *notHasTerm) Matches(ls Fields) bool {
|
||||
return ls.Get(t.field) != t.value
|
||||
}
|
||||
|
||||
func (t *notHasTerm) Empty() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *notHasTerm) RequiresExactMatch(field string) (value string, found bool) {
|
||||
return "", false
|
||||
}
|
||||
|
||||
func (t *notHasTerm) Transform(fn TransformFunc) (Selector, error) {
|
||||
field, value, err := fn(t.field, t.value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ¬HasTerm{field, value}, nil
|
||||
}
|
||||
|
||||
func (t *notHasTerm) Requirements() Requirements {
|
||||
return []Requirement{{
|
||||
Field: t.field,
|
||||
Operator: selection.NotEquals,
|
||||
Value: t.value,
|
||||
}}
|
||||
}
|
||||
|
||||
func (t *notHasTerm) String() string {
|
||||
return fmt.Sprintf("%v!=%v", t.field, t.value)
|
||||
}
|
||||
|
||||
type andTerm []Selector
|
||||
|
||||
func (t andTerm) Matches(ls Fields) bool {
|
||||
for _, q := range t {
|
||||
if !q.Matches(ls) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (t andTerm) Empty() bool {
|
||||
if t == nil {
|
||||
return true
|
||||
}
|
||||
if len([]Selector(t)) == 0 {
|
||||
return true
|
||||
}
|
||||
for i := range t {
|
||||
if !t[i].Empty() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (t andTerm) RequiresExactMatch(field string) (string, bool) {
|
||||
if t == nil || len([]Selector(t)) == 0 {
|
||||
return "", false
|
||||
}
|
||||
for i := range t {
|
||||
if value, found := t[i].RequiresExactMatch(field); found {
|
||||
return value, found
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func (t andTerm) Transform(fn TransformFunc) (Selector, error) {
|
||||
next := make([]Selector, len([]Selector(t)))
|
||||
for i, s := range []Selector(t) {
|
||||
n, err := s.Transform(fn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
next[i] = n
|
||||
}
|
||||
return andTerm(next), nil
|
||||
}
|
||||
|
||||
func (t andTerm) Requirements() Requirements {
|
||||
reqs := make([]Requirement, 0, len(t))
|
||||
for _, s := range []Selector(t) {
|
||||
rs := s.Requirements()
|
||||
reqs = append(reqs, rs...)
|
||||
}
|
||||
return reqs
|
||||
}
|
||||
|
||||
func (t andTerm) String() string {
|
||||
var terms []string
|
||||
for _, q := range t {
|
||||
terms = append(terms, q.String())
|
||||
}
|
||||
return strings.Join(terms, ",")
|
||||
}
|
||||
|
||||
// SelectorFromSet returns a Selector which will match exactly the given Set. A
|
||||
// nil Set is considered equivalent to Everything().
|
||||
func SelectorFromSet(ls Set) Selector {
|
||||
if ls == nil {
|
||||
return Everything()
|
||||
}
|
||||
items := make([]Selector, 0, len(ls))
|
||||
for field, value := range ls {
|
||||
items = append(items, &hasTerm{field: field, value: value})
|
||||
}
|
||||
if len(items) == 1 {
|
||||
return items[0]
|
||||
}
|
||||
return andTerm(items)
|
||||
}
|
||||
|
||||
// ParseSelectorOrDie takes a string representing a selector and returns an
|
||||
// object suitable for matching, or panic when an error occur.
|
||||
func ParseSelectorOrDie(s string) Selector {
|
||||
selector, err := ParseSelector(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// ParseSelector takes a string representing a selector and returns an
|
||||
// object suitable for matching, or an error.
|
||||
func ParseSelector(selector string) (Selector, error) {
|
||||
return parseSelector(selector,
|
||||
func(lhs, rhs string) (newLhs, newRhs string, err error) {
|
||||
return lhs, rhs, nil
|
||||
})
|
||||
}
|
||||
|
||||
// Parses the selector and runs them through the given TransformFunc.
|
||||
func ParseAndTransformSelector(selector string, fn TransformFunc) (Selector, error) {
|
||||
return parseSelector(selector, fn)
|
||||
}
|
||||
|
||||
// Function to transform selectors.
|
||||
type TransformFunc func(field, value string) (newField, newValue string, err error)
|
||||
|
||||
func try(selectorPiece, op string) (lhs, rhs string, ok bool) {
|
||||
pieces := strings.Split(selectorPiece, op)
|
||||
if len(pieces) == 2 {
|
||||
return pieces[0], pieces[1], true
|
||||
}
|
||||
return "", "", false
|
||||
}
|
||||
|
||||
func parseSelector(selector string, fn TransformFunc) (Selector, error) {
|
||||
parts := strings.Split(selector, ",")
|
||||
sort.StringSlice(parts).Sort()
|
||||
var items []Selector
|
||||
for _, part := range parts {
|
||||
if part == "" {
|
||||
continue
|
||||
}
|
||||
if lhs, rhs, ok := try(part, "!="); ok {
|
||||
items = append(items, ¬HasTerm{field: lhs, value: rhs})
|
||||
} else if lhs, rhs, ok := try(part, "=="); ok {
|
||||
items = append(items, &hasTerm{field: lhs, value: rhs})
|
||||
} else if lhs, rhs, ok := try(part, "="); ok {
|
||||
items = append(items, &hasTerm{field: lhs, value: rhs})
|
||||
} else {
|
||||
return nil, fmt.Errorf("invalid selector: '%s'; can't understand '%s'", selector, part)
|
||||
}
|
||||
}
|
||||
if len(items) == 1 {
|
||||
return items[0].Transform(fn)
|
||||
}
|
||||
return andTerm(items).Transform(fn)
|
||||
}
|
||||
|
||||
// OneTermEqualSelector returns an object that matches objects where one field/field equals one value.
|
||||
// Cannot return an error.
|
||||
func OneTermEqualSelector(k, v string) Selector {
|
||||
return &hasTerm{field: k, value: v}
|
||||
}
|
35
vendor/k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime/BUILD
generated
vendored
Normal file
35
vendor/k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime/BUILD
generated
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"api.pb.go",
|
||||
"constants.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//vendor:github.com/gogo/protobuf/proto",
|
||||
"//vendor:golang.org/x/net/context",
|
||||
"//vendor:google.golang.org/grpc",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
4135
vendor/k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime/api.pb.go
generated
vendored
Normal file
4135
vendor/k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime/api.pb.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
943
vendor/k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime/api.proto
generated
vendored
Normal file
943
vendor/k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime/api.proto
generated
vendored
Normal file
|
@ -0,0 +1,943 @@
|
|||
// To regenerate api.pb.go run hack/update-generated-runtime.sh
|
||||
syntax = 'proto2';
|
||||
|
||||
package runtime;
|
||||
|
||||
// Runtime service defines the public APIs for remote container runtimes
|
||||
service RuntimeService {
|
||||
// Version returns the runtime name, runtime version, and runtime API version.
|
||||
rpc Version(VersionRequest) returns (VersionResponse) {}
|
||||
|
||||
// RunPodSandbox creates and starts a pod-level sandbox. Runtimes must ensure
|
||||
// the sandbox is in the ready state on success.
|
||||
rpc RunPodSandbox(RunPodSandboxRequest) returns (RunPodSandboxResponse) {}
|
||||
// StopPodSandbox stops any running process that is part of the sandbox and
|
||||
// reclaims network resources (e.g., IP addresses) allocated to the sandbox.
|
||||
// If there are any running containers in the sandbox, they must be forcibly
|
||||
// terminated.
|
||||
// This call is idempotent, and must not return an error if all relevant
|
||||
// resources have already been reclaimed. kubelet will call StopPodSandbox
|
||||
// at least once before calling RemovePodSandbox. It will also attempt to
|
||||
// reclaim resources eagerly, as soon as a sandbox is not needed. Hence,
|
||||
// multiple StopPodSandbox calls are expected.
|
||||
rpc StopPodSandbox(StopPodSandboxRequest) returns (StopPodSandboxResponse) {}
|
||||
// RemovePodSandbox removes the sandbox. If there are any running containers
|
||||
// in the sandbox, they must be forcibly terminated and removed.
|
||||
// This call is idempotent, and must not return an error if the sandbox has
|
||||
// already been removed.
|
||||
rpc RemovePodSandbox(RemovePodSandboxRequest) returns (RemovePodSandboxResponse) {}
|
||||
// PodSandboxStatus returns the status of the PodSandbox.
|
||||
rpc PodSandboxStatus(PodSandboxStatusRequest) returns (PodSandboxStatusResponse) {}
|
||||
// ListPodSandbox returns a list of PodSandboxes.
|
||||
rpc ListPodSandbox(ListPodSandboxRequest) returns (ListPodSandboxResponse) {}
|
||||
|
||||
// CreateContainer creates a new container in specified PodSandbox
|
||||
rpc CreateContainer(CreateContainerRequest) returns (CreateContainerResponse) {}
|
||||
// StartContainer starts the container.
|
||||
rpc StartContainer(StartContainerRequest) returns (StartContainerResponse) {}
|
||||
// StopContainer stops a running container with a grace period (i.e., timeout).
|
||||
// This call is idempotent, and must not return an error if the container has
|
||||
// already been stopped.
|
||||
// TODO: what must the runtime do after the grace period is reached?
|
||||
rpc StopContainer(StopContainerRequest) returns (StopContainerResponse) {}
|
||||
// RemoveContainer removes the container. If the container is running, the
|
||||
// container must be forcibly removed.
|
||||
// This call is idempotent, and must not return an error if the container has
|
||||
// already been removed.
|
||||
rpc RemoveContainer(RemoveContainerRequest) returns (RemoveContainerResponse) {}
|
||||
// ListContainers lists all containers by filters.
|
||||
rpc ListContainers(ListContainersRequest) returns (ListContainersResponse) {}
|
||||
// ContainerStatus returns status of the container.
|
||||
rpc ContainerStatus(ContainerStatusRequest) returns (ContainerStatusResponse) {}
|
||||
|
||||
// ExecSync runs a command in a container synchronously.
|
||||
rpc ExecSync(ExecSyncRequest) returns (ExecSyncResponse) {}
|
||||
// Exec prepares a streaming endpoint to execute a command in the container.
|
||||
rpc Exec(ExecRequest) returns (ExecResponse) {}
|
||||
// Attach prepares a streaming endpoint to attach to a running container.
|
||||
rpc Attach(AttachRequest) returns (AttachResponse) {}
|
||||
// PortForward prepares a streaming endpoint to forward ports from a PodSandbox.
|
||||
rpc PortForward(PortForwardRequest) returns (PortForwardResponse) {}
|
||||
|
||||
// UpdateRuntimeConfig updates the runtime configuration based on the given request.
|
||||
rpc UpdateRuntimeConfig(UpdateRuntimeConfigRequest) returns (UpdateRuntimeConfigResponse) {}
|
||||
|
||||
// Status returns the status of the runtime.
|
||||
rpc Status(StatusRequest) returns (StatusResponse) {}
|
||||
}
|
||||
|
||||
// ImageService defines the public APIs for managing images.
|
||||
service ImageService {
|
||||
// ListImages lists existing images.
|
||||
rpc ListImages(ListImagesRequest) returns (ListImagesResponse) {}
|
||||
// ImageStatus returns the status of the image. If the image is not
|
||||
// present, returns a response with ImageStatusResponse.Image set to
|
||||
// nil.
|
||||
rpc ImageStatus(ImageStatusRequest) returns (ImageStatusResponse) {}
|
||||
// PullImage pulls an image with authentication config.
|
||||
rpc PullImage(PullImageRequest) returns (PullImageResponse) {}
|
||||
// RemoveImage removes the image.
|
||||
// This call is idempotent, and must not return an error if the image has
|
||||
// already been removed.
|
||||
rpc RemoveImage(RemoveImageRequest) returns (RemoveImageResponse) {}
|
||||
}
|
||||
|
||||
message VersionRequest {
|
||||
// Version of the kubelet runtime API.
|
||||
optional string version = 1;
|
||||
}
|
||||
|
||||
message VersionResponse {
|
||||
// Version of the kubelet runtime API.
|
||||
optional string version = 1;
|
||||
// Name of the container runtime.
|
||||
optional string runtime_name = 2;
|
||||
// Version of the container runtime. The string must be
|
||||
// semver-compatible.
|
||||
optional string runtime_version = 3;
|
||||
// API version of the container runtime. The string must be
|
||||
// semver-compatible.
|
||||
optional string runtime_api_version = 4;
|
||||
}
|
||||
|
||||
// DNSConfig specifies the DNS servers and search domains of a sandbox.
|
||||
message DNSConfig {
|
||||
// List of DNS servers of the cluster.
|
||||
repeated string servers = 1;
|
||||
// List of DNS search domains of the cluster.
|
||||
repeated string searches = 2;
|
||||
// List of DNS options. See https://linux.die.net/man/5/resolv.conf
|
||||
// for all available options.
|
||||
repeated string options = 3;
|
||||
}
|
||||
|
||||
enum Protocol {
|
||||
TCP = 0;
|
||||
UDP = 1;
|
||||
}
|
||||
|
||||
// PortMapping specifies the port mapping configurations of a sandbox.
|
||||
message PortMapping {
|
||||
// Protocol of the port mapping.
|
||||
optional Protocol protocol = 1;
|
||||
// Port number within the container.
|
||||
optional int32 container_port = 2;
|
||||
// Port number on the host.
|
||||
optional int32 host_port = 3;
|
||||
// Host IP.
|
||||
optional string host_ip = 4;
|
||||
}
|
||||
|
||||
// Mount specifies a host volume to mount into a container.
|
||||
message Mount {
|
||||
// Path of the mount within the container.
|
||||
optional string container_path = 1;
|
||||
// Path of the mount on the host.
|
||||
optional string host_path = 2;
|
||||
// If set, the mount is read-only.
|
||||
optional bool readonly = 3;
|
||||
// If set, the mount needs SELinux relabeling.
|
||||
optional bool selinux_relabel = 4;
|
||||
}
|
||||
|
||||
// NamespaceOption provides options for Linux namespaces.
|
||||
message NamespaceOption {
|
||||
// If set, use the host's network namespace.
|
||||
optional bool host_network = 1;
|
||||
// If set, use the host's PID namespace.
|
||||
optional bool host_pid = 2;
|
||||
// If set, use the host's IPC namespace.
|
||||
optional bool host_ipc = 3;
|
||||
}
|
||||
|
||||
// LinuxSandboxSecurityContext holds linux security configuration that will be
|
||||
// applied to a sandbox. Note that:
|
||||
// 1) It does not apply to containers in the pods.
|
||||
// 2) It may not be applicable to a PodSandbox which does not contain any running
|
||||
// process.
|
||||
message LinuxSandboxSecurityContext {
|
||||
// Configurations for the sandbox's namespaces.
|
||||
// This will be used only if the PodSandbox uses namespace for isolation.
|
||||
optional NamespaceOption namespace_options = 1;
|
||||
// Optional SELinux context to be applied.
|
||||
optional SELinuxOption selinux_options = 2;
|
||||
// UID to run sandbox processes as, when applicable.
|
||||
optional int64 run_as_user = 3;
|
||||
// If set, the root filesystem of the sandbox is read-only.
|
||||
optional bool readonly_rootfs = 4;
|
||||
// List of groups applied to the first process run in the sandbox, in
|
||||
// addition to the sandbox's primary GID.
|
||||
repeated int64 supplemental_groups = 5;
|
||||
// Indicates whether the sandbox will be asked to run a privileged
|
||||
// container. If a privileged container is to be executed within it, this
|
||||
// MUST be true.
|
||||
// This allows a sandbox to take additional security precautions if no
|
||||
// privileged containers are expected to be run.
|
||||
optional bool privileged = 6;
|
||||
}
|
||||
|
||||
// LinuxPodSandboxConfig holds platform-specific configurations for Linux
|
||||
// host platforms and Linux-based containers.
|
||||
message LinuxPodSandboxConfig {
|
||||
// Parent cgroup of the PodSandbox.
|
||||
// The cgroupfs style syntax will be used, but the container runtime can
|
||||
// convert it to systemd semantics if needed.
|
||||
optional string cgroup_parent = 1;
|
||||
// LinuxSandboxSecurityContext holds sandbox security attributes.
|
||||
optional LinuxSandboxSecurityContext security_context = 2;
|
||||
}
|
||||
|
||||
// PodSandboxMetadata holds all necessary information for building the sandbox name.
|
||||
// The container runtime is encouraged to expose the metadata associated with the
|
||||
// PodSandbox in its user interface for better user experience. For example,
|
||||
// the runtime can construct a unique PodSandboxName based on the metadata.
|
||||
message PodSandboxMetadata {
|
||||
// Pod name of the sandbox. Same as the pod name in the PodSpec.
|
||||
optional string name = 1;
|
||||
// Pod UID of the sandbox. Same as the pod UID in the PodSpec.
|
||||
optional string uid = 2;
|
||||
// Pod namespace of the sandbox. Same as the pod namespace in the PodSpec.
|
||||
optional string namespace = 3;
|
||||
// Attempt number of creating the sandbox.
|
||||
optional uint32 attempt = 4;
|
||||
}
|
||||
|
||||
// PodSandboxConfig holds all the required and optional fields for creating a
|
||||
// sandbox.
|
||||
message PodSandboxConfig {
|
||||
// Metadata of the sandbox. This information will uniquely identify the
|
||||
// sandbox, and the runtime should leverage this to ensure correct
|
||||
// operation. The runtime may also use this information to improve UX, such
|
||||
// as by constructing a readable name.
|
||||
optional PodSandboxMetadata metadata = 1;
|
||||
// Hostname of the sandbox.
|
||||
optional string hostname = 2;
|
||||
// Path to the directory on the host in which container log files are
|
||||
// stored.
|
||||
// By default the log of a container going into the LogDirectory will be
|
||||
// hooked up to STDOUT and STDERR. However, the LogDirectory may contain
|
||||
// binary log files with structured logging data from the individual
|
||||
// containers. For example, the files might be newline separated JSON
|
||||
// structured logs, systemd-journald journal files, gRPC trace files, etc.
|
||||
// E.g.,
|
||||
// PodSandboxConfig.LogDirectory = `/var/log/pods/<podUID>/`
|
||||
// ContainerConfig.LogPath = `containerName_Instance#.log`
|
||||
//
|
||||
// WARNING: Log management and how kubelet should interface with the
|
||||
// container logs are under active discussion in
|
||||
// https://issues.k8s.io/24677. There *may* be future change of direction
|
||||
// for logging as the discussion carries on.
|
||||
optional string log_directory = 3;
|
||||
// DNS config for the sandbox.
|
||||
optional DNSConfig dns_config = 4;
|
||||
// Port mappings for the sandbox.
|
||||
repeated PortMapping port_mappings = 5;
|
||||
// Key-value pairs that may be used to scope and select individual resources.
|
||||
map<string, string> labels = 6;
|
||||
// Unstructured key-value map that may be set by the kubelet to store and
|
||||
// retrieve arbitrary metadata. This will include any annotations set on a
|
||||
// pod through the Kubernetes API.
|
||||
//
|
||||
// Annotations MUST NOT be altered by the runtime; the annotations stored
|
||||
// here MUST be returned in the PodSandboxStatus associated with the pod
|
||||
// this PodSandboxConfig creates.
|
||||
//
|
||||
// In general, in order to preserve a well-defined interface between the
|
||||
// kubelet and the container runtime, annotations SHOULD NOT influence
|
||||
// runtime behaviour. For legacy reasons, there are some annotations which
|
||||
// currently explicitly break this rule, listed below; in future versions
|
||||
// of the interface these will be promoted to typed features.
|
||||
//
|
||||
// Annotations can also be useful for runtime authors to experiment with
|
||||
// new features that are opaque to the Kubernetes APIs (both user-facing
|
||||
// and the CRI). Whenever possible, however, runtime authors SHOULD
|
||||
// consider proposing new typed fields for any new features instead.
|
||||
//
|
||||
// 1. AppArmor
|
||||
//
|
||||
// key: container.apparmor.security.beta.kubernetes.io/<container_name>
|
||||
// description: apparmor profile for a container in this pod.
|
||||
// value:
|
||||
// * runtime/default: equivalent to not specifying a profile.
|
||||
// * localhost/<profile_name>: profile loaded on the node
|
||||
// (localhost) by name. The possible profile names are detailed at
|
||||
// http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference
|
||||
//
|
||||
// 2. Seccomp
|
||||
//
|
||||
// key: security.alpha.kubernetes.io/seccomp/pod
|
||||
// description: the seccomp profile for the containers of an entire pod.
|
||||
// value: see below.
|
||||
//
|
||||
// key: security.alpha.kubernetes.io/seccomp/container/<container name>
|
||||
// description: the seccomp profile for the container (overrides pod).
|
||||
// value: see below
|
||||
//
|
||||
// The value of seccomp is runtime agnostic:
|
||||
// * runtime/default: the default profile for the container runtime
|
||||
// * unconfined: unconfined profile, ie, no seccomp sandboxing
|
||||
// * localhost/<profile-name>: the profile installed to the node's
|
||||
// local seccomp profile root. Note that profile root is set in
|
||||
// kubelet, and it is not passed in CRI yet, see https://issues.k8s.io/36997.
|
||||
//
|
||||
// 3. Sysctls
|
||||
//
|
||||
// key: security.alpha.kubernetes.io/sysctls
|
||||
// description: list of safe sysctls which are set for the sandbox.
|
||||
// value: comma separated list of sysctl_name=value key-value pairs.
|
||||
//
|
||||
// key: security.alpha.kubernetes.io/unsafe-sysctls
|
||||
// description: list of unsafe sysctls which are set for the sandbox.
|
||||
// value: comma separated list of sysctl_name=value key-value pairs.
|
||||
//
|
||||
map<string, string> annotations = 7;
|
||||
// Optional configurations specific to Linux hosts.
|
||||
optional LinuxPodSandboxConfig linux = 8;
|
||||
}
|
||||
|
||||
message RunPodSandboxRequest {
|
||||
// Configuration for creating a PodSandbox.
|
||||
optional PodSandboxConfig config = 1;
|
||||
}
|
||||
|
||||
message RunPodSandboxResponse {
|
||||
// ID of the PodSandbox to run.
|
||||
optional string pod_sandbox_id = 1;
|
||||
}
|
||||
|
||||
message StopPodSandboxRequest {
|
||||
// ID of the PodSandbox to stop.
|
||||
optional string pod_sandbox_id = 1;
|
||||
}
|
||||
|
||||
message StopPodSandboxResponse {}
|
||||
|
||||
message RemovePodSandboxRequest {
|
||||
// ID of the PodSandbox to remove.
|
||||
optional string pod_sandbox_id = 1;
|
||||
}
|
||||
|
||||
message RemovePodSandboxResponse {}
|
||||
|
||||
message PodSandboxStatusRequest {
|
||||
// ID of the PodSandbox for which to retrieve status.
|
||||
optional string pod_sandbox_id = 1;
|
||||
}
|
||||
|
||||
// PodSandboxNetworkStatus is the status of the network for a PodSandbox.
|
||||
message PodSandboxNetworkStatus {
|
||||
// IP address of the PodSandbox.
|
||||
optional string ip = 1;
|
||||
}
|
||||
|
||||
// Namespace contains paths to the namespaces.
|
||||
message Namespace {
|
||||
// Path to the network namespace.
|
||||
optional string network = 1;
|
||||
// Namespace options for Linux namespaces.
|
||||
optional NamespaceOption options = 2;
|
||||
}
|
||||
|
||||
// LinuxSandboxStatus contains status specific to Linux sandboxes.
|
||||
message LinuxPodSandboxStatus {
|
||||
// Paths to the sandbox's namespaces.
|
||||
optional Namespace namespaces = 1;
|
||||
}
|
||||
|
||||
enum PodSandboxState {
|
||||
SANDBOX_READY = 0;
|
||||
SANDBOX_NOTREADY = 1;
|
||||
}
|
||||
|
||||
// PodSandboxStatus contains the status of the PodSandbox.
|
||||
message PodSandboxStatus {
|
||||
// ID of the sandbox.
|
||||
optional string id = 1;
|
||||
// Metadata of the sandbox.
|
||||
optional PodSandboxMetadata metadata = 2;
|
||||
// State of the sandbox.
|
||||
optional PodSandboxState state = 3;
|
||||
// Creation timestamp of the sandbox in nanoseconds.
|
||||
optional int64 created_at = 4;
|
||||
// Network contains network status if network is handled by the runtime.
|
||||
optional PodSandboxNetworkStatus network = 5;
|
||||
// Linux-specific status to a pod sandbox.
|
||||
optional LinuxPodSandboxStatus linux = 6;
|
||||
// Labels are key-value pairs that may be used to scope and select individual resources.
|
||||
map<string, string> labels = 7;
|
||||
// Unstructured key-value map holding arbitrary metadata.
|
||||
// Annotations MUST NOT be altered by the runtime; the value of this field
|
||||
// MUST be identical to that of the corresponding PodSandboxConfig used to
|
||||
// instantiate the pod sandbox this status represents.
|
||||
map<string, string> annotations = 8;
|
||||
}
|
||||
|
||||
message PodSandboxStatusResponse {
|
||||
// Status of the PodSandbox.
|
||||
optional PodSandboxStatus status = 1;
|
||||
}
|
||||
|
||||
// PodSandboxFilter is used to filter a list of PodSandboxes.
|
||||
// All those fields are combined with 'AND'
|
||||
message PodSandboxFilter {
|
||||
// ID of the sandbox.
|
||||
optional string id = 1;
|
||||
// State of the sandbox.
|
||||
optional PodSandboxState state = 2;
|
||||
// LabelSelector to select matches.
|
||||
// Only api.MatchLabels is supported for now and the requirements
|
||||
// are ANDed. MatchExpressions is not supported yet.
|
||||
map<string, string> label_selector = 3;
|
||||
}
|
||||
|
||||
message ListPodSandboxRequest {
|
||||
// PodSandboxFilter to filter a list of PodSandboxes.
|
||||
optional PodSandboxFilter filter = 1;
|
||||
}
|
||||
|
||||
|
||||
// PodSandbox contains minimal information about a sandbox.
|
||||
message PodSandbox {
|
||||
// ID of the PodSandbox.
|
||||
optional string id = 1;
|
||||
// Metadata of the PodSandbox.
|
||||
optional PodSandboxMetadata metadata = 2;
|
||||
// State of the PodSandbox.
|
||||
optional PodSandboxState state = 3;
|
||||
// Creation timestamps of the PodSandbox in nanoseconds.
|
||||
optional int64 created_at = 4;
|
||||
// Labels of the PodSandbox.
|
||||
map<string, string> labels = 5;
|
||||
// Unstructured key-value map holding arbitrary metadata.
|
||||
// Annotations MUST NOT be altered by the runtime; the value of this field
|
||||
// MUST be identical to that of the corresponding PodSandboxConfig used to
|
||||
// instantiate this PodSandbox.
|
||||
map<string, string> annotations = 6;
|
||||
}
|
||||
|
||||
message ListPodSandboxResponse {
|
||||
// List of PodSandboxes.
|
||||
repeated PodSandbox items = 1;
|
||||
}
|
||||
|
||||
// ImageSpec is an internal representation of an image. Currently, it wraps the
|
||||
// value of a Container's Image field (e.g. imageID or imageDigest), but in the
|
||||
// future it will include more detailed information about the different image types.
|
||||
message ImageSpec {
|
||||
optional string image = 1;
|
||||
}
|
||||
|
||||
message KeyValue {
|
||||
optional string key = 1;
|
||||
optional string value = 2;
|
||||
}
|
||||
|
||||
// LinuxContainerResources specifies Linux specific configuration for
|
||||
// resources.
|
||||
// TODO: Consider using Resources from opencontainers/runtime-spec/specs-go
|
||||
// directly.
|
||||
message LinuxContainerResources {
|
||||
// CPU CFS (Completely Fair Scheduler) period.
|
||||
optional int64 cpu_period = 1;
|
||||
// CPU CFS (Completely Fair Scheduler) quota.
|
||||
optional int64 cpu_quota = 2;
|
||||
// CPU shares (relative weight vs. other containers).
|
||||
optional int64 cpu_shares = 3;
|
||||
// Memory limit in bytes.
|
||||
optional int64 memory_limit_in_bytes = 4;
|
||||
// OOMScoreAdj adjusts the oom-killer score.
|
||||
optional int64 oom_score_adj = 5;
|
||||
}
|
||||
|
||||
// SELinuxOption are the labels to be applied to the container.
|
||||
message SELinuxOption {
|
||||
optional string user = 1;
|
||||
optional string role = 2;
|
||||
optional string type = 3;
|
||||
optional string level = 4;
|
||||
}
|
||||
|
||||
// Capability contains the container capabilities to add or drop
|
||||
message Capability {
|
||||
// List of capabilities to add.
|
||||
repeated string add_capabilities = 1;
|
||||
// List of capabilities to drop.
|
||||
repeated string drop_capabilities = 2;
|
||||
}
|
||||
|
||||
// LinuxContainerSecurityContext holds linux security configuration that will be applied to a container.
|
||||
message LinuxContainerSecurityContext {
|
||||
// Capabilities to add or drop.
|
||||
optional Capability capabilities = 1;
|
||||
// If set, run container in privileged mode.
|
||||
// Privileged mode is incompatible with the following options. If
|
||||
// privileged is set, the following features MAY have no effect:
|
||||
// 1. capabilities
|
||||
// 2. selinux_options
|
||||
// 4. seccomp
|
||||
// 5. apparmor
|
||||
//
|
||||
// Privileged mode implies the following specific options are applied:
|
||||
// 1. All capabilities are added.
|
||||
// 2. Sensitive paths, such as kernel module paths within sysfs, are not masked.
|
||||
// 3. Any sysfs and procfs mounts are mounted RW.
|
||||
// 4. Apparmor confinement is not applied.
|
||||
// 5. Seccomp restrictions are not applied.
|
||||
// 6. The device cgroup does not restrict access to any devices.
|
||||
// 7. All devices from the host's /dev are available within the container.
|
||||
// 8. SELinux restrictions are not applied (e.g. label=disabled).
|
||||
optional bool privileged = 2;
|
||||
// Configurations for the container's namespaces.
|
||||
// Only used if the container uses namespace for isolation.
|
||||
optional NamespaceOption namespace_options = 3;
|
||||
// SELinux context to be optionally applied.
|
||||
optional SELinuxOption selinux_options = 4;
|
||||
// UID to run the container process as. Only one of run_as_user and
|
||||
// run_as_username can be specified at a time.
|
||||
optional int64 run_as_user = 5;
|
||||
// User name to run the container process as. If specified, the user MUST
|
||||
// exist in the container image (i.e. in the /etc/passwd inside the image),
|
||||
// and be resolved there by the runtime; otherwise, the runtime MUST error.
|
||||
optional string run_as_username = 6;
|
||||
// If set, the root filesystem of the container is read-only.
|
||||
optional bool readonly_rootfs = 7;
|
||||
// List of groups applied to the first process run in the container, in
|
||||
// addition to the container's primary GID.
|
||||
repeated int64 supplemental_groups = 8;
|
||||
}
|
||||
|
||||
// LinuxContainerConfig contains platform-specific configuration for
|
||||
// Linux-based containers.
|
||||
message LinuxContainerConfig {
|
||||
// Resources specification for the container.
|
||||
optional LinuxContainerResources resources = 1;
|
||||
// LinuxContainerSecurityContext configuration for the container.
|
||||
optional LinuxContainerSecurityContext security_context = 2;
|
||||
}
|
||||
|
||||
// ContainerMetadata holds all necessary information for building the container
|
||||
// name. The container runtime is encouraged to expose the metadata in its user
|
||||
// interface for better user experience. E.g., runtime can construct a unique
|
||||
// container name based on the metadata. Note that (name, attempt) is unique
|
||||
// within a sandbox for the entire lifetime of the sandbox.
|
||||
message ContainerMetadata {
|
||||
// Name of the container. Same as the container name in the PodSpec.
|
||||
optional string name = 1;
|
||||
// Attempt number of creating the container.
|
||||
optional uint32 attempt = 2;
|
||||
}
|
||||
|
||||
// Device specifies a host device to mount into a container.
|
||||
message Device {
|
||||
// Path of the device within the container.
|
||||
optional string container_path = 1;
|
||||
// Path of the device on the host.
|
||||
optional string host_path = 2;
|
||||
// Cgroups permissions of the device, candidates are one or more of
|
||||
// * r - allows container to read from the specified device.
|
||||
// * w - allows container to write to the specified device.
|
||||
// * m - allows container to create device files that do not yet exist.
|
||||
optional string permissions = 3;
|
||||
}
|
||||
|
||||
// ContainerConfig holds all the required and optional fields for creating a
|
||||
// container.
|
||||
message ContainerConfig {
|
||||
// Metadata of the container. This information will uniquely identify the
|
||||
// container, and the runtime should leverage this to ensure correct
|
||||
// operation. The runtime may also use this information to improve UX, such
|
||||
// as by constructing a readable name.
|
||||
optional ContainerMetadata metadata = 1 ;
|
||||
// Image to use.
|
||||
optional ImageSpec image = 2;
|
||||
// Command to execute (i.e., entrypoint for docker)
|
||||
repeated string command = 3;
|
||||
// Args for the Command (i.e., command for docker)
|
||||
repeated string args = 4;
|
||||
// Current working directory of the command.
|
||||
optional string working_dir = 5;
|
||||
// List of environment variable to set in the container.
|
||||
repeated KeyValue envs = 6;
|
||||
// Mounts for the container.
|
||||
repeated Mount mounts = 7;
|
||||
// Devices for the container.
|
||||
repeated Device devices = 8;
|
||||
// Key-value pairs that may be used to scope and select individual resources.
|
||||
// Label keys are of the form:
|
||||
// label-key ::= prefixed-name | name
|
||||
// prefixed-name ::= prefix '/' name
|
||||
// prefix ::= DNS_SUBDOMAIN
|
||||
// name ::= DNS_LABEL
|
||||
map<string, string> labels = 9;
|
||||
// Unstructured key-value map that may be used by the kubelet to store and
|
||||
// retrieve arbitrary metadata.
|
||||
//
|
||||
// Annotations MUST NOT be altered by the runtime; the annotations stored
|
||||
// here MUST be returned in the ContainerStatus associated with the container
|
||||
// this ContainerConfig creates.
|
||||
//
|
||||
// In general, in order to preserve a well-defined interface between the
|
||||
// kubelet and the container runtime, annotations SHOULD NOT influence
|
||||
// runtime behaviour.
|
||||
map<string, string> annotations = 10;
|
||||
// Path relative to PodSandboxConfig.LogDirectory for container to store
|
||||
// the log (STDOUT and STDERR) on the host.
|
||||
// E.g.,
|
||||
// PodSandboxConfig.LogDirectory = `/var/log/pods/<podUID>/`
|
||||
// ContainerConfig.LogPath = `containerName_Instance#.log`
|
||||
//
|
||||
// WARNING: Log management and how kubelet should interface with the
|
||||
// container logs are under active discussion in
|
||||
// https://issues.k8s.io/24677. There *may* be future change of direction
|
||||
// for logging as the discussion carries on.
|
||||
optional string log_path = 11;
|
||||
|
||||
// Variables for interactive containers, these have very specialized
|
||||
// use-cases (e.g. debugging).
|
||||
// TODO: Determine if we need to continue supporting these fields that are
|
||||
// part of Kubernetes's Container Spec.
|
||||
optional bool stdin = 12;
|
||||
optional bool stdin_once = 13;
|
||||
optional bool tty = 14;
|
||||
|
||||
// Configuration specific to Linux containers.
|
||||
optional LinuxContainerConfig linux = 15;
|
||||
}
|
||||
|
||||
message CreateContainerRequest {
|
||||
// ID of the PodSandbox in which the container should be created.
|
||||
optional string pod_sandbox_id = 1;
|
||||
// Config of the container.
|
||||
optional ContainerConfig config = 2;
|
||||
// Config of the PodSandbox. This is the same config that was passed
|
||||
// to RunPodSandboxRequest to create the PodSandbox. It is passed again
|
||||
// here just for easy reference. The PodSandboxConfig is immutable and
|
||||
// remains the same throughout the lifetime of the pod.
|
||||
optional PodSandboxConfig sandbox_config = 3;
|
||||
}
|
||||
|
||||
message CreateContainerResponse {
|
||||
// ID of the created container.
|
||||
optional string container_id = 1;
|
||||
}
|
||||
|
||||
message StartContainerRequest {
|
||||
// ID of the container to start.
|
||||
optional string container_id = 1;
|
||||
}
|
||||
|
||||
message StartContainerResponse {}
|
||||
|
||||
message StopContainerRequest {
|
||||
// ID of the container to stop.
|
||||
optional string container_id = 1;
|
||||
// Timeout, in seconds, to stop the container.
|
||||
optional int64 timeout = 2;
|
||||
}
|
||||
|
||||
message StopContainerResponse {}
|
||||
|
||||
message RemoveContainerRequest {
|
||||
// ID of the container to remove.
|
||||
optional string container_id = 1;
|
||||
}
|
||||
|
||||
message RemoveContainerResponse {}
|
||||
|
||||
enum ContainerState {
|
||||
CONTAINER_CREATED = 0;
|
||||
CONTAINER_RUNNING = 1;
|
||||
CONTAINER_EXITED = 2;
|
||||
CONTAINER_UNKNOWN = 3;
|
||||
}
|
||||
|
||||
// ContainerFilter is used to filter containers.
|
||||
// All those fields are combined with 'AND'
|
||||
message ContainerFilter {
|
||||
// ID of the container.
|
||||
optional string id = 1;
|
||||
// State of the container.
|
||||
optional ContainerState state = 2;
|
||||
// ID of the PodSandbox.
|
||||
optional string pod_sandbox_id = 3;
|
||||
// LabelSelector to select matches.
|
||||
// Only api.MatchLabels is supported for now and the requirements
|
||||
// are ANDed. MatchExpressions is not supported yet.
|
||||
map<string, string> label_selector = 4;
|
||||
}
|
||||
|
||||
message ListContainersRequest {
|
||||
optional ContainerFilter filter = 1;
|
||||
}
|
||||
|
||||
// Container provides the runtime information for a container, such as ID, hash,
|
||||
// state of the container.
|
||||
message Container {
|
||||
// ID of the container, used by the container runtime to identify
|
||||
// a container.
|
||||
optional string id = 1;
|
||||
// ID of the sandbox to which this container belongs.
|
||||
optional string pod_sandbox_id = 2;
|
||||
// Metadata of the container.
|
||||
optional ContainerMetadata metadata = 3;
|
||||
// Spec of the image.
|
||||
optional ImageSpec image = 4;
|
||||
// Reference to the image in use. For most runtimes, this should be an
|
||||
// image ID.
|
||||
optional string image_ref = 5;
|
||||
// State of the container.
|
||||
optional ContainerState state = 6;
|
||||
// Creation time of the container in nanoseconds.
|
||||
optional int64 created_at = 7;
|
||||
// Key-value pairs that may be used to scope and select individual resources.
|
||||
map<string, string> labels = 8;
|
||||
// Unstructured key-value map holding arbitrary metadata.
|
||||
// Annotations MUST NOT be altered by the runtime; the value of this field
|
||||
// MUST be identical to that of the corresponding ContainerConfig used to
|
||||
// instantiate this Container.
|
||||
map<string, string> annotations = 9;
|
||||
}
|
||||
|
||||
message ListContainersResponse {
|
||||
// List of containers.
|
||||
repeated Container containers = 1;
|
||||
}
|
||||
|
||||
message ContainerStatusRequest {
|
||||
// ID of the container for which to retrieve status.
|
||||
optional string container_id = 1;
|
||||
}
|
||||
|
||||
// ContainerStatus represents the status of a container.
|
||||
message ContainerStatus {
|
||||
// ID of the container.
|
||||
optional string id = 1;
|
||||
// Metadata of the container.
|
||||
optional ContainerMetadata metadata = 2;
|
||||
// Status of the container.
|
||||
optional ContainerState state = 3;
|
||||
// Creation time of the container in nanoseconds.
|
||||
optional int64 created_at = 4;
|
||||
// Start time of the container in nanoseconds.
|
||||
optional int64 started_at = 5;
|
||||
// Finish time of the container in nanoseconds.
|
||||
optional int64 finished_at = 6;
|
||||
// Exit code of the container.
|
||||
optional int32 exit_code = 7;
|
||||
// Spec of the image.
|
||||
optional ImageSpec image = 8;
|
||||
// Reference to the image in use. For most runtimes, this should be an
|
||||
// image ID
|
||||
optional string image_ref = 9;
|
||||
// Brief CamelCase string explaining why container is in its current state.
|
||||
optional string reason = 10;
|
||||
// Human-readable message indicating details about why container is in its
|
||||
// current state.
|
||||
optional string message = 11;
|
||||
// Key-value pairs that may be used to scope and select individual resources.
|
||||
map<string,string> labels = 12;
|
||||
// Unstructured key-value map holding arbitrary metadata.
|
||||
// Annotations MUST NOT be altered by the runtime; the value of this field
|
||||
// MUST be identical to that of the corresponding ContainerConfig used to
|
||||
// instantiate the Container this status represents.
|
||||
map<string,string> annotations = 13;
|
||||
// Mounts for the container.
|
||||
repeated Mount mounts = 14;
|
||||
}
|
||||
|
||||
message ContainerStatusResponse {
|
||||
// Status of the container.
|
||||
optional ContainerStatus status = 1;
|
||||
}
|
||||
|
||||
message ExecSyncRequest {
|
||||
// ID of the container.
|
||||
optional string container_id = 1;
|
||||
// Command to execute.
|
||||
repeated string cmd = 2;
|
||||
// Timeout in seconds to stop the command. Default: run forever.
|
||||
optional int64 timeout = 3;
|
||||
}
|
||||
|
||||
message ExecSyncResponse {
|
||||
// Captured command stdout output.
|
||||
optional bytes stdout = 1;
|
||||
// Captured command stderr output.
|
||||
optional bytes stderr = 2;
|
||||
// Exit code the command finished with.
|
||||
optional int32 exit_code = 3;
|
||||
}
|
||||
|
||||
message ExecRequest {
|
||||
// ID of the container in which to execute the command.
|
||||
optional string container_id = 1;
|
||||
// Command to execute.
|
||||
repeated string cmd = 2;
|
||||
// Whether to exec the command in a TTY.
|
||||
optional bool tty = 3;
|
||||
// Whether to stream stdin.
|
||||
optional bool stdin = 4;
|
||||
}
|
||||
|
||||
message ExecResponse {
|
||||
// Fully qualified URL of the exec streaming server.
|
||||
optional string url = 1;
|
||||
}
|
||||
|
||||
message AttachRequest {
|
||||
// ID of the container to which to attach.
|
||||
optional string container_id = 1;
|
||||
// Whether to stream stdin.
|
||||
optional bool stdin = 2;
|
||||
// Whether the process being attached is running in a TTY.
|
||||
// This must match the TTY setting in the ContainerConfig.
|
||||
optional bool tty = 3;
|
||||
}
|
||||
|
||||
message AttachResponse {
|
||||
// Fully qualified URL of the attach streaming server.
|
||||
optional string url = 1;
|
||||
}
|
||||
|
||||
message PortForwardRequest {
|
||||
// ID of the container to which to forward the port.
|
||||
optional string pod_sandbox_id = 1;
|
||||
// Port to forward.
|
||||
repeated int32 port = 2;
|
||||
}
|
||||
|
||||
message PortForwardResponse {
|
||||
// Fully qualified URL of the port-forward streaming server.
|
||||
optional string url = 1;
|
||||
}
|
||||
|
||||
message ImageFilter {
|
||||
// Spec of the image.
|
||||
optional ImageSpec image = 1;
|
||||
}
|
||||
|
||||
message ListImagesRequest {
|
||||
// Filter to list images.
|
||||
optional ImageFilter filter = 1;
|
||||
}
|
||||
|
||||
// Basic information about a container image.
|
||||
message Image {
|
||||
// ID of the image.
|
||||
optional string id = 1;
|
||||
// Other names by which this image is known.
|
||||
repeated string repo_tags = 2;
|
||||
// Digests by which this image is known.
|
||||
repeated string repo_digests = 3;
|
||||
// Size of the image in bytes.
|
||||
optional uint64 size = 4;
|
||||
// UID that will run the command(s). This is used as a default if no user is
|
||||
// specified when creating the container. UID and the following user name
|
||||
// are mutually exclusive.
|
||||
optional int64 uid = 5;
|
||||
// User name that will run the command(s). This is used if UID is not set
|
||||
// and no user is specified when creating container.
|
||||
optional string username = 6;
|
||||
}
|
||||
|
||||
message ListImagesResponse {
|
||||
// List of images.
|
||||
repeated Image images = 1;
|
||||
}
|
||||
|
||||
message ImageStatusRequest {
|
||||
// Spec of the image.
|
||||
optional ImageSpec image = 1;
|
||||
}
|
||||
|
||||
message ImageStatusResponse {
|
||||
// Status of the image.
|
||||
optional Image image = 1;
|
||||
}
|
||||
|
||||
// AuthConfig contains authorization information for connecting to a registry.
|
||||
message AuthConfig {
|
||||
optional string username = 1;
|
||||
optional string password = 2;
|
||||
optional string auth = 3;
|
||||
optional string server_address = 4;
|
||||
// IdentityToken is used to authenticate the user and get
|
||||
// an access token for the registry.
|
||||
optional string identity_token = 5;
|
||||
// RegistryToken is a bearer token to be sent to a registry
|
||||
optional string registry_token = 6;
|
||||
}
|
||||
|
||||
message PullImageRequest {
|
||||
// Spec of the image.
|
||||
optional ImageSpec image = 1;
|
||||
// Authentication configuration for pulling the image.
|
||||
optional AuthConfig auth = 2;
|
||||
// Config of the PodSandbox, which is used to pull image in PodSandbox context.
|
||||
optional PodSandboxConfig sandbox_config = 3;
|
||||
}
|
||||
|
||||
message PullImageResponse {
|
||||
// Reference to the image in use. For most runtimes, this should be an
|
||||
// image ID or digest.
|
||||
optional string image_ref = 1;
|
||||
}
|
||||
|
||||
message RemoveImageRequest {
|
||||
// Spec of the image to remove.
|
||||
optional ImageSpec image = 1;
|
||||
}
|
||||
|
||||
message RemoveImageResponse {}
|
||||
|
||||
message NetworkConfig {
|
||||
// CIDR to use for pod IP addresses.
|
||||
optional string pod_cidr = 1;
|
||||
}
|
||||
|
||||
message RuntimeConfig {
|
||||
optional NetworkConfig network_config = 1;
|
||||
}
|
||||
|
||||
message UpdateRuntimeConfigRequest {
|
||||
optional RuntimeConfig runtime_config = 1;
|
||||
}
|
||||
|
||||
message UpdateRuntimeConfigResponse {}
|
||||
|
||||
// RuntimeCondition contains condition information for the runtime.
|
||||
// There are 2 kinds of runtime conditions:
|
||||
// 1. Required condtitions: Conditions are required for kubelet to work
|
||||
// properly. If any required condition is unmet, the node will be not ready.
|
||||
// The required conditions include:
|
||||
// * RuntimeReady: RuntimeReady means the runtime is up and ready to accept
|
||||
// basic containers e.g. container only needs host network.
|
||||
// * NetworkReady: NetworkReady means the runtime network is up and ready to
|
||||
// accept containers which require container network.
|
||||
// 2. Optional conditions: Conditions are informative to the user, but kubelet
|
||||
// will not rely on. Since condition type is an arbitrary string, all conditions
|
||||
// not required are optional. These conditions will be exposed to users to help
|
||||
// them understand the status of the system.
|
||||
message RuntimeCondition {
|
||||
// Type of runtime condition.
|
||||
optional string type = 1;
|
||||
// Status of the condition, one of true/false.
|
||||
optional bool status = 2;
|
||||
// Brief CamelCase string containing reason for the condition's last transition.
|
||||
optional string reason = 3;
|
||||
// Human-readable message indicating details about last transition.
|
||||
optional string message = 4;
|
||||
}
|
||||
|
||||
// RuntimeStatus is information about the current status of the runtime.
|
||||
message RuntimeStatus {
|
||||
// List of current observed runtime conditions.
|
||||
repeated RuntimeCondition conditions = 1;
|
||||
}
|
||||
|
||||
message StatusRequest {}
|
||||
|
||||
message StatusResponse {
|
||||
// Status of the Runtime.
|
||||
optional RuntimeStatus status = 1;
|
||||
}
|
27
vendor/k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime/constants.go
generated
vendored
Normal file
27
vendor/k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime/constants.go
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
Copyright 2016 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 runtime
|
||||
|
||||
// This file contains all constants defined in CRI.
|
||||
|
||||
// Required runtime condition type.
|
||||
const (
|
||||
// RuntimeReady means the runtime is up and ready to accept basic containers.
|
||||
RuntimeReady = "RuntimeReady"
|
||||
// NetworkReady means the runtime network is up and ready to accept containers which require network.
|
||||
NetworkReady = "NetworkReady"
|
||||
)
|
0
vendor/k8s.io/kubernetes/pkg/util/errors/.readonly
generated
vendored
Normal file
0
vendor/k8s.io/kubernetes/pkg/util/errors/.readonly
generated
vendored
Normal file
38
vendor/k8s.io/kubernetes/pkg/util/errors/BUILD
generated
vendored
Normal file
38
vendor/k8s.io/kubernetes/pkg/util/errors/BUILD
generated
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"errors.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["errors_test.go"],
|
||||
library = ":go_default_library",
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
18
vendor/k8s.io/kubernetes/pkg/util/errors/doc.go
generated
vendored
Normal file
18
vendor/k8s.io/kubernetes/pkg/util/errors/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
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 errors implements various utility functions and types around errors.
|
||||
package errors // import "k8s.io/kubernetes/pkg/util/errors"
|
182
vendor/k8s.io/kubernetes/pkg/util/errors/errors.go
generated
vendored
Normal file
182
vendor/k8s.io/kubernetes/pkg/util/errors/errors.go
generated
vendored
Normal file
|
@ -0,0 +1,182 @@
|
|||
/*
|
||||
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 errors
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Aggregate represents an object that contains multiple errors, but does not
|
||||
// necessarily have singular semantic meaning.
|
||||
type Aggregate interface {
|
||||
error
|
||||
Errors() []error
|
||||
}
|
||||
|
||||
// NewAggregate converts a slice of errors into an Aggregate interface, which
|
||||
// is itself an implementation of the error interface. If the slice is empty,
|
||||
// this returns nil.
|
||||
// It will check if any of the element of input error list is nil, to avoid
|
||||
// nil pointer panic when call Error().
|
||||
func NewAggregate(errlist []error) Aggregate {
|
||||
if len(errlist) == 0 {
|
||||
return nil
|
||||
}
|
||||
// In case of input error list contains nil
|
||||
var errs []error
|
||||
for _, e := range errlist {
|
||||
if e != nil {
|
||||
errs = append(errs, e)
|
||||
}
|
||||
}
|
||||
if len(errs) == 0 {
|
||||
return nil
|
||||
}
|
||||
return aggregate(errs)
|
||||
}
|
||||
|
||||
// This helper implements the error and Errors interfaces. Keeping it private
|
||||
// prevents people from making an aggregate of 0 errors, which is not
|
||||
// an error, but does satisfy the error interface.
|
||||
type aggregate []error
|
||||
|
||||
// Error is part of the error interface.
|
||||
func (agg aggregate) Error() string {
|
||||
if len(agg) == 0 {
|
||||
// This should never happen, really.
|
||||
return ""
|
||||
}
|
||||
if len(agg) == 1 {
|
||||
return agg[0].Error()
|
||||
}
|
||||
result := fmt.Sprintf("[%s", agg[0].Error())
|
||||
for i := 1; i < len(agg); i++ {
|
||||
result += fmt.Sprintf(", %s", agg[i].Error())
|
||||
}
|
||||
result += "]"
|
||||
return result
|
||||
}
|
||||
|
||||
// Errors is part of the Aggregate interface.
|
||||
func (agg aggregate) Errors() []error {
|
||||
return []error(agg)
|
||||
}
|
||||
|
||||
// Matcher is used to match errors. Returns true if the error matches.
|
||||
type Matcher func(error) bool
|
||||
|
||||
// FilterOut removes all errors that match any of the matchers from the input
|
||||
// error. If the input is a singular error, only that error is tested. If the
|
||||
// input implements the Aggregate interface, the list of errors will be
|
||||
// processed recursively.
|
||||
//
|
||||
// This can be used, for example, to remove known-OK errors (such as io.EOF or
|
||||
// os.PathNotFound) from a list of errors.
|
||||
func FilterOut(err error, fns ...Matcher) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if agg, ok := err.(Aggregate); ok {
|
||||
return NewAggregate(filterErrors(agg.Errors(), fns...))
|
||||
}
|
||||
if !matchesError(err, fns...) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// matchesError returns true if any Matcher returns true
|
||||
func matchesError(err error, fns ...Matcher) bool {
|
||||
for _, fn := range fns {
|
||||
if fn(err) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// filterErrors returns any errors (or nested errors, if the list contains
|
||||
// nested Errors) for which all fns return false. If no errors
|
||||
// remain a nil list is returned. The resulting silec will have all
|
||||
// nested slices flattened as a side effect.
|
||||
func filterErrors(list []error, fns ...Matcher) []error {
|
||||
result := []error{}
|
||||
for _, err := range list {
|
||||
r := FilterOut(err, fns...)
|
||||
if r != nil {
|
||||
result = append(result, r)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Flatten takes an Aggregate, which may hold other Aggregates in arbitrary
|
||||
// nesting, and flattens them all into a single Aggregate, recursively.
|
||||
func Flatten(agg Aggregate) Aggregate {
|
||||
result := []error{}
|
||||
if agg == nil {
|
||||
return nil
|
||||
}
|
||||
for _, err := range agg.Errors() {
|
||||
if a, ok := err.(Aggregate); ok {
|
||||
r := Flatten(a)
|
||||
if r != nil {
|
||||
result = append(result, r.Errors()...)
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
result = append(result, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return NewAggregate(result)
|
||||
}
|
||||
|
||||
// Reduce will return err or, if err is an Aggregate and only has one item,
|
||||
// the first item in the aggregate.
|
||||
func Reduce(err error) error {
|
||||
if agg, ok := err.(Aggregate); ok && err != nil {
|
||||
switch len(agg.Errors()) {
|
||||
case 1:
|
||||
return agg.Errors()[0]
|
||||
case 0:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// AggregateGoroutines runs the provided functions in parallel, stuffing all
|
||||
// non-nil errors into the returned Aggregate.
|
||||
// Returns nil if all the functions complete successfully.
|
||||
func AggregateGoroutines(funcs ...func() error) Aggregate {
|
||||
errChan := make(chan error, len(funcs))
|
||||
for _, f := range funcs {
|
||||
go func(f func() error) { errChan <- f() }(f)
|
||||
}
|
||||
errs := make([]error, 0)
|
||||
for i := 0; i < cap(errChan); i++ {
|
||||
if err := <-errChan; err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
return NewAggregate(errs)
|
||||
}
|
||||
|
||||
// ErrPreconditionViolated is returned when the precondition is violated
|
||||
var ErrPreconditionViolated = errors.New("precondition is violated")
|
27
vendor/k8s.io/kubernetes/pkg/util/homedir/BUILD
generated
vendored
Normal file
27
vendor/k8s.io/kubernetes/pkg/util/homedir/BUILD
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["homedir.go"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
47
vendor/k8s.io/kubernetes/pkg/util/homedir/homedir.go
generated
vendored
Normal file
47
vendor/k8s.io/kubernetes/pkg/util/homedir/homedir.go
generated
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
Copyright 2016 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 homedir
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// HomeDir returns the home directory for the current user
|
||||
func HomeDir() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
|
||||
// First prefer the HOME environmental variable
|
||||
if home := os.Getenv("HOME"); len(home) > 0 {
|
||||
if _, err := os.Stat(home); err == nil {
|
||||
return home
|
||||
}
|
||||
}
|
||||
if homeDrive, homePath := os.Getenv("HOMEDRIVE"), os.Getenv("HOMEPATH"); len(homeDrive) > 0 && len(homePath) > 0 {
|
||||
homeDir := homeDrive + homePath
|
||||
if _, err := os.Stat(homeDir); err == nil {
|
||||
return homeDir
|
||||
}
|
||||
}
|
||||
if userProfile := os.Getenv("USERPROFILE"); len(userProfile) > 0 {
|
||||
if _, err := os.Stat(userProfile); err == nil {
|
||||
return userProfile
|
||||
}
|
||||
}
|
||||
}
|
||||
return os.Getenv("HOME")
|
||||
}
|
0
vendor/k8s.io/kubernetes/pkg/util/net/.readonly
generated
vendored
Normal file
0
vendor/k8s.io/kubernetes/pkg/util/net/.readonly
generated
vendored
Normal file
59
vendor/k8s.io/kubernetes/pkg/util/net/BUILD
generated
vendored
Normal file
59
vendor/k8s.io/kubernetes/pkg/util/net/BUILD
generated
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"http.go",
|
||||
"interface.go",
|
||||
"port_range.go",
|
||||
"port_split.go",
|
||||
"util.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/util/sets:go_default_library",
|
||||
"//vendor:github.com/golang/glog",
|
||||
"//vendor:golang.org/x/net/http2",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"http_test.go",
|
||||
"interface_test.go",
|
||||
"port_range_test.go",
|
||||
"port_split_test.go",
|
||||
"util_test.go",
|
||||
],
|
||||
library = ":go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/util/sets:go_default_library",
|
||||
"//vendor:github.com/spf13/pflag",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [
|
||||
":package-srcs",
|
||||
"//pkg/util/net/sets:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
)
|
269
vendor/k8s.io/kubernetes/pkg/util/net/http.go
generated
vendored
Normal file
269
vendor/k8s.io/kubernetes/pkg/util/net/http.go
generated
vendored
Normal file
|
@ -0,0 +1,269 @@
|
|||
/*
|
||||
Copyright 2016 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 net
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"golang.org/x/net/http2"
|
||||
)
|
||||
|
||||
// IsProbableEOF returns true if the given error resembles a connection termination
|
||||
// scenario that would justify assuming that the watch is empty.
|
||||
// These errors are what the Go http stack returns back to us which are general
|
||||
// connection closure errors (strongly correlated) and callers that need to
|
||||
// differentiate probable errors in connection behavior between normal "this is
|
||||
// disconnected" should use the method.
|
||||
func IsProbableEOF(err error) bool {
|
||||
if uerr, ok := err.(*url.Error); ok {
|
||||
err = uerr.Err
|
||||
}
|
||||
switch {
|
||||
case err == io.EOF:
|
||||
return true
|
||||
case err.Error() == "http: can't write HTTP request on broken connection":
|
||||
return true
|
||||
case strings.Contains(err.Error(), "connection reset by peer"):
|
||||
return true
|
||||
case strings.Contains(strings.ToLower(err.Error()), "use of closed network connection"):
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var defaultTransport = http.DefaultTransport.(*http.Transport)
|
||||
|
||||
// SetOldTransportDefaults applies the defaults from http.DefaultTransport
|
||||
// for the Proxy, Dial, and TLSHandshakeTimeout fields if unset
|
||||
func SetOldTransportDefaults(t *http.Transport) *http.Transport {
|
||||
if t.Proxy == nil || isDefault(t.Proxy) {
|
||||
// http.ProxyFromEnvironment doesn't respect CIDRs and that makes it impossible to exclude things like pod and service IPs from proxy settings
|
||||
// ProxierWithNoProxyCIDR allows CIDR rules in NO_PROXY
|
||||
t.Proxy = NewProxierWithNoProxyCIDR(http.ProxyFromEnvironment)
|
||||
}
|
||||
if t.Dial == nil {
|
||||
t.Dial = defaultTransport.Dial
|
||||
}
|
||||
if t.TLSHandshakeTimeout == 0 {
|
||||
t.TLSHandshakeTimeout = defaultTransport.TLSHandshakeTimeout
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// SetTransportDefaults applies the defaults from http.DefaultTransport
|
||||
// for the Proxy, Dial, and TLSHandshakeTimeout fields if unset
|
||||
func SetTransportDefaults(t *http.Transport) *http.Transport {
|
||||
t = SetOldTransportDefaults(t)
|
||||
// Allow clients to disable http2 if needed.
|
||||
if s := os.Getenv("DISABLE_HTTP2"); len(s) > 0 {
|
||||
glog.Infof("HTTP2 has been explicitly disabled")
|
||||
} else {
|
||||
if err := http2.ConfigureTransport(t); err != nil {
|
||||
glog.Warningf("Transport failed http2 configuration: %v", err)
|
||||
}
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
type RoundTripperWrapper interface {
|
||||
http.RoundTripper
|
||||
WrappedRoundTripper() http.RoundTripper
|
||||
}
|
||||
|
||||
type DialFunc func(net, addr string) (net.Conn, error)
|
||||
|
||||
func Dialer(transport http.RoundTripper) (DialFunc, error) {
|
||||
if transport == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
switch transport := transport.(type) {
|
||||
case *http.Transport:
|
||||
return transport.Dial, nil
|
||||
case RoundTripperWrapper:
|
||||
return Dialer(transport.WrappedRoundTripper())
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown transport type: %v", transport)
|
||||
}
|
||||
}
|
||||
|
||||
// CloneTLSConfig returns a tls.Config with all exported fields except SessionTicketsDisabled and SessionTicketKey copied.
|
||||
// This makes it safe to call CloneTLSConfig on a config in active use by a server.
|
||||
// TODO: replace with tls.Config#Clone when we move to go1.8
|
||||
func CloneTLSConfig(cfg *tls.Config) *tls.Config {
|
||||
if cfg == nil {
|
||||
return &tls.Config{}
|
||||
}
|
||||
return &tls.Config{
|
||||
Rand: cfg.Rand,
|
||||
Time: cfg.Time,
|
||||
Certificates: cfg.Certificates,
|
||||
NameToCertificate: cfg.NameToCertificate,
|
||||
GetCertificate: cfg.GetCertificate,
|
||||
RootCAs: cfg.RootCAs,
|
||||
NextProtos: cfg.NextProtos,
|
||||
ServerName: cfg.ServerName,
|
||||
ClientAuth: cfg.ClientAuth,
|
||||
ClientCAs: cfg.ClientCAs,
|
||||
InsecureSkipVerify: cfg.InsecureSkipVerify,
|
||||
CipherSuites: cfg.CipherSuites,
|
||||
PreferServerCipherSuites: cfg.PreferServerCipherSuites,
|
||||
ClientSessionCache: cfg.ClientSessionCache,
|
||||
MinVersion: cfg.MinVersion,
|
||||
MaxVersion: cfg.MaxVersion,
|
||||
CurvePreferences: cfg.CurvePreferences,
|
||||
}
|
||||
}
|
||||
|
||||
type TLSClientConfigHolder interface {
|
||||
TLSClientConfig() *tls.Config
|
||||
}
|
||||
|
||||
func TLSClientConfig(transport http.RoundTripper) (*tls.Config, error) {
|
||||
if transport == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
switch transport := transport.(type) {
|
||||
case *http.Transport:
|
||||
return transport.TLSClientConfig, nil
|
||||
case TLSClientConfigHolder:
|
||||
return transport.TLSClientConfig(), nil
|
||||
case RoundTripperWrapper:
|
||||
return TLSClientConfig(transport.WrappedRoundTripper())
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown transport type: %v", transport)
|
||||
}
|
||||
}
|
||||
|
||||
func FormatURL(scheme string, host string, port int, path string) *url.URL {
|
||||
return &url.URL{
|
||||
Scheme: scheme,
|
||||
Host: net.JoinHostPort(host, strconv.Itoa(port)),
|
||||
Path: path,
|
||||
}
|
||||
}
|
||||
|
||||
func GetHTTPClient(req *http.Request) string {
|
||||
if userAgent, ok := req.Header["User-Agent"]; ok {
|
||||
if len(userAgent) > 0 {
|
||||
return userAgent[0]
|
||||
}
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
// Extracts and returns the clients IP from the given request.
|
||||
// Looks at X-Forwarded-For header, X-Real-Ip header and request.RemoteAddr in that order.
|
||||
// Returns nil if none of them are set or is set to an invalid value.
|
||||
func GetClientIP(req *http.Request) net.IP {
|
||||
hdr := req.Header
|
||||
// First check the X-Forwarded-For header for requests via proxy.
|
||||
hdrForwardedFor := hdr.Get("X-Forwarded-For")
|
||||
if hdrForwardedFor != "" {
|
||||
// X-Forwarded-For can be a csv of IPs in case of multiple proxies.
|
||||
// Use the first valid one.
|
||||
parts := strings.Split(hdrForwardedFor, ",")
|
||||
for _, part := range parts {
|
||||
ip := net.ParseIP(strings.TrimSpace(part))
|
||||
if ip != nil {
|
||||
return ip
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try the X-Real-Ip header.
|
||||
hdrRealIp := hdr.Get("X-Real-Ip")
|
||||
if hdrRealIp != "" {
|
||||
ip := net.ParseIP(hdrRealIp)
|
||||
if ip != nil {
|
||||
return ip
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to Remote Address in request, which will give the correct client IP when there is no proxy.
|
||||
// Remote Address in Go's HTTP server is in the form host:port so we need to split that first.
|
||||
host, _, err := net.SplitHostPort(req.RemoteAddr)
|
||||
if err == nil {
|
||||
return net.ParseIP(host)
|
||||
}
|
||||
|
||||
// Fallback if Remote Address was just IP.
|
||||
return net.ParseIP(req.RemoteAddr)
|
||||
}
|
||||
|
||||
var defaultProxyFuncPointer = fmt.Sprintf("%p", http.ProxyFromEnvironment)
|
||||
|
||||
// isDefault checks to see if the transportProxierFunc is pointing to the default one
|
||||
func isDefault(transportProxier func(*http.Request) (*url.URL, error)) bool {
|
||||
transportProxierPointer := fmt.Sprintf("%p", transportProxier)
|
||||
return transportProxierPointer == defaultProxyFuncPointer
|
||||
}
|
||||
|
||||
// NewProxierWithNoProxyCIDR constructs a Proxier function that respects CIDRs in NO_PROXY and delegates if
|
||||
// no matching CIDRs are found
|
||||
func NewProxierWithNoProxyCIDR(delegate func(req *http.Request) (*url.URL, error)) func(req *http.Request) (*url.URL, error) {
|
||||
// we wrap the default method, so we only need to perform our check if the NO_PROXY envvar has a CIDR in it
|
||||
noProxyEnv := os.Getenv("NO_PROXY")
|
||||
noProxyRules := strings.Split(noProxyEnv, ",")
|
||||
|
||||
cidrs := []*net.IPNet{}
|
||||
for _, noProxyRule := range noProxyRules {
|
||||
_, cidr, _ := net.ParseCIDR(noProxyRule)
|
||||
if cidr != nil {
|
||||
cidrs = append(cidrs, cidr)
|
||||
}
|
||||
}
|
||||
|
||||
if len(cidrs) == 0 {
|
||||
return delegate
|
||||
}
|
||||
|
||||
return func(req *http.Request) (*url.URL, error) {
|
||||
host := req.URL.Host
|
||||
// for some urls, the Host is already the host, not the host:port
|
||||
if net.ParseIP(host) == nil {
|
||||
var err error
|
||||
host, _, err = net.SplitHostPort(req.URL.Host)
|
||||
if err != nil {
|
||||
return delegate(req)
|
||||
}
|
||||
}
|
||||
|
||||
ip := net.ParseIP(host)
|
||||
if ip == nil {
|
||||
return delegate(req)
|
||||
}
|
||||
|
||||
for _, cidr := range cidrs {
|
||||
if cidr.Contains(ip) {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
return delegate(req)
|
||||
}
|
||||
}
|
278
vendor/k8s.io/kubernetes/pkg/util/net/interface.go
generated
vendored
Normal file
278
vendor/k8s.io/kubernetes/pkg/util/net/interface.go
generated
vendored
Normal file
|
@ -0,0 +1,278 @@
|
|||
/*
|
||||
Copyright 2016 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 net
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
type Route struct {
|
||||
Interface string
|
||||
Destination net.IP
|
||||
Gateway net.IP
|
||||
// TODO: add more fields here if needed
|
||||
}
|
||||
|
||||
func getRoutes(input io.Reader) ([]Route, error) {
|
||||
routes := []Route{}
|
||||
if input == nil {
|
||||
return nil, fmt.Errorf("input is nil")
|
||||
}
|
||||
scanner := bufio.NewReader(input)
|
||||
for {
|
||||
line, err := scanner.ReadString('\n')
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
//ignore the headers in the route info
|
||||
if strings.HasPrefix(line, "Iface") {
|
||||
continue
|
||||
}
|
||||
fields := strings.Fields(line)
|
||||
routes = append(routes, Route{})
|
||||
route := &routes[len(routes)-1]
|
||||
route.Interface = fields[0]
|
||||
ip, err := parseIP(fields[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
route.Destination = ip
|
||||
ip, err = parseIP(fields[2])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
route.Gateway = ip
|
||||
}
|
||||
return routes, nil
|
||||
}
|
||||
|
||||
func parseIP(str string) (net.IP, error) {
|
||||
if str == "" {
|
||||
return nil, fmt.Errorf("input is nil")
|
||||
}
|
||||
bytes, err := hex.DecodeString(str)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//TODO add ipv6 support
|
||||
if len(bytes) != net.IPv4len {
|
||||
return nil, fmt.Errorf("only IPv4 is supported")
|
||||
}
|
||||
bytes[0], bytes[1], bytes[2], bytes[3] = bytes[3], bytes[2], bytes[1], bytes[0]
|
||||
return net.IP(bytes), nil
|
||||
}
|
||||
|
||||
func isInterfaceUp(intf *net.Interface) bool {
|
||||
if intf == nil {
|
||||
return false
|
||||
}
|
||||
if intf.Flags&net.FlagUp != 0 {
|
||||
glog.V(4).Infof("Interface %v is up", intf.Name)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//getFinalIP method receives all the IP addrs of a Interface
|
||||
//and returns a nil if the address is Loopback, Ipv6, link-local or nil.
|
||||
//It returns a valid IPv4 if an Ipv4 address is found in the array.
|
||||
func getFinalIP(addrs []net.Addr) (net.IP, error) {
|
||||
if len(addrs) > 0 {
|
||||
for i := range addrs {
|
||||
glog.V(4).Infof("Checking addr %s.", addrs[i].String())
|
||||
ip, _, err := net.ParseCIDR(addrs[i].String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//Only IPv4
|
||||
//TODO : add IPv6 support
|
||||
if ip.To4() != nil {
|
||||
if !ip.IsLoopback() && !ip.IsLinkLocalMulticast() && !ip.IsLinkLocalUnicast() {
|
||||
glog.V(4).Infof("IP found %v", ip)
|
||||
return ip, nil
|
||||
} else {
|
||||
glog.V(4).Infof("Loopback/link-local found %v", ip)
|
||||
}
|
||||
} else {
|
||||
glog.V(4).Infof("%v is not a valid IPv4 address", ip)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func getIPFromInterface(intfName string, nw networkInterfacer) (net.IP, error) {
|
||||
intf, err := nw.InterfaceByName(intfName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isInterfaceUp(intf) {
|
||||
addrs, err := nw.Addrs(intf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
glog.V(4).Infof("Interface %q has %d addresses :%v.", intfName, len(addrs), addrs)
|
||||
finalIP, err := getFinalIP(addrs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if finalIP != nil {
|
||||
glog.V(4).Infof("valid IPv4 address for interface %q found as %v.", intfName, finalIP)
|
||||
return finalIP, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func flagsSet(flags net.Flags, test net.Flags) bool {
|
||||
return flags&test != 0
|
||||
}
|
||||
|
||||
func flagsClear(flags net.Flags, test net.Flags) bool {
|
||||
return flags&test == 0
|
||||
}
|
||||
|
||||
func chooseHostInterfaceNativeGo() (net.IP, error) {
|
||||
intfs, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
i := 0
|
||||
var ip net.IP
|
||||
for i = range intfs {
|
||||
if flagsSet(intfs[i].Flags, net.FlagUp) && flagsClear(intfs[i].Flags, net.FlagLoopback|net.FlagPointToPoint) {
|
||||
addrs, err := intfs[i].Addrs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(addrs) > 0 {
|
||||
for _, addr := range addrs {
|
||||
if addrIP, _, err := net.ParseCIDR(addr.String()); err == nil {
|
||||
if addrIP.To4() != nil {
|
||||
ip = addrIP.To4()
|
||||
if !ip.IsLinkLocalMulticast() && !ip.IsLinkLocalUnicast() {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ip != nil {
|
||||
// This interface should suffice.
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ip == nil {
|
||||
return nil, fmt.Errorf("no acceptable interface from host")
|
||||
}
|
||||
glog.V(4).Infof("Choosing interface %s (IP %v) as default", intfs[i].Name, ip)
|
||||
return ip, nil
|
||||
}
|
||||
|
||||
//ChooseHostInterface is a method used fetch an IP for a daemon.
|
||||
//It uses data from /proc/net/route file.
|
||||
//For a node with no internet connection ,it returns error
|
||||
//For a multi n/w interface node it returns the IP of the interface with gateway on it.
|
||||
func ChooseHostInterface() (net.IP, error) {
|
||||
inFile, err := os.Open("/proc/net/route")
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return chooseHostInterfaceNativeGo()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
defer inFile.Close()
|
||||
var nw networkInterfacer = networkInterface{}
|
||||
return chooseHostInterfaceFromRoute(inFile, nw)
|
||||
}
|
||||
|
||||
type networkInterfacer interface {
|
||||
InterfaceByName(intfName string) (*net.Interface, error)
|
||||
Addrs(intf *net.Interface) ([]net.Addr, error)
|
||||
}
|
||||
|
||||
type networkInterface struct{}
|
||||
|
||||
func (_ networkInterface) InterfaceByName(intfName string) (*net.Interface, error) {
|
||||
intf, err := net.InterfaceByName(intfName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return intf, nil
|
||||
}
|
||||
|
||||
func (_ networkInterface) Addrs(intf *net.Interface) ([]net.Addr, error) {
|
||||
addrs, err := intf.Addrs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return addrs, nil
|
||||
}
|
||||
|
||||
func chooseHostInterfaceFromRoute(inFile io.Reader, nw networkInterfacer) (net.IP, error) {
|
||||
routes, err := getRoutes(inFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
zero := net.IP{0, 0, 0, 0}
|
||||
var finalIP net.IP
|
||||
for i := range routes {
|
||||
//find interface with gateway
|
||||
if routes[i].Destination.Equal(zero) {
|
||||
glog.V(4).Infof("Default route transits interface %q", routes[i].Interface)
|
||||
finalIP, err := getIPFromInterface(routes[i].Interface, nw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if finalIP != nil {
|
||||
glog.V(4).Infof("Choosing IP %v ", finalIP)
|
||||
return finalIP, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
glog.V(4).Infof("No valid IP found")
|
||||
if finalIP == nil {
|
||||
return nil, fmt.Errorf("Unable to select an IP.")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// If bind-address is usable, return it directly
|
||||
// If bind-address is not usable (unset, 0.0.0.0, or loopback), we will use the host's default
|
||||
// interface.
|
||||
func ChooseBindAddress(bindAddress net.IP) (net.IP, error) {
|
||||
if bindAddress == nil || bindAddress.IsUnspecified() || bindAddress.IsLoopback() {
|
||||
hostIP, err := ChooseHostInterface()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bindAddress = hostIP
|
||||
}
|
||||
return bindAddress, nil
|
||||
}
|
113
vendor/k8s.io/kubernetes/pkg/util/net/port_range.go
generated
vendored
Normal file
113
vendor/k8s.io/kubernetes/pkg/util/net/port_range.go
generated
vendored
Normal file
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
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 net
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// PortRange represents a range of TCP/UDP ports. To represent a single port,
|
||||
// set Size to 1.
|
||||
type PortRange struct {
|
||||
Base int
|
||||
Size int
|
||||
}
|
||||
|
||||
// Contains tests whether a given port falls within the PortRange.
|
||||
func (pr *PortRange) Contains(p int) bool {
|
||||
return (p >= pr.Base) && ((p - pr.Base) < pr.Size)
|
||||
}
|
||||
|
||||
// String converts the PortRange to a string representation, which can be
|
||||
// parsed by PortRange.Set or ParsePortRange.
|
||||
func (pr PortRange) String() string {
|
||||
if pr.Size == 0 {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%d-%d", pr.Base, pr.Base+pr.Size-1)
|
||||
}
|
||||
|
||||
// Set parses a string of the form "min-max", inclusive at both ends, and
|
||||
// sets the PortRange from it. This is part of the flag.Value and pflag.Value
|
||||
// interfaces.
|
||||
func (pr *PortRange) Set(value string) error {
|
||||
value = strings.TrimSpace(value)
|
||||
|
||||
// TODO: Accept "80" syntax
|
||||
// TODO: Accept "80+8" syntax
|
||||
|
||||
if value == "" {
|
||||
pr.Base = 0
|
||||
pr.Size = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
hyphenIndex := strings.Index(value, "-")
|
||||
if hyphenIndex == -1 {
|
||||
return fmt.Errorf("expected hyphen in port range")
|
||||
}
|
||||
|
||||
var err error
|
||||
var low int
|
||||
var high int
|
||||
low, err = strconv.Atoi(value[:hyphenIndex])
|
||||
if err == nil {
|
||||
high, err = strconv.Atoi(value[hyphenIndex+1:])
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to parse port range: %s: %v", value, err)
|
||||
}
|
||||
|
||||
if low > 65535 || high > 65535 {
|
||||
return fmt.Errorf("the port range cannot be greater than 65535: %s", value)
|
||||
}
|
||||
|
||||
if high < low {
|
||||
return fmt.Errorf("end port cannot be less than start port: %s", value)
|
||||
}
|
||||
|
||||
pr.Base = low
|
||||
pr.Size = 1 + high - low
|
||||
return nil
|
||||
}
|
||||
|
||||
// Type returns a descriptive string about this type. This is part of the
|
||||
// pflag.Value interface.
|
||||
func (*PortRange) Type() string {
|
||||
return "portRange"
|
||||
}
|
||||
|
||||
// ParsePortRange parses a string of the form "min-max", inclusive at both
|
||||
// ends, and initializs a new PortRange from it.
|
||||
func ParsePortRange(value string) (*PortRange, error) {
|
||||
pr := &PortRange{}
|
||||
err := pr.Set(value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pr, nil
|
||||
}
|
||||
|
||||
func ParsePortRangeOrDie(value string) *PortRange {
|
||||
pr, err := ParsePortRange(value)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("couldn't parse port range %q: %v", value, err))
|
||||
}
|
||||
return pr
|
||||
}
|
77
vendor/k8s.io/kubernetes/pkg/util/net/port_split.go
generated
vendored
Normal file
77
vendor/k8s.io/kubernetes/pkg/util/net/port_split.go
generated
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
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 net
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
)
|
||||
|
||||
var validSchemes = sets.NewString("http", "https", "")
|
||||
|
||||
// SplitSchemeNamePort takes a string of the following forms:
|
||||
// * "<name>", returns "", "<name>","", true
|
||||
// * "<name>:<port>", returns "", "<name>","<port>",true
|
||||
// * "<scheme>:<name>:<port>", returns "<scheme>","<name>","<port>",true
|
||||
//
|
||||
// Name must be non-empty or valid will be returned false.
|
||||
// Scheme must be "http" or "https" if specified
|
||||
// Port is returned as a string, and it is not required to be numeric (could be
|
||||
// used for a named port, for example).
|
||||
func SplitSchemeNamePort(id string) (scheme, name, port string, valid bool) {
|
||||
parts := strings.Split(id, ":")
|
||||
switch len(parts) {
|
||||
case 1:
|
||||
name = parts[0]
|
||||
case 2:
|
||||
name = parts[0]
|
||||
port = parts[1]
|
||||
case 3:
|
||||
scheme = parts[0]
|
||||
name = parts[1]
|
||||
port = parts[2]
|
||||
default:
|
||||
return "", "", "", false
|
||||
}
|
||||
|
||||
if len(name) > 0 && validSchemes.Has(scheme) {
|
||||
return scheme, name, port, true
|
||||
} else {
|
||||
return "", "", "", false
|
||||
}
|
||||
}
|
||||
|
||||
// JoinSchemeNamePort returns a string that specifies the scheme, name, and port:
|
||||
// * "<name>"
|
||||
// * "<name>:<port>"
|
||||
// * "<scheme>:<name>:<port>"
|
||||
// None of the parameters may contain a ':' character
|
||||
// Name is required
|
||||
// Scheme must be "", "http", or "https"
|
||||
func JoinSchemeNamePort(scheme, name, port string) string {
|
||||
if len(scheme) > 0 {
|
||||
// Must include three segments to specify scheme
|
||||
return scheme + ":" + name + ":" + port
|
||||
}
|
||||
if len(port) > 0 {
|
||||
// Must include two segments to specify port
|
||||
return name + ":" + port
|
||||
}
|
||||
// Return name alone
|
||||
return name
|
||||
}
|
46
vendor/k8s.io/kubernetes/pkg/util/net/util.go
generated
vendored
Normal file
46
vendor/k8s.io/kubernetes/pkg/util/net/util.go
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
Copyright 2016 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 net
|
||||
|
||||
import (
|
||||
"net"
|
||||
"reflect"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// IPNetEqual checks if the two input IPNets are representing the same subnet.
|
||||
// For example,
|
||||
// 10.0.0.1/24 and 10.0.0.0/24 are the same subnet.
|
||||
// 10.0.0.1/24 and 10.0.0.0/25 are not the same subnet.
|
||||
func IPNetEqual(ipnet1, ipnet2 *net.IPNet) bool {
|
||||
if ipnet1 == nil || ipnet2 == nil {
|
||||
return false
|
||||
}
|
||||
if reflect.DeepEqual(ipnet1.Mask, ipnet2.Mask) && ipnet1.Contains(ipnet2.IP) && ipnet2.Contains(ipnet1.IP) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Returns if the given err is "connection reset by peer" error.
|
||||
func IsConnectionReset(err error) bool {
|
||||
opErr, ok := err.(*net.OpError)
|
||||
if ok && opErr.Err.Error() == syscall.ECONNRESET.Error() {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
0
vendor/k8s.io/kubernetes/pkg/util/sets/.readonly
generated
vendored
Normal file
0
vendor/k8s.io/kubernetes/pkg/util/sets/.readonly
generated
vendored
Normal file
65
vendor/k8s.io/kubernetes/pkg/util/sets/BUILD
generated
vendored
Normal file
65
vendor/k8s.io/kubernetes/pkg/util/sets/BUILD
generated
vendored
Normal file
|
@ -0,0 +1,65 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
":set-gen",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["set_test.go"],
|
||||
library = ":go_default_library",
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "set-gen",
|
||||
srcs = [
|
||||
"//pkg/util/sets/types:types.go",
|
||||
"//hack/boilerplate:boilerplate.go.txt",
|
||||
],
|
||||
outs = [
|
||||
"byte.go",
|
||||
"doc.go",
|
||||
"empty.go",
|
||||
"int.go",
|
||||
"int64.go",
|
||||
"string.go",
|
||||
],
|
||||
cmd = """
|
||||
$(location //cmd/libs/go2idl/set-gen) \
|
||||
--input-dirs ./pkg/util/sets/types \
|
||||
--output-base $(GENDIR)/pkg/util \
|
||||
--go-header-file $(location //hack/boilerplate:boilerplate.go.txt) \
|
||||
--output-package sets
|
||||
""",
|
||||
tools = [
|
||||
"//cmd/libs/go2idl/set-gen",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [
|
||||
":package-srcs",
|
||||
"//pkg/util/sets/types:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
)
|
203
vendor/k8s.io/kubernetes/pkg/util/sets/byte.go
generated
vendored
Normal file
203
vendor/k8s.io/kubernetes/pkg/util/sets/byte.go
generated
vendored
Normal file
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
// This file was autogenerated by set-gen. Do not edit it manually!
|
||||
|
||||
package sets
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// sets.Byte is a set of bytes, implemented via map[byte]struct{} for minimal memory consumption.
|
||||
type Byte map[byte]Empty
|
||||
|
||||
// New creates a Byte from a list of values.
|
||||
func NewByte(items ...byte) Byte {
|
||||
ss := Byte{}
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
}
|
||||
|
||||
// ByteKeySet creates a Byte from a keys of a map[byte](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func ByteKeySet(theMap interface{}) Byte {
|
||||
v := reflect.ValueOf(theMap)
|
||||
ret := Byte{}
|
||||
|
||||
for _, keyValue := range v.MapKeys() {
|
||||
ret.Insert(keyValue.Interface().(byte))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s Byte) Insert(items ...byte) {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s Byte) Delete(items ...byte) {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s Byte) Has(item byte) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s Byte) HasAll(items ...byte) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s Byte) HasAny(items ...byte) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s Byte) Difference(s2 Byte) Byte {
|
||||
result := NewByte()
|
||||
for key := range s {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a3, a4}
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 Byte) Union(s2 Byte) Byte {
|
||||
result := NewByte()
|
||||
for key := range s1 {
|
||||
result.Insert(key)
|
||||
}
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 Byte) Intersection(s2 Byte) Byte {
|
||||
var walk, other Byte
|
||||
result := NewByte()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 Byte) IsSuperset(s2 Byte) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 Byte) Equal(s2 Byte) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
}
|
||||
|
||||
type sortableSliceOfByte []byte
|
||||
|
||||
func (s sortableSliceOfByte) Len() int { return len(s) }
|
||||
func (s sortableSliceOfByte) Less(i, j int) bool { return lessByte(s[i], s[j]) }
|
||||
func (s sortableSliceOfByte) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// List returns the contents as a sorted byte slice.
|
||||
func (s Byte) List() []byte {
|
||||
res := make(sortableSliceOfByte, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return []byte(res)
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s Byte) UnsortedList() []byte {
|
||||
res := make([]byte, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Returns a single element from the set.
|
||||
func (s Byte) PopAny() (byte, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue byte
|
||||
return zeroValue, false
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s Byte) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func lessByte(lhs, rhs byte) bool {
|
||||
return lhs < rhs
|
||||
}
|
20
vendor/k8s.io/kubernetes/pkg/util/sets/doc.go
generated
vendored
Normal file
20
vendor/k8s.io/kubernetes/pkg/util/sets/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
// This file was autogenerated by set-gen. Do not edit it manually!
|
||||
|
||||
// Package sets has auto-generated set types.
|
||||
package sets
|
23
vendor/k8s.io/kubernetes/pkg/util/sets/empty.go
generated
vendored
Normal file
23
vendor/k8s.io/kubernetes/pkg/util/sets/empty.go
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
// This file was autogenerated by set-gen. Do not edit it manually!
|
||||
|
||||
package sets
|
||||
|
||||
// Empty is public since it is used by some internal API objects for conversions between external
|
||||
// string arrays and internal sets, and conversion logic requires public types today.
|
||||
type Empty struct{}
|
203
vendor/k8s.io/kubernetes/pkg/util/sets/int.go
generated
vendored
Normal file
203
vendor/k8s.io/kubernetes/pkg/util/sets/int.go
generated
vendored
Normal file
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
// This file was autogenerated by set-gen. Do not edit it manually!
|
||||
|
||||
package sets
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// sets.Int is a set of ints, implemented via map[int]struct{} for minimal memory consumption.
|
||||
type Int map[int]Empty
|
||||
|
||||
// New creates a Int from a list of values.
|
||||
func NewInt(items ...int) Int {
|
||||
ss := Int{}
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
}
|
||||
|
||||
// IntKeySet creates a Int from a keys of a map[int](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func IntKeySet(theMap interface{}) Int {
|
||||
v := reflect.ValueOf(theMap)
|
||||
ret := Int{}
|
||||
|
||||
for _, keyValue := range v.MapKeys() {
|
||||
ret.Insert(keyValue.Interface().(int))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s Int) Insert(items ...int) {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s Int) Delete(items ...int) {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s Int) Has(item int) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s Int) HasAll(items ...int) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s Int) HasAny(items ...int) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s Int) Difference(s2 Int) Int {
|
||||
result := NewInt()
|
||||
for key := range s {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a3, a4}
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 Int) Union(s2 Int) Int {
|
||||
result := NewInt()
|
||||
for key := range s1 {
|
||||
result.Insert(key)
|
||||
}
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 Int) Intersection(s2 Int) Int {
|
||||
var walk, other Int
|
||||
result := NewInt()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 Int) IsSuperset(s2 Int) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 Int) Equal(s2 Int) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
}
|
||||
|
||||
type sortableSliceOfInt []int
|
||||
|
||||
func (s sortableSliceOfInt) Len() int { return len(s) }
|
||||
func (s sortableSliceOfInt) Less(i, j int) bool { return lessInt(s[i], s[j]) }
|
||||
func (s sortableSliceOfInt) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// List returns the contents as a sorted int slice.
|
||||
func (s Int) List() []int {
|
||||
res := make(sortableSliceOfInt, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return []int(res)
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s Int) UnsortedList() []int {
|
||||
res := make([]int, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Returns a single element from the set.
|
||||
func (s Int) PopAny() (int, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue int
|
||||
return zeroValue, false
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s Int) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func lessInt(lhs, rhs int) bool {
|
||||
return lhs < rhs
|
||||
}
|
203
vendor/k8s.io/kubernetes/pkg/util/sets/int64.go
generated
vendored
Normal file
203
vendor/k8s.io/kubernetes/pkg/util/sets/int64.go
generated
vendored
Normal file
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
// This file was autogenerated by set-gen. Do not edit it manually!
|
||||
|
||||
package sets
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// sets.Int64 is a set of int64s, implemented via map[int64]struct{} for minimal memory consumption.
|
||||
type Int64 map[int64]Empty
|
||||
|
||||
// New creates a Int64 from a list of values.
|
||||
func NewInt64(items ...int64) Int64 {
|
||||
ss := Int64{}
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
}
|
||||
|
||||
// Int64KeySet creates a Int64 from a keys of a map[int64](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func Int64KeySet(theMap interface{}) Int64 {
|
||||
v := reflect.ValueOf(theMap)
|
||||
ret := Int64{}
|
||||
|
||||
for _, keyValue := range v.MapKeys() {
|
||||
ret.Insert(keyValue.Interface().(int64))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s Int64) Insert(items ...int64) {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s Int64) Delete(items ...int64) {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s Int64) Has(item int64) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s Int64) HasAll(items ...int64) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s Int64) HasAny(items ...int64) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s Int64) Difference(s2 Int64) Int64 {
|
||||
result := NewInt64()
|
||||
for key := range s {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a3, a4}
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 Int64) Union(s2 Int64) Int64 {
|
||||
result := NewInt64()
|
||||
for key := range s1 {
|
||||
result.Insert(key)
|
||||
}
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 Int64) Intersection(s2 Int64) Int64 {
|
||||
var walk, other Int64
|
||||
result := NewInt64()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 Int64) IsSuperset(s2 Int64) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 Int64) Equal(s2 Int64) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
}
|
||||
|
||||
type sortableSliceOfInt64 []int64
|
||||
|
||||
func (s sortableSliceOfInt64) Len() int { return len(s) }
|
||||
func (s sortableSliceOfInt64) Less(i, j int) bool { return lessInt64(s[i], s[j]) }
|
||||
func (s sortableSliceOfInt64) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// List returns the contents as a sorted int64 slice.
|
||||
func (s Int64) List() []int64 {
|
||||
res := make(sortableSliceOfInt64, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return []int64(res)
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s Int64) UnsortedList() []int64 {
|
||||
res := make([]int64, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Returns a single element from the set.
|
||||
func (s Int64) PopAny() (int64, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue int64
|
||||
return zeroValue, false
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s Int64) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func lessInt64(lhs, rhs int64) bool {
|
||||
return lhs < rhs
|
||||
}
|
203
vendor/k8s.io/kubernetes/pkg/util/sets/string.go
generated
vendored
Normal file
203
vendor/k8s.io/kubernetes/pkg/util/sets/string.go
generated
vendored
Normal file
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
// This file was autogenerated by set-gen. Do not edit it manually!
|
||||
|
||||
package sets
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// sets.String is a set of strings, implemented via map[string]struct{} for minimal memory consumption.
|
||||
type String map[string]Empty
|
||||
|
||||
// New creates a String from a list of values.
|
||||
func NewString(items ...string) String {
|
||||
ss := String{}
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
}
|
||||
|
||||
// StringKeySet creates a String from a keys of a map[string](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func StringKeySet(theMap interface{}) String {
|
||||
v := reflect.ValueOf(theMap)
|
||||
ret := String{}
|
||||
|
||||
for _, keyValue := range v.MapKeys() {
|
||||
ret.Insert(keyValue.Interface().(string))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s String) Insert(items ...string) {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s String) Delete(items ...string) {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s String) Has(item string) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s String) HasAll(items ...string) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s String) HasAny(items ...string) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s String) Difference(s2 String) String {
|
||||
result := NewString()
|
||||
for key := range s {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a3, a4}
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 String) Union(s2 String) String {
|
||||
result := NewString()
|
||||
for key := range s1 {
|
||||
result.Insert(key)
|
||||
}
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 String) Intersection(s2 String) String {
|
||||
var walk, other String
|
||||
result := NewString()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 String) IsSuperset(s2 String) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 String) Equal(s2 String) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
}
|
||||
|
||||
type sortableSliceOfString []string
|
||||
|
||||
func (s sortableSliceOfString) Len() int { return len(s) }
|
||||
func (s sortableSliceOfString) Less(i, j int) bool { return lessString(s[i], s[j]) }
|
||||
func (s sortableSliceOfString) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// List returns the contents as a sorted string slice.
|
||||
func (s String) List() []string {
|
||||
res := make(sortableSliceOfString, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return []string(res)
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s String) UnsortedList() []string {
|
||||
res := make([]string, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Returns a single element from the set.
|
||||
func (s String) PopAny() (string, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue string
|
||||
return zeroValue, false
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s String) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func lessString(lhs, rhs string) bool {
|
||||
return lhs < rhs
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue