Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #305 from twelho/storage-cleanup
Browse files Browse the repository at this point in the history
Storage cleanup: document RawStorage, make RawStorage and MappedRawStorage more compatible
  • Loading branch information
luxas authored Aug 9, 2019
2 parents 6a40c22 + 58ef9db commit d9ec168
Show file tree
Hide file tree
Showing 21 changed files with 204 additions and 74 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ CACHE_DIR = $(shell pwd)/bin/cache
DOCS_PORT = 8000
# Specifies if this is a CI build or not; if it is, it will save the docker image created to bin/$(GOARCH)/image.tar
IS_CI_BUILD ?= 0
# Unset any GOFLAGS that would interfere with the build
undefine GOFLAGS

## Multi-platform-related stuff
GOHOSTARCH = $(shell go env GOARCH 2>/dev/null || echo "amd64")
Expand Down
35 changes: 22 additions & 13 deletions docs/api/meta_v1alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [type IPAddresses](#IPAddresses)
- [func (i IPAddresses) String() string](#IPAddresses.String)
- [type Kind](#Kind)
- [func ParseKind(input string) Kind](#ParseKind)
- [func (k Kind) Lower() string](#Kind.Lower)
- [func (k Kind) String() string](#Kind.String)
- [func (k Kind) Title() string](#Kind.Title)
Expand Down Expand Up @@ -216,6 +217,14 @@ func (i IPAddresses) String() string
type Kind string
```

### <a name="ParseKind">func</a> [ParseKind](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=2055:2088#L95)

``` go
func ParseKind(input string) Kind
```

Returns a Kind parsed from the given string

### <a name="Kind.Lower">func</a> (Kind) [Lower](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=1933:1961#L90)

``` go
Expand Down Expand Up @@ -279,7 +288,7 @@ func (i OCIImageRef) String() string
func (i *OCIImageRef) UnmarshalJSON(b []byte) error
```

## <a name="Object">type</a> [Object](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=4013:4448#L174)
## <a name="Object">type</a> [Object](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=4245:4680#L186)

``` go
type Object interface {
Expand Down Expand Up @@ -312,7 +321,7 @@ type Object interface {
Object extends k8s.io/apimachinery’s runtime.Object with extra GetName()
and GetUID() methods from ObjectMeta

## <a name="ObjectMeta">type</a> [ObjectMeta](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=2168:2460#L97)
## <a name="ObjectMeta">type</a> [ObjectMeta](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=2400:2692#L109)

``` go
type ObjectMeta struct {
Expand All @@ -328,87 +337,87 @@ ObjectMeta have to be embedded into any serializable object. It provides
the .GetName() and .GetUID() methods that help implement the Object
interface

### <a name="ObjectMeta.GetAnnotation">func</a> (\*ObjectMeta) [GetAnnotation](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3568:3621#L157)
### <a name="ObjectMeta.GetAnnotation">func</a> (\*ObjectMeta) [GetAnnotation](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3800:3853#L169)

``` go
func (o *ObjectMeta) GetAnnotation(key string) string
```

GetAnnotation returns the label value for the key

### <a name="ObjectMeta.GetCreated">func</a> (\*ObjectMeta) [GetCreated](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3005:3043#L131)
### <a name="ObjectMeta.GetCreated">func</a> (\*ObjectMeta) [GetCreated](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3237:3275#L143)

``` go
func (o *ObjectMeta) GetCreated() Time
```

GetCreated returns when the Object was created

### <a name="ObjectMeta.GetLabel">func</a> (\*ObjectMeta) [GetLabel](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3226:3274#L141)
### <a name="ObjectMeta.GetLabel">func</a> (\*ObjectMeta) [GetLabel](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3458:3506#L153)

``` go
func (o *ObjectMeta) GetLabel(key string) string
```

GetLabel returns the label value for the key

### <a name="ObjectMeta.GetName">func</a> (\*ObjectMeta) [GetName](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=2611:2648#L111)
### <a name="ObjectMeta.GetName">func</a> (\*ObjectMeta) [GetName](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=2843:2880#L123)

``` go
func (o *ObjectMeta) GetName() string
```

GetName returns the name of the Object

### <a name="ObjectMeta.GetObjectMeta">func</a> (\*ObjectMeta) [GetObjectMeta](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=2505:2553#L106)
### <a name="ObjectMeta.GetObjectMeta">func</a> (\*ObjectMeta) [GetObjectMeta](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=2737:2785#L118)

``` go
func (o *ObjectMeta) GetObjectMeta() *ObjectMeta
```

This is a helper for APIType generation

### <a name="ObjectMeta.GetUID">func</a> (\*ObjectMeta) [GetUID](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=2810:2843#L121)
### <a name="ObjectMeta.GetUID">func</a> (\*ObjectMeta) [GetUID](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3042:3075#L133)

``` go
func (o *ObjectMeta) GetUID() UID
```

GetUID returns the UID of the Object

### <a name="ObjectMeta.SetAnnotation">func</a> (\*ObjectMeta) [SetAnnotation](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3742:3795#L165)
### <a name="ObjectMeta.SetAnnotation">func</a> (\*ObjectMeta) [SetAnnotation](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3974:4027#L177)

``` go
func (o *ObjectMeta) SetAnnotation(key, value string)
```

SetAnnotation sets a label value for a key

### <a name="ObjectMeta.SetCreated">func</a> (\*ObjectMeta) [SetCreated](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3118:3157#L136)
### <a name="ObjectMeta.SetCreated">func</a> (\*ObjectMeta) [SetCreated](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3350:3389#L148)

``` go
func (o *ObjectMeta) SetCreated(t Time)
```

SetCreated sets the creation time of the Object

### <a name="ObjectMeta.SetLabel">func</a> (\*ObjectMeta) [SetLabel](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3380:3428#L149)
### <a name="ObjectMeta.SetLabel">func</a> (\*ObjectMeta) [SetLabel](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3612:3660#L161)

``` go
func (o *ObjectMeta) SetLabel(key, value string)
```

SetLabel sets a label value for a key

### <a name="ObjectMeta.SetName">func</a> (\*ObjectMeta) [SetName](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=2708:2749#L116)
### <a name="ObjectMeta.SetName">func</a> (\*ObjectMeta) [SetName](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=2940:2981#L128)

``` go
func (o *ObjectMeta) SetName(name string)
```

SetName sets the name of the Object

### <a name="ObjectMeta.SetUID">func</a> (\*ObjectMeta) [SetUID](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=2900:2936#L126)
### <a name="ObjectMeta.SetUID">func</a> (\*ObjectMeta) [SetUID](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/meta.go?s=3132:3168#L138)

``` go
func (o *ObjectMeta) SetUID(uid UID)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d // indirect
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e
github.com/gorilla/mux v1.7.2 // indirect
github.com/json-iterator/go v1.1.7 // indirect
github.com/krolaw/dhcp4 v0.0.0-20190531080455-7b64900047ae
github.com/lithammer/dedent v1.1.0
github.com/miekg/dns v1.1.14
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gnostic v0.0.0-20170426233943-68f4ded48ba9/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
Expand All @@ -144,6 +146,8 @@ github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBv
github.com/json-iterator/go v0.0.0-20180701071628-ab8a2e0c74be/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand Down Expand Up @@ -174,9 +178,11 @@ github.com/miekg/dns v1.1.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3N
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8dQu6DMTwH4oIuGN8GJDAlqDdVE=
Expand Down
12 changes: 12 additions & 0 deletions pkg/apis/meta/v1alpha1/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ func (k Kind) Lower() string {
return string(bytes.ToLower([]byte(k)))
}

// Returns a Kind parsed from the given string
func ParseKind(input string) Kind {
b := bytes.ToUpper([]byte(input))

// Leave TLAs as uppercase
if len(b) > 3 {
b = append(b[:1], bytes.ToLower(b[1:])...)
}

return Kind(b)
}

// ObjectMeta have to be embedded into any serializable object.
// It provides the .GetName() and .GetUID() methods that help
// implement the Object interface
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ func SetGenericStorage() error {
log.Trace("Initializing the GenericStorage provider...")
providers.Storage = cache.NewCache(
storage.NewGenericStorage(
storage.NewDefaultRawStorage(constants.DATA_DIR), scheme.Serializer))
storage.NewGenericRawStorage(constants.DATA_DIR), scheme.Serializer))
return nil
}
16 changes: 16 additions & 0 deletions pkg/storage/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package storage

import (
"fmt"
"os"
"path"
"path/filepath"
"strings"

meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
)
Expand Down Expand Up @@ -36,6 +39,19 @@ func NewKey(kind meta.Kind, uid meta.UID) Key {
}
}

// ParseKey parses the given string and returns a Key
func ParseKey(input string) (k Key, err error) {
splitInput := strings.Split(filepath.Clean(input), string(os.PathSeparator))
if len(splitInput) != 2 {
err = fmt.Errorf("invalid input for key parsing: %s", input)
} else {
k.Kind = meta.ParseKind(splitInput[0])
k.UID = meta.UID(splitInput[1])
}

return
}

// String returns the virtual path for the Kind
func (k KindKey) String() string {
return k.Lower()
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/manifest/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NewManifestStorage(dataDir string) (*ManifestStorage, error) {

ss := sync.NewSyncStorage(
storage.NewGenericStorage(
storage.NewDefaultRawStorage(constants.DATA_DIR), scheme.Serializer),
storage.NewGenericRawStorage(constants.DATA_DIR), scheme.Serializer),
ws)

return &ManifestStorage{
Expand Down
17 changes: 7 additions & 10 deletions pkg/storage/mappedrawstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ type MappedRawStorage interface {

// AddMapping binds a Key's virtual path to a physical file path
AddMapping(key Key, path string)
// GetMapping retrieves the Key containing the virtual
// path based on the given physical file path
GetMapping(path string) (Key, error)
// RemoveMapping removes the physical file
// path mapping matching the given Key
RemoveMapping(key Key)
Expand Down Expand Up @@ -135,16 +132,11 @@ func (r *GenericMappedRawStorage) Format(key Key) (f Format) {
return
}

func (r *GenericMappedRawStorage) Dir() string {
func (r *GenericMappedRawStorage) WatchDir() string {
return r.dir
}

func (r *GenericMappedRawStorage) AddMapping(key Key, path string) {
log.Debugf("GenericMappedRawStorage: AddMapping: %q -> %q", key, path)
r.fileMappings[key] = path
}

func (r *GenericMappedRawStorage) GetMapping(path string) (Key, error) {
func (r *GenericMappedRawStorage) GetKey(path string) (Key, error) {
for key, p := range r.fileMappings {
if p == path {
return key, nil
Expand All @@ -154,6 +146,11 @@ func (r *GenericMappedRawStorage) GetMapping(path string) (Key, error) {
return Key{}, fmt.Errorf("no mapping found for path %q", path)
}

func (r *GenericMappedRawStorage) AddMapping(key Key, path string) {
log.Debugf("GenericMappedRawStorage: AddMapping: %q -> %q", key, path)
r.fileMappings[key] = path
}

func (r *GenericMappedRawStorage) RemoveMapping(key Key) {
log.Debugf("GenericMappedRawStorage: RemoveMapping: %q", key)
delete(r.fileMappings, key)
Expand Down
Loading

0 comments on commit d9ec168

Please sign in to comment.