move cri to oci package

pull/6112/head
Medya Gh 2019-12-17 16:04:03 -08:00
parent 5c1145bcd8
commit 46df68ca4b
7 changed files with 46 additions and 57 deletions

1
go.sum
View File

@ -347,6 +347,7 @@ github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp
github.com/mattn/go-shellwords v0.0.0-20180605041737-f8471b0a71de/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= github.com/mattn/go-shellwords v0.0.0-20180605041737-f8471b0a71de/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/medyagh/kic v0.0.16 h1:Ty44nRMd/CiEX5Bu3+0qhNdeAWYMhQR62ab2YNjM1Gk=
github.com/mesos/mesos-go v0.0.9/go.mod h1:kPYCMQ9gsOXVAle1OsoY4I1+9kPu8GHkf88aV59fDr4= github.com/mesos/mesos-go v0.0.9/go.mod h1:kPYCMQ9gsOXVAle1OsoY4I1+9kPu8GHkf88aV59fDr4=
github.com/mholt/caddy v0.0.0-20180213163048-2de495001514/go.mod h1:Wb1PlT4DAYSqOEd03MsqkdkXnTxA8v9pKjdpxbqM1kY= github.com/mholt/caddy v0.0.0-20180213163048-2de495001514/go.mod h1:Wb1PlT4DAYSqOEd03MsqkdkXnTxA8v9pKjdpxbqM1kY=
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=

View File

@ -24,8 +24,8 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
pkgdrivers "k8s.io/minikube/pkg/drivers" pkgdrivers "k8s.io/minikube/pkg/drivers"
"k8s.io/minikube/pkg/drivers/kic/node" "k8s.io/minikube/pkg/drivers/kic/node"
"k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/minikube/command" "k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/pkg/drivers/kic/cri"
) )
// https://minikube.sigs.k8s.io/docs/reference/drivers/kic/ // https://minikube.sigs.k8s.io/docs/reference/drivers/kic/
@ -78,9 +78,9 @@ func (d *Driver) Create() error {
CPUs: strconv.Itoa(d.CPU), //TODO: change kic to take int CPUs: strconv.Itoa(d.CPU), //TODO: change kic to take int
Memory: strconv.Itoa(d.Memory) + "mb", // TODO: change kic to take int Memory: strconv.Itoa(d.Memory) + "mb", // TODO: change kic to take int
Role: "control-plane", Role: "control-plane",
ExtraMounts: []cri.Mount{}, ExtraMounts: []oci.Mount{},
ExtraPortMappings: []cri.PortMapping{}, ExtraPortMappings: []oci.PortMapping{},
APIServerAddress: "127.0.0.1", // MEDYA:TODO make configurable APIServerAddress: "127.0.0.1", // medyagh:TODO make configurable
APIServerPort: d.APIServerPort, APIServerPort: d.APIServerPort,
IPv6: false, // MEDYA:TODO add proxy envs here IPv6: false, // MEDYA:TODO add proxy envs here
} }

View File

@ -24,7 +24,6 @@ import (
"strings" "strings"
"github.com/docker/machine/libmachine/state" "github.com/docker/machine/libmachine/state"
"k8s.io/minikube/pkg/drivers/kic/cri"
"k8s.io/minikube/pkg/drivers/kic/oci" "k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/minikube/assets" "k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/command" "k8s.io/minikube/pkg/minikube/command"
@ -113,12 +112,13 @@ func (n *Node) LoadImageArchive(image io.Reader) error {
} }
// Copy copies a local asset into the node // Copy copies a local asset into the node
func (n *Node) Copy(ociBinary string, asset assets.CopyAsset) error { func (n *Node) Copy(ociBinary string, asset assets.CopyableFile) error {
if err := oci.Copy(ociBinary, n.name, asset); err != nil { if err := oci.Copy(ociBinary, n.name, asset); err != nil {
return errors.Wrap(err, "failed to copy file/folder") return errors.Wrap(err, "failed to copy file/folder")
} }
cmd := exec.Command("chmod", asset.Permissions, asset.TargetPath()) // TODO: medya verify add tests
cmd := exec.Command("chmod", asset.GetPermissions(), asset.GetTargetName())
if _, err := n.R.RunCmd(cmd); err != nil { if _, err := n.R.RunCmd(cmd); err != nil {
return errors.Wrap(err, "failed to chmod file permissions") return errors.Wrap(err, "failed to chmod file permissions")
} }
@ -150,8 +150,8 @@ type CreateParams struct {
Image string // container image to use to create the node. Image string // container image to use to create the node.
ClusterLabel string ClusterLabel string
Role string // currently only role supported is control-plane Role string // currently only role supported is control-plane
Mounts []cri.Mount Mounts []oci.Mount
PortMappings []cri.PortMapping PortMappings []oci.PortMapping
Cpus string Cpus string
Memory string Memory string
Envs map[string]string Envs map[string]string

View File

@ -24,7 +24,7 @@ import (
"strings" "strings"
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/minikube/pkg/drivers/kic/cri" "k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/minikube/command" "k8s.io/minikube/pkg/minikube/command"
) )
@ -37,8 +37,8 @@ type Spec struct {
Image string // for example 4000mb based on https://docs.docker.com/config/containers/resource_constraints/ Image string // for example 4000mb based on https://docs.docker.com/config/containers/resource_constraints/
CPUs string // for example 2 CPUs string // for example 2
Memory string Memory string
ExtraMounts []cri.Mount ExtraMounts []oci.Mount
ExtraPortMappings []cri.PortMapping ExtraPortMappings []oci.PortMapping
APIServerPort int32 APIServerPort int32
APIServerAddress string APIServerAddress string
IPv6 bool IPv6 bool
@ -60,7 +60,7 @@ func (d *Spec) Create(cmder command.Runner) (node *Node, err error) {
switch d.Role { switch d.Role {
case "control-plane": case "control-plane":
params.PortMappings = append(params.PortMappings, cri.PortMapping{ params.PortMappings = append(params.PortMappings, oci.PortMapping{
ListenAddress: d.APIServerAddress, ListenAddress: d.APIServerAddress,
HostPort: d.APIServerPort, HostPort: d.APIServerPort,
ContainerPort: 6443, ContainerPort: 6443,

View File

@ -15,30 +15,22 @@ package oci
import ( import (
"os" "os"
"os/exec"
"github.com/docker/machine/libmachine/state" "github.com/docker/machine/libmachine/state"
"k8s.io/minikube/pkg/minikube/assets" "k8s.io/minikube/pkg/minikube/assets"
"bufio" "bufio"
"bytes" "bytes"
"os/exec"
"github.com/pkg/errors" "github.com/pkg/errors"
"bufio"
"bytes"
"fmt" "fmt"
"net" "net"
"os/exec" "os/exec"
"strings" "strings"
"time" "time"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/drives/kic/cri"
"github.com/cenkalti/backoff" "github.com/cenkalti/backoff"
"github.com/pkg/errors"
) )
// can be podman // can be podman
@ -201,7 +193,7 @@ https://github.com/kubernetes/kubernetes/blob/07a5488b2a8f67add543da72e8819407d8
// is a comma-separated list of the following strings: // is a comma-separated list of the following strings:
// 'ro', if the path is read only // 'ro', if the path is read only
// 'Z', if the volume requires SELinux relabeling // 'Z', if the volume requires SELinux relabeling
func generateMountBindings(mounts ...cri.Mount) []string { func generateMountBindings(mounts ...Mount) []string {
result := make([]string, 0, len(mounts)) result := make([]string, 0, len(mounts))
for _, m := range mounts { for _, m := range mounts {
bind := fmt.Sprintf("%s:%s", m.HostPath, m.ContainerPath) bind := fmt.Sprintf("%s:%s", m.HostPath, m.ContainerPath)
@ -217,11 +209,11 @@ func generateMountBindings(mounts ...cri.Mount) []string {
attrs = append(attrs, "Z") attrs = append(attrs, "Z")
} }
switch m.Propagation { switch m.Propagation {
case cri.MountPropagationNone: case MountPropagationNone:
// noop, private is default // noop, private is default
case cri.MountPropagationBidirectional: case MountPropagationBidirectional:
attrs = append(attrs, "rshared") attrs = append(attrs, "rshared")
case cri.MountPropagationHostToContainer: case MountPropagationHostToContainer:
attrs = append(attrs, "rslave") attrs = append(attrs, "rslave")
default: default:
// Falls back to "private" // Falls back to "private"
@ -285,7 +277,7 @@ func UsernsRemap() bool {
return false return false
} }
func generatePortMappings(portMappings ...cri.PortMapping) []string { func generatePortMappings(portMappings ...PortMapping) []string {
result := make([]string, 0, len(portMappings)) result := make([]string, 0, len(portMappings))
for _, pm := range portMappings { for _, pm := range portMappings {
var hostPortBinding string var hostPortBinding string
@ -325,8 +317,8 @@ type CreateOpt func(*createOpts) *createOpts
type createOpts struct { type createOpts struct {
RunArgs []string RunArgs []string
ContainerArgs []string ContainerArgs []string
Mounts []cri.Mount Mounts []Mount
PortMappings []cri.PortMapping PortMappings []PortMapping
} }
// CreateContainer creates a container with "docker/podman run" // CreateContainer creates a container with "docker/podman run"
@ -382,7 +374,7 @@ func WithRunArgs(args ...string) CreateOpt {
} }
// WithMounts sets the container mounts // WithMounts sets the container mounts
func WithMounts(mounts []cri.Mount) CreateOpt { func WithMounts(mounts []Mount) CreateOpt {
return func(r *createOpts) *createOpts { return func(r *createOpts) *createOpts {
r.Mounts = mounts r.Mounts = mounts
return r return r
@ -390,7 +382,7 @@ func WithMounts(mounts []cri.Mount) CreateOpt {
} }
// WithPortMappings sets the container port mappings to the host // WithPortMappings sets the container port mappings to the host
func WithPortMappings(portMappings []cri.PortMapping) CreateOpt { func WithPortMappings(portMappings []PortMapping) CreateOpt {
return func(r *createOpts) *createOpts { return func(r *createOpts) *createOpts {
r.PortMappings = portMappings r.PortMappings = portMappings
return r return r
@ -398,16 +390,15 @@ func WithPortMappings(portMappings []cri.PortMapping) CreateOpt {
} }
// Copy copies a local asset into the container // Copy copies a local asset into the container
func Copy(ociBinary string, ociID string, asset assets.CopyAsset) error { func Copy(ociBinary string, ociID string, asset assets.CopyableFile) error {
if _, err := os.Stat(asset.AssetName); os.IsNotExist(err) { if _, err := os.Stat(asset.GetAssetName()); os.IsNotExist(err) {
return errors.Wrapf(err, "error source %s does not exist", asset.AssetName) return errors.Wrapf(err, "error source %s does not exist", asset.GetAssetName())
} }
destination := fmt.Sprintf("%s:%s", ociID, asset.GetTargetDir())
destination := fmt.Sprintf("%s:%s", ociID, asset.TargetPath()) cmd := exec.Command(ociBinary, "cp", asset.GetAssetName(), destination)
cmd := exec.Command(ociBinary, "cp", asset.AssetName, destination)
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
return errors.Wrapf(err, "error copying %s into node", asset.AssetName) return errors.Wrapf(err, "error copying %s into node", asset.GetAssetName())
} }
return nil return nil
} }

View File

@ -1,12 +1,9 @@
/* /*
Copyright 2019 The Kubernetes Authors All rights reserved. Copyright 2019 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -14,7 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package cri package oci
/* /*
These types are from These types are from

View File

@ -127,7 +127,8 @@ func (k *kicRunner) Copy(f assets.CopyableFile) error {
fc := make([]byte, f.GetLength()) // Read asset file into a []byte fc := make([]byte, f.GetLength()) // Read asset file into a []byte
if _, err := f.Read(fc); err != nil { if _, err := f.Read(fc); err != nil {
return errors.Wrap(err, "can't copy non-existing file") return errors.Wrap(err, "can't copy non-existing file")
} else { // we have a MemoryAsset, will write to disk before copying } // we have a MemoryAsset, will write to disk before copying
tmpFile, err := ioutil.TempFile(os.TempDir(), "tmpf-memory-asset") tmpFile, err := ioutil.TempFile(os.TempDir(), "tmpf-memory-asset")
if err != nil { if err != nil {
return errors.Wrap(err, "creating temporary file") return errors.Wrap(err, "creating temporary file")
@ -145,7 +146,6 @@ func (k *kicRunner) Copy(f assets.CopyableFile) error {
assetName = tmpFile.Name() assetName = tmpFile.Name()
} }
}
// based of format of "docker cp containerName:destination" // based of format of "docker cp containerName:destination"
destination := fmt.Sprintf("%s:%s/%s", k.nameOrID, f.GetTargetDir(), f.GetTargetName()) destination := fmt.Sprintf("%s:%s/%s", k.nameOrID, f.GetTargetDir(), f.GetTargetName())
// make sure dir exists inside the container // make sure dir exists inside the container