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

Commit

Permalink
Split manifest storage into two types
Browse files Browse the repository at this point in the history
  • Loading branch information
luxas committed Aug 19, 2019
1 parent 5c4534e commit 6588f62
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pkg/gitops/gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"time"

log "github.com/sirupsen/logrus"
"github.com/weaveworks/ignite/pkg/apis/ignite/scheme"
"github.com/weaveworks/ignite/pkg/constants"
"github.com/weaveworks/ignite/pkg/gitops/gitdir"
"github.com/weaveworks/ignite/pkg/operations/reconcile"
"github.com/weaveworks/ignite/pkg/storage/manifest"
Expand All @@ -22,7 +24,7 @@ func RunGitOps(url, branch string, paths []string) error {
gitDir.WaitForClone()

// Construct a manifest storage for the path backed by git
s, err := manifest.NewManifestStorage(gitDir.Dir())
s, err := manifest.NewTwoWayManifestStorage(gitDir.Dir(), constants.DATA_DIR, scheme.Serializer)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/providers/manifeststorage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package manifeststorage

import (
log "github.com/sirupsen/logrus"
"github.com/weaveworks/ignite/pkg/apis/ignite/scheme"
"github.com/weaveworks/ignite/pkg/constants"
"github.com/weaveworks/ignite/pkg/providers"
"github.com/weaveworks/ignite/pkg/storage/cache"
Expand All @@ -12,7 +13,7 @@ var ManifestStorage *manifest.ManifestStorage

func SetManifestStorage() (err error) {
log.Trace("Initializing the ManifestStorage provider...")
ManifestStorage, err = manifest.NewManifestStorage(constants.MANIFEST_DIR)
ManifestStorage, err = manifest.NewTwoWayManifestStorage(constants.MANIFEST_DIR, constants.DATA_DIR, scheme.Serializer)
if err != nil {
return
}
Expand Down
21 changes: 20 additions & 1 deletion pkg/storage/manifest/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@ import (
"github.com/weaveworks/ignite/pkg/storage/watch"
)

func NewManifestStorage(manifestDir, dataDir string, ser serializer.Serializer) (*ManifestStorage, error) {
// NewManifestStorage constructs a new storage that watches unstructured manifests in the specified directory,
// decodable using the given serializer.
func NewManifestStorage(manifestDir string, ser serializer.Serializer) (*ManifestStorage, error) {
ws, err := watch.NewGenericWatchStorage(storage.NewGenericStorage(storage.NewGenericMappedRawStorage(manifestDir), ser))
if err != nil {
return nil, err
}

ss := sync.NewSyncStorage(ws)

return &ManifestStorage{
Storage: ss,
}, nil
}

// NewManifestStorage constructs a new storage that watches unstructured manifests in the specified directory,
// decodable using the given serializer. However, all changes in the manifest directory, are also propagated to
// the structured data directory that's backed by the default storage implementation. Writes to this storage are
// propagated to both the manifest directory, and the data directory.
func NewTwoWayManifestStorage(manifestDir, dataDir string, ser serializer.Serializer) (*ManifestStorage, error) {
ws, err := watch.NewGenericWatchStorage(storage.NewGenericStorage(storage.NewGenericMappedRawStorage(manifestDir), ser))
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/rawstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (r *GenericRawStorage) realPath(key AnyKey) string {
// KindKeys get no special treatment
case Key:
// Keys get the metadata filename added to the returned path
file = constants.MetadataJSON
file = constants.METADATA
default:
panic(fmt.Sprintf("invalid key type received: %T", key))
}
Expand Down

0 comments on commit 6588f62

Please sign in to comment.