Skip to content

Commit

Permalink
fix: Reload registry TLS certificate when it is updated on the file s…
Browse files Browse the repository at this point in the history
…ystem (#805)

Watch the filesystem for changes to the certificate, and reload when it
is updated.

Introduces a dependency on
https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/certwatcher. This
does not appear to impact the executable size.

The first commit is a test. On its own, it fails. With the fix in the
second commit, the test passes.

Fixes #803

(Note: This is stacked on #804)

---------

Co-authored-by: Jimmi Dyson <[email protected]>
  • Loading branch information
dlipovetsky and jimmidyson authored Nov 11, 2024
1 parent eacbf34 commit 26203e6
Show file tree
Hide file tree
Showing 15 changed files with 418 additions and 274 deletions.
2 changes: 1 addition & 1 deletion cmd/mindthegap/create/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func NewCommand(out output.Output) *cobra.Command {
return fmt.Errorf("failed to create local Docker registry: %w", err)
}
go func() {
if err := reg.ListenAndServe(); err != nil {
if err := reg.ListenAndServe(output.NewOutputLogr(out)); err != nil {
out.Error(err, "error serving Docker registry")
os.Exit(2)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/mindthegap/importcmd/imagebundle/image_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewCommand(out output.Output) *cobra.Command {
return fmt.Errorf("failed to create local Docker registry: %w", err)
}
go func() {
if err := reg.ListenAndServe(); err != nil {
if err := reg.ListenAndServe(output.NewOutputLogr(out)); err != nil {
out.Error(err, "error serving Docker registry")
os.Exit(2)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/mindthegap/push/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func NewCommand(out output.Output, bundleCmdName string) *cobra.Command {
return fmt.Errorf("failed to create local Docker registry: %w", err)
}
go func() {
if err := reg.ListenAndServe(); err != nil {
if err := reg.ListenAndServe(output.NewOutputLogr(out)); err != nil {
out.Error(err, "error serving Docker registry")
os.Exit(2)
}
Expand Down
11 changes: 11 additions & 0 deletions cmd/mindthegap/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/spf13/cobra"
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/mesosphere/dkp-cli-runtime/core/cmd/root"
"github.com/mesosphere/dkp-cli-runtime/core/output"
Expand All @@ -19,6 +20,12 @@ import (
"github.com/mesosphere/mindthegap/cmd/mindthegap/serve"
)

const (
// MinimumVerbosityForControllerRuntimeMessages is the minimum verbosity at which controller-runtime
// log messages are included in the output. Set to >= 1 to exclude from default output.
MinimumVerbosityForControllerRuntimeMessages = 1
)

func NewCommand(in io.Reader, out, errOut io.Writer) (*cobra.Command, output.Output) {
rootCmd, rootOpts := root.NewCommand(out, errOut)

Expand Down Expand Up @@ -53,6 +60,10 @@ func Execute() {
// disable cobra built-in error printing, we output the error with formatting.
rootCmd.SilenceErrors = true

// All packages in the controller-runtime module expect this logger to be
// defined within 30 seconds of initialization.
ctrllog.SetLogger(output.NewOutputLogr(out))

if err := rootCmd.Execute(); err != nil {
out.Error(err, "")
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mindthegap/serve/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewCommand(
out.Infof("Listening on %s\n", reg.Address())

go func() {
if err := reg.ListenAndServe(); err != nil &&
if err := reg.ListenAndServe(output.NewOutputLogr(out)); err != nil &&
!errors.Is(err, http.ErrServerClosed) {
out.Error(err, "error serving Docker registry")
os.Exit(2)
Expand Down
Loading

0 comments on commit 26203e6

Please sign in to comment.