-
Notifications
You must be signed in to change notification settings - Fork 560
fix(vendor/scoped): bump k8s version to 1.24, go version to 1.18 and fix scoped client #2794
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
21edf69
fix(vendor): bump k8s version to 1.24 and go version to 1.18
dinhxuanvu 289833e
Update clock package from apimachinery to utils
dinhxuanvu b14f97d
fix(go.mod): pin opentelemetry packages into specific versions
dinhxuanvu 03758a9
fix(scoped): update scoped client library to handle token secret
dinhxuanvu 2dee09d
fix(e2e): Fix several RBAC-related e2e test cases
dinhxuanvu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ import ( | |
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient" | ||
"github.com/sirupsen/logrus" | ||
corev1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
|
@@ -50,29 +49,45 @@ func (r *BearerTokenRetriever) Retrieve(reference *corev1.ObjectReference) (toke | |
} | ||
|
||
func getAPISecret(logger logrus.FieldLogger, kubeclient operatorclient.ClientInterface, sa *corev1.ServiceAccount) (APISecret *corev1.Secret, err error) { | ||
for _, ref := range sa.Secrets { | ||
// corev1.ObjectReference only has Name populated. | ||
secret, getErr := kubeclient.KubernetesInterface().CoreV1().Secrets(sa.GetNamespace()).Get(context.TODO(), ref.Name, metav1.GetOptions{}) | ||
if getErr != nil { | ||
if apierrors.IsNotFound(getErr) { | ||
logger.Warnf("skipping secret %s - %v", ref.Name, getErr) | ||
continue | ||
} | ||
seList, err := kubeclient.KubernetesInterface().CoreV1().Secrets(sa.GetNamespace()).List(context.TODO(), metav1.ListOptions{}) | ||
if err != nil { | ||
logger.Errorf("unable to retrieve list of secrets in the namespace %s - %v", sa.GetNamespace(), err) | ||
return nil, err | ||
} | ||
secrets := filterSecretsBySAName(sa.Name, seList) | ||
|
||
err = getErr | ||
break | ||
for _, ref := range sa.Secrets { | ||
if _, ok := secrets[ref.Name]; !ok { | ||
logger.Warnf("skipping secret %s: secret not found", ref.Name) | ||
continue | ||
} | ||
} | ||
|
||
for _, secret := range secrets { | ||
// Validate that this is a token for API access. | ||
if !IsServiceAccountToken(secret, sa) { | ||
logger.Warnf("skipping secret %s - %v", ref.Name, getErr) | ||
logger.Warnf("skipping secret %s: not token secret", secret.Name) | ||
continue | ||
} | ||
|
||
// The first eligible secret that has an API access token is returned. | ||
APISecret = secret | ||
break | ||
} | ||
|
||
return | ||
} | ||
|
||
// filterSecretsBySAName returna a maps of secrets that are associated with a | ||
// specific ServiceAccount via annotations kubernetes.io/service-account.name | ||
func filterSecretsBySAName(saName string, secrets *corev1.SecretList) map[string]*corev1.Secret { | ||
secretMap := make(map[string]*corev1.Secret) | ||
for _, ref := range secrets.Items { | ||
annotations := ref.GetAnnotations() | ||
value := annotations[corev1.ServiceAccountNameKey] | ||
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. Do we need to nil check the annotations map here before indexing for the SA name key, or do maps handle this instruction fine? |
||
if value == saName { | ||
secretMap[ref.Name] = &ref | ||
} | ||
} | ||
|
||
return secretMap | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We're iterating over the list of SA secrets, purely for logging purposes, here? Is that right?