Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCM localization support #70

Merged
merged 7 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions cmds/helminstaller/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/json"

v1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
"github.com/open-component-model/ocm/pkg/contexts/ocm/utils/localize"
"github.com/open-component-model/ocm/pkg/errors"
)

Expand All @@ -31,12 +32,7 @@ type Config struct {
KubeConfigName string `json:"kubeConfigName,omitempty"`
}

type ImageMapping struct {
v1.ResourceReference
Tag string `json:"tag,omitempty"`
Repository string `json:"repository,omitempty"`
Image string `json:"image,omitempty"`
}
type ImageMapping = localize.ImageMapping

func (c *Config) GetValues() (map[string]interface{}, error) {
if len(c.Values) == 0 {
Expand Down
1 change: 1 addition & 0 deletions cmds/helminstaller/app/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func Execute(d driver.Driver, action string, ctx ocm.Context, octx out.Context,
}
}
}

ns := "default"
if cfg.Namespace != "" {
ns = cfg.Namespace
Expand Down
159 changes: 0 additions & 159 deletions cmds/ocm/commands/ocmcmds/common/inputs/types/directory/utils.go

This file was deleted.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ require (
github.com/docker/distribution v2.8.1+incompatible
github.com/docker/go-connections v0.4.0
github.com/drone/envsubst v1.0.3
github.com/goccy/go-yaml v1.9.5
github.com/golang/mock v1.6.0
github.com/google/go-github/v45 v45.2.0
github.com/klauspost/compress v1.14.4
Expand Down
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d h1:105gxyaGwC
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4=
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
Expand Down Expand Up @@ -509,6 +510,13 @@ github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng=
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-sql-driver/mysql v1.3.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
Expand All @@ -525,6 +533,8 @@ github.com/gobuffalo/packr/v2 v2.8.3 h1:xE1yzvnO56cUC0sTpKR3DIbxZgB54AftTFMhB2XE
github.com/gobuffalo/packr/v2 v2.8.3/go.mod h1:0SahksCVcx4IMnigTjiFuyldmTrdTctXsOdiU5KwbKc=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/goccy/go-yaml v1.9.5 h1:Eh/+3uk9kLxG4koCX6lRMAPS1OaMSAi+FJcya0INdB0=
github.com/goccy/go-yaml v1.9.5/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3KfscvA=
github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
github.com/godbus/dbus v0.0.0-20180201030542-885f9cc04c9c/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
Expand Down Expand Up @@ -778,6 +788,8 @@ github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/lib/pq v0.0.0-20150723085316-0dad96c0b94f/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
Expand Down Expand Up @@ -819,6 +831,7 @@ github.com/marstr/guid v1.1.0 h1:/M4H/1G4avsieL6BbUwCOBzulmoeKVP5ux/3mQNnbyI=
github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho=
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"io"
"os"
"sync"

"github.com/open-component-model/ocm/pkg/errors"
)
Expand Down Expand Up @@ -109,6 +110,7 @@ type Buffer interface {
Reader() (io.ReadCloser, error)
Len() int
Close() error
Release() error
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
}

type memoryBuffer struct {
Expand All @@ -125,9 +127,15 @@ func (m *memoryBuffer) Close() error {
return nil
}

func (m *memoryBuffer) Release() error {
return nil
}

type fileBuffer struct {
path string
file *os.File
lock sync.RWMutex
readcount int
path string
file *os.File
}

var _ Buffer = (*fileBuffer)(nil)
Expand All @@ -144,14 +152,38 @@ func NewFileBuffer() (*fileBuffer, error) {
}

func (b *fileBuffer) Write(out []byte) (int, error) {
b.lock.RLock()
defer b.lock.RUnlock()

if b.file == nil {
return 0, ErrClosed
}
return b.file.Write(out)
}

func (b *fileBuffer) Reader() (io.ReadCloser, error) {
return os.Open(b.path)
b.lock.Lock()
defer b.lock.Unlock()

if b.file == nil {
return nil, ErrClosed
}
r, err := os.Open(b.path)
if err != nil {
return nil, err
}
b.readcount++
return &bufferReader{buffer: b, ReadCloser: r}, nil
}

func (b *fileBuffer) Len() int {
b.lock.RLock()
defer b.lock.RUnlock()

if b.file == nil {
return -1
}

fi, err := b.file.Stat()
if err != nil {
return -1
Expand All @@ -160,5 +192,50 @@ func (b *fileBuffer) Len() int {
}

func (b *fileBuffer) Close() error {
return errors.ErrListf("closing file buffer").Add(b.file.Close(), os.Remove(b.path)).Result()
b.lock.Lock()
defer b.lock.Unlock()

if b.file == nil {
return ErrClosed
}
return b.file.Close()
}

func (b *fileBuffer) Release() error {
b.lock.Lock()
defer b.lock.Unlock()

if b.file == nil {
return nil
}
// just assure file to be closed
_ = b.file.Close()
b.file = nil
if b.readcount == 0 {
return os.Remove(b.path)
}
return nil
}

type bufferReader struct {
io.ReadCloser
buffer *fileBuffer
}

func (b *bufferReader) Close() error {
b.buffer.lock.Lock()
defer b.buffer.lock.Unlock()

if b.ReadCloser == nil {
return ErrClosed
}
list := errors.ErrListf("closing file buffer")
r := b.ReadCloser
b.ReadCloser = nil
b.buffer.readcount--
list.Add(r.Close())
if b.buffer.readcount <= 0 && b.buffer.file == nil {
list.Add(os.Remove(b.buffer.path))
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
}
return list.Result()
}
Loading