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

Commit

Permalink
Make manifeststorage constructors generic
Browse files Browse the repository at this point in the history
  • Loading branch information
luxas committed Aug 19, 2019
1 parent bf90952 commit c767243
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 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
28 changes: 23 additions & 5 deletions pkg/storage/manifest/storage.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
package manifest

import (
"github.com/weaveworks/ignite/pkg/apis/ignite/scheme"
"github.com/weaveworks/ignite/pkg/constants"
"github.com/weaveworks/ignite/pkg/serializer"
"github.com/weaveworks/ignite/pkg/storage"
"github.com/weaveworks/ignite/pkg/storage/sync"
"github.com/weaveworks/ignite/pkg/storage/watch"
)

func NewManifestStorage(dataDir string) (*ManifestStorage, error) {
ws, err := watch.NewGenericWatchStorage(storage.NewGenericStorage(storage.NewGenericMappedRawStorage(dataDir), scheme.Serializer))
// 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
}

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

return &ManifestStorage{
Expand Down

0 comments on commit c767243

Please sign in to comment.