Skip to content
This repository has been archived by the owner on Oct 5, 2020. It is now read-only.

Commit

Permalink
Fixup goclient upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
bethge committed Jan 2, 2018
1 parent 13982c1 commit fe07a81
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 32 deletions.
15 changes: 5 additions & 10 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions pkg/api/init.go

This file was deleted.

9 changes: 6 additions & 3 deletions pkg/api/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/rebuy-de/kubernetes-deployment/pkg/templates"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/pkg/api"
"k8s.io/client-go/kubernetes/scheme"
)

func (app *App) Render(fetched *FetchResult) ([]runtime.Object, error) {
Expand All @@ -28,9 +28,12 @@ func (app *App) Render(fetched *FetchResult) ([]runtime.Object, error) {
return nil, errors.WithStack(err)
}

decode := api.Codecs.UniversalDeserializer().Decode
return app.decode(rendered)
}

objects := []runtime.Object{}
func (app *App) decode(rendered map[string]string) ([]runtime.Object, error) {
var objects []runtime.Object
decode := scheme.Codecs.UniversalDeserializer().Decode

for name, data := range rendered {
if !strings.HasSuffix(name, ".yaml") && !strings.HasSuffix(name, ".yml") {
Expand Down
39 changes: 39 additions & 0 deletions pkg/api/render_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package api

import (
"github.com/rebuy-de/kubernetes-deployment/pkg/interceptors"
"github.com/rebuy-de/kubernetes-deployment/pkg/testutil"
"testing"
"io/ioutil"
"path"
)

func readFile(t *testing.T, path string) string {
dat, err := ioutil.ReadFile(path)
if err != nil {
t.Fatal(err)
}
return string(dat)
}

func TestDecode(t *testing.T) {
dir := "test-fixtures"
tcs := map[string]string{
"manifest-deployment.yaml": "",
"manifest-podpreset.yaml": "",
}
golden := "decoded-golden.yaml"

for fname := range tcs {
p := path.Join(dir, fname)
tcs[fname] = readFile(t, p)
}

app := App{Interceptors: &interceptors.Multi{}}
objects, err := app.decode(tcs)
if err != nil {
t.Fatal(err)
}
g := path.Join(dir, golden)
testutil.AssertGoldenJSON(t, g, objects)
}
73 changes: 73 additions & 0 deletions pkg/api/test-fixtures/decoded-golden.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
[
{
"kind": "Deployment",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "maintenance",
"namespace": "kube-system",
"creationTimestamp": null,
"labels": {
"app": "maintenance",
"team": "platform",
"tier": "maintenance"
}
},
"spec": {
"replicas": 1,
"template": {
"metadata": {
"name": "maintenance",
"namespace": "kube-system",
"creationTimestamp": null,
"labels": {
"app": "maintenance",
"team": "platform",
"tier": "maintenance"
}
},
"spec": {
"containers": [
{
"name": "maintenance",
"image": "074509403805.dkr.ecr.eu-west-1.amazonaws.com/maintenance:master",
"resources": {},
"imagePullPolicy": "Always"
}
]
}
},
"strategy": {
"rollingUpdate": {
"maxSurge": 0
}
},
"revisionHistoryLimit": 1
},
"status": {}
},
{
"kind": "PodPreset",
"apiVersion": "settings.k8s.io/v1alpha1",
"metadata": {
"name": "cluster-profile",
"namespace": "default",
"creationTimestamp": null,
"labels": {
"team": "platform"
}
},
"spec": {
"selector": {
"matchExpressions": [
{
"key": "role",
"operator": "In",
"values": [
"silo"
]
}
]
}
}
}
]
32 changes: 32 additions & 0 deletions pkg/api/test-fixtures/manifest-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: extensions/v1beta1
kind: Deployment

metadata:
name: maintenance
namespace: kube-system
labels:
team: platform
tier: maintenance
app: maintenance

spec:
revisionHistoryLimit: 1
replicas: 1
strategy:
rollingUpdate:
maxSurge: 0

template:
metadata:
name: maintenance
namespace: kube-system
labels:
team: platform
tier: maintenance
app: maintenance

spec:
containers:
- name: maintenance
image: 074509403805.dkr.ecr.eu-west-1.amazonaws.com/maintenance:master
imagePullPolicy: Always
13 changes: 13 additions & 0 deletions pkg/api/test-fixtures/manifest-podpreset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: settings.k8s.io/v1alpha1
kind: PodPreset

metadata:
name: cluster-profile
namespace: default
labels:
team: platform

spec:
selector:
matchExpressions:
- {key: role, operator: In, values: [silo]}
4 changes: 2 additions & 2 deletions pkg/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"os/exec"
"strings"

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/pkg/api"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -69,6 +69,6 @@ func (k *Kubectl) Apply(obj runtime.Object) (runtime.Object, error) {
return nil, errors.WithStack(err)
}

newObj, _, err := api.Codecs.UniversalDeserializer().Decode(stdout.Bytes(), nil, nil)
newObj, _, err := scheme.Codecs.UniversalDeserializer().Decode(stdout.Bytes(), nil, nil)
return newObj, errors.Wrapf(err, "failed to decode result json")
}

0 comments on commit fe07a81

Please sign in to comment.