Skip to content

Commit c906111

Browse files
committed
Skip security databases pull for editions without them
- Editions without security databases (CE, BE, SE) produced contradictory logs: "Skipping pull" followed by "All required databases are pulled" and an empty security.tar - securityDatabasesAvailable now returns (bool, error) so the caller can distinguish "images exist" from "images not found" and skip the entire pull early Signed-off-by: Roman Berezkin <roman.berezkin@flant.com>
1 parent 5c17a35 commit c906111

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

internal/mirror/security/security.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,37 +103,39 @@ func NewService(
103103
// PullSecurity pulls the security databases
104104
// It validates access to the registry and pulls the security database images
105105
func (svc *Service) PullSecurity(ctx context.Context) error {
106-
err := svc.validateSecurityAccess(ctx)
106+
available, err := svc.securityDatabasesAvailable(ctx)
107107
if err != nil {
108-
return fmt.Errorf("validate security access: %w", err)
108+
return fmt.Errorf("check security databases availability: %w", err)
109109
}
110110

111-
err = svc.pullSecurityDatabases(ctx)
112-
if err != nil {
111+
if !available {
112+
return nil
113+
}
114+
115+
if err := svc.pullSecurityDatabases(ctx); err != nil {
113116
return fmt.Errorf("pull security databases: %w", err)
114117
}
115118

116119
return nil
117120
}
118121

119-
// validateSecurityAccess validates access to the security registry
120-
// It checks if the security database image exists in the source registry
121-
func (svc *Service) validateSecurityAccess(ctx context.Context) error {
122-
svc.logger.Debug("Validating access to the security registry")
122+
// securityDatabasesAvailable checks if security database images exist in the source registry.
123+
// Returns false for editions that do not include security databases (e.g. CE, BE, SE).
124+
func (svc *Service) securityDatabasesAvailable(ctx context.Context) (bool, error) {
125+
svc.logger.Debug("Checking if security databases are available in registry")
123126

124-
// For specific tags, check if the tag exists
125127
err := svc.securityService.Security(internal.SecurityTrivyDBSegment).CheckImageExists(ctx, "2")
126128
if errors.Is(err, client.ErrImageNotFound) {
127-
svc.userLogger.Warnf("Skipping pull of security databases: %v", err)
129+
svc.userLogger.WarnLn("Security databases are not available in this edition, skipping")
128130

129-
return nil
131+
return false, nil
130132
}
131133

132134
if err != nil {
133-
return fmt.Errorf("failed to check security database tag %q in registry: %w", "2", err)
135+
return false, fmt.Errorf("failed to check security database tag %q in registry: %w", "2", err)
134136
}
135137

136-
return nil
138+
return true, nil
137139
}
138140

139141
func (svc *Service) pullSecurityDatabases(ctx context.Context) error {

0 commit comments

Comments
 (0)