Skip to content

Commit

Permalink
style: apply go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
j4m3s-s committed Jan 5, 2022
1 parent df888ce commit 747429a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
6 changes: 2 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

package main


import (
"fmt"
m "github.com/Polyconseil/k8s-proxy-image-swapper/mutate"
"html"
"os"
"io/ioutil"
"log"
"net/http"
"os"
"time"
m "github.com/Polyconseil/k8s-proxy-image-swapper/mutate"
)

func handleRoot(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -46,7 +45,6 @@ func handleMutation(w http.ResponseWriter, r *http.Request) {
w.Write(mutated)
}


func main() {
log.Println("Starting server ...")

Expand Down
54 changes: 27 additions & 27 deletions mutate/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (

// registry/namespace/image:tag
type DockerImageUrl struct {
registry string
registry string
namespace string
image string
tag string
image string
tag string
}

// takes toto:tata or toto, gives tata or latest
Expand All @@ -28,13 +28,13 @@ func getImgTag(img string) string {
tag = imgTagArr[1]
}

return tag
return tag
}

// takes toto:tata or toto, gives toto
func getImgName(img string) string {
imgTagArr := strings.Split(img, ":")
return imgTagArr[0]
imgTagArr := strings.Split(img, ":")
return imgTagArr[0]
}

func getDockerImageUrl(img string) DockerImageUrl {
Expand All @@ -43,49 +43,49 @@ func getDockerImageUrl(img string) DockerImageUrl {
if len(imgArr) == 1 {
// Case busybox or busybox:tag
return DockerImageUrl{
registry: "docker.io", // default
namespace: "library", // default
image: getImgName(img),
tag: getImgTag(img),
registry: "docker.io", // default
namespace: "library", // default
image: getImgName(img),
tag: getImgTag(img),
}
}

imgUrl := imgArr[0]
// Case docker.io/busybox
if len(imgArr) == 2 && imgUrl == "docker.io" {
return DockerImageUrl {
registry: imgUrl,
return DockerImageUrl{
registry: imgUrl,
namespace: "library",
image: getImgName(imgArr[1]),
tag: getImgTag(imgArr[1]),
image: getImgName(imgArr[1]),
tag: getImgTag(imgArr[1]),
}
}

// Case toto/tata (and ! gcr.io/toto)
if len(imgArr) == 2 && !strings.Contains(imgUrl, ".") {
return DockerImageUrl {
registry: "docker.io",
return DockerImageUrl{
registry: "docker.io",
namespace: imgArr[0],
image: getImgName(imgArr[1]),
tag: getImgTag(imgArr[1]),
image: getImgName(imgArr[1]),
tag: getImgTag(imgArr[1]),
}
}

if len(imgArr) == 2 && strings.Contains(imgUrl, ".") {
return DockerImageUrl {
registry: imgUrl,
return DockerImageUrl{
registry: imgUrl,
namespace: "", // ??? TODO does it exist?
image: getImgName(imgArr[1]),
tag: getImgTag(imgArr[1]),
image: getImgName(imgArr[1]),
tag: getImgTag(imgArr[1]),
}
}

// case toto.io/tata/titi[:tag]
return DockerImageUrl {
registry: imgArr[0],
return DockerImageUrl{
registry: imgArr[0],
namespace: imgArr[1],
image: getImgName(imgArr[2]),
tag: getImgTag(imgArr[2]),
image: getImgName(imgArr[2]),
tag: getImgTag(imgArr[2]),
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ func getPatchFromContainerList(ctn []corev1.Container, registry, containerType s

// In case there's a tag
if strings.HasPrefix(patchedImg, "docker.io/library/registry") ||
strings.HasPrefix(patchedImg, "registry") {
strings.HasPrefix(patchedImg, "registry") {
// We don't patch the registry to avoid the bootstrap problem
continue
}
Expand Down
1 change: 0 additions & 1 deletion mutate/mutate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func TestRegistryPathImage(t *testing.T) {
}
}


func TestRegistryFullPathImage(t *testing.T) {
if GetPatchedImageUrl("docker.io/library/registry", "example.com") != "docker.io/library/registry:latest" {
t.Log("Error TestRegistryFullPathImage")
Expand Down

0 comments on commit 747429a

Please sign in to comment.