-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generrates Containerd config.toml for harbor satellite #59
base: main
Are you sure you want to change the base?
Changes from all commits
b0304ff
8a5ba11
c291e6a
fe299f8
b6b5dea
91222d4
09419ce
c60f7a4
18b5633
dec1ba0
ef0d82a
74fc4b9
3d0e209
6e54a14
8904e99
d14af7e
7254c1b
d111454
222c666
d2180bf
fcb7426
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,6 @@ dist/ | |
zot/cache.db | ||
secrets.txt | ||
__debug_bin1949266242 | ||
|
||
/zot | ||
runtime/containerd/config.toml |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,126 @@ | ||||||||||||||||||||||||||||||||||
package runtime | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||||||||||||||
"os" | ||||||||||||||||||||||||||||||||||
"path/filepath" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
"container-registry.com/harbor-satellite/internal/config" | ||||||||||||||||||||||||||||||||||
"container-registry.com/harbor-satellite/internal/utils" | ||||||||||||||||||||||||||||||||||
"container-registry.com/harbor-satellite/logger" | ||||||||||||||||||||||||||||||||||
"container-registry.com/harbor-satellite/registry" | ||||||||||||||||||||||||||||||||||
containerd "github.com/containerd/containerd/pkg/cri/config" | ||||||||||||||||||||||||||||||||||
toml "github.com/pelletier/go-toml" | ||||||||||||||||||||||||||||||||||
"github.com/rs/zerolog" | ||||||||||||||||||||||||||||||||||
"github.com/spf13/cobra" | ||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
const ( | ||||||||||||||||||||||||||||||||||
ContainerDCertPath = "/etc/containerd/certs.d" | ||||||||||||||||||||||||||||||||||
DefaultGeneratedTomlName = "config.toml" | ||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
var DefaultGenPath string | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
func init() { | ||||||||||||||||||||||||||||||||||
cwd, err := os.Getwd() | ||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||
fmt.Printf("Error getting current working directory: %v\n", err) | ||||||||||||||||||||||||||||||||||
DefaultGenPath = "/runtime/containerd" // Fallback in case of error | ||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||
DefaultGenPath = filepath.Join(cwd, "runtime/containerd") | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
func NewContainerdCommand() *cobra.Command { | ||||||||||||||||||||||||||||||||||
var generateConfig bool | ||||||||||||||||||||||||||||||||||
var defaultZotConfig *registry.DefaultZotConfig | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Comment on lines
+37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initialize The variable Initialize var generateConfig bool
-var defaultZotConfig *registry.DefaultZotConfig
+var defaultZotConfig = ®istry.DefaultZotConfig{} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||
containerdCmd := &cobra.Command{ | ||||||||||||||||||||||||||||||||||
Use: "containerd", | ||||||||||||||||||||||||||||||||||
Short: "Creates the config file for the containerd runtime to fetch the images from the local repository", | ||||||||||||||||||||||||||||||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||||||||||||||||||||||||||||||||||
var err error | ||||||||||||||||||||||||||||||||||
utils.SetupContextForCommand(cmd) | ||||||||||||||||||||||||||||||||||
log := logger.FromContext(cmd.Context()) | ||||||||||||||||||||||||||||||||||
if config.GetOwnRegistry() { | ||||||||||||||||||||||||||||||||||
log.Info().Msg("Using own registry for config generation") | ||||||||||||||||||||||||||||||||||
address, err := utils.ValidateRegistryAddress(config.GetOwnRegistryAdr(), config.GetOwnRegistryPort()) | ||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||
log.Err(err).Msg("Error validating registry address") | ||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
log.Info().Msgf("Registry address validated: %s", address) | ||||||||||||||||||||||||||||||||||
defaultZotConfig.HTTP.Address = config.GetOwnRegistryAdr() | ||||||||||||||||||||||||||||||||||
defaultZotConfig.HTTP.Port = config.GetOwnRegistryPort() | ||||||||||||||||||||||||||||||||||
Comment on lines
+54
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevent nil pointer dereference when setting As Ensure |
||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||
log.Info().Msg("Using default registry for config generation") | ||||||||||||||||||||||||||||||||||
defaultZotConfig, err = registry.ReadConfig(config.GetZotConfigPath()) | ||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||
return fmt.Errorf("could not read config: %w", err) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
log.Info().Msgf("Default config read successfully: %v", defaultZotConfig.HTTP.Address+":"+defaultZotConfig.HTTP.Port) | ||||||||||||||||||||||||||||||||||
Comment on lines
+58
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle potential error when reading default Zot configuration In the else block, if Ensure that defaultZotConfig, err = registry.ReadConfig(config.GetZotConfigPath())
if err != nil {
return fmt.Errorf("could not read config: %w", err)
}
+if defaultZotConfig == nil {
+ return fmt.Errorf("defaultZotConfig is nil after reading config")
+}
log.Info().Msgf("Default config read successfully: %v", defaultZotConfig.HTTP.Address+":"+defaultZotConfig.HTTP.Port) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
RunE: func(cmd *cobra.Command, args []string) error { | ||||||||||||||||||||||||||||||||||
log := logger.FromContext(cmd.Context()) | ||||||||||||||||||||||||||||||||||
if !generateConfig { | ||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
log.Info().Msg("Generating containerd config file for containerd ...") | ||||||||||||||||||||||||||||||||||
return GenerateContainerdConfig(defaultZotConfig, log) | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
containerdCmd.Flags().BoolVarP(&generateConfig, "gen", "g", false, "Generate the containerd config file") | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
return containerdCmd | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
func GenerateContainerdConfig(defaultZotConfig *registry.DefaultZotConfig, log *zerolog.Logger) error { | ||||||||||||||||||||||||||||||||||
containerdConfig := containerd.Config{} | ||||||||||||||||||||||||||||||||||
containerdConfig.PluginConfig = containerd.DefaultConfig() | ||||||||||||||||||||||||||||||||||
containerdConfig.PluginConfig.Registry.ConfigPath = ContainerDCertPath | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
registryMirror := map[string]containerd.Mirror{ | ||||||||||||||||||||||||||||||||||
defaultZotConfig.HTTP.Address: { | ||||||||||||||||||||||||||||||||||
Endpoints: []string{defaultZotConfig.HTTP.Address + ":" + defaultZotConfig.HTTP.Port}, | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
registryConfig := map[string]containerd.RegistryConfig{ | ||||||||||||||||||||||||||||||||||
defaultZotConfig.HTTP.Address: { | ||||||||||||||||||||||||||||||||||
TLS: &containerd.TLSConfig{ | ||||||||||||||||||||||||||||||||||
InsecureSkipVerify: config.UseUnsecure(), | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
containerdConfig.PluginConfig.Registry.Mirrors = registryMirror | ||||||||||||||||||||||||||||||||||
containerdConfig.PluginConfig.Registry.Configs = registryConfig | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
generatedConfig, err := toml.Marshal(containerdConfig) | ||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||
log.Error().Err(err).Msg("Error marshalling config") | ||||||||||||||||||||||||||||||||||
return fmt.Errorf("could not marshal config: %w", err) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
filePath := filepath.Join(DefaultGenPath, DefaultGeneratedTomlName) | ||||||||||||||||||||||||||||||||||
log.Info().Msgf("Writing config to file: %s", filePath) | ||||||||||||||||||||||||||||||||||
file, err := os.Create(filePath) | ||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||
log.Err(err).Msg("Error creating file") | ||||||||||||||||||||||||||||||||||
return fmt.Errorf("could not create file: %w", err) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
defer file.Close() | ||||||||||||||||||||||||||||||||||
Comment on lines
+111
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Handle file closing errors and use deferred error checking When using Instead of deferring file, err := os.Create(filePath)
if err != nil {
log.Err(err).Msg("Error creating file")
return fmt.Errorf("could not create file: %w", err)
}
-defer file.Close()
+defer func() {
+ if err := file.Close(); err != nil {
+ log.Err(err).Msg("Error closing file")
+ }
+}() 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
_, err = file.Write(generatedConfig) | ||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||
log.Err(err).Msg("Error writing to file") | ||||||||||||||||||||||||||||||||||
return fmt.Errorf("could not write to file: %w", err) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
log.Info().Msgf("Config file generated successfully at: %s", filePath) | ||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package runtime | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"container-registry.com/harbor-satellite/internal/utils" | ||
"container-registry.com/harbor-satellite/logger" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
DefaultContainerdConfigPath string = filepath.Join("/", "etc/containerd/config.toml") | ||
) | ||
|
||
func NewReadConfigCommand(runtime string) *cobra.Command { | ||
var defaultPath string | ||
switch runtime { | ||
case "containerd": | ||
defaultPath = DefaultContainerdConfigPath | ||
default: | ||
defaultPath = "" | ||
} | ||
readContainerdConfig := &cobra.Command{ | ||
Use: "read", | ||
Short: fmt.Sprintf("Reads the config file for the %s runtime", runtime), | ||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
utils.SetupContextForCommand(cmd) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
//Parse the flags | ||
path, err := cmd.Flags().GetString("path") | ||
if err != nil { | ||
return fmt.Errorf("error reading the path flag: %v", err) | ||
} | ||
log := logger.FromContext(cmd.Context()) | ||
log.Info().Msgf("Reading the containerd config file from path: %s", path) | ||
err = utils.ReadFile(path) | ||
if err != nil { | ||
return fmt.Errorf("error reading the containerd config file: %v", err) | ||
} | ||
return nil | ||
}, | ||
} | ||
readContainerdConfig.Flags().StringP("path", "p", defaultPath, "Path to the containerd config file of the container runtime") | ||
return readContainerdConfig | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,160 @@ | ||||||||||||||||||||
package cmd | ||||||||||||||||||||
|
||||||||||||||||||||
import ( | ||||||||||||||||||||
"context" | ||||||||||||||||||||
"fmt" | ||||||||||||||||||||
|
||||||||||||||||||||
runtime "container-registry.com/harbor-satellite/cmd/container_runtime" | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid aliasing imports as standard library package names to prevent confusion The alias Apply this diff to change the alias: -import runtime "container-registry.com/harbor-satellite/cmd/container_runtime"
+import containerRuntime "container-registry.com/harbor-satellite/cmd/container_runtime" 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
"container-registry.com/harbor-satellite/internal/config" | ||||||||||||||||||||
"container-registry.com/harbor-satellite/internal/satellite" | ||||||||||||||||||||
"container-registry.com/harbor-satellite/internal/scheduler" | ||||||||||||||||||||
"container-registry.com/harbor-satellite/internal/server" | ||||||||||||||||||||
"container-registry.com/harbor-satellite/internal/state" | ||||||||||||||||||||
"container-registry.com/harbor-satellite/internal/utils" | ||||||||||||||||||||
"container-registry.com/harbor-satellite/logger" | ||||||||||||||||||||
"github.com/rs/zerolog" | ||||||||||||||||||||
"github.com/spf13/cobra" | ||||||||||||||||||||
"golang.org/x/sync/errgroup" | ||||||||||||||||||||
) | ||||||||||||||||||||
|
||||||||||||||||||||
func NewRootCommand() *cobra.Command { | ||||||||||||||||||||
rootCmd := &cobra.Command{ | ||||||||||||||||||||
Use: "harbor-satellite", | ||||||||||||||||||||
Short: "Harbor Satellite is a tool to replicate images from source registry to Harbor registry", | ||||||||||||||||||||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||||||||||||||||||||
config.InitConfig() | ||||||||||||||||||||
}, | ||||||||||||||||||||
RunE: func(cmd *cobra.Command, args []string) error { | ||||||||||||||||||||
ctx := cmd.Context() | ||||||||||||||||||||
ctx, cancel := utils.SetupContext(ctx) | ||||||||||||||||||||
ctx = logger.AddLoggerToContext(ctx, config.GetLogLevel()) | ||||||||||||||||||||
return run(ctx, cancel) | ||||||||||||||||||||
}, | ||||||||||||||||||||
} | ||||||||||||||||||||
rootCmd.AddCommand(runtime.NewContainerdCommand()) | ||||||||||||||||||||
return rootCmd | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func Execute() error { | ||||||||||||||||||||
return NewRootCommand().Execute() | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func run(ctx context.Context, cancel context.CancelFunc) error { | ||||||||||||||||||||
g, ctx := errgroup.WithContext(ctx) | ||||||||||||||||||||
log := logger.FromContext(ctx) | ||||||||||||||||||||
|
||||||||||||||||||||
// Set up router and app | ||||||||||||||||||||
app := setupServerApp(ctx, log) | ||||||||||||||||||||
app.SetupRoutes() | ||||||||||||||||||||
app.SetupServer(g) | ||||||||||||||||||||
|
||||||||||||||||||||
// Handle registry setup | ||||||||||||||||||||
if err := handleRegistrySetup(g, log, cancel); err != nil { | ||||||||||||||||||||
return err | ||||||||||||||||||||
} | ||||||||||||||||||||
scheduler := scheduler.NewBasicScheduler(ctx) | ||||||||||||||||||||
ctx = context.WithValue(ctx, scheduler.GetSchedulerKey(), scheduler) | ||||||||||||||||||||
err := scheduler.Start() | ||||||||||||||||||||
if err != nil { | ||||||||||||||||||||
log.Error().Err(err).Msg("Error starting scheduler") | ||||||||||||||||||||
return err | ||||||||||||||||||||
} | ||||||||||||||||||||
// Process Input (file or URL) | ||||||||||||||||||||
stateArtifactFetcher, err := processInput(ctx, log) | ||||||||||||||||||||
if err != nil || stateArtifactFetcher == nil { | ||||||||||||||||||||
return fmt.Errorf("error processing input: %w", err) | ||||||||||||||||||||
} | ||||||||||||||||||||
Comment on lines
+64
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle If Apply this diff to fix the error handling: -if err != nil || stateArtifactFetcher == nil {
- return fmt.Errorf("error processing input: %w", err)
+if err != nil {
+ return fmt.Errorf("error processing input: %w", err)
+}
+if stateArtifactFetcher == nil {
+ return fmt.Errorf("stateArtifactFetcher is nil")
+} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
satelliteService := satellite.NewSatellite(ctx, stateArtifactFetcher, scheduler.GetSchedulerKey()) | ||||||||||||||||||||
|
||||||||||||||||||||
g.Go(func() error { | ||||||||||||||||||||
return satelliteService.Run(ctx) | ||||||||||||||||||||
}) | ||||||||||||||||||||
|
||||||||||||||||||||
log.Info().Msg("Startup complete 🚀") | ||||||||||||||||||||
return g.Wait() | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func initConfig() error { | ||||||||||||||||||||
if err := config.InitConfig(); err != nil { | ||||||||||||||||||||
return fmt.Errorf("error initializing config: %w", err) | ||||||||||||||||||||
} | ||||||||||||||||||||
return nil | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func setupServerApp(ctx context.Context, log *zerolog.Logger) *server.App { | ||||||||||||||||||||
router := server.NewDefaultRouter("/api/v1") | ||||||||||||||||||||
router.Use(server.LoggingMiddleware) | ||||||||||||||||||||
|
||||||||||||||||||||
return server.NewApp( | ||||||||||||||||||||
router, | ||||||||||||||||||||
ctx, | ||||||||||||||||||||
log, | ||||||||||||||||||||
config.AppConfig, | ||||||||||||||||||||
&server.MetricsRegistrar{}, | ||||||||||||||||||||
&server.DebugRegistrar{}, | ||||||||||||||||||||
&satellite.SatelliteRegistrar{}, | ||||||||||||||||||||
) | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func handleRegistrySetup(g *errgroup.Group, log *zerolog.Logger, cancel context.CancelFunc) error { | ||||||||||||||||||||
if config.GetOwnRegistry() { | ||||||||||||||||||||
if err := utils.HandleOwnRegistry(); err != nil { | ||||||||||||||||||||
log.Error().Err(err).Msg("Error handling own registry") | ||||||||||||||||||||
return err | ||||||||||||||||||||
} | ||||||||||||||||||||
} else { | ||||||||||||||||||||
log.Info().Msg("Launching default registry") | ||||||||||||||||||||
g.Go(func() error { | ||||||||||||||||||||
if err := utils.LaunchDefaultZotRegistry(); err != nil { | ||||||||||||||||||||
log.Error().Err(err).Msg("Error launching default registry") | ||||||||||||||||||||
cancel() | ||||||||||||||||||||
return err | ||||||||||||||||||||
} | ||||||||||||||||||||
cancel() | ||||||||||||||||||||
return nil | ||||||||||||||||||||
}) | ||||||||||||||||||||
} | ||||||||||||||||||||
return nil | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func processInput(ctx context.Context, log *zerolog.Logger) (state.StateFetcher, error) { | ||||||||||||||||||||
input := config.GetInput() | ||||||||||||||||||||
|
||||||||||||||||||||
if utils.IsValidURL(input) { | ||||||||||||||||||||
return processURLInput(input, log) | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
log.Info().Msg("Input is not a valid URL, checking if it is a file path") | ||||||||||||||||||||
if err := validateFilePath(input, log); err != nil { | ||||||||||||||||||||
return nil, err | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
return processFileInput(log) | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func processURLInput(input string, log *zerolog.Logger) (state.StateFetcher, error) { | ||||||||||||||||||||
log.Info().Msg("Input is a valid URL") | ||||||||||||||||||||
config.SetRemoteRegistryURL(input) | ||||||||||||||||||||
|
||||||||||||||||||||
stateArtifactFetcher := state.NewURLStateFetcher() | ||||||||||||||||||||
|
||||||||||||||||||||
return stateArtifactFetcher, nil | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func processFileInput(log *zerolog.Logger) (state.StateFetcher, error) { | ||||||||||||||||||||
stateArtifactFetcher := state.NewFileStateFetcher() | ||||||||||||||||||||
return stateArtifactFetcher, nil | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func validateFilePath(path string, log *zerolog.Logger) error { | ||||||||||||||||||||
if utils.HasInvalidPathChars(path) { | ||||||||||||||||||||
log.Error().Msg("Path contains invalid characters") | ||||||||||||||||||||
return fmt.Errorf("invalid file path: %s", path) | ||||||||||||||||||||
} | ||||||||||||||||||||
if err := utils.GetAbsFilePath(path); err != nil { | ||||||||||||||||||||
log.Error().Err(err).Msg("No file found") | ||||||||||||||||||||
return fmt.Errorf("no file found: %s", path) | ||||||||||||||||||||
} | ||||||||||||||||||||
return nil | ||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
"name": "harbor-satellite", | ||
"sdk": "go", | ||
"source": "ci", | ||
"engineVersion": "v0.13.3" | ||
"engineVersion": "v0.13.0" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure
DefaultGenPath
is valid and writableIn the
init()
function, ifos.Getwd()
fails,DefaultGenPath
is set to"/runtime/containerd"
. This fallback path may not exist or might not be writable, potentially causing issues when attempting to write the configuration file later.Consider verifying the existence and writability of
DefaultGenPath
after setting it: