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

Migrate ServiceAccount to ServiceAccountName in v1alpha2 #835

Merged
merged 1 commit into from
Sep 28, 2021
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
4 changes: 2 additions & 2 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5543,7 +5543,7 @@
"schedulerName": {
"type": "string"
},
"serviceAccount": {
"serviceAccountName": {
"type": "string"
},
"services": {
Expand Down Expand Up @@ -6260,7 +6260,7 @@
"projectDescriptorPath": {
"type": "string"
},
"serviceAccount": {
"serviceAccountName": {
"type": "string"
},
"source": {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/build/v1alpha2/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (b *Build) Tag() string {
}

func (b *Build) ServiceAccount() string {
return b.Spec.ServiceAccount
return b.Spec.ServiceAccountName
}

func (b *Build) BuilderSpec() corev1alpha1.BuildBuilderSpec {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/build/v1alpha2/build_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (bs *BuildSpec) convertTo(to *v1alpha1.BuildSpec) {
StackId: bs.LastBuild.StackId,
}
}
to.ServiceAccount = bs.ServiceAccount
to.ServiceAccount = bs.ServiceAccountName
to.Builder = bs.Builder
to.Notary = bs.Notary
to.Bindings = bs.CNBBindings
Expand All @@ -72,7 +72,7 @@ func (bs *BuildSpec) convertFrom(from *v1alpha1.BuildSpec) {
StackId: from.LastBuild.StackId,
}
}
bs.ServiceAccount = from.ServiceAccount
bs.ServiceAccountName = from.ServiceAccount
bs.Builder = from.Builder
bs.Notary = from.Notary
bs.CNBBindings = from.Bindings
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/build/v1alpha2/build_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func testBuildConversion(t *testing.T, when spec.G, it spec.S) {
Name: "secret",
}},
},
ServiceAccount: "default",
ServiceAccountName: "default",
Cache: &BuildCacheConfig{
Volume: &BuildPersistentVolumeCache{
ClaimName: "some-claim-name",
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/build/v1alpha2/build_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func (b *Build) BuildPod(images BuildPodImages, secrets []corev1.Secret, config
)...,
)
}),
ServiceAccountName: b.Spec.ServiceAccount,
ServiceAccountName: b.Spec.ServiceAccountName,
NodeSelector: b.nodeSelector(config.OS),
Tolerations: b.Spec.Tolerations,
Affinity: b.Spec.Affinity,
Expand Down Expand Up @@ -586,7 +586,7 @@ func (b *Build) rebasePod(secrets []corev1.Secret, images BuildPodImages, config
},
},
Spec: corev1.PodSpec{
ServiceAccountName: b.Spec.ServiceAccount,
ServiceAccountName: b.Spec.ServiceAccountName,
NodeSelector: b.nodeSelector("linux"),
Tolerations: b.Spec.Tolerations,
Affinity: b.Spec.Affinity,
Expand Down Expand Up @@ -842,7 +842,7 @@ func setupBindingVolumesAndMounts(bindings []ServiceBinding) ([]corev1.Volume, [
)
}
default:
return nil,nil, errors.Errorf("unsupported binding type: %T", b)
return nil, nil, errors.Errorf("unsupported binding type: %T", b)
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/build/v1alpha2/build_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
CreationTimestamp: metav1.Date(1944, 6, 6, 13, 30, 0, 0, time.UTC),
},
Spec: buildapi.BuildSpec{
Tags: []string{"someimage/name", "someimage/name:tag2", "someimage/name:tag3"},
Builder: builderImageRef,
ServiceAccount: serviceAccount,
Tags: []string{"someimage/name", "someimage/name:tag2", "someimage/name:tag3"},
Builder: builderImageRef,
ServiceAccountName: serviceAccount,
Source: corev1alpha1.SourceConfig{
Git: &corev1alpha1.Git{
URL: "giturl.com/git.git",
Expand Down Expand Up @@ -1097,7 +1097,7 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
})

require.Equal(t, corev1.PodSpec{
ServiceAccountName: build.Spec.ServiceAccount,
ServiceAccountName: build.Spec.ServiceAccountName,
NodeSelector: map[string]string{
"kubernetes.io/os": "linux",
"foo": "bar",
Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/build/v1alpha2/build_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ var (
// +k8s:openapi-gen=true
type BuildSpec struct {
// +listType
Tags []string `json:"tags,omitempty"`
Builder corev1alpha1.BuildBuilderSpec `json:"builder,omitempty"`
ServiceAccount string `json:"serviceAccount,omitempty"`
Source corev1alpha1.SourceConfig `json:"source"`
Cache *BuildCacheConfig `json:"cache,omitempty"`
Tags []string `json:"tags,omitempty"`
Builder corev1alpha1.BuildBuilderSpec `json:"builder,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
Source corev1alpha1.SourceConfig `json:"source"`
Cache *BuildCacheConfig `json:"cache,omitempty"`
// +listType
Services Services `json:"services,omitempty"`
// +listType
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/build/v1alpha2/build_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
const kpackControllerServiceAccountUsername = "system:serviceaccount:kpack:controller"

func (b *Build) SetDefaults(ctx context.Context) {
if b.Spec.ServiceAccount == "" {
b.Spec.ServiceAccount = "default"
if b.Spec.ServiceAccountName == "" {
b.Spec.ServiceAccountName = "default"
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/build/v1alpha2/build_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func testBuildValidation(t *testing.T, when spec.G, it spec.S) {
Image: "builder/bionic-builder@sha256:e431a4f94fb84854fd081da62762192f36fd093fdfb85ad3bc009b9309524e2d",
ImagePullSecrets: nil,
},
ServiceAccount: "some/service-account",
ServiceAccountName: "some/service-account",
Source: corev1alpha1.SourceConfig{
Git: &corev1alpha1.Git{
URL: "http://github.com/repo",
Expand All @@ -47,11 +47,11 @@ func testBuildValidation(t *testing.T, when spec.G, it spec.S) {
})

it("defaults service account to default", func() {
build.Spec.ServiceAccount = ""
build.Spec.ServiceAccountName = ""

build.SetDefaults(context.TODO())

assert.Equal(t, build.Spec.ServiceAccount, "default")
assert.Equal(t, build.Spec.ServiceAccountName, "default")
})
})

Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/build/v1alpha2/image_builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (im *Image) Build(sourceResolver *SourceResolver, builder BuilderResource,
Spec: BuildSpec{
Tags: im.generateTags(buildNumber),
Builder: builder.BuildBuilderSpec(),
ServiceAccount: im.Spec.ServiceAccount,
ServiceAccountName: im.Spec.ServiceAccountName,
Source: sourceResolver.SourceConfig(),
Cache: im.getBuildCacheConfig(),
Services: im.Services(),
Expand Down Expand Up @@ -224,8 +224,8 @@ func (im *Image) SourceResolver() *SourceResolver {
Labels: im.Labels,
},
Spec: SourceResolverSpec{
ServiceAccount: im.Spec.ServiceAccount,
Source: im.Spec.Source,
ServiceAccountName: im.Spec.ServiceAccountName,
Source: im.Spec.Source,
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/build/v1alpha2/image_builds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) {
},
},
Spec: ImageSpec{
Tag: "some/image",
ServiceAccount: "some/service-account",
Tag: "some/image",
ServiceAccountName: "some/service-account",
Builder: corev1.ObjectReference{
Kind: "Builder",
Name: "builder-name",
Expand Down Expand Up @@ -67,9 +67,9 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) {
Name: "image-name",
},
Spec: BuildSpec{
Tags: []string{"some/image"},
Builder: builder.BuildBuilderSpec(),
ServiceAccount: "some/serviceaccount",
Tags: []string{"some/image"},
Builder: builder.BuildBuilderSpec(),
ServiceAccountName: "some/serviceaccount",
},
Status: BuildStatus{
Status: corev1alpha1.Status{
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/build/v1alpha2/image_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (i *Image) ConvertFrom(_ context.Context, from apis.Convertible) error {
func (is *ImageSpec) convertTo(to *v1alpha1.ImageSpec) {
to.Tag = is.Tag
to.Builder = is.Builder
to.ServiceAccount = is.ServiceAccount
to.ServiceAccount = is.ServiceAccountName
if is.Cache != nil && is.Cache.Volume != nil {
to.CacheSize = is.Cache.Volume.Size
}
Expand All @@ -58,7 +58,7 @@ func (is *ImageSpec) convertTo(to *v1alpha1.ImageSpec) {
func (is *ImageSpec) convertFrom(from *v1alpha1.ImageSpec) {
is.Tag = from.Tag
is.Builder = from.Builder
is.ServiceAccount = from.ServiceAccount
is.ServiceAccountName = from.ServiceAccount
is.Source = from.Source
if from.CacheSize != nil {
is.Cache = &ImageCacheConfig{
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/build/v1alpha2/image_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func testImageConversion(t *testing.T, when spec.G, it spec.S) {
Name: "my-super-convertable-image",
},
Spec: ImageSpec{
Tag: "my-tag",
Builder: corev1.ObjectReference{},
ServiceAccount: "service-account",
Tag: "my-tag",
Builder: corev1.ObjectReference{},
ServiceAccountName: "service-account",
Source: corev1alpha1.SourceConfig{
Git: &corev1alpha1.Git{
URL: "https://my-github.com/git",
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/build/v1alpha2/image_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Image struct {
type ImageSpec struct {
Tag string `json:"tag"`
Builder corev1.ObjectReference `json:"builder,omitempty"`
ServiceAccount string `json:"serviceAccount,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
Source corev1alpha1.SourceConfig `json:"source"`
Cache *ImageCacheConfig `json:"cache,omitempty"`
FailedBuildHistoryLimit *int64 `json:"failedBuildHistoryLimit,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/build/v1alpha2/image_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func init() {
}

func (i *Image) SetDefaults(ctx context.Context) {
if i.Spec.ServiceAccount == "" {
i.Spec.ServiceAccount = "default"
if i.Spec.ServiceAccountName == "" {
i.Spec.ServiceAccountName = "default"
}

if i.Spec.ImageTaggingStrategy == "" {
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/build/v1alpha2/image_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func testImageValidation(t *testing.T, when spec.G, it spec.S) {
Kind: "ClusterBuilder",
Name: "builder-name",
},
ServiceAccount: "some/service-account",
ServiceAccountName: "some/service-account",
Source: corev1alpha1.SourceConfig{
Git: &corev1alpha1.Git{
URL: "http://github.com/repo",
Expand Down Expand Up @@ -72,11 +72,11 @@ func testImageValidation(t *testing.T, when spec.G, it spec.S) {
})

it("defaults service account to default", func() {
image.Spec.ServiceAccount = ""
image.Spec.ServiceAccountName = ""

image.SetDefaults(ctx)

assert.Equal(t, image.Spec.ServiceAccount, "default")
assert.Equal(t, image.Spec.ServiceAccountName, "default")
})

it("defaults ImageTaggingStrategy to BuildNumber", func() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/build/v1alpha2/source_resolver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type SourceResolver struct {

// +k8s:openapi-gen=true
type SourceResolverSpec struct {
ServiceAccount string `json:"serviceAccount,omitempty"`
Source corev1alpha1.SourceConfig `json:"source"`
ServiceAccountName string `json:"serviceAccount,omitempty"`
Source corev1alpha1.SourceConfig `json:"source"`
}

// +k8s:openapi-gen=true
Expand Down
4 changes: 2 additions & 2 deletions pkg/cnb/cnb_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type RemoteMetadataRetriever struct {

func (r *RemoteMetadataRetriever) GetBuiltImage(ctx context.Context, build *buildapi.Build) (BuiltImage, error) {
keychain, err := r.KeychainFactory.KeychainForSecretRef(ctx, registry.SecretRef{
ServiceAccount: build.Spec.ServiceAccount,
ServiceAccount: build.Spec.ServiceAccountName,
Namespace: build.Namespace,
})
if err != nil {
Expand All @@ -59,7 +59,7 @@ func (r *RemoteMetadataRetriever) GetCacheImage(ctx context.Context, build *buil
}

keychain, err := r.KeychainFactory.KeychainForSecretRef(ctx, registry.SecretRef{
ServiceAccount: build.Spec.ServiceAccount,
ServiceAccount: build.Spec.ServiceAccountName,
Namespace: build.Namespace,
})

Expand Down
8 changes: 4 additions & 4 deletions pkg/cnb/cnb_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func testMetadataRetriever(t *testing.T, when spec.G, it spec.S) {
Namespace: "namespace-name",
},
Spec: buildapi.BuildSpec{
Tags: []string{"reg.io/appimage/name"},
ServiceAccount: "service-account",
Tags: []string{"reg.io/appimage/name"},
ServiceAccountName: "service-account",
},
Status: buildapi.BuildStatus{},
}
Expand All @@ -46,7 +46,7 @@ func testMetadataRetriever(t *testing.T, when spec.G, it spec.S) {

it("retrieves the metadata from the registry", func() {
appImageSecretRef := registry.SecretRef{
ServiceAccount: build.Spec.ServiceAccount,
ServiceAccount: build.Spec.ServiceAccountName,
Namespace: build.Namespace,
}
appImageKeychain := &registryfakes.FakeKeychain{}
Expand Down Expand Up @@ -101,7 +101,7 @@ func testMetadataRetriever(t *testing.T, when spec.G, it spec.S) {

it("retrieves the metadata from the registry", func() {
appImageSecretRef := registry.SecretRef{
ServiceAccount: build.Spec.ServiceAccount,
ServiceAccount: build.Spec.ServiceAccountName,
Namespace: build.Namespace,
}
appImageKeychain := &registryfakes.FakeKeychain{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/git/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewResolver(k8sClient k8sclient.Interface) *Resolver {
}

func (r *Resolver) Resolve(ctx context.Context, sourceResolver *buildapi.SourceResolver) (corev1alpha1.ResolvedSourceConfig, error) {
keychain, err := r.gitKeychain.KeychainForServiceAccount(ctx, sourceResolver.Namespace, sourceResolver.Spec.ServiceAccount)
keychain, err := r.gitKeychain.KeychainForServiceAccount(ctx, sourceResolver.Namespace, sourceResolver.Spec.ServiceAccountName)
if err != nil {
return corev1alpha1.ResolvedSourceConfig{}, err
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/openapi/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/reconciler/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func testBuildReconciler(t *testing.T, when spec.G, it spec.S) {
Generation: originalGeneration,
},
Spec: buildapi.BuildSpec{
Tags: []string{"someimage/name", "someimage/name:tag2", "someimage/name:tag3"},
ServiceAccount: serviceAccountName,
Tags: []string{"someimage/name", "someimage/name:tag2", "someimage/name:tag3"},
ServiceAccountName: serviceAccountName,
Builder: corev1alpha1.BuildBuilderSpec{
Image: "somebuilder/123@sha256:12334563ad",
ImagePullSecrets: []corev1.LocalObjectReference{
Expand Down
Loading