Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

Commit

Permalink
Fix kustomize integration (#1247)
Browse files Browse the repository at this point in the history
This upgrades Kustomize to the highest stable version and includes
a simple workaround that can work now because of kustomize
improved normalization logic.

There is an open issue against kustomize to get rid of
normalization entirely when one uses their in-memory FS impl like
riff does: kubernetes-sigs/kustomize#963

Back-port of #1247 commit c65b91b

Fixes #1252
  • Loading branch information
trisberg committed Apr 12, 2019
1 parent e2d4c24 commit 4ac4aea
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ require (
k8s.io/apimachinery v0.0.0-20180904193909-def12e63c512
k8s.io/client-go v0.0.0-20180910083459-2cefa64ff137
k8s.io/kube-openapi v0.0.0-20181114233023-0317810137be // indirect
sigs.k8s.io/kustomize v1.0.11
sigs.k8s.io/kustomize v2.0.3+incompatible
)

replace github.com/Nvveen/Gotty => github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pivotal/go-ape v0.0.0-20190404203804-81ff0d7e7716 h1:2thc2e0pNH/rqWqZoHEo+Dsf4LybZ1wYyRDKYHvZR1Q=
github.com/pivotal/go-ape v0.0.0-20190404203804-81ff0d7e7716/go.mod h1:WRTmFu8GsOA1bSwOUVchskvhrQA9gIZiZV2U+WOW2wY=
github.com/pivotal/go-ape v0.0.0-20190405150324-756013ecae13 h1:Wg9lCEP1JL6E2Ip6wCTD1W3+8R8v9DML/xZo5pk7rpk=
github.com/pivotal/go-ape v0.0.0-20190405150324-756013ecae13/go.mod h1:WRTmFu8GsOA1bSwOUVchskvhrQA9gIZiZV2U+WOW2wY=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
Expand Down Expand Up @@ -544,5 +542,5 @@ k8s.io/client-go v0.0.0-20180910083459-2cefa64ff137 h1:4DIWGqvAjLME47asVwjb14H+6
k8s.io/client-go v0.0.0-20180910083459-2cefa64ff137/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
k8s.io/kube-openapi v0.0.0-20181114233023-0317810137be h1:aWEq4nbj7HRJ0mtKYjNSk/7X28Tl6TI6FeG8gKF+r7Q=
k8s.io/kube-openapi v0.0.0-20181114233023-0317810137be/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
sigs.k8s.io/kustomize v1.0.11 h1:Yb+6DDt9+aR2AvQApvUaKS/ugteeG4MPyoFeUHiPOjk=
sigs.k8s.io/kustomize v1.0.11/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0=
sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
3 changes: 2 additions & 1 deletion pkg/core/kustomize/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io/ioutil"
"net/url"
"path/filepath"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -51,7 +52,7 @@ type kustomizer struct {
func MakeKustomizer(timeout time.Duration) Kustomizer {
return &kustomizer{
fs: fs.MakeFakeFS(), // keep contents in-memory
fakeDir: "/",
fakeDir: filepath.FromSlash("/"),
httpTimeout: timeout,
}
}
Expand Down
42 changes: 18 additions & 24 deletions pkg/core/kustomize/kustomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/projectriff/riff/pkg/test_support"
"net"
"net/url"
"runtime"
"time"
)

Expand Down Expand Up @@ -80,34 +79,29 @@ spec:
test_support.CleanupDirs(GinkgoT(), workDir)
})

// ToDo: figure out how to run the kustomize tests on Windows https://github.com/projectriff/riff/issues/1226
if runtime.GOOS != "windows" {

It("customizes remote resources with provided labels", func() {
resourceListener, _ := net.Listen("tcp", "127.0.0.1:0")
go func() {
err := test_support.Serve(resourceListener, httpResponse)
Expect(err).NotTo(HaveOccurred())
}()
resourceUrl := unsafeParseUrl(fmt.Sprintf("http://%s/%s", resourceListener.Addr().String(), "pvc.yaml"))

result, err := kustomizer.ApplyLabels(resourceUrl, initLabels)

It("customizes remote resources with provided labels", func() {
resourceListener, _ := net.Listen("tcp", "127.0.0.1:0")
go func() {
err := test_support.Serve(resourceListener, httpResponse)
Expect(err).NotTo(HaveOccurred())
Expect(string(result)).To(Equal(expectedResourceContent))
})
}()
resourceUrl := unsafeParseUrl(fmt.Sprintf("http://%s/%s", resourceListener.Addr().String(), "pvc.yaml"))

It("customizes local resources with provided labels", func() {
file := test_support.CreateFile(workDir, "pvc.yaml", initialResourceContent)
resourceUrl := unsafeParseUrl(test_support.FileURL(test_support.AbsolutePath(file)))
result, err := kustomizer.ApplyLabels(resourceUrl, initLabels)

result, err := kustomizer.ApplyLabels(resourceUrl, initLabels)
Expect(err).NotTo(HaveOccurred())
Expect(string(result)).To(Equal(expectedResourceContent))
})

Expect(err).NotTo(HaveOccurred())
Expect(string(result)).To(Equal(expectedResourceContent))
})
It("customizes local resources with provided labels", func() {
file := test_support.CreateFile(workDir, "pvc.yaml", initialResourceContent)
resourceUrl := unsafeParseUrl(test_support.FileURL(test_support.AbsolutePath(file)))

}
result, err := kustomizer.ApplyLabels(resourceUrl, initLabels)

Expect(err).NotTo(HaveOccurred())
Expect(string(result)).To(Equal(expectedResourceContent))
})

It("fails on unsupported scheme", func() {
resourceUrl := unsafeParseUrl("ftp://127.0.0.1/goodluck.yaml")
Expand Down

0 comments on commit 4ac4aea

Please sign in to comment.