Skip to content

Commit

Permalink
Fix decoding issue during the installation (kyma-project#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
Suleyman Akbas authored Jul 10, 2020
1 parent 5992f6d commit f6d1534
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 32 deletions.
15 changes: 13 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,34 @@ replace (

require (
github.com/Masterminds/semver v1.5.0
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/Microsoft/hcsshim v0.8.6 // indirect
github.com/avast/retry-go v2.4.3+incompatible
github.com/briandowns/spinner v1.7.0
github.com/containerd/containerd v1.3.0 // indirect
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 // indirect
github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v1.4.2-0.20190927142053-ada3c14355ce
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/fatih/color v1.7.0
github.com/fsouza/go-dockerclient v1.4.5-0.20191009031337-a958d2e31b6c
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450 // indirect
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995 // indirect
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e // indirect
github.com/gorilla/mux v1.7.3 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/kyma-incubator/hydroform/install v0.0.0-20200624085426-7c04bd6a1185
github.com/kyma-incubator/hydroform/provision v0.0.0-20200528121905-83605518328f
github.com/kyma-incubator/octopus v0.0.0-20191009105757-2e9d86cd9967
github.com/kyma-project/kyma v0.5.1-0.20200211132707-0a36a0f31d7e
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/mitchellh/mapstructure v1.1.2
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c // indirect
github.com/olekukonko/tablewriter v0.0.1
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runc v0.1.1 // indirect
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
github.com/pkg/errors v0.8.1
github.com/spf13/cobra v0.0.5
Expand All @@ -39,6 +49,7 @@ require (
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c // indirect
google.golang.org/genproto v0.0.0-20191002211648-c459b9ce5143 // indirect
google.golang.org/grpc v1.22.0 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v2 v2.2.8
gotest.tools v2.2.0+incompatible
Expand Down
7 changes: 1 addition & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/containerd/containerd v1.3.0 h1:xjvXQWABwS2uiv3TWgQt5Uth60Gu86LTGZXMJkjc7rY=
github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/coreos/bbolt v1.3.0 h1:HIgH5xUWXT914HCI671AxuTTqjj64UOFr7pHn48LUTI=
Expand Down Expand Up @@ -184,8 +183,6 @@ github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjr
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsouza/go-dockerclient v1.4.5-0.20191009031337-a958d2e31b6c h1:S2NmO9lgc5gWo8v+5LE1zvI8MhsBOGYsD2zGcjZCKCY=
github.com/fsouza/go-dockerclient v1.4.5-0.20191009031337-a958d2e31b6c/go.mod h1:uwBnf441eWBzHXdRSdNQO2ep59Ds1oPVd++3YgWKehg=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v0.0.0-20180820084758-c7ce16629ff4/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
Expand Down Expand Up @@ -250,7 +247,6 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -295,6 +291,7 @@ github.com/gophercloud/utils v0.0.0-20190128072930-fbb6ab446f01 h1:OgCNGSnEalfkR
github.com/gophercloud/utils v0.0.0-20190128072930-fbb6ab446f01/go.mod h1:wjDF8z83zTeg5eMLml5EBSlAhbF7G8DobyI1YsMuyzw=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
Expand Down Expand Up @@ -686,7 +683,6 @@ golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -790,7 +786,6 @@ google.golang.org/appengine v1.6.1 h1:QzqyMA1tlu6CgqCDUtU9V+ZKhLFT2dkJuANu5QaxI3
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
google.golang.org/genproto v0.0.0-20170731182057-09f6ed296fc6/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
Expand Down
4 changes: 2 additions & 2 deletions internal/minikube/minikube.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/Masterminds/semver"
docker "github.com/fsouza/go-dockerclient"
docker "github.com/docker/docker/client"
)

const (
Expand Down Expand Up @@ -103,5 +103,5 @@ func DockerClient(verbose bool, profile string, timeout time.Duration) (*docker.
}
}
}
return docker.NewClientFromEnv()
return docker.NewClientWithOpts(docker.FromEnv)
}
68 changes: 46 additions & 22 deletions pkg/installation/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ import (
"time"

"github.com/Masterminds/semver"
docker "github.com/fsouza/go-dockerclient"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/archive"
"github.com/kyma-incubator/hydroform/install/config"
installationSDK "github.com/kyma-incubator/hydroform/install/installation"
"github.com/kyma-incubator/hydroform/install/scheme"
"github.com/kyma-project/cli/internal/minikube"
"github.com/kyma-project/kyma/components/kyma-operator/pkg/apis/installer/v1alpha1"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/storage/memory"
"gopkg.in/yaml.v2"
v1 "k8s.io/api/apps/v1"
)

func (i *Installation) buildKymaInstaller(imageName string) error {
Expand All @@ -35,14 +34,33 @@ func (i *Installation) buildKymaInstaller(imageName string) error {
return err
}

var args []docker.BuildArg
return dc.BuildImage(docker.BuildImageOptions{
Name: strings.TrimSpace(string(imageName)),
Dockerfile: filepath.Join("tools", "kyma-installer", "kyma.Dockerfile"),
OutputStream: ioutil.Discard,
ContextDir: filepath.Join(i.Options.LocalSrcPath),
BuildArgs: args,
})
reader, err := archive.TarWithOptions(filepath.Join(i.Options.LocalSrcPath), &archive.TarOptions{})
if err != nil {
return err
}

ctx, cancel := context.WithTimeout(context.Background(), time.Duration(300)*time.Second)
defer cancel()

dc.NegotiateAPIVersion(ctx)

args := make(map[string]*string)
_, err = dc.ImageBuild(
ctx,
reader,
types.ImageBuildOptions{
Tags: []string{strings.TrimSpace(string(imageName))},
SuppressOutput: true,
Remove: true,
Dockerfile: filepath.Join("tools", "kyma-installer", "kyma.Dockerfile"),
BuildArgs: args,
},
)
if err != nil {
return err
}

return nil
}

func (i *Installation) getMasterHash() (string, error) {
Expand Down Expand Up @@ -297,17 +315,23 @@ func downloadFile(path string) (io.ReadCloser, error) {
}

func getInstallerImage(installerFile *File) (string, error) {
for _, res := range installerFile.Content {
if res["kind"] == "Deployment" {

var deployment v1.Deployment
err := mapstructure.Decode(res, &deployment)
if err != nil {
return "", err
}

if deployment.Spec.Template.Spec.Containers[0].Name == "kyma-installer-container" {
return deployment.Spec.Template.Spec.Containers[0].Image, nil
for _, config := range installerFile.Content {
if kind, ok := config["kind"]; ok && kind == "Deployment" {
if spec, ok := config["spec"].(map[interface{}]interface{}); ok {
if template, ok := spec["template"].(map[interface{}]interface{}); ok {
if spec, ok = template["spec"].(map[interface{}]interface{}); ok {
if containers, ok := spec["containers"].([]interface{}); ok {
for _, c := range containers {
container := c.(map[interface{}]interface{})
if cName, ok := container["name"]; ok && cName == "kyma-installer-container" {
if _, ok := container["image"]; ok {
return container["image"].(string), nil
}
}
}
}
}
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/installation/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ import (
"github.com/stretchr/testify/require"
)

func Test_GetMasterHash(t *testing.T) {
i := Installation{}
h, err := i.getMasterHash()
require.NoError(t, err)
require.True(t, isHex(h))
}

func Test_GetLatestAvailableMasterHash(t *testing.T) {
i := Installation{
Options: &Options{
FallbackLevel: 5,
},
}
h, err := i.getLatestAvailableMasterHash()
require.NoError(t, err)
require.True(t, isHex(h))
}

func Test_GetInstallerImage(t *testing.T) {
const image = "eu.gcr.io/kyma-project/kyma-installer:63f27f76"
testData := File{Content: []map[string]interface{}{{
Expand Down

0 comments on commit f6d1534

Please sign in to comment.