This repository was archived by the owner on Mar 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Serve locally stored fbc content via an http server #148
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: catalogserver | ||
| namespace: system | ||
| spec: | ||
| selector: | ||
| control-plane: controller-manager | ||
| ports: | ||
| - name: http | ||
| protocol: TCP | ||
| port: 80 | ||
| targetPort: 8083 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| Copyright 2022 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| // this is copied from https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/77b08a845e451b695cfa25b79ebe277d85064345/pkg/manager/server.go | ||
| // we will remove this once we update to a version of controller-runitme that has this included | ||
| // https://github.com/kubernetes-sigs/controller-runtime/pull/2473 | ||
|
|
||
| package server | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "net" | ||
| "net/http" | ||
| "time" | ||
|
|
||
| "github.com/go-logr/logr" | ||
|
|
||
| crlog "sigs.k8s.io/controller-runtime/pkg/log" | ||
| "sigs.k8s.io/controller-runtime/pkg/manager" | ||
| ) | ||
|
|
||
| var ( | ||
| _ manager.Runnable = (*Server)(nil) | ||
| _ manager.LeaderElectionRunnable = (*Server)(nil) | ||
| ) | ||
|
|
||
| // Server is a general purpose HTTP server Runnable for a manager. | ||
| // It is used to serve some internal handlers for health probes and profiling, | ||
| // but it can also be used to run custom servers. | ||
| type Server struct { | ||
| // Kind is an optional string that describes the purpose of the server. It is used in logs to distinguish | ||
| // among multiple servers. | ||
| Kind string | ||
|
|
||
| // Log is the logger used by the server. If not set, a logger will be derived from the context passed to Start. | ||
| Log logr.Logger | ||
|
|
||
| // Server is the HTTP server to run. It is required. | ||
| Server *http.Server | ||
|
|
||
| // Listener is an optional listener to use. If not set, the server start a listener using the server.Addr. | ||
| // Using a listener is useful when the port reservation needs to happen in advance of this runnable starting. | ||
| Listener net.Listener | ||
|
|
||
| // OnlyServeWhenLeader is an optional bool that indicates that the server should only be started when the manager is the leader. | ||
| OnlyServeWhenLeader bool | ||
|
|
||
| // ShutdownTimeout is an optional duration that indicates how long to wait for the server to shutdown gracefully. If not set, | ||
| // the server will wait indefinitely for all connections to close. | ||
| ShutdownTimeout *time.Duration | ||
| } | ||
|
|
||
| // Start starts the server. It will block until the server is stopped or an error occurs. | ||
| func (s *Server) Start(ctx context.Context) error { | ||
| log := s.Log | ||
| if log.GetSink() == nil { | ||
| log = crlog.FromContext(ctx) | ||
| } | ||
| if s.Kind != "" { | ||
| log = log.WithValues("kind", s.Kind) | ||
| } | ||
| log = log.WithValues("addr", s.addr()) | ||
|
|
||
| serverShutdown := make(chan struct{}) | ||
| go func() { | ||
| <-ctx.Done() | ||
| log.Info("shutting down server") | ||
|
|
||
| shutdownCtx := context.Background() | ||
| if s.ShutdownTimeout != nil { | ||
| var shutdownCancel context.CancelFunc | ||
| shutdownCtx, shutdownCancel = context.WithTimeout(context.Background(), *s.ShutdownTimeout) | ||
| defer shutdownCancel() | ||
| } | ||
|
|
||
| if err := s.Server.Shutdown(shutdownCtx); err != nil { | ||
| log.Error(err, "error shutting down server") | ||
| } | ||
| close(serverShutdown) | ||
| }() | ||
|
|
||
| log.Info("starting server") | ||
| if err := s.serve(); err != nil && !errors.Is(err, http.ErrServerClosed) { | ||
| return err | ||
| } | ||
|
|
||
| <-serverShutdown | ||
| return nil | ||
| } | ||
|
|
||
| // NeedLeaderElection returns true if the server should only be started when the manager is the leader. | ||
| func (s *Server) NeedLeaderElection() bool { | ||
| return s.OnlyServeWhenLeader | ||
| } | ||
|
|
||
| func (s *Server) addr() string { | ||
| if s.Listener != nil { | ||
| return s.Listener.Addr().String() | ||
| } | ||
| return s.Server.Addr | ||
| } | ||
|
|
||
| func (s *Server) serve() error { | ||
| if s.Listener != nil { | ||
| return s.Server.Serve(s.Listener) | ||
| } | ||
| return s.Server.ListenAndServe() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.