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

Remove compatability code to remove service account with -sa suffix #957

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/buildrun.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SPDX-License-Identifier: Apache-2.0
- [Defining ParamValues](#defining-paramvalues)
- [Defining the ServiceAccount](#defining-the-serviceaccount)
- [Canceling a `BuildRun`](#canceling-a-buildrun)
- [Specifying Environment Variables](#specifying-environment-variables)
- [BuildRun Status](#buildrun-status)
- [Understanding the state of a BuildRun](#understanding-the-state-of-a-buildrun)
- [Understanding failed BuildRuns](#understanding-failed-buildruns)
Expand Down Expand Up @@ -132,9 +133,9 @@ spec:
name: pipeline
```

You can also use set the `spec.serviceAccount.generate` path to `true`. This will generate the service account during runtime for you.
You can also use set the `spec.serviceAccount.generate` path to `true`. This will generate the service account during runtime for you. The name of the generated service account is the name of the BuildRun.

_**Note**_: When the SA is not defined, the `BuildRun` will default to the `default` SA in the namespace.
_**Note**_: When the service account is not defined, the `BuildRun` will use the `pipeline` service account if it exists in the namespace, and fall back to the `default` service account.

## Canceling a `BuildRun`

Expand Down
18 changes: 2 additions & 16 deletions pkg/reconciler/buildrun/resources/service_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ func GetGeneratedServiceAccountName(buildRun *buildv1alpha1.BuildRun) string {
return buildRun.Name
}

// GetHeritageGeneratedServiceAccountName return the name of the generated service account for
// a build run as it was used in older releases of Shipwright Build
func GetHeritageGeneratedServiceAccountName(buildRun *buildv1alpha1.BuildRun) string {
return buildRun.Name + "-sa"
}

// IsGeneratedServiceAccountUsed checks if a build run uses a generated service account
func IsGeneratedServiceAccountUsed(buildRun *buildv1alpha1.BuildRun) bool {
return buildRun.Spec.ServiceAccount != nil && buildRun.Spec.ServiceAccount.Generate
Expand Down Expand Up @@ -103,16 +97,8 @@ func DeleteServiceAccount(ctx context.Context, client client.Client, completedBu
serviceAccount.Namespace = completedBuildRun.Namespace

ctxlog.Info(ctx, "deleting service account", namespace, completedBuildRun.Namespace, name, completedBuildRun.Name, "serviceAccount", serviceAccount.Name)
if err := client.Delete(ctx, serviceAccount); err != nil {
if apierrors.IsNotFound(err) {
serviceAccount.Name = GetHeritageGeneratedServiceAccountName(completedBuildRun)
ctxlog.Info(ctx, "deleting service account", namespace, completedBuildRun.Namespace, name, completedBuildRun.Name, "serviceAccount", serviceAccount.Name)
err = client.Delete(ctx, serviceAccount)
}

if err != nil && !apierrors.IsNotFound(err) {
return err
}
if err := client.Delete(ctx, serviceAccount); err != nil && !apierrors.IsNotFound(err) {
return err
}

return nil
Expand Down
1 change: 0 additions & 1 deletion pkg/reconciler/buildrun/resources/service_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ var _ = Describe("Operating service accounts", func() {

It("should provide a generated sa name", func() {
Expect(resources.GetGeneratedServiceAccountName(buildRunSample)).To(Equal(buildRunSample.Name))
Expect(resources.GetHeritageGeneratedServiceAccountName(buildRunSample)).To(Equal(buildRunSample.Name + "-sa"))
})

It("should return a generated sa with a label, ownerreference and a ref secret if it does not exists", func() {
Expand Down