move cri to oci package
parent
5c1145bcd8
commit
46df68ca4b
1
go.sum
1
go.sum
|
@ -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/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/medyagh/kic v0.0.16 h1:Ty44nRMd/CiEX5Bu3+0qhNdeAWYMhQR62ab2YNjM1Gk=
|
||||
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/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
|
||||
|
|
|
@ -24,8 +24,8 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
pkgdrivers "k8s.io/minikube/pkg/drivers"
|
||||
"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/pkg/drivers/kic/cri"
|
||||
)
|
||||
|
||||
// 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
|
||||
Memory: strconv.Itoa(d.Memory) + "mb", // TODO: change kic to take int
|
||||
Role: "control-plane",
|
||||
ExtraMounts: []cri.Mount{},
|
||||
ExtraPortMappings: []cri.PortMapping{},
|
||||
APIServerAddress: "127.0.0.1", // MEDYA:TODO make configurable
|
||||
ExtraMounts: []oci.Mount{},
|
||||
ExtraPortMappings: []oci.PortMapping{},
|
||||
APIServerAddress: "127.0.0.1", // medyagh:TODO make configurable
|
||||
APIServerPort: d.APIServerPort,
|
||||
IPv6: false, // MEDYA:TODO add proxy envs here
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/docker/machine/libmachine/state"
|
||||
"k8s.io/minikube/pkg/drivers/kic/cri"
|
||||
"k8s.io/minikube/pkg/drivers/kic/oci"
|
||||
"k8s.io/minikube/pkg/minikube/assets"
|
||||
"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
|
||||
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 {
|
||||
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 {
|
||||
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.
|
||||
ClusterLabel string
|
||||
Role string // currently only role supported is control-plane
|
||||
Mounts []cri.Mount
|
||||
PortMappings []cri.PortMapping
|
||||
Mounts []oci.Mount
|
||||
PortMappings []oci.PortMapping
|
||||
Cpus string
|
||||
Memory string
|
||||
Envs map[string]string
|
||||
|
|
|
@ -24,7 +24,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/minikube/pkg/drivers/kic/cri"
|
||||
"k8s.io/minikube/pkg/drivers/kic/oci"
|
||||
"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/
|
||||
CPUs string // for example 2
|
||||
Memory string
|
||||
ExtraMounts []cri.Mount
|
||||
ExtraPortMappings []cri.PortMapping
|
||||
ExtraMounts []oci.Mount
|
||||
ExtraPortMappings []oci.PortMapping
|
||||
APIServerPort int32
|
||||
APIServerAddress string
|
||||
IPv6 bool
|
||||
|
@ -60,7 +60,7 @@ func (d *Spec) Create(cmder command.Runner) (node *Node, err error) {
|
|||
|
||||
switch d.Role {
|
||||
case "control-plane":
|
||||
params.PortMappings = append(params.PortMappings, cri.PortMapping{
|
||||
params.PortMappings = append(params.PortMappings, oci.PortMapping{
|
||||
ListenAddress: d.APIServerAddress,
|
||||
HostPort: d.APIServerPort,
|
||||
ContainerPort: 6443,
|
||||
|
|
|
@ -15,30 +15,22 @@ package oci
|
|||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"github.com/docker/machine/libmachine/state"
|
||||
"k8s.io/minikube/pkg/minikube/assets"
|
||||
|
||||
"bufio"
|
||||
"bytes"
|
||||
"os/exec"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/minikube/pkg/drives/kic/cri"
|
||||
|
||||
"github.com/cenkalti/backoff"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// can be podman
|
||||
|
@ -201,7 +193,7 @@ https://github.com/kubernetes/kubernetes/blob/07a5488b2a8f67add543da72e8819407d8
|
|||
// is a comma-separated list of the following strings:
|
||||
// 'ro', if the path is read only
|
||||
// 'Z', if the volume requires SELinux relabeling
|
||||
func generateMountBindings(mounts ...cri.Mount) []string {
|
||||
func generateMountBindings(mounts ...Mount) []string {
|
||||
result := make([]string, 0, len(mounts))
|
||||
for _, m := range mounts {
|
||||
bind := fmt.Sprintf("%s:%s", m.HostPath, m.ContainerPath)
|
||||
|
@ -217,11 +209,11 @@ func generateMountBindings(mounts ...cri.Mount) []string {
|
|||
attrs = append(attrs, "Z")
|
||||
}
|
||||
switch m.Propagation {
|
||||
case cri.MountPropagationNone:
|
||||
case MountPropagationNone:
|
||||
// noop, private is default
|
||||
case cri.MountPropagationBidirectional:
|
||||
case MountPropagationBidirectional:
|
||||
attrs = append(attrs, "rshared")
|
||||
case cri.MountPropagationHostToContainer:
|
||||
case MountPropagationHostToContainer:
|
||||
attrs = append(attrs, "rslave")
|
||||
default:
|
||||
// Falls back to "private"
|
||||
|
@ -285,7 +277,7 @@ func UsernsRemap() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func generatePortMappings(portMappings ...cri.PortMapping) []string {
|
||||
func generatePortMappings(portMappings ...PortMapping) []string {
|
||||
result := make([]string, 0, len(portMappings))
|
||||
for _, pm := range portMappings {
|
||||
var hostPortBinding string
|
||||
|
@ -325,8 +317,8 @@ type CreateOpt func(*createOpts) *createOpts
|
|||
type createOpts struct {
|
||||
RunArgs []string
|
||||
ContainerArgs []string
|
||||
Mounts []cri.Mount
|
||||
PortMappings []cri.PortMapping
|
||||
Mounts []Mount
|
||||
PortMappings []PortMapping
|
||||
}
|
||||
|
||||
// CreateContainer creates a container with "docker/podman run"
|
||||
|
@ -382,7 +374,7 @@ func WithRunArgs(args ...string) CreateOpt {
|
|||
}
|
||||
|
||||
// WithMounts sets the container mounts
|
||||
func WithMounts(mounts []cri.Mount) CreateOpt {
|
||||
func WithMounts(mounts []Mount) CreateOpt {
|
||||
return func(r *createOpts) *createOpts {
|
||||
r.Mounts = mounts
|
||||
return r
|
||||
|
@ -390,7 +382,7 @@ func WithMounts(mounts []cri.Mount) CreateOpt {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
r.PortMappings = portMappings
|
||||
return r
|
||||
|
@ -398,16 +390,15 @@ func WithPortMappings(portMappings []cri.PortMapping) CreateOpt {
|
|||
}
|
||||
|
||||
// Copy copies a local asset into the container
|
||||
func Copy(ociBinary string, ociID string, asset assets.CopyAsset) error {
|
||||
if _, err := os.Stat(asset.AssetName); os.IsNotExist(err) {
|
||||
return errors.Wrapf(err, "error source %s does not exist", asset.AssetName)
|
||||
func Copy(ociBinary string, ociID string, asset assets.CopyableFile) error {
|
||||
if _, err := os.Stat(asset.GetAssetName()); os.IsNotExist(err) {
|
||||
return errors.Wrapf(err, "error source %s does not exist", asset.GetAssetName())
|
||||
}
|
||||
|
||||
destination := fmt.Sprintf("%s:%s", ociID, asset.TargetPath())
|
||||
cmd := exec.Command(ociBinary, "cp", asset.AssetName, destination)
|
||||
destination := fmt.Sprintf("%s:%s", ociID, asset.GetTargetDir())
|
||||
cmd := exec.Command(ociBinary, "cp", asset.GetAssetName(), destination)
|
||||
err := cmd.Run()
|
||||
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
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
/*
|
||||
Copyright 2019 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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.
|
||||
|
@ -14,7 +11,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cri
|
||||
package oci
|
||||
|
||||
/*
|
||||
These types are from
|
|
@ -127,24 +127,24 @@ func (k *kicRunner) Copy(f assets.CopyableFile) error {
|
|||
fc := make([]byte, f.GetLength()) // Read asset file into a []byte
|
||||
if _, err := f.Read(fc); err != nil {
|
||||
return errors.Wrap(err, "can't copy non-existing file")
|
||||
} else { // we have a MemoryAsset, will write to disk before copying
|
||||
tmpFile, err := ioutil.TempFile(os.TempDir(), "tmpf-memory-asset")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "creating temporary file")
|
||||
}
|
||||
// clean up the temp file
|
||||
defer os.Remove(tmpFile.Name())
|
||||
if _, err = tmpFile.Write(fc); err != nil {
|
||||
return errors.Wrap(err, "write to temporary file")
|
||||
}
|
||||
|
||||
// Close the file
|
||||
if err := tmpFile.Close(); err != nil {
|
||||
return errors.Wrap(err, "close temporary file")
|
||||
}
|
||||
assetName = tmpFile.Name()
|
||||
} // we have a MemoryAsset, will write to disk before copying
|
||||
|
||||
tmpFile, err := ioutil.TempFile(os.TempDir(), "tmpf-memory-asset")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "creating temporary file")
|
||||
}
|
||||
// clean up the temp file
|
||||
defer os.Remove(tmpFile.Name())
|
||||
if _, err = tmpFile.Write(fc); err != nil {
|
||||
return errors.Wrap(err, "write to temporary file")
|
||||
}
|
||||
|
||||
// Close the file
|
||||
if err := tmpFile.Close(); err != nil {
|
||||
return errors.Wrap(err, "close temporary file")
|
||||
}
|
||||
assetName = tmpFile.Name()
|
||||
|
||||
}
|
||||
// based of format of "docker cp containerName:destination"
|
||||
destination := fmt.Sprintf("%s:%s/%s", k.nameOrID, f.GetTargetDir(), f.GetTargetName())
|
||||
|
|
Loading…
Reference in New Issue