Skip to content

Commit

Permalink
try to create every secret instead of returning eraly
Browse files Browse the repository at this point in the history
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
  • Loading branch information
zhaohuabing committed Mar 8, 2024
1 parent 6806195 commit 20d5d3a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
17 changes: 9 additions & 8 deletions internal/cmd/certgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,18 @@ func outputCerts(ctx context.Context, cli client.Client, cfg *config.Server, cer
log := cfg.Logger

if err != nil {
if errors.Is(err, kubernetes.ErrSecretExists) {
log.Info("exiting early", "reason", err)
return nil
if !errors.Is(err, kubernetes.ErrSecretExists) {
log.Info(err.Error())
} else {
return fmt.Errorf("failed to create or update secrets: %w", err)
}

return fmt.Errorf("failed to create or update secrets: %w", err)
}

for i := range secrets {
s := secrets[i]
log.Info("created secret", "namespace", s.Namespace, "name", s.Name)
if secrets != nil {
for i := range secrets {
s := secrets[i]
log.Info("created secret", "namespace", s.Namespace, "name", s.Name)
}
}

return nil
Expand Down
17 changes: 13 additions & 4 deletions internal/provider/kubernetes/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ func CertsToSecret(namespace string, certs *crypto.Certificates) []corev1.Secret
// CreateOrUpdateSecrets creates the provided secrets if they don't exist or updates
// them if they do.
func CreateOrUpdateSecrets(ctx context.Context, client client.Client, secrets []corev1.Secret, update bool) ([]corev1.Secret, error) {
var tidySecrets []corev1.Secret
var (
tidySecrets []corev1.Secret
existingSecrets []string
)

for i := range secrets {
secret := secrets[i]
current := new(corev1.Secret)
Expand All @@ -109,9 +113,8 @@ func CreateOrUpdateSecrets(ctx context.Context, client client.Client, secrets []
// Update if current value is different and update arg is set.
} else {
if !update {
return nil, fmt.Errorf("%s/%s: %w;"+
"Either update it manually or set overwriteControlPlaneCerts "+
"in the EnvoyGateway config", secret.Namespace, secret.Name, ErrSecretExists)
existingSecrets = append(existingSecrets, fmt.Sprintf("%s/%s", secret.Namespace, secret.Name))
continue
}

if !reflect.DeepEqual(secret.Data, current.Data) {
Expand All @@ -123,5 +126,11 @@ func CreateOrUpdateSecrets(ctx context.Context, client client.Client, secrets []
tidySecrets = append(tidySecrets, secret)
}

if len(existingSecrets) > 0 {
return tidySecrets, fmt.Errorf("%v: %w;"+
"Either update the secrets manually or set overwriteControlPlaneCerts "+
"in the EnvoyGateway config", existingSecrets, ErrSecretExists)
}

return tidySecrets, nil
}

0 comments on commit 20d5d3a

Please sign in to comment.