Skip to content
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

Refactor secrets linking #130

Merged
merged 1 commit into from
Jul 12, 2024
Merged

Refactor secrets linking #130

merged 1 commit into from
Jul 12, 2024

Conversation

rcerven
Copy link
Contributor

@rcerven rcerven commented Jul 2, 2024

  1. when linking secret to SA, don't add it if already present
  2. unlink secret from SA upon imageRepository deletion
  3. don't link secret anymore to imagePullSecrets (used for the image pod is using, task/pipeline bundle image)
  4. new option to clean up secret links via spec.credentials.verify-linking
    • It will link secret to service account if link is missing.
    • It will remove duplicate links of secret in service account.
    • It will remove secret from imagePullSecrets in service account.
    • It will unlink secret from service account, if secret doesn't exist (can recreated by using 'regenerate-token').

STONEBLD-2540

@openshift-ci openshift-ci bot requested review from mmorhun and psturc July 2, 2024 20:09
@rcerven rcerven removed the request for review from psturc July 2, 2024 20:10
@rcerven rcerven force-pushed the fixlinking branch 2 times, most recently from 145bbd1 to afc28c9 Compare July 4, 2024 22:23
@rcerven rcerven changed the title [WIP] Refactor secrets linking Refactor secrets linking Jul 4, 2024
@rcerven
Copy link
Contributor Author

rcerven commented Jul 4, 2024

/test image-controller-e2e

@rcerven
Copy link
Contributor Author

rcerven commented Jul 4, 2024

/test images

1 similar comment
@rcerven
Copy link
Contributor Author

rcerven commented Jul 4, 2024

/test images

controllers/imagerepository_controller.go Outdated Show resolved Hide resolved
controllers/imagerepository_controller.go Outdated Show resolved Hide resolved
if errors.IsNotFound(err) {
return nil
}
log.Error(err, "Failed to read pipeline service account", "ServiceAccountName", buildPipelineServiceAccountName, "NamespaceName", namespace, l.Action, l.ActionView)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add common log entries to the log above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what you mean.

you mean in log := ctrllog.FromContext(ctx) ???

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean something like
log := ctrllog.FromContext(ctx).WithValues("ServiceAccountName", buildPipelineServiceAccountName)
so all the log entries will have the value. But up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok didn't know that

will change it

controllers/imagerepository_controller.go Outdated Show resolved Hide resolved

secretExists = false
log.Info("Secret doesn't exist, will unlink secret from service account", "SecretName", secretName)
log.Info("To recreate secret use regenerate-token")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log is not visible to the user, so makes no sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it isn't visible to the user, but it is good for debugging

keeping it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For debugging we can relay on Secret doesn't exist, will unlink secret from service account, cannot we?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok removing

controllers/suite_util_test.go Outdated Show resolved Hide resolved
@@ -296,6 +296,27 @@ func waitImageRepositoryFinalizerOnImageRepository(imageRepositoryKey types.Name
}, timeout, interval).Should(BeTrue())
}

// func waitImageRepositoryCredentialGone(imageRepositoryKey types.NamespacedName, credentialName string) {
func waitImageRepositoryCredentialGone(imageRepositoryKey types.NamespacedName, operationName string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name is confusing. It seems that it waits until the secrets with credentials gone...

Copy link
Contributor Author

@rcerven rcerven Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it waits until imageRepository.Spec.Credentials sections are gone

hence the name : ImageRepositoryCredential

suggest better one if you have a idea

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waitImageRepositoryCredentialSectionGone at least? Or maybe waitImageRepositoryCredentialSectionRequestGone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok renamed

@rcerven rcerven force-pushed the fixlinking branch 3 times, most recently from 70274be to 4d0be12 Compare July 11, 2024 18:38
1. when linking secret to SA, don't add it if already present
2. unlink secret from SA upon imageRepository deletion
3. don't link secret anymore to imagePullSecrets (used for the image pod
   is using, task/pipeline bundle image)
4. new option to clean up secret links via spec.credentials.verify-linking
   - It will link secret to service account if link is missing.
   - It will remove duplicate links of secret in service account.
   - It will remove secret from imagePullSecrets in service account.
   - It will unlink secret from service account, if secret doesn't exist (can recreated by using 'regenerate-token').

STONEBLD-2540

Signed-off-by: Robert Cerven <[email protected]>
Copy link

openshift-ci bot commented Jul 12, 2024

New changes are detected. LGTM label has been removed.

@rcerven rcerven merged commit e138500 into konflux-ci:main Jul 12, 2024
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants