summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
Diffstat (limited to 'libpod')
-rw-r--r--libpod/image/utils.go22
-rw-r--r--libpod/kube.go34
-rw-r--r--libpod/runtime.go5
3 files changed, 50 insertions, 11 deletions
diff --git a/libpod/image/utils.go b/libpod/image/utils.go
index 9a75ca6dc..b944de1bb 100644
--- a/libpod/image/utils.go
+++ b/libpod/image/utils.go
@@ -2,6 +2,8 @@ package image
import (
"io"
+ "net/url"
+ "regexp"
"strings"
cp "github.com/containers/image/copy"
@@ -117,3 +119,23 @@ func GetAdditionalTags(images []string) ([]reference.NamedTagged, error) {
}
return allTags, nil
}
+
+// IsValidImageURI checks if image name has valid format
+func IsValidImageURI(imguri string) (bool, error) {
+ uri := "http://" + imguri
+ u, err := url.Parse(uri)
+ if err != nil {
+ return false, errors.Wrapf(err, "invalid image uri: %s", imguri)
+ }
+ reg := regexp.MustCompile(`^[a-zA-Z0-9-_\.]+\/?:?[0-9]*[a-z0-9-\/:]*$`)
+ ret := reg.FindAllString(u.Host, -1)
+ if len(ret) == 0 {
+ return false, errors.Wrapf(err, "invalid image uri: %s", imguri)
+ }
+ reg = regexp.MustCompile(`^[a-z0-9-:\./]*$`)
+ ret = reg.FindAllString(u.Fragment, -1)
+ if len(ret) == 0 {
+ return false, errors.Wrapf(err, "invalid image uri: %s", imguri)
+ }
+ return true, nil
+}
diff --git a/libpod/kube.go b/libpod/kube.go
index c164ca0c5..f34805e39 100644
--- a/libpod/kube.go
+++ b/libpod/kube.go
@@ -30,7 +30,10 @@ func (c *Container) GenerateForKube() (*v1.Pod, error) {
// one v1.Pod description
func (p *Pod) GenerateForKube() (*v1.Pod, []v1.ServicePort, error) {
// Generate the v1.Pod yaml description
- var servicePorts []v1.ServicePort
+ var (
+ servicePorts []v1.ServicePort
+ ports []v1.ContainerPort
+ )
allContainers, err := p.allContainers()
if err != nil {
@@ -51,13 +54,13 @@ func (p *Pod) GenerateForKube() (*v1.Pod, []v1.ServicePort, error) {
return nil, servicePorts, err
}
- ports, err := ocicniPortMappingToContainerPort(infraContainer.config.PortMappings)
+ ports, err = ocicniPortMappingToContainerPort(infraContainer.config.PortMappings)
if err != nil {
return nil, servicePorts, err
}
servicePorts = containerPortsToServicePorts(ports)
}
- pod, err := p.podWithContainers(allContainers)
+ pod, err := p.podWithContainers(allContainers, ports)
return pod, servicePorts, err
}
@@ -124,18 +127,27 @@ func containersToServicePorts(containers []v1.Container) []v1.ServicePort {
return sps
}
-func (p *Pod) podWithContainers(containers []*Container) (*v1.Pod, error) {
- var podContainers []v1.Container
+func (p *Pod) podWithContainers(containers []*Container, ports []v1.ContainerPort) (*v1.Pod, error) {
+ var (
+ podContainers []v1.Container
+ )
+ first := true
for _, ctr := range containers {
- result, err := containerToV1Container(ctr)
- if err != nil {
- return nil, err
- }
if !ctr.IsInfra() {
+ result, err := containerToV1Container(ctr)
+ if err != nil {
+ return nil, err
+ }
+ // We add the original port declarations from the libpod infra container
+ // to the first kubernetes container description because otherwise we loose
+ // the original container/port bindings.
+ if first && len(ports) > 0 {
+ result.Ports = ports
+ first = false
+ }
podContainers = append(podContainers, result)
}
}
-
return addContainersToPodObject(podContainers, p.Name()), nil
}
@@ -150,7 +162,7 @@ func addContainersToPodObject(containers []v1.Container, podName string) *v1.Pod
labels["app"] = removeUnderscores(podName)
om := v12.ObjectMeta{
// The name of the pod is container_name-libpod
- Name: fmt.Sprintf("%s-libpod", removeUnderscores(podName)),
+ Name: fmt.Sprintf("%s", removeUnderscores(podName)),
Labels: labels,
// CreationTimestamp seems to be required, so adding it; in doing so, the timestamp
// will reflect time this is run (not container create time) because the conversion
diff --git a/libpod/runtime.go b/libpod/runtime.go
index 82473aae9..2dfebf565 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -877,3 +877,8 @@ func (r *Runtime) generateName() (string, error) {
func (r *Runtime) ImageRuntime() *image.Runtime {
return r.imageRuntime
}
+
+// SystemContext returns the imagecontext
+func (r *Runtime) SystemContext() *types.SystemContext {
+ return r.imageContext
+}