-
Notifications
You must be signed in to change notification settings - Fork 23
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 secrets for serviceaccounts #125
Conversation
🤖 Created branch: z_pr125/vthapar/secret-tokens |
Reworked the code, addressed comments
@skitt @tpantelis This is ready for review. I have only tweaked the UTs just enough to pass so that we can get this in and unblock submariner-io/shipyard#825 I can add UTs in a subsequent PR, unless you think UTs need to come in this patch itself. |
@vthapar is this ready for review? It looks like two CI jobs are failing |
Upgrade job is the only one that failed more than once, e2e has failed just once. Re-ran the jobs to see if e2e fails again. Looking into upgrade job issue. |
543b847
to
678c374
Compare
🤖 I had an issue pushing the updated branch: already up-to-date |
@skitt @sridhargaddam @tpantelis this one needs review |
pkg/broker/ensure.go
Outdated
return nil, err | ||
} | ||
|
||
_, err = serviceaccount.EnsureSecretFromSA(kubeClient, sa.Name, inNamespace) |
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.
My previous comment still applies, unless I’ve missed something:
I would prefer the secret handling to be hidden in the SA handling — callers shouldn’t have to know that to set up a service account correctly, they have to set up a secret.
In other words, there should only be a call to serviceaccount.Ensure()
in this function, and serviceaccount.Ensure()
should handle the secret (perhaps by calling EnsureSecretFromSA()
, of course, but that should be transparent to the caller).
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.
My previous comment still applies, unless I’ve missed something:
I would prefer the secret handling to be hidden in the SA handling — callers shouldn’t have to know that to set up a service account correctly, they have to set up a secret.
In other words, there should only be a call to
serviceaccount.Ensure()
in this function, andserviceaccount.Ensure()
should handle the secret (perhaps by callingEnsureSecretFromSA()
, of course, but that should be transparent to the caller).
Got it. I missed the context of comment for Ensure
and only addressed for EnsureFromYaml
.
@vthapar can you please address Stephen's comment? |
Done. |
pkg/serviceaccount/ensure.go
Outdated
if err == nil { | ||
return true, nil | ||
} |
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 should distinguish NotFound
error
if err == nil { | |
return true, nil | |
} | |
if apierrors.IsNotFound(err) | |
return nil | |
} | |
if err != nil { | |
return err | |
} |
f152db6
to
3b61f57
Compare
🤖 I had an issue pushing the updated branch: already up-to-date |
K8s 1.24+ doesn't autocreate secret for serviceaccount. This breaks submariner deployments which expects secret to be created and associated to the corresponding serviceaccount. The fix ensures the Secret of type service-account-token exists, is annotated with ServiceAccount.Name, and is added to Secrets list in the ServiceAccount. Fixes submariner-io#102 Signed-off-by: Vishal Thapar <[email protected]>
Signed-off-by: Vishal Thapar <[email protected]>
pkg/broker/ensure.go
Outdated
if apierrors.IsNotFound(err) { | ||
|
||
} |
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.
There’s something missing here, I presume.
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.
There’s something missing here, I presume.
Missed cleanup after refactor.
if err != nil { | ||
newSecret := &corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: fmt.Sprintf("%s-token-%s", sa.Name, generateRandomString(5)), |
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.
Can’t we use GenerateName
here?
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 can fix this up later, this shouldn’t block the PR.
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.
I used GenerateName in intial draft, but then needed to do another Get to find the generated name. Went with this coz similar to what OCP's controller is doing.
Refactor serviceaccount.Ensure so that creation of secret is transparent to caller. Signed-off-by: Vishal Thapar <[email protected]>
🤖 Closed branches: [z_pr125/vthapar/secret-tokens] |
K8s 1.24+ doesn't autocreate secret for serviceaccount. This
breaks submariner deployments which expects secret to be created
and associated to the corresponding serviceaccount.
The fix ensures the Secret of type service-account-token exists,
is annotated with ServiceAccount.Name, and is added to Secrets list in
the ServiceAccount.
Fixes #102
Signed-off-by: Vishal Thapar [email protected]