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

Create a k8schain directly from pull secrets #1049

Merged
merged 2 commits into from
Jun 24, 2021

Conversation

scothis
Copy link
Contributor

@scothis scothis commented Jun 15, 2021

The k8schain package creates a new keychain by resolving Kubernets
secrets from service accounts and other image pull secrets specified by
name. The k8s client gets the full secret content for these named
resources.

Sometimes it's desirable to pull the content of a secret from a cache,
or to watch a resource for changes in a controller. In this situation
it would be helpful to create a k8schain directly from resolved secrets,
without making calls to the k8s api server.

This change refactors the existing k8schain.New() method to separate the
resolution of secrets from the creation of the keychain. This is only a
refactoring of existing behavior to shortcut the k8s api lookups. There
is no change in existing behavior for the keychain.

Added:

k8schain.NewFromPullSecrets(context.Context, []corev1.Secret) (authn.Keychain, error)

Signed-off-by: Scott Andrews andrewssc@vmware.com

The k8schain package creates a new keychain by resolving Kubernets
secrets from service accounts and other image pull secrets specified by
name. The k8s client gets the full secret content for these named
resources.

Sometimes it's desirable to pull the content of a secret from a cache,
or to watch a resource for changes in a controller. In this situation
it would be helpful to create a k8schain directly from resolved secrets,
without making calls to the k8s api server.

This change refactors the existing k8schain.New() method to separate the
resolution of secrets from the creation of the keychain. This is only a
refactoring of existing behavior to shortcut the k8s api lookups. There
is no change in existing behavior for the keychain.

Added:

    k8schain.NewFromPullSecrets(context.Context, []corev1.Secret) (authn.Keychain, error)

Signed-off-by: Scott Andrews <andrewssc@vmware.com>
})

// Extend the default keyring with the pull secrets.
kr, err := credentialprovidersecrets.MakeDockerKeyring(pullSecrets, keyring)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You're okay with the default keyring here being the magical NewDockerKeyring() thing?

I'm starting to lean away from that (#1042) because it's caused problems (knative/serving#10259).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My goal for this PR was to not change the current behavior. I agree with the spirit of #1042

Copy link
Collaborator

@jonjohnsonjr jonjohnsonjr left a comment

Choose a reason for hiding this comment

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

Thanks!

@codecov-commenter
Copy link

codecov-commenter commented Jun 24, 2021

Codecov Report

Merging #1049 (9244d45) into main (a27f4a4) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1049      +/-   ##
==========================================
+ Coverage   75.47%   75.50%   +0.02%     
==========================================
  Files         107      107              
  Lines        5092     5094       +2     
==========================================
+ Hits         3843     3846       +3     
+ Misses        704      703       -1     
  Partials      545      545              
Impacted Files Coverage Δ
pkg/name/registry.go 100.00% <ø> (+2.43%) ⬆️
pkg/v1/remote/transport/ping.go 86.95% <100.00%> (-1.05%) ⬇️
pkg/crane/get.go 100.00% <0.00%> (ø)
pkg/v1/mutate/mutate.go 73.00% <0.00%> (+0.50%) ⬆️
pkg/v1/mutate/image.go 69.74% <0.00%> (+1.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11f8769...9244d45. Read the comment docs.

@jonjohnsonjr
Copy link
Collaborator

Ah sorry, can you fix the fmt error?

Signed-off-by: Scott Andrews <andrewssc@vmware.com>
@scothis
Copy link
Contributor Author

scothis commented Jun 24, 2021

@jonjohnsonjr done

@jonjohnsonjr jonjohnsonjr merged commit ce35c99 into google:main Jun 24, 2021
@scothis scothis deleted the k8schain-pullsecrets branch June 24, 2021 22:58
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.

None yet

3 participants