Skip to content

Commit

Permalink
store catalogs in /var/cache/catalogs dir
Browse files Browse the repository at this point in the history
Signed-off-by: Anik <anikbhattacharya93@gmail.com>
  • Loading branch information
anik120 committed Aug 16, 2023
1 parent 9d60f83 commit 4e304f9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
4 changes: 2 additions & 2 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ spec:
- "./manager"
args:
- --leader-elect
- "--catalogs-storage-dir=/var/cache"
- "--catalogs-server-port=:8083"
- "--catalogs-storage-dir=/var/cache/catalogs"
- "--catalogs-server-addr=127.0.0.1:8083"
image: controller:latest
name: manager
ports:
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/core/catalog_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (
"github.com/operator-framework/catalogd/pkg/storage"
)

const fbcDeletionFinalizer = "operator-framework.catalogd/localstore"
const fbcDeletionFinalizer = "catalogd.operatorframework.io/delete-server-cache"

// CatalogReconciler reconciles a Catalog object
type CatalogReconciler struct {
Expand Down
9 changes: 1 addition & 8 deletions pkg/controllers/core/catalog_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/format"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -156,13 +155,7 @@ var _ = Describe("Catalogd Controller Test", func() {

AfterEach(func() {
By("tearing down cluster state")
Eventually(func() error {
err := cl.Delete(ctx, catalog)
if !apierrors.IsNotFound(err) {
return err
}
return nil
}).Should(Succeed())
Expect(client.IgnoreNotFound(cl.Delete(ctx, catalog))).To(Succeed())
})

When("unpacker returns source.Result with state == 'Pending'", func() {
Expand Down
23 changes: 8 additions & 15 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,20 @@ func (s *Storage) Store(owner string, fbc *declcfg.DeclarativeConfig) error {
if err := declcfg.WriteJSON(*fbc, fbcFile); err != nil {
return err
}
s.registerFileForServing(s.ServerMux, owner)
s.ServerMux.HandleFunc(fmt.Sprintf("/catalogs/%s", owner), func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filepath.Join(s.RootDirectory, fmt.Sprintf("%s.json", owner)))
})
return nil
}

func (s *Storage) Delete(owner string) error {
return ignoreNotExist(os.Remove(s.fbcPath(owner)))
}

func (s *Storage) registerFileForServing(mux *http.ServeMux, name string) {
mux.HandleFunc(fmt.Sprintf("/catalogs/%s", name), func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filepath.Join(s.RootDirectory, fmt.Sprintf("%s.json", name)))
})
}

func (s *Storage) fbcPath(catalogName string) string {
return filepath.Join(s.RootDirectory, fmt.Sprintf("%s.json", catalogName))
}

func ignoreNotExist(err error) error {
err := os.Remove(s.fbcPath(owner))
if errors.Is(err, os.ErrNotExist) {
return nil
}
return err
}

func (s *Storage) fbcPath(catalogName string) string {
return filepath.Join(s.RootDirectory, fmt.Sprintf("%s.json", catalogName))
}

0 comments on commit 4e304f9

Please sign in to comment.