Skip to content

Commit

Permalink
Serve stored FBC content
Browse files Browse the repository at this point in the history
  • Loading branch information
anik120 committed Aug 10, 2023
1 parent 85aa44d commit 046fd14
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/operator-framework/catalogd/internal/version"
corecontrollers "github.com/operator-framework/catalogd/pkg/controllers/core"
"github.com/operator-framework/catalogd/pkg/features"
httpserver "github.com/operator-framework/catalogd/pkg/http_server"
"github.com/operator-framework/catalogd/pkg/profile"
"github.com/operator-framework/catalogd/pkg/storage"

Expand Down Expand Up @@ -67,6 +68,7 @@ func main() {
catalogdVersion bool
systemNamespace string
storageDir string
serverPort string
)
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
Expand All @@ -77,6 +79,7 @@ func main() {
flag.StringVar(&unpackImage, "unpack-image", "quay.io/operator-framework/rukpak:v0.12.0", "The unpack image to use when unpacking catalog images")
flag.StringVar(&systemNamespace, "system-namespace", "", "The namespace catalogd uses for internal state, configuration, and workloads")
flag.StringVar(&storageDir, "catalogs-storage-dir", "/var/cache", "The directory in the filesystem where unpacked catalog content will be stored and served from")
flag.StringVar(&serverPort, "catalogs-server-port", ":8083", "The port where the unpacked catalog content will be accessible")
flag.BoolVar(&profiling, "profiling", false, "enable profiling endpoints to allow for using pprof")
flag.BoolVar(&catalogdVersion, "version", false, "print the catalogd version and exit")
opts := zap.Options{
Expand Down Expand Up @@ -145,7 +148,11 @@ func main() {
os.Exit(1)
}
}

catalogServer := httpserver.NewServer(storageDir, ":8083")
if err := mgr.Add(catalogServer); err != nil {
setupLog.Error(err, "unable to start catalog server")
os.Exit(1)
}
setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down
12 changes: 12 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,17 @@ spec:
- "./manager"
args:
- --leader-elect
- "--catalogs-storage-dir=/var/cache"
- "--catalogs-server-port=:8083"
image: controller:latest
name: manager
ports:
- containerPort: 8083
protocol: TCP
name: https
volumeMounts:
- name: catalog-cache
mountPath: /var/cache/
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand All @@ -73,3 +82,6 @@ spec:
imagePullPolicy: IfNotPresent
serviceAccountName: controller-manager
terminationGracePeriodSeconds: 10
volumes:
- name: catalog-cache
emptyDir: {}
25 changes: 25 additions & 0 deletions pkg/http_server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package httpserver

import (
"context"
"net/http"
)

type server struct {
Dir string
Port string
}

// NewServer returns a manager.Runnable server, that takes
// a directory and port number, and serves the files in the
// directory from the given port number.
func NewServer(dir, port string) server {

Check warning on line 16 in pkg/http_server/server.go

View workflow job for this annotation

GitHub Actions / lint

unexported-return: exported func NewServer returns unexported type httpserver.server, which can be annoying to use (revive)
return server{
Dir: dir,
Port: port,
}
}

func (s server) Start(_ context.Context) error {
return http.ListenAndServe(s.Port, http.FileServer(http.Dir(s.Dir)))

Check failure on line 24 in pkg/http_server/server.go

View workflow job for this annotation

GitHub Actions / lint

G114: Use of net/http serve function that has no support for setting timeouts (gosec)
}

0 comments on commit 046fd14

Please sign in to comment.