Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Commit

Permalink
wip-2
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmiskiewicz committed Jun 12, 2020
1 parent 6ce257a commit 40b3b71
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cmd/indexbuilder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
l.Panicln(errors.Wrap(err, "while listing source dir"))
}

var loader *addon.Loader
var loader *addon.LoaderV3
yLog := l.WithField("service", "addon checker")

removeTempDir := func(path string) {
Expand All @@ -49,7 +49,7 @@ func main() {
}
defer removeTempDir(tmpDir)

loader = addon.NewLoader(tmpDir, yLog)
loader = addon.NewLoaderV3(tmpDir, yLog)
b, _, err := loader.LoadDir(fullPath)
if err != nil {
l.Panicln(errors.Wrap(err, "while loading addon"))
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/helm/pkg/proto/hapi/chart"
"helm.sh/helm/v3/pkg/chart"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/kyma-project/helm-broker/internal"
"github.com/kyma-project/helm-broker/internal/addon/provider"
"github.com/kyma-project/helm-broker/pkg/apis/addons/v1alpha1"
"k8s.io/helm/pkg/proto/hapi/chart"
"helm.sh/helm/v3/pkg/chart"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func SetupAndStartController(cfg *rest.Config, ctrCfg *config.ControllerConfig,
lg.Infof("Disabling support for HTTP protocol because DevelopMode is set to false.")
}

addonGetterFactory, err := provider.NewClientFactory(allowedGetters, addon.NewLoader(ctrCfg.TmpDir, lg), ctrCfg.DocumentationEnabled, lg)
addonGetterFactory, err := provider.NewClientFactory(allowedGetters, addon.NewLoaderV3(ctrCfg.TmpDir, lg), ctrCfg.DocumentationEnabled, lg)
fatalOnError(err, "cannot setup addon getter")

instChecker := instance.New(mgr.GetClient(), ctrCfg.ClusterServiceBrokerName)
Expand Down
6 changes: 3 additions & 3 deletions internal/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/helm/pkg/proto/hapi/chart"
//"helm.sh/helm/v3/pkg/chart"
chartv2 "k8s.io/helm/pkg/proto/hapi/chart"
"helm.sh/helm/v3/pkg/chart"
)

// Index contains collection of all addons from the given repository
Expand Down Expand Up @@ -313,7 +313,7 @@ type Namespace string
type ReleaseInfo struct {
Time time.Time
Revision int
Config *chart.Config
Config *chartv2.Config
ConfigValues map[string]interface{}
}

Expand Down
26 changes: 19 additions & 7 deletions internal/storage/driver/etcd/entity_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"strings"

"github.com/Masterminds/semver"
"github.com/golang/protobuf/proto"
"github.com/pkg/errors"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/clientv3/namespace"
"helm.sh/helm/v3/pkg/chart"

"github.com/kyma-project/helm-broker/internal"
"bytes"
"encoding/gob"
)

// NewChart creates new storage for Charts
Expand Down Expand Up @@ -46,12 +47,13 @@ func (s *Chart) Upsert(namespace internal.Namespace, c *chart.Chart) (replaced b
return false, err
}

data, err := proto.Marshal(c)
if err != nil {
return false, errors.Wrap(err, "while encoding DSO")
buf := bytes.Buffer{}
enc := gob.NewEncoder(&buf)
if err := enc.Encode(c); err != nil {
return false, errors.Wrap(err, "while encoding entity")
}

resp, err := s.kv.Put(context.TODO(), s.key(namespace, nv), string(data), clientv3.WithPrevKV())
resp, err := s.kv.Put(context.TODO(), s.key(namespace, nv), buf.String(), clientv3.WithPrevKV())
if err != nil {
return false, errors.Wrap(err, "while calling database")
}
Expand Down Expand Up @@ -83,9 +85,19 @@ func (s *Chart) Get(namespace internal.Namespace, name internal.ChartName, ver s
return nil, errors.New("more than one element matching requested id, should never happen")
}

c, err := s.decodeChart(resp.Kvs[0].Value)
if err != nil {
return nil, errors.Wrap(err, "while decoding single DSO")
}

return c, nil
}

func (s *Chart) decodeChart(raw []byte) (*chart.Chart, error) {
dec := gob.NewDecoder(bytes.NewReader(raw))
var c chart.Chart
if err := proto.Unmarshal(resp.Kvs[0].Value, &c); err != nil {
return nil, errors.Wrap(err, "while decoding DSO")
if err := dec.Decode(&c); err != nil {
return nil, err
}

return &c, nil
Expand Down
3 changes: 1 addition & 2 deletions internal/storage/driver/memory/entity_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (

"github.com/Masterminds/semver"
"github.com/pkg/errors"

"k8s.io/helm/pkg/proto/hapi/chart"
"helm.sh/helm/v3/pkg/chart"

"github.com/kyma-project/helm-broker/internal"
)
Expand Down
2 changes: 1 addition & 1 deletion test/charts/helm_broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/vrischmann/envconfig"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/rand"
_ "k8s.io/client-go/plugin/pkg/client/auth"
//_ "k8s.io/client-go/plugin/pkg/client/auth"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
Expand Down

0 comments on commit 40b3b71

Please sign in to comment.